pub struct MetadataMessage {
pub msg_type: MetadataMessageType,
pub piece: u32,
pub total_size: Option<u64>,
pub data: Option<Bytes>,
}Expand description
ut_metadata message (BEP 9).
Fields§
§msg_type: MetadataMessageTypeMessage type (request, data, or reject).
piece: u32Zero-based metadata piece index.
total_size: Option<u64>Total metadata size (included in Data messages).
data: Option<Bytes>Metadata piece data (appended after the bencode dict for Data messages).
Implementations§
Source§impl MetadataMessage
impl MetadataMessage
Sourcepub fn data(piece: u32, total_size: u64, data: Bytes) -> Self
pub fn data(piece: u32, total_size: u64, data: Bytes) -> Self
Create a data response for a metadata piece.
Sourcepub fn to_bytes(&self) -> Result<Bytes>
pub fn to_bytes(&self) -> Result<Bytes>
Encode to bytes (bencode dict + optional trailing data).
§Errors
Returns an error if serialization fails.
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
pub fn from_bytes(data: &[u8]) -> Result<Self>
Parse from bytes. The bencode dict may be followed by raw data.
§Errors
Returns an error if the data is not a valid metadata message.
Trait Implementations§
Source§impl Clone for MetadataMessage
impl Clone for MetadataMessage
Source§fn clone(&self) -> MetadataMessage
fn clone(&self) -> MetadataMessage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MetadataMessage
impl Debug for MetadataMessage
Source§impl PartialEq for MetadataMessage
impl PartialEq for MetadataMessage
Source§fn eq(&self, other: &MetadataMessage) -> bool
fn eq(&self, other: &MetadataMessage) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for MetadataMessage
impl StructuralPartialEq for MetadataMessage
Auto Trait Implementations§
impl !Freeze for MetadataMessage
impl RefUnwindSafe for MetadataMessage
impl Send for MetadataMessage
impl Sync for MetadataMessage
impl Unpin for MetadataMessage
impl UnsafeUnpin for MetadataMessage
impl UnwindSafe for MetadataMessage
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