Skip to main content

decode_file_to_jsonl

Function decode_file_to_jsonl 

Source
pub fn decode_file_to_jsonl(
    schema: &Schema,
    input: impl Read,
    output: impl Write,
    options: &DecodeOptions,
) -> Result<RunSummary>
Expand description

Decode a file to JSONL format

Reads records from input using the configured RecordFormat

§Examples

use copybook_core::parse_copybook;
use copybook_codec::{decode_file_to_jsonl, DecodeOptions};
use copybook_codec::options::{Codepage, RecordFormat};

let schema = parse_copybook("01 FLD PIC X(5).").unwrap();
let input: &[u8] = b"HELLOWORLD";  // Two 5-byte records
let mut output = Vec::new();
let options = DecodeOptions::new()
    .with_codepage(Codepage::ASCII)
    .with_format(RecordFormat::Fixed);
let summary = decode_file_to_jsonl(&schema, input, &mut output, &options).unwrap();
assert_eq!(summary.records_processed, 2);

§Errors

Returns an error if the input cannot be read, decoded, or written.