Module

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 UnknownField

Parse 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 a

Lift 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 a

Lift 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 a

Lift 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

#Bytes Source

newtype Bytes

Representation 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

#Default Source

class Default a 

In Protobuf, zero values are “default values” and have special semantics.

Instances

#toDefault Source

toDefault :: forall a. Default a => Maybe a -> a

Turns 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.

#label Source

label :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a

If parsing fails inside this labelled context, then prepend the String to the error String in the ParseError. Use this to establish context for parsing failure error messages.

Re-exports from Protobuf.Internal.Runtime

#UnknownField Source

data UnknownField

A message field value from an unknown .proto definition.

See Message Structure for an explanation.

  • UnknownVarInt Use Protobuf.Internal.Decode.decodeZigzag64 to interpret this as a signed integer.
  • UnknownLenDel holds a variable-length Bytes.
  • UnknownBits64 must hold Bytes of length 8.
  • UnknownBits32 must hold Bytes of length 4.

See the modules Protobuf.Internal.Encode and Protobuf.Internal.Decode for ways to operate on the Bytes.

Constructors

Instances