-
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
Enables the StreamingRawReader to detect incomplete text #784
Conversation
a4451e0
to
66a4683
Compare
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.
🗺️ PR tour 🧭
@@ -402,6 +396,16 @@ impl<'data> LazyRawReader<'data, AnyEncoding> for LazyRawAnyReader<'data> { | |||
Binary_1_1(r) => r.position(), | |||
} | |||
} | |||
|
|||
fn encoding(&self) -> IonEncoding { |
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.
🗺️ All raw readers now provide a fn encoding(&self) -> IonEncoding
, which allows generic code to tell which Ion encoding it's working with.
src/lazy/binary/raw/value.rs
Outdated
@@ -258,7 +258,7 @@ impl<'a, 'top> EncodedBinaryValueData_1_0<'a, 'top> { | |||
/// value's body (that is: the content of the value that follows its opcode and length). | |||
pub fn body_range(&self) -> Range<usize> { | |||
let encoded = &self.value.encoded_value; | |||
let body_offset = encoded.header_length(); | |||
let body_offset = encoded.annotations_header_length as usize + encoded.header_length(); |
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.
🗺️ This fixes a bug that the ion-cli
has to work around.
In binary encodings, stream items contain enough data for the reader to tell whether they are complete. In text encodings, it's possible for the buffer to end with data that looks like a complete item but is not. The only way to be certain is to try to read again from the input source to confirm there's no more data. Consider the following examples in which Ion is being pulled from a
File
into aVec<u8>
:To avoid misinterpreting the data, the
StreamingRawReader
now performs a final check for text readers who have emptied their buffer: it does not consider the item complete unless the input source is exhausted.Other changes:
IonStream
a public part of theexperimental-reader-writer
API.EncodedBinaryValueData_1_0::body_span
that caused it to fail if the value in question was annotated.The three commits are each self-contained; reviewing them separately may be helpful.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.