pub struct UnknownFieldsView<'a> { /* private fields */ }Expand description
A borrowed view of unknown fields.
Stores raw byte slices from the input buffer rather than decoded values,
enabling zero-copy round-tripping of unknown fields. Each stored span
holds one or more consecutive complete (tag, value) records:
adjacent unknown fields are coalesced into a single span, so a long run
of unknown fields costs one Vec slot rather than one per field.
Coalescing bounds the view’s memory only — the decode-time
unknown-field allowance is still charged per field (see
push_record).
Implementations§
Source§impl<'a> UnknownFieldsView<'a>
impl<'a> UnknownFieldsView<'a>
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Total byte length of all unknown field data.
Sourcepub fn write_to(&self, buf: &mut impl BufMut)
pub fn write_to(&self, buf: &mut impl BufMut)
Write all unknown-field bytes verbatim. Each span holds one or more
complete (tag, value) records as they appeared on the wire, so
concatenating the spans produces a valid encoding.
Sourcepub fn to_owned(&self) -> Result<UnknownFields, DecodeError>
pub fn to_owned(&self) -> Result<UnknownFields, DecodeError>
Convert to an owned UnknownFields by parsing all stored raw byte spans.
Each span holds one or more consecutive (tag + value) records as they
appeared on the wire. Parsing uses
crate::encoding::decode_unknown_field under exactly the budget
push_record charged at decode time — the same
field count and group-nesting depth — so replay cannot exhaust
either. Views holding manually pushed spans (via
push_raw) additionally get
DEFAULT_UNKNOWN_FIELD_LIMIT
slots and the full RECURSION_LIMIT, since
those spans were never charged.
A coalesced span re-materializes one owned UnknownField per
record, so this conversion is where a long run of unknown fields
actually allocates.
§Errors
Returns Err if a stored span is malformed or exceeds the replay
budget. Neither can occur when the view was produced by wire
decoding — every span was parsed off the wire, and the budget equals
what decoding charged — so any view that decoded successfully
converts successfully. Only views holding
push_raw spans can fail here.
Trait Implementations§
Source§impl<'a> Clone for UnknownFieldsView<'a>
impl<'a> Clone for UnknownFieldsView<'a>
Source§fn clone(&self) -> UnknownFieldsView<'a>
fn clone(&self) -> UnknownFieldsView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more