Giter Club home page Giter Club logo

protobuf-c-rpc's Introduction

Build Status Coverage Status

Overview

This is protobuf-c, a C implementation of the Google 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 project.

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!

Mailing list

protobuf-c's mailing list is hosted on a Google Groups forum. Subscribe by sending an email to [email protected].

Building

protobuf-c requires a C compiler, a C++ compiler, protobuf, and pkg-config to be installed.

./configure && make && make install

If building from a git checkout, the autotools (autoconf, automake, libtool) must also be installed, and the build system must be generated by running the autogen.sh script.

./autogen.sh && ./configure && make && make install

Test

If you want to execute test cases individually, please run the following command after running ./configure once:

 make check

Documentation

See the online Doxygen documentation here or the Wiki for a detailed reference. The Doxygen documentation can be built from the source tree by running:

make html

Synopsis

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.

protoc --c_out=. example.proto

Include the .pb-c.h file from your C source code.

#include "example.pb-c.h"

Compile your C source code together with the .pb-c.c file. Add the output of the following command to your compile flags.

pkg-config --cflags 'libprotobuf-c >= 1.0.0'

Link against the libprotobuf-c support library. Add the output of the following command to your link flags.

pkg-config --libs 'libprotobuf-c >= 1.0.0'

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:

PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 1.0.0])

This will place compiler flags in the PROTOBUF_C_CFLAGS variable and linker flags in the PROTOBUF_C_LDFLAGS variable. Read more information here about the PKG_CHECK_MODULES macro.

Versioning

protobuf-c follows the Semantic Versioning Specification as of version 1.0.0.

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.)

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.

Contributing

Please send patches to the protobuf-c mailing list or by opening a GitHub pull request.

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.

Copyright to all contributions are retained by the original author, but must be licensed under the terms of the BSD-2-Clause license. Please add a Signed-off-by header to your commit message (git commit -s) to indicate that you are licensing your contribution under these terms.

protobuf-c-rpc's People

Contributors

baloo avatar eroullit avatar lipnitsk avatar worr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protobuf-c-rpc's Issues

protobuf-c-rpc.h has no C++ header guard (extern "C")

When I currently include protobuf-c-rpc.h, I'm forced to externally bracket it with:

#ifdef __cplusplus
extern "C" {
#endif
#include <protobuf-c-rpc/protobuf-c-rpc.h>
#ifdef __cplusplus
}
#endif

This could be remedied by adding something like this before the #includes in protobuf-c-rpc.h:

#if defined(__cplusplus) && !defined(PROTOBUF_C__BEGIN_DECLS)
# define PROTOBUF_C__BEGIN_DECLS	extern "C" {
# define PROTOBUF_C__END_DECLS		}
#else
# define PROTOBUF_C__BEGIN_DECLS
# define PROTOBUF_C__END_DECLS
#endif

protobuf_c_dispatch_run return information

I think this function protobuf_c_dispatch_run must return int code.
I apply this code to project but can't handle when "rpc timeout" or "rpc ok".
Maybe get return error from poll and 0 when "rpc ok"

compile error

