RADLib
RADical C++ application framework
RADNet Protocol Generation

There is no standalone RADProtocol module. RADLib's binary-protocol support is a facet of RADNet: the RADProtocol* types live in the RADNet namespace (RADNet/headers/RADNet.h), and the code generator ships as a CMake-invoked Python tool.

Wire frame

RADLib includes a CMake-invoked Python generator for compact binary TCP protocols. The wire frame is:

  • uint32 messageId in network byte order.
  • uint32 payloadSize in network byte order.
  • Binary payload.

JSON protocol files define messages and fields. The generator emits C++ structs, message IDs, payload encoders/decoders, and frame helpers.

Runtime API

At runtime a frame is the RADNet::RADTcpFrame struct (a messageId plus a payload byte vector). RADNet::encodeFrame() serializes one frame to wire bytes, and RADNet::decodeFrames() pulls all complete frames out of a receive buffer, enforcing maxPayloadBytes. Endpoint configuration is described by RADNet::RADProtocolEndpointConfig (address, port, backlog, connect timeout, max payload) and stays JSON-loadable through RADNet::endpointConfigFromJson().

RADNet::RADProtocolSocket is a RADCore::RADObject that frames a RADTcpSocket byte stream. It exposes sendFrame() and the frameReceived, connected, disconnected, and errorOccurred events. RADNet::RADProtocolClient adds connectUsingConfig(), and RADNet::RADProtocolServer adds listenUsingConfig() plus a newConnection event delivering accepted RADProtocolSocket instances.

Core features

  • CMake-invoked Python generator for compact binary TCP protocols.
  • Fixed messageId/payloadSize network-byte-order frame header.
  • RADTcpFrame with encodeFrame()/decodeFrames() helpers.
  • JSON-loadable RADProtocolEndpointConfig via endpointConfigFromJson().
  • RADProtocolSocket/RADProtocolClient/RADProtocolServer event-driven types.

Example:

config.address = "127.0.0.1";
config.port = 9000;
RADCONNECT(client, frameReceived, &handler, Handler, onFrame);
if (client.connectUsingConfig(config)) {
std::vector<uint8_t> payload{0x01, 0x02};
client.sendFrame(/*messageId=*/42, payload);
}
loop.exec();
#define RADCONNECT(Sender, RadEvent, Receiver, Class, RadEventHandler)
Connects an event to a receiver handler using the receiver's thread affinity.
Definition: RADCore.h:100
RADCore task event loop with locked and low-latency scheduling strategies.
Definition: RADCore.h:988
void exec()
Runs the event loop until quit() is called.
Framed protocol TCP client.
Definition: RADNet.h:357
Runtime endpoint configuration loaded from JSON.
Definition: RADNet.h:278
std::string address
Server bind address or client host.
Definition: RADNet.h:280
uint16_t port
TCP port.
Definition: RADNet.h:282