Skip to content

Binary Frame Specification

AfterLink v1.2.4 operates at the binary transport boundary. Every packet consists of a rigid, color-coded 10-byte fixed header, followed immediately by an optional variable-length MessagePack-encoded payload.

Header Byte Layout Mapping

Below is the logical arrangement of AfterLink's 10-byte header on the TCP network wire:

Frame Header Structure

Magic Identifier
2 Bytes (0xAF 0x1C)
Version
1 Byte (0x01)
Type
1 Byte
Sequence No.
2 Bytes (0-65535)
Payload Length
4 Bytes (uint32)
Payload Body Data
Variable size (MessagePack bytes)

Field Definitions

Field Size Wire Type Offset (Bytes) Description
magic 2 bytes UInt8[2] 0 – 1 Protocol identifier: fixed 0xAF 0x1C. Restricts incoming socket streams.
version 1 byte UInt8 2 Protocol version encoder flag. Currently fixed to 0x01.
type 1 byte UInt8 3 Message type byte determining how the frame is routed.
seq 2 bytes UInt16BE 4 – 5 Sequence index for reliable RPC matching. Wraps at 65535.
length 4 bytes UInt32BE 6 – 9 Big-endian size count of payload data in bytes (max ~4.29 GB).
payload variable Buffer 10+ MessagePack-encoded message body containing payload values.

Message Types

The Message Type flag byte defines the routing channel behavior of the server:

Hex Value Constant Direction Purpose & Description
0x01 MSG_REQUEST Client → Server RPC request — expects a responsive matching reply frame.
0x02 MSG_RESPONSE Server → Client RPC response payload frame matched by sequence number.
0x03 MSG_PUBLISH Client → Server Broadcast a message frame to a Pub/Sub channel.
0x04 MSG_SUBSCRIBE Client → Server Subscribe to Pub/Sub channel notifications.
0x05 MSG_BROADCAST Server → Client Fan-out pub/sub message forwarded to active subscribers.
0x06 MSG_STREAM Server → Client Streaming data chunks (multi-frame chunk payloads).
0x07 MSG_STREAM_END Server → Client End of stream signal payload packet.
0x08 MSG_ERROR Both Error flag indicating payload parsing or connection errors.
0xFE MSG_ACK Both Acknowledge code payload packet matched by sequence number.
0xFF MSG_PING Both Keepalive heartbeat ping to check connection availability.

Low-Level Codec Code Example

Using the @afterlink/core library, developers can encode and decode raw frames directly on top of raw socket streams: