From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 1EC73BC0A for ; Fri, 18 May 2007 16:44:20 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.231]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4IEiJ6f015760 for ; Fri, 18 May 2007 16:44:19 +0200 Received: by wr-out-0506.google.com with SMTP id l58so920298wrl for ; Fri, 18 May 2007 07:44:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=apngkies1N+6znF6yWxA85aKbZEjOHuuJzutCADAXcM+5RmF67Sr4aTlPGY7WctCn6vc5MQcsw+36lfrNric6v9CLSHKK8r+r2HvBMsQPa73fPvQhxnc36lYuICP9kGPeu4Impjwpf7Cc92O4cGbvSollHohk8Cnvn8bV6TmAts= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=NkhTZRKiOA++Oe8q4isTe1BerNGTJQDyfUQYNzfbO8OmFhmaO0QYDhv5ouO5Ybr9GNMzQbAWu5MrSQI8KT1Xo7Nekz4wb9U70VqRliMQ2eqLD5C7QguwCziu7bF+6s7nEotQVTeXk1Egpc9FUUlH4IaIJpU6Dx1auVkfwXnCIWs= Received: by 10.78.204.7 with SMTP id b7mr515026hug.1179499458123; Fri, 18 May 2007 07:44:18 -0700 (PDT) Received: by 10.78.16.3 with HTTP; Fri, 18 May 2007 07:44:17 -0700 (PDT) Message-ID: Date: Fri, 18 May 2007 10:44:17 -0400 From: "Markus Mottl" To: "Richard Jones" Subject: Re: [Caml-list] DSL for handling parsing binary memory structures? Cc: caml-list@inria.fr In-Reply-To: <20070517212157.GA20085@furbychan.cocan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070517212157.GA20085@furbychan.cocan.org> X-j-chkmail-Score: MSGID : 464DBBC3.005 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 464DBBC3.005 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 parsing:01 ocaml:01 alignment:01 bitfields:01 accessors:01 ocaml:01 wrote:01 abstract:01 integer:01 preprocessor:01 caml-list:01 On 5/17/07, Richard Jones wrote: > I wonder if anyone has thought about or developed a domain-specific > language in OCaml for handling the processing of binary structures? > > I was thinking of writing something to make system calls into the Xen > hypervisor. The main problem is that the hypervisor takes & returns > binary structures which have very precise size / alignment > requirements, bitfields, etc. (and the requirements change with > versions of the hypervisor). It sounds like the ideal use for a DSL > to describe the binary structure of each version of each call and > automatically build accessors. I'm currently developing a preprocessor that generates readers/writers for binary protocols from OCaml type specifications. It should be very easy to add custom binary decoders by specifying an abstract type for such values + custom readers/writer. Or one can (ab)use the existing ones to get the intended result (e.g. just use the int32 type to read a 32bit integer from some memory loccation, etc.). The protocol is very compact (even slightly more so than the OCaml-marshal format), and performance is extremely high, usually even higher than the standard marshal function, though it doesn't handle shared/cyclic datastructures. I also haven't looked into endianness functionality yet (should be easy to add), but both 32bit and 64bit platforms are supported. In later stages there will also be a feature for a "protocol handshake", which guarantees that e.g. the type specifications used by two communicating machines are compatible. We (Jane Street Capital) will eventually release this library as open source so stay tuned... Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com