haskell - How to output minimal binary using Data.Binary and Data.ByteString.Lazy? -


minimal test code (bs.hs):

import qualified data.binary b import qualified data.bytestring.lazy.char8 bslc  main =     bslc.putstr $ b.encode $ pad $ bslc.pack "xxx"  data pad = pad bslc.bytestring instance b.binary pad     put (pad p) =         b.put p     =         p <- b.get         return $ pad p 

and get:

% runghc bs.hs | od -c 0000000   \0  \0  \0  \0  \0  \0  \0 003   x   x   x                     0000013 % ghc --version glorious glasgow haskell compilation system, version 7.10.2 

i expect "xxx". have no idea how first 8 bytes (7 x \0 + 1 x 003) come from.

from comment, explanation of output format binary uses serializing bytestrings output length 64-bit integer followed contents of bytestring.

generally, though, binary class of limited use. there's no guarantee of forward or backward compatibility, no mechanism allow schema evolution, no standard or specification instances allow cross-language interoperability. it's useful if want opaque binary blob store temporarily and/or communicate nodes have high level of control over. consumer, can expect of binary instance. while there no reason not make binary instance type create serialization code, if offer guarantees beyond above should (also) present separately binary class. ideally, instance of class communicates guarantees, e.g. class serializing specific format such avro.

all directed @ binary class. rest of binary package quite useful intended purpose.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -