Skip to main content

encode_jsonl_to_file

Function encode_jsonl_to_file 

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

Encode JSONL to binary file

§Arguments

  • schema - The parsed copybook schema
  • input - Input stream to read JSONL from
  • output - Output stream to write binary to
  • options - Encoding options

§Examples

use copybook_core::parse_copybook;
use copybook_codec::{encode_jsonl_to_file, EncodeOptions};
use copybook_codec::options::{Codepage, RecordFormat};

let schema = parse_copybook("01 FLD PIC X(5).").unwrap();
let jsonl = br#"{"fields":{"FLD":"HELLO"}}
{"fields":{"FLD":"WORLD"}}
"#;
let mut output = Vec::new();
let options = EncodeOptions::new()
    .with_codepage(Codepage::ASCII)
    .with_format(RecordFormat::Fixed);
let summary = encode_jsonl_to_file(&schema, &jsonl[..], &mut output, &options).unwrap();
assert_eq!(summary.records_processed, 2);
assert_eq!(&output[..5], b"HELLO");
assert_eq!(&output[5..10], b"WORLD");

§Errors

Returns an error if the JSONL cannot be encoded or written.