Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data VGet a
- getVRef :: VCacheable a => VGet (VRef a)
- getPVar :: VCacheable a => VGet (PVar a)
- getVSpace :: VGet VSpace
- getWord8 :: VGet Word8
- getWord16le :: VGet Word16
- getWord16be :: VGet Word16
- getWord32le :: VGet Word32
- getWord32be :: VGet Word32
- getWord64le :: VGet Word64
- getWord64be :: VGet Word64
- getStorable :: Storable a => VGet a
- getVarNat :: VGet Integer
- getVarInt :: VGet Integer
- getByteString :: Int -> VGet ByteString
- getByteStringLazy :: Int -> VGet ByteString
- getc :: VGet Char
- withBytes :: Int -> (Ptr Word8 -> IO a) -> VGet a
- isolate :: Int -> Int -> VGet a -> VGet a
- label :: ShowS -> VGet a -> VGet a
- lookAhead :: VGet a -> VGet a
- lookAheadM :: VGet (Maybe a) -> VGet (Maybe a)
- lookAheadE :: VGet (Either a b) -> VGet (Either a b)
- isEmpty :: VGet Bool
Documentation
VGet is a parser combinator monad for VCache. Unlike pure binary parsers, VGet supports reads from a stack of VRefs and PVars to directly model structured data.
Prim Readers
getVRef :: VCacheable a => VGet (VRef a) Source
Load a VRef, just the reference rather than the content. User must know the type of the value, since getVRef is essentially a typecast. VRef content is not read until deref.
All instances of a VRef with the same type and address will share the same cache.
getPVar :: VCacheable a => VGet (PVar a) Source
Load a PVar, just the variable. Content is loaded lazily on first read, then kept in memory until the PVar is GC'd. Unlike other Haskell variables, PVars can be serialized to the VCache address space. All PVars for a specific address are collapsed, using the same TVar.
Developers must know the type of the PVar, since getPVar will cast to any cacheable type. A runtime error is raised only if you attempt to load the same PVar address with two different types.
getVSpace :: VGet VSpace Source
Obtain the VSpace associated with content being read. Does not consume any data.
getWord16le :: VGet Word16 Source
Read words of size 16, 32, or 64 in little-endian or big-endian.
getWord16be :: VGet Word16 Source
Read words of size 16, 32, or 64 in little-endian or big-endian.
getStorable :: Storable a => VGet a Source
Read a Storable value. In this case, the content should be bytes only, since pointers aren't really meaningful when persisted. Data is copied to an intermediate structure via alloca to avoid alignment issues.
getVarNat :: VGet Integer Source
Get a non-negative number represented in the Google protocol
buffers varint
encoding, e.g. as produced by putVarNat
.
getVarInt :: VGet Integer Source
Get an integer represented in the Google protocol buffers zigzag
varint
encoding, e.g. as produced by putVarInt
.
getByteString :: Int -> VGet ByteString Source
Load a number of bytes from the underlying object. A copy is performed in this case (typically no copy is performed by VGet, but the underlying pointer is ephemeral, becoming invalid after the current read transaction). Fails if not enough data. O(N)
getByteStringLazy :: Int -> VGet ByteString Source
Get a lazy bytestring. (Simple wrapper on strict bytestring.)
Get a character from UTF-8 format. Assumes a valid encoding. (In case of invalid encoding, arbitrary characters may be returned.)
zero copy access
withBytes :: Int -> (Ptr Word8 -> IO a) -> VGet a Source
Access a given number of bytes without copying them. These bytes are read-only, and are considered to be consumed upon returning. The pointer should be considered invalid after returning from the withBytes computation.
Parser Combinators
isolate :: Int -> Int -> VGet a -> VGet a Source
isolate a parser to a subset of bytes and value references. The child parser must process its entire input (all bytes and values) or will fail. If there is not enough available input to isolate, this operation will fail.
isolate nBytes nVRefs operation
label :: ShowS -> VGet a -> VGet a Source
label will modify the error message returned from the argument operation; it can help contextualize parse errors.
lookAheadM :: VGet (Maybe a) -> VGet (Maybe a) Source
lookAheadM will consume input only if it returns `Just a`.