Skip to content

Commit

Permalink
Shift opcodes (#786)
Browse files Browse the repository at this point in the history
* Shift writer opcodes between 0x50 and 0xE0 right by 16

* Shift opcodes for binary 1.1 reader

---------

Co-authored-by: Zack Slayton <zslayton@amazon.com>
  • Loading branch information
zslayton and zslayton authored Jun 6, 2024
1 parent cdbc815 commit 8d1178e
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 393 deletions.
280 changes: 140 additions & 140 deletions src/lazy/binary/raw/v1_1/reader.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/lazy/binary/raw/v1_1/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl<'top> RawBinaryStructIterator_1_1<'top> {
source: input,
bytes_to_skip: 0,
struct_type: match opcode_type {
OpcodeType::StructSymAddress => StructType::SymbolAddress,
OpcodeType::StructFlexSym => StructType::FlexSym,
// TODO: Delimited struct handling
OpcodeType::Struct => StructType::FlexSym,
_ => unreachable!("Unexpected opcode for structure"),
},
}
Expand Down
49 changes: 27 additions & 22 deletions src/lazy/binary/raw/v1_1/type_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ use crate::IonType;
pub enum OpcodeType {
EExpressionWithAddress, // 0x00-0x4F -
EExpressionAddressFollows, // 0x40-0x4F -
Integer, // 0x50-0x58 - Integer up to 8 bytes wide
Float, // 0x5A-0x5D -
Boolean, // 0x5E-0x5F -
Decimal, // 0x60-0x6F -
TimestampShort, // 0x70-0x7F -
String, // 0x80-0x80 -
InlineSymbol, // 0x90-0x9F -
List, // 0xA0-0xAF -
SExpression, // 0xB0-0xBF -
StructEmpty, // 0xC0 -
// reserved
StructSymAddress, // 0xC2-0xCF -
// reserved
StructFlexSym, // 0xD2-0xDF -
Integer, // 0x60-0x68 - Integer up to 8 bytes wide
Float, // 0x6A-0x6D -
Boolean, // 0x6E-0x6F -
Decimal, // 0x70-0x7F -
TimestampShort, // 0x80-0x8F -
String, // 0x90-0x9F -
InlineSymbol, // 0xA0-0xAF -
List, // 0xB0-0xBF -
SExpression, // 0xC0-0xCF -
StructEmpty, // 0xD0 -
// 0xD1 reserved
Struct, // 0xD2-0xDF -
IonVersionMarker, // 0xE0 -

SymbolAddress, // 0xE1-0xE3 -
Expand All @@ -39,14 +37,21 @@ pub enum OpcodeType {
Nop, // 0xEC-0xED -
// Reserved
SystemMacroInvoke, // 0xEF -
// delimited container end
// delimited list start
// delimited s-expression start
LargeInteger, // 0xF5 - Integer preceeded by FlexUInt length
Blob, // 0xFE -
Clob, // 0xFF -
TimestampLong, // 0xF7 - Long-form Timestamp
Invalid, // Represents an encoded value that does not match a defined opcode.
// 0xF0 delimited container end
// 0xF1 delimited list start
// 0xF2 delimited s-expression start
// 0xF3 delimited struct start
LargeInteger, // 0xF6 - Integer preceded by FlexUInt length
Blob, // 0xFE -
Clob, // 0xFF -
// 0xF8 Long decimal
TimestampLong, // 0xF8 - Long-form Timestamp
// 0xF9 - Long string
// 0xFA - FlexSym symbol
// 0xFB - Long list
// 0xFC - Long sexp
// 0xFD - Long struct
Invalid, // Represents an encoded value that does not match a defined opcode.
}

impl TryFrom<OpcodeType> for IonType {
Expand Down
41 changes: 19 additions & 22 deletions src/lazy/binary/raw/v1_1/type_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,31 @@ impl Opcode {
use OpcodeType::*;

let (opcode_type, length_code, ion_type) = match (high_nibble, low_nibble) {
(0x5, 0x0..=0x8) => (Integer, low_nibble, Some(IonType::Int)),
(0x5, 0xA..=0xD) => (Float, low_nibble, Some(IonType::Float)),
(0x5, 0xE..=0xF) => (Boolean, low_nibble, Some(IonType::Bool)),
(0x6, _) => (Decimal, low_nibble, Some(IonType::Decimal)),
(0x7, 0x0..=0xC) => (TimestampShort, low_nibble, Some(IonType::Timestamp)),
(0x8, _) => (String, low_nibble, Some(IonType::String)),
(0x9, _) => (InlineSymbol, low_nibble, Some(IonType::Symbol)),
(0xA, _) => (List, low_nibble, Some(IonType::List)),
(0xB, _) => (SExpression, low_nibble, Some(IonType::SExp)),
(0xC, _) => (StructSymAddress, low_nibble, Some(IonType::Struct)),
(0xD, _) => (StructFlexSym, low_nibble, Some(IonType::Struct)),
(0x6, 0x0..=0x8) => (Integer, low_nibble, Some(IonType::Int)),
(0x6, 0xA..=0xD) => (Float, low_nibble, Some(IonType::Float)),
(0x6, 0xE..=0xF) => (Boolean, low_nibble, Some(IonType::Bool)),
(0x7, _) => (Decimal, low_nibble, Some(IonType::Decimal)),
(0x8, 0x0..=0xC) => (TimestampShort, low_nibble, Some(IonType::Timestamp)),
(0x9, _) => (String, low_nibble, Some(IonType::String)),
(0xA, _) => (InlineSymbol, low_nibble, Some(IonType::Symbol)),
(0xB, _) => (List, low_nibble, Some(IonType::List)),
(0xC, _) => (SExpression, low_nibble, Some(IonType::SExp)),
(0xD, _) => (Struct, low_nibble, Some(IonType::Struct)),
(0xE, 0x0) => (IonVersionMarker, low_nibble, None),
(0xE, 0x1..=0x3) => (SymbolAddress, low_nibble, Some(IonType::Symbol)),
(0xE, 0xA) => (NullNull, low_nibble, Some(IonType::Null)),
(0xE, 0xB) => (TypedNull, low_nibble, Some(IonType::Null)),
(0xE, 0xC..=0xD) => (Nop, low_nibble, None),
(0xF, 0x5) => (LargeInteger, low_nibble, Some(IonType::Int)),
(0xF, 0x6) => (Decimal, 0xFF, Some(IonType::Decimal)),
(0xF, 0x8) => (String, 0xFF, Some(IonType::String)), // 0xFF indicates >15 byte string.
(0xF, 0x9) => (InlineSymbol, 0xFF, Some(IonType::Symbol)),
(0xF, 0xA) => (List, 0xFF, Some(IonType::List)),
(0xF, 0xB) => (SExpression, 0xFF, Some(IonType::SExp)),
(0xF, 0xC) => (StructSymAddress, 0xFF, Some(IonType::Struct)),
(0xF, 0xD) => (StructFlexSym, 0xFF, Some(IonType::Struct)),
(0xF, 0x6) => (LargeInteger, low_nibble, Some(IonType::Int)),
(0xF, 0x7) => (Decimal, 0xFF, Some(IonType::Decimal)),
(0xF, 0x8) => (TimestampLong, low_nibble, Some(IonType::Timestamp)),
(0xF, 0x9) => (String, 0xFF, Some(IonType::String)), // 0xFF indicates >15 byte string.
(0xF, 0xA) => (InlineSymbol, 0xFF, Some(IonType::Symbol)),
(0xF, 0xB) => (List, 0xFF, Some(IonType::List)),
(0xF, 0xC) => (SExpression, 0xFF, Some(IonType::SExp)),
(0xF, 0xD) => (Struct, 0xFF, Some(IonType::Struct)),
(0xF, 0xE) => (Blob, low_nibble, Some(IonType::Blob)),
(0xF, 0xF) => (Clob, low_nibble, Some(IonType::Clob)),
(0xF, 0x7) => (TimestampLong, low_nibble, Some(IonType::Timestamp)),
_ => (Invalid, low_nibble, None),
};
Opcode {
Expand Down Expand Up @@ -159,8 +157,7 @@ impl Header {
InOpcode(ION_1_1_TIMESTAMP_SHORT_SIZE[self.length_code as usize])
}
(OpcodeType::TypedNull, _) => InOpcode(1),
(OpcodeType::StructSymAddress, n) if n < 16 => InOpcode(n),
(OpcodeType::StructFlexSym, n) if n < 16 => InOpcode(n),
(OpcodeType::Struct, n) if n < 16 => InOpcode(n),
_ => FlexUIntFollows,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/binary/raw/v1_1/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'top> LazyRawBinaryValue_1_1<'top> {
// We have n bytes following that make up our integer.
self.input.consume(1).read_fixed_int(n)?.0.into()
}
(OpcodeType::LargeInteger, 0x5) => {
(OpcodeType::LargeInteger, 0x6) => {
// We have a FlexUInt size, then big int.
let value_bytes = self.value_body()?;
FixedInt::read(value_bytes, value_bytes.len(), 0)?.into()
Expand Down
12 changes: 6 additions & 6 deletions src/lazy/encoder/binary/v1_1/container_writers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl<'value, 'top> BinaryListWriter_1_1<'value, 'top> {
allocator: &'top BumpAllocator,
buffer: &'value mut BumpVec<'top, u8>,
) -> Self {
const LENGTH_PREFIXED_LIST_TYPE_CODE: u8 = 0xA0;
const LENGTH_PREFIXED_FLEX_LEN_LIST_TYPE_CODE: u8 = 0xFA;
const LENGTH_PREFIXED_LIST_TYPE_CODE: u8 = 0xB0;
const LENGTH_PREFIXED_FLEX_LEN_LIST_TYPE_CODE: u8 = 0xFB;
let container_writer = BinaryContainerWriter_1_1::new_length_prefixed(
LENGTH_PREFIXED_LIST_TYPE_CODE,
LENGTH_PREFIXED_FLEX_LEN_LIST_TYPE_CODE,
Expand Down Expand Up @@ -225,8 +225,8 @@ impl<'value, 'top> BinarySExpWriter_1_1<'value, 'top> {
allocator: &'top BumpAllocator,
buffer: &'value mut BumpVec<'top, u8>,
) -> Self {
const LENGTH_PREFIXED_SEXP_TYPE_CODE: u8 = 0xB0;
const LENGTH_PREFIXED_FLEX_LEN_SEXP_TYPE_CODE: u8 = 0xFB;
const LENGTH_PREFIXED_SEXP_TYPE_CODE: u8 = 0xC0;
const LENGTH_PREFIXED_FLEX_LEN_SEXP_TYPE_CODE: u8 = 0xFC;
let container_writer = BinaryContainerWriter_1_1::new_length_prefixed(
LENGTH_PREFIXED_SEXP_TYPE_CODE,
LENGTH_PREFIXED_FLEX_LEN_SEXP_TYPE_CODE,
Expand Down Expand Up @@ -278,8 +278,8 @@ impl<'value, 'top> BinaryStructWriter_1_1<'value, 'top> {
allocator: &'top BumpAllocator,
buffer: &'value mut BumpVec<'top, u8>,
) -> Self {
const LENGTH_PREFIXED_STRUCT_TYPE_CODE: u8 = 0xC0;
const LENGTH_PREFIXED_FLEX_LEN_STRUCT_TYPE_CODE: u8 = 0xFC;
const LENGTH_PREFIXED_STRUCT_TYPE_CODE: u8 = 0xD0;
const LENGTH_PREFIXED_FLEX_LEN_STRUCT_TYPE_CODE: u8 = 0xFD;
let container_writer = BinaryContainerWriter_1_1::new_length_prefixed(
LENGTH_PREFIXED_STRUCT_TYPE_CODE,
LENGTH_PREFIXED_FLEX_LEN_STRUCT_TYPE_CODE,
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/encoder/binary/v1_1/flex_sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'top> FlexSym<'top> {
fn encode_special_case(output: &mut BumpVec<u8>, symbol: RawSymbolRef) {
let encoding: &[u8] = match symbol {
SymbolId(_) => &[FlexSym::ZERO, 0xE1, 0x00],
Text(_) => &[FlexSym::ZERO, 0x80],
Text(_) => &[FlexSym::ZERO, 0x90],
};
output.extend_from_slice_copy(encoding);
}
Expand Down
Loading

0 comments on commit 8d1178e

Please sign in to comment.