| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.ProtocolBuffers.Internal
Synopsis
- type Tag = Word32
- data WireField
- = VarintField !Tag !Word64
- | Fixed64Field !Tag !Word64
- | DelimitedField !Tag !ByteString
- | StartField !Tag
- | EndField !Tag
- | Fixed32Field !Tag !Word32
- wireFieldTag :: WireField -> Tag
- getWireField :: Get WireField
- class EncodeWire a where
- encodeWire :: Tag -> a -> Put
- class DecodeWire a where
- decodeWire :: WireField -> Get a
- zzEncode32 :: Int32 -> Word32
- zzEncode64 :: Int64 -> Word64
- zzDecode32 :: Word32 -> Int32
- zzDecode64 :: Word64 -> Int64
- getVarintPrefixedBS :: Get ByteString
- getVarInt :: (Integral a, Bits a) => Get a
- putVarintPrefixedBS :: ByteString -> Put
- putVarSInt :: (Integral a, Bits a) => a -> Put
- putVarUInt :: (Integral a, Bits a) => a -> Put
- newtype Field (n :: Nat) a = Field {
- runField :: a
- newtype Value a = Value {
- runValue :: a
- newtype Always a = Always {
- runAlways :: a
- newtype Enumeration a = Enumeration {
- runEnumeration :: a
- newtype RequiredField a = Required {
- runRequired :: a
- newtype OptionalField a = Optional {
- runOptional :: a
- newtype RepeatedField a = Repeated {
- runRepeated :: a
- newtype PackedField a = PackedField {
- runPackedField :: a
- newtype PackedList a = PackedList {
- unPackedList :: [a]
- newtype Message m = Message {
- runMessage :: m
- class GDecode (f :: * -> *)
- class GEncode (f :: * -> *)
- class GMessageMonoid (f :: * -> *)
Documentation
A representation of the wire format as described in https://developers.google.com/protocol-buffers/docs/encoding#structure
Constructors
| VarintField !Tag !Word64 | For: int32, int64, uint32, uint64, sint32, sint64, bool, enum |
| Fixed64Field !Tag !Word64 | For: fixed64, sfixed64, double |
| DelimitedField !Tag !ByteString | For: string, bytes, embedded messages, packed repeated fields |
| StartField !Tag | For: groups (deprecated) |
| EndField !Tag | For: groups (deprecated) |
| Fixed32Field !Tag !Word32 | For: fixed32, sfixed32, float |
Instances
| Eq WireField Source # | |
| Ord WireField Source # | |
| Show WireField Source # | |
| DecodeWire WireField Source # | |
Defined in Data.ProtocolBuffers.Wire | |
| EncodeWire WireField Source # | |
Defined in Data.ProtocolBuffers.Wire | |
| Encode (HashMap Tag [WireField]) Source # | Untyped message encoding |
| Decode (HashMap Tag [WireField]) Source # | |
wireFieldTag :: WireField -> Tag Source #
class EncodeWire a where Source #
Methods
encodeWire :: Tag -> a -> Put Source #
Instances
class DecodeWire a where Source #
Methods
decodeWire :: WireField -> Get a Source #
Instances
zzEncode32 :: Int32 -> Word32 Source #
zzEncode64 :: Int64 -> Word64 Source #
zzDecode32 :: Word32 -> Int32 Source #
zzDecode64 :: Word64 -> Int64 Source #
putVarintPrefixedBS :: ByteString -> Put Source #
putVarSInt :: (Integral a, Bits a) => a -> Put Source #
This can be used on any Integral type and is needed for signed types; unsigned can use putVarUInt below. This has been changed to handle only up to 64 bit integral values (to match documentation).
putVarUInt :: (Integral a, Bits a) => a -> Put Source #
This should be used on unsigned Integral types only (not checked)
newtype Field (n :: Nat) a Source #
Fields are merely a way to hold a field tag along with its type, this shouldn't normally be referenced directly.
This provides better error messages than older versions which used Tagged
Instances
Value selects the normal/typical way for encoding scalar (primitive) values.
Instances
To provide consistent instances for serialization a Traversable Functor is needed to
make RequiredField fields have the same shape as OptionalField, RepeatedField and Packed.
Instances
newtype Enumeration a Source #
Enumeration fields use fromEnum and toEnum when encoding and decoding messages.
Constructors
| Enumeration | |
Fields
| |
Instances
newtype RequiredField a Source #
RequiredField is a newtype wrapped used to break overlapping instances
for encoding and decoding values
Constructors
| Required | |
Fields
| |
Instances
newtype OptionalField a Source #
OptionalField is a newtype wrapped used to break overlapping instances
for encoding and decoding values
Constructors
| Optional | |
Fields
| |
Instances
newtype RepeatedField a Source #
RepeatedField is a newtype wrapped used to break overlapping instances
for encoding and decoding values
Constructors
| Repeated | |
Fields
| |
Instances
newtype PackedField a Source #
A Traversable Functor used to select packed sequence encoding/decoding.
Constructors
| PackedField | |
Fields
| |
Instances
newtype PackedList a Source #
A list that is stored in a packed format.
Constructors
| PackedList | |
Fields
| |
Instances
The way to embed a message within another message. These embedded messages are stored as length-delimited fields.
For example:
data Inner = Inner
{ innerField :: Required '1' (Value Int64)
} deriving (Generic, Show)
instance Encode Inner
instance Decode Inner
data Outer = Outer
{ outerField :: Required '1' (Message Inner)
} deriving (Generic, Show)
instance Encode Outer
instance Decode Outer
It's worth noting that is a Message a Monoid and NFData instance. The Monoid behavior models
that of the Protocol Buffers documentation, effectively Last. It's done with a fairly big hammer
and it isn't possible to override this behavior. This can cause some less-obvious compile errors for
paramterized Message types:
data Inner = Inner{inner :: RequiredField '2' (Value Float)} deriving (Generic, Show)
instance Encode Inner
instance Decode Inner
data Outer a = Outer{outer :: RequiredField '3' (Message a)} deriving (Generic, Show)
instance Encode a => Encode (Outer a)
instance Decode a => Decode (Outer a)
This fails because Decode needs to know that the message can be merged. The resulting error
implies that you may want to add a constraint to the internal GMessageMonoid class:
/tmp/tst.hs:18:10: Could not deduce (protobuf-0.1:GMessageMonoid(Repa)) arising from a use of `protobuf-0.1:Decode.$gdmdecode' from the context (Decodea) bound by the instance declaration at /tmp/tst.hs:18:10-39 Possible fix: add an instance declaration for (protobuf-0.1:GMessageMonoid(Repa)) In the expression: (protobuf-0.1:Decode.$gdmdecode) In an equation fordecode: decode = (protobuf-0.1:Decode.$gdmdecode) In the instance declaration for `Decode(Outer a)'
The correct fix is to add the Monoid constraint for the message:
- instance (Encodea) =>Decode(Outer a) + instance (Monoid(Messagea),Decodea) =>Decode(Outer a)
Constructors
| Message | |
Fields
| |
Instances
class GDecode (f :: * -> *) Source #
Minimal complete definition
gdecode
Instances
class GEncode (f :: * -> *) Source #
Minimal complete definition
gencode
Instances
| GEncode (U1 :: Type -> Type) Source # | |
Defined in Data.ProtocolBuffers.Encode | |
| (EncodeWire a, KnownNat n, Foldable f) => GEncode (K1 i (Field n (f a)) :: Type -> Type) Source # | |
Defined in Data.ProtocolBuffers.Encode | |
| (GEncode a, GEncode b) => GEncode (a :+: b) Source # | |
Defined in Data.ProtocolBuffers.Encode | |
| (GEncode a, GEncode b) => GEncode (a :*: b) Source # | |
Defined in Data.ProtocolBuffers.Encode | |
| GEncode a => GEncode (M1 i c a) Source # | |
Defined in Data.ProtocolBuffers.Encode | |
class GMessageMonoid (f :: * -> *) Source #
Minimal complete definition
gmempty, gmappend
Instances
| GMessageMonoid (U1 :: Type -> Type) Source # | |
| Monoid c => GMessageMonoid (K1 i c :: Type -> Type) Source # | |
| (GMessageMonoid x, GMessageMonoid y) => GMessageMonoid (x :+: y) Source # | |
| (GMessageMonoid x, GMessageMonoid y) => GMessageMonoid (x :*: y) Source # | |
| GMessageMonoid f => GMessageMonoid (M1 i c f) Source # | |