RpcProtocolHeader

Struct RpcProtocolHeader 

Source
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: u16

Magic number: 0xD3A7

§version: u16

Protocol version: 0x0000

§datacrc: u32

Data CRC32 checksum (on uncompressed body)

§sequence: u64

Sequence ID for request/response matching

§msg_type: u8

Message type: REQ/RSP/NOTIFY/SYSRSP

§flags: u8

Flags: bit 0 = compressed, bit 1 = encrypted, bit 2 = has extra data

§headcrc16: u16

Header CRC16 checksum (simple sum of header fields)

§body_length: u32

Body length

§timeout: u64

Timeout in milliseconds

§traceid: u64

Trace ID / extra data length

Implementations§

Source§

impl RpcProtocolHeader

Source

pub const HEADER_SIZE: usize = 40

Source

pub fn new(sequence: u64, msg_type: u8) -> Self

Source

pub fn is_compressed(&self) -> bool

Source

pub fn is_encrypted(&self) -> bool

Source

pub fn has_extra_data(&self) -> bool

Source

pub fn set_compressed(&mut self, compressed: bool)

Source

pub fn set_encrypted(&mut self, encrypted: bool)

Source

pub fn set_extra_data(&mut self, has_extra: bool)

Source

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

Source

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

Source

pub fn calculate_datacrc(data: &[u8]) -> u32

Calculate CRC32 for body data (uncompressed) This matches the Java implementation which uses standard CRC32

Source

pub fn verify_datacrc(&self, data: &[u8]) -> bool

Verify data CRC32

Trait Implementations§

Source§

impl Clone for RpcProtocolHeader

Source§

fn clone(&self) -> RpcProtocolHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RpcProtocolHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more