pub struct Encoder { /* private fields */ }alloc only.Expand description
Streaming encoder that writes canonical CBOR directly into a Vec<u8>.
This supports splicing validated canonical bytes.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a canonical encoder with pre-allocated capacity.
Sourcepub fn into_canonical(self) -> Result<CanonicalCbor, CborError>
pub fn into_canonical(self) -> Result<CanonicalCbor, CborError>
Consume and return canonical bytes as a CanonicalCbor.
§Errors
Returns an error if the buffer does not contain exactly one canonical CBOR item.
Sourcepub fn int(&mut self, v: i64) -> Result<(), CborError>
pub fn int(&mut self, v: i64) -> Result<(), CborError>
Encode a safe-range integer.
§Errors
Returns an error if the integer is outside the safe range or if encoding fails.
Sourcepub fn int_u128(&mut self, v: u128) -> Result<(), CborError>
pub fn int_u128(&mut self, v: u128) -> Result<(), CborError>
Encode an unsigned integer, using a bignum when outside the safe range.
§Errors
Returns an error if encoding fails or allocation for the bignum magnitude fails.
Sourcepub fn int_i128(&mut self, v: i128) -> Result<(), CborError>
pub fn int_i128(&mut self, v: i128) -> Result<(), CborError>
Encode a signed integer, using a bignum when outside the safe range.
§Errors
Returns an error if encoding fails or allocation for the bignum magnitude fails.
Sourcepub fn bignum(
&mut self,
negative: bool,
magnitude: &[u8],
) -> Result<(), CborError>
pub fn bignum( &mut self, negative: bool, magnitude: &[u8], ) -> Result<(), CborError>
Encode a CBOR bignum (tag 2/3 + byte string magnitude).
§Errors
Returns an error if the magnitude is not canonical or if encoding fails.
Sourcepub fn raw_cbor(&mut self, v: CanonicalCborRef<'_>) -> Result<(), CborError>
pub fn raw_cbor(&mut self, v: CanonicalCborRef<'_>) -> Result<(), CborError>
Splice already validated canonical CBOR bytes as the next value.
§Errors
Returns an error if writing to the underlying buffer fails.
Sourcepub fn raw_value_ref(&mut self, v: CborValueRef<'_>) -> Result<(), CborError>
pub fn raw_value_ref(&mut self, v: CborValueRef<'_>) -> Result<(), CborError>
Splice a canonical sub-value reference.
§Errors
Returns an error if writing to the underlying buffer fails.