This is protobuf2json-c
, pure C implementation of the Google Protocol Buffers to/from JSON converter.
protobuf2json-c
requires a C compiler, protobuf-c 1.1.0 and jansson 2.7 to be installed.
If building from a git checkout, the autotools
(autoconf
, automake
, libtool
) must also be installed,
and the build system must be generated by running the autogen.sh
script:
./autogen.sh && ./configure && make && make install
protobuf2json-c
piblic API containt 6 functions:
3 for Protobuf to JSON conversion and 3 for JSON to Protobuf conversion.
They uses json_t
object, char *
C-string or file for JSON.
Protobuf to JSON conversion functions:
int protobuf2json_object(
ProtobufCMessage *protobuf_message,
json_t **json_object,
char *error_string,
size_t error_size
);
int protobuf2json_string(
ProtobufCMessage *protobuf_message,
size_t json_flags,
char **json_string,
char *error_string,
size_t error_size
);
int protobuf2json_file(
ProtobufCMessage *protobuf_message,
size_t json_flags,
char *json_file,
char *fopen_mode,
char *error_string,
size_t error_size
);
JSON to Protobuf conversion functions:
int json2protobuf_object(
json_t *json_object,
const ProtobufCMessageDescriptor *protobuf_message_descriptor,
ProtobufCMessage **protobuf_message,
char *error_string,
size_t error_size
);
int json2protobuf_string(
char *json_string,
size_t json_flags,
const ProtobufCMessageDescriptor *protobuf_message_descriptor,
ProtobufCMessage **protobuf_message,
char *error_string,
size_t error_size
);
int json2protobuf_file(
char *json_file,
size_t json_flags,
const ProtobufCMessageDescriptor *protobuf_message_descriptor,
ProtobufCMessage **protobuf_message,
char *error_string,
size_t error_size
);
Each of them have error_string
and error_size
arguments used to pass error description from protobuf2json-c
functions.
You can pass NULL
and 0
to avoid setting error description.
protobuf2json-c
based on code from:
- https://github.com/wickedck/protobuf-to-json
- https://github.com/renenglish/pb2json
- https://github.com/michaelstorm/Tangent
MIT license. See license text in file LICENSE.