N      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMportable to Hugs and GHC experimental%Lennart Kolmodin <kolmodin@gmail.com> TrustworthyA # is an efficient way to build lazy Ns. . There are several functions for constructing s, but only one G to inspect them: to extract any data, you have to turn them into lazy  Ns using . Internally, a  constructs a lazy  by filling byte 9 arrays piece by piece. As each buffer is filled, it is 'popped' 2 off, to become a new chunk of the resulting lazy N. ) All this is hidden from the user of the . O(1). The empty Builder, satisfying    = OO(1)., A Builder taking a single byte, satisfying   ( b) = P bO(1).= The concatenation of two Builders, an associative operation  with identity  , satisfying   ( x y) = Q ( x) ( y)O(1). A Builder taking a R , satisfying   ( bs) = S [bs]O(1). A Builder taking a lazy N , satisfying   ( bs) = bsO(n). Extract a lazy N from a . D The construction work takes place if and when the relevant part of  the lazy N is demanded. O(1). Pop the R% we have constructed so far, if any, ) yielding a new chunk in the result lazy N.  Ensure that n# bytes are available, and then use f to write at  most n bytes into memory. f" must return the actual number of  bytes written.  Ensure that n# bytes are available, and then use f to write  exactly n bytes into memory. $Write a Word16 in big endian format 'Write a Word16 in little endian format $Write a Word32 in big endian format 'Write a Word32 in little endian format $Write a Word64 in big endian format 'Write a Word64 in little endian format O(1).< A Builder taking a single native machine word. The word is = written in host order, host endian form, for the machine you're on. G On a 64 bit machine the Word is an 8 byte value, on a 32 bit machine, 6 4 bytes. Values written this way are not portable to > different endian or word sized machines, without conversion. 9Write a Word16 in native host order and host endianness. % 2 bytes will be written, unaligned. 9Write a Word32 in native host order and host endianness. % 4 bytes will be written, unaligned. %Write a Word64 in native host order. J On a 32 bit machine we write two host order Word32s, in big endian form. % 8 bytes will be written, unaligned. (Write a character using UTF-8 encoding.  T  Tportable to Hugs and GHC experimental%Lennart Kolmodin <kolmodin@gmail.com> Trustworthy  portable to Hugs and GHC experimental%Lennart Kolmodin <kolmodin@gmail.com>Safe   portable to Hugs and GHC. experimental%Lennart Kolmodin <kolmodin@gmail.com> TrustworthyIThe Get monad is just a State monad carrying around the input ByteString ' We treat it as a strict state monad. Run the Get monad applies a U&-based parser on the input ByteString Run the Get monad applies a U-based parser on the input F ByteString. Additional to the result of get it returns the number of + consumed bytes and the rest of the input.  Skip ahead n bytes. Fails if fewer than n bytes are available.  Skip ahead n bytes. No error if there isn't enough bytes. Run ga*, but return without consuming its input.  Fails if ga fails. Like , but consume the input if gma returns 'Just _'.  Fails if gma fails. Like , but consume the input if gea returns 'Right _'.  Fails if gea fails. Get the next up to n6 bytes as a lazy ByteString, without consuming them. 2Get the total number of bytes read to this point. ,Get the number of remaining unparsed bytes. : Useful for checking whether all input has been consumed. . Note that this forces the rest of the input. *Test whether all input has been consumed, - i.e. there are no remaining unparsed bytes. ! An efficient U/ method for strict ByteStrings. Fails if fewer  than n bytes are left in the input. " An efficient U: method for lazy ByteStrings. Does not fail if fewer than  n bytes are left in the input. #@Get a lazy ByteString that is terminated with a NUL byte. Fails 7 if it reaches the end of input without hitting a NUL. $-Get the remaining bytes as a lazy ByteString % important Pull n/ bytes from the input, as a strict ByteString. &"Read a Word8 from the monad state '#Read a Word16 in big endian format (&Read a Word16 in little endian format )#Read a Word32 in big endian format *&Read a Word32 in little endian format +#Read a Word64 in big endian format ,&Read a Word64 in little endian format -O(1).8 Read a single native machine word. The word is read in 2 host order, host endian form, for the machine you're on. On a 64 bit D machine the Word is an 8 byte value, on a 32 bit machine, 4 bytes. .O(1).@ Read a 2 byte Word16 in native host order and host endianness. /O(1).9 Read a Word32 in native host order and host endianness. 0O(1).8 Read a Word64 in native host order and host endianess.  !"#$%&'()*+,-./0VWXY !"#$%&'()*+,-./0% &!"#$')+(*,-./0  !"#$%&'()*+,-./0VWXY(Portable to Hugs and GHC. Requires MPTCsstable%Lennart Kolmodin <kolmodin@gmail.com> Trustworthy1=Put merely lifts Builder into a Writer monad, applied to (). 2AThe PutM type. A Writer monad over the efficient Builder monoid. 6Run the 1 monad 7Run the 1 monad with a serialiser 8Run the 1, monad with a serialiser and get its result 9BPop the ByteString we have constructed so far, if any, yielding a % new chunk in the result ByteString. :0Efficiently write a byte into the output buffer ;LAn efficient primitive to write a strict ByteString into the output buffer. J It flushes the current buffer, and writes the argument into a new chunk. <?Write a lazy ByteString efficiently, simply appending the lazy ( ByteString chunks to the output buffer =$Write a Word16 in big endian format >'Write a Word16 in little endian format ?$Write a Word32 in big endian format @'Write a Word32 in little endian format A$Write a Word64 in big endian format B'Write a Word64 in little endian format CO(1).1 Write a single native machine word. The word is = written in host order, host endian form, for the machine you're on. G On a 64 bit machine the Word is an 8 byte value, on a 32 bit machine, 6 4 bytes. Values written this way are not portable to > different endian or word sized machines, without conversion. DO(1).: Write a Word16 in native host order and host endianness.  For portability issues see  putWordhost. EO(1).: Write a Word32 in native host order and host endianness.  For portability issues see  putWordhost. FO(1).% Write a Word64 in native host order J On a 32 bit machine we write two host order Word32s, in big endian form.  For portability issues see  putWordhost. 123456789:;<=>?@ABCDEFZ[\123456789:;<=>?@ABCDEF123478569:;<=?A>@BCDEF123456789:;<=>?@ABCDEFZ[\Fportable to Hugs and GHC. Requires the FFI and some flexible instancesunstable%Lennart Kolmodin <kolmodin@gmail.com> TrustworthyGThe Binary class provides H and I, methods to encode and F decode a Haskell value to a lazy ByteString. It mirrors the Read and B Show classes for textual representation of Haskell types, and is D suitable for serialising Haskell values to disk, over the network. BFor parsing and generating simple external binary formats (e.g. C A structures), Binary may be used, but in general is not suitable ? for complex protocols. Instead use the Put and Get primitives  directly. ;Instances of Binary should satisfy the following property:   decode . encode == id  That is, the I and H' methods should be the inverse of each D other. A range of instances are provided for basic Haskell types. H!Encode a value in the Put monad. I Decode a value in the Get monad J@Encode a value using binary serialisation to a lazy ByteString. KNDecode a value from a lazy ByteString, reconstructing the original structure. L#Lazily serialise a value to a file 'This is just a convenience function, it's defined simply as:  ' encodeFile f = B.writeFile f . encode ASo for example if you wanted to compress as well, you could use: # B.writeFile f . compress . encode M9Lazily reconstruct a value previously written to a file. 'This is just a convenience function, it's defined simply as:  1 decodeFile f = return . decode =<< B.readFile f CSo for example if you wanted to decompress as well, you could use:  / return . decode . decompress =<< B.readFile f 0After contructing the data from the input file, M checks F if the file is empty, and in doing so will force the associated file B handle closed, if it is indeed empty. If the file is not empty, D it is up to the decoding instance to consume the rest of the data, % or otherwise finalise the resource. /GHIJKLM]^_`abcdefghijklmnopqrstuvwxyz{|}~&1:GHIJKLM GHI1:&JKLM-GHIJKLM]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;:<=>?@ABCDEFGHIJKLMKN KN KN KOMKNPQFRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~binary-0.5.1.1Data.Binary.BuilderData.Binary.Builder.InternalData.Binary.GetData.Binary.Put Data.BinaryData.Binary.Builder.BaseL BytestringBuilderempty singletonappendfromByteStringfromLazyByteStringtoLazyByteStringflush writeAtMostwriteN putWord16be putWord16le putWord32be putWord32le putWord64be putWord64le putWordhost putWord16host putWord32host putWord64host putCharUtf8GetrunGet runGetStateskip uncheckedSkip lookAhead lookAheadM lookAheadEuncheckedLookAhead bytesRead remainingisEmpty getByteStringgetLazyByteStringgetLazyByteStringNulgetRemainingLazyByteStringgetBytesgetWord8 getWord16be getWord16le getWord32be getWord32le getWord64be getWord64le getWordhost getWord16host getWord32host getWord64hostPutPutMunPut putBuilderexecPutrunPutrunPutMputWord8 putByteStringputLazyByteStringBinaryputgetencodedecode encodeFile decodeFilebytestring-0.9.2.1Data.ByteString.Lazy.Internal ByteStringData.ByteString.LazyData.ByteString.Internal fromChunks$fMonoidBuilder $fMonadFixGet $fMonadGet$fApplicativeGet $fFunctorGet $fMonadPutM$fApplicativePutM $fFunctorPutM$fBinaryUArray $fBinaryArray $fBinaryTree $fBinaryFloat$fBinaryDouble $fBinarySeq$fBinaryIntMap$fBinaryIntSet $fBinaryMap $fBinarySet$fBinaryByteString$fBinaryByteString0$fBinaryEither $fBinaryMaybe $fBinary[]$fBinary(,,,,,,,,,)$fBinary(,,,,,,,,)$fBinary(,,,,,,,)$fBinary(,,,,,,)$fBinary(,,,,,)$fBinary(,,,,) $fBinary(,,,) $fBinary(,,) $fBinary(,) $fBinaryChar $fBinaryRatio$fBinaryInteger $fBinaryInt $fBinaryWord $fBinaryInt64 $fBinaryInt32 $fBinaryInt16 $fBinaryInt8$fBinaryWord64$fBinaryWord32$fBinaryWord16 $fBinaryWord8$fBinaryOrdering $fBinaryBool $fBinary()baseGHC.WordWordWord8Word16Word32Word64