Skip to content

Commit

Permalink
rename length_code to low_nibble
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Jun 8, 2024
1 parent 9470b5b commit 2cef814
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/lazy/binary/encoded_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions src/lazy/binary/raw/v1_1/immutable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 188 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope
// 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 {

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 191 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope
// 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()?;
Expand Down Expand Up @@ -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() {

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope

Check failure on line 370 in src/lazy/binary/raw/v1_1/immutable_buffer.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

no method named `low_nibble` found for struct `lazy::binary::raw::v1_1::type_descriptor::Opcode` in the current scope
7 => {
let (flex_sym, remaining_input) = input_after_opcode.read_flex_sym()?;
let sequence = EncodedAnnotations {
Expand Down
24 changes: 12 additions & 12 deletions src/lazy/binary/raw/v1_1/type_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::IonType;
pub struct Opcode {
pub opcode_type: OpcodeType,
pub ion_type: Option<IonType>,
pub length_code: u8,
pub low_nibble: u8,
}

/// A statically defined array of TypeDescriptor that allows a binary reader to map a given
Expand All @@ -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] {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Opcode {
Opcode {
ion_type,
opcode_type,
length_code,
low_nibble: length_code,
}
}

Expand All @@ -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)
}
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/lazy/binary/raw/v1_1/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand All @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<SymbolId> {
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())?;
Expand Down

0 comments on commit 2cef814

Please sign in to comment.