diff --git a/src/lazy/binary/encoded_value.rs b/src/lazy/binary/encoded_value.rs index fba9d50e..531cfef2 100644 --- a/src/lazy/binary/encoded_value.rs +++ b/src/lazy/binary/encoded_value.rs @@ -7,7 +7,7 @@ pub(crate) trait EncodedHeader: Copy { type TypeCode; fn ion_type(&self) -> IonType; fn type_code(&self) -> Self::TypeCode; - fn length_code(&self) -> u8; + fn low_nibble(&self) -> u8; fn is_null(&self) -> bool; } @@ -23,7 +23,7 @@ impl EncodedHeader for Header { self.ion_type_code } - fn length_code(&self) -> u8 { + fn low_nibble(&self) -> u8 { self.length_code } diff --git a/src/lazy/binary/raw/v1_1/immutable_buffer.rs b/src/lazy/binary/raw/v1_1/immutable_buffer.rs index 1cfdab9a..94acddbc 100644 --- a/src/lazy/binary/raw/v1_1/immutable_buffer.rs +++ b/src/lazy/binary/raw/v1_1/immutable_buffer.rs @@ -185,10 +185,10 @@ impl<'a> ImmutableBuffer<'a> { let opcode = self.peek_opcode()?; // We need to determine the size of the nop.. - let (size, remaining) = if opcode.length_code == 0xC { + let (size, remaining) = if opcode.low_nibble() == 0xC { // Size 0; the nop is contained entirely within the OpCode. (0, self.consume(1)) - } else if opcode.length_code == 0xD { + } else if opcode.low_nibble() == 0xD { // We have a flexuint telling us how long our nop is. let after_header = self.consume(1); let (len, rest) = after_header.read_flex_uint()?; @@ -367,7 +367,7 @@ impl<'a> ImmutableBuffer<'a> { // the annotations and remember their encoding; later on, the annotations iterator // can actually do the reading. That optimization would be impactful for FlexSyms // that represent inline text. - let (sequence, remaining_input) = match opcode.length_code { + let (sequence, remaining_input) = match opcode.low_nibble() { 7 => { let (flex_sym, remaining_input) = input_after_opcode.read_flex_sym()?; let sequence = EncodedAnnotations { diff --git a/src/lazy/binary/raw/v1_1/type_descriptor.rs b/src/lazy/binary/raw/v1_1/type_descriptor.rs index ea96a834..5de9a84e 100644 --- a/src/lazy/binary/raw/v1_1/type_descriptor.rs +++ b/src/lazy/binary/raw/v1_1/type_descriptor.rs @@ -8,7 +8,7 @@ use crate::IonType; pub struct Opcode { pub opcode_type: OpcodeType, pub ion_type: Option, - pub length_code: u8, + pub low_nibble: u8, } /// A statically defined array of TypeDescriptor that allows a binary reader to map a given @@ -34,7 +34,7 @@ static ION_1_1_TIMESTAMP_SHORT_SIZE: [u8; 13] = [1, 2, 2, 4, 5, 6, 7, 8, 5, 5, 7 const DEFAULT_HEADER: Opcode = Opcode { opcode_type: OpcodeType::Nop, ion_type: None, - length_code: 0, + low_nibble: 0, }; pub(crate) const fn init_opcode_cache() -> [Opcode; 256] { @@ -87,7 +87,7 @@ impl Opcode { Opcode { ion_type, opcode_type, - length_code, + low_nibble: length_code, } } @@ -114,7 +114,7 @@ impl Opcode { let header = Header { ion_type, ion_type_code: self.opcode_type, - length_code: self.length_code, + low_nibble: self.low_nibble, }; Some(header) } @@ -136,27 +136,27 @@ pub struct Header { // The only time the `ion_type_code` is required is to distinguish between positive // and negative integers. pub ion_type_code: OpcodeType, - pub length_code: u8, + pub low_nibble: u8, } impl Header { pub fn length_type(&self) -> LengthType { use LengthType::*; - match (self.ion_type_code, self.length_code) { + match (self.ion_type_code, self.low_nibble) { (OpcodeType::Boolean, 0xE..=0xF) => InOpcode(0), (OpcodeType::Float, 0xA) => InOpcode(0), - (OpcodeType::Float, 0xB..=0xD) => InOpcode(1 << (self.length_code - 0xA)), + (OpcodeType::Float, 0xB..=0xD) => InOpcode(1 << (self.low_nibble - 0xA)), (OpcodeType::Integer, n) => InOpcode(n), (OpcodeType::Nop, 0xC) => InOpcode(0), (OpcodeType::NullNull, 0xA) => InOpcode(0), - (OpcodeType::String, 0..=15) => InOpcode(self.length_code), + (OpcodeType::String, 0..=15) => InOpcode(self.low_nibble), (OpcodeType::InlineSymbol, n) if n < 16 => InOpcode(n), (OpcodeType::SymbolAddress, n) if n < 4 => InOpcode(n), - (OpcodeType::Decimal, 0..=15) => InOpcode(self.length_code), + (OpcodeType::Decimal, 0..=15) => InOpcode(self.low_nibble), (OpcodeType::List, n) if n < 16 => InOpcode(n), (OpcodeType::SExpression, n) if n < 16 => InOpcode(n), (OpcodeType::TimestampShort, 0..=12) => { - InOpcode(ION_1_1_TIMESTAMP_SHORT_SIZE[self.length_code as usize]) + InOpcode(ION_1_1_TIMESTAMP_SHORT_SIZE[self.low_nibble as usize]) } (OpcodeType::TypedNull, _) => InOpcode(1), (OpcodeType::Struct, n) if n < 16 => InOpcode(n), @@ -176,8 +176,8 @@ impl EncodedHeader for Header { self.ion_type_code } - fn length_code(&self) -> u8 { - self.length_code + fn low_nibble(&self) -> u8 { + self.low_nibble } fn is_null(&self) -> bool { diff --git a/src/lazy/binary/raw/v1_1/value.rs b/src/lazy/binary/raw/v1_1/value.rs index c5025d0f..93f9121c 100644 --- a/src/lazy/binary/raw/v1_1/value.rs +++ b/src/lazy/binary/raw/v1_1/value.rs @@ -237,7 +237,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { debug_assert!(self.encoded_value.ion_type() == IonType::Bool); let header = &self.encoded_value.header(); let representation = header.type_code(); - let value = match (representation, header.length_code) { + let value = match (representation, header.low_nibble) { (OpcodeType::Boolean, 0xE) => true, (OpcodeType::Boolean, 0xF) => false, _ => unreachable!("found a boolean value with an illegal length code."), @@ -251,7 +251,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { let header = &self.encoded_value.header(); let representation = header.type_code(); - let value = match (representation, header.length_code as usize) { + let value = match (representation, header.low_nibble as usize) { (OpcodeType::Integer, 0x0) => 0.into(), (OpcodeType::Integer, n) => { // We have n bytes following that make up our integer. @@ -334,7 +334,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { const MILLISECONDS_MASK_16BIT: u16 = 0x0F_FC; const MICROSECONDS_MASK_32BIT: u32 = 0x3F_FF_FC_00; - let length_code = self.encoded_value.header.length_code(); + let length_code = self.encoded_value.header.low_nibble(); // An offset bit of `1` indicates UTC while a `0` indicates 'unknown' let is_utc = (value_bytes[3] & 0x08) == 0x08; @@ -421,7 +421,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { const MICROSECOND_MASK_32BIT: u32 = 0x0F_FF_00; const NANOSECOND_MASK_32BIT: u32 = 0x3F_FF_FF_FF; - let length_code = self.encoded_value.header.length_code(); + let length_code = self.encoded_value.header.low_nibble(); // Read offset as 15min multiple let offset: u16 = u16::from_le_bytes(value_bytes[3..=4].try_into().unwrap()) @@ -481,7 +481,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { fn read_timestamp_short(&self) -> ValueParseResult<'top, BinaryEncoding_1_1> { const MONTH_MASK_16BIT: u16 = 0x07_80; - let length_code = self.encoded_value.header.length_code(); + let length_code = self.encoded_value.header.low_nibble(); let value_bytes = self.value_body()?; // Year is biased offset by 1970, and is held in the lower 7 bits of the first byte. @@ -636,7 +636,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> { /// Helper method called by [`Self::read_symbol`]. Reads the current value as a symbol ID. fn read_symbol_id(&self) -> IonResult { let biases: [usize; 3] = [0, 256, 65792]; - let length_code = self.encoded_value.header.length_code; + let length_code = self.encoded_value.header.low_nibble; if (1..=3).contains(&length_code) { let (id, _) = self.available_body().read_fixed_uint(length_code.into())?; let id = usize::try_from(id.value())?;