mirror of
https://github.com/logos-co/logos-protocol.git
synced 2026-08-27 12:01:15 +00:00
* Extract the Logos protocol layer from logos-cpp-sdk
Transports (plain TCP/TLS, qt_local, qt_remote/QRO, mock), token manager,
consumer core (LogosAPIClient/LogosAPIConsumer incl. the capability
auto-requestModule flow), ModuleProxy, the abstract LogosProviderObject
interface, and the canonical QVariant<->JSON conversion — now behind the
language-neutral lp_* C ABI (logos_protocol.h) carrying the protocol
semver (LOGOS_PROTOCOL_VERSION_*, lp_protocol_version()).
Bytes crossing the ABI use the lossless {"_bytes": base64url} tagging
(NUL-safe), matching the plain wire encoding.
Provider lp_* surface is compiled groundwork; serving lands with module
authoring.
* consumer: typed requestModule for the capability flow
Port of logos-cpp-sdk master f5a127dd ('use updated capability module',
cpp-sdk#85, Iuri Matias) — the touched files (logos_api_client.cpp,
logos_api_consumer.{h,cpp}) moved into this repo in the P1 extraction.
The capability auto-requestModule path now calls a typed std::string
helper on the consumer (which acquires the capability object directly)
instead of a stringly invokeRemoteMethod round-trip. 111/111 tests.
63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
#ifndef LOGOS_PLAIN_RPC_FRAMING_H
|
|
#define LOGOS_PLAIN_RPC_FRAMING_H
|
|
|
|
#include "rpc_message.h"
|
|
#include "wire_codec.h"
|
|
|
|
#include <cstdint>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
|
|
namespace logos::plain {
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Wire framing: one frame is
|
|
//
|
|
// [4-byte big-endian length N][1-byte MessageType tag][N-1 payload bytes]
|
|
//
|
|
// The length covers the tag + payload. 4 bytes give us 4 GiB max per frame
|
|
// (way more than we'll ever need); 1-byte tag holds a MessageType enum
|
|
// value. Payload bytes come from an IWireCodec.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
class FramingError : public std::runtime_error {
|
|
public:
|
|
using std::runtime_error::runtime_error;
|
|
};
|
|
|
|
// Maximum accepted frame length (length-prefix value). 16 MiB is plenty for
|
|
// anything we'll RPC today, and guards against runaway allocation on
|
|
// malformed input.
|
|
constexpr uint32_t kMaxFrameLength = 16u * 1024u * 1024u;
|
|
|
|
// Build a complete frame around a codec-produced payload.
|
|
std::vector<uint8_t>
|
|
encodeFrame(MessageType tag, const std::vector<uint8_t>& payload);
|
|
|
|
// Convenience: encode message via codec + frame in one step.
|
|
std::vector<uint8_t> encodeFrame(IWireCodec& codec, const AnyMessage& msg);
|
|
|
|
// Incremental reader: feed bytes via `append`, pull complete frames out via
|
|
// `next`. Useful with Asio async reads that deliver arbitrary chunk sizes.
|
|
class FrameReader {
|
|
public:
|
|
void append(const uint8_t* data, std::size_t len);
|
|
void append(const std::vector<uint8_t>& chunk) {
|
|
append(chunk.data(), chunk.size());
|
|
}
|
|
|
|
// Returns true and populates `tag` + `payload` with one frame's worth
|
|
// of data. Returns false if the buffer doesn't yet contain a complete
|
|
// frame. Throws FramingError on unrecoverable corruption.
|
|
bool next(MessageType& tag, std::vector<uint8_t>& payload);
|
|
|
|
std::size_t buffered() const { return m_buf.size(); }
|
|
|
|
private:
|
|
std::vector<uint8_t> m_buf;
|
|
};
|
|
|
|
} // namespace logos::plain
|
|
|
|
#endif // LOGOS_PLAIN_RPC_FRAMING_H
|