shuai132 / rpc_core

a tiny rpc core library, support c++11、rust.
MIT License
42 stars 4 forks source link
cpp11 mcu rpc rpccore rust serialization

rpc_core

Build Status Build Status Release License

a tiny c++11 rpc library, supports all platforms (macOS, Linux, Windows, iOS, Android, etc.) and most microchips ( Arduino, STM32, ESP32/ESP8266, etc.)

Introduction

Full-feature rpc frameworks (e.g. gRPC and bRPC) very complex and not suitable for embedded systems.

This project offers a lightweight and user-friend rpc library that is better suited for one-to-one rpc calls. It supports all platforms and a wide range of microchips, including Arduino, STM32, ESP32/ESP8266, and more.

Note: This project only offers the protocol layer and API, it does not include the implementation of the transport layer. For TCP-based implementations: asio_net

Features

TCP-based implementations

Requirements

Usage

// The Receiver
rpc->subscribe("cmd", [](const std::string& msg) -> std::string {
    assert(msg == "hello");
    return "world";
});

// The Sender
rpc->cmd("cmd")
    ->msg(std::string("hello"))
    ->rsp([](const std::string& rsp) {
      assert(rsp == "world");
    })
    ->call();

msg and rsp support any serializable type, see Serialization.

Detailed usages and unittests can be found here: rpc_test.cpp

Serialization

High-performance and memory-saving binary serialization.

For example, user data:

struct Type {
  uint8_t id = 1;
  uint8_t age = 18;
  std::string name = "test";
};

json: {"id":1,"age":18,"name":"test"}

library bytes
json 31
flatbuffers 44
protobuf 10
msgpack 8
rpc_core 8

Serialization Plugins

License

This project is licensed under the MIT license.

Links