Files
praxisandClaude Fable 5.2 c2194c59d4 Protocol core: packet translation between source and native
127 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:47 +02:00

23 lines
1.1 KiB
C++

#pragma once
#include "gateway/protocol.hpp"
namespace gateway {
enum class Direction : uint32_t { client_to_server = 0x544E4C43, server_to_client = 0x52565253 };
struct ForeverPacket { uint32_t opcode; Bytes body; };
// One instance per stream direction. Plaintext packets also consume a counter.
// No compression, opcode translation or handshake is implied by this codec.
class ForeverChannel {
Direction direction_; Bytes key_; uint64_t counter_ = 0; bool failed_ = false; size_t packet_limit_ = 65535;
void ready() const;
public:
explicit ForeverChannel(Direction direction,size_t packet_limit=65535): direction_(direction),packet_limit_(packet_limit) {
if(packet_limit<4 || packet_limit>16777216) throw Error("invalid Forever packet limit");
}
~ForeverChannel();
ForeverChannel(const ForeverChannel&) = delete;
ForeverChannel& operator=(const ForeverChannel&) = delete;
void enter_encrypted_mode(Bytes key);
Bytes encode(uint32_t opcode, std::span<const uint8_t> body);
ForeverPacket decode(std::span<const uint8_t> frame);
};
}