mirror of
https://github.com/logos-co/logos-protocol.git
synced 2026-08-27 20:11:07 +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.
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#ifndef LOGOS_PLAIN_WIRE_CODEC_H
|
|
#define LOGOS_PLAIN_WIRE_CODEC_H
|
|
|
|
#include "rpc_message.h"
|
|
|
|
#include <cstdint>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace logos::plain {
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// IWireCodec — pluggable (de)serializer for the wire message set.
|
|
//
|
|
// The plan calls out CDDL/CBOR as the intended future format. Shipping
|
|
// implementation is `JsonCodec` (nlohmann::json::dump / parse). A future
|
|
// `CborCodec` uses `to_cbor` / `from_cbor` on the same message structs; the
|
|
// messages don't change.
|
|
//
|
|
// `encode` / `decode` produce / consume bare payload bytes — they do NOT
|
|
// handle framing (length prefix or type tag). Framing is `rpc_framing.{h,cpp}`.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
class CodecError : public std::runtime_error {
|
|
public:
|
|
using std::runtime_error::runtime_error;
|
|
};
|
|
|
|
class IWireCodec {
|
|
public:
|
|
virtual ~IWireCodec() = default;
|
|
|
|
// Encode one message to bytes. The caller stamps the type tag and
|
|
// length prefix around the returned payload.
|
|
virtual std::vector<uint8_t> encode(const AnyMessage&) = 0;
|
|
|
|
// Decode one payload of the given type (learned from the 1-byte tag).
|
|
// Throws CodecError on malformed input.
|
|
virtual AnyMessage decode(MessageType tag,
|
|
const uint8_t* data,
|
|
std::size_t len) = 0;
|
|
|
|
// Human-readable name: "json" | "cbor" | ...
|
|
virtual std::string name() const = 0;
|
|
};
|
|
|
|
} // namespace logos::plain
|
|
|
|
#endif // LOGOS_PLAIN_WIRE_CODEC_H
|