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.
121 lines
3.3 KiB
C++
121 lines
3.3 KiB
C++
#ifndef LOGOS_PLAIN_RPC_MESSAGE_H
|
|
#define LOGOS_PLAIN_RPC_MESSAGE_H
|
|
|
|
#include "rpc_value.h"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
namespace logos::plain {
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Wire message definitions.
|
|
//
|
|
// Each on-wire frame is [4-byte big-endian length][1-byte type tag][payload].
|
|
// The payload encoding is decided by the codec (JSON today, CBOR planned).
|
|
//
|
|
// `MessageType` doubles as the 1-byte type tag so the codec can decode the
|
|
// right struct without peeking inside the payload. Keep the values stable —
|
|
// they're on the wire.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
enum class MessageType : uint8_t {
|
|
Call = 1,
|
|
Result = 2,
|
|
Subscribe = 3,
|
|
Unsubscribe = 4,
|
|
Event = 5,
|
|
Token = 6,
|
|
Methods = 7,
|
|
MethodsResult = 8,
|
|
};
|
|
|
|
struct MethodMetadata {
|
|
std::string name;
|
|
std::string signature;
|
|
std::string returnType;
|
|
bool isInvokable = true;
|
|
RpcList parameters; // list of {name, type} maps — schema-flexible
|
|
};
|
|
|
|
// Call <module>.<method>(args...). The response is a Result with the same id.
|
|
struct CallMessage {
|
|
uint64_t id;
|
|
std::string authToken;
|
|
std::string object;
|
|
std::string method;
|
|
std::vector<RpcValue> args;
|
|
};
|
|
|
|
// Response to a Call (or Methods) message, matched by id.
|
|
struct ResultMessage {
|
|
uint64_t id;
|
|
bool ok = false;
|
|
RpcValue value; // present when ok
|
|
std::string err; // present when !ok
|
|
std::string errCode; // present when !ok
|
|
};
|
|
|
|
// Subscribe / unsubscribe to a named event on an object.
|
|
// After Subscribe, the peer pushes EventMessage frames whenever the provider
|
|
// emits that event until an Unsubscribe arrives (or the connection closes).
|
|
// eventName "" means "all events on this object" (wildcard).
|
|
struct SubscribeMessage {
|
|
std::string object;
|
|
std::string eventName;
|
|
};
|
|
struct UnsubscribeMessage {
|
|
std::string object;
|
|
std::string eventName;
|
|
};
|
|
|
|
// Fire-and-forget event delivery from provider → subscriber.
|
|
struct EventMessage {
|
|
std::string object;
|
|
std::string eventName;
|
|
std::vector<RpcValue> data;
|
|
};
|
|
|
|
// Authorization token that the consumer wants registered for a specific
|
|
// module name. Mirrors LogosObject::informModuleToken today.
|
|
struct TokenMessage {
|
|
std::string authToken;
|
|
std::string moduleName;
|
|
std::string token;
|
|
};
|
|
|
|
// Query the set of methods a published object exposes. Response is a
|
|
// MethodsResult keyed to the same id.
|
|
struct MethodsMessage {
|
|
uint64_t id;
|
|
std::string authToken;
|
|
std::string object;
|
|
};
|
|
struct MethodsResultMessage {
|
|
uint64_t id;
|
|
bool ok = false;
|
|
std::vector<MethodMetadata> methods;
|
|
std::string err;
|
|
};
|
|
|
|
// Tagged union of every message the wire stack knows.
|
|
using AnyMessage = std::variant<
|
|
CallMessage,
|
|
ResultMessage,
|
|
SubscribeMessage,
|
|
UnsubscribeMessage,
|
|
EventMessage,
|
|
TokenMessage,
|
|
MethodsMessage,
|
|
MethodsResultMessage
|
|
>;
|
|
|
|
// Lookup: AnyMessage variant ↔ MessageType tag.
|
|
MessageType messageTypeOf(const AnyMessage& m);
|
|
|
|
} // namespace logos::plain
|
|
|
|
#endif // LOGOS_PLAIN_RPC_MESSAGE_H
|