Protobuf.Library
- Package
- purescript-protobuf
- Repository
- xc-jp/purescript-protobuf
Module for types to be imported by a progam which uses protobuf.
#parseAnyMessage Source
parseAnyMessage :: ParserT DataView Effect (Array UnknownField)Parse one Protobuf message without the .proto definition.
If you have a DataView which you know contains one Protobuf message
but you don’t have the compile-time .proto definition for the message,
you can use this function to parse the message.
If one of the UnknownFields is a LenDel field, and you know
from the FieldNumber that
the field should be a nested message field, then you can
try to recursively parseAnyMessage on the LenDel field value.
#parseAnyField Source
parseAnyField :: ParserT DataView Effect UnknownFieldParse one Protobuf field without the .proto definition.
Re-exports from Parsing
#liftMaybe Source
liftMaybe :: forall s m a. Monad m => (Unit -> String) -> Maybe a -> ParserT s m aLift a Maybe a computation into a ParserT, with a note for
the ParseError message in case of Nothing.
Consumes no parsing input, does not change the parser state at all.
If the Maybe computation is Nothing, then this will fail in the
ParserT monad with the given error message String at the current input
Position.
This is a “validation” function, for when we want to produce some data from the parsing input or fail at the current parsing position if that’s impossible.
For example, parse an integer
BoundedEnum
code and validate it by turning it
into a MyEnum. Use tryRethrow to position the parse error at the
beginning of the integer in the input String if the toEnum fails.
runParser "3" do
myenum :: MyEnum <- tryRethrow do
x <- intDecimal
liftMaybe (\_ -> "Bad MyEnum " <> show x) $ toEnum x
#liftExceptT Source
liftExceptT :: forall s m a. Monad m => ExceptT String m a -> ParserT s m aLift an ExceptT String m a computation into a ParserT.
Consumes no parsing input, does not change the parser state at all.
If the ExceptT computation is Left String, then this will fail in the
ParserT monad at the current input Position.
This is a “validation” function, for when we want to produce some data from the parsing input or fail at the current parsing position if that’s impossible.
#liftEither Source
liftEither :: forall s m a. Monad m => Either String a -> ParserT s m aLift an Either String a computation into a ParserT.
Consumes no parsing input, does not change the parser state at all.
If the Either computation is Left String, then this will fail in the
ParserT monad at the current input Position.
This is a “validation” function, for when we want to produce some data from the parsing input or fail at the current parsing position if that’s impossible.
Re-exports from Protobuf.Internal.Common
#FieldNumber Source
type FieldNumber = UInt#Bytes Source
newtype BytesRepresentation of a bytes Scalar Value Type field.
On a message which has been decoded,
The wrapped DataBuff will usually be a DataView.
In that case, the DataView is a view into the
received message I/O buffer.
For messages which you intend to encode,
You may set the DataBuff to DataView or ArrayBuffer,
whichever seems best.
The ArrayBuffer and DataView are mutable, so be careful not to mutate
them if anything might read them again. Here we trade off typechecker
guarantees for implementation simplicity.
Constructors
Instances
#toDefault Source
toDefault :: forall a. Default a => Maybe a -> aTurns Nothing into a “default” (zero) value.
The Protobuf spec requires that a no presence field set to its “default” (zero) value must not be serialized to the wire.
When receiving messages we can use this function to interpret a missing no presence field as a “default” value.
Re-exports from Protobuf.Internal.Runtime
#UnknownField Source
data UnknownFieldA message field value from an unknown .proto definition.
See Message Structure for an explanation.
UnknownVarIntUseProtobuf.Internal.Decode.decodeZigzag64to interpret this as a signed integer.UnknownLenDelholds a variable-lengthBytes.UnknownBits64must holdBytesof length 8.UnknownBits32must holdBytesof length 4.
See the modules Protobuf.Internal.Encode
and Protobuf.Internal.Decode for ways to operate on the Bytes.
Constructors
UnknownVarInt FieldNumber UInt64UnknownBits64 FieldNumber BytesUnknownLenDel FieldNumber BytesUnknownBits32 FieldNumber Bytes
Zero-length