Skip to main content

encode_zoned_decimal_with_scratch

Function encode_zoned_decimal_with_scratch 

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

Encode a zoned decimal while reusing caller-owned scratch buffers to avoid per-call heap allocations on the hot path.

Converts the pre-parsed SmallDecimal to its string representation using the scratch buffer and then delegates to encode_zoned_decimal. The _bwz_encode parameter is reserved for future BLANK WHEN ZERO integration but is currently unused.

§Arguments

  • decimal - Pre-parsed decimal value to encode
  • digits - Number of digit positions in the COBOL field
  • signed - Whether the field carries a sign
  • codepage - Target character encoding (ASCII or EBCDIC variant)
  • _bwz_encode - Reserved for BLANK WHEN ZERO support (currently unused)
  • scratch - Reusable scratch buffers for zero-allocation string processing

§Returns

A vector of bytes containing the encoded zoned decimal.

§Policy

Callers typically resolve policy using zoned_encoding_override → preserved metadata → preferred_zoned_encoding, matching the documented library behavior for zoned decimals.

§Errors

Returns an error when the decimal value cannot be represented with the requested digit count or encoding format.

§See Also