proto-lens-0.7.1.4: A lens-based implementation of protocol buffers in Haskell.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Instances details
MonadFail Parser Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Parser.Internal

Methods

fail :: String -> Parser a #

Applicative Parser Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Parser.Internal

Methods

pure :: 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 #

Functor Parser Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Parser.Internal

Methods

fmap :: (a -> b) -> Parser a -> Parser b #

(<$) :: a -> Parser b -> Parser a #

Monad Parser Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Parser.Internal

Methods

(>>=) :: Parser a -> (a -> Parser b) -> Parser b #

(>>) :: Parser a -> Parser b -> Parser b #

return :: a -> 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

Instances details
Monoid Builder 
Instance details

Defined in Data.ByteString.Builder.Internal

Semigroup Builder 
Instance details

Defined in Data.ByteString.Builder.Internal

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.

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.

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.

Text

Integral types

Floating-point types

Signed types

Other utilities

atEnd :: Parser Bool Source #

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.