
//////////////////////////////////////////////////////////////////////////////
//
//   FlatBuffers schema for WAMP v2 messages
//   Copyright (c) typedef int GmbH and contributors
//   Licensed under the MIT License (MIT)
//
//////////////////////////////////////////////////////////////////////////////

/// Define custom attributes to hint a string subtypes:
attribute "uri";
attribute "uri_pattern";
attribute "principal";
attribute "hex";
attribute "base64";

/// WAMP Payload Passthru (PPT) encryption key id. The value can be a hex-encoded string, URI, DNS name, Ethereum address, UUID identifier - any meaningful value which allows the target peer to choose a private key without guessing. The format of the value may depend on the ppt_scheme attribute.
attribute "ppt_keyid";


/// Namespace for WAMP.
namespace wamp;


/// Simple mapping, from string keys to string values.
table Map {
    /// Key, which must match the regular expression `[A-Za-z_][A-Za-z0-9_]*`. That
    /// makes keys a valid identified in FlatBuffers (and most programming languages)
    key: string (required, key);

    /// Value, which may be any (UTF8 encoded Unicode) string.
    value: string;
}

/// Void type (table based) for use with services.
table Void
{
    /// nothing here!
}


/// Namespace for WAMP protocol.
namespace wamp.proto;


/// WAMP message type IDs organized by message categories:
/// - Category 1: Neither Payload nor Forwarding (12 messages)
/// - Category 2: Payload Only (0 messages) - architecturally empty
/// - Category 3: Forwarding Only (3 messages)
/// - Category 4: Both Payload and Forwarding (7 messages)
enum MessageType: uint16
{
    /// No valid message type
    NULL = 0,

    /// [Category 1] Session opening, authentication and closing
    HELLO = 1,
    WELCOME = 2,
    ABORT = 3,
    CHALLENGE = 4,
    AUTHENTICATE = 5,
    GOODBYE = 6,

    /// [Category 4] Used in both PubSub and RPC
    ERROR = 8,

    /// Publish & Subscribe (PubSub)
    PUBLISH = 16,          // [Category 4] Publisher sends event with application payload
    PUBLISHED = 17,        // [Category 1] Router acknowledges publication
    SUBSCRIBE = 32,        // [Category 1] Client subscribes to topic
    SUBSCRIBED = 33,       // [Category 1] Router acknowledges subscription
    UNSUBSCRIBE = 34,      // [Category 1] Client unsubscribes from topic
    UNSUBSCRIBED = 35,     // [Category 1] Router acknowledges unsubscription
    EVENT = 36,            // [Category 4] Router dispatches event with application payload
    EVENT_RECEIVED = 37,   // [Category 3] Subscriber acknowledges event reception (QoS level 2)

    /// Remote Procedure Calls (RPC)
    CALL = 48,             // [Category 4] Caller invokes procedure with application payload
    CANCEL = 49,           // [Category 3] Caller cancels pending call
    RESULT = 50,           // [Category 4] Callee returns result with application payload
    REGISTER = 64,         // [Category 1] Callee registers procedure
    REGISTERED = 65,       // [Category 1] Router acknowledges registration
    UNREGISTER = 66,       // [Category 1] Callee unregisters procedure
    UNREGISTERED = 67,     // [Category 1] Router acknowledges unregistration
    INVOCATION = 68,       // [Category 4] Router invokes procedure with application payload
    INTERRUPT = 69,        // [Category 3] Router interrupts pending invocation
    YIELD = 70             // [Category 4] Callee yields result with application payload
}


/// WAMP session identity information.
table Principal
{
    /// WAMP session ID.
    session: uint64;

    /// WAMP session authentication ID.
    authid: string (principal);

    /// WAMP session authentication role.
    authrole: string (principal);
}


/// WAMP Payload Passthru (PPT) scheme (renamed from `Payload`).
enum PPTScheme: uint8
{
    /// Unset (plain WAMP application payload)
    NONE = 0,

    /// WAMP-cryptobox end-to-end encrypted application payload
    CRYPTOBOX = 1,

    /// MQTT passthrough-mode application payload
    MQTT = 2,

    /// XBR end-to-end encrypted and Ethereum anchored application payload
    XBR = 3,

    /// Raw pass-through of app payload, uninterpreted in any way.
    OPAQUE = 4
}


/// WAMP Payload Passthru (PPT) application payload serializer (renamed from `Serializer`).
enum PPTSerializer: uint8
{
    /// Use same serializer (dynamically or statically typed) for the application payload as used on the transport for the WAMP message envelope.
    TRANSPORT = 0,

    /// Use JSON serializer for dynamically typed application payload.
    JSON = 1,

    /// Use MsgPack serializer for dynamically typed application payload.
    MSGPACK = 2,

    /// Use CBOR serializer for dynamically typed application payload.
    CBOR = 3,

    /// Use UBJSON serializer for dynamically typed application payload.
    UBJSON = 4,

    /// Raw pass-through of application payload, uninterpreted in any way.
    OPAQUE = 5,

    /// Use FlatBuffers serializer for statically typed application payload (https://google.github.io/flatbuffers/index.html).
    FLATBUFFERS = 6,

