pub fn encode_zoned_decimal_with_format(
value: &str,
digits: u16,
scale: i16,
signed: bool,
codepage: Codepage,
encoding_override: Option<ZonedEncodingFormat>,
) -> Result<Vec<u8>>Expand description
Encode a zoned decimal using an explicit encoding override when supplied.
Encodes zoned decimal values with an explicit encoding format (ASCII or EBCDIC).
When encoding_override is provided, it takes precedence over the codepage default.
When Auto is specified, the codepage default is used.
§Arguments
value- String representation of the decimal value to encodedigits- Number of digit characters (field length)scale- Number of decimal places (can be negative for scaling)signed- Whether the field is signed (true) or unsigned (false)codepage- Character encoding (ASCII or EBCDIC variant)encoding_override- Optional explicit encoding format (ASCII/EBCDIC/Auto)
§Returns
A vector of bytes containing the encoded zoned decimal
§Policy
Resolves ZeroSignPolicy from encoding_override first; when unset or Auto, falls back to the code page defaults.
§Errors
Returns an error if the value cannot be encoded as a zoned decimal with the specified parameters.
§Examples
§ASCII Encoding (Explicit)
use copybook_codec::numeric::{encode_zoned_decimal_with_format};
use copybook_codec::options::Codepage;
use copybook_codec::options::ZonedEncodingFormat;
// Encode "123" with explicit ASCII encoding
let encoded = encode_zoned_decimal_with_format(
"123", 3, 0, false, Codepage::ASCII, Some(ZonedEncodingFormat::Ascii)
)?;
assert_eq!(encoded, b"123");§EBCDIC Encoding (Explicit)
use copybook_codec::numeric::{encode_zoned_decimal_with_format};
use copybook_codec::options::Codepage;
use copybook_codec::options::ZonedEncodingFormat;
// Encode "789" with explicit EBCDIC encoding
let encoded = encode_zoned_decimal_with_format(
"789", 3, 0, false, Codepage::CP037, Some(ZonedEncodingFormat::Ebcdic)
)?;
assert_eq!(encoded, [0xF7, 0xF8, 0xF9]);§Auto Encoding (Codepage Default)
use copybook_codec::numeric::{encode_zoned_decimal_with_format};
use copybook_codec::options::Codepage;
use copybook_codec::options::ZonedEncodingFormat;
// Encode "456" with Auto encoding (uses EBCDIC default for CP037)
let encoded = encode_zoned_decimal_with_format(
"456", 3, 0, false, Codepage::CP037, Some(ZonedEncodingFormat::Auto)
)?;
assert_eq!(encoded, [0xF4, 0xF5, 0xF6]);§See Also
encode_zoned_decimal- For encoding with codepage defaultsencode_zoned_decimal_with_format_and_policy- For encoding with format and policy