Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Encode data with protobuf. Under the hood, this uses catenable byte
sequences, meaning that a large number of small ByteArray
s are allocated
during encoding. That makes this a simple but low-performance solution.
To prevent incorrect use, Builder
is parameterized by Value
. This
distinguishes encodings of primitives from encodings of sequences of
key-value pairs. The functions message
and pair
are used to move
between these two domains.
Synopsis
- data Builder :: Value -> Type where
- data WireType
- data Value
- run :: Builder v -> Bytes
- variableWord8 :: Word8 -> Builder ('Primitive 'BitsVariable)
- variableWord16 :: Word16 -> Builder ('Primitive 'BitsVariable)
- variableWord32 :: Word32 -> Builder ('Primitive 'BitsVariable)
- variableWord64 :: Word64 -> Builder ('Primitive 'BitsVariable)
- sint64 :: Int64 -> Builder ('Primitive 'BitsVariable)
- int64 :: Int64 -> Builder ('Primitive 'BitsVariable)
- sint32 :: Int32 -> Builder ('Primitive 'BitsVariable)
- int32 :: Int32 -> Builder ('Primitive 'BitsVariable)
- fixed32 :: Word32 -> Builder ('Primitive 'BitsFixed32)
- fixed64 :: Word64 -> Builder ('Primitive 'BitsFixed64)
- double :: Double -> Builder ('Primitive 'BitsFixed64)
- message :: Builder 'Pairs -> Builder ('Primitive 'Bytes)
- pair :: forall (ty :: WireType). HasWireTypeNumber ty => Word32 -> Builder ('Primitive ty) -> Builder 'Pairs
- shortText :: ShortText -> Builder ('Primitive 'Bytes)
- shortByteString :: ShortByteString -> Builder ('Primitive 'Bytes)
Documentation
data Builder :: Value -> Type where Source #
A protobuf object builder. The data constructor is exposed, but it is unsafe to use it.
Note that Builder 'Pairs
has Semigroup
and Monoid
instances.
This is an important part of the interface.
Either a primitive type (a wire type) or a collector of encoded key-value pairs.
Variable Length
variableWord8 :: Word8 -> Builder ('Primitive 'BitsVariable) Source #
variableWord16 :: Word16 -> Builder ('Primitive 'BitsVariable) Source #
variableWord32 :: Word32 -> Builder ('Primitive 'BitsVariable) Source #
variableWord64 :: Word64 -> Builder ('Primitive 'BitsVariable) Source #
Fixed Length 32
Fixed Length 64
Messages
Length-Delimited
shortByteString :: ShortByteString -> Builder ('Primitive 'Bytes) Source #