Module mobile_codec

Module mobile_codec 

Source
Expand description

Mobile Protocol Codec (16-byte header)

This module implements the mobile-optimized ZUS RPC protocol with a compact 16-byte header designed for mobile clients with bandwidth constraints.

§Protocol Differences from Standard (40-byte)

FeatureStandard (40-byte)Mobile (16-byte)
Header size40 bytes16 bytes
Magic0xD3A7 (2 bytes)0xDF (1 byte)
Sequence IDu64 (8 bytes)u16 (2 bytes)
Timeoutu64 (8 bytes)u16 (2 bytes, seconds)
Data CRCu32 (full CRC32)u16 (lower 16 bits)
Trace IDu64 (8 bytes)Not present
Compress threshold4096 bytes256 bytes

§Header Layout (16 bytes, Big-Endian)

Offset  Field       Type    Size    Description
------  ----------  ------  ------  -----------
0       magic       u8      1       0xDF
1       version     u8      1       Protocol version
2       cmdtype     u8      1       Message type (1=REQ, 2=RSP, 3=NOTIFY, 4=SYSRSP)
3       flag        u8      1       Flags: bit0=compressed, bit1=encrypted, bit2=fragment
4       headcrc16   u16     2       Header CRC (truncating addition)
6       datacrc     u16     2       Data CRC (lower 16 bits of CRC32)
8       seqId       u16     2       Sequence ID (0-65535, wraps around)
10      timeout     u16     2       Timeout in seconds (not milliseconds!)
12      datalen     u32     4       Body length in bytes
Total: 16 bytes

§Heartbeat Packet (8 bytes)

Mobile clients send periodic heartbeat packets with magic 0xEF:

Offset  Field       Type    Size    Description
------  ----------  ------  ------  -----------
0       magic       u8      1       0xEF
1-7     padding     [u8;7]  7       Reserved/padding
Total: 8 bytes

Structs§

MobileCodec
Mobile Protocol Codec
MobileHeartbeat
Mobile Heartbeat Packet (8 bytes)
MobileMessage
Mobile RPC Message
MobileProtocolHeader
Mobile Protocol Header (16 bytes)

Enums§

MobilePacket
Decoded packet type from mobile protocol

Constants§

HEARTBEAT_MAGIC
Mobile heartbeat magic number (1 byte)
HEARTBEAT_SIZE
Heartbeat packet size
MOBILE_COMPRESS_THRESHOLD
Default compression threshold for mobile protocol (256 bytes) Lower than standard (4KB) to optimize for mobile bandwidth
MOBILE_HEADER_SIZE
Mobile protocol header size
MOBILE_MAGIC
Mobile protocol magic number (1 byte)