pub struct ResourceAdvertisement {
pub transfer_size: u64,
pub data_size: u64,
pub num_parts: u64,
pub resource_hash: Vec<u8>,
pub random_hash: Vec<u8>,
pub original_hash: Vec<u8>,
pub hashmap: Vec<u8>,
pub flags: AdvFlags,
pub segment_index: u64,
pub total_segments: u64,
pub request_id: Option<Vec<u8>>,
}Expand description
Resource advertisement data, corresponding to Python’s ResourceAdvertisement.
Fields§
§transfer_size: u64Transfer size (encrypted data size)
data_size: u64Total uncompressed data size (including metadata overhead)
num_parts: u64Number of parts
resource_hash: Vec<u8>Resource hash (full 32 bytes)
random_hash: Vec<u8>Random hash (4 bytes)
original_hash: Vec<u8>Original hash (first segment, 32 bytes)
hashmap: Vec<u8>Hashmap segment (concatenated 4-byte part hashes)
flags: AdvFlagsFlags byte
segment_index: u64Segment index (1-based)
total_segments: u64Total segments
request_id: Option<Vec<u8>>Request ID (optional)
Implementations§
Source§impl ResourceAdvertisement
impl ResourceAdvertisement
Sourcepub fn pack(&self, segment: usize) -> Vec<u8> ⓘ
pub fn pack(&self, segment: usize) -> Vec<u8> ⓘ
Pack the advertisement to msgpack bytes.
segment controls which hashmap segment to include (0-based).
Sourcepub fn pack_for_mdu(&self, segment: usize, mdu: usize) -> Vec<u8> ⓘ
pub fn pack_for_mdu(&self, segment: usize, mdu: usize) -> Vec<u8> ⓘ
Pack the advertisement for a link with the given MDU.
Like Python, an advertisement that would exceed the MDU is sent with
an empty hashmap, and the receiver requests the first hashmap segment
with RESOURCE_HASHMAP_IS_EMPTY before any part.
Sourcepub fn unpack(data: &[u8]) -> Result<Self, ResourceError>
pub fn unpack(data: &[u8]) -> Result<Self, ResourceError>
Unpack an advertisement from msgpack bytes.
Sourcepub fn is_request(&self) -> bool
pub fn is_request(&self) -> bool
Check if this advertisement is a request.
Sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
Check if this advertisement is a response.
Sourcepub fn app_flag_set(&self) -> bool
pub fn app_flag_set(&self) -> bool
Whether the sender set the application flag (Python app_flag_set).
Sourcepub fn hashmap_segments(&self) -> usize
pub fn hashmap_segments(&self) -> usize
Get the number of hashmap segments needed.