HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleproto-lens-0.7.1.5Haskell2010

Data.ProtoLens.Message

Datatypes for reflection of protocol buffer messages.

  • 13 types
  • 3 classes
  • 10 values

Reflection of Messages

14 declarations
classclass Message msg where
#

Every protocol buffer is an instance of Message. This class enables serialization by providing reflection of all of the fields that may be used by this type.

Methods

  • messageName :: Proxy msg -> Text

    A unique identifier for this type, of the format "packagename.messagename".

  • packedMessageDescriptor :: Proxy msg -> ByteString

    The serialized protobuffer message descriptor for this type.

    For a friendlier version which returns the actual descriptor type, use Data.ProtoLens.Descriptor.messageDescriptor from the proto-lens-protobuf-types package.

  • packedFileDescriptor :: Proxy msg -> ByteString

    The serialized protobuffer file message descriptor containing this type.

    For a friendlier version which returns the actual file descriptor type, use Data.ProtoLens.Descriptor.fileDescriptor from the proto-lens-protobuf-types package.

  • defMessage :: msg

    A message with all fields set to their default values.

    Satisfies encodeMessage defMessage == "" and decodeMessage "" == Right defMessage.

  • fieldsByTag :: Map Tag (FieldDescriptor msg)

    The fields of the proto, indexed by their (integer) tag.

  • fieldsByTextFormatName :: Map String (FieldDescriptor msg)

    This map is keyed by the name of the field used for text format protos. This is just the field name for every field except for group fields, which use their Message type name in text protos instead of their field name. For example, "optional group Foo" has the field name "foo" but in this map it is stored with the key Foo.

  • unknownFields :: Lens' msg FieldSet

    Access the unknown fields of a Message.

  • parseMessage :: Parser msg

    Decode a message value.

    See also the functions in Data.ProtoLens.Encoding.

  • buildMessage :: msg -> Builder

    Encode a message value.

    See also the functions in Data.ProtoLens.Encoding.

newtypenewtype Tag
#

A tag that identifies a particular field of the message when converting to/from the wire format.

Constructors

Instances5Eq, Num, Ord, Show, NFData
  • Eq TagDefined in proto-lens-0.7.1.5 · Data.ProtoLens.Encoding.Wire
  • Num TagDefined in proto-lens-0.7.1.5 · Data.ProtoLens.Encoding.Wire
  • Ord TagDefined in proto-lens-0.7.1.5 · Data.ProtoLens.Encoding.Wire
  • Show TagDefined in proto-lens-0.7.1.5 · Data.ProtoLens.Encoding.Wire
  • NFData TagDefined in proto-lens-0.7.1.5 · Data.ProtoLens.Encoding.Wire
datadata ScalarField t where
#
Instances1Show
  • Show (ScalarField value)Defined in proto-lens-0.7.1.5 · Data.ProtoLens.Message
classclass FieldDefault value where
#

A proto3 field type with an implicit default value.

This is distinct from, say, Data.Default to avoid orphan instances, and because Bool doesn't necessarily have a good Default instance for general usage.

Methods

Instances9FieldDefault, …
classclass (Enum a, Bounded a) => MessageEnum a where
#

A class for protocol buffer enums that enables safe decoding.

Methods

  • maybeToEnum :: Int -> Maybe a

    Convert the given Int to an enum value. Returns Nothing if no corresponding value was defined in the .proto file.

  • showEnum :: a -> String

    Get the name of this enum as defined in the .proto file. Used for the human-readable output in Data.ProtoLens.TextFormat.

  • readEnum :: String -> Maybe a

    Convert the given String to an enum value. Returns Nothing if no corresponding value was defined in the .proto file.

Constructing protocol buffers

1 declaration
valuebuild :: Message a => (a -> a) -> a
#

Utility function for building a message from a default value. For example:

instance Default A where ...
x, y :: Lens' A Int
m :: A
m = build ((x .~ 5) . (y .~ 7))

Proto registries

4 declarations
newtypenewtype Registry
#

A set of known message types. Can help encode/decode protobufs containing Data.ProtoLens.Any values in a more human-readable text format.

Registries can be combined using their Monoid instance.

See the withRegistry functions in Data.ProtoLens.TextFormat

Instances2Semigroup, Monoid

Any messages

2 declarations

Utilities for constructing protocol buffer lenses

1 declaration
valuemaybeLens :: b -> Lens' (Maybe b) b
#

A helper lens for accessing optional fields. This is used as part of code generation, and should generally not be needed explicitly.

Note that maybeLens does not satisfy the lens laws, which expect that set l (view l x) == x. For example,

set (maybeLens 'a') (view (maybeLens 'a') Nothing) == Just 'a'

However, this is the behavior generally expected by users, and only matters if we're explicitly checking whether a field is set.

Internal utilities for parsing protocol buffers

1 declaration
valuereverseRepeatedFields :: Map k (FieldDescriptor msg) -> msg -> msg
#

Reverse every repeated (list) field in the message.

During parsing, we store fields temporarily in reverse order, and then un-reverse them at the end. This helps avoid the quadratic blowup from repeatedly appending to lists. TODO: Benchmark how much of a problem this is in practice, and whether it's still a net win for small protobufs. If we decide on it more permanently, consider moving it to a more internal module.

Unknown fields

3 declarations