pub struct RpcProtocolHeader {
pub magic: u16,
pub version: u16,
pub datacrc: u32,
pub sequence: u64,
pub msg_type: u8,
pub flags: u8,
pub headcrc16: u16,
pub body_length: u32,
pub timeout: u64,
pub traceid: u64,
}Expand description
RPC Protocol Header (matching Java version RpcProtHead) Total size: 40 bytes
Header structure (matching Java RpcProtHead.java):
- magic (2 bytes): 0xD3A7
- version (2 bytes): 0x0000
- datacrc (4 bytes): CRC32 of uncompressed body data
- seq (8 bytes): sequence number for request/response matching
- cmdtype (1 byte): message type (REQ=0, RSP=1, NOTIFY=2, SYSRSP=3)
- flag (1 byte): bit0=compressed, bit1=encrypted, bit2=has_extra_data
- headcrc16 (2 bytes): simple sum checksum of all header fields (excluding headcrc16 itself)
- datalen (4 bytes): body length
- timeout (8 bytes): timeout in milliseconds
- traceid (8 bytes): trace ID or extra data length when bit2 of flag is set
Fields§
§magic: u16Magic number: 0xD3A7
version: u16Protocol version: 0x0000
datacrc: u32Data CRC32 checksum (on uncompressed body)
sequence: u64Sequence ID for request/response matching
msg_type: u8Message type: REQ/RSP/NOTIFY/SYSRSP
flags: u8Flags: bit 0 = compressed, bit 1 = encrypted, bit 2 = has extra data
headcrc16: u16Header CRC16 checksum (simple sum of header fields)
body_length: u32Body length
timeout: u64Timeout in milliseconds
traceid: u64Trace ID / extra data length
Implementations§
Source§impl RpcProtocolHeader
impl RpcProtocolHeader
pub const HEADER_SIZE: usize = 40
pub fn new(sequence: u64, msg_type: u8) -> Self
pub fn is_compressed(&self) -> bool
pub fn is_encrypted(&self) -> bool
pub fn has_extra_data(&self) -> bool
pub fn set_compressed(&mut self, compressed: bool)
pub fn set_encrypted(&mut self, encrypted: bool)
pub fn set_extra_data(&mut self, has_extra: bool)
Sourcepub fn encode(&self, buf: &mut BytesMut)
pub fn encode(&self, buf: &mut BytesMut)
Encode header to bytes Field order matches Java RpcProtHead.packData(): magic, version, datacrc, seq, cmdtype, flag, headcrc16, datalen, timeout, traceid
Sourcepub fn decode(buf: &mut BytesMut) -> Result<Self>
pub fn decode(buf: &mut BytesMut) -> Result<Self>
Decode header from bytes Field order matches Java RpcProtHead.unpackData(): magic, version, datacrc, seq, cmdtype, flag, headcrc16, datalen, timeout, traceid
Sourcepub fn calculate_datacrc(data: &[u8]) -> u32
pub fn calculate_datacrc(data: &[u8]) -> u32
Calculate CRC32 for body data (uncompressed) This matches the Java implementation which uses standard CRC32
Sourcepub fn verify_datacrc(&self, data: &[u8]) -> bool
pub fn verify_datacrc(&self, data: &[u8]) -> bool
Verify data CRC32
Trait Implementations§
Source§impl Clone for RpcProtocolHeader
impl Clone for RpcProtocolHeader
Source§fn clone(&self) -> RpcProtocolHeader
fn clone(&self) -> RpcProtocolHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more