pub struct UnknownFields { /* private fields */ }Expand description
A collection of unknown fields encountered during decoding.
When a message is decoded with a schema that doesn’t include all fields present on the wire, the unknown fields are stored here so they can be re-encoded without data loss.
Implementations§
Source§impl UnknownFields
impl UnknownFields
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty set of unknown fields.
const so an empty set can be a static (e.g. the default
ReflectMessage::unknown_fields return value for implementations
that don’t preserve unknown fields).
Sourcepub fn push(&mut self, field: UnknownField)
pub fn push(&mut self, field: UnknownField)
Appends an unknown field.
Sourcepub fn iter(&self) -> Iter<'_, UnknownField> ⓘ
pub fn iter(&self) -> Iter<'_, UnknownField> ⓘ
Returns an iterator over the recorded unknown fields.
Sourcepub fn retain(&mut self, f: impl FnMut(&UnknownField) -> bool)
pub fn retain(&mut self, f: impl FnMut(&UnknownField) -> bool)
Retain only the fields for which the predicate returns true.
Used by ExtensionSet::set_extension
and clear_extension to remove
prior occurrences at a given field number.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Compute the encoded size of all unknown fields.
Sourcepub fn write_to(&self, buf: &mut impl EncodeSink)
pub fn write_to(&self, buf: &mut impl EncodeSink)
Re-encode all unknown fields to buf in their original wire format.
Sourcepub fn decode_from_slice(data: &[u8]) -> Result<Self, DecodeError>
pub fn decode_from_slice(data: &[u8]) -> Result<Self, DecodeError>
Decode a concatenation of wire-format fields into UnknownFields.
Reads tag/data pairs until data is exhausted. Each field is decoded
via decode_unknown_field
with the full RECURSION_LIMIT
depth budget and a fresh
DEFAULT_UNKNOWN_FIELD_LIMIT
unknown-field allowance.
Used by GroupCodec to turn a
message’s encoded bytes back into the inner-field representation that
UnknownFieldData::Group wraps.
§Errors
Returns DecodeError if data contains a
malformed tag, truncated field, or exceeds the recursion limit or
unknown-field limit.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for UnknownFields
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for UnknownFields
arbitrary only.Source§fn arbitrary(_u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(_u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Clone for UnknownFields
impl Clone for UnknownFields
Source§impl Debug for UnknownFields
impl Debug for UnknownFields
Source§impl Default for UnknownFields
impl Default for UnknownFields
impl Eq for UnknownFields
Source§impl Extend<UnknownField> for UnknownFields
impl Extend<UnknownField> for UnknownFields
Source§fn extend<T: IntoIterator<Item = UnknownField>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = UnknownField>>(&mut self, iter: T)
Appends each field, in iteration order. A field whose number is already
present is kept as a further record, as push
does.
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<UnknownField> for UnknownFields
impl FromIterator<UnknownField> for UnknownFields
Source§fn from_iter<T: IntoIterator<Item = UnknownField>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = UnknownField>>(iter: T) -> Self
Collects unknown fields into an UnknownFields, keeping their order
and any repeated field numbers.