proto-lens-0.4.0.0: A lens-based implementation of protocol buffers in Haskell.

Safe HaskellNone
LanguageHaskell2010

Data.ProtoLens.Message

Contents

Description

Datatypes for reflection of protocol buffer messages.

Synopsis

Reflection of Messages

class Message msg where Source #

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.

Minimal complete definition

messageName, defMessage, fieldsByTag, unknownFields

Methods

messageName :: Proxy msg -> Text Source #

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

defMessage :: msg Source #

A message with all fields set to their default values.

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

fieldsByTag :: Map Tag (FieldDescriptor msg) Source #

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

fieldsByTextFormatName :: Map String (FieldDescriptor msg) Source #

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 Source #

Access the unknown fields of a Message.

Instances
Message UninterpretedOption'NamePart Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message UninterpretedOption Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message SourceCodeInfo'Location Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message SourceCodeInfo Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message ServiceOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message ServiceDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message OneofOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message OneofDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message MethodOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message MethodDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message MessageOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message GeneratedCodeInfo'Annotation Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message GeneratedCodeInfo Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message FileOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message FileDescriptorSet Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message FileDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message FieldOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message FieldDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message ExtensionRangeOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message EnumValueOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message EnumValueDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message EnumOptions Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message EnumDescriptorProto'EnumReservedRange Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message EnumDescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message DescriptorProto'ReservedRange Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message DescriptorProto'ExtensionRange Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message DescriptorProto Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Message Version Source # 
Instance details

Defined in Proto.Google.Protobuf.Compiler.Plugin

Message CodeGeneratorResponse'File Source # 
Instance details

Defined in Proto.Google.Protobuf.Compiler.Plugin

Message CodeGeneratorResponse Source # 
Instance details

Defined in Proto.Google.Protobuf.Compiler.Plugin

Message CodeGeneratorRequest Source # 
Instance details

Defined in Proto.Google.Protobuf.Compiler.Plugin

newtype Tag Source #

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

Constructors

Tag 

Fields

Instances
Eq Tag Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Wire

Methods

(==) :: Tag -> Tag -> Bool #

(/=) :: Tag -> Tag -> Bool #

Num Tag Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Wire

Methods

(+) :: Tag -> Tag -> Tag #

(-) :: Tag -> Tag -> Tag #

(*) :: Tag -> Tag -> Tag #

negate :: Tag -> Tag #

abs :: Tag -> Tag #

signum :: Tag -> Tag #

fromInteger :: Integer -> Tag #

Ord Tag Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Wire

Methods

compare :: Tag -> Tag -> Ordering #

(<) :: Tag -> Tag -> Bool #

(<=) :: Tag -> Tag -> Bool #

(>) :: Tag -> Tag -> Bool #

(>=) :: Tag -> Tag -> Bool #

max :: Tag -> Tag -> Tag #

min :: Tag -> Tag -> Tag #

Show Tag Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Wire

Methods

showsPrec :: Int -> Tag -> ShowS #

show :: Tag -> String #

showList :: [Tag] -> ShowS #

NFData Tag Source # 
Instance details

Defined in Data.ProtoLens.Encoding.Wire

Methods

rnf :: Tag -> () #

data FieldDescriptor msg where Source #

A description of a specific field of a protocol buffer.

The String parameter is the name of the field from the .proto file, as used in TextFormat, with the same behavior for groups as fieldsByTextFormatName. (Haddock doesn't support per-argument docs for GADTs.)

Constructors

FieldDescriptor :: String -> FieldTypeDescriptor value -> FieldAccessor msg value -> FieldDescriptor msg 

fieldDescriptorName :: FieldDescriptor msg -> String Source #

The original name of the field in the .proto file.

isRequired :: FieldDescriptor msg -> Bool Source #

Whether the given field is required. Specifically, if its FieldAccessor is a Required PlainField.

data FieldAccessor msg value where Source #

A Lens for accessing the value of an individual field in a protocol buffer message.

Constructors

PlainField :: WireDefault value -> Lens' msg value -> FieldAccessor msg value 
OptionalField :: Lens' msg (Maybe value) -> FieldAccessor msg value 
RepeatedField :: Packing -> Lens' msg [value] -> FieldAccessor msg value 
MapField :: (Ord key, Message entry) => Lens' entry key -> Lens' entry value -> Lens' msg (Map key value) -> FieldAccessor msg entry 

data WireDefault value where Source #

The default value (if any) for a PlainField on the wire.

Constructors

Required :: WireDefault value 
Optional :: (FieldDefault value, Eq value) => WireDefault value 

data Packing Source #

How a given repeated field is transmitted on the wire format.

Constructors

Packed 
Unpacked 

data FieldTypeDescriptor value where Source #

A description of the type of a given field value.

Instances
Show (FieldTypeDescriptor value) Source # 
Instance details

Defined in Data.ProtoLens.Message

class FieldDefault value where Source #

A proto3 field type with an implicit default value.

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

Minimal complete definition

fieldDefault

Methods

fieldDefault :: value Source #

Instances
FieldDefault Bool Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Double Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Float Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Int32 Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Int64 Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Word32 Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Word64 Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault ByteString Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault Text Source # 
Instance details

Defined in Data.ProtoLens.Message

FieldDefault MethodOptions'IdempotencyLevel Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

FieldDefault FileOptions'OptimizeMode Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

FieldDefault FieldOptions'JSType Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

FieldDefault FieldOptions'CType Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

FieldDefault FieldDescriptorProto'Type Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

FieldDefault FieldDescriptorProto'Label Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

class (Enum a, Bounded a) => MessageEnum a where Source #

A class for protocol buffer enums that enables safe decoding.

Minimal complete definition

maybeToEnum, showEnum, readEnum

Methods

maybeToEnum :: Int -> Maybe a Source #

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

showEnum :: a -> String Source #

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 Source #

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

Instances
MessageEnum MethodOptions'IdempotencyLevel Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

MessageEnum FileOptions'OptimizeMode Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

MessageEnum FieldOptions'JSType Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

MessageEnum FieldOptions'CType Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

MessageEnum FieldDescriptorProto'Type Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

MessageEnum FieldDescriptorProto'Label Source # 
Instance details

Defined in Proto.Google.Protobuf.Descriptor

Building protocol buffers

build :: Message a => (a -> a) -> a Source #

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

data Registry Source #

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 TextFormat

register :: forall msg. Message msg => Proxy msg -> Registry Source #

Build a Registry containing a single proto type.

Example: > register (Proxy :: Proxy Proto.My.Proto.Type)

lookupRegistered :: Text -> Registry -> Maybe SomeMessageType Source #

Look up a message type by name (e.g., "type.googleapis.com/google.protobuf.FloatValue"). The URL corresponds to the field google.protobuf.Any.type_url.

data SomeMessageType where Source #

Constructors

SomeMessageType :: Message msg => Proxy msg -> SomeMessageType 

Any messages

Utilities for constructing protocol buffer lenses

maybeLens :: b -> Lens' (Maybe b) b Source #

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

reverseRepeatedFields :: Map k (FieldDescriptor msg) -> msg -> msg Source #

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

discardUnknownFields :: Message msg => msg -> msg Source #