Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data VPut a
- putVRef :: VRef a -> VPut ()
- putPVar :: PVar a -> VPut ()
- putVSpace :: VSpace -> VPut ()
- putWord8 :: Word8 -> VPut ()
- putWord16le :: Word16 -> VPut ()
- putWord16be :: Word16 -> VPut ()
- putWord32le :: Word32 -> VPut ()
- putWord32be :: Word32 -> VPut ()
- putWord64le :: Word64 -> VPut ()
- putWord64be :: Word64 -> VPut ()
- putStorable :: Storable a => a -> VPut ()
- putVarNat :: Integer -> VPut ()
- putVarInt :: Integer -> VPut ()
- reserve :: Int -> VPut ()
- reserving :: Int -> VPut a -> VPut a
- unsafePutWord8 :: Word8 -> VPut ()
- putByteString :: ByteString -> VPut ()
- putByteStringLazy :: ByteString -> VPut ()
- putc :: Char -> VPut ()
- peekBufferSize :: VPut Int
- peekChildCount :: VPut Int
Documentation
VPut is a serialization monad akin to Data.Binary or Data.Cereal. However, VPut is not restricted to pure binaries: developers may include VRefs and PVars in the output.
Content emitted by VPut will generally be read only by VCache. So it may be worth optimizing some cases, such as lists are written in reverse such that readers won't need to reverse the list.
Prim Writers
putVRef :: VRef a -> VPut () Source
Store a reference to a value. The value reference must already use the same VCache and addres space as where you're putting it.
putPVar :: PVar a -> VPut () Source
Store an identifier for a persistent variable in the same VCache and address space.
putVSpace :: VSpace -> VPut () Source
Put VSpace doesn't actually output anything, but will fail if the target space does not match the given one.
putWord16le :: Word16 -> VPut () Source
Put a Word in little-endian or big-endian form.
Note: These are mostly included because they're part of the Data.Binary and Data.Cereal APIs. They may be useful in some cases, but putVarInt will frequently be preferable.
putWord16be :: Word16 -> VPut () Source
Put a Word in little-endian or big-endian form.
Note: These are mostly included because they're part of the Data.Binary and Data.Cereal APIs. They may be useful in some cases, but putVarInt will frequently be preferable.
putWord32le :: Word32 -> VPut () Source
putWord32be :: Word32 -> VPut () Source
putWord64le :: Word64 -> VPut () Source
putWord64be :: Word64 -> VPut () Source
putStorable :: Storable a => a -> VPut () Source
Put a Data.Storable value, using intermediate storage to ensure alignment when serializing argument. Note that this shouldn't have any pointers, since serialized pointers won't usually be valid when loaded later. Also, the storable type shouldn't have any gaps (unassigned bytes); uninitialized bytes may interfere with structure sharing in VCache.
putVarNat :: Integer -> VPut () Source
Put an arbitrary non-negative integer in varint
format associated
with Google protocol buffers. This takes one byte for values 0..127,
two bytes for 128..16k, etc.. Will fail if given a negative argument.
putVarInt :: Integer -> VPut () Source
Put an arbitrary integer in a varint
format associated with
Google protocol buffers with zigzag encoding of negative numbers.
This takes one byte for values -64..63, two bytes for -8k..8k,
three bytes for -1M..1M, etc.. Very useful if most numbers are
near 0.
reserve :: Int -> VPut () Source
Ensure that at least N bytes are available for storage without growing the underlying buffer. Use this before unsafePutWord8 and similar operations. If the buffer must grow, it will grow exponentially to ensure amortized constant allocation costs.
unsafePutWord8 :: Word8 -> VPut () Source
Store an 8 bit word *assuming* enough space has been reserved.
This can be used safely together with reserve
.
putByteString :: ByteString -> VPut () Source
Put the contents of a bytestring directly. Unlike the put
method for
bytestrings, this does not include size information; just raw bytes.
putByteStringLazy :: ByteString -> VPut () Source
Put contents of a lazy bytestring directly. Unlike the put
method for
bytestrings, this does not include size information; just raw bytes.
peekBufferSize :: VPut Int Source
Obtain the number of bytes output by this VPut effort so far. This might be useful if you're breaking data structures up by their serialization sizes. This does not include VRefs or PVars, only raw binary data. See also peekChildCount.
peekChildCount :: VPut Int Source
Obtain the total count of VRefs and PVars in the VPut buffer.