This document describes the binary wire protocol used by the protocol package. The protocol is designed to be simple, efficient, and suitable for streaming over any io.Reader / io.Writer (e.g. TCP connections).
Each message is sent as a fixed-order binary frame:
+------------+----------------+-------------------+-------------------+
| 1 byte | 8 bytes | 4 bytes | N bytes |
| MsgType | RequestID | Payload Length | Payload |
+------------+----------------+-------------------+-------------------+
All multi-byte integer fields are encoded using big-endian byte order.
The first byte of every message identifies its type.
| Name | Value | Description |
|---|---|---|
MsgReady |
1 | Indicates readiness or successful initialization |
MsgPing |
2 | Keepalive or liveness check |
MsgPong |
3 | Response to MsgPing |
MsgError |
4 | Error message |
MsgRequest |
6 | Request message |
MsgResponse |
7 | Response message |
- Type:
byte - Purpose: Identifies the semantic meaning of the message
- Required: Yes
-
Type:
uint64 -
Encoding: Big-endian
-
Purpose:
- Correlates requests and responses
- Can be
0for messages that do not participate in request/response semantics (e.g.Ping,Ready)
-
Type:
uint32 -
Encoding: Big-endian
-
Purpose: Specifies the number of bytes in the payload
-
Value:
0means no payload
- Type: Raw bytes (
[]byte) - Length: Defined by the Payload Length field
- Encoding: Application-defined
type Message struct {
Type MsgType
RequestID uint64
Payload []byte
}Messages are read sequentially from a stream in the following order:
- Read 1 byte →
MsgType - Read 8 bytes →
RequestID - Read 4 bytes →
Payload Length - Read
Payload Lengthbytes →Payload
Note
This file is generated by AI from the project code