vcache-0.2.3: large, persistent, memcached values and structure sharing for Haskell

Safe HaskellNone
LanguageHaskell2010

Database.VCache.VPut

Contents

Synopsis

Documentation

data VPut a Source

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.

putWord8 :: Word8 -> VPut () Source

Store an 8 bit word.

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.

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.

putc :: Char -> VPut () Source

Put a character in UTF-8 format.

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.