<br>dude .. you rock ... let me check it out ;^)<br><br>Vasili<br><br><br><div class="gmail_quote">On Fri, Jan 2, 2009 at 12:24 AM, Antoine Latter <span dir="ltr">&lt;<a href="mailto:aslatter@gmail.com">aslatter@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Jan 1, 2009 11:50pm, &quot;Galchin, Vasili&quot; &lt;<a href="mailto:vigalchin@gmail.com">vigalchin@gmail.com</a>&gt; wrote:<br>

&gt; it is a bioinformatics standard .. . I am writing on this newsgroup in order to try to be objective to get a &quot;correct&quot; and elegant answer .. in any case I am helping on the bioinformatics code (you can see on Hackage). I am trying to finish the 2Bit file format code ... it seems to me that bioinformatics as an area is not clearly defined .... e.g. it is unclear to me whether &quot;offset&quot; is a marshalled/serialized concept or or unmarshalled/unserialized concept ..... this distinction is very important .... I will have to think about more myself!<br>

&gt;<br>
&gt;<br>
&gt; Regards, Vasili<br>
&gt;<br>
<br>
<br>
</div>Here&#39;s some code using Data.Binary to store data as offsets into a<br>
byte array. &nbsp;I haven&#39;t tested it too much, so it may have bugs. &nbsp;Maybe<br>
there&#39;s some inspiration in there.<br>
<br>
-Antoine<br>
<br>
&gt;&gt;&gt;&gt;<br>
import Data.Binary<br>
import Data.Binary.Get<br>
import Data.Binary.Put<br>
<br>
import Data.ByteString.Lazy (ByteString)<br>
import qualified Data.ByteString.Lazy as B<br>
<br>
data TestStruct = TestStruct<br>
 &nbsp; &nbsp;{ property1 :: ByteString<br>
 &nbsp; &nbsp;, property2 :: ByteString<br>
 &nbsp; &nbsp;, property3 :: ByteString<br>
 &nbsp; &nbsp;}<br>
&nbsp;deriving Show<br>
<br>
{-<br>
<br>
&nbsp;The serialized format looks like (all big-endian):<br>
<br>
&nbsp;* first offset into data block (Word32)<br>
&nbsp;* second offset into data block (Word32)<br>
&nbsp;* third offset into data block (Word32)<br>
&nbsp;* length of bnary data block (Word32)<br>
&nbsp;* binary data block (Arbitrary binary data)<br>
<br>
-}<br>
instance Binary TestStruct where<br>
 &nbsp; &nbsp;put struct =<br>
 &nbsp; &nbsp; &nbsp; &nbsp;let data1 = property1 struct<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data2 = property2 struct<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data3 = property3 struct<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataBlock = data1 `B.append` data2 `B.append` data3<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;offset1 = 0<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;offset2 = offset1 + B.length data1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;offset3 = offset2 + B.length data2<br>
<br>
 &nbsp; &nbsp; &nbsp; in do<br>
 &nbsp; &nbsp; &nbsp; &nbsp; putWord32be $ fromIntegral offset1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; putWord32be $ fromIntegral offset2<br>
 &nbsp; &nbsp; &nbsp; &nbsp; putWord32be $ fromIntegral offset3<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; putWord32be $ fromIntegral $ B.length dataBlock<br>
 &nbsp; &nbsp; &nbsp; &nbsp; putLazyByteString dataBlock<br>
<br>
 &nbsp; &nbsp;get = do<br>
 &nbsp; &nbsp; &nbsp;offset1 &lt;- getWord32be<br>
 &nbsp; &nbsp; &nbsp;offset2 &lt;- getWord32be<br>
 &nbsp; &nbsp; &nbsp;offset3 &lt;- getWord32be<br>
<br>
 &nbsp; &nbsp; &nbsp;dataBlockLength &lt;- getWord32be<br>
 &nbsp; &nbsp; &nbsp;dataBlock &lt;- B.drop (fromIntegral offset1) `fmap`<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getLazyByteString (fromIntegral dataBlockLength)<br>
<br>
 &nbsp; &nbsp; &nbsp;let (data1, rest1) =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B.splitAt (fromIntegral $ offset2 - offset1) dataBlock<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(data2, rest2) =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B.splitAt (fromIntegral $ offset3 - offset2 - offset1) rest1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= rest2<br>
<br>
 &nbsp; &nbsp; &nbsp;return $ TestStruct data1 data2 data3<br>
&lt;&lt;&lt;&lt;&lt;<br>
</blockquote></div><br>