protocol-buffers-0.3.1: Parse Google Protocol Buffer specificationsSource codeContentsIndex
Text.ProtocolBuffers.Basic
Contents
Basic types for protocol buffer fields in Haskell
Haskell types that act in the place of DescritorProto values
Some of the type classes implemented messages and fields
Description
Text.ProtocolBuffers.Basic defines or re-exports most of the basic field types; Maybe,Bool, Double, and Float come from the Prelude instead. This module also defined the Mergeable, Default, and Wire classes.
Synopsis
newtype Utf8 = Utf8 {
utf8 :: ByteString
}
newtype WireTag = WireTag {
getWireTag :: Word32
}
newtype FieldId = FieldId {
getFieldId :: Int32
}
newtype WireType = WireType {
getWireType :: Word32
}
newtype FieldType = FieldType {
getFieldType :: Int
}
newtype EnumCode = EnumCode {
getEnumCode :: Int32
}
type WireSize = Int64
class Mergeable a where
mergeEmpty :: a
mergeAppend :: a -> a -> a
mergeConcat :: Foldable t => t a -> a
class Default a where
defaultValue :: a
class Wire b where
wireSize :: FieldType -> b -> WireSize
wirePut :: FieldType -> b -> Put
wireGet :: FieldType -> Get b
Basic types for protocol buffer fields in Haskell
newtype Utf8 Source
Utf8 is used to mark ByteString values that (should) contain valud utf8 encoded strings. This type is used to represent TYPE_STRING values.
Constructors
Utf8
utf8 :: ByteString
show/hide Instances
Haskell types that act in the place of DescritorProto values
newtype WireTag Source
WireTag is the 32 bit value with the upper 29 bits being the FieldId and the lower 3 bits being the WireType
Constructors
WireTag
getWireTag :: Word32
show/hide Instances
newtype FieldId Source
FieldId is the field number which can be in the range 1 to 2^29-1 but the value from 19000 to 19999 are forbidden (so sayeth Google).
Constructors
FieldId
getFieldId :: Int32
show/hide Instances
newtype WireType Source

WireType is the 3 bit wire encoding value, and is currently in the range 0 to 5, leaving 6 and 7 currently invalid.

  • 0 Varint : int32, int64, uint32, uint64, sint32, sint64, bool, enum
  • 1 64-bit : fixed64, sfixed64, double
  • 2 Length-delimited : string, bytes, embedded messages
  • 3 Start group : groups (deprecated)
  • 4 End group : groups (deprecated)
  • 5 32-bit : fixed32, sfixed32, float
Constructors
WireType
getWireType :: Word32
show/hide Instances
newtype FieldType Source

FieldType is the integer associated with the FieldDescriptorProto's Type. The allowed range is currently 1 to 18, as shown below (excerpt from descritor.proto)

    // 0 is reserved for errors.
    // Order is weird for historical reasons.
    TYPE_DOUBLE         = 1;
    TYPE_FLOAT          = 2;
    TYPE_INT64          = 3;   // Not ZigZag encoded.  Negative numbers
                               // take 10 bytes.  Use TYPE_SINT64 if negative
                               // values are likely.
    TYPE_UINT64         = 4;
    TYPE_INT32          = 5;   // Not ZigZag encoded.  Negative numbers
                               // take 10 bytes.  Use TYPE_SINT32 if negative
                               // values are likely.
    TYPE_FIXED64        = 6;
    TYPE_FIXED32        = 7;
    TYPE_BOOL           = 8;
    TYPE_STRING         = 9;
    TYPE_GROUP          = 10;  // Tag-delimited aggregate.
    TYPE_MESSAGE        = 11;  // Length-delimited aggregate.

    // New in version 2.
    TYPE_BYTES          = 12;
    TYPE_UINT32         = 13;
    TYPE_ENUM           = 14;
    TYPE_SFIXED32       = 15;
    TYPE_SFIXED64       = 16;
    TYPE_SINT32         = 17;  // Uses ZigZag encoding.
    TYPE_SINT64         = 18;  // Uses ZigZag encoding.
Constructors
FieldType
getFieldType :: Int
show/hide Instances
newtype EnumCode Source
EnumCode is the Int32 assoicated with a EnumValueDescriptorProto and is in the range 0 to 2^31-1.
Constructors
EnumCode
getEnumCode :: Int32
show/hide Instances
type WireSize = Int64Source
WireSize is the Int64 size type associate with the lazy bytestrings used in the Put and Get monads.
Some of the type classes implemented messages and fields
class Mergeable a whereSource
The Mergeable class is not a Monoid, mergeEmpty is not a left or right unit like mempty. The default mergeAppend is to take the second parameter and discard the first one. The mergeConcat defaults to foldl associativity.
Methods
mergeEmpty :: aSource
The mergeEmpty value of a basic type or a message with required fields will be undefined and a runtime error to evaluate. These are only handy for reading the wire encoding and users should employ defaultValue instead.
mergeAppend :: a -> a -> aSource
mergeAppend is the right-biased merge of two values. A message (or group) is merged recursively. Required field are always taken from the second message. Optional field values are taken from the most defined message or the message message if both are set. Repeated fields have the sequences concatenated. Note that strings and bytes are NOT concatenated.
mergeConcat :: Foldable t => t a -> aSource
mergeConcat is F.foldl mergeAppend mergeEmpty and this default definition is not overrring in any of the code.
show/hide Instances
class Default a whereSource
The Default class has the default-default values of types. See http://code.google.com/apis/protocolbuffers/docs/proto.html#optional and also note that Enum types have a defaultValue that is the first one in the .proto file (there is always at least one value). Instances of this for messages hold any default value defined in the .proto file. defaultValue is where the MessageAPI function getVal looks when an optional field is not set.
Methods
defaultValue :: aSource
The defaultValue is never undefined or an error to evalute. This makes it much more useful compared to mergeEmpty. In a default message all Optional field values are set to Nothing and Repeated field values are empty.
show/hide Instances
class Wire b whereSource

The Wire class is for internal use, and may change. If there is a mis-match between the FieldType and the type of b then you will get a failure at runtime.

Users should stick to the message functions defined in Text.ProtocolBuffers.WireMessage and exported to use user by Text.ProtocolBuffers. These are less likely to change.

Methods
wireSize :: FieldType -> b -> WireSizeSource
wirePut :: FieldType -> b -> PutSource
wireGet :: FieldType -> Get bSource
show/hide Instances
Produced by Haddock version 2.3.0