-
Notifications
You must be signed in to change notification settings - Fork 36
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
Adds additional tooling APIs to enable Ion 1.1 support in the CLI's inspect
command
#802
Changes from all commits
10dfcd4
6cf797d
e386d22
5ffea14
f33e007
d9b4133
eca73b4
174522f
d3e5cc5
bd495be
5134408
2ee125b
e5152f3
4bda375
ddeaa7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ use crate::lazy::expanded::EncodingContextRef; | |
use crate::lazy::raw_stream_item::LazyRawStreamItem; | ||
use crate::lazy::raw_value_ref::RawValueRef; | ||
use crate::lazy::span::Span; | ||
use crate::lazy::streaming_raw_reader::RawReaderState; | ||
use crate::lazy::text::raw::r#struct::{ | ||
LazyRawTextFieldName_1_0, LazyRawTextStruct_1_0, RawTextStructIterator_1_0, | ||
}; | ||
|
@@ -599,20 +600,20 @@ impl<'data> LazyRawReader<'data, AnyEncoding> for LazyRawAnyReader<'data> { | |
} | ||
} | ||
|
||
fn stream_data(&self) -> (&'data [u8], usize, IonEncoding) { | ||
fn save_state(&self) -> RawReaderState<'data> { | ||
use RawReaderKind::*; | ||
let (remaining_data, stream_offset, mut encoding) = match &self.encoding_reader { | ||
Text_1_0(r) => r.stream_data(), | ||
Binary_1_0(r) => r.stream_data(), | ||
Text_1_1(r) => r.stream_data(), | ||
Binary_1_1(r) => r.stream_data(), | ||
let reader_state = match &self.encoding_reader { | ||
Text_1_0(r) => r.save_state(), | ||
Binary_1_0(r) => r.save_state(), | ||
Text_1_1(r) => r.save_state(), | ||
Binary_1_1(r) => r.save_state(), | ||
}; | ||
// If we hit an IVM that changed the encoding but we haven't changed our reader yet, | ||
// we still want to report the new encoding. | ||
if let Some(new_encoding) = self.new_encoding { | ||
encoding = new_encoding; | ||
return RawReaderState::new(reader_state.data(), reader_state.offset(), new_encoding); | ||
} | ||
(remaining_data, stream_offset, encoding) | ||
reader_state | ||
} | ||
|
||
fn next<'top>( | ||
|
@@ -625,9 +626,12 @@ impl<'data> LazyRawReader<'data, AnyEncoding> for LazyRawAnyReader<'data> { | |
// If we previously ran into an IVM that changed the stream encoding, replace our reader | ||
// with one that can read the new encoding. | ||
if let Some(new_encoding) = self.new_encoding.take() { | ||
let (remaining_data, stream_offset, _) = self.stream_data(); | ||
let new_encoding_reader = | ||
RawReaderKind::resume_at_offset(remaining_data, stream_offset, new_encoding); | ||
let reader_state = self.save_state(); | ||
let new_encoding_reader = RawReaderKind::resume_at_offset( | ||
reader_state.data(), | ||
reader_state.offset(), | ||
new_encoding, | ||
); | ||
self.encoding_reader = new_encoding_reader; | ||
} | ||
|
||
|
@@ -1149,10 +1153,12 @@ impl<'top> LazyContainerPrivate<'top, AnyEncoding> for LazyRawAnyList<'top> { | |
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Lots of structs now implement |
||
pub struct RawAnyListIterator<'data> { | ||
encoding: RawAnyListIteratorKind<'data>, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum RawAnyListIteratorKind<'data> { | ||
Text_1_0(RawTextListIterator_1_0<'data>), | ||
Binary_1_0(RawBinarySequenceIterator_1_0<'data>), | ||
|
@@ -1310,10 +1316,12 @@ impl<'data> LazyContainerPrivate<'data, AnyEncoding> for LazyRawAnySExp<'data> { | |
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct RawAnySExpIterator<'data> { | ||
encoding: RawAnySExpIteratorKind<'data>, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum RawAnySExpIteratorKind<'data> { | ||
Text_1_0(RawTextSExpIterator_1_0<'data>), | ||
Binary_1_0(RawBinarySequenceIterator_1_0<'data>), | ||
|
@@ -1513,10 +1521,12 @@ impl<'top> From<LazyRawBinaryFieldName_1_1<'top>> for LazyRawAnyFieldName<'top> | |
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct RawAnyStructIterator<'data> { | ||
encoding: RawAnyStructIteratorKind<'data>, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum RawAnyStructIteratorKind<'data> { | ||
Text_1_0(RawTextStructIterator_1_0<'data>), | ||
Binary_1_0(RawBinaryStructIterator_1_0<'data>), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,7 +247,7 @@ impl<'a> ImmutableBuffer<'a> { | |
} | ||
// XXX: This *doesn't* slice `self` because FlexUInt::read() is faster if the input | ||
// is at least the size of a u64. | ||
let matched_input = self; | ||
let matched_input = self.slice(0, size_in_bytes); | ||
let remaining_input = self.slice_to_end(size_in_bytes); | ||
let value = LazyRawBinaryValue_1_1::for_flex_uint(matched_input); | ||
Ok((value, remaining_input)) | ||
|
@@ -622,7 +622,7 @@ impl<'a> ImmutableBuffer<'a> { | |
let header = opcode | ||
.to_header() | ||
.ok_or_else(|| IonError::decoding_error("found a non-value in value position .."))?; | ||
|
||
let header_offset = input.offset(); | ||
let (total_length, length_length, value_body_length, delimited_contents) = if opcode.is_delimited_start() { | ||
let (contents, after) = input.peek_delimited_container(opcode)?; | ||
let total_length = after.offset() - self.offset(); | ||
|
@@ -646,10 +646,17 @@ impl<'a> ImmutableBuffer<'a> { | |
(total_length, length_length, value_length, DelimitedContents::None) | ||
}; | ||
|
||
let header_offset = input.offset(); | ||
if total_length > input.len() { | ||
return IonResult::incomplete( | ||
"the stream ended unexpectedly in the middle of a value", | ||
header_offset, | ||
); | ||
} | ||
Comment on lines
+649
to
+654
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Somehow the test for incomplete binary values never made the leap from 1.0 to 1.1, so here it is. |
||
|
||
let encoded_value = EncodedValue { | ||
encoding: ParameterEncoding::Tagged, | ||
header, | ||
// If applicable, these are populated by the caller: `read_annotated_value()` | ||
annotations_header_length: 0, | ||
annotations_sequence_length: 0, | ||
annotations_encoding: AnnotationsEncoding::SymbolAddress, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ I renamed
stream_data
tosave_state
to eliminate the noun/verb ambiguity Matt noticed in the feedback for #796.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to find the comment: #796 (comment)
It's a little ironic because "save state" is nearly as ambiguous as "stream data". Both "save" and "stream" may be adjectives or verbs. "save state" is clearer though, and has the correct implication interpreted either way. I like the change :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a noun, consider
data_stream
,saved_state
. If it's a verb, considersave_reader_state
maybe?Or even
get_reader_state()
? (Or, if it accepts ownedself
, then maybeinto_reader_state()
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the name
stream_data
was noun/verb ambiguous, I think the actual problem being solved was that the name didn't explain what it did. I thinksave_state
addresses that, even if it remains noun/verb ambiguous.