|
libsignal-protocol-c
master
|
For each enum, we generate a C enum. For each message, we generate a C structure which can be cast to a ProtobufCMessage.
For each enum and message, we generate a descriptor object that allows us to implement a kind of reflection on the structures.
First, some naming conventions:
.proto file:would generate a C type Foo__Bar__BazBah.
protoc-c for the above example:For example, in the name of the unpack function above, the package name foo.bar has become foo__bar, the message name BazBah has become baz_bah, and the method name is unpack. These are all joined with double underscores to form the C identifier foo__bar__baz_bah__unpack.
We also generate descriptor objects for messages and enums. These are declared in the .pb-c.h files:
The message structures all begin with ProtobufCMessageDescriptor * which is sufficient to allow them to be cast to ProtobufCMessage.
For each message defined in a .proto file, we generate a number of functions and macros. Each function name contains a prefix based on the package name and message name in order to make it a unique C identifier.
INIT. Statically initializes a message object, initializing its descriptor and setting its fields to default values. Uninitialized messages cannot be processed by the protobuf-c library.init(). Initializes a message object, initializing its descriptor and setting its fields to default values. Uninitialized messages cannot be processed by the protobuf-c library.unpack(). Unpacks data for a particular message format. Note that the allocator parameter is usually NULL to indicate that the system's malloc() and free() functions should be used for dynamically allocating memory.free_unpacked(). Frees a message object obtained with the unpack() method.get_packed_size(). Calculates the length in bytes of the serialized representation of the message object.pack(). Pack a message object into a preallocated buffer. Assumes that the buffer is large enough. (Use get_packed_size() first.)pack_to_buffer(). Packs a message into a "virtual buffer". This is an object which defines an "append bytes" callback to consume data as it is serialized.