Safe Haskell | None |
---|---|
Language | Haskell2010 |
See the Proto3.Wire.Tutorial module.
Synopsis
- newtype FieldNumber = FieldNumber {}
- fieldNumber :: Word64 -> FieldNumber
- at :: Parser RawField a -> FieldNumber -> Parser RawMessage a
- oneof :: a -> [(FieldNumber, Parser RawField a)] -> Parser RawMessage a
- one :: Parser RawPrimitive a -> a -> Parser RawField a
- repeated :: Parser RawPrimitive a -> Parser RawField [a]
Message Structure
newtype FieldNumber Source #
A FieldNumber
identifies a field inside a protobufs message.
This library makes no attempt to generate these automatically, or even make sure that field numbers are provided in increasing order. Such things are left to other, higher-level libraries.
Instances
fieldNumber :: Word64 -> FieldNumber Source #
Create a FieldNumber
given the (one-based) integer which would label
the field in the corresponding .proto file.
Decoding Messages
at :: Parser RawField a -> FieldNumber -> Parser RawMessage a Source #
Turn a field parser into a message parser, by specifying the FieldNumber
.
This parser will fail if the specified FieldNumber
is not present.
For example:
one float `at` fieldNumber 1 :: Parser RawMessage (Maybe Float)
:: a | The value to produce when no field numbers belonging to the oneof are present in the input |
-> [(FieldNumber, Parser RawField a)] | Left-biased oneof field parsers, one per field number belonging to the oneof |
-> Parser RawMessage a |
Try to parse different field numbers with their respective parsers. This is used to express alternative between possible fields of a oneof.
TODO: contrary to the protobuf spec, in the case of multiple fields number matching the oneof content, the choice of field is biased to the order of the list, instead of being biased to the last field of group of field number in the oneof. This is related to the Map used for input that preserve order across multiple invocation of the same field, but not across a group of field.
one :: Parser RawPrimitive a -> a -> Parser RawField a Source #
This turns a primitive parser into a field parser by keeping the last received value, or return a default value if the field number is missing.
Used to ensure that we return the last value with the given field number in the message, in compliance with the protobuf standard.
The protocol buffers specification specifies default values for primitive types.
For example:
one float 0 :: Parser RawField Float
repeated :: Parser RawPrimitive a -> Parser RawField [a] Source #
Parse a repeated field, or an unpacked collection of primitives.
Each value with the identified FieldNumber
will be passed to the parser
in the first argument, to be converted into a value of the correct type.
For example, to parse a packed collection of uint32
values:
repeated uint32 :: Parser RawField ([Word32])
or to parse a collection of embedded messages:
repeated . embedded' :: Parser RawMessage a -> Parser RawField ([a])