├── protobuf-c ├── t │ ├── issue204 │ │ ├── .gitignore │ │ ├── issue204.proto │ │ └── issue204.c │ ├── issue220 │ │ ├── .gitignore │ │ ├── issue220.c │ │ └── issue220.proto │ ├── issue251 │ │ ├── .gitignore │ │ ├── issue251.proto │ │ └── issue251.c │ ├── issue330 │ │ ├── .gitignore │ │ ├── issue330.proto │ │ └── issue330.c │ ├── issue375 │ │ ├── .gitignore │ │ ├── issue375.proto │ │ └── issue375.c │ ├── issue440 │ │ ├── .gitignore │ │ ├── issue440.proto │ │ └── issue440.c │ ├── issue389 │ │ └── issue389.proto │ ├── test-optimized.proto │ ├── test-proto3.proto │ ├── test.proto │ ├── README │ ├── generated-code │ │ └── test-generated-code.c │ ├── version │ │ └── version.c │ └── generated-code2 │ │ └── common-test-arrays.h ├── autogen.sh ├── build-cmake │ ├── .gitignore │ └── Config.cmake.in ├── m4 │ ├── .gitignore │ ├── valgrind-tests.m4 │ ├── ld-version-script.m4 │ ├── ax_check_compile_flag.m4 │ └── code_coverage.m4 ├── protobuf-c │ ├── libprotobuf-c.pc.in │ ├── libprotobuf-c.sym │ └── protobuf-c.proto ├── CONTRIBUTING.md ├── .gitignore ├── protoc-c │ ├── main.cc │ ├── c_extension.cc │ ├── c_message_field.h │ ├── c_primitive_field.h │ ├── c_enum_field.h │ ├── c_bytes_field.h │ ├── c_string_field.h │ ├── c_generator.h │ ├── c_extension.h │ ├── c_service.h │ ├── c_enum.h │ ├── c_file.h │ ├── c_field.h │ ├── c_message_field.cc │ ├── c_message.h │ └── c_enum_field.cc ├── CHANGELOG.md ├── LICENSE ├── .commit_docs.sh ├── TODO ├── configure.ac ├── README.md └── DoxygenLayout.xml ├── example ├── CMakeLists.txt └── foo │ ├── .gitignore │ ├── foo_main.c │ ├── foo.proto │ ├── CMakeLists.txt │ ├── foo_client.c │ └── foo_server.c ├── .gitignore ├── vcpkg.json ├── compiler ├── main.cc ├── CMakeLists.txt ├── grpc_c_helpers.h ├── grpc_c_helpers.cc ├── grpc_c_generator.h ├── grpc_c_service.h ├── grpc_c_message.h └── grpc_c_file.h ├── lib ├── src │ ├── metadata_array.h │ ├── context.h │ ├── trace.h │ ├── init.c │ ├── thread_pool.h │ ├── memory.c │ ├── list.h │ ├── metadata_array.c │ ├── stream_ops.h │ ├── thread_pool.c │ └── trace.c └── CMakeLists.txt ├── vcpkg-configuration.json ├── CMakePresets.json ├── CMakeLists.txt └── README.md /protobuf-c/t/issue204/.gitignore: -------------------------------------------------------------------------------- 1 | issue204 2 | -------------------------------------------------------------------------------- /protobuf-c/t/issue220/.gitignore: -------------------------------------------------------------------------------- 1 | issue220 2 | -------------------------------------------------------------------------------- /protobuf-c/t/issue251/.gitignore: -------------------------------------------------------------------------------- 1 | issue251 2 | -------------------------------------------------------------------------------- /protobuf-c/t/issue330/.gitignore: -------------------------------------------------------------------------------- 1 | issue330 2 | -------------------------------------------------------------------------------- /protobuf-c/t/issue375/.gitignore: -------------------------------------------------------------------------------- 1 | issue375 2 | -------------------------------------------------------------------------------- /protobuf-c/t/issue440/.gitignore: -------------------------------------------------------------------------------- 1 | issue440 2 | -------------------------------------------------------------------------------- /protobuf-c/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec autoreconf -fvi 3 | -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | add_subdirectory(foo) -------------------------------------------------------------------------------- /example/foo/.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | foo.grpc-c.c 3 | foo.grpc-c.h 4 | foo.grpc-c.service.c 5 | -------------------------------------------------------------------------------- /protobuf-c/build-cmake/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !CMakeLists.txt 4 | !Config.cmake.in 5 | -------------------------------------------------------------------------------- /protobuf-c/m4/.gitignore: -------------------------------------------------------------------------------- 1 | libtool.m4 2 | ltoptions.m4 3 | ltsugar.m4 4 | ltversion.m4 5 | lt~obsolete.m4 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | build/* 3 | log/* 4 | ._.* 5 | ._* 6 | *.out 7 | *.tar.gz 8 | publish/* 9 | vcpkg_installed/* -------------------------------------------------------------------------------- /protobuf-c/build-cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | include("${CMAKE_CURRENT_LIST_DIR}/protobuf-c-targets.cmake") 3 | -------------------------------------------------------------------------------- /protobuf-c/t/issue330/issue330.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message pbr_route { 4 | repeated int32 acl_id = 10; 5 | } 6 | -------------------------------------------------------------------------------- /protobuf-c/t/issue375/issue375.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package issue375; 4 | 5 | message TestMessage { 6 | repeated int32 nums = 1; 7 | } 8 | -------------------------------------------------------------------------------- /protobuf-c/t/issue440/issue440.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Int { 4 | repeated int32 int = 1; 5 | } 6 | 7 | message Boolean { 8 | repeated bool boolean = 1; 9 | } 10 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | "protobuf", 4 | { 5 | "name": "protobuf-c", 6 | "features": [] 7 | }, 8 | "grpc" 9 | ] 10 | } -------------------------------------------------------------------------------- /protobuf-c/t/issue389/issue389.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message EnumIntTest { 4 | enum Label { 5 | LABEL_1 = 0; 6 | LABEL_2 = 1; 7 | } 8 | oneof label { 9 | Label label_label = 123; 10 | uint64 label_uint64 = 124; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /protobuf-c/t/issue251/issue251.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message two_oneofs { 4 | oneof first_oneof { 5 | bool a = 10; 6 | bool b = 11; 7 | } 8 | 9 | oneof second_oneof { 10 | bool c = 20; 11 | bool d = 21; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /compiler/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "grpc_c_generator.h" 3 | 4 | 5 | int main(int argc, char* argv[]) { 6 | google::protobuf::compiler::grpc_c::GrpcCGenerator grpc_c_generator; 7 | return google::protobuf::compiler::PluginMain(argc, argv, &grpc_c_generator); 8 | } 9 | -------------------------------------------------------------------------------- /protobuf-c/t/test-optimized.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package foo; 4 | 5 | option optimize_for = CODE_SIZE; 6 | 7 | enum TestEnumLite { 8 | LITE = 0; 9 | LITE1 = 1; 10 | } 11 | 12 | message TestMessLite { 13 | required int32 field1 = 1; 14 | required TestEnumLite field2 = 2; 15 | } 16 | -------------------------------------------------------------------------------- /protobuf-c/t/issue251/issue251.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "t/issue251/issue251.pb-c.h" 4 | 5 | int main(void) 6 | { 7 | /* 8 | * The problem in #251 caused invalid code to be generated in the 9 | * .pb-c.h file, so there's nothing for us to do here. 10 | */ 11 | return EXIT_SUCCESS; 12 | } 13 | -------------------------------------------------------------------------------- /protobuf-c/protobuf-c/libprotobuf-c.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | bindir=@bindir@ 6 | 7 | Name: @PACKAGE_NAME@ 8 | Description: @PACKAGE_DESCRIPTION@ 9 | Version: @PACKAGE_VERSION@ 10 | URL: @PACKAGE_URL@ 11 | Libs: -L${libdir} -lprotobuf-c 12 | Libs.private: 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /lib/src/metadata_array.h: -------------------------------------------------------------------------------- 1 | #ifndef GRPC_C_INTERNAL_METADATA_ARRAY_H 2 | #define GRPC_C_INTERNAL_METADATA_ARRAY_H 3 | 4 | #include "trace.h" 5 | #include 6 | 7 | int grpc_c_metadata_array_get(grpc_c_metadata_array_t *mdarray, const char *key, 8 | char *value, size_t len); 9 | 10 | #endif /* GRPC_C_INTERNAL_METADATA_ARRAY_H */ 11 | -------------------------------------------------------------------------------- /protobuf-c/t/issue204/issue204.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "protobuf-c/protobuf-c.proto"; 4 | 5 | option (pb_c_file).use_oneof_field_name = true; 6 | 7 | message two_oneofs { 8 | oneof first_oneof { 9 | bool a = 10; 10 | bool b = 11; 11 | } 12 | 13 | oneof second_oneof { 14 | bool c = 20; 15 | bool d = 21; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /protobuf-c/t/issue220/issue220.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "t/issue220/issue220.pb-c.h" 6 | 7 | int main(void) 8 | { 9 | assert(_MESSAGE_TYPE1__FLAG_IS_INT_SIZE == INT_MAX); 10 | assert(_MESSAGE_TYPE2__ANOTHER_FLAG_IS_INT_SIZE == INT_MAX); 11 | assert(_TOP_LEVEL__SUBMESSAGES__CASE_IS_INT_SIZE == INT_MAX); 12 | return EXIT_SUCCESS; 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/context.h: -------------------------------------------------------------------------------- 1 | #ifndef GRPC_C_INTERNAL_CONTEXT_H 2 | #define GRPC_C_INTERNAL_CONTEXT_H 3 | 4 | #include 5 | 6 | /* 7 | * Allocate and initialize context object 8 | */ 9 | grpc_c_context_t *grpc_c_context_init(grpc_c_method_t *method, int is_client); 10 | 11 | /* 12 | * Destroy and free context 13 | */ 14 | void grpc_c_context_free(grpc_c_context_t *context); 15 | 16 | #endif /* GRPC_C_INTERNAL_CONTEXT_H */ 17 | -------------------------------------------------------------------------------- /protobuf-c/t/issue220/issue220.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message TopLevel { 4 | oneof submessages { 5 | MessageType1 type1 = 1; 6 | MessageType2 type2 = 2; 7 | } 8 | } 9 | 10 | message MessageType1 { 11 | enum Flag { 12 | OK = 1; 13 | } 14 | optional Flag flag = 1; 15 | } 16 | 17 | message MessageType2 { 18 | enum AnotherFlag { 19 | OK = 1; 20 | } 21 | optional AnotherFlag flag = 1; 22 | } 23 | -------------------------------------------------------------------------------- /vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "fb544875b93bffebe96c6f720000003234cfba08", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /protobuf-c/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | The most recently released `protobuf-c` version is kept on the `master` branch, while the `next` branch is used for commits targeted at the next release. Please base patches and pull requests against the `next` branch. __Do not open pull requests against master!__ 4 | 5 | Copyright to all contributions are retained by the original author, but must be licensed under the terms of the [BSD-2-Clause](http://opensource.org/licenses/BSD-2-Clause) license. 6 | -------------------------------------------------------------------------------- /example/foo/foo_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "foo.grpc-c.h" 6 | 7 | int foo_server(); 8 | int foo_client(); 9 | 10 | int main(int argv, char ** args) { 11 | if ( argv < 2) { 12 | printf("usage: \n"); 13 | return -1; 14 | } 15 | if ( 0 == strcmp(args[1],"server") ) { 16 | foo_server(); 17 | }else { 18 | foo_client(); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /example/foo/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package foo; 4 | 5 | // The greeting service definition. 6 | service Greeter { 7 | // Sends a greeting 8 | rpc SayHello (HelloRequest) returns (HelloReply) {} 9 | rpc SayHello1 (stream HelloRequest) returns (HelloReply) {} 10 | rpc SayHello2 (HelloRequest) returns (stream HelloReply) {} 11 | rpc SayHello3 (stream HelloRequest) returns (stream HelloReply) {} 12 | } 13 | 14 | // The request message containing the user's name. 15 | message HelloRequest { 16 | string name = 1; 17 | } 18 | 19 | // The response message containing the greetings 20 | message HelloReply { 21 | string message = 1; 22 | } 23 | -------------------------------------------------------------------------------- /protobuf-c/t/issue330/issue330.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "t/issue330/issue330.pb-c.h" 5 | 6 | int main(void) 7 | { 8 | /* Output of $ echo acl_id: 2 acl_id: 3 | protoc issue330.proto \ 9 | * --encode=pbr_route | xxd -i: 0x52, 0x02, 0x02, 0x03 10 | */ 11 | uint8_t protoc[] = {0x52, 0x02, 0x02, 0x03}; 12 | PbrRoute msg = PBR_ROUTE__INIT; 13 | int ids[] = {2, 3}; 14 | uint8_t buf[16] = {0}; 15 | size_t sz = 0; 16 | 17 | msg.n_acl_id = 2; 18 | msg.acl_id = ids; 19 | sz = pbr_route__pack(&msg, buf); 20 | 21 | assert (sz == sizeof protoc); 22 | assert (memcmp (protoc, buf, sz) == 0); 23 | 24 | return EXIT_SUCCESS; 25 | } 26 | -------------------------------------------------------------------------------- /protobuf-c/t/test-proto3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package foo; 4 | 5 | message Person { 6 | string name = 1; 7 | int32 id = 2; 8 | string email = 3; 9 | 10 | enum PhoneType { 11 | MOBILE = 0; 12 | HOME = 1; 13 | WORK = 2; 14 | } 15 | 16 | message PhoneNumber { 17 | message Comment { 18 | string comment = 1; 19 | } 20 | 21 | string number = 1; 22 | PhoneType type = 2; 23 | Comment comment = 3; 24 | } 25 | 26 | repeated PhoneNumber phone = 4; 27 | } 28 | 29 | message LookupResult 30 | { 31 | Person person = 1; 32 | } 33 | 34 | message Name { 35 | string name = 1; 36 | }; 37 | 38 | service DirLookup { 39 | rpc ByName (Name) returns (LookupResult); 40 | } 41 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "release", 6 | "binaryDir": "${sourceDir}/build", 7 | "cacheVariables": { 8 | "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 9 | "CMAKE_BUILD_TYPE": "Release" 10 | } 11 | }, 12 | { 13 | "name": "debug", 14 | "binaryDir": "${sourceDir}/build", 15 | "cacheVariables": { 16 | "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 17 | "CMAKE_BUILD_TYPE": "Debug" 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /lib/src/trace.h: -------------------------------------------------------------------------------- 1 | #ifndef GRPC_C_INTERNAL_TRACE_H 2 | #define GRPC_C_INTERNAL_TRACE_H 3 | 4 | void grpc_c_log(int level, const char *file, int line, const char *format, ...); 5 | 6 | #define GRPC_C_DBG(format, args...) \ 7 | grpc_c_log(0, __FILE__, __LINE__, format, ##args) 8 | 9 | #define GRPC_C_INF(format, args...) \ 10 | grpc_c_log(1, __FILE__, __LINE__, format, ##args) 11 | 12 | #define GRPC_C_ERR(format, args...) \ 13 | grpc_c_log(2, __FILE__, __LINE__, format, ##args) 14 | 15 | /* 16 | * Initialize tracing 17 | */ 18 | void grpc_c_trace_init(void); 19 | 20 | #endif /* GRPC_C_INTERNAL_TRACE_H */ 21 | -------------------------------------------------------------------------------- /lib/src/init.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "trace.h" 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | #if __cplusplus 11 | extern "C" { 12 | #endif 13 | #endif /* __cplusplus */ 14 | 15 | /* 16 | * Initializes japi library 17 | */ 18 | int grpc_c_init() { 19 | /* 20 | * Initialize trace functions 21 | */ 22 | grpc_c_trace_init(); 23 | 24 | /* 25 | * Initialize grpc 26 | */ 27 | grpc_init(); 28 | 29 | return 0; 30 | } 31 | 32 | /* 33 | * Cleans up and shutsdown japi library 34 | */ 35 | int grpc_c_shutdown() { 36 | grpc_shutdown(); 37 | 38 | return 0; 39 | } 40 | 41 | #ifdef __cplusplus 42 | #if __cplusplus 43 | } 44 | #endif 45 | #endif /* __cplusplus */ 46 | -------------------------------------------------------------------------------- /protobuf-c/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*swp 3 | *.la 4 | *.gcda 5 | *.gcno 6 | *.lo 7 | *.log 8 | *.o 9 | *.tar.gz 10 | *.trs 11 | .deps/ 12 | .dirstamp 13 | .libs/ 14 | /Doxyfile 15 | /Makefile 16 | /Makefile.in 17 | /aclocal.m4 18 | /autom4te.cache 19 | /build-aux 20 | /config.* 21 | /configure 22 | /doxygen-doc 23 | /html 24 | /libtool 25 | /protobuf-c-*-coverage.info 26 | /protobuf-c-*-coverage/ 27 | /stamp-h1 28 | /stamp-html 29 | /test-suite.log 30 | TAGS 31 | protobuf-c/libprotobuf-c.pc 32 | protoc-c/protoc-c 33 | protoc-c/protoc-gen-c 34 | t/generated-code/test-generated-code 35 | t/generated-code2/cxx-generate-packed-data 36 | t/generated-code2/test-full-cxx-output.inc 37 | t/generated-code2/test-generated-code2 38 | t/generated-code3/test-generated-code3 39 | t/version/version 40 | *.pb-c.c 41 | *.pb-c.h 42 | *.pb.cc 43 | *.pb.h 44 | -------------------------------------------------------------------------------- /protobuf-c/t/issue375/issue375.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "t/issue375/issue375.pb-c.h" 5 | 6 | int main(void) { 7 | // This buffer represents some serialized bytes where we have a length 8 | // delimiter of 2^32 - 1 bytes for a particular repeated int32 field. 9 | // We want to make sure that parsing a length delimiter this large does 10 | // not cause a problematic integer overflow. 11 | uint8_t buffer[] = { 12 | // Field 1 with wire type 2 (length-delimited) 13 | 0x0a, 14 | // Varint length delimiter: 2^32 - 1 15 | 0xff, 0xff, 0xff, 0xff, 0x0f, 16 | }; 17 | // The parser should detect that this message is malformed and return 18 | // null. 19 | Issue375__TestMessage* m = 20 | issue375__test_message__unpack(NULL, sizeof(buffer), buffer); 21 | assert(m == NULL); 22 | 23 | return EXIT_SUCCESS; 24 | } 25 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | google::protobuf::compiler::c::CGenerator c_generator; 9 | 10 | std::string invocation_name = argv[0]; 11 | std::string invocation_basename = invocation_name.substr(invocation_name.find_last_of("/") + 1); 12 | const std::string standalone_name = "protoc-c"; 13 | 14 | if (invocation_basename == standalone_name) { 15 | google::protobuf::compiler::CommandLineInterface cli; 16 | cli.RegisterGenerator("--c_out", &c_generator, "Generate C/H files."); 17 | cli.SetVersionInfo(PACKAGE_STRING); 18 | return cli.Run(argc, argv); 19 | } 20 | 21 | return google::protobuf::compiler::PluginMain(argc, argv, &c_generator); 22 | } 23 | -------------------------------------------------------------------------------- /protobuf-c/t/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package foo; 4 | 5 | import "protobuf-c/protobuf-c.proto"; 6 | 7 | option (pb_c_file).c_package = "foo"; 8 | 9 | message Person { 10 | required string name = 1; 11 | required int32 id = 2; 12 | optional string email = 3; 13 | 14 | enum PhoneType { 15 | MOBILE = 0; 16 | HOME = 1; 17 | WORK = 2; 18 | } 19 | 20 | message PhoneNumber { 21 | message Comment { 22 | required string comment = 1; 23 | } 24 | 25 | required string number = 1; 26 | optional PhoneType type = 2 [default = HOME]; 27 | optional Comment comment = 3; 28 | } 29 | 30 | repeated PhoneNumber phone = 4; 31 | } 32 | 33 | message LookupResult 34 | { 35 | optional Person person = 1; 36 | } 37 | 38 | message Name { 39 | optional string name = 1; 40 | }; 41 | 42 | service DirLookup { 43 | rpc ByName (Name) returns (LookupResult); 44 | } 45 | -------------------------------------------------------------------------------- /protobuf-c/protobuf-c/libprotobuf-c.sym: -------------------------------------------------------------------------------- 1 | LIBPROTOBUF_C_1.0.0 { 2 | global: 3 | protobuf_c_buffer_simple_append; 4 | protobuf_c_enum_descriptor_get_value; 5 | protobuf_c_enum_descriptor_get_value_by_name; 6 | protobuf_c_message_check; 7 | protobuf_c_message_descriptor_get_field; 8 | protobuf_c_message_descriptor_get_field_by_name; 9 | protobuf_c_message_free_unpacked; 10 | protobuf_c_message_get_packed_size; 11 | protobuf_c_message_init; 12 | protobuf_c_message_pack; 13 | protobuf_c_message_pack_to_buffer; 14 | protobuf_c_message_unpack; 15 | protobuf_c_service_descriptor_get_method_by_name; 16 | protobuf_c_service_destroy; 17 | protobuf_c_service_generated_init; 18 | protobuf_c_service_invoke_internal; 19 | protobuf_c_version; 20 | protobuf_c_version_number; 21 | local: 22 | *; 23 | }; 24 | 25 | LIBPROTOBUF_C_1.3.0 { 26 | global: 27 | protobuf_c_empty_string; 28 | } LIBPROTOBUF_C_1.0.0; 29 | -------------------------------------------------------------------------------- /protobuf-c/t/issue440/issue440.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "t/issue440/issue440.pb-c.h" 5 | 6 | int main(void) 7 | { 8 | /* Output of $ echo "int: 1 int: -142342 int: 0 int: 423423222" | \ 9 | * protoc issue440.proto --encode=Int | xxd -i: 10 | * 0x0a, 0x11, 0x01, 0xfa, 0xa7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11 | * 0x01, 0x00, 0xf6, 0xd9, 0xf3, 0xc9, 0x01 12 | * 13 | * Output of $ echo "int: 1 int: -142342 int: 0 int: 423423222" | \ 14 | * protoc issue440.proto --encode=Int | protoc issue440.proto \ 15 | * --decode=Boolean: boolean: true boolean: true boolean: false boolean: true 16 | */ 17 | uint8_t protoc[] = {0x0a, 0x11, 0x01, 0xfa, 0xa7, 0xf7, 0xff, 0xff, 18 | 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf6, 0xd9, 0xf3, 0xc9, 19 | 0x01}; 20 | Boolean *msg = boolean__unpack (NULL, sizeof protoc, protoc); 21 | assert(msg); 22 | assert(msg->n_boolean == 4); 23 | assert(msg->boolean[0] == 1); 24 | assert(msg->boolean[1] == 1); 25 | assert(msg->boolean[2] == 0); 26 | assert(msg->boolean[3] == 1); 27 | boolean__free_unpacked (msg, NULL); 28 | 29 | return EXIT_SUCCESS; 30 | } 31 | -------------------------------------------------------------------------------- /example/foo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(example-foo) 4 | 5 | include_directories("${PROJECT_SOURCE_DIR}") 6 | include_directories("${PROJECT_SOURCE_DIR}/../../lib/include") 7 | 8 | set(PROTO_C_FILE "foo.proto") 9 | 10 | find_package(protobuf CONFIG REQUIRED) 11 | find_package(protobuf-c CONFIG REQUIRED) 12 | find_package(gRPC CONFIG REQUIRED) 13 | 14 | add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/foo.grpc-c.c ${PROJECT_SOURCE_DIR}/foo.grpc-c.service.c 15 | COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I ${PROJECT_SOURCE_DIR} --grpc-c_out=${PROJECT_SOURCE_DIR} --plugin=protoc-gen-grpc-c=$ --proto_path=${PROTO_C_DIR}/protobuf-c/ ${PROTO_C_FILE} 16 | ) 17 | 18 | add_executable(example-foo 19 | foo.grpc-c.c 20 | foo.grpc-c.service.c 21 | foo_client.c 22 | foo_server.c 23 | foo_main.c) 24 | 25 | TARGET_LINK_LIBRARIES(example-foo PRIVATE protobuf-c::protobuf-c gRPC::gpr gRPC::grpc++ grpc-c-static) 26 | 27 | install(TARGETS example-foo DESTINATION bin 28 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 29 | GROUP_EXECUTE GROUP_READ 30 | WORLD_EXECUTE WORLD_READ) -------------------------------------------------------------------------------- /protobuf-c/m4/valgrind-tests.m4: -------------------------------------------------------------------------------- 1 | # valgrind-tests.m4 serial 2 2 | dnl Copyright (C) 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Simon Josefsson 8 | 9 | # gl_VALGRIND_TESTS() 10 | # ------------------- 11 | # Check if valgrind is available, and set VALGRIND to it if available. 12 | AC_DEFUN([gl_VALGRIND_TESTS], 13 | [ 14 | AC_ARG_ENABLE(valgrind-tests, 15 | AS_HELP_STRING([--enable-valgrind-tests], 16 | [run self tests under valgrind]), 17 | [opt_valgrind_tests=$enableval], [opt_valgrind_tests=no]) 18 | 19 | # Run self-tests under valgrind? 20 | if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then 21 | AC_CHECK_PROGS(VALGRIND, valgrind) 22 | fi 23 | 24 | if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then 25 | opt_valgrind_tests=yes 26 | VALGRIND="$VALGRIND -q --error-exitcode=1 --leak-check=full \ 27 | --trace-children=yes --trace-children-skip=/usr/*,/bin/*" 28 | else 29 | opt_valgrind_tests=no 30 | VALGRIND= 31 | fi 32 | 33 | AC_MSG_CHECKING([whether self tests are run under valgrind]) 34 | AC_MSG_RESULT($opt_valgrind_tests) 35 | ]) 36 | -------------------------------------------------------------------------------- /protobuf-c/t/issue204/issue204.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "t/issue251/issue251.pb-c.h" 4 | 5 | int main(void) 6 | { 7 | TwoOneofs msg = TWO_ONEOFS__INIT; 8 | const ProtobufCFieldDescriptor *field; 9 | unsigned off1, off2, off_name; 10 | field = protobuf_c_message_descriptor_get_field_by_name( 11 | msg.base.descriptor, 12 | "first_oneof"); 13 | assert (field); 14 | off_name = field->offset; 15 | field = protobuf_c_message_descriptor_get_field( 16 | msg.base.descriptor, 17 | 10); 18 | assert (field); 19 | off1 = field->offset; 20 | field = protobuf_c_message_descriptor_get_field( 21 | msg.base.descriptor, 22 | 11); 23 | assert (field); 24 | off2 = field->offset; 25 | 26 | assert (off_name == off1); 27 | assert (off1 == off2); 28 | 29 | field = protobuf_c_message_descriptor_get_field_by_name( 30 | msg.base.descriptor, 31 | "second_oneof"); 32 | assert (field); 33 | off_name = field->offset; 34 | field = protobuf_c_message_descriptor_get_field( 35 | msg.base.descriptor, 36 | 20); 37 | assert (field); 38 | off1 = field->offset; 39 | field = protobuf_c_message_descriptor_get_field( 40 | msg.base.descriptor, 41 | 21); 42 | assert (field); 43 | off2 = field->offset; 44 | 45 | assert (off_name == off1); 46 | assert (off1 == off2); 47 | return EXIT_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /protobuf-c/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [1.5.0] - 2023-11-25 2 | 3 | ## What's Changed 4 | * Makefile.am: change link order by @franksinankaya in https://github.com/protobuf-c/protobuf-c/pull/486 5 | * GitHub actions fail on Windows due to missing unzip command by @britzl in https://github.com/protobuf-c/protobuf-c/pull/525 6 | * Export and install CMake targets by @morrisonlevi in https://github.com/protobuf-c/protobuf-c/pull/472 7 | * Use CMAKE_CURRENT_BINARY_DIR instead of CMAKE_BINARY_DIR by @KivApple in https://github.com/protobuf-c/protobuf-c/pull/482 8 | * remove deprecated functionality by @aviborg in https://github.com/protobuf-c/protobuf-c/pull/542 9 | * Avoid "unused variable" compiler warning by @rgriege in https://github.com/protobuf-c/protobuf-c/pull/545 10 | * Update autotools by @AtariDreams in https://github.com/protobuf-c/protobuf-c/pull/550 11 | * Support for new Google protobuf 22.x, 23.x releases by @edmonds in https://github.com/protobuf-c/protobuf-c/pull/673 12 | * Miscellaneous fixes by @edmonds in https://github.com/protobuf-c/protobuf-c/pull/675 13 | * Remove protobuf 2.x support by @edmonds in https://github.com/protobuf-c/protobuf-c/pull/676 14 | * Silence some compiler diagnostics by @edmonds in https://github.com/protobuf-c/protobuf-c/pull/677 15 | * Fixing MSVC build for Msbuild and Makefile generators by @MiguelBarro in https://github.com/protobuf-c/protobuf-c/pull/685 16 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | project(grpc-c) 3 | 4 | include_directories("${PROJECT_SOURCE_DIR}") 5 | include_directories("${PROJECT_SOURCE_DIR}/include") 6 | 7 | file(GLOB_RECURSE SRC_FILE "src/*.c") 8 | file(GLOB_RECURSE INC_FILE "include/*.h") 9 | 10 | # add the executable 11 | add_library(grpc-c-shared SHARED ${SRC_FILE}) 12 | add_library(grpc-c-static STATIC ${SRC_FILE}) 13 | 14 | SET_TARGET_PROPERTIES (grpc-c-shared PROPERTIES OUTPUT_NAME "grpc-c") 15 | SET_TARGET_PROPERTIES (grpc-c-static PROPERTIES OUTPUT_NAME "grpc-c") 16 | 17 | find_package(protobuf CONFIG REQUIRED) 18 | find_package(protobuf-c CONFIG REQUIRED) 19 | find_package(gRPC CONFIG REQUIRED) 20 | 21 | TARGET_LINK_LIBRARIES(grpc-c-shared PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf-c::protobuf-c gRPC::gpr gRPC::grpc++) 22 | TARGET_LINK_LIBRARIES(grpc-c-static PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf-c::protobuf-c gRPC::gpr gRPC::grpc++) 23 | 24 | # add the install targets 25 | install(TARGETS grpc-c-shared DESTINATION lib 26 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 27 | GROUP_EXECUTE GROUP_READ 28 | WORLD_EXECUTE WORLD_READ) 29 | 30 | install(TARGETS grpc-c-static DESTINATION lib 31 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 32 | GROUP_EXECUTE GROUP_READ 33 | WORLD_EXECUTE WORLD_READ) 34 | 35 | install (FILES ${INC_FILE} DESTINATION include) 36 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(grpc-c) 4 | 5 | set(CMAKE_VERBOSE_MAKEFILE ON) 6 | 7 | set(CMAKE_CXX_STANDARD 20) 8 | 9 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") 10 | set(CMAKE_C_FLAGS " -g -fPIC -fpermissive ") 11 | endif() 12 | 13 | set(CMAKE_THREAD_LIBS_INIT "-lpthread") 14 | 15 | execute_process( 16 | COMMAND bash -c "git rev-parse HEAD" 17 | OUTPUT_VARIABLE COMMIT_ID 18 | OUTPUT_STRIP_TRAILING_WHITESPACE 19 | ) 20 | execute_process( 21 | COMMAND bash -c "git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S'" 22 | OUTPUT_VARIABLE COMMIT_DATE 23 | OUTPUT_STRIP_TRAILING_WHITESPACE 24 | ) 25 | 26 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 27 | message("This is a Linux environment.") 28 | add_definitions(-DLINUX) 29 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 30 | message("This is a Windows environment.") 31 | add_definitions(-DWINDOWS) 32 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 33 | message("This is a macOS environment.") 34 | add_definitions(-DDARWIN) 35 | else() 36 | message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}.") 37 | endif() 38 | 39 | set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}") 40 | message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") 41 | 42 | set(CMAKE_INSTALL_PREFIX "publish") 43 | 44 | add_subdirectory(lib) 45 | add_subdirectory(compiler) 46 | add_subdirectory(example) 47 | -------------------------------------------------------------------------------- /lib/src/thread_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef GRPC_C_INTERNAL_THREAD_POOL_H 2 | #define GRPC_C_INTERNAL_THREAD_POOL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "list.h" 15 | #include 16 | 17 | #ifdef __cplusplus 18 | #if __cplusplus 19 | extern "C" { 20 | #endif 21 | #endif /* __cplusplus */ 22 | 23 | typedef void (*grpc_c_callback_func_t)(void *); 24 | 25 | typedef struct grpc_c_thread_callback_s { 26 | grpc_c_list_t list; 27 | grpc_c_callback_func_t func; 28 | void *data; 29 | } grpc_c_thread_callback_t; 30 | 31 | typedef struct grpc_c_thread_s { 32 | grpc_c_list_t list; 33 | pthread_t tid; 34 | } grpc_c_thread_t; 35 | 36 | typedef struct grpc_c_thread_pool_s { 37 | 38 | int max_threads; 39 | int stop_threads; 40 | int shutdown; 41 | 42 | gpr_mu lock; 43 | gpr_cv cv; 44 | 45 | grpc_c_list_t callbacks_head; 46 | grpc_c_list_t threads_head; 47 | } grpc_c_thread_pool_t; 48 | 49 | grpc_c_thread_pool_t *grpc_c_thread_pool_create(int n); 50 | 51 | int grpc_c_thread_pool_add(grpc_c_thread_pool_t *pool, 52 | grpc_c_callback_func_t func, void *arg); 53 | 54 | void grpc_c_thread_pool_shutdown(grpc_c_thread_pool_t *pool); 55 | 56 | #ifdef __cplusplus 57 | #if __cplusplus 58 | } 59 | #endif 60 | #endif /* __cplusplus */ 61 | 62 | #endif /* GRPC_C_INTERNAL_THREAD_POOL_H */ 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GRPC-C 2 | 3 | C implementation of [gRPC](http://www.grpc.io/) layered of top of core libgrpc. 4 | 5 | ## Prerequisites 6 | 7 | The current project is built based on [vcpkg + cmake] and supports multi-platform, such as windows, linux, macos. 8 | You need to prepare the [vcpkg + cmake] tool local platform first. 9 | Refer to the official website: https://github.com/microsoft/vcpkg 10 | 11 | ## Build 12 | 13 | ```sh 14 | git clone https://github.com/linimbus/grpc-c.git 15 | cd grpc-c 16 | #For linux/macos 17 | ./build_release.sh 18 | #For windows 19 | ./build_release.bat 20 | ``` 21 | 22 | 23 | If you see the following result, congratulations, you have compiled successfully. 24 | 25 | ``` 26 | -- Install configuration: "Release" 27 | -- Installing: /Users/linimbus/workspace/grpc-c/publish/lib/libgrpc-c.dylib 28 | -- Installing: /Users/linimbus/workspace/grpc-c/publish/lib/libgrpc-c.a 29 | -- Up-to-date: /Users/linimbus/workspace/grpc-c/publish/include/grpc-c.h 30 | -- Installing: /Users/linimbus/workspace/grpc-c/publish/bin/protoc-gen-grpc-c 31 | -- Installing: /Users/linimbus/workspace/grpc-c/publish/bin/example-foo 32 | ``` 33 | 34 | To run example code: 35 | 36 | ```sh 37 | export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 38 | cd publish/bin 39 | ./bin/foo_bin server 40 | ./bin/foo_bin client 41 | ``` 42 | 43 | ## Dependencies 44 | 45 | Maintain in vcpkg.json file 46 | 47 | ``` 48 | { 49 | "dependencies": [ 50 | "protobuf", 51 | { 52 | "name": "protobuf-c", 53 | "features": [] 54 | }, 55 | "grpc" 56 | ] 57 | } 58 | ``` 59 | -------------------------------------------------------------------------------- /protobuf-c/t/README: -------------------------------------------------------------------------------- 1 | There are two tests. 2 | 3 | "test-generated-code" is a simple test that can easily be adapted. 4 | "test-generated-code2" is a comprehensive test. 5 | 6 | -- 7 | 8 | If you have a quick problem, hack at "test-generated-code"; 9 | but i don't want that file to be too hard to navigate, 10 | so you must eventually add a test to "test-generated-code2". 11 | 12 | I appreciate additional test cases! 13 | Please submit them as issues in the tracking system, or email me. 14 | 15 | -- 16 | 17 | Here are the files involved in each test: 18 | 19 | test.proto Protobuf declarations for the simple test. 20 | test.pb-c.c Protobuf-C generated code based on test.proto 21 | test.pb-c.h Protobuf-C generated code based on test.proto 22 | 23 | test-full.proto Protobuf declarations for the exhaustive test. 24 | test-full.pb-c.c Protobuf-C generated code based on test-full.proto 25 | test-full.pb-c.h Protobuf-C generated code based on test-full.proto 26 | test-full.pb.cc Protobuf (C++) generated code based on test-full.proto 27 | test-full.pb.h Protobuf (C++) generated code based on test-full.proto 28 | 29 | generated-code/ 30 | test-generated-code.c Actual test code. 31 | test-generated-code Test executable. 32 | 33 | generated-code2/ 34 | cxx-generate-packed-data.cc C++ code to generated data to compare with C. 35 | cxx-generate-packed-data Program whichs generates data (using C++ api) 36 | test-full-cxx-output.inc Output of cxx-generate-packed-data. 37 | test-generated-code2.c Actual test code. 38 | test-generated-code2 Test executable. 39 | -------------------------------------------------------------------------------- /protobuf-c/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2023, Dave Benson and the protobuf-c authors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | The code generated by the protoc-gen-c code generator and by the 29 | protoc-c compiler is owned by the owner of the input files used when 30 | generating it. This code is not standalone and requires a support 31 | library to be linked with it. This support library is covered by the 32 | above license. 33 | -------------------------------------------------------------------------------- /compiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(protoc-gen-grpc-c) 4 | 5 | set(PROTO_C_FILE "protobuf-c.proto") 6 | set(PROTO_C_DIR "${PROJECT_SOURCE_DIR}/../protobuf-c/") 7 | 8 | include_directories("${PROJECT_SOURCE_DIR}/") 9 | include_directories("${PROTO_C_DIR}") 10 | 11 | find_package(protobuf CONFIG REQUIRED) 12 | find_package(protobuf-c CONFIG REQUIRED) 13 | 14 | add_custom_command( 15 | OUTPUT ${PROTO_C_DIR}/protobuf-c/protobuf-c.pb.cc 16 | COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out=${PROTO_C_DIR}/protobuf-c/ --proto_path=${PROTO_C_DIR}/protobuf-c/ ${PROTO_C_FILE} 17 | ) 18 | 19 | # add the executable 20 | add_executable(protoc-gen-grpc-c 21 | ${PROTO_C_DIR}/protobuf-c/protobuf-c.pb.cc 22 | ${PROTO_C_DIR}/protoc-c/c_bytes_field.cc 23 | ${PROTO_C_DIR}/protoc-c/c_enum.cc 24 | ${PROTO_C_DIR}/protoc-c/c_enum_field.cc 25 | ${PROTO_C_DIR}/protoc-c/c_extension.cc 26 | ${PROTO_C_DIR}/protoc-c/c_field.cc 27 | ${PROTO_C_DIR}/protoc-c/c_file.cc 28 | ${PROTO_C_DIR}/protoc-c/c_generator.cc 29 | ${PROTO_C_DIR}/protoc-c/c_helpers.cc 30 | ${PROTO_C_DIR}/protoc-c/c_message.cc 31 | ${PROTO_C_DIR}/protoc-c/c_message_field.cc 32 | ${PROTO_C_DIR}/protoc-c/c_primitive_field.cc 33 | ${PROTO_C_DIR}/protoc-c/c_service.cc 34 | ${PROTO_C_DIR}/protoc-c/c_string_field.cc 35 | grpc_c_file.cc 36 | grpc_c_generator.cc 37 | grpc_c_helpers.cc 38 | grpc_c_message.cc 39 | grpc_c_service.cc 40 | main.cc ) 41 | 42 | TARGET_LINK_LIBRARIES(protoc-gen-grpc-c PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf-c::protobuf-c ) 43 | 44 | install(TARGETS protoc-gen-grpc-c DESTINATION bin 45 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 46 | GROUP_EXECUTE GROUP_READ 47 | WORLD_EXECUTE WORLD_READ) -------------------------------------------------------------------------------- /protobuf-c/m4/ld-version-script.m4: -------------------------------------------------------------------------------- 1 | # ld-version-script.m4 serial 3 2 | dnl Copyright (C) 2008-2014 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Simon Josefsson 8 | 9 | # FIXME: The test below returns a false positive for mingw 10 | # cross-compiles, 'local:' statements does not reduce number of 11 | # exported symbols in a DLL. Use --disable-ld-version-script to work 12 | # around the problem. 13 | 14 | # gl_LD_VERSION_SCRIPT 15 | # -------------------- 16 | # Check if LD supports linker scripts, and define automake conditional 17 | # HAVE_LD_VERSION_SCRIPT if so. 18 | AC_DEFUN([gl_LD_VERSION_SCRIPT], 19 | [ 20 | AC_ARG_ENABLE([ld-version-script], 21 | AS_HELP_STRING([--enable-ld-version-script], 22 | [enable linker version script (default is enabled when possible)]), 23 | [have_ld_version_script=$enableval], []) 24 | if test -z "$have_ld_version_script"; then 25 | AC_MSG_CHECKING([if LD -Wl,--version-script works]) 26 | save_LDFLAGS="$LDFLAGS" 27 | LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" 28 | cat > conftest.map < conftest.map </dev/null || exit 1 6 | git update-index -q --ignore-submodules --refresh 7 | err=0 8 | 9 | if ! git diff-files --quiet --ignore-submodules 10 | then 11 | echo >&2 "Cannot $0: You have unstaged changes." 12 | err=1 13 | fi 14 | 15 | if ! git diff-index --cached --quiet --ignore-submodules HEAD -- 16 | then 17 | if [ $err = 0 ] 18 | then 19 | echo >&2 "Cannot $0: Your index contains uncommitted changes." 20 | else 21 | echo >&2 "Additionally, your index contains uncommitted changes." 22 | fi 23 | err=1 24 | fi 25 | 26 | if [ $err = 1 ] 27 | then 28 | test -n "$2" && echo >&2 "$2" 29 | exit 1 30 | fi 31 | } 32 | 33 | require_clean_work_tree 34 | 35 | if ! which doxygen >/dev/null; then 36 | echo "Error: doxygen is required" 37 | exit 1 38 | fi 39 | 40 | DOXYGEN_VERSION="$(doxygen --version)" 41 | 42 | DOC_BRANCH="gh-pages" 43 | ORIG_BRANCH="$(git rev-parse --abbrev-ref HEAD)" 44 | ORIG_COMMIT="$(git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty)" 45 | 46 | TOP="$(pwd)" 47 | export GIT_DIR="$TOP/.git" 48 | 49 | TMPDIR="$(mktemp --tmpdir=$TOP -d)" 50 | HTMLDIR="$TMPDIR/_build/html" 51 | INDEX_FILE="$GIT_DIR/index.${DOC_BRANCH}" 52 | 53 | rm -f "$INDEX_FILE" 54 | 55 | trap "{ cd $TOP; git checkout --force ${ORIG_BRANCH}; rm -f $INDEX_FILE; rm -rf $TMPDIR; }" EXIT 56 | 57 | cd "$TMPDIR" 58 | git reset --hard HEAD 59 | 60 | ./autogen.sh 61 | mkdir _build 62 | cd _build 63 | ../configure 64 | make html 65 | 66 | if ! git checkout "${DOC_BRANCH}"; then 67 | git checkout --orphan "${DOC_BRANCH}" 68 | fi 69 | 70 | touch "$HTMLDIR/.nojekyll" 71 | 72 | GIT_INDEX_FILE="$INDEX_FILE" GIT_WORK_TREE="$HTMLDIR" \ 73 | git add --no-ignore-removal . 74 | GIT_INDEX_FILE="$INDEX_FILE" GIT_WORK_TREE="$HTMLDIR" \ 75 | git commit -m "Rebuild html documentation from commit ${ORIG_COMMIT} using Doxygen ${DOXYGEN_VERSION}" 76 | -------------------------------------------------------------------------------- /lib/src/memory.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | #if __cplusplus 8 | extern "C" { 9 | #endif 10 | #endif /* __cplusplus */ 11 | 12 | /* 13 | * Signatures for protobuf allocate and free function callbacks 14 | */ 15 | typedef void *(*protobuf_c_alloc_func_t)(void *allocator_data, size_t size); 16 | typedef void (*protobuf_c_free_func_t)(void *allocator_data, void *data); 17 | 18 | void *grpc_malloc(size_t size) { return malloc(size); } 19 | 20 | void *grpc_realloc(void *ptr, size_t size) { return realloc(ptr, size); } 21 | 22 | void grpc_free(void *data) { free(data); } 23 | 24 | void *grpc_c_malloc(grpc_c_context_t *context, size_t size) { 25 | return grpc_malloc(size); 26 | } 27 | 28 | void grpc_c_free(grpc_c_context_t *context, void *data) { grpc_free(data); } 29 | 30 | /* 31 | * User provided allocate and free functions 32 | */ 33 | grpc_c_memory_alloc_func_t grpc_c_alloc_func = grpc_c_malloc; 34 | grpc_c_memory_free_func_t groc_c_free_func = grpc_c_free; 35 | 36 | /* 37 | * Sets allocate function callback 38 | */ 39 | void grpc_c_set_memory_function(grpc_c_memory_alloc_func_t allocfunc, 40 | grpc_c_memory_free_func_t freefunc) { 41 | grpc_c_alloc_func = allocfunc; 42 | groc_c_free_func = freefunc; 43 | } 44 | 45 | /* 46 | * Takes pointer to allocator and fills alloc, free functions if available. 47 | * Else return NULL 48 | */ 49 | ProtobufCAllocator * 50 | grpc_c_get_protobuf_c_allocator(grpc_c_context_t *context, 51 | ProtobufCAllocator *allocator) { 52 | if (grpc_c_alloc_func && groc_c_free_func && allocator) { 53 | 54 | allocator->alloc = (protobuf_c_alloc_func_t)grpc_c_alloc_func; 55 | allocator->free = (protobuf_c_free_func_t)groc_c_free_func; 56 | 57 | if (context) { 58 | allocator->allocator_data = (void *)context; 59 | } else { 60 | allocator->allocator_data = NULL; 61 | } 62 | 63 | return allocator; 64 | } 65 | 66 | return NULL; 67 | } 68 | 69 | #ifdef __cplusplus 70 | #if __cplusplus 71 | } 72 | #endif 73 | #endif /* __cplusplus */ 74 | -------------------------------------------------------------------------------- /protobuf-c/t/generated-code/test-generated-code.c: -------------------------------------------------------------------------------- 1 | #ifdef PROTO3 2 | #include "t/test-proto3.pb-c.h" 3 | #else 4 | #include "t/test.pb-c.h" 5 | #endif 6 | #include 7 | #include 8 | #include 9 | 10 | int main(void) 11 | { 12 | Foo__Person__PhoneNumber__Comment comment = FOO__PERSON__PHONE_NUMBER__COMMENT__INIT; 13 | Foo__Person__PhoneNumber phone = FOO__PERSON__PHONE_NUMBER__INIT; 14 | Foo__Person__PhoneNumber *phone_numbers[1]; 15 | Foo__Person person = FOO__PERSON__INIT; 16 | Foo__Person *person2; 17 | unsigned char simple_pad[8]; 18 | size_t size, size2; 19 | unsigned char *packed; 20 | ProtobufCBufferSimple bs = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_pad); 21 | 22 | comment.comment = "protobuf-c guy"; 23 | 24 | phone.number = "1234"; 25 | #ifndef PROTO3 26 | phone.has_type = 1; 27 | #endif 28 | phone.type = FOO__PERSON__PHONE_TYPE__WORK; 29 | phone.comment = &comment; 30 | 31 | phone_numbers[0] = ☎ 32 | 33 | person.name = "dave b"; 34 | person.id = 42; 35 | person.n_phone = 1; 36 | person.phone = phone_numbers; 37 | 38 | size = foo__person__get_packed_size (&person); 39 | packed = malloc (size); 40 | assert (packed); 41 | 42 | size2 = foo__person__pack (&person, packed); 43 | 44 | assert (size == size2); 45 | foo__person__pack_to_buffer (&person, &bs.base); 46 | assert (bs.len == size); 47 | assert (memcmp (bs.data, packed, size) == 0); 48 | 49 | PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&bs); 50 | 51 | person2 = foo__person__unpack (NULL, size, packed); 52 | assert (person2 != NULL); 53 | assert (person2->id == 42); 54 | #ifndef PROTO3 55 | assert (person2->email == NULL); 56 | #else 57 | assert (strcmp (person2->email, "") == 0); 58 | #endif 59 | assert (strcmp (person2->name, "dave b") == 0); 60 | assert (person2->n_phone == 1); 61 | assert (strcmp (person2->phone[0]->number, "1234") == 0); 62 | assert (person2->phone[0]->type == FOO__PERSON__PHONE_TYPE__WORK); 63 | assert (strcmp (person2->phone[0]->comment->comment, "protobuf-c guy") == 0); 64 | 65 | foo__person__free_unpacked (person2, NULL); 66 | free (packed); 67 | 68 | printf ("test succeeded.\n"); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /lib/src/list.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __GRPC_C_LIST_H__ 3 | #define __GRPC_C_LIST_H__ 4 | 5 | #ifdef __cplusplus 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | #endif /* __cplusplus */ 10 | 11 | #define GRPC_LIST_EMPTY(head) ((head)->next == (head)) 12 | 13 | #define GRPC_LIST_NEXT(item) ((item)->next) 14 | 15 | #define GRPC_LIST_BEFORE(item) ((item)->prev) 16 | 17 | #define GRPC_LIST_INIT(head) \ 18 | (head)->next = (head); \ 19 | (head)->prev = (head); 20 | 21 | #define GRPC_LIST_ADD(item, where) \ 22 | (item)->next = (where)->next; \ 23 | (item)->prev = (where); \ 24 | (where)->next->prev = (item); \ 25 | (where)->next = (item); 26 | 27 | #define GRPC_LIST_ADD_BEFORE(item, where) \ 28 | (item)->prev = (where)->prev; \ 29 | (item)->next = (where); \ 30 | (where)->prev->next = (item); \ 31 | (where)->prev = (item); 32 | 33 | #define GRPC_LIST_REMOVE(item) \ 34 | (item)->next->prev = (item)->prev; \ 35 | (item)->prev->next = (item)->next; 36 | 37 | #define GRPC_LIST_OFFSET(item, struct, stitem) \ 38 | (struct *)((char *)item - (char *)(&((struct *)0)->stitem)) 39 | 40 | #define GRPC_LIST_TRAVERSAL(pstItem, pstHead) \ 41 | for ((pstItem) = (pstHead)->next; (pstItem) != (pstHead); \ 42 | (pstItem) = (pstItem)->next) 43 | 44 | #define GRPC_LIST_TRAVERSAL_REMOVE(pstItem, pstTemp, pstHead) \ 45 | for ((pstItem) = (pstHead)->next, (pstTemp) = (pstItem)->next; \ 46 | (pstItem) != (pstHead); \ 47 | (pstItem) = (pstTemp), (pstTemp) = (pstTemp)->next) 48 | 49 | #ifdef __cplusplus 50 | #if __cplusplus 51 | } 52 | #endif 53 | #endif /* __cplusplus */ 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /protobuf-c/t/version/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, The protobuf-c authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "protobuf-c.h" 36 | 37 | int 38 | main(void) 39 | { 40 | printf("PACKAGE_VERSION = %s\n", 41 | PACKAGE_VERSION); 42 | printf("PROTOBUF_C_VERSION = %s\n", 43 | PROTOBUF_C_VERSION); 44 | printf("PROTOBUF_C_VERSION_NUMBER = %d\n", 45 | PROTOBUF_C_VERSION_NUMBER); 46 | printf("protobuf_c_version() = %s\n", 47 | protobuf_c_version()); 48 | printf("protobuf_c_version_number() = %d\n", 49 | protobuf_c_version_number()); 50 | 51 | assert(strcmp(PACKAGE_VERSION, PROTOBUF_C_VERSION) == 0); 52 | assert(strcmp(PROTOBUF_C_VERSION, protobuf_c_version()) == 0); 53 | assert(PROTOBUF_C_VERSION_NUMBER == protobuf_c_version_number()); 54 | 55 | return EXIT_SUCCESS; 56 | } 57 | -------------------------------------------------------------------------------- /lib/src/metadata_array.c: -------------------------------------------------------------------------------- 1 | #include "metadata_array.h" 2 | #include 3 | 4 | #ifdef __cplusplus 5 | #if __cplusplus 6 | extern "C" { 7 | #endif 8 | #endif /* __cplusplus */ 9 | 10 | /* 11 | * Initializes metadata array 12 | */ 13 | void grpc_c_metadata_array_init(grpc_c_metadata_array_t *array) { 14 | grpc_metadata_array_init(array); 15 | } 16 | 17 | /* 18 | * Destroys metadata array after destroying metadata 19 | */ 20 | void grpc_c_metadata_array_destroy(grpc_c_metadata_array_t *array) { 21 | /* 22 | * Free metadata keyvalue pairs 23 | */ 24 | while (array->count > 0) { 25 | grpc_slice_unref(array->metadata[array->count - 1].key); 26 | grpc_slice_unref(array->metadata[array->count - 1].value); 27 | array->count -= 1; 28 | } 29 | grpc_metadata_array_destroy(array); 30 | } 31 | 32 | int grpc_c_metadata_array_get(grpc_c_metadata_array_t *mdarray, const char *key, 33 | char *value, size_t len) { 34 | int i; 35 | char *value_src; 36 | 37 | if (key == NULL || value == NULL || len == 0) { 38 | GRPC_C_ERR("Invalid key or value"); 39 | return GRPC_C_ERR_FAIL; 40 | } 41 | 42 | for (i = 0; i < mdarray->count; i++) { 43 | 44 | if (grpc_slice_str_cmp(mdarray->metadata[i].key, key)) { 45 | continue; 46 | } 47 | 48 | value_src = grpc_slice_to_c_string(mdarray->metadata[i].value); 49 | strncpy(value, value_src, len); 50 | gpr_free(value_src); 51 | 52 | return GRPC_C_OK; 53 | } 54 | 55 | return GRPC_C_ERR_FAIL; 56 | } 57 | 58 | /* 59 | * Inserts given keyvalue pair into metadata array. Returns 0 on success and 1 60 | * on failure 61 | */ 62 | int grpc_c_metadata_array_add(grpc_c_metadata_array_t *mdarray, const char *key, 63 | const char *value) { 64 | if (key == NULL || value == NULL) { 65 | GRPC_C_ERR("Invalid key or value"); 66 | return GRPC_C_ERR_FAIL; 67 | } 68 | 69 | /* 70 | * Make space to hold metada 71 | */ 72 | mdarray->capacity += 1; 73 | mdarray->count += 1; 74 | if (mdarray->metadata != NULL) { 75 | mdarray->metadata = gpr_realloc(mdarray->metadata, 76 | mdarray->capacity * sizeof(grpc_metadata)); 77 | } else { 78 | mdarray->metadata = gpr_malloc(sizeof(grpc_metadata)); 79 | } 80 | 81 | if (mdarray->metadata == NULL) { 82 | GRPC_C_ERR("Failed to (re)allocate memory for metadata"); 83 | return GRPC_C_ERR_NOMEM; 84 | } 85 | 86 | mdarray->metadata[mdarray->count - 1].key = 87 | grpc_slice_from_copied_string(key); 88 | mdarray->metadata[mdarray->count - 1].value = 89 | grpc_slice_from_copied_string(value); 90 | 91 | return GRPC_C_OK; 92 | } 93 | 94 | #ifdef __cplusplus 95 | #if __cplusplus 96 | } 97 | #endif 98 | #endif /* __cplusplus */ 99 | -------------------------------------------------------------------------------- /protobuf-c/t/generated-code2/common-test-arrays.h: -------------------------------------------------------------------------------- 1 | 2 | /* data included from the c++ packed-data generator, 3 | and from the c test code. */ 4 | 5 | #define THOUSAND 1000 6 | #define MILLION 1000000 7 | #define BILLION 1000000000LL 8 | #define TRILLION 1000000000000LL 9 | #define QUADRILLION 1000000000000000LL 10 | #define QUINTILLION 1000000000000000000LL 11 | 12 | int32_t int32_arr0[2] = { -1, 1 }; 13 | int32_t int32_arr1[5] = { 42, 666, -1123123, 0, 47 }; 14 | int32_t int32_arr_min_max[2] = { INT32_MIN, INT32_MAX }; 15 | 16 | uint32_t uint32_roundnumbers[4] = { BILLION, MILLION, 1, 0 }; 17 | uint32_t uint32_0_max[2] = { 0, UINT32_MAX }; 18 | 19 | int64_t int64_roundnumbers[15] = { -QUINTILLION, -QUADRILLION, -TRILLION, 20 | -BILLION, -MILLION, -THOUSAND, 21 | 1, 22 | THOUSAND, MILLION, BILLION, 23 | TRILLION, QUADRILLION, QUINTILLION }; 24 | int64_t int64_min_max[2] = { INT64_MIN, INT64_MAX }; 25 | 26 | uint64_t uint64_roundnumbers[9] = { 1, 27 | THOUSAND, MILLION, BILLION, 28 | TRILLION, QUADRILLION, QUINTILLION }; 29 | uint64_t uint64_0_1_max[3] = { 0, 1, UINT64_MAX }; 30 | uint64_t uint64_random[] = {0, 31 | 666, 32 | 4200000000ULL, 33 | 16ULL * (uint64_t) QUINTILLION + 33 }; 34 | 35 | #define FLOATING_POINT_RANDOM \ 36 | -1000.0, -100.0, -42.0, 0, 666, 131313 37 | float float_random[] = { FLOATING_POINT_RANDOM }; 38 | double double_random[] = { FLOATING_POINT_RANDOM }; 39 | 40 | protobuf_c_boolean boolean_0[] = {0 }; 41 | protobuf_c_boolean boolean_1[] = {1 }; 42 | protobuf_c_boolean boolean_random[] = {0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1,1,0,1,1,0 }; 43 | 44 | TEST_ENUM_SMALL_TYPE_NAME enum_small_0[] = { TEST_ENUM_SMALL(VALUE) }; 45 | TEST_ENUM_SMALL_TYPE_NAME enum_small_1[] = { TEST_ENUM_SMALL(OTHER_VALUE) }; 46 | #define T(v) (TEST_ENUM_SMALL_TYPE_NAME)(v) 47 | TEST_ENUM_SMALL_TYPE_NAME enum_small_random[] = {T(0),T(1),T(1),T(0),T(0),T(1),T(1),T(1),T(0),T(0),T(0),T(0),T(0),T(1),T(1),T(1),T(1),T(1),T(1),T(0),T(1),T(1),T(0),T(1),T(1),T(0) }; 48 | #undef T 49 | 50 | #define T(v) (TEST_ENUM_TYPE_NAME)(v) 51 | TEST_ENUM_TYPE_NAME enum_0[] = { T(0) }; 52 | TEST_ENUM_TYPE_NAME enum_1[] = { T(1) }; 53 | TEST_ENUM_TYPE_NAME enum_random[] = { 54 | T(0), T(268435455), T(127), T(16384), T(16383), 55 | T(2097152), T(2097151), T(128), T(268435456), 56 | T(0), T(2097152), T(268435455), T(127), T(16383), T(16384) }; 57 | #undef T 58 | 59 | const char *repeated_strings_0[] = { "onestring" }; 60 | const char *repeated_strings_1[] = { "two", "string" }; 61 | const char *repeated_strings_2[] = { "many", "tiny", "little", "strings", "should", "be", "handled" }; 62 | const char *repeated_strings_3[] = { "one very long strings XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }; 63 | -------------------------------------------------------------------------------- /protobuf-c/TODO: -------------------------------------------------------------------------------- 1 | ---------------------- 2 | --- IMPORTANT TODO --- 3 | ---------------------- 4 | 5 | -------------------- 6 | --- NEEDED TESTS --- 7 | -------------------- 8 | - test: 9 | - service method lookups 10 | - out-of-order fields in messages (ie if the number isn't ascending) 11 | - gaps in numbers: check that the number of ranges is correct 12 | - default values 13 | - message unpack alloc failures when allocating new slab 14 | - message unpack alloc failures when allocating unknown field buffers 15 | - packed message corruption. 16 | - meta-todo: get a list of all the unpack errors together to check off 17 | 18 | --------------------- 19 | --- DOCUMENTATION --- 20 | --------------------- 21 | Document: 22 | - services 23 | - check over documentation again 24 | 25 | -------------------------- 26 | --- LOW PRIORITY STUFF --- 27 | -------------------------- 28 | - support Group (whatever it is) 29 | - proper support for extensions 30 | - slot for ranges in descriptor 31 | - extends is implemented as c-style function 32 | whose name is built from the package, the base message type-name 33 | and the member. which takes the base message and returns the 34 | value, if it is found in "unknown_values". 35 | boolean package__extension_member_name__get(Message *message, 36 | type *out); 37 | void package__extension_member_name__set_raw(type in, 38 | ProtobufCUnknownValue *to_init); 39 | 40 | ------------------------------------ 41 | --- EXTREMELY LOW PRIORITY STUFF --- 42 | ------------------------------------ 43 | - stop using qsort in the code generator: find some c++ish way to do it 44 | 45 | ---------------------------------------------- 46 | --- ISSUES WE ARE PROBABLY GOING TO IGNORE --- 47 | ---------------------------------------------- 48 | - strings may not contain NULs 49 | 50 | ------------------------- 51 | --- IDEAS TO CONSIDER --- 52 | ------------------------- 53 | 54 | - optimization: structures without repeated members could skip 55 | the ScannedMember phase 56 | 57 | - optimization: a way to ignore unknown-fields when unpacking 58 | 59 | - optimization: certain functions are not well setup for WORDSIZE==64; 60 | especially the int64 routines are inefficient that way. 61 | The best might be an internal #define WORDSIZE (sizeof(long)*8)" 62 | except w/ a real constant there, one that the preprocessor can use. 63 | I think the functions in protobuf-c.c are already tagged. 64 | 65 | - lifetime functions for messages: 66 | message__new() 67 | return a new message using an allocator with standard allocation policy 68 | message__unpack_onto(...) 69 | unpack onto an initialized message 70 | message__clear(...) 71 | clears all allocations, does not free the message itself 72 | message__free(...) 73 | free the message. 74 | [yeah, right: after typing it out, i see it's way too complicated] 75 | 76 | - switching to pure C. 77 | - Rewrite the code-generator in C, including the parser. 78 | - This would have the huge advantage that we could use ".proto" files 79 | directly, instead of having to invoke the compilers. 80 | - keep in a separate c file for static linking optimziation purposes 81 | - need alignment tests 82 | - the CAVEATS should discuss our structure-packing assumptions 83 | -------------------------------------------------------------------------------- /protobuf-c/m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # This program is free software: you can redistribute it and/or modify it 33 | # under the terms of the GNU General Public License as published by the 34 | # Free Software Foundation, either version 3 of the License, or (at your 35 | # option) any later version. 36 | # 37 | # This program is distributed in the hope that it will be useful, but 38 | # WITHOUT ANY WARRANTY; without even the implied warranty of 39 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 40 | # Public License for more details. 41 | # 42 | # You should have received a copy of the GNU General Public License along 43 | # with this program. If not, see . 44 | # 45 | # As a special exception, the respective Autoconf Macro's copyright owner 46 | # gives unlimited permission to copy, distribute and modify the configure 47 | # scripts that are the output of Autoconf when processing the Macro. You 48 | # need not follow the terms of the GNU General Public License when using 49 | # or distributing such scripts, even though portions of the text of the 50 | # Macro appear in them. The GNU General Public License (GPL) does govern 51 | # all other use of the material that constitutes the Autoconf Macro. 52 | # 53 | # This special exception to the GPL applies to versions of the Autoconf 54 | # Macro released by the Autoconf Archive. When you make and distribute a 55 | # modified version of the Autoconf Macro, you may extend this special 56 | # exception to the GPL to apply to your modified version as well. 57 | 58 | #serial 5 59 | 60 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 61 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 62 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 63 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 64 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 65 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 66 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 67 | [AS_VAR_SET(CACHEVAR,[yes])], 68 | [AS_VAR_SET(CACHEVAR,[no])]) 69 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 70 | AS_VAR_IF(CACHEVAR,yes, 71 | [m4_default([$2], :)], 72 | [m4_default([$3], :)]) 73 | AS_VAR_POPDEF([CACHEVAR])dnl 74 | ])dnl AX_CHECK_COMPILE_FLAGS 75 | -------------------------------------------------------------------------------- /protobuf-c/protobuf-c/protobuf-c.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, the protobuf-c authors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | syntax = "proto2"; 31 | import "google/protobuf/descriptor.proto"; 32 | 33 | // We never need to generate protobuf-c.pb-c.{c,h}, the options are used 34 | // only by protoc-gen-c, never by the protobuf-c runtime itself 35 | option (pb_c_file).no_generate = true; 36 | 37 | message ProtobufCFileOptions { 38 | // Suppresses pb-c.{c,h} file output completely. 39 | optional bool no_generate = 1 [default = false]; 40 | 41 | // Generate helper pack/unpack functions? 42 | // For backwards compatibility, if this field is not explicitly set, 43 | // only top-level message pack/unpack functions will be generated 44 | optional bool gen_pack_helpers = 2 [default = true]; 45 | 46 | // Generate helper init message functions? 47 | optional bool gen_init_helpers = 3 [default = true]; 48 | 49 | // Use const char * instead of char * for string fields 50 | optional bool const_strings = 4 [default = false]; 51 | 52 | // For oneof fields, set ProtobufCFieldDescriptor name field to the 53 | // name of the containing oneof, instead of the field name 54 | optional bool use_oneof_field_name = 5 [default = false]; 55 | 56 | // Overrides the package name, if present 57 | optional string c_package = 6; 58 | } 59 | 60 | extend google.protobuf.FileOptions { 61 | optional ProtobufCFileOptions pb_c_file = 1019; 62 | } 63 | 64 | message ProtobufCMessageOptions { 65 | // Overrides the parent setting only if present 66 | optional bool gen_pack_helpers = 1 [default = false]; 67 | 68 | // Overrides the parent setting only if present 69 | optional bool gen_init_helpers = 2 [default = true]; 70 | 71 | // Reserved base message field name 72 | optional string base_field_name = 3 [default = "base"]; 73 | } 74 | 75 | extend google.protobuf.MessageOptions { 76 | optional ProtobufCMessageOptions pb_c_msg = 1019; 77 | } 78 | 79 | message ProtobufCFieldOptions { 80 | // Treat string as bytes in generated code 81 | optional bool string_as_bytes = 1 [default = false]; 82 | } 83 | 84 | extend google.protobuf.FieldOptions { 85 | optional ProtobufCFieldOptions pb_c_field = 1019; 86 | } 87 | -------------------------------------------------------------------------------- /lib/src/stream_ops.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GRPC_C_INTERNAL_STREAM_OPS_H 3 | #define GRPC_C_INTERNAL_STREAM_OPS_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "context.h" 18 | #include "metadata_array.h" 19 | 20 | grpc_c_stream_read_t *grpc_c_stream_reader_init(int streaming); 21 | 22 | void grpc_c_stream_reader_destory(grpc_c_stream_read_t *reader); 23 | 24 | grpc_c_stream_write_t *grpc_c_stream_writer_init(int streaming); 25 | 26 | void grpc_c_stream_writer_destory(grpc_c_stream_write_t *writer); 27 | 28 | /* 29 | * Read handler. Returns data if already available or puts in a request for 30 | * data 31 | */ 32 | int grpc_c_stream_read(grpc_call *call, grpc_c_stream_read_t *reader, 33 | grpc_byte_buffer **output, uint32_t flags, long timeout); 34 | 35 | /* 36 | * Sends given data into the stream. If previous write is still pending, 37 | * return GRPC_C_WRITE_PENDING 38 | */ 39 | int grpc_c_stream_write(grpc_call *call, grpc_c_stream_write_t *writer, 40 | grpc_byte_buffer *input, uint32_t flags, long timeout); 41 | 42 | /* 43 | * Finishes write from client 44 | */ 45 | int grpc_c_stream_write_done(grpc_call *call, grpc_c_stream_write_t *writer, 46 | uint32_t flags, long timeout); 47 | 48 | grpc_c_stream_status_t *grpc_c_status_init(int is_client); 49 | 50 | void grpc_c_status_destory(grpc_c_stream_status_t *status); 51 | 52 | /* 53 | * Finishes stream from client 54 | */ 55 | int grpc_c_status_send(grpc_call *call, grpc_c_stream_status_t *status, 56 | grpc_c_status_t *status_input, uint32_t flags); 57 | 58 | /* 59 | * Finishes stream from server 60 | */ 61 | int grpc_c_status_recv(grpc_call *call, grpc_c_stream_status_t *status, 62 | grpc_c_status_t *status_output, uint32_t flags); 63 | 64 | int grpc_c_status_trailing_metadata_set(grpc_c_stream_status_t *status, 65 | const char *key, const char *value); 66 | 67 | int grpc_c_status_trailing_metadata_get(grpc_c_stream_status_t *status, 68 | const char *key, char *value, 69 | size_t len); 70 | 71 | int grpc_c_initial_metadata_set(grpc_c_initial_metadata_t *init_metadata, 72 | const char *key, const char *value); 73 | 74 | int grpc_c_initial_metadata_get(grpc_c_initial_metadata_t *init_metadata, 75 | const char *key, char *value, size_t len); 76 | 77 | grpc_c_initial_metadata_t *grpc_c_initial_metadata_init(int is_send); 78 | 79 | void grpc_c_initial_metadata_destory(grpc_c_initial_metadata_t *init_metadata); 80 | 81 | int grpc_c_send_initial_metadata(grpc_call *call, 82 | grpc_c_initial_metadata_t *init_metadata, 83 | long timeout); 84 | 85 | int grpc_c_recv_initial_metadata(grpc_call *call, 86 | grpc_c_initial_metadata_t *init_metadata, 87 | long timeout); 88 | 89 | grpc_c_recv_close_t *grpc_c_server_recv_close_init(); 90 | 91 | void grpc_c_server_recv_close_destory(grpc_c_recv_close_t *recv_close); 92 | 93 | int grpc_c_server_recv_close(grpc_call *call, grpc_c_recv_close_t *recv_close); 94 | 95 | int grpc_c_server_recv_close_wait(grpc_c_recv_close_t *recv_close); 96 | 97 | /* 98 | * Calculate timeout spec from millisecs 99 | */ 100 | gpr_timespec grpc_c_deadline_from_timeout(long timeout); 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /compiler/grpc_c_helpers.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GRPC_C_INTERNAL_COMPILER_C_HELPERS_H 64 | #define GRPC_C_INTERNAL_COMPILER_C_HELPERS_H 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | 73 | namespace google { 74 | namespace protobuf { 75 | namespace compiler { 76 | namespace grpc_c { 77 | 78 | // Strips ".proto 79 | std::string StripProto(const std::string &filename); 80 | 81 | // Convert to Grpc C 82 | std::string FullNameToGrpcC(const std::string &full_name); 83 | 84 | } // namespace grpc_c 85 | } // namespace compiler 86 | } // namespace protobuf 87 | 88 | } // namespace google 89 | #endif // GRPC_C_INTERNAL_COMPILER_C_HELPERS_H 90 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_extension.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #include 64 | #include 65 | #include 66 | 67 | namespace google { 68 | namespace protobuf { 69 | namespace compiler { 70 | namespace c { 71 | 72 | ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, 73 | const std::string& dllexport_decl) 74 | : descriptor_(descriptor), 75 | dllexport_decl_(dllexport_decl) { 76 | } 77 | 78 | ExtensionGenerator::~ExtensionGenerator() {} 79 | 80 | void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) { 81 | } 82 | 83 | void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { 84 | } 85 | 86 | } // namespace c 87 | } // namespace compiler 88 | } // namespace protobuf 89 | 90 | } // namespace google 91 | -------------------------------------------------------------------------------- /compiler/grpc_c_helpers.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #include 64 | #include 65 | #include // for snprintf 66 | #include 67 | 68 | #include "grpc_c_helpers.h" 69 | #include 70 | 71 | namespace google { 72 | namespace protobuf { 73 | namespace compiler { 74 | namespace grpc_c { 75 | 76 | std::string StripProto(const std::string &filename) { 77 | return c::StripSuffixString(filename, ".proto"); 78 | } 79 | 80 | std::string FullNameToGrpcC(const std::string &full_name) { 81 | std::vector pieces; 82 | c::SplitStringUsing(full_name, ".", &pieces); 83 | std::string rv = ""; 84 | for (unsigned i = 0; i < pieces.size(); i++) { 85 | if (pieces[i] == "") 86 | continue; 87 | if (rv != "") 88 | rv += "__"; 89 | rv += pieces[i]; 90 | } 91 | return rv; 92 | } 93 | 94 | } // namespace grpc_c 95 | } // namespace compiler 96 | } // namespace protobuf 97 | } // namespace google 98 | -------------------------------------------------------------------------------- /protobuf-c/configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.63]) 2 | 3 | AC_INIT([protobuf-c], 4 | [1.5.0], 5 | [https://github.com/protobuf-c/protobuf-c/issues], 6 | [protobuf-c], 7 | [https://github.com/protobuf-c/protobuf-c]) 8 | PACKAGE_DESCRIPTION="Protocol Buffers implementation in C" 9 | AC_SUBST(PACKAGE_DESCRIPTION) 10 | 11 | AC_CONFIG_SRCDIR([protobuf-c/protobuf-c.c]) 12 | AC_CONFIG_AUX_DIR([build-aux]) 13 | AM_INIT_AUTOMAKE([foreign 1.11 -Wall -Wno-portability silent-rules subdir-objects]) 14 | AC_PROG_CC 15 | AC_PROG_CXX 16 | AC_PROG_LN_S 17 | AC_PROG_MKDIR_P 18 | AC_USE_SYSTEM_EXTENSIONS 19 | AC_SYS_LARGEFILE 20 | AC_CONFIG_MACRO_DIR([m4]) 21 | AM_SILENT_RULES([yes]) 22 | LT_INIT 23 | 24 | AC_CONFIG_HEADERS(config.h) 25 | AC_CONFIG_FILES([Makefile protobuf-c/libprotobuf-c.pc]) 26 | 27 | my_CFLAGS="\ 28 | -Wall \ 29 | -Wchar-subscripts \ 30 | -Wdeclaration-after-statement \ 31 | -Wformat-security \ 32 | -Wmissing-declarations \ 33 | -Wmissing-prototypes \ 34 | -Wnested-externs \ 35 | -Wpointer-arith \ 36 | -Wshadow \ 37 | -Wsign-compare \ 38 | -Wstrict-prototypes \ 39 | -Wtype-limits \ 40 | " 41 | AX_CHECK_COMPILE_FLAG(["-Werror=incompatible-pointer-types"], 42 | [my_CFLAGS="$my_CFLAGS -Werror=incompatible-pointer-types"]) 43 | AX_CHECK_COMPILE_FLAG(["-Werror=int-conversion"], 44 | [my_CFLAGS="$my_CFLAGS -Werror=int-conversion"]) 45 | AX_CHECK_COMPILE_FLAG(["-Wnull-dereference"], 46 | [my_CFLAGS="$my_CFLAGS -Wnull-dereference"]) 47 | AC_SUBST([my_CFLAGS]) 48 | 49 | AC_CHECK_PROGS([DOXYGEN], [doxygen]) 50 | AM_CONDITIONAL([HAVE_DOXYGEN], 51 | [test -n "$DOXYGEN"]) 52 | AM_COND_IF([HAVE_DOXYGEN], 53 | [AC_CONFIG_FILES([Doxyfile]) 54 | DOXYGEN_INPUT="${srcdir}/protobuf-c" 55 | AC_SUBST(DOXYGEN_INPUT) 56 | ]) 57 | 58 | PKG_PROG_PKG_CONFIG 59 | if test -n "$PKG_CONFIG"; then 60 | # Horrible hack for systems where the pkg-config install directory is simply wrong! 61 | if $PKG_CONFIG --variable=pc_path pkg-config 2>/dev/null | grep -q /libdata/; then 62 | PKG_INSTALLDIR(['${prefix}/libdata/pkgconfig']) 63 | else 64 | PKG_INSTALLDIR 65 | fi 66 | fi 67 | 68 | AC_ARG_ENABLE([protoc], 69 | AS_HELP_STRING([--disable-protoc], [Disable building protoc_c (also disables tests)])) 70 | if test "x$enable_protoc" != "xno"; then 71 | AC_LANG_PUSH([C++]) 72 | AX_CXX_COMPILE_STDCXX(17, noext, mandatory) 73 | PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0]) 74 | 75 | save_CPPFLAGS="$CPPFLAGS" 76 | CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS" 77 | AC_CHECK_HEADERS([google/protobuf/compiler/command_line_interface.h], 78 | [], 79 | [AC_MSG_ERROR([required protobuf header file not found])]) 80 | CPPFLAGS="$save_CPPFLAGS" 81 | 82 | AC_ARG_VAR([PROTOC], [protobuf compiler command]) 83 | AC_PATH_PROG([PROTOC], [protoc], [], 84 | [`$PKG_CONFIG --variable=exec_prefix protobuf`/bin:$PATH]) 85 | if test -z "$PROTOC"; then 86 | AC_MSG_ERROR([Please install the protobuf compiler from https://code.google.com/p/protobuf/.]) 87 | fi 88 | 89 | PROTOBUF_VERSION="$($PROTOC --version)" 90 | 91 | else 92 | PROTOBUF_VERSION="not required, not building compiler" 93 | fi 94 | 95 | AM_CONDITIONAL([BUILD_COMPILER], [test "x$enable_protoc" != "xno"]) 96 | AM_CONDITIONAL([CROSS_COMPILING], [test "x$cross_compiling" != "xno"]) 97 | 98 | gl_LD_VERSION_SCRIPT 99 | 100 | gl_VALGRIND_TESTS 101 | 102 | MY_CODE_COVERAGE 103 | 104 | AC_C_BIGENDIAN 105 | 106 | AC_OUTPUT 107 | AC_MSG_RESULT([ 108 | $PACKAGE $VERSION 109 | 110 | CC: ${CC} 111 | CFLAGS: ${CFLAGS} 112 | CXX: ${CXX} 113 | CXXFLAGS: ${CXXFLAGS} 114 | LDFLAGS: ${LDFLAGS} 115 | LIBS: ${LIBS} 116 | 117 | prefix: ${prefix} 118 | sysconfdir: ${sysconfdir} 119 | libdir: ${libdir} 120 | includedir: ${includedir} 121 | pkgconfigdir: ${pkgconfigdir} 122 | 123 | bigendian: ${ac_cv_c_bigendian} 124 | protobuf version: ${PROTOBUF_VERSION} 125 | ]) 126 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_message_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace compiler { 73 | namespace c { 74 | 75 | class MessageFieldGenerator : public FieldGenerator { 76 | public: 77 | explicit MessageFieldGenerator(const FieldDescriptor* descriptor); 78 | ~MessageFieldGenerator(); 79 | 80 | // implements FieldGenerator --------------------------------------- 81 | void GenerateStructMembers(io::Printer* printer) const; 82 | void GenerateDescriptorInitializer(io::Printer* printer) const; 83 | std::string GetDefaultValue(void) const; 84 | void GenerateStaticInit(io::Printer* printer) const; 85 | }; 86 | 87 | 88 | } // namespace c 89 | } // namespace compiler 90 | } // namespace protobuf 91 | 92 | } // namespace google 93 | #endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__ 94 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_primitive_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace compiler { 73 | namespace c { 74 | 75 | class PrimitiveFieldGenerator : public FieldGenerator { 76 | public: 77 | explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); 78 | ~PrimitiveFieldGenerator(); 79 | 80 | // implements FieldGenerator --------------------------------------- 81 | void GenerateStructMembers(io::Printer* printer) const; 82 | void GenerateDescriptorInitializer(io::Printer* printer) const; 83 | std::string GetDefaultValue(void) const; 84 | void GenerateStaticInit(io::Printer* printer) const; 85 | }; 86 | 87 | } // namespace c 88 | } // namespace compiler 89 | } // namespace protobuf 90 | 91 | } // namespace google 92 | #endif // GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__ 93 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_enum_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace compiler { 73 | namespace c { 74 | 75 | class EnumFieldGenerator : public FieldGenerator { 76 | public: 77 | explicit EnumFieldGenerator(const FieldDescriptor* descriptor); 78 | ~EnumFieldGenerator(); 79 | 80 | // implements FieldGenerator --------------------------------------- 81 | void GenerateStructMembers(io::Printer* printer) const; 82 | void GenerateDescriptorInitializer(io::Printer* printer) const; 83 | std::string GetDefaultValue(void) const; 84 | void GenerateStaticInit(io::Printer* printer) const; 85 | 86 | private: 87 | std::map variables_; 88 | }; 89 | 90 | 91 | } // namespace c 92 | } // namespace compiler 93 | } // namespace protobuf 94 | 95 | } // namespace google 96 | #endif // GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__ 97 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_bytes_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_BYTES_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_BYTES_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace compiler { 73 | namespace c { 74 | 75 | class BytesFieldGenerator : public FieldGenerator { 76 | public: 77 | explicit BytesFieldGenerator(const FieldDescriptor* descriptor); 78 | ~BytesFieldGenerator(); 79 | 80 | // implements FieldGenerator --------------------------------------- 81 | void GenerateStructMembers(io::Printer* printer) const; 82 | void GenerateDescriptorInitializer(io::Printer* printer) const; 83 | void GenerateDefaultValueDeclarations(io::Printer* printer) const; 84 | void GenerateDefaultValueImplementations(io::Printer* printer) const; 85 | std::string GetDefaultValue(void) const; 86 | void GenerateStaticInit(io::Printer* printer) const; 87 | 88 | private: 89 | std::map variables_; 90 | }; 91 | 92 | 93 | } // namespace c 94 | } // namespace compiler 95 | } // namespace protobuf 96 | } // namespace google 97 | 98 | #endif // GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ 99 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_string_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace compiler { 73 | namespace c { 74 | 75 | class StringFieldGenerator : public FieldGenerator { 76 | public: 77 | explicit StringFieldGenerator(const FieldDescriptor* descriptor); 78 | ~StringFieldGenerator(); 79 | 80 | // implements FieldGenerator --------------------------------------- 81 | void GenerateStructMembers(io::Printer* printer) const; 82 | void GenerateDescriptorInitializer(io::Printer* printer) const; 83 | void GenerateDefaultValueDeclarations(io::Printer* printer) const; 84 | void GenerateDefaultValueImplementations(io::Printer* printer) const; 85 | std::string GetDefaultValue(void) const; 86 | void GenerateStaticInit(io::Printer* printer) const; 87 | 88 | private: 89 | std::map variables_; 90 | }; 91 | 92 | 93 | } // namespace c 94 | } // namespace compiler 95 | } // namespace protobuf 96 | 97 | } // namespace google 98 | #endif // GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ 99 | -------------------------------------------------------------------------------- /lib/src/thread_pool.c: -------------------------------------------------------------------------------- 1 | #include "thread_pool.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | #if __cplusplus 8 | extern "C" { 9 | #endif 10 | #endif /* __cplusplus */ 11 | 12 | void *grpc_c_thread_body(void *arg) { 13 | grpc_c_thread_callback_t *callback; 14 | grpc_c_thread_pool_t *pool = (grpc_c_thread_pool_t *)arg; 15 | 16 | for (;;) { 17 | gpr_mu_lock(&pool->lock); 18 | if (pool->shutdown) { 19 | pool->stop_threads++; 20 | gpr_mu_unlock(&pool->lock); 21 | break; 22 | } 23 | 24 | if (GRPC_LIST_EMPTY(&pool->callbacks_head)) { 25 | gpr_cv_wait(&pool->cv, &pool->lock, gpr_inf_future(GPR_CLOCK_MONOTONIC)); 26 | gpr_mu_unlock(&pool->lock); 27 | continue; 28 | } 29 | 30 | callback = (grpc_c_thread_callback_t *)pool->callbacks_head.next; 31 | GRPC_LIST_REMOVE(&callback->list); 32 | 33 | gpr_mu_unlock(&pool->lock); 34 | 35 | callback->func(callback->data); 36 | grpc_free(callback); 37 | } 38 | 39 | return NULL; 40 | } 41 | 42 | grpc_c_thread_t *grpc_c_thread_new(void *arg) { 43 | int ret; 44 | grpc_c_thread_t *thread; 45 | pthread_attr_t attr; 46 | 47 | thread = (grpc_c_thread_t *)grpc_malloc(sizeof(grpc_c_thread_t)); 48 | if (NULL == thread) { 49 | GRPC_C_ERR("Failed to allocate memory for thread!"); 50 | return NULL; 51 | } 52 | 53 | (void)pthread_attr_init(&attr); 54 | (void)pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); 55 | 56 | ret = pthread_create(&thread->tid, &attr, grpc_c_thread_body, arg); 57 | if (ret != 0) { 58 | GRPC_C_ERR("Failed to create thread!"); 59 | return NULL; 60 | } 61 | 62 | return thread; 63 | } 64 | 65 | /* 66 | * Create a structure to hold details about pool of threads. Takes the maximum 67 | * number of threads in pool as argument 68 | */ 69 | grpc_c_thread_pool_t *grpc_c_thread_pool_create(int n) { 70 | int i; 71 | grpc_c_thread_t *thread; 72 | grpc_c_thread_pool_t *pool = gpr_malloc(sizeof(grpc_c_thread_pool_t)); 73 | if (pool == NULL) { 74 | GRPC_C_ERR("Failed to allocate memory for thread pool"); 75 | return NULL; 76 | } 77 | 78 | memset(pool, 0, sizeof(grpc_c_thread_pool_t)); 79 | 80 | pool->max_threads = n; 81 | gpr_mu_init(&pool->lock); 82 | gpr_cv_init(&pool->cv); 83 | 84 | GRPC_LIST_INIT(&pool->callbacks_head); 85 | GRPC_LIST_INIT(&pool->threads_head); 86 | 87 | for (i = 0; i < n; i++) { 88 | thread = grpc_c_thread_new((void *)pool); 89 | if (NULL == thread) { 90 | return NULL; 91 | } 92 | GRPC_LIST_ADD(&thread->list, &pool->threads_head); 93 | } 94 | 95 | return pool; 96 | } 97 | 98 | /* 99 | * Adds a new job to the pool of threads. Creates one if necessary 100 | */ 101 | int grpc_c_thread_pool_add(grpc_c_thread_pool_t *pool, 102 | grpc_c_callback_func_t func, void *arg) { 103 | grpc_c_thread_callback_t *callback; 104 | 105 | if (pool == NULL) { 106 | GRPC_C_ERR("Uninitialized pool"); 107 | return 1; 108 | } 109 | 110 | callback = grpc_malloc(sizeof(grpc_c_thread_callback_t)); 111 | if (callback == NULL) { 112 | GRPC_C_ERR("Failed to allocate memory for thread callback"); 113 | return 1; 114 | } 115 | 116 | callback->func = func; 117 | callback->data = arg; 118 | 119 | /* 120 | * Add callback function and arguments to the queue 121 | */ 122 | gpr_mu_lock(&pool->lock); 123 | GRPC_LIST_ADD_BEFORE(&callback->list, &pool->callbacks_head); 124 | gpr_cv_signal(&pool->cv); 125 | gpr_mu_unlock(&pool->lock); 126 | 127 | return 0; 128 | } 129 | 130 | /* 131 | * Shutdown thread pool 132 | */ 133 | void grpc_c_thread_pool_shutdown(grpc_c_thread_pool_t *pool) { 134 | grpc_c_list_t *item; 135 | grpc_c_list_t *temp; 136 | 137 | if (!pool) { 138 | return; 139 | } 140 | 141 | gpr_mu_lock(&pool->lock); 142 | pool->shutdown = 1; 143 | gpr_cv_broadcast(&pool->cv); 144 | gpr_mu_unlock(&pool->lock); 145 | 146 | GRPC_LIST_TRAVERSAL_REMOVE(item, temp, &pool->threads_head) { 147 | grpc_c_thread_t *thread; 148 | thread = GRPC_LIST_OFFSET(item, grpc_c_thread_t, list); 149 | pthread_join(thread->tid, NULL); 150 | grpc_free(thread); 151 | } 152 | 153 | GRPC_LIST_TRAVERSAL_REMOVE(item, temp, &pool->callbacks_head) { 154 | grpc_c_thread_callback_t *callback; 155 | callback = GRPC_LIST_OFFSET(item, grpc_c_thread_callback_t, list); 156 | grpc_free(callback); 157 | } 158 | 159 | grpc_free(pool); 160 | } 161 | 162 | #ifdef __cplusplus 163 | #if __cplusplus 164 | } 165 | #endif 166 | #endif /* __cplusplus */ 167 | -------------------------------------------------------------------------------- /compiler/grpc_c_generator.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Generates C code for a given .proto file. 62 | 63 | #ifndef GRPC_C_INTERNAL_COMPILER_C_GENERATOR_H 64 | #define GRPC_C_INTERNAL_COMPILER_C_GENERATOR_H 65 | 66 | #include 67 | #include 68 | 69 | namespace google { 70 | namespace protobuf { 71 | namespace compiler { 72 | namespace grpc_c { 73 | 74 | // CodeGenerator implementation which generates a C++ source file and 75 | // header. If you create your own protocol compiler binary and you want 76 | // it to support C++ output, you can do so by registering an instance of this 77 | // CodeGenerator with the CommandLineInterface in your main() function. 78 | class LIBPROTOC_EXPORT GrpcCGenerator : public CodeGenerator { 79 | public: 80 | GrpcCGenerator(); 81 | ~GrpcCGenerator(); 82 | 83 | GrpcCGenerator(const GrpcCGenerator &) = delete; 84 | GrpcCGenerator &operator=(const GrpcCGenerator &) = delete; 85 | 86 | // implements CodeGenerator ---------------------------------------- 87 | bool Generate(const FileDescriptor *file, const std::string ¶meter, 88 | GeneratorContext *generator_context, 89 | std::string *error) const override; 90 | }; 91 | 92 | } // namespace grpc_c 93 | } // namespace compiler 94 | } // namespace protobuf 95 | 96 | } // namespace google 97 | #endif // GRPC_C_INTERNAL_COMPILER_C_GENERATOR_H 98 | -------------------------------------------------------------------------------- /lib/src/trace.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "trace.h" 9 | 10 | #ifdef __cplusplus 11 | #if __cplusplus 12 | extern "C" { 13 | #endif 14 | #endif /* __cplusplus */ 15 | 16 | static int grpc_c_output_level = 2; 17 | 18 | void grpc_c_log(int level, const char *file, int line, const char *format, 19 | ...) { 20 | va_list args; 21 | const char *fname; 22 | char *rslash; 23 | const char level_name[3] = {'D', 'I', 'E'}; 24 | char buffer[1024]; 25 | int cnt; 26 | 27 | if (level < grpc_c_output_level) { 28 | return; 29 | } 30 | 31 | rslash = strrchr(file, '/'); 32 | if (rslash == NULL) { 33 | fname = file; 34 | } else { 35 | fname = rslash + 1; 36 | } 37 | 38 | cnt = snprintf(buffer, sizeof(buffer) - 1, "[grpc-c]%c %s:%d ", 39 | level_name[level], fname, line); 40 | if (cnt == -1) { 41 | return; 42 | } 43 | 44 | va_start(args, format); 45 | vsnprintf(&buffer[cnt], sizeof(buffer) - cnt - 1, format, args); 46 | va_end(args); 47 | 48 | fprintf(stderr, "%s\n", buffer); 49 | } 50 | 51 | void grpc_c_log_output_level(int level) { grpc_c_output_level = level; } 52 | 53 | /* 54 | * Internal grpc-c trace callback that gets registered into grpc context 55 | */ 56 | void grpc_c_gpr_log(gpr_log_func_args *args) { 57 | int priority = 0; 58 | const char *fname; 59 | char *rslash; 60 | 61 | rslash = strrchr(args->file, '/'); 62 | if (rslash == NULL) { 63 | fname = args->file; 64 | } else { 65 | fname = rslash + 1; 66 | } 67 | 68 | fprintf(stderr, "[grpc-core]%s %s:%d %s\n", 69 | gpr_log_severity_string(args->severity), fname, args->line, 70 | args->message); 71 | } 72 | 73 | /* 74 | * Enable/disable tracing by given flags 75 | */ 76 | void grpc_c_trace_enable_by_flag(int flags, int enabled) { 77 | if (flags & GRPC_C_TRACE_ALL) { 78 | grpc_tracer_set_enabled("all", enabled); 79 | return; 80 | } 81 | 82 | if (flags & GRPC_C_TRACE_TCP) { 83 | grpc_tracer_set_enabled("tcp", enabled); 84 | } 85 | 86 | if (flags & GRPC_C_TRACE_CHANNEL) { 87 | grpc_tracer_set_enabled("channel", enabled); 88 | } 89 | 90 | if (flags & GRPC_C_TRACE_SURFACE) { 91 | grpc_tracer_set_enabled("surface", enabled); 92 | } 93 | 94 | if (flags & GRPC_C_TRACE_HTTP) { 95 | grpc_tracer_set_enabled("http", enabled); 96 | } 97 | 98 | if (flags & GRPC_C_TRACE_FLOWCTL) { 99 | grpc_tracer_set_enabled("flowctl", enabled); 100 | } 101 | 102 | if (flags & GRPC_C_TRACE_BATCH) { 103 | grpc_tracer_set_enabled("batch", enabled); 104 | } 105 | 106 | if (flags & GRPC_C_TRACE_CONNECTIVITY_STATE) { 107 | grpc_tracer_set_enabled("connectivity_state", enabled); 108 | } 109 | 110 | if (flags & GRPC_C_TRACE_SECURE_ENDPOINT) { 111 | grpc_tracer_set_enabled("secure_endpoint", enabled); 112 | } 113 | 114 | if (flags & GRPC_C_TRACE_TRANSPORT_SECURITY) { 115 | grpc_tracer_set_enabled("transport_security", enabled); 116 | } 117 | 118 | if (flags & GRPC_C_TRACE_ROUND_ROBIN) { 119 | grpc_tracer_set_enabled("round_robin", enabled); 120 | } 121 | 122 | if (flags & GRPC_C_TRACE_HTTP_WRITE_STATE) { 123 | grpc_tracer_set_enabled("http_write_state", enabled); 124 | } 125 | 126 | if (flags & GRPC_C_TRACE_API) { 127 | grpc_tracer_set_enabled("api", enabled); 128 | } 129 | 130 | if (flags & GRPC_C_TRACE_CHANNEL_STACK_BUILDER) { 131 | grpc_tracer_set_enabled("channel_stack_builder", enabled); 132 | } 133 | 134 | if (flags & GRPC_C_TRACE_HTTP1) { 135 | grpc_tracer_set_enabled("http1", enabled); 136 | } 137 | 138 | if (flags & GRPC_C_TRACE_COMPRESSION) { 139 | grpc_tracer_set_enabled("compression", enabled); 140 | } 141 | 142 | if (flags & GRPC_C_TRACE_QUEUE_PLUCK) { 143 | grpc_tracer_set_enabled("queue_pluck", enabled); 144 | } 145 | 146 | if (flags & GRPC_C_TRACE_QUEUE_TIMEOUT) { 147 | grpc_tracer_set_enabled("queue_timeout", enabled); 148 | } 149 | 150 | if (flags & GRPC_C_TRACE_OP_FAILURE) { 151 | grpc_tracer_set_enabled("op_failure", enabled); 152 | } 153 | } 154 | 155 | /* 156 | * Enable tracing by flags 157 | */ 158 | void grpc_c_trace_enable(int flags, int severity) { 159 | grpc_c_trace_enable_by_flag(flags, 1); 160 | gpr_set_log_verbosity(severity); 161 | } 162 | 163 | /* 164 | * Disables tracing by flag 165 | */ 166 | void grpc_c_trace_disable(int flags) { grpc_c_trace_enable_by_flag(flags, 0); } 167 | 168 | /* 169 | * Initializes tracing. Sets grpc-c trace function into grpc context 170 | */ 171 | void grpc_c_trace_init() { gpr_set_log_function(grpc_c_gpr_log); } 172 | 173 | #ifdef __cplusplus 174 | #if __cplusplus 175 | } 176 | #endif 177 | #endif /* __cplusplus */ 178 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_generator.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | // Generates C code for a given .proto file. 64 | 65 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__ 66 | #define GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__ 67 | 68 | #include 69 | #include 70 | 71 | #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) 72 | # define PROTOC_C_EXPORT __declspec(dllexport) 73 | #else 74 | # define PROTOC_C_EXPORT 75 | #endif 76 | 77 | namespace google { 78 | namespace protobuf { 79 | namespace compiler { 80 | namespace c { 81 | 82 | // CodeGenerator implementation which generates a C++ source file and 83 | // header. If you create your own protocol compiler binary and you want 84 | // it to support C++ output, you can do so by registering an instance of this 85 | // CodeGenerator with the CommandLineInterface in your main() function. 86 | class PROTOC_C_EXPORT CGenerator : public CodeGenerator { 87 | public: 88 | CGenerator(); 89 | ~CGenerator(); 90 | 91 | // implements CodeGenerator ---------------------------------------- 92 | bool Generate(const FileDescriptor* file, 93 | const std::string& parameter, 94 | OutputDirectory* output_directory, 95 | std::string* error) const; 96 | }; 97 | 98 | } // namespace c 99 | } // namespace compiler 100 | } // namespace protobuf 101 | 102 | } // namespace google 103 | #endif // GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__ 104 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_extension.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_EXTENSION_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_EXTENSION_H__ 65 | 66 | #include 67 | #include 68 | 69 | namespace google { 70 | namespace protobuf { 71 | class FieldDescriptor; // descriptor.h 72 | namespace io { 73 | class Printer; // printer.h 74 | } 75 | } 76 | 77 | namespace protobuf { 78 | namespace compiler { 79 | namespace c { 80 | 81 | // Generates code for an extension, which may be within the scope of some 82 | // message or may be at file scope. This is much simpler than FieldGenerator 83 | // since extensions are just simple identifiers with interesting types. 84 | class ExtensionGenerator { 85 | public: 86 | // See generator.cc for the meaning of dllexport_decl. 87 | explicit ExtensionGenerator(const FieldDescriptor* descriptor, 88 | const std::string& dllexport_decl); 89 | ~ExtensionGenerator(); 90 | 91 | // Header stuff. 92 | void GenerateDeclaration(io::Printer* printer); 93 | 94 | // Source file stuff. 95 | void GenerateDefinition(io::Printer* printer); 96 | 97 | private: 98 | const FieldDescriptor* descriptor_; 99 | std::string type_traits_; 100 | std::string dllexport_decl_; 101 | }; 102 | 103 | } // namespace c 104 | } // namespace compiler 105 | } // namespace protobuf 106 | 107 | } // namespace google 108 | #endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ 109 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_service.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace io { 73 | class Printer; // printer.h 74 | } 75 | } 76 | 77 | namespace protobuf { 78 | namespace compiler { 79 | namespace c { 80 | 81 | class ServiceGenerator { 82 | public: 83 | // See generator.cc for the meaning of dllexport_decl. 84 | explicit ServiceGenerator(const ServiceDescriptor* descriptor, 85 | const std::string& dllexport_decl); 86 | ~ServiceGenerator(); 87 | 88 | // Header stuff. 89 | void GenerateMainHFile(io::Printer* printer); 90 | void GenerateVfuncs(io::Printer* printer); 91 | void GenerateInitMacros(io::Printer* printer); 92 | void GenerateDescriptorDeclarations(io::Printer* printer); 93 | void GenerateCallersDeclarations(io::Printer* printer); 94 | 95 | // Source file stuff. 96 | void GenerateCFile(io::Printer* printer); 97 | void GenerateServiceDescriptor(io::Printer* printer); 98 | void GenerateInit(io::Printer* printer); 99 | void GenerateCallersImplementations(io::Printer* printer); 100 | 101 | const ServiceDescriptor* descriptor_; 102 | std::map vars_; 103 | }; 104 | 105 | } // namespace c 106 | } // namespace compiler 107 | } // namespace protobuf 108 | 109 | } // namespace google 110 | #endif // GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__ 111 | -------------------------------------------------------------------------------- /compiler/grpc_c_service.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GRPC_C_INTERNAL_COMPILER_C_SERVICE_H 64 | #define GRPC_C_INTERNAL_COMPILER_C_SERVICE_H 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace io { 73 | class Printer; // printer.h 74 | } 75 | } // namespace protobuf 76 | 77 | namespace protobuf { 78 | namespace compiler { 79 | namespace grpc_c { 80 | 81 | class GrpcCServiceGenerator { 82 | public: 83 | // See generator.cc for the meaning of dllexport_decl. 84 | explicit GrpcCServiceGenerator(const ServiceDescriptor *descriptor, 85 | const std::string &dllexport_decl); 86 | ~GrpcCServiceGenerator(); 87 | 88 | // Header stuff. 89 | void GenerateMainHFile(io::Printer *printer); 90 | void GenerateVfuncs(io::Printer *printer); 91 | void GenerateInitMacros(io::Printer *printer); 92 | void GenerateDescriptorDeclarations(io::Printer *printer); 93 | void GenerateCallersDeclarations(io::Printer *printer); 94 | 95 | // Source file stuff. 96 | void GenerateCFile(io::Printer *printer); 97 | void GenerateCServiceFile(io::Printer *printer); 98 | void GenerateServiceDescriptor(io::Printer *printer); 99 | void GenerateInit(io::Printer *printer); 100 | void GenerateCallersImplementations(io::Printer *printer); 101 | 102 | const ServiceDescriptor *descriptor_; 103 | std::map vars_; 104 | }; 105 | 106 | } // namespace grpc_c 107 | } // namespace compiler 108 | } // namespace protobuf 109 | 110 | } // namespace google 111 | #endif // GRPC_C_INTERNAL_COMPILER_C_SERVICE_H 112 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_enum.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__ 65 | 66 | #include 67 | #include 68 | 69 | namespace google { 70 | namespace protobuf { 71 | namespace io { 72 | class Printer; // printer.h 73 | } 74 | } 75 | 76 | namespace protobuf { 77 | namespace compiler { 78 | namespace c { 79 | 80 | class EnumGenerator { 81 | public: 82 | // See generator.cc for the meaning of dllexport_decl. 83 | explicit EnumGenerator(const EnumDescriptor* descriptor, 84 | const std::string& dllexport_decl); 85 | ~EnumGenerator(); 86 | 87 | // Header stuff. 88 | 89 | // Generate header code defining the enum. This code should be placed 90 | // within the enum's package namespace, but NOT within any class, even for 91 | // nested enums. 92 | void GenerateDefinition(io::Printer* printer); 93 | 94 | void GenerateDescriptorDeclarations(io::Printer* printer); 95 | 96 | 97 | // Source file stuff. 98 | 99 | // Generate the ProtobufCEnumDescriptor for this enum 100 | void GenerateEnumDescriptor(io::Printer* printer); 101 | 102 | // Generate static initializer for a ProtobufCEnumValue 103 | // given the index of the value in the enum. 104 | void GenerateValueInitializer(io::Printer *printer, int index); 105 | 106 | private: 107 | const EnumDescriptor* descriptor_; 108 | std::string dllexport_decl_; 109 | }; 110 | 111 | } // namespace c 112 | } // namespace compiler 113 | } // namespace protobuf 114 | 115 | } // namespace google 116 | #endif // GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__ 117 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_file.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | 72 | namespace google { 73 | namespace protobuf { 74 | class FileDescriptor; // descriptor.h 75 | namespace io { 76 | class Printer; // printer.h 77 | } 78 | } 79 | 80 | namespace protobuf { 81 | namespace compiler { 82 | namespace c { 83 | 84 | class EnumGenerator; // enum.h 85 | class MessageGenerator; // message.h 86 | class ServiceGenerator; // service.h 87 | class ExtensionGenerator; // extension.h 88 | 89 | class FileGenerator { 90 | public: 91 | // See generator.cc for the meaning of dllexport_decl. 92 | explicit FileGenerator(const FileDescriptor* file, 93 | const std::string& dllexport_decl); 94 | ~FileGenerator(); 95 | 96 | void GenerateHeader(io::Printer* printer); 97 | void GenerateSource(io::Printer* printer); 98 | 99 | private: 100 | const FileDescriptor* file_; 101 | 102 | std::unique_ptr[]> message_generators_; 103 | std::unique_ptr[]> enum_generators_; 104 | std::unique_ptr[]> service_generators_; 105 | std::unique_ptr[]> extension_generators_; 106 | }; 107 | 108 | } // namespace c 109 | } // namespace compiler 110 | } // namespace protobuf 111 | 112 | } // namespace google 113 | #endif // GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ 114 | -------------------------------------------------------------------------------- /compiler/grpc_c_message.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GRPC_C_INTERNAL_COMPILER_C_MESSAGE_H 64 | #define GRPC_C_INTERNAL_COMPILER_C_MESSAGE_H 65 | 66 | #include 67 | 68 | #include 69 | #include 70 | #include 71 | 72 | namespace google { 73 | namespace protobuf { 74 | namespace io { 75 | class Printer; // printer.h 76 | } 77 | } // namespace protobuf 78 | 79 | namespace protobuf { 80 | namespace compiler { 81 | namespace grpc_c { 82 | 83 | class MessagePackUnpackGenerator { 84 | public: 85 | // See generator.cc for the meaning of dllexport_decl. 86 | explicit MessagePackUnpackGenerator(const Descriptor *descriptor, 87 | const std::string &dllexport_decl); 88 | ~MessagePackUnpackGenerator(); 89 | 90 | // Header stuff. 91 | 92 | // Generate standard helper functions declarations for this message. 93 | void GenerateHelperFunctionDeclarations(io::Printer *printer); 94 | 95 | // Source file stuff. 96 | 97 | // Generate code that initializes the global variable storing the message's 98 | // descriptor. 99 | void GenerateHelperFunctionDefinitions(io::Printer *printer); 100 | 101 | private: 102 | std::string GetDefaultValueC(const FieldDescriptor *fd); 103 | 104 | const Descriptor *descriptor_; 105 | std::string dllexport_decl_; 106 | }; 107 | 108 | class GrpcCMessageGenerator { 109 | public: 110 | explicit GrpcCMessageGenerator(const Descriptor *descriptor, 111 | const std::string &dllexport_decl); 112 | 113 | ~GrpcCMessageGenerator(); 114 | 115 | void GenerateStructTypedef(io::Printer *printer); 116 | 117 | private: 118 | const Descriptor *descriptor_; 119 | std::string dllexport_decl_; 120 | std::unique_ptr[]> 121 | grpc_c_nested_generators_; 122 | }; 123 | 124 | } // namespace grpc_c 125 | } // namespace compiler 126 | } // namespace protobuf 127 | 128 | } // namespace google 129 | #endif // GRPC_C_INTERNAL_COMPILER_C_MESSAGE_H 130 | -------------------------------------------------------------------------------- /example/foo/foo_client.c: -------------------------------------------------------------------------------- 1 | #include "foo.grpc-c.h" 2 | #include 3 | 4 | void foo_client_call_0(grpc_c_client_t *client) { 5 | 6 | int i; 7 | int ret; 8 | grpc_c_status_t status; 9 | 10 | for (i = 0; i < 10000; i++) { 11 | /* 12 | * Create a hello request message and call RPC 13 | */ 14 | Foo__HelloRequest h; 15 | foo__hello_request__init(&h); 16 | Foo__HelloReply *r; 17 | 18 | char str[BUFSIZ]; 19 | snprintf(str, BUFSIZ, "world"); 20 | h.name = str; 21 | 22 | /* 23 | * This will invoke a blocking RPC 24 | */ 25 | ret = foo__greeter__say_hello__sync(client, NULL, 0, &h, &r, &status, -1); 26 | if (ret) { 27 | printf("call failed! %d\n", ret); 28 | break; 29 | } 30 | 31 | foo__hello_reply_free(r); 32 | } 33 | 34 | printf("Total Count %d\n", i); 35 | } 36 | 37 | void foo_client_call_1(grpc_c_client_t *client) { 38 | int i; 39 | int ret; 40 | grpc_c_status_t status; 41 | grpc_c_context_t *context; 42 | 43 | ret = foo__greeter__say_hello1__stream(client, NULL, 0, &context, -1); 44 | if (ret) { 45 | printf("stream connect failed! %d\n", ret); 46 | return; 47 | } 48 | 49 | /* 50 | * Create a hello request message and call RPC 51 | */ 52 | Foo__HelloRequest h; 53 | foo__hello_request__init(&h); 54 | 55 | char str[1024]; 56 | 57 | snprintf(str, 1024, "world"); 58 | h.name = str; 59 | 60 | for (i = 0; i < 10000; i++) { 61 | ret = grpc_c_write(context, &h, 0, -1); 62 | if (ret) { 63 | printf("stream write failed! %d\n", ret); 64 | break; 65 | } 66 | } 67 | 68 | ret = grpc_c_write_done(context, 0, -1); 69 | if (ret) { 70 | printf("stream write done failed! %d\n", ret); 71 | } 72 | 73 | Foo__HelloReply *r; 74 | 75 | ret = grpc_c_read(context, (void **)&r, 0, -1); 76 | if (ret) { 77 | printf("stream read failed! %d\n", ret); 78 | } else { 79 | foo__hello_reply_free(r); 80 | } 81 | 82 | ret = grpc_c_finish(context, &status, 0); 83 | if (ret) { 84 | printf("stream finish failed! %d\n", ret); 85 | } 86 | 87 | printf("Total Count %d\n", i); 88 | } 89 | 90 | void foo_client_call_2(grpc_c_client_t *client) { 91 | int i; 92 | int ret; 93 | grpc_c_status_t status; 94 | grpc_c_context_t *context; 95 | 96 | ret = foo__greeter__say_hello2__stream(client, NULL, 0, &context, -1); 97 | if (ret) { 98 | printf("stream connect failed! %d\n", ret); 99 | return; 100 | } 101 | 102 | /* 103 | * Create a hello request message and call RPC 104 | */ 105 | Foo__HelloRequest h; 106 | foo__hello_request__init(&h); 107 | 108 | char str[1024]; 109 | 110 | snprintf(str, 1024, "world"); 111 | h.name = str; 112 | 113 | ret = grpc_c_write(context, &h, 0, -1); 114 | if (ret) { 115 | printf("stream write failed! %d\n", ret); 116 | } 117 | 118 | ret = grpc_c_write_done(context, 0, -1); 119 | if (ret) { 120 | printf("stream write done failed! %d\n", ret); 121 | } 122 | 123 | for (i = 0;; i++) { 124 | Foo__HelloReply *r; 125 | 126 | ret = grpc_c_read(context, (void **)&r, 0, -1); 127 | if (ret) { 128 | break; 129 | } 130 | 131 | foo__hello_reply_free(r); 132 | } 133 | 134 | ret = grpc_c_finish(context, &status, 0); 135 | if (ret) { 136 | printf("stream finish failed! %d\n", ret); 137 | } 138 | 139 | printf("Total Count %d\n", i); 140 | } 141 | 142 | void foo_client_call_3(grpc_c_client_t *client) { 143 | int i; 144 | int ret; 145 | grpc_c_status_t status; 146 | grpc_c_context_t *context; 147 | 148 | ret = foo__greeter__say_hello3__stream(client, NULL, 0, &context, -1); 149 | if (ret) { 150 | printf("stream connect failed! %d\n", ret); 151 | return; 152 | } 153 | 154 | /* 155 | * Create a hello request message and call RPC 156 | */ 157 | Foo__HelloRequest h; 158 | foo__hello_request__init(&h); 159 | 160 | char str[1024]; 161 | 162 | snprintf(str, 1024, "world"); 163 | h.name = str; 164 | 165 | for (i = 0; i < 10000; i++) { 166 | ret = grpc_c_write(context, &h, 0, -1); 167 | if (ret) { 168 | printf("stream write failed! %d\n", ret); 169 | break; 170 | } 171 | 172 | foo__HelloReply *r; 173 | 174 | ret = grpc_c_read(context, (void **)&r, 0, -1); 175 | if (ret) { 176 | printf("stream read failed! %d\n", ret); 177 | break; 178 | } 179 | 180 | foo__hello_reply_free(r); 181 | } 182 | 183 | ret = grpc_c_write_done(context, 0, -1); 184 | if (ret) { 185 | printf("stream write done failed! %d\n", ret); 186 | } 187 | 188 | ret = grpc_c_finish(context, &status, 0); 189 | if (ret) { 190 | printf("stream finish failed! %d\n", ret); 191 | } 192 | 193 | printf("Total Count %d\n", i); 194 | } 195 | 196 | /* 197 | * Takes as argument the socket name 198 | */ 199 | int foo_client() { 200 | /* 201 | * Initialize grpc-c library to be used with vanilla grpc 202 | */ 203 | grpc_c_init(); 204 | 205 | /* 206 | * Create a client object with client name as foo client to be talking to 207 | * a insecure server 208 | */ 209 | grpc_c_client_t *client = grpc_c_client_init("127.0.0.1:3000", NULL, NULL); 210 | 211 | foo_client_call_0(client); 212 | foo_client_call_1(client); 213 | foo_client_call_2(client); 214 | foo_client_call_3(client); 215 | 216 | grpc_c_client_stop(client); 217 | grpc_c_client_wait(client); 218 | grpc_c_client_free(client); 219 | 220 | grpc_c_shutdown(); 221 | } 222 | -------------------------------------------------------------------------------- /compiler/grpc_c_file.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GRPC_C_INTERNAL_COMPILER_C_FILE_H 64 | #define GRPC_C_INTERNAL_COMPILER_C_FILE_H 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | #include "grpc_c_service.h" 72 | 73 | namespace google { 74 | namespace protobuf { 75 | class FileDescriptor; // descriptor.h 76 | namespace io { 77 | class Printer; // printer.h 78 | } 79 | } // namespace protobuf 80 | 81 | namespace protobuf { 82 | namespace compiler { 83 | namespace c { 84 | class MessageGenerator; 85 | class EnumGenerator; 86 | class ExtensionGenerator; 87 | } // namespace c 88 | namespace grpc_c { 89 | class GrpcCMessageGenerator; 90 | class MessagePackUnpackGenerator; 91 | 92 | class FileGenerator { 93 | public: 94 | // See generator.cc for the meaning of dllexport_decl. 95 | explicit FileGenerator(const FileDescriptor *file, 96 | const std::string &dllexport_decl); 97 | ~FileGenerator(); 98 | 99 | void GenerateHeader(io::Printer *printer); 100 | void GenerateSource(io::Printer *printer); 101 | void GenerateServiceSource(io::Printer *printer); 102 | 103 | private: 104 | const FileDescriptor *file_; 105 | 106 | std::unique_ptr[]> message_generators_; 107 | std::unique_ptr[]> 108 | grpc_c_message_generators_; 109 | std::unique_ptr[]> 110 | message_pack_unpack_generators_; 111 | std::unique_ptr[]> enum_generators_; 112 | std::unique_ptr[]> service_generators_; 113 | std::unique_ptr[]> 114 | extension_generators_; 115 | 116 | // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. 117 | std::vector package_parts_; 118 | }; 119 | 120 | } // namespace grpc_c 121 | } // namespace compiler 122 | } // namespace protobuf 123 | 124 | } // namespace google 125 | #endif // GRPC_C_INTERNAL_COMPILER_C_FILE_H 126 | -------------------------------------------------------------------------------- /example/foo/foo_server.c: -------------------------------------------------------------------------------- 1 | #include "foo.grpc-c.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static grpc_c_server_t *test_server; 8 | 9 | int test_times = 0; 10 | 11 | /* 12 | * This function gets invoked whenever say_hello RPC gets called 13 | */ 14 | void foo__greeter__say_hello_cb(grpc_c_context_t *context) { 15 | int ret; 16 | Foo__HelloRequest *h = NULL; 17 | 18 | /* 19 | * Read incoming message into h 20 | */ 21 | if (grpc_c_read(context, (void **)&h, 0, -1)) { 22 | printf("Failed to read data from client\n"); 23 | } 24 | 25 | if (h) { 26 | foo__hello_request_free(h); 27 | } 28 | 29 | /* 30 | * Create a reply 31 | */ 32 | Foo__HelloReply r; 33 | foo__hello_reply__init(&r); 34 | 35 | char buf[1024]; 36 | buf[0] = '\0'; 37 | snprintf(buf, 1024, "hello, world! from server."); 38 | r.message = buf; 39 | 40 | /* 41 | * Write reply back to the client 42 | */ 43 | 44 | ret = grpc_c_write(context, &r, 0, -1); 45 | if (ret) { 46 | printf("Failed to write %d\n", ret); 47 | } 48 | 49 | grpc_c_status_t status; 50 | status.code = 0; 51 | status.message[0] = '\0'; 52 | 53 | /* 54 | * Finish response for RPC 55 | */ 56 | if (grpc_c_finish(context, &status, 0)) { 57 | printf("Failed to write status\n"); 58 | } 59 | } 60 | 61 | void foo__greeter__say_hello1_cb(grpc_c_context_t *context) { 62 | int ret; 63 | Foo__HelloRequest *h = NULL; 64 | 65 | char buf[1024]; 66 | Foo__HelloReply r; 67 | foo__hello_reply__init(&r); 68 | 69 | /* 70 | * Create a reply 71 | */ 72 | 73 | buf[0] = '\0'; 74 | snprintf(buf, 1024, "hello, world! from server."); 75 | r.message = buf; 76 | 77 | for (;;) { 78 | /* 79 | * Read incoming message into h 80 | */ 81 | ret = grpc_c_read(context, (void **)&h, 0, -1); 82 | if (ret) { 83 | break; 84 | } 85 | foo__hello_request_free(h); 86 | } 87 | 88 | /* 89 | * Write reply back to the client 90 | */ 91 | 92 | ret = grpc_c_write(context, &r, 0, -1); 93 | if (ret) { 94 | printf("Failed to write %d\n", ret); 95 | } 96 | 97 | grpc_c_status_t status; 98 | status.code = 0; 99 | status.message[0] = '\0'; 100 | 101 | /* 102 | * Finish response for RPC 103 | */ 104 | if (grpc_c_finish(context, &status, 0)) { 105 | printf("Failed to write status\n"); 106 | } 107 | } 108 | 109 | void foo__greeter__say_hello2_cb(grpc_c_context_t *context) { 110 | int i; 111 | int ret; 112 | foo__HelloRequest *h = NULL; 113 | 114 | /* 115 | * Read incoming message into h 116 | */ 117 | if (grpc_c_read(context, (void **)&h, 0, -1)) { 118 | printf("Failed to read data from client\n"); 119 | } 120 | 121 | if (h) { 122 | foo__hello_request_free(h); 123 | } 124 | 125 | /* 126 | * Create a reply 127 | */ 128 | Foo__HelloReply r; 129 | foo__hello_reply__init(&r); 130 | 131 | char buf[1024]; 132 | buf[0] = '\0'; 133 | snprintf(buf, 1024, "hello, world! from server."); 134 | r.message = buf; 135 | 136 | for (i = 0; i < 10000; i++) { 137 | /* 138 | * Write reply back to the client 139 | */ 140 | ret = grpc_c_write(context, &r, 0, -1); 141 | if (ret) { 142 | printf("Failed to write %d\n", ret); 143 | break; 144 | } 145 | } 146 | 147 | grpc_c_status_t status; 148 | status.code = 0; 149 | status.message[0] = '\0'; 150 | 151 | /* 152 | * Finish response for RPC 153 | */ 154 | if (grpc_c_finish(context, &status, 0)) { 155 | printf("Failed to write status\n"); 156 | } 157 | } 158 | 159 | void foo__greeter__say_hello3_cb(grpc_c_context_t *context) { 160 | int ret; 161 | Foo__HelloRequest *h = NULL; 162 | 163 | char buf[1024]; 164 | Foo__HelloReply r; 165 | foo__hello_reply__init(&r); 166 | 167 | /* 168 | * Create a reply 169 | */ 170 | for (;;) { 171 | /* 172 | * Read incoming message into h 173 | */ 174 | ret = grpc_c_read(context, (void **)&h, 0, -1); 175 | if (ret) { 176 | break; 177 | } 178 | 179 | snprintf(buf, 1024, "hello, %s! from server.", h->name); 180 | r.message = buf; 181 | 182 | foo__hello_request_free(h); 183 | 184 | /* 185 | * Write reply back to the client 186 | */ 187 | ret = grpc_c_write(context, &r, 0, -1); 188 | if (ret) { 189 | printf("Failed to write %d\n", ret); 190 | break; 191 | } 192 | } 193 | 194 | grpc_c_status_t status; 195 | status.code = 0; 196 | status.message[0] = '\0'; 197 | 198 | /* 199 | * Finish response for RPC 200 | */ 201 | if (grpc_c_finish(context, &status, 0)) { 202 | printf("Failed to write status\n"); 203 | } 204 | } 205 | 206 | /* 207 | * Takes socket path as argument 208 | */ 209 | int foo_server() { 210 | int i = 0; 211 | 212 | /* 213 | * Initialize grpc-c library to be used with vanilla gRPC 214 | */ 215 | grpc_c_init(); 216 | 217 | /* 218 | * Create server object 219 | */ 220 | test_server = grpc_c_server_create("127.0.0.1:3000", NULL, NULL); 221 | if (test_server == NULL) { 222 | printf("Failed to create server\n"); 223 | exit(1); 224 | } 225 | 226 | /* 227 | * Initialize greeter service 228 | */ 229 | foo__greeter__service_init(test_server); 230 | 231 | /* 232 | * Start server 233 | */ 234 | grpc_c_server_start(test_server); 235 | 236 | /* 237 | * Blocks server to wait to completion 238 | */ 239 | grpc_c_server_wait(test_server); 240 | 241 | /* 242 | * Destory server 243 | */ 244 | grpc_c_server_destroy(test_server); 245 | 246 | /* 247 | * Destory grpc-c library. 248 | */ 249 | grpc_c_shutdown(); 250 | } 251 | -------------------------------------------------------------------------------- /protobuf-c/README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://github.com/protobuf-c/protobuf-c/actions/workflows/build.yml/badge.svg)](https://github.com/protobuf-c/protobuf-c/actions) [![Coverage Status](https://coveralls.io/repos/protobuf-c/protobuf-c/badge.png)](https://coveralls.io/r/protobuf-c/protobuf-c) 2 | 3 | ## Overview 4 | 5 | This is `protobuf-c`, a C implementation of the [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) data serialization format. 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](https://github.com/protobuf-c/protobuf-c-rpc) project. 6 | 7 | `protobuf-c` was originally written by Dave Benson and maintained by him through version 0.15 but is now being maintained by a new team. Thanks, Dave! 8 | 9 | ## Mailing list 10 | 11 | `protobuf-c`'s mailing list is hosted on a [Google Groups forum](https://groups.google.com/forum/#!forum/protobuf-c). Subscribe by sending an email to [protobuf-c+subscribe@googlegroups.com](mailto:protobuf-c+subscribe@googlegroups.com). 12 | 13 | ## Building 14 | 15 | `protobuf-c` requires a C compiler, a C++ compiler, [protobuf](https://github.com/google/protobuf), and `pkg-config` to be installed. 16 | 17 | ./configure && make && make install 18 | 19 | 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. 20 | 21 | ./autogen.sh && ./configure && make && make install 22 | 23 | ## Test 24 | 25 | If you want to execute test cases individually, please run the following command after running `./configure` once: 26 | 27 | make check 28 | 29 | ## Documentation 30 | 31 | See the [online Doxygen documentation here](https://protobuf-c.github.io/protobuf-c) or [the Wiki](https://github.com/protobuf-c/protobuf-c/wiki) for a detailed reference. The Doxygen documentation can be built from the source tree by running: 32 | 33 | make html 34 | 35 | ## Synopsis 36 | 37 | Use the `protoc` command to generate `.pb-c.c` and `.pb-c.h` output files from your `.proto` input file. The `--c_out` options instructs `protoc` to use the protobuf-c plugin. 38 | 39 | protoc --c_out=. example.proto 40 | 41 | Include the `.pb-c.h` file from your C source code. 42 | 43 | #include "example.pb-c.h" 44 | 45 | Compile your C source code together with the `.pb-c.c` file. Add the output of the following command to your compile flags. 46 | 47 | pkg-config --cflags 'libprotobuf-c >= 1.0.0' 48 | 49 | Link against the `libprotobuf-c` support library. Add the output of the following command to your link flags. 50 | 51 | pkg-config --libs 'libprotobuf-c >= 1.0.0' 52 | 53 | If using autotools, the `PKG_CHECK_MODULES` macro can be used to detect the presence of `libprotobuf-c`. Add the following line to your `configure.ac` file: 54 | 55 | PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 1.0.0]) 56 | 57 | This will place compiler flags in the `PROTOBUF_C_CFLAGS` variable and linker flags in the `PROTOBUF_C_LDFLAGS` variable. Read [more information here](https://autotools.io/pkgconfig/pkg_check_modules.html) about the `PKG_CHECK_MODULES` macro. 58 | 59 | ## Versioning 60 | 61 | `protobuf-c` follows the [Semantic Versioning Specification](http://semver.org/) as of version 1.0.0. 62 | 63 | Note that as of version of 1.0.0, the header files generated by the `protoc-c` compiler contain version guards to prevent incompatibilities due to version skew between the `.pb-c.h` files generated by `protoc-c` and the public `protobuf-c.h` include file supplied by the `libprotobuf-c` support library. While we will try not to make changes to `protobuf-c` that will require triggering the version guard often, such as releasing a new major version of `protobuf-c`, this cannot be guaranteed. Thus, it's a good idea to recompile your `.pb-c.c` and `.pb-c.h` files from their source `.proto` files with `protoc-c` as part of your build system, with proper source file dependency tracking, rather than shipping potentially stale `.pb-c.c` and `.pb-c.h` files that may not be compatible with the `libprotobuf-c` headers installed on the system in project artifacts like repositories and release tarballs. (Note that the output of the `protoc-c` code generator is not standalone, as the output of some other tools that generate C code is, such as `flex` and `bison`.) 64 | 65 | Major API/ABI changes may occur between major version releases, by definition. It is not recommended to export the symbols in the code generated by `protoc-c` in a stable library interface, as this will embed the `protobuf-c` ABI into your library's ABI. Nor is it recommended to install generated `.pb-c.h` files into a public header file include path as part of a library API, as this will tie clients of your library's API to particular versions of `libprotobuf-c`. 66 | 67 | ## Contributing 68 | 69 | Please send patches to the [protobuf-c mailing list](https://groups.google.com/forum/#!forum/protobuf-c) or by opening a GitHub pull request. 70 | 71 | The most recently released `protobuf-c` version is kept on the `master` branch, while the `next` branch is used for commits targeted at the next release. Please base patches and pull requests against the `next` branch, not the `master` branch. 72 | 73 | Copyright to all contributions are retained by the original author, but must be licensed under the terms of the [BSD-2-Clause](http://opensource.org/licenses/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. 74 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_field.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | namespace google { 71 | namespace protobuf { 72 | namespace io { 73 | class Printer; // printer.h 74 | } 75 | } 76 | 77 | namespace protobuf { 78 | namespace compiler { 79 | namespace c { 80 | 81 | class FieldGenerator { 82 | public: 83 | explicit FieldGenerator(const FieldDescriptor *descriptor) : descriptor_(descriptor) {} 84 | virtual ~FieldGenerator(); 85 | 86 | // Generate definitions to be included in the structure. 87 | virtual void GenerateStructMembers(io::Printer* printer) const = 0; 88 | 89 | // Generate a static initializer for this field. 90 | virtual void GenerateDescriptorInitializer(io::Printer* printer) const = 0; 91 | 92 | virtual void GenerateDefaultValueDeclarations(io::Printer* printer) const { } 93 | virtual void GenerateDefaultValueImplementations(io::Printer* printer) const { } 94 | virtual std::string GetDefaultValue() const = 0; 95 | 96 | // Generate members to initialize this field from a static initializer 97 | virtual void GenerateStaticInit(io::Printer* printer) const = 0; 98 | 99 | 100 | protected: 101 | void GenerateDescriptorInitializerGeneric(io::Printer* printer, 102 | bool optional_uses_has, 103 | const std::string &type_macro, 104 | const std::string &descriptor_addr) const; 105 | const FieldDescriptor *descriptor_; 106 | }; 107 | 108 | // Convenience class which constructs FieldGenerators for a Descriptor. 109 | class FieldGeneratorMap { 110 | public: 111 | explicit FieldGeneratorMap(const Descriptor* descriptor); 112 | ~FieldGeneratorMap(); 113 | 114 | const FieldGenerator& get(const FieldDescriptor* field) const; 115 | 116 | private: 117 | const Descriptor* descriptor_; 118 | std::unique_ptr[]> field_generators_; 119 | 120 | static FieldGenerator* MakeGenerator(const FieldDescriptor* field); 121 | }; 122 | 123 | } // namespace c 124 | } // namespace compiler 125 | } // namespace protobuf 126 | 127 | } // namespace google 128 | #endif // GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ 129 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_message_field.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | namespace google { 69 | namespace protobuf { 70 | namespace compiler { 71 | namespace c { 72 | 73 | using internal::WireFormat; 74 | 75 | // =================================================================== 76 | 77 | MessageFieldGenerator:: 78 | MessageFieldGenerator(const FieldDescriptor* descriptor) 79 | : FieldGenerator(descriptor) { 80 | } 81 | 82 | MessageFieldGenerator::~MessageFieldGenerator() {} 83 | 84 | void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const 85 | { 86 | std::map vars; 87 | vars["name"] = FieldName(descriptor_); 88 | vars["type"] = FullNameToC(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()); 89 | vars["deprecated"] = FieldDeprecated(descriptor_); 90 | switch (descriptor_->label()) { 91 | case FieldDescriptor::LABEL_REQUIRED: 92 | case FieldDescriptor::LABEL_OPTIONAL: 93 | printer->Print(vars, "$type$ *$name$$deprecated$;\n"); 94 | break; 95 | case FieldDescriptor::LABEL_REPEATED: 96 | printer->Print(vars, "size_t n_$name$$deprecated$;\n"); 97 | printer->Print(vars, "$type$ **$name$$deprecated$;\n"); 98 | break; 99 | } 100 | } 101 | std::string MessageFieldGenerator::GetDefaultValue(void) const 102 | { 103 | /* XXX: update when protobuf gets support 104 | * for default-values of message fields. 105 | */ 106 | return "NULL"; 107 | } 108 | void MessageFieldGenerator::GenerateStaticInit(io::Printer* printer) const 109 | { 110 | switch (descriptor_->label()) { 111 | case FieldDescriptor::LABEL_REQUIRED: 112 | case FieldDescriptor::LABEL_OPTIONAL: 113 | printer->Print("NULL"); 114 | break; 115 | case FieldDescriptor::LABEL_REPEATED: 116 | printer->Print("0,NULL"); 117 | break; 118 | } 119 | } 120 | void MessageFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const 121 | { 122 | std::string addr = "&" + FullNameToLower(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()) + "__descriptor"; 123 | GenerateDescriptorInitializerGeneric(printer, false, "MESSAGE", addr); 124 | } 125 | 126 | } // namespace c 127 | } // namespace compiler 128 | } // namespace protobuf 129 | } // namespace google 130 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_message.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #ifndef GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ 64 | #define GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | namespace google { 72 | namespace protobuf { 73 | namespace io { 74 | class Printer; // printer.h 75 | } 76 | } 77 | 78 | namespace protobuf { 79 | namespace compiler { 80 | namespace c { 81 | 82 | class EnumGenerator; // enum.h 83 | class ExtensionGenerator; // extension.h 84 | 85 | class MessageGenerator { 86 | public: 87 | // See generator.cc for the meaning of dllexport_decl. 88 | explicit MessageGenerator(const Descriptor* descriptor, 89 | const std::string& dllexport_decl); 90 | ~MessageGenerator(); 91 | 92 | // Header stuff. 93 | 94 | // Generate typedef. 95 | void GenerateStructTypedef(io::Printer* printer); 96 | 97 | // Generate descriptor prototype 98 | void GenerateDescriptorDeclarations(io::Printer* printer); 99 | 100 | // Generate descriptor prototype 101 | void GenerateClosureTypedef(io::Printer* printer); 102 | 103 | // Generate definitions of all nested enums (must come before class 104 | // definitions because those classes use the enums definitions). 105 | void GenerateEnumDefinitions(io::Printer* printer); 106 | 107 | // Generate definitions for this class and all its nested types. 108 | void GenerateStructDefinition(io::Printer* printer); 109 | 110 | // Generate __INIT macro for populating this structure 111 | void GenerateStructStaticInitMacro(io::Printer* printer); 112 | 113 | // Generate standard helper functions declarations for this message. 114 | void GenerateHelperFunctionDeclarations(io::Printer* printer, 115 | bool is_pack_deep, 116 | bool gen_pack, 117 | bool gen_init); 118 | 119 | // Source file stuff. 120 | 121 | // Generate code that initializes the global variable storing the message's 122 | // descriptor. 123 | void GenerateMessageDescriptor(io::Printer* printer, bool gen_init); 124 | void GenerateHelperFunctionDefinitions(io::Printer* printer, 125 | bool is_pack_deep, 126 | bool gen_pack, 127 | bool gen_init); 128 | 129 | private: 130 | 131 | std::string GetDefaultValueC(const FieldDescriptor *fd); 132 | 133 | const Descriptor* descriptor_; 134 | std::string dllexport_decl_; 135 | FieldGeneratorMap field_generators_; 136 | std::unique_ptr[]> nested_generators_; 137 | std::unique_ptr[]> enum_generators_; 138 | std::unique_ptr[]> extension_generators_; 139 | }; 140 | 141 | } // namespace c 142 | } // namespace compiler 143 | } // namespace protobuf 144 | 145 | } // namespace google 146 | #endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ 147 | -------------------------------------------------------------------------------- /protobuf-c/protoc-c/c_enum_field.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // http://code.google.com/p/protobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: kenton@google.com (Kenton Varda) 32 | // Based on original Protocol Buffers design by 33 | // Sanjay Ghemawat, Jeff Dean, and others. 34 | 35 | // Copyright (c) 2008-2013, Dave Benson. All rights reserved. 36 | // 37 | // Redistribution and use in source and binary forms, with or without 38 | // modification, are permitted provided that the following conditions are 39 | // met: 40 | // 41 | // * Redistributions of source code must retain the above copyright 42 | // notice, this list of conditions and the following disclaimer. 43 | // 44 | // * Redistributions in binary form must reproduce the above 45 | // copyright notice, this list of conditions and the following disclaimer 46 | // in the documentation and/or other materials provided with the 47 | // distribution. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Modified to implement C code by Dave Benson. 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | namespace google { 69 | namespace protobuf { 70 | namespace compiler { 71 | namespace c { 72 | 73 | using internal::WireFormat; 74 | 75 | // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of 76 | // repeat code between this and the other field types. 77 | void SetEnumVariables(const FieldDescriptor* descriptor, 78 | std::map* variables) { 79 | 80 | (*variables)["name"] = FieldName(descriptor); 81 | (*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name(), descriptor->enum_type()->file()); 82 | const EnumValueDescriptor* default_value = descriptor->default_value_enum(); 83 | (*variables)["default"] = FullNameToUpper(default_value->type()->full_name(), default_value->type()->file()) 84 | + "__" + default_value->name(); 85 | (*variables)["deprecated"] = FieldDeprecated(descriptor); 86 | } 87 | 88 | // =================================================================== 89 | 90 | EnumFieldGenerator:: 91 | EnumFieldGenerator(const FieldDescriptor* descriptor) 92 | : FieldGenerator(descriptor) 93 | { 94 | SetEnumVariables(descriptor, &variables_); 95 | } 96 | 97 | EnumFieldGenerator::~EnumFieldGenerator() {} 98 | 99 | void EnumFieldGenerator::GenerateStructMembers(io::Printer* printer) const 100 | { 101 | switch (descriptor_->label()) { 102 | case FieldDescriptor::LABEL_REQUIRED: 103 | printer->Print(variables_, "$type$ $name$$deprecated$;\n"); 104 | break; 105 | case FieldDescriptor::LABEL_OPTIONAL: 106 | if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) 107 | printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n"); 108 | printer->Print(variables_, "$type$ $name$$deprecated$;\n"); 109 | break; 110 | case FieldDescriptor::LABEL_REPEATED: 111 | printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); 112 | printer->Print(variables_, "$type$ *$name$$deprecated$;\n"); 113 | break; 114 | } 115 | } 116 | 117 | std::string EnumFieldGenerator::GetDefaultValue(void) const 118 | { 119 | return variables_.find("default")->second; 120 | } 121 | void EnumFieldGenerator::GenerateStaticInit(io::Printer* printer) const 122 | { 123 | switch (descriptor_->label()) { 124 | case FieldDescriptor::LABEL_REQUIRED: 125 | printer->Print(variables_, "$default$"); 126 | break; 127 | case FieldDescriptor::LABEL_OPTIONAL: 128 | if (FieldSyntax(descriptor_) == 2) 129 | printer->Print(variables_, "0, "); 130 | printer->Print(variables_, "$default$"); 131 | break; 132 | case FieldDescriptor::LABEL_REPEATED: 133 | // no support for default? 134 | printer->Print("0,NULL"); 135 | break; 136 | } 137 | } 138 | 139 | void EnumFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const 140 | { 141 | std::string addr = "&" + FullNameToLower(descriptor_->enum_type()->full_name(), descriptor_->enum_type()->file()) + "__descriptor"; 142 | GenerateDescriptorInitializerGeneric(printer, true, "ENUM", addr); 143 | } 144 | 145 | 146 | } // namespace c 147 | } // namespace compiler 148 | } // namespace protobuf 149 | } // namespace google 150 | -------------------------------------------------------------------------------- /protobuf-c/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /protobuf-c/m4/code_coverage.m4: -------------------------------------------------------------------------------- 1 | # SYNOPSIS 2 | # 3 | # MY_CODE_COVERAGE() 4 | # 5 | # DESCRIPTION 6 | # 7 | # Defines CODE_COVERAGE_CFLAGS and CODE_COVERAGE_LDFLAGS which should be 8 | # included in the CFLAGS and LIBS/LDFLAGS variables of every build target 9 | # (program or library) which should be built with code coverage support. 10 | # Also defines CODE_COVERAGE_RULES which should be substituted in your 11 | # Makefile; and $enable_code_coverage which can be used in subsequent 12 | # configure output. CODE_COVERAGE_ENABLED is defined and substituted, and 13 | # corresponds to the value of the --enable-code-coverage option, which 14 | # defaults to being disabled. 15 | # 16 | # Usage example: 17 | # configure.ac: 18 | # MY_CODE_COVERAGE 19 | # 20 | # Makefile.am: 21 | # @CODE_COVERAGE_RULES@ 22 | # my_program_LIBS = … $(CODE_COVERAGE_LDFLAGS) … 23 | # my_program_CFLAGS = … $(CODE_COVERAGE_CFLAGS) … 24 | # 25 | # This results in a “check-code-coverage” rule being added to any Makefile.am 26 | # which includes “@CODE_COVERAGE_RULES@” (assuming the module has been 27 | # configured with --enable-code-coverage). Running `make check-code-coverage` 28 | # in that directory will run the module’s test suite (`make check`) and build 29 | # a code coverage report detailing the code which was touched, then print the 30 | # URI for the report. 31 | # 32 | # LICENSE 33 | # 34 | # Copyright © 2012, 2014 Philip Withnall 35 | # Copyright © 2012 Xan Lopez 36 | # Copyright © 2012 Christian Persch 37 | # Copyright © 2012 Paolo Borelli 38 | # Copyright © 2012 Dan Winship 39 | # 40 | # Derived from Makefile.decl in GLib, originally licenced under LGPLv2.1+. 41 | # This file is licenced under LGPLv2.1+. 42 | 43 | AC_DEFUN([MY_CODE_COVERAGE],[ 44 | dnl Check for --enable-code-coverage 45 | AC_MSG_CHECKING([whether to build with code coverage support]) 46 | AC_ARG_ENABLE([code-coverage], AS_HELP_STRING([--enable-code-coverage], [Whether to enable code coverage support]),, enable_code_coverage=no) 47 | AM_CONDITIONAL([CODE_COVERAGE_ENABLED], [test x$enable_code_coverage = xyes]) 48 | AC_SUBST([CODE_COVERAGE_ENABLED], [$enable_code_coverage]) 49 | AC_MSG_RESULT($enable_code_coverage) 50 | 51 | AS_IF([ test "$enable_code_coverage" = "yes" ], [ 52 | dnl Check if gcc is being used 53 | AS_IF([ test "$GCC" = "no" ], [ 54 | AC_MSG_ERROR([not compiling with gcc, which is required for gcov code coverage]) 55 | ]) 56 | 57 | AC_CHECK_PROG([LCOV], [lcov], [lcov]) 58 | AC_CHECK_PROG([GENHTML], [genhtml], [genhtml]) 59 | 60 | AS_IF([ test -z "$LCOV" ], [ 61 | AC_MSG_ERROR([The lcov program was not found. Please install lcov!]) 62 | ]) 63 | 64 | AS_IF([ test -z "$GENHTML" ], [ 65 | AC_MSG_ERROR([The genhtml program was not found. Please install lcov!]) 66 | ]) 67 | 68 | dnl Build the code coverage flags 69 | CODE_COVERAGE_CFLAGS="-O0 -g --coverage" 70 | CODE_COVERAGE_LDFLAGS="--coverage" 71 | 72 | AC_SUBST([CODE_COVERAGE_CFLAGS]) 73 | AC_SUBST([CODE_COVERAGE_LDFLAGS]) 74 | 75 | dnl Strip optimisation flags 76 | changequote({,}) 77 | CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` 78 | changequote([,]) 79 | ]) 80 | 81 | CODE_COVERAGE_RULES=' 82 | # Code coverage 83 | # 84 | # Optional: 85 | # - CODE_COVERAGE_DIRECTORY: Top-level directory for code coverage reporting. 86 | # (Default: $(top_builddir)) 87 | # - CODE_COVERAGE_OUTPUT_FILE: Filename and path for the .info file generated 88 | # by lcov for code coverage. (Default: 89 | # $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info) 90 | # - CODE_COVERAGE_OUTPUT_DIRECTORY: Directory for generated code coverage 91 | # reports to be created. (Default: 92 | # $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage) 93 | # - CODE_COVERAGE_LCOV_OPTIONS: Extra options to pass to the lcov instance. 94 | # (Default: empty) 95 | # - CODE_COVERAGE_GENHTML_OPTIONS: Extra options to pass to the genhtml 96 | # instance. (Default: empty) 97 | # - CODE_COVERAGE_IGNORE_PATTERN: Extra glob pattern of files to ignore 98 | # 99 | # The generated report will be titled using the $(PACKAGE_NAME) and 100 | # $(PACKAGE_VERSION). In order to add the current git hash to the title, 101 | # use the git-version-gen script, available online. 102 | 103 | # Optional variables 104 | CODE_COVERAGE_DIRECTORY ?= $(abs_top_builddir) 105 | CODE_COVERAGE_OUTPUT_FILE ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info 106 | CODE_COVERAGE_OUTPUT_DIRECTORY ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage 107 | CODE_COVERAGE_LCOV_OPTIONS ?= 108 | CODE_COVERAGE_GENHTML_OPTIONS ?= 109 | CODE_COVERAGE_IGNORE_PATTERN ?= 110 | 111 | code_coverage_quiet = $(code_coverage_quiet_$(V)) 112 | code_coverage_quiet_ = $(code_coverage_quiet_$(AM_DEFAULT_VERBOSITY)) 113 | code_coverage_quiet_0 = --quiet 114 | 115 | # Use recursive makes in order to ignore errors during check 116 | check-code-coverage: 117 | ifeq ($(CODE_COVERAGE_ENABLED),yes) 118 | -$(MAKE) $(AM_MAKEFLAGS) -k check 119 | $(MAKE) $(AM_MAKEFLAGS) code-coverage-capture 120 | else 121 | @echo "Need to reconfigure with --enable-code-coverage" 122 | endif 123 | 124 | # Capture code coverage data 125 | code-coverage-capture: code-coverage-capture-hook 126 | ifeq ($(CODE_COVERAGE_ENABLED),yes) 127 | $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --capture --output-file "$(CODE_COVERAGE_OUTPUT_FILE).tmp" --test-name "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" --no-checksum --compat-libtool $(CODE_COVERAGE_LCOV_OPTIONS) 128 | $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --remove "$(CODE_COVERAGE_OUTPUT_FILE).tmp" "/tmp/*" $(CODE_COVERAGE_IGNORE_PATTERN) --output-file "$(CODE_COVERAGE_OUTPUT_FILE)" 129 | -@rm -f $(CODE_COVERAGE_OUTPUT_FILE).tmp 130 | LANG=C $(GENHTML) $(code_coverage_quiet) --prefix $(CODE_COVERAGE_DIRECTORY) --output-directory "$(CODE_COVERAGE_OUTPUT_DIRECTORY)" --title "$(PACKAGE_NAME)-$(PACKAGE_VERSION) Code Coverage" --legend --show-details "$(CODE_COVERAGE_OUTPUT_FILE)" $(CODE_COVERAGE_GENHTML_OPTIONS) 131 | @echo "file://$(abs_builddir)/$(CODE_COVERAGE_OUTPUT_DIRECTORY)/index.html" 132 | else 133 | @echo "Need to reconfigure with --enable-code-coverage" 134 | endif 135 | 136 | # Hook rule executed before code-coverage-capture, overridable by the user 137 | code-coverage-capture-hook: 138 | 139 | ifeq ($(CODE_COVERAGE_ENABLED),yes) 140 | clean: code-coverage-clean 141 | code-coverage-clean: 142 | -$(LCOV) --directory $(CODE_COVERAGE_DIRECTORY) -z 143 | -rm -rf $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_FILE).tmp $(CODE_COVERAGE_OUTPUT_DIRECTORY) 144 | -find . -name "*.gcda" -o -name "*.gcov" -delete 145 | endif 146 | 147 | GITIGNOREFILES ?= 148 | GITIGNOREFILES += $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_DIRECTORY) 149 | 150 | DISTCHECK_CONFIGURE_FLAGS ?= 151 | DISTCHECK_CONFIGURE_FLAGS += --disable-code-coverage 152 | 153 | .PHONY: check-code-coverage code-coverage-capture code-coverage-capture-hook code-coverage-clean 154 | ' 155 | 156 | AC_SUBST([CODE_COVERAGE_RULES]) 157 | m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([CODE_COVERAGE_RULES])]) 158 | ]) 159 | --------------------------------------------------------------------------------