Documentation
¶
Overview ¶
Code generated by wireforge. DO NOT EDIT.
This file contains type-safe message definitions with binary serialization for a length-prefixed wire protocol. All multi-byte integers are encoded in Big-Endian (network byte order) to ensure cross-platform compatibility.
Wire Protocol Layout (per message):
[Message Type ID : 2 bytes, Big-Endian uint16] [Fixed Header Length : 2 bytes, Big-Endian uint16] [Fixed Header Block : N bytes, padded for natural alignment] [Dynamic Payload : variable length, concatenated string/byte data]
Safety guarantees:
- MaxAllowedPacket (16 MB) prevents memory allocation exploits from corrupted length fields ("poison pill" attack mitigation).
- init() performs compile-time layout validation via unsafe.Sizeof to catch struct size mismatches between the generator and the Go compiler.
- All reads use io.ReadFull to handle socket short-reads correctly.
- Big-Endian encoding ensures consistent behavior across architectures.
Index ¶
Constants ¶
const ( // FrameHeaderSize represents the 2 bytes for TypeID and 2 bytes for FixedHeaderLen. FrameHeaderSize = 4 // MaxAllowedPacket is the hard ceiling on any single message size (16 MB). // Any incoming length field exceeding this value is treated as corrupted // data and rejected immediately, preventing denial-of-service via // malicious allocation requests. MaxAllowedPacket = 16 * 1024 * 1024 )
const HeartbeatMessageFixedSize = 8
HeartbeatMessageFixedSize is the byte size of the fixed header portion (all fixed-width fields including alignment padding, plus uint32 length prefixes for any variable-length fields). This value is encoded in the wire frame header so the receiver knows how many bytes to read before parsing dynamic payload data.
const UserJoinedMessageFixedSize = 16
UserJoinedMessageFixedSize is the byte size of the fixed header portion (all fixed-width fields including alignment padding, plus uint32 length prefixes for any variable-length fields). This value is encoded in the wire frame header so the receiver knows how many bytes to read before parsing dynamic payload data.
const UserLeftMessageFixedSize = 16
UserLeftMessageFixedSize is the byte size of the fixed header portion (all fixed-width fields including alignment padding, plus uint32 length prefixes for any variable-length fields). This value is encoded in the wire frame header so the receiver knows how many bytes to read before parsing dynamic payload data.
const UserMessageFixedSize = 16
UserMessageFixedSize is the byte size of the fixed header portion (all fixed-width fields including alignment padding, plus uint32 length prefixes for any variable-length fields). This value is encoded in the wire frame header so the receiver knows how many bytes to read before parsing dynamic payload data.
Variables ¶
This section is empty.
Functions ¶
func ReadMessageFrame ¶
ReadMessageFrame reads the 4-byte wire frame header from r and returns the message type ID and fixed header length. Use this when you need to dispatch to different message types based on the type ID before calling Unmarshal.
Types ¶
type HeartbeatMessage ¶
type HeartbeatMessage struct {
Timestamp int64
}
HeartbeatMessage represents a wire-serializable message. Fields are ordered and padded to match natural alignment requirements, ensuring identical memory layout between Go and C implementations.
func (*HeartbeatMessage) Marshal ¶
func (h *HeartbeatMessage) Marshal() ([]byte, error)
Marshal serializes the HeartbeatMessage message into wire format and writes the complete framed message (header + payload) to writer in a single Write call.
Wire layout written:
[0:2] Message Type ID (2) [2:4] Fixed Header Length (8) [4:12] Fixed header (primitives + length prefixes, Big-Endian) [12:end] Dynamic payload (concatenated variable-length data)
Returns an error if the total message size exceeds MaxAllowedPacket.
func (*HeartbeatMessage) MessageTypeID ¶
func (h *HeartbeatMessage) MessageTypeID() uint16
MessageTypeID returns the unique wire protocol type identifier for HeartbeatMessage. This ID occupies the first 2 bytes of every framed message on the wire and is used by the receiver to select the correct deserialization codec.
func (*HeartbeatMessage) Unmarshal ¶
func (h *HeartbeatMessage) Unmarshal(reader io.Reader, fixedHeaderLen uint16) error
Unmarshal deserializes a HeartbeatMessage from the wire after the 4-byte frame header has already been consumed. The caller provides fixedHeaderLen (read from the frame) so forward-compatible readers can skip unknown trailing bytes in the fixed header if a newer sender adds fields.
All variable-length fields are validated against MaxAllowedPacket before allocation, and io.ReadFull is used to guarantee complete reads even on streaming sockets that may deliver partial data.
type UserJoinedMessage ¶
UserJoinedMessage represents a wire-serializable message. Fields are ordered and padded to match natural alignment requirements, ensuring identical memory layout between Go and C implementations.
func (*UserJoinedMessage) Marshal ¶
func (u *UserJoinedMessage) Marshal() ([]byte, error)
Marshal serializes the UserJoinedMessage message into wire format and writes the complete framed message (header + payload) to writer in a single Write call.
Wire layout written:
[0:2] Message Type ID (3) [2:4] Fixed Header Length (16) [4:20] Fixed header (primitives + length prefixes, Big-Endian) [20:end] Dynamic payload (concatenated variable-length data)
Returns an error if the total message size exceeds MaxAllowedPacket.
func (*UserJoinedMessage) MessageTypeID ¶
func (u *UserJoinedMessage) MessageTypeID() uint16
MessageTypeID returns the unique wire protocol type identifier for UserJoinedMessage. This ID occupies the first 2 bytes of every framed message on the wire and is used by the receiver to select the correct deserialization codec.
func (*UserJoinedMessage) Unmarshal ¶
func (u *UserJoinedMessage) Unmarshal(reader io.Reader, fixedHeaderLen uint16) error
Unmarshal deserializes a UserJoinedMessage from the wire after the 4-byte frame header has already been consumed. The caller provides fixedHeaderLen (read from the frame) so forward-compatible readers can skip unknown trailing bytes in the fixed header if a newer sender adds fields.
All variable-length fields are validated against MaxAllowedPacket before allocation, and io.ReadFull is used to guarantee complete reads even on streaming sockets that may deliver partial data.
type UserLeftMessage ¶
UserLeftMessage represents a wire-serializable message. Fields are ordered and padded to match natural alignment requirements, ensuring identical memory layout between Go and C implementations.
func (*UserLeftMessage) Marshal ¶
func (u *UserLeftMessage) Marshal() ([]byte, error)
Marshal serializes the UserLeftMessage message into wire format and writes the complete framed message (header + payload) to writer in a single Write call.
Wire layout written:
[0:2] Message Type ID (4) [2:4] Fixed Header Length (16) [4:20] Fixed header (primitives + length prefixes, Big-Endian) [20:end] Dynamic payload (concatenated variable-length data)
Returns an error if the total message size exceeds MaxAllowedPacket.
func (*UserLeftMessage) MessageTypeID ¶
func (u *UserLeftMessage) MessageTypeID() uint16
MessageTypeID returns the unique wire protocol type identifier for UserLeftMessage. This ID occupies the first 2 bytes of every framed message on the wire and is used by the receiver to select the correct deserialization codec.
func (*UserLeftMessage) Unmarshal ¶
func (u *UserLeftMessage) Unmarshal(reader io.Reader, fixedHeaderLen uint16) error
Unmarshal deserializes a UserLeftMessage from the wire after the 4-byte frame header has already been consumed. The caller provides fixedHeaderLen (read from the frame) so forward-compatible readers can skip unknown trailing bytes in the fixed header if a newer sender adds fields.
All variable-length fields are validated against MaxAllowedPacket before allocation, and io.ReadFull is used to guarantee complete reads even on streaming sockets that may deliver partial data.
type UserMessage ¶
UserMessage represents a wire-serializable message. Fields are ordered and padded to match natural alignment requirements, ensuring identical memory layout between Go and C implementations.
func (*UserMessage) Marshal ¶
func (u *UserMessage) Marshal() ([]byte, error)
Marshal serializes the UserMessage message into wire format and writes the complete framed message (header + payload) to writer in a single Write call.
Wire layout written:
[0:2] Message Type ID (1) [2:4] Fixed Header Length (16) [4:20] Fixed header (primitives + length prefixes, Big-Endian) [20:end] Dynamic payload (concatenated variable-length data)
Returns an error if the total message size exceeds MaxAllowedPacket.
func (*UserMessage) MessageTypeID ¶
func (u *UserMessage) MessageTypeID() uint16
MessageTypeID returns the unique wire protocol type identifier for UserMessage. This ID occupies the first 2 bytes of every framed message on the wire and is used by the receiver to select the correct deserialization codec.
func (*UserMessage) Unmarshal ¶
func (u *UserMessage) Unmarshal(reader io.Reader, fixedHeaderLen uint16) error
Unmarshal deserializes a UserMessage from the wire after the 4-byte frame header has already been consumed. The caller provides fixedHeaderLen (read from the frame) so forward-compatible readers can skip unknown trailing bytes in the fixed header if a newer sender adds fields.
All variable-length fields are validated against MaxAllowedPacket before allocation, and io.ReadFull is used to guarantee complete reads even on streaming sockets that may deliver partial data.