Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utility functions for parsing and encoding individual types.
Synopsis
- data Parser a
- data Builder
- runParser :: Parser a -> ByteString -> Either String a
- isolate :: Int -> Parser a -> Parser a
- runBuilder :: Builder -> ByteString
- getBytes :: Int -> Parser ByteString
- putBytes :: ByteString -> Builder
- getVarInt :: Parser Word64
- getVarIntH :: Handle -> ExceptT String IO Word64
- putVarInt :: Word64 -> Builder
- getFixed32 :: Parser Word32
- getFixed64 :: Parser Word64
- putFixed32 :: Word32 -> Builder
- putFixed64 :: Word64 -> Builder
- wordToFloat :: Word32 -> Float
- wordToDouble :: Word64 -> Double
- floatToWord :: Float -> Word32
- doubleToWord :: Double -> Word64
- signedInt32ToWord :: Int32 -> Word32
- wordToSignedInt32 :: Word32 -> Int32
- signedInt64ToWord :: Int64 -> Word64
- wordToSignedInt64 :: Word64 -> Int64
- atEnd :: Parser Bool
- runEither :: Either String a -> Parser a
- (<?>) :: Parser a -> String -> Parser a
- foldMapBuilder :: Vector v a => (a -> Builder) -> v a -> Builder
Running encodings
A monad for parsing an input buffer.
Builder
s denote sequences of bytes.
They are Monoid
s where
mempty
is the zero-length sequence and
mappend
is concatenation, which runs in O(1).
runParser :: Parser a -> ByteString -> Either String a Source #
Evaluates a parser on the given input.
If the parser does not consume all of the input, the rest of the
input is discarded and the parser still succeeds. Parsers may use
atEnd
to detect whether they are at the end of the input.
Values returned from actions in this monad will not hold onto the original ByteString, but rather make immutable copies of subsets of its bytes.
runBuilder :: Builder -> ByteString Source #
Constructs a strict ByteString
from the given Builder
.
Bytestrings
getBytes :: Int -> Parser ByteString Source #
Parse a sequence of zero or more bytes of the given length.
The new ByteString is an immutable copy of the bytes in the input
and will be managed separately on the Haskell heap from the original
input ByteString
.
Fails the parse if given a negative length.
putBytes :: ByteString -> Builder Source #
Emit a given ByteString
.
Integral types
putFixed32 :: Word32 -> Builder Source #
putFixed64 :: Word64 -> Builder Source #
Floating-point types
wordToFloat :: Word32 -> Float Source #
wordToDouble :: Word64 -> Double Source #
floatToWord :: Float -> Word32 Source #
doubleToWord :: Double -> Word64 Source #
Signed types
signedInt32ToWord :: Int32 -> Word32 Source #
wordToSignedInt32 :: Word32 -> Int32 Source #
signedInt64ToWord :: Int64 -> Word64 Source #
wordToSignedInt64 :: Word64 -> Int64 Source #