    /// Use FlexBuffers serializer dynamically typed application payload (https://google.github.io/flatbuffers/flexbuffers.html).
    FLEXBUFFERS = 7
}


/// WAMP Payload Passthru (PPT) application payload cipher (NEW!).
enum PPTCipher: uint8
{
    /// No valid cipher (unfilled)
    NULL = 0,

    /// Particular combination of Salsa20 and Poly1305 specified in Daniel J. Bernstein, "Cryptography in NaCl" (https://cr.yp.to/highspeed/naclcrypto-20090310.pdf), see NaCl (https://nacl.cr.yp.to/) "crypto_secretbox_xsalsa20poly1305" (aka WAMP "cryptobox").
    XSALSA20POLY1305 = 1,

    /// Galois/Counter Mode (GCM), see https://en.wikipedia.org/wiki/Galois/Counter_Mode.
    AES256GCM = 2
}


/// Subscription topic matching method.
enum Match: uint8
{
    /// Match URI exact.
    EXACT = 0,

    /// Match URI by prefix.
    PREFIX = 1,

    /// Match URI by wildcard.
    WILDCARD = 2
}


/// Remote procedure invocation policy, for use with shared registrations.
enum InvocationPolicy: uint8
{
    /// Standard invocation policy: a procedure may only be registered by at most
    /// one callee at a time. This is the default.
    SINGLE = 0,

    /// First callee invocation policy: all calls to a procedure are forwarded to
    /// the callee that first registered. Should that callee unregister, calls
    /// are forwarded to the callee that registered next after the former.
    FIRST = 1,

    /// Last callee invocation policy: all calls to a procedure are forwwrded to
    /// the callee that last registered. Should that callee unregister, calls
    /// are forwarded to the callee that registered next before the former.
    LAST = 2,

    /// Round-robin invocation policy: calls are forward to all registered callees
    /// in a round-robin fashion. Callees that unregister are removed from the
    /// round-robin list, and new callees registering will get calls immediately
    /// in the next dispatching round.
    ROUNDROBIN = 3,

    /// Random invocation policy: calls are forwarded to all registered callees
    /// in a random fashion. Callees that unregister are removed from the set
    /// of callees randomly drawn from to dispatch incoming calls.
    RANDOM = 4
}


/// Call cancel mode.
enum CancelMode: uint8
{
    /// Skip running invocation call.
    SKIP = 0,

    /// Kill running invocation and call.
    KILL = 1,

    /// Kill running invocation and call without waiting.
    KILLNOWAIT = 2
}


/// WAMP transport channel type (`channel_type`). WAMP can run over any Transport which is message-based (requiring no WAMP transport channel framing) or stream-based (requiring WAMP transport channel framing), and bidirectional, reliable and ordered.
enum TransportChannelType: uint8
{
    /// Not set or applicable.
    NULL = 0,

    /// Host language native function call transport, e.g. inherently message-based already (function call).
    FUNCTION = 1,

    /// Host run-time / OS level in-memory transport, e.g. (unframed / stream-based) memory buffer.
    MEMORY = 2,

    /// Serial (UART) based transport (unframed / stream-based).
    SERIAL = 3,

    /// TCP (non-TLS) based transport (unframed / stream-based).
    TCP = 4,

    /// TLS (over TCP) based transport (unframed / stream-based).
    TLS = 5

    /// FUTURE (?):
    /// - add WireGuard (over UDP) based transport.
    /// - add QUIC (over UDP; using TLS 1.3 handshake messages; WebTransport browser API) based transport.
    /// - add WebRTC data channels (SCTP over DTLS; RTCDataChannel browser API) based transport.
    /// - add VirtIO (in-memory queues) based transport.
}


/// WAMP transport channel framing (`channel_framing`).
enum TransportChannelFraming: uint8
{
    /// Not set.
    NULL = 0,

    /// Raw transport itself is inherently message-based already (e.g. FUNCTION or VIRTIO).
    NATIVE = 1,

    /// Raw transport itself (e.g. TCP) is stream-based and channel framing applied is WebSocket (RFC6455).
    WEBSOCKET = 2,

    /// Raw transport itself (e.g. TCP) is stream-based and channel framing applied is RawSocket (WAMP).
    RAWSOCKET = 3
}


/// WAMP transport channel serializer (`channel_serializer`).
enum TransportChannelSerializer: uint8
{
    /// Not set or applicable.
    NULL = 0,

    /// Use JSON serializer (for dynamically typed app payload).
    JSON = 1,

    /// Use MsgPack serializer (for dynamically typed app payload).
    MSGPACK = 2,

    /// Use CBOR serializer (for dynamically typed app payload).
    CBOR = 3,

    /// Use UBJSON serializer (for dynamically typed app payload).
    UBJSON = 4,

    /// Raw pass-through of app payload, uninterpreted in any way.
    OPAQUE = 5,

    /// Use FlatBuffers serialized (statically typed) payload (https://google.github.io/flatbuffers/index.html).
    FLATBUFFERS = 6,

    /// Use FlexBuffers serialized (dynamically typed) payload (https://google.github.io/flatbuffers/flexbuffers.html).
    FLEXBUFFERS = 7
}
