pub struct Header {
pub method_id: u16,
pub flags: u8,
pub request_id: u32,
pub payload_length: u32,
}Expand description
Decoded header from wire format.
Fields§
§method_id: u16Method identifier (1-65534, 0 reserved, 0xFFFF = abort).
flags: u8Flags byte (see flags module).
request_id: u32Request identifier (0 = event/fire-and-forget).
payload_length: u32Payload length in bytes.
Implementations§
Source§impl Header
impl Header
Sourcepub fn new(
method_id: u16,
flags: u8,
request_id: u32,
payload_length: u32,
) -> Self
pub fn new( method_id: u16, flags: u8, request_id: u32, payload_length: u32, ) -> Self
Create a new header.
Sourcepub fn encode(&self) -> [u8; 11]
pub fn encode(&self) -> [u8; 11]
Encode header to bytes (Big Endian).
§Example
use procwire_client::protocol::{Header, flags};
let header = Header::new(1, flags::RESPONSE, 42, 100);
let bytes = header.encode();
assert_eq!(bytes.len(), 11);Sourcepub fn encode_into(&self, buf: &mut [u8])
pub fn encode_into(&self, buf: &mut [u8])
Encode header into an existing buffer.
§Panics
Panics if buffer is smaller than HEADER_SIZE (11 bytes).
Sourcepub fn decode(buf: &[u8]) -> Option<Self>
pub fn decode(buf: &[u8]) -> Option<Self>
Decode header from bytes (Big Endian).
Returns None if buffer is too short.
§Example
use procwire_client::protocol::Header;
let bytes = [0, 1, 0x03, 0, 0, 0, 42, 0, 0, 0, 100];
let header = Header::decode(&bytes).unwrap();
assert_eq!(header.method_id, 1);
assert_eq!(header.request_id, 42);
assert_eq!(header.payload_length, 100);Sourcepub fn validate(&self, max_payload_size: u32) -> Result<()>
pub fn validate(&self, max_payload_size: u32) -> Result<()>
Validate the header for protocol compliance.
Checks:
- Method ID is not 0 (reserved)
- Payload length doesn’t exceed max
- Reserved flag bits are 0
Sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
Check if this is a response.
Sourcepub fn is_stream_end(&self) -> bool
pub fn is_stream_end(&self) -> bool
Check if this is the final stream chunk.
Sourcepub fn is_to_parent(&self) -> bool
pub fn is_to_parent(&self) -> bool
Check if direction is to parent.
Trait Implementations§
impl Copy for Header
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more