protocol-buffers-1.4.0: Parse Google Protocol Buffer specifications



A strong feature of the protocol-buffers package is that it does not contain any structures defined by descriptor.proto! This prevents me hitting any annoying circular dependencies. The structures defined here are included in each module created by hprotoc. They are optimized for use in code generation.

These values can be inspected at runtime by the user's code, but I have yet to write much documentation. Luckily the record field names are somewhat descriptive.

The other reflection is using the fileDescriptorProto which is put into the top level module created by hprotoc.



data ProtoName Source

This is fully qualified name data type for code generation. The haskellPrefix was possibly specified on the hprotoc command line. The parentModule is a combination of the module prefix from the '.proto' file and any nested levels of definition.

The name components are likely to have been mangled to ensure the baseName started with an uppercase letter, in ['A'..'Z'] .




protobufName :: FIName Utf8

fully qualified name using package prefix (no mangling)

haskellPrefix :: [MName String]

Haskell specific prefix to module hierarchy (e.g. Text.Foo)

parentModule :: [MName String]

.proto specified namespace (like Com.Google.Bar)

baseName :: MName String

data ProtoFName Source




protobufName' :: FIName Utf8

fully qualified name using package prefix (no mangling)

haskellPrefix' :: [MName String]

Haskell specific prefix to module hierarchy (e.g. Text.Foo)

parentModule' :: [MName String]

.proto specified namespace (like Com.Google.Bar)

baseName' :: FName String

data ProtoInfo Source




protoMod :: ProtoName

blank protobufName, maybe blank haskellPrefix and/or parentModule

protoFilePath :: [FilePath]

path to haskell module

protoSource :: FilePath

filename without path of .proto file

extensionKeys :: Seq KeyInfo

top level keys

messages :: [DescriptorInfo]

all messages and groups

enums :: [EnumInfo]

all enums

knownKeyMap :: Map ProtoName (Seq FieldInfo)

data FieldInfo Source




fieldName :: ProtoFName
fieldNumber :: FieldId
wireTag :: WireTag
wireTagLength :: WireSize

Bytes required in the Varint formatted wireTag

isRequired :: Bool
canRepeat :: Bool
typeCode :: FieldType

fromEnum of Text.DescriptorProtos.FieldDescriptorProto.Type

typeName :: Maybe ProtoName

Set for Messages,Groups,and Enums

hsRawDefault :: Maybe ByteString

crappy, but not escaped, thing

hsDefault :: Maybe HsDefault

nice parsed thing

data HsDefault Source

HsDefault stores the parsed default from the proto file in a form that will make a nice literal in the Language.Haskell.Exts.Syntax code generation by hprotoc.

Note that Utf8 labeled byte sequences have been stripped to just ByteString here as this is sufficient for code generation.

class ReflectDescriptor m whereSource


getMessageInfo :: m -> GetMessageInfoSource

This is obtained via read on the stored show output of the DescriptorInfo in the module file. It is used in getting messages from the wire.

Must not inspect argument



:: m 
-> DescriptorInfo

Must not inspect argument

class ReflectEnum e whereSource


reflectEnum :: EnumInfoApp eSource



:: e 
-> EnumInfo

Must not inspect argument



:: e 
-> Maybe DescriptorInfo

Must not inspect argument

data GetMessageInfo Source

GetMessageInfo is used in getting messages from the wire. It supplies the Set of precomposed wire tags that must be found in the message as well as a Set of all allowed tags (including known extension fields and all required wire tags).

Extension fields not in the allowedTags set are still loaded, but only as ByteString blobs that will have to interpreted later.

makePNF :: ByteString -> [String] -> [String] -> String -> ProtoNameSource

makePNF is used by the generated code to create a ProtoName with less newtype noise.