⇒ make
GEN t/test.pb-c.c
[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: t/test.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-am
CC protobuf-c-rpc/protobuf-c-rpc-data-buffer.lo
CC protobuf-c-rpc/protobuf-c-rpc-dispatch.lo
CC protobuf-c-rpc/protobuf-c-rpc-client.lo
CC protobuf-c-rpc/protobuf-c-rpc-server.lo
CCLD protobuf-c-rpc/libprotobuf-c-rpc.la
Undefined symbols for architecture x86_64:
"_protobuf_c_buffer_simple_append", referenced from:
_server_connection_response_closure in protobuf-c-rpc-server.o
"_protobuf_c_message_check", referenced from:
_client_serialize in protobuf-c-rpc-client.o
_server_serialize in protobuf-c-rpc-server.o
"_protobuf_c_message_free_unpacked", referenced from:
_handle_client_fd_events in protobuf-c-rpc-client.o
_handle_server_connection_events in protobuf-c-rpc-server.o
"_protobuf_c_message_get_packed_size", referenced from:
_client_serialize in protobuf-c-rpc-client.o
_server_serialize in protobuf-c-rpc-server.o
"_protobuf_c_message_pack_to_buffer", referenced from:
_client_serialize in protobuf-c-rpc-client.o
_server_serialize in protobuf-c-rpc-server.o
"_protobuf_c_message_unpack", referenced from:
_client_deserialize in protobuf-c-rpc-client.o
_server_deserialize in protobuf-c-rpc-server.o
"_protobuf_c_service_destroy", referenced from:
_protobuf_c_rpc_server_destroy in protobuf-c-rpc-server.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[1]: *** [protobuf-c-rpc/libprotobuf-c-rpc.la] Error 1
make: *** [all] Error 2

Endianess check for convert functions seems not to work properly

The function uint32_to_le/uint32_to_le shall convert an integer value to little endian or from little endian. But it seems that the endianess check seems a bit weak. When cross compiled for a big endian target, the check mentioned above has not detected the targets big endianess.

#if !defined(WORDS_BIGENDIAN)

#if !defined(WORDS_BIGENDIAN)

Can not parse data, returns null, WireType 7 missing??

code
gdb

Protocol: https://raw.githubusercontent.com/libp2p/js-libp2p-secio/master/src/handshake/secio.proto.js (the Propose protocol)
Data(hex): 0a10cb5d0c1c2adbdf1ec86f731725ac04e512ab02080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100d0da1c02f3f66ef502ab1e741c9be07e8e2f013959443c1714148745f9d8cdc3f40e43276835620a7358350d577c19beea7cb50a7ce746412a48632d9622862567a356fe1121517996c25097db4e2c83c2d470e7ed7680e8bbe5af44e7cab9cb3b75420522b770995ad214b28945de8e886ad8afa92ef122144ba2ae95b5ae78eefdcb3b680dd2ce79b9ed23e1d409960027b101205a80b6f40cfe80fac560e9f35b98d4ec43b2c6ebe8cd6a88594f9cb1a1bc011a7426c332e5d7ccbe0aa591687b17716770530b3aa54e7b52457155792c21c399801379355139fcf7ccc7d3d9c3d4474345cc59b994eb542d13ed018178d1c2ed23a22c0ab9d039c6e347a102030100011a11502d3235362c502d3338342c502d35323122184145532d3235362c4145532d3132382c426c6f77666973682a0d5348413235362c534841353132

some question about the detail design of dispatcher

hi, im trying to implement the dispatcher's poll mode into epoll mode, but when i read the code, i found some questions:
why does the function protobuf_c_rpc_dispatch_run have to allocate and copy and then free over and over again? Maybe its better to create a thread-private pollfd, and update it instead of allocating and using it just one time?
Maybe i misunderstand the code, but i'd appreciate it if you give me some detail explanation, thx!

How to configure for using other specificy gcc by Buildroot

Hi, I want to compile protobuf-c-rpc for the embedded system using bulldroot, could you tell me how this can be done?

Usually it's enough just to specify arm-buildroot-linux-gnueabihf-gcc instead of gcc in Makefile;
and need to change output directories in make install from
/usr/local/include/ and /usr/local/lib/ to
.../buildroot/output/target/usr/include and .../buildroot/output/target/usr/lib for example:

How do I change the instruction set to achieve this?

Compatibility with protobuf.socketrpc

protobuf.socketrpc uses a slightly more complex rpc wrapper (along with a .proto definition), which is incompatible with protobuf-c-rpc's fixed size header/response.

Using this, protobuf-c-rpc could be scriptable in Java/Python as an example.

Access the child connection file descriptor

When a new connection is made, the accept() system call returns a file descriptor that is used to perform all subsequent communication for a given session.

That FD is maintained in:

struct _ServerConnection
{
  int fd;
...

Now, this structure is private and thus no advertised API.

However, I would like to access this FD as I would like to use it to use it with getsockopt().

Currently I have to copy the structure definitions of struct _ServerConnection and struct _ServerRequest into my code and resolve it using the closure data as follows:

int func(void *closure_data)
{
        ServerRequest *server_request = closure_data;
        ServerConnection *conn = server_request->conn;
        struct ucred cred;
        socklen_t len = sizeof(cred);

        if (getsockopt(conn->fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
...

This is a hack that I would like to avoid. Is there a way to access the FD using the API? If not, I would be willing to write a patch. But I am not sure how such a patch would look like as there are 2 options:

  • make the FD available, i.e. return the FD number

  • provide wrapper API calls around getsockopt (e.g. one API call to obtain SO_PEERCRED, one for another call).

I would lean towards the first option.

(Question) Golang client compatibility

Greetings!
I’m trying to implement a gRPC server based on the examples you have provided.
As for the client, I’m using a Go client, setting it up like this:

func setupClient(target string) (pb.Rpc1Client, error) {
  conn, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
  if err != nil {
    return nil, err
  }
  return pb.NewRpc1Client(conn), nil
}

Unfortunately, when trying to send a request to the server I get an error. Client side:

2023/08/03 05:37:01 INFO: [transport] transport: loopyWriter.run returning. connection error: desc = "transport is closing"
2023/08/03 05:37:01 WARNING: [core] grpc: addrConn.createTransport failed to connect to {192.168.98.13:7777 192.168.98.13:7777 <nil> <nil> 0 <nil>}: failed to receive server preface within timeout

Server side: PROTOBUF_C_RPC_PROTOCOL_STATUS_INCOMPLETE_BUFFER

Successful request, C client:
изображение

Failed exchange, Go client:
изображение

It looks like the Go client attempts to connect using HTTP/2 as transport whereas the server does not support it.
Could you please help me solve this problem: is there a way I can tune the server to be compatible with the Go client or it is not possible at all?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.