protobuf-c-text
Library to generate & parse text format protobufs in C.
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups
Data Structures | Functions
Public API for text format protobufs

These functions supplement the generated code from protoc-c to allow you to import and export ProtobufCMessage structures from/to the protobuf text mode serialisation. More...

Data Structures

struct  ProtobufCTextError
 Structure for reporting API errors. More...
 

Functions

char * protobuf_c_text_to_string (ProtobufCMessage *m, ProtobufCAllocator *allocator)
 Convert a ProtobufCMessage to a string. More...
 
ProtobufCMessage * protobuf_c_text_from_string (const ProtobufCMessageDescriptor *descriptor, char *msg, ProtobufCTextError *result, ProtobufCAllocator *allocator)
 Import a text format protobuf from a string into a ProtobufCMessage. More...
 
ProtobufCMessage * protobuf_c_text_from_file (const ProtobufCMessageDescriptor *descriptor, FILE *msg_file, ProtobufCTextError *result, ProtobufCAllocator *allocator)
 Import a text format protobuf from a FILE into a ProtobufCMessage. More...
 

Detailed Description

These functions supplement the generated code from protoc-c to allow you to import and export ProtobufCMessage structures from/to the protobuf text mode serialisation.

These will work with any code generated from protoc-c.

Function Documentation

ProtobufCMessage* protobuf_c_text_from_file ( const ProtobufCMessageDescriptor *  descriptor,
FILE *  msg_file,
ProtobufCTextError result,
ProtobufCAllocator *  allocator 
)

Import a text format protobuf from a FILE into a ProtobufCMessage.

Given a FILE containing a text format protobuf, parse it and return the corresponding ProtobufCMessage struct. On failure, NULL is returned and result is updated with why.

The resulting ProtobufCMessage should be freed with protobuf_c_message_free_unpacked() or the generated ..._free_upacked() function. Either is fine, but that's how the memory should be freed.

Parameters
[in]descriptorThe descriptor from the generated code.
[in]msg_fileThe FILE containing the text format protobuf.
[out]resultThis structure contains information on any error that halted processing.
[in]allocatorThis is the same ProtobufCAllocator type used by the libprotobuf-c library. You can set it to NULL to accept protobuf_c_default_allocator - the default allocator.
Returns
The resulting ProtobufCMessage . It returns NULL on error. Check result->complete to make sure the message is valid.

Definition at line 1233 of file parse.re.

References protobuf_c_text_parse(), and scanner_init_file().

Here is the call graph for this function:

ProtobufCMessage* protobuf_c_text_from_string ( const ProtobufCMessageDescriptor *  descriptor,
char *  msg,
ProtobufCTextError result,
ProtobufCAllocator *  allocator 
)

Import a text format protobuf from a string into a ProtobufCMessage.

Given a string containing a text format protobuf, parse it and return the corresponding ProtobufCMessage struct. On failure, NULL is returned and result is updated with why.

The resulting ProtobufCMessage should be freed with protobuf_c_message_free_unpacked() or the generated ..._free_upacked() function. Either is fine, but that's how the memory should be freed.

Parameters
[in]descriptorThe descriptor from the generated code.
[in]msgThe string containing the text format protobuf.
[out]resultThis structure contains information on any error that halted processing.
[in]allocatorThis is the same ProtobufCAllocator type used by the libprotobuf-c library. You can set it to NULL to accept protobuf_c_default_allocator - the default allocator.
Returns
The resulting ProtobufCMessage . It returns NULL on error. Check result->complete to make sure the message is valid.

Definition at line 1245 of file parse.re.

References protobuf_c_text_parse(), and scanner_init_string().

Here is the call graph for this function:

char* protobuf_c_text_to_string ( ProtobufCMessage *  m,
ProtobufCAllocator *  allocator 
)

Convert a ProtobufCMessage to a string.

Given a ProtobufCMessage serialise it as a text format protobuf.

Parameters
[in]mThe ProtobufCMessage to be serialised.
[in]allocatorThis is the same ProtobufCAllocator type used by the libprotobuf-c library. You can set it to NULL to accept protobuf_c_default_allocator - the default allocator.
Returns
The string with the text format serialised ProtobufCMessage. On failure it will return NULL. On success, the resulting value be freed by you with the allocator you provided. If you didn't provide an allocator technically you should do:
protobuf_c_default_allocator.free(
protobuf_c_default_allocator.allocator_data, retval);
Though technically free(retval); is probably sufficient.

Definition at line 498 of file generate.c.

References protobuf_c_text_to_string_internal(), and ReturnString::s.

Here is the call graph for this function: