-
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
Version bump to 1.0.0-rc.6, improvements to IonEncoding #785
Changes from 7 commits
3beb771
c8921de
90e1fbd
9356402
3c1532c
cd52d10
44be8d1
21fd8c3
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 |
---|---|---|
|
@@ -53,7 +53,7 @@ use crate::lazy::text::value::{ | |
LazyRawTextValue_1_0, LazyRawTextValue_1_1, LazyRawTextVersionMarker_1_0, | ||
LazyRawTextVersionMarker_1_1, RawTextAnnotationsIterator, | ||
}; | ||
use crate::{IonResult, IonType, RawSymbolRef}; | ||
use crate::{Encoding, IonResult, IonType, RawSymbolRef}; | ||
use bumpalo::Bump as BumpAllocator; | ||
|
||
/// An implementation of the `LazyDecoder` trait that can read any encoding of Ion. | ||
|
@@ -89,6 +89,18 @@ pub enum LazyRawAnyVersionMarkerKind<'top> { | |
Binary_1_1(LazyRawBinaryVersionMarker_1_1<'top>), | ||
} | ||
|
||
impl<'top> LazyRawAnyVersionMarker<'top> { | ||
pub fn encoding(&self) -> IonEncoding { | ||
use crate::lazy::any_encoding::LazyRawAnyVersionMarkerKind::*; | ||
match self.encoding { | ||
Text_1_0(_) => TextEncoding_1_0.encoding(), | ||
Binary_1_0(_) => BinaryEncoding_1_0.encoding(), | ||
Text_1_1(_) => TextEncoding_1_1.encoding(), | ||
Binary_1_1(_) => BinaryEncoding_1_1.encoding(), | ||
} | ||
} | ||
} | ||
|
||
impl<'top> HasSpan<'top> for LazyRawAnyVersionMarker<'top> { | ||
fn span(&self) -> Span<'top> { | ||
use LazyRawAnyVersionMarkerKind::*; | ||
|
@@ -165,6 +177,16 @@ pub enum LazyRawAnyEExpressionKind<'top> { | |
Binary_1_1(Never), // TODO: RawBinaryEExpression_1_1 | ||
} | ||
|
||
impl<'top> LazyRawAnyEExpression<'top> { | ||
pub fn encoding(&self) -> IonEncoding { | ||
use LazyRawAnyEExpressionKind::*; | ||
match self.encoding { | ||
Text_1_1(_) => TextEncoding_1_1.encoding(), | ||
Binary_1_1(_) => BinaryEncoding_1_1.encoding(), | ||
} | ||
} | ||
} | ||
|
||
impl<'top> From<RawTextEExpression_1_1<'top>> for LazyRawAnyEExpression<'top> { | ||
fn from(text_invocation: RawTextEExpression_1_1<'top>) -> Self { | ||
LazyRawAnyEExpression { | ||
|
@@ -278,7 +300,7 @@ pub enum RawReaderKind<'data> { | |
Binary_1_1(LazyRawBinaryReader_1_1<'data>), | ||
} | ||
|
||
#[derive(Default, Copy, Clone)] | ||
#[derive(Default, Debug, Copy, Clone)] | ||
#[non_exhaustive] | ||
pub enum IonEncoding { | ||
// In the absence of a binary IVM, readers must assume Ion 1.0 text data until a | ||
|
@@ -300,6 +322,24 @@ impl IonEncoding { | |
use IonEncoding::*; | ||
matches!(*self, Binary_1_0 | Binary_1_1) | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
use IonEncoding::*; | ||
match self { | ||
Text_1_0 => TextEncoding_1_0::name(), | ||
Binary_1_0 => BinaryEncoding_1_0::name(), | ||
Text_1_1 => TextEncoding_1_1::name(), | ||
Binary_1_1 => BinaryEncoding_1_1::name(), | ||
} | ||
} | ||
|
||
pub fn version(&self) -> (u8, u8) { | ||
use IonEncoding::*; | ||
match self { | ||
Text_1_0 | Binary_1_0 => (1, 0), | ||
Text_1_1 | Binary_1_1 => (1, 1), | ||
} | ||
} | ||
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. 🗺️ These methods make it easier for programs like |
||
} | ||
|
||
impl<'data> From<LazyRawTextReader_1_0<'data>> for LazyRawAnyReader<'data> { | ||
|
@@ -421,6 +461,16 @@ impl<'top> LazyRawAnyValue<'top> { | |
pub fn kind(&self) -> LazyRawValueKind<'top> { | ||
self.encoding | ||
} | ||
|
||
pub fn encoding(&self) -> IonEncoding { | ||
use LazyRawValueKind::*; | ||
match &self.encoding { | ||
Text_1_0(_) => TextEncoding_1_0.encoding(), | ||
Binary_1_0(_) => BinaryEncoding_1_0.encoding(), | ||
Text_1_1(_) => TextEncoding_1_1.encoding(), | ||
Binary_1_1(_) => BinaryEncoding_1_1.encoding(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use crate::lazy::decoder::{Decoder, HasRange, HasSpan}; | ||
use crate::lazy::span::Span; | ||
use crate::result::IonFailure; | ||
use crate::{IonError, IonResult}; | ||
use crate::{AnyEncoding, IonEncoding, IonError, IonResult}; | ||
use std::fmt::Debug; | ||
use std::ops::Range; | ||
|
||
|
@@ -27,6 +27,17 @@ pub type LazyRawStreamItem<'top, D> = RawStreamItem< | |
<D as Decoder>::EExp<'top>, | ||
>; | ||
|
||
impl<'top> LazyRawStreamItem<'top, AnyEncoding> { | ||
pub fn encoding(&self) -> IonEncoding { | ||
match self { | ||
LazyRawStreamItem::<AnyEncoding>::VersionMarker(m) => m.encoding(), | ||
LazyRawStreamItem::<AnyEncoding>::Value(v) => v.encoding(), | ||
LazyRawStreamItem::<AnyEncoding>::EExpression(e) => e.encoding(), | ||
LazyRawStreamItem::<AnyEncoding>::EndOfStream(eos) => eos.encoding(), | ||
} | ||
} | ||
} | ||
|
||
impl<M: Debug + HasRange, V: Debug + HasRange, E: Debug + HasRange> HasRange | ||
for RawStreamItem<M, V, E> | ||
{ | ||
|
@@ -116,12 +127,17 @@ impl<M: Copy + Debug, V: Copy + Debug, E: Copy + Debug> RawStreamItem<M, V, E> { | |
/// an `EndOfStream(EndPosition)` variant) to also implement them. | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct EndPosition { | ||
encoding: IonEncoding, | ||
position: usize, | ||
} | ||
|
||
impl EndPosition { | ||
pub(crate) fn new(position: usize) -> Self { | ||
Self { position } | ||
pub(crate) fn new(encoding: IonEncoding, position: usize) -> Self { | ||
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. 🗺️ While it seems a bit silly for the end of the stream to have an 'encoding' despite being a zero-length entity, this enables the |
||
Self { encoding, position } | ||
} | ||
|
||
pub fn encoding(&self) -> IonEncoding { | ||
self.encoding | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,17 +73,16 @@ impl<'top, D: Decoder> SystemStreamItem<'top, D> { | |
} | ||
} | ||
|
||
/// Like [`Self::symbol_table`], but returns a [`IonError::Decoding`] if this item is not | ||
/// a symbol table. | ||
pub fn symbol_table(self) -> Option<LazyStruct<'top, D>> { | ||
/// If this item is a symbol table, returns `Some(lazy_struct)`. Otherwise, returns `None`. | ||
pub fn as_symbol_table(self) -> Option<LazyStruct<'top, D>> { | ||
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. 🗺️ I renamed this method for consistency; other types use |
||
if let Self::SymbolTable(struct_) = self { | ||
Some(struct_) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Like [`Self::symbol_table`], but returns a [`IonError::Decoding`] if this item is not | ||
/// Like [`Self::as_symbol_table`], but returns a [`IonError::Decoding`] if this item is not | ||
/// a symbol table. | ||
pub fn expect_symbol_table(self) -> IonResult<LazyStruct<'top, D>> { | ||
if let Self::SymbolTable(value) = self { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,7 @@ macro_rules! v1_x_reader_writer { | |
lazy::r#struct::{LazyStruct, LazyField}, | ||
lazy::sequence::{LazyList, LazySExp}, | ||
lazy::encoder::value_writer::{ValueWriter, StructWriter, SequenceWriter, EExpWriter}, | ||
lazy::any_encoding::IonEncoding, | ||
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. 🗺️ This re-export is only visible when the |
||
}; | ||
}; | ||
} | ||
|
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 plumbed the
IonEncoding
from the reader up through all of the raw stream item types (version marker, value, e-expression, end of stream), making it easy to check the encoding of any item during iteration.