Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames ImmutableBuffer/TextBufferView to BinaryBuffer/TextBuffer #831

Merged
merged 11 commits into from
Sep 7, 2024
18 changes: 9 additions & 9 deletions benches/encoding_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod benchmark {
use rand::{distributions::Uniform, Rng, SeedableRng};
use std::io;

use ion_rs::v1_0::{ImmutableBuffer, VarInt, VarUInt};
use ion_rs::v1_0::{BinaryBuffer, VarInt, VarUInt};
use ion_rs::v1_1::{FlexInt, FlexUInt};

// Rather than store a set of test values, we hardcode a seed value and generate the same set
Expand Down Expand Up @@ -74,7 +74,7 @@ mod benchmark {
binary_1_0_group.bench_function("read VarUInt", |b| {
b.iter(|| {
let mut decoded_length: usize = 0;
let mut input = ImmutableBuffer::new(encoded_var_uints.as_slice());
let mut input = BinaryBuffer::new(encoded_var_uints.as_slice());
for _ in 0..unsigned_values.len() {
let (var_uint, remaining) = input.read_var_uint().unwrap();
input = remaining;
Expand All @@ -96,7 +96,7 @@ mod benchmark {
binary_1_0_group.bench_function("read VarInt", |b| {
b.iter(|| {
let mut decoded_length: usize = 0;
let mut input = ImmutableBuffer::new(encoded_var_ints.as_slice());
let mut input = BinaryBuffer::new(encoded_var_ints.as_slice());
for _ in 0..unsigned_values.len() {
let (var_int, remaining) = input.read_var_int().unwrap();
input = remaining;
Expand All @@ -121,7 +121,7 @@ mod benchmark {
binary_1_1_group.bench_function("read FlexUInt", |b| {
b.iter(|| {
let mut decoded_length: usize = 0;
let mut input = ImmutableBuffer::new(encoded_flex_uints.as_slice());
let mut input = BinaryBuffer::new(encoded_flex_uints.as_slice());
for _ in 0..unsigned_values.len() {
let (flex_uint, remaining) = input.read_flex_uint().unwrap();
input = remaining;
Expand All @@ -143,7 +143,7 @@ mod benchmark {
binary_1_1_group.bench_function("read FlexInt", |b| {
b.iter(|| {
let mut decoded_length: usize = 0;
let mut input = ImmutableBuffer::new(encoded_flex_ints.as_slice());
let mut input = BinaryBuffer::new(encoded_flex_ints.as_slice());
for _ in 0..unsigned_values.len() {
let (flex_int, remaining) = input.read_flex_int().unwrap();
input = remaining;
Expand All @@ -161,7 +161,7 @@ mod benchmark {
VarUInt::write_u64(&mut encoded_values_buffer, *value)?;
}
let mut decoded_values = Vec::new();
let mut input = ImmutableBuffer::new(encoded_values_buffer.as_slice());
let mut input = BinaryBuffer::new(encoded_values_buffer.as_slice());
for _ in 0..unsigned_values.len() {
let (var_uint, remaining) = input.read_var_uint()?;
input = remaining;
Expand All @@ -177,7 +177,7 @@ mod benchmark {
VarInt::write_i64(&mut encoded_values_buffer, *value)?;
}
let mut decoded_values = Vec::new();
let mut input = ImmutableBuffer::new(encoded_values_buffer.as_slice());
let mut input = BinaryBuffer::new(encoded_values_buffer.as_slice());
for _ in 0..signed_values.len() {
let (var_int, remaining) = input.read_var_int()?;
input = remaining;
Expand All @@ -193,7 +193,7 @@ mod benchmark {
FlexUInt::write(&mut encoded_values_buffer, *value)?;
}
let mut decoded_values = Vec::new();
let mut input = ImmutableBuffer::new(encoded_values_buffer.as_slice());
let mut input = BinaryBuffer::new(encoded_values_buffer.as_slice());
for _ in 0..unsigned_values.len() {
let (flex_uint, remaining) = input.read_flex_uint()?;
input = remaining;
Expand All @@ -209,7 +209,7 @@ mod benchmark {
FlexInt::write_i64(&mut encoded_values_buffer, *value)?;
}
let mut decoded_values = Vec::new();
let mut input = ImmutableBuffer::new(encoded_values_buffer.as_slice());
let mut input = BinaryBuffer::new(encoded_values_buffer.as_slice());
for _ in 0..signed_values.len() {
let (flex_int, remaining) = input.read_flex_int()?;
input = remaining;
Expand Down
16 changes: 11 additions & 5 deletions src/lazy/any_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ pub enum AnyEExpArgGroupKind<'top> {
Binary_1_1(BinaryEExpArgGroup<'top>),
}

impl<'top> AnyEExpArgGroupKind<'top> {
fn encoding(&self) -> &ParameterEncoding {
match self {
AnyEExpArgGroupKind::Text_1_1(g) => g.encoding(),
AnyEExpArgGroupKind::Binary_1_1(g) => g.encoding(),
}
}
}

impl<'top> HasRange for AnyEExpArgGroup<'top> {
fn range(&self) -> Range<usize> {
match self.kind {
Expand Down Expand Up @@ -353,11 +362,8 @@ impl<'top> Iterator for AnyEExpArgGroupIterator<'top> {
impl<'top> EExpressionArgGroup<'top, AnyEncoding> for AnyEExpArgGroup<'top> {
type Iterator = AnyEExpArgGroupIterator<'top>;

fn encoding(&self) -> ParameterEncoding {
match self.kind {
AnyEExpArgGroupKind::Text_1_1(g) => g.encoding(),
AnyEExpArgGroupKind::Binary_1_1(g) => g.encoding(),
}
fn encoding(&self) -> &ParameterEncoding {
self.kind.encoding()
}

fn resolve(self, context: EncodingContextRef<'top>) -> ArgGroup<'top, AnyEncoding> {
Expand Down
20 changes: 13 additions & 7 deletions src/lazy/binary/encoded_value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::lazy::binary::raw::type_descriptor::Header;
use crate::lazy::binary::raw::v1_1::immutable_buffer::AnnotationsEncoding;
use crate::lazy::expanded::template::ParameterEncoding;
use crate::lazy::binary::raw::v1_1::value::BinaryValueEncoding;
use crate::IonType;
use std::ops::Range;

Expand Down Expand Up @@ -41,7 +41,7 @@ impl EncodedHeader for Header {
/// without re-parsing its header information each time.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct EncodedValue<HeaderType: EncodedHeader> {
pub(crate) encoding: ParameterEncoding,
pub(crate) encoding: BinaryValueEncoding,
// If the compiler decides that a value is too large to be moved/copied with inline code,
// it will relocate the value using memcpy instead. This can be quite slow by comparison.
//
Expand Down Expand Up @@ -90,8 +90,6 @@ pub(crate) struct EncodedValue<HeaderType: EncodedHeader> {
pub annotations_encoding: AnnotationsEncoding,
// The offset of the type descriptor byte within the overall input stream.
pub header_offset: usize,
// If this value was written with a tagless encoding, this will be 0. Otherwise, it's 1.
pub opcode_length: u8,
// The number of bytes used to encode the optional length VarUInt following the header byte.
pub length_length: u8,
// The number of bytes used to encode the value itself, not including the header byte
Expand Down Expand Up @@ -130,6 +128,15 @@ impl<HeaderType: EncodedHeader> EncodedValue<HeaderType> {
start..end
}

/// Returns the number of bytes used to encode this value's opcode. If this value was serialized
/// using a tagless encoding, returns `0`.
pub fn opcode_length(&self) -> usize {
match self.encoding {
BinaryValueEncoding::Tagged => 1,
_ => 0,
}
}

/// Returns the number of bytes used to encode this value's data.
/// If the value can fit in the type descriptor byte (e.g. `true`, `false`, `null`, `0`),
/// this function will return 0.
Expand Down Expand Up @@ -262,14 +269,14 @@ mod tests {
use crate::lazy::binary::encoded_value::EncodedValue;
use crate::lazy::binary::raw::type_descriptor::Header;
use crate::lazy::binary::raw::v1_1::immutable_buffer::AnnotationsEncoding;
use crate::lazy::expanded::template::ParameterEncoding;
use crate::lazy::binary::raw::v1_1::value::BinaryValueEncoding;
use crate::{IonResult, IonType};

#[test]
fn accessors() -> IonResult<()> {
// 3-byte String with 1-byte annotation
let value = EncodedValue {
encoding: ParameterEncoding::Tagged,
encoding: BinaryValueEncoding::Tagged,
header: Header {
ion_type: IonType::String,
ion_type_code: IonTypeCode::String,
Expand All @@ -279,7 +286,6 @@ mod tests {
annotations_sequence_length: 1,
annotations_encoding: AnnotationsEncoding::SymbolAddress,
header_offset: 200,
opcode_length: 1,
length_length: 0,
value_body_length: 3,
total_length: 7,
Expand Down
Loading
Loading