there is some confusion with regard to the use of lower case letters in enum values. take the following message definition: message LowerCase { enum CaseEnum { UPPER = 1; lower = 2; } optional CaseEnum value = 1 [default = lower]; } this generates the following C enum: typedef enum _LowerCase__CaseEnum { LOWER_CASE__CASE_ENUM__UPPER = 1, LOWER_CASE__CASE_ENUM__lower = 2 _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE(LOWER_CASE__CASE_ENUM) } LowerCase__CaseEnum; note that the case of the enum value 'lower' was preserved in the C symbol name as 'LOWER_CASE__CASE_ENUM__lower', but that the _INIT macro references the same enum value with the (non-existent) C symbol name 'LOWER_CASE__CASE_ENUM__LOWER': #define LOWER_CASE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&lower_case__descriptor) \ , 0,LOWER_CASE__CASE_ENUM__LOWER } additionally, the ProtobufCEnumValue array generated also refers to the same enum value with the (non-existent) upper cased version: const ProtobufCEnumValue lower_case__case_enum__enum_values_by_number[2] = { { "UPPER", "LOWER_CASE__CASE_ENUM__UPPER", 1 }, { "lower", "LOWER_CASE__CASE_ENUM__LOWER", 2 }, }; we should preserve the existing behavior of copying the case from the enum values in the message definition and fix up the places where the (non-existent) upper case version is used, rather than changing the enum definition itself to match the case used in the _INIT macro and enum_values_by_number array, because it's possible that there might be existing working code that uses enum values with lower case letters that would be affected by such a change. incidentally, google's C++ protobuf implementation preserves case in enum values. protoc --cpp_out generates the following enum declaration for the message descriptor above: enum LowerCase_CaseEnum { LowerCase_CaseEnum_UPPER = 1, LowerCase_CaseEnum_lower = 2 };
Overview
This is protobuf-c
, a C implementation of Google Protocol Buffers. It includes libprotobuf-c
, a pure C library that implements protobuf encoding and decoding, and protoc-c
, a code generator that converts Protocol Buffer .proto
files to C descriptor code, based on the original protoc
. protobuf-c
formerly included an RPC implementation; that code has been split out into the protobuf-c-rpc project.
protobuf-c
was originally maintained by Dave Benson through version 0.15 but is now being maintained by a new team. Thanks, Dave!
Building
protobuf-c
requires a C compiler, a C++ compiler, Google Protocol Buffers, and pkg-config
to be installed.
./configure && make && make install
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
Synopsis
Include the protobuf-c
header file:
#include <protobuf-c/protobuf-c.h>
Link against the protobuf-c
library.
-lprotobuf-c
libprotobuf-c
includes a pkg-config
file. It is recommended to use the pkg-config
system in order to determine the complete set of compiler and linker flags for building applications that utilize libprotobuf-c
. If using pkg-config
with autoconf
, the PKG_CHECK_MODULES
macro can be used to detect the presence of libprotobuf-c
:
PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c])
This will place compiler flags in the PROTOBUF_C_CFLAGS
variable and linker flags in the PROTOBUF_C_LDFLAGS
variable.
(Note that the protobuf-c
header file used to be installed as google/protobuf-c/protobuf-c.h
in previous versions.)
Contributing
Please send patches to the protobuf-c mailing list or by opening a GitHub pull request.
Copyright to all contributions are retained by the original author, but must be licensed under the terms of the BSD-2-Clause license. Please add a Signed-off-by
header to your commit message (git commit -s
) to indicate that you are licensing your contribution under these terms.