sled/3party/rpc_core
tqcq 5c1056cbc8
Some checks failed
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m26s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 1m43s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m52s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m59s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m58s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m24s
feat update
2024-04-13 02:00:19 +08:00
..
include feat update 2024-04-13 02:00:19 +08:00
CMakeLists.txt feat use rpc_core self serializer 2024-04-09 06:36:06 +00:00
LICENSE feat update rpc_core 2024-04-08 22:29:06 +08:00
README.md feat update rpc_core 2024-04-08 22:29:06 +08:00

rpc_core

Build Status Build Status

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

Introduction

The complete rpc frameworks (such as gRPC and brpc) have complex functions and are not practical on embedded platforms.

This project offers a lightweight and user-friendly 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 solely offers the protocol layer and API, and does not include the implementation of the transport layer. For TCP-based implementations: asio_net

Features

  • Header-Only
  • No-Schema
  • Support performance-limited platforms including microchips
  • Support any connection type (tcp socket, serial port, etc.)
  • High Performance Serialization, support most STL containers and user type
  • Serialization plugins implementations for flatbuffers and nlohmann::json
  • RAII-based dispose for automatic cancel request
  • Timeout and Retry API
  • Support std::future interface

Language supports

Requirements

  • C++11
  • Provide your connection implementation: connection
    NOTICE: complete data packets are required for data transmission, such as websocket.
    If using tcp socket, serial port, etc., message pack and unpack need to be implemented. Or you can use stream_connection.

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

  • flatbuffers.hpp
    Supports using types generated by flatbuffers directly as message
    (add the option --gen-object-api when using flatc)

  • json_msg.hpp
    Supports using types supported by nlohmann/json directly as message
    (the to_json/from_json rules in nlohmann/json need to be satisfied, and use DEFINE_JSON_CLASS).

  • json.hpp
    A flexible way to use nlohmann/json

License

This project is licensed under the MIT license.

  • Implementation based on asio: asio_net
    support macOS, Linux, Windows, iOS, Android, etc. and can be used on MCUs that support asio, such as ESP32.

  • Implementation suitable for ESP8266: esp_rpc