use std::ops::Range;
use crate::lazy::encoding::TextEncoding;
use crate::lazy::text::matched::MatchedValue;
use crate::IonType;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct EncodedTextValue<'top, E: TextEncoding> {
data_offset: u16,
matched_value: MatchedValue<'top, E>,
}
impl<'top, E: TextEncoding> EncodedTextValue<'top, E> {
pub(crate) fn new(matched_value: MatchedValue<'top, E>) -> EncodedTextValue<'top, E> {
EncodedTextValue {
data_offset: 0,
matched_value,
}
}
pub(crate) fn with_annotations_sequence(mut self, length: u16) -> EncodedTextValue<'top, E> {
self.data_offset = length;
self
}
pub fn ion_type(&self) -> IonType {
match self.matched_value {
MatchedValue::Null(ion_type) => ion_type,
MatchedValue::Bool(_) => IonType::Bool,
MatchedValue::Int(_) => IonType::Int,
MatchedValue::Float(_) => IonType::Float,
MatchedValue::Decimal(_) => IonType::Decimal,
MatchedValue::Timestamp(_) => IonType::Timestamp,
MatchedValue::String(_) => IonType::String,
MatchedValue::Symbol(_) => IonType::Symbol,
MatchedValue::Blob(_) => IonType::Blob,
MatchedValue::Clob(_) => IonType::Clob,
MatchedValue::List(_) => IonType::List,
MatchedValue::SExp(_) => IonType::SExp,
MatchedValue::Struct(_) => IonType::Struct,
}
}
pub fn is_null(&self) -> bool {
matches!(self.matched_value, MatchedValue::Null(_))
}
pub fn data_offset(&self) -> usize {
self.data_offset as usize
}
pub fn annotations_range(&self) -> Option<Range<usize>> {
if self.data_offset == 0 {
return None;
}
Some(0..self.data_offset as usize)
}
pub fn has_annotations(&self) -> bool {
self.data_offset > 0
}
pub fn matched(&self) -> MatchedValue<'top, E> {
self.matched_value
}
}