Skip to main content

encode_packed_decimal_with_scratch

Function encode_packed_decimal_with_scratch 

Source
pub fn encode_packed_decimal_with_scratch(
    decimal: &SmallDecimal,
    digits: u16,
    signed: bool,
    scratch: &mut ScratchBuffers,
) -> Result<Vec<u8>>
Expand description

Encode a packed decimal (COMP-3) while reusing caller-owned scratch buffers to minimize per-call allocations.

Converts the pre-parsed SmallDecimal to its string representation using the scratch buffer and then delegates to encode_packed_decimal. Intended for use on codec hot paths where many records are encoded sequentially with the same ScratchBuffers instance.

§Arguments

  • decimal - Pre-parsed decimal value to encode
  • digits - Number of decimal digits in the field (1-18)
  • signed - Whether the field is signed (true) or unsigned (false)
  • scratch - Reusable scratch buffers for zero-allocation string processing

§Returns

A vector of bytes containing the encoded packed decimal (COMP-3 format).

§Errors

Returns an error when the decimal value cannot be encoded into the requested packed representation (delegates to encode_packed_decimal).

§See Also