| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Proto3.Suite.Form
Description
Type-Level Format Information
Use compile-proto-file --typeLevelFormat ... to instantiate these type families to
provide type-level information that may be used to define custom encoders and decoders.
WARNING: This module is experimental and breaking changes may occur much more frequently than in the other modules of this package, perhaps even in patch releases.
Synopsis
- type family NamesOf message :: [Symbol]
- type family NumberOf message (name :: Symbol) :: Nat
- type family ProtoTypeOf message (name :: Symbol) :: ProtoType
- type family OneOfOf message (name :: Symbol) :: Symbol
- type family CardinalityOf message (name :: Symbol) :: Cardinality
- type FieldNotFound message (name :: Symbol) = (('Text "Field " ':<>: 'ShowType name) ':<>: 'Text " not found in message:") ':$$: 'ShowType message
- type FieldOrOneOfNotFound message (name :: Symbol) = (('Text "Field or oneof " ':<>: 'ShowType name) ':<>: 'Text " not found in message:") ':$$: 'ShowType message
- data Packing
- data Cardinality
- data ProtoType
- data Association (key :: ProtoType) (value :: ProtoType)
- type family CardinalityOfMapped (protoType :: ProtoType) :: Cardinality where ...
- data Wrapper (protoType :: ProtoType)
- type family RecoverCardinality haskellType :: Cardinality where ...
- type family RecoverProtoType haskellType :: ProtoType where ...
- class (RecoverCardinality haskellType ~ cardinality, RecoverProtoType haskellType ~ protoType) => MessageFieldType (cardinality :: Cardinality) (protoType :: ProtoType) haskellType
- type family OptionalMessageFieldType m haskellType where ...
- type family RepeatedMessageFieldType m haskellType where ...
Documentation
type family NamesOf message :: [Symbol] Source #
Returns the names of the fields within a given type of message.
The names appear in increasing order of field number, in case that helps type-level search algorithms, though at present it is likely that there is no benefit other than ensuring that declaration order is irrelevant.
Note that the names of fields and oneofs must be unique within their shared namespace (see https://protobuf.dev/reference/protobuf/proto3-spec/#message_definition).
Instances
| type NamesOf (Wrapper protoType) Source # | |
Defined in Proto3.Suite.Form | |
| type NamesOf (Association _1 _2) Source # | |
Defined in Proto3.Suite.Form | |
type family NumberOf message (name :: Symbol) :: Nat Source #
In the context of a message type, maps its field names to their numbers.
Instances
| type NumberOf (Wrapper protoType) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type NumberOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type NumberOf (Association _1 _2) "value" Source # | |
Defined in Proto3.Suite.Form | |
type family ProtoTypeOf message (name :: Symbol) :: ProtoType Source #
In the context of a message type, maps the name of every field to its protobuf type.
Instances
| type ProtoTypeOf (Wrapper protoType) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type ProtoTypeOf (Association _1 value) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type ProtoTypeOf (Association key _1) "key" Source # | |
Defined in Proto3.Suite.Form | |
type family OneOfOf message (name :: Symbol) :: Symbol Source #
In the context of a message type, maps the name of every field to the name
of its containing oneof, or to "" if that field is not part of a oneof.
Also maps the name of every oneof in the message to itself.
Instances
| type OneOfOf (Wrapper protoType) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type OneOfOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type OneOfOf (Association _1 _2) "value" Source # | |
Defined in Proto3.Suite.Form | |
type family CardinalityOf message (name :: Symbol) :: Cardinality Source #
In the context of a message type, maps the name
of every field and oneof to its Cardinality.
(Every oneof in the message is mapped to OneOf,
as are those fields that are within oneofs.)
Instances
| type CardinalityOf (Wrapper protoType) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type CardinalityOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type CardinalityOf (Association _1 value) "value" Source # | |
Defined in Proto3.Suite.Form | |
type FieldNotFound message (name :: Symbol) = (('Text "Field " ':<>: 'ShowType name) ':<>: 'Text " not found in message:") ':$$: 'ShowType message Source #
A compilation error message for when the given message does not contain a field with the given name.
type FieldOrOneOfNotFound message (name :: Symbol) = (('Text "Field or oneof " ':<>: 'ShowType name) ':<>: 'Text " not found in message:") ':$$: 'ShowType message Source #
A compilation error message for when the given message does not contain a field or oneof with the given name.
The packing of field that is repeated or is a map. Every
encoding appends and element, and omission means zero elements.
data Cardinality Source #
Expresses how many values we expect a field to contain, what it means when its
encoding is omitted, and if it is repeated, whether or not packing is preferred.
Each data constructor is chosen in such a way that it implies how many
values are expected as arguments to field.
This choice simplifies instantiation of type classes.
Constructors
| Implicit | We expect exactly one value for this field, though the default value is expressed by omission in the binary format. Such a field is never "unset". In the terminology of the proto3 specification, the field is
"singular" and is neither Put another way: the field is not declared
|
| Optional | The field is singular and has optional field presence. That is,
That is, it is a non-
|
| Repeated Packing | The field is
|
The type of a message field, but when the field is repeated, this is the element type.
Design Note: We do not use the same Haskell types recognized
by MessageField because there more than
one such type corresponds to protobuf type string.
But see RecoverProtoType.
Constructors
| Int32 | |
| Int64 | |
| SInt32 | |
| SInt64 | |
| UInt32 | |
| UInt64 | |
| Fixed32 | |
| Fixed64 | |
| SFixed32 | |
| SFixed64 | |
| String | |
| Bytes | |
| Bool | |
| Float | |
| Double | |
| Enumeration Type | The field is the type created by code generation from the protobuf enum. |
| Message Type | The field is the type created by code generation from the protobuf message. |
| Map ProtoType ProtoType | A map with the given key and value types. |
data Association (key :: ProtoType) (value :: ProtoType) Source #
The type of the repeated key-value pair submessage implied by a map field.
We never need to construct values; instead we construct values of types
such as .Encoding (Association key value)
The key field is named "key" and the value field is named "value".
Instances
| FieldForm 'Optional ('Map key value) (Identity (MessageEncoding (Association key value)) :: Type) Source # | This instance is rather artificial because maps are automatically
repeated and unpacked, with no option to specify a single key-value pair
as an |
Defined in Proto3.Suite.Form.Encode Methods fieldForm :: Proxy# 'Optional -> Proxy# ('Map key value) -> FieldNumber -> Identity (MessageEncoding (Association key value)) -> MessageBuilder Source # | |
| FieldForm 'Optional ('Map key value) (Identity (MessageEncoder (Association key value)) :: Type) Source # | This instance is rather artificial because maps are automatically
repeated and unpacked, with no option to specify a single key-value pair
as an |
Defined in Proto3.Suite.Form.Encode.Core Methods fieldForm :: Proxy# 'Optional -> Proxy# ('Map key value) -> FieldNumber -> Identity (MessageEncoder (Association key value)) -> MessageBuilder Source # | |
| type NamesOf (Association _1 _2) Source # | |
Defined in Proto3.Suite.Form | |
| type CardinalityOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type CardinalityOf (Association _1 value) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type NumberOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type NumberOf (Association _1 _2) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type OneOfOf (Association _1 _2) "key" Source # | |
Defined in Proto3.Suite.Form | |
| type OneOfOf (Association _1 _2) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type ProtoTypeOf (Association _1 value) "value" Source # | |
Defined in Proto3.Suite.Form | |
| type ProtoTypeOf (Association key _1) "key" Source # | |
Defined in Proto3.Suite.Form | |
type family CardinalityOfMapped (protoType :: ProtoType) :: Cardinality where ... Source #
Yields the field presence of a mapped value of the given protobuf type.
Equations
| CardinalityOfMapped ('Message _1) = 'Optional | |
| CardinalityOfMapped ('Map k v) = TypeError ('Text "Nested maps are disallowed, so this cannot be a mapped type:" ':$$: 'ShowType ('Map k v)) :: Cardinality | |
| CardinalityOfMapped _1 = 'Implicit |
data Wrapper (protoType :: ProtoType) Source #
Indicates the standard protobuf wrapper having the field type given by the type argument.
We never need to construct values; instead we construct values of types
such as or
Encoding (Wrapper protoType), where Wrap aa is a corresponding native representation.
Note that if Google ever adds wrappers for "sint..." or "...fixed..." then this type constructor will naturally support such wrappers.
Instances
type family RecoverCardinality haskellType :: Cardinality where ... Source #
Given the Haskell type used by features such as MessageField
to indicate the encoding of a message field.
Equations
type family RecoverProtoType haskellType :: ProtoType where ... Source #
Given the Haskell type used by features such as MessageField
to indicate the encoding of a message field, returns the corresponding type of kind
ProtoType, which for repeated types is the element type. This type family is not
injective because multiple types are supported for fields of protobuf type string.
Equations
class (RecoverCardinality haskellType ~ cardinality, RecoverProtoType haskellType ~ protoType) => MessageFieldType (cardinality :: Cardinality) (protoType :: ProtoType) haskellType Source #
Inhabited by Haskell types used by features such as MessageField
that correspond to particular protobuf types that are repeated in the specified way.
Instances
type family OptionalMessageFieldType m haskellType where ... Source #
Helps to diagnose the absence of an instance for MessageFieldType
for optional submessages by requiring that the second type parameter
be Nested of the first. Please try to avoid using this type family
directly; it is exported only to help explain compilation errors.
Equations
| OptionalMessageFieldType m (Nested m) = () | |
| OptionalMessageFieldType m (Nested a) = TypeError (('Text "Expected reflected protobuf submessage type " ':<>: 'ShowType m) ':$$: ('Text "Actual type: " ':<>: 'ShowType a)) :: Constraint | |
| OptionalMessageFieldType m haskellType = TypeError (((('Text "When using a Haskell type to specify an optional protobuf submessage" ':$$: 'Text "(as opposed to repeated one or a submessage within a oneof)") ':$$: 'Text "you must wrap the Haskell reflection type in Proto3.Suite.Nested.") ':$$: ('Text "Expected reflected protobuf submessage type " ':<>: 'ShowType m)) ':$$: ('Text "Haskell type provided: " ':<>: 'ShowType haskellType)) :: Constraint |
type family RepeatedMessageFieldType m haskellType where ... Source #
Helps to diagnose the absence of an instance for MessageFieldType
for repeated submessages by requiring that the second type parameter
be NestedVec of the first. Please try to avoid using this type family
directly; it is exported only to help explain compilation errors.
Equations
| RepeatedMessageFieldType m (NestedVec m) = () | |
| RepeatedMessageFieldType m (NestedVec a) = TypeError (('Text "Expected reflected protobuf submessage type " ':<>: 'ShowType m) ':$$: ('Text "Actual type: " ':<>: 'ShowType a)) :: Constraint | |
| RepeatedMessageFieldType m haskellType = TypeError (((('Text "When using a Haskell type to specify a repeated protobuf submessage" ':$$: 'Text "(as opposed to an optional one or a submessage within a oneof)") ':$$: 'Text "you must wrap the Haskell reflection type in Proto3.Suite.NestedVec.") ':$$: ('Text "Expected reflected protobuf submessage type " ':<>: 'ShowType m)) ':$$: ('Text "Haskell type provided: " ':<>: 'ShowType haskellType)) :: Constraint |