From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 710B8BC37 for ; Thu, 29 Oct 2009 11:34:50 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhICAO4M6UrZSMDqkWdsb2JhbACBT5l3AQEBAQkLCgcTA8AzhD0EgWI X-IronPort-AV: E=Sophos;i="4.44,645,1249250400"; d="scan'208";a="49450534" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail4-smtp-sop.national.inria.fr with ESMTP; 29 Oct 2009 11:34:39 +0100 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate03.web.de (Postfix) with ESMTP id 3697D12C544A7; Thu, 29 Oct 2009 11:34:39 +0100 (CET) Received: from [95.208.117.111] (helo=frosties.localdomain) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1N3SL0-00029K-00; Thu, 29 Oct 2009 11:34:38 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1N3SKx-0003h2-Gf; Thu, 29 Oct 2009 11:34:35 +0100 From: Goswin von Brederlow To: Goswin von Brederlow Cc: blue storm , Sylvain Le Gall , caml-list@inria.fr Subject: Re: [Caml-list] Re: How to read different ints from a Bigarray? References: <87eiond3of.fsf@frosties.localdomain> <87639zd0m9.fsf@frosties.localdomain> <87tyxj5rkv.fsf@frosties.localdomain> <527cf6bc0910281548s53a00ec9s99402f4249b2d411@mail.gmail.com> <873a52wmu0.fsf@frosties.localdomain> Date: Thu, 29 Oct 2009 11:34:35 +0100 In-Reply-To: <873a52wmu0.fsf@frosties.localdomain> (Goswin von Brederlow's message of "Thu, 29 Oct 2009 10:50:31 +0100") Message-ID: <87fx9232v8.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/NTxUlHNMleE+7JGChJfdgsAOox8mmLJV2+a7D wTKLg+SjKmlvczo+K6GsoTWxwaZI5Eh3pi9LVr5y2d7K37VDkv xrbipz2Lc= X-Spam: no; 0.00; bigarray:01 buf:01 camlp:01 on-topic:01 foo:01 foo:01 unparsing:01 storm:98 28,:98 2009:98 glanced:98 mfg:98 mfg:98 char:01 wrote:01 Goswin von Brederlow writes: > blue storm writes: > >> On Wed, Oct 28, 2009 at 6:57 PM, Goswin von Brederlow wrote: >>> Maybe ideal would be a format string based interface that calls C with >>> a format string and a record of values. Because what I really need is >>> to read/write records in an architecture independend way. Something >>> like >>> >>> type t = { x:int; y:char; z:int64 } >>> let t_format = "%2u%c%8d" >>> >>> put_formated buf t_format t >>> >>> But how to get that type safe? Maybe a camlp4 module that generates >>> the format string and type from a single declaration so they always >>> match. >> >> It's possibly off-topic, but you might be interested in Richard >> Jones's Bitstring project [1] wich deals with similar issues quite >> nicely in my opinion. >> >> [1] http://code.google.com/p/bitstring/ > > No, quite on-topic. > > I glanced at the examples and code and it looks to me though as if > this can only parse bitstrings but not create them from a pattern. > You have > > let parse_foo bits = > bitmatch bits with > | { x : 16 : littleendian; y : 16 : littleendian } -> fun x y -> (x, y) > > but no > > let unparse_foo (x, y) = > bitmake { x : 16 : littleendian; y : 16 : littleendian } x y > > > Idealy would be something along > > let pattern = make_pattern { x : 16 : littleendian; y : 16 : littleendian } > let parse_foo bits = parse pattern (fun x y -> (x, y)) > let unparse_foo (x, y) = unparse pattern x y > > But I know how to do that with CPS already. I just need the primitives > to get/set the basic types. > > MfG > Goswin And I was wrong. There is http://code.google.com/p/bitstring/source/browse/trunk/examples/make_ipv4_header.ml as an example. Not ideal since parsing and unparsing will duplicate the pattern definition but that will be locale for each type. MfG Goswin