Coder Social home page Coder Social logo

exbotanical / lib.rpc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 20 KB

generic, programmable Remote Procedure Calls and data serialization interface for the C programming language

License: MIT License

Makefile 1.71% Shell 8.62% C 89.67%
rpc rpc-framework application-state-transfer state-synchronization remote-procedure-calls serialization marshalling

lib.rpc's Introduction

lib.rpc

lib.rpc is a C library that describes a data exchange format for Remote Procedure Calls, and exposes a public API for socket-based, multi-node RPC

Serialization Format

The lib.rpc serialization format is a binary representation of the original struct data. The data is buffered into a stream; each unique object is delimited by a cursor (pointer to the memory offset). All NULL data is supplanted with a sentinel identifier (0xFFFFFFFF); this format does not support back-pointers, currently (e.g. no graphs or circular linked lists - fixing this in an upcoming release but by all means open a PR if you beat me to it).

To serialize any object, simply write a function which calls rpc_serialize_data on each member of the given structure; for nested structures, you may recurse and reference its serialization method.

Finally, initialize a buffer (serialbuf_t**) with rpc_serialbuf_init and serialize your data thereon.

Remote Procedure Calls

Given the serialization format, basic RPC is trivial. See the examples dir for an implementation of RPC via UDP sockets.

To run the program:

# you may need to do this
export LD_LIBRARY_PATH=path/to/shared/object
# compile & srv listen
make clean && make && ./server
# in another shell
./client

That is, to implement RPC, one need only write stub functions that serialize and deserialize the data, and the actual remote procedure, of course.

The transport mechanism (e.g. sockets) is negligible here.

Additionally, you may wish to include a header as demonstrated in the aforementioned example. The header should describe the RPC signature and include an identifier that can be interpreted by the RPC server as an available remote procedure (here, this is implemented as an enumeration).

Dynamic Linking

Linking to lib.rpc:

# 1) include and use lib.rpc in your project
# 2) generate object file for your project
gcc -I ../path/to/librpc -c main.c -o main.o
# 3) generate shared object file
make
# 4) link your project to lib.rpc
gcc -o main main.o -L../path/to/librpc -llibrpc
# you may need to add the lib location to your PATH

Linking to lib.rpc on Windows:

# 1) include and use lib.rpc in your project
# 2) generate object file for your project
gcc -I ../path/to/librpc -c main.c -o main.o
# 3) generate shared object file
make win
# 3) link your project to lib.rpc
gcc -o main.exe main.o -L /path/to/lib.rpc -llib_rpc.dll
# you may need to add the lib location to your PATH

Note You may need to add the shared object location by exporting the LD_LIBRARY_PATH variable

Current Limitations

  • cannot serialize/deserialize objects with back-pointers (e.g. circular linked lists, graphs, et al)
  • does not support TLVs or byte endianness

lib.rpc's People

Watchers

 avatar

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.