Expand description

Classifiers working on the input stream.

This base module provides the ResumeClassifierState struct common between all higher-level classifiers that work on top of a QuoteClassifiedIterator. It allows saving the state of a classifier and can be later used to resume classification from a, possibly different, high-level classifier. This state’s index can be pushed forward.

Examples

use rsonpath_lib::classification::quotes::classify_quoted_sequences;
use rsonpath_lib::classification::structural::{
    classify_structural_characters, resume_structural_classification, Structural,
    StructuralIterator,
};
use aligners::AlignedBytes;

let input = AlignedBytes::new_padded(r#"{"a":[42, {}, 44]}"#.as_bytes());
let quote_classifier = classify_quoted_sequences(&input);
let mut structural_classifier = classify_structural_characters(quote_classifier);
structural_classifier.turn_colons_on(0);
structural_classifier.turn_commas_on(0);

// Classify first two structural characters.
assert_eq!(
    structural_classifier.next(),
    Some(Structural::Opening(0))
);
assert_eq!(
    structural_classifier.next(),
    Some(Structural::Colon(4))
);

// We stop at the first non-classified character, Opening(5).
let mut resume_state = structural_classifier.stop();
assert_eq!(resume_state.get_idx(), 5);

// Skip 6 bytes.
resume_state.offset_bytes(6);
assert_eq!(resume_state.get_idx(), 11);

// Resume.
let mut structural_classifier_2 = resume_structural_classification(resume_state);
assert_eq!(
    structural_classifier_2.next(),
    Some(Structural::Closing(11))
);

Modules

JSON depth calculations on byte streams.
Classification of bytes withing JSON quote sequences.
Classification of structurally significant JSON bytes.

Structs

State of the block at which classification was stopped.
State allowing resumption of a classifier from a particular place in the input along with the stopped QuoteClassifiedIterator.