Skip to main content

decode_binary_int_fast

Function decode_binary_int_fast 

Source
pub fn decode_binary_int_fast(
    data: &[u8],
    bits: u16,
    signed: bool,
) -> Result<i64>
Expand description

Decode a COBOL binary integer (USAGE BINARY / COMP) with optimized fast paths for 16-, 32-, and 64-bit widths.

For the three common widths this function reads the big-endian bytes directly into the native integer type, avoiding the generic loop in decode_binary_int. Uncommon widths fall back to that generic implementation.

§Arguments

  • data - Raw big-endian byte data containing the binary integer
  • bits - Expected field width in bits (16, 32, or 64 for fast path)
  • signed - Whether the field is signed (PIC S9 COMP) or unsigned (PIC 9 COMP)

§Returns

The decoded integer value as i64.

§Errors

  • CBKD401_COMP3_INVALID_NIBBLE - if an unsigned 64-bit value exceeds i64::MAX
  • Delegates to decode_binary_int for unsupported widths, which may return its own errors.

§See Also