Skip to content

Commit

Permalink
incorporates feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Aug 28, 2024
1 parent b6f6c23 commit 5f03149
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lazy/binary/raw/v1_1/immutable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<'a> ImmutableBuffer<'a> {

use OpcodeType::*;
let result = match opcode.opcode_type {
EExpressionWith4BitAddress
EExpressionWith6BitAddress
| EExpressionWith12BitAddress
| EExpressionWith20BitAddress
| EExpressionWithLengthPrefix => {
Expand Down Expand Up @@ -874,7 +874,7 @@ impl<'a> ImmutableBuffer<'a> {
pub fn read_e_expression(self, opcode: Opcode) -> ParseResult<'a, BinaryEExpression_1_1<'a>> {
use OpcodeType::*;
let (macro_address, input_after_address) = match opcode.opcode_type {
EExpressionWith4BitAddress => (opcode.byte as usize, self.consume(1)),
EExpressionWith6BitAddress => (opcode.byte as usize, self.consume(1)),
EExpressionWith12BitAddress => {
if self.len() < 2 {
return IonResult::incomplete("parsing a 12-bit e-exp address", self.offset);
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/binary/raw/v1_1/type_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::IonType;
/// * Whether the next type code is reserved.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum OpcodeType {
EExpressionWith4BitAddress, // 0x00-0x3F -
EExpressionWith6BitAddress, // 0x00-0x3F -
EExpressionWith12BitAddress, // 0x40-0x4F -
EExpressionWith20BitAddress, // 0x50-0x5F -
Integer, // 0x60-0x68 - Integer up to 8 bytes wide
Expand Down
4 changes: 2 additions & 2 deletions src/lazy/binary/raw/v1_1/type_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Opcode {
use OpcodeType::*;

let (opcode_type, length_code, ion_type) = match (high_nibble, low_nibble) {
(0x0..=0x3, _) => (EExpressionWith4BitAddress, low_nibble, None),
(0x0..=0x3, _) => (EExpressionWith6BitAddress, low_nibble, None),
(0x4, _) => (EExpressionWith12BitAddress, low_nibble, None),
(0x5, _) => (EExpressionWith20BitAddress, low_nibble, None),
(0x6, 0x0..=0x8) => (Integer, low_nibble, Some(IonType::Int)),
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Opcode {
use OpcodeType::*;
matches!(
self.opcode_type,
EExpressionWith4BitAddress
EExpressionWith6BitAddress
| EExpressionWith12BitAddress
| EExpressionWith20BitAddress
| EExpressionWithLengthPrefix
Expand Down
14 changes: 7 additions & 7 deletions src/lazy/encoder/binary/v1_1/value_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,17 @@ impl<'value, 'top> BinaryValueWriter_1_1<'value, 'top> {
const BIAS: usize = MIN_20_BIT_ADDRESS;
let biased = address - BIAS;
let low_opcode_nibble = biased >> 16;
self.encoding_buffer.extend_from_slices_copy(&[
&[
// Opcode with low nibble setting bias
0x50 | low_opcode_nibble as u8,
],
let le_bytes = (biased as u16).to_le_bytes();
self.encoding_buffer.extend_from_slice_copy(&[
// Opcode with low nibble setting bias
0x50 | low_opcode_nibble as u8,
// Remaining bytes of magnitude in biased address
&(biased as u16).to_le_bytes(),
le_bytes[0],
le_bytes[1],
]);
}
MacroIdRef::LocalAddress(_address) => {
todo!("macros with addresses higher than (2^20)-1");
todo!("macros with addresses greater than {MAX_20_BIT_ADDRESS}");
}
};

Expand Down

0 comments on commit 5f03149

Please sign in to comment.