Skip to main content

put_shared_bytes_field

Function put_shared_bytes_field 

Source
pub fn put_shared_bytes_field<B: AsSharedBytes, S: EncodeSink>(
    field_number: u32,
    value: &B,
    buf: &mut S,
)
Expand description

Write a tagged bytes field, splicing the payload into segmented sinks by reference count when the value can produce a Bytes handle.

Generated write_to bodies use this for every bytes field. The zero-copy attempt runs only when the sink declares IS_SEGMENTED — for contiguous sinks (Vec<u8>, BytesMut, every other BufMut) the constant is false, the branch const-folds away, and the payload is copied exactly as put_bytes_field would, with no refcount traffic. Into a Rope, bytes::Bytes fields (and custom ProtoBytes representations implementing as_shared) become refcount-shared segments; Vec<u8> and view &[u8] values fall back to EncodeSink::put_slice, where the rope’s backing-buffer capture can still apply.