proto-lens-0.5.1.0: A lens-based implementation of protocol buffers in Haskell.

Data.ProtoLens.Encoding.Bytes

Description

Utility functions for parsing and encoding individual types.

Synopsis

# Running encodings

data Parser a Source #

A monad for parsing an input buffer.

Instances
 Source # Instance detailsDefined in Data.ProtoLens.Encoding.Parser.Internal Methods(>>=) :: Parser a -> (a -> Parser b) -> Parser b #(>>) :: Parser a -> Parser b -> Parser b #return :: a -> Parser a #fail :: String -> Parser a # Source # Instance detailsDefined in Data.ProtoLens.Encoding.Parser.Internal Methodsfmap :: (a -> b) -> Parser a -> Parser b #(<\$) :: a -> Parser b -> Parser a # Source # Instance detailsDefined in Data.ProtoLens.Encoding.Parser.Internal Methodspure :: a -> Parser a #(<*>) :: Parser (a -> b) -> Parser a -> Parser b #liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c #(*>) :: Parser a -> Parser b -> Parser b #(<*) :: Parser a -> Parser b -> Parser a #

data Builder #

Builders denote sequences of bytes. They are Monoids where mempty is the zero-length sequence and mappend is concatenation, which runs in O(1).

Instances
 Instance detailsDefined in Data.ByteString.Builder.Internal Methodsstimes :: Integral b => b -> Builder -> Builder # Instance detailsDefined in Data.ByteString.Builder.Internal Methodsmconcat :: [Builder] -> Builder #

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.

isolate :: Int -> Parser a -> Parser a Source #

Run the given parsing action as if there are only len bytes remaining. That is, once len bytes have been consumed, atEnd will return True and other actions like getWord8 will act like there is no input remaining.

Fails the parse if given a negative length.

Constructs a strict ByteString from the given Builder.

# Bytestrings

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.

Emit a given ByteString.

# Other utilities

Returns True if there is no more input left to consume.

(<?>) :: Parser a -> String -> Parser a Source #

If the parser fails, prepend an error message.

foldMapBuilder :: Vector v a => (a -> Builder) -> v a -> Builder Source #

Loop over the elements of a vector and concatenate the resulting Builders.

This function has been hand-tuned to perform better than a naive implementation using, e.g., Vector.foldr or a manual loop.