pub struct Data<T> { /* private fields */ }Expand description
The packet returned in response to a matching Interest.
T is the type the content decodes/encodes as; use Bytes to work
with the raw payload, or a type implementing
ndn_tlv::TlvEncode/ndn_tlv::TlvDecode to work with it directly.
Implementations§
Source§impl Data<Bytes>
impl Data<Bytes>
Sourcepub fn decode_content<U>(self) -> Data<U>where
U: TlvDecode,
pub fn decode_content<U>(self) -> Data<U>where
U: TlvDecode,
Decodes the raw content into a concrete type U, converting a Data<Bytes> into the
corresponding Data<U>.
If decoding fails, or there was no content to begin with, the returned Data simply has none.
Source§impl<T> Data<T>where
T: TlvEncode,
impl<T> Data<T>where
T: TlvEncode,
Sourcepub const fn new(name: Name, content: T) -> Self
pub const fn new(name: Name, content: T) -> Self
Creates a new, unsigned Data packet for name carrying content,
with its content type defaulted to ContentType::BLOB.
Sourcepub fn set_meta_info(&mut self, meta_info: Option<MetaInfo>) -> &mut Self
pub fn set_meta_info(&mut self, meta_info: Option<MetaInfo>) -> &mut Self
Sets the Data packet’s MetaInfo, or clears it if None.
Sourcepub fn set_content(&mut self, content: Option<T>) -> &mut Self
pub fn set_content(&mut self, content: Option<T>) -> &mut Self
Sets the Data packet’s content, or clears it if None.
Sourcepub fn encode_content(self) -> Data<Bytes>
pub fn encode_content(self) -> Data<Bytes>
Encodes the content to its raw TLV bytes, the inverse of
Data::decode_content.
Sourcepub fn sign<S>(&mut self, sign_method: &mut S)where
S: SignMethod,
pub fn sign<S>(&mut self, sign_method: &mut S)where
S: SignMethod,
Signs the Data packet with sign_method.
Sourcepub fn sign_cert<S>(&mut self, sign_method: &S, validity_period: ValidityPeriod)where
S: SignMethod,
pub fn sign_cert<S>(&mut self, sign_method: &S, validity_period: ValidityPeriod)where
S: SignMethod,
Signs the Data packet with sign_method, additionally recording a
ValidityPeriod the signature is only considered valid within.
Used to sign certificates, which need an expiry.
Sourcepub fn signature_info(&self) -> Option<&SignatureInfo>
pub fn signature_info(&self) -> Option<&SignatureInfo>
The signature info added by Data::sign/Data::sign_cert, if the Data is signed.
Sourcepub fn matches_interest<D>(&self, interest: &Interest<D>) -> bool
pub fn matches_interest<D>(&self, interest: &Interest<D>) -> bool
Returns whether this Data satisfies interest by name, respecting
CanBePrefix and an implicit digest
component, if present.
This only checks the name; it doesn’t check
MustBeFresh, since freshness depends on
when the Data was received, which this packet doesn’t know.
Sourcepub fn verify<S>(&self, sign_method: &S) -> Result<(), VerifyError>where
S: SignatureVerifier + ?Sized,
pub fn verify<S>(&self, sign_method: &S) -> Result<(), VerifyError>where
S: SignatureVerifier + ?Sized,
Verify the signature of this Data packet with the given SignMethod
Trait Implementations§
impl<T: Eq> Eq for Data<T>
impl<T: PartialEq> StructuralPartialEq for Data<T>
Source§impl<T> Tlv for Data<T>where
T: TlvEncode,
impl<T> Tlv for Data<T>where
T: TlvEncode,
Source§fn inner_size(&self) -> usize
fn inner_size(&self) -> usize
Source§fn critical() -> bool
fn critical() -> bool
tlv_criticalAuto Trait Implementations§
impl<T> !Freeze for Data<T>
impl<T> RefUnwindSafe for Data<T>where
T: RefUnwindSafe,
impl<T> Send for Data<T>where
T: Send,
impl<T> Sync for Data<T>where
T: Sync,
impl<T> Unpin for Data<T>where
T: Unpin,
impl<T> UnsafeUnpin for Data<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Data<T>where
T: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more