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

Adds a 1.1 ValueWriter setting for writing symbol text inline #804

Merged
merged 19 commits into from
Aug 15, 2024

Conversation

zslayton
Copy link
Contributor

This PR builds on the changes in #802.


To start, the setting currently governs symbol values and annotations. There is not yet a way to:

  • write inline annotations and interned values or vice-versa.
  • write a length-prefixed struct that writes its field names inline.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor Author

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ PR tour

Comment on lines 465 to 470
let header = type_descriptor.to_header().ok_or_else(|| {
IonError::decoding_error(format!(
"found a non-value in value position; buffer=<{:X?}>",
input.bytes_range(0, 16.min(input.bytes().len()))
))
})?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ The old error message was maddening. Now you can at least see the unexpected opcode.

src/lazy/encoder/binary/v1_1/container_writers.rs Outdated Show resolved Hide resolved
Comment on lines +77 to +79
if input.len() < flex_sym_end {
return IonResult::incomplete("reading a FlexSym", offset);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ If the buffer ended in the middle of a FlexSym, it would lead to a panic instead of reporting Incomplete.

Comment on lines 210 to 231
if self.encoding.symbol_creation_policy == SymbolCreationPolicy::WriteProvidedToken {
if self.has_inline_symbol_text() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ has_inline_symbol_text is more specific than the initial SymbolCreationPolicy. It may be that I can remove that concept, but if so I'll do that in another PR.

// Store the tokens as they are. Text will be written as text, symbol IDs will be written
// as symbol IDs. TODO: Lookup SIDs to see if they have text?
// as symbol IDs.
// TODO: Replace SIDs w/text if they're defined? (Config setting?)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ If the caller passes a SID, we write it as-is. At a minimum, we should validate that it's in range.

Comment on lines -22 to -36
let item = reader.next_item()?;
match item {
SystemStreamItem::VersionMarker(marker) => {
// Note that this uses the Ion version with which the IVM was encoded rather than
// the Ion version the stream is switching to. We can do this because the format
// (i.e text or binary) stays the same when the version changes.
// TODO: Use new encoding, once we have APIs to get new/old encodings for the marker.
let is_human_readable = marker.encoding().is_text();
let value = reader.expect_next_value()?;
let value_deserializer = ValueDeserializer::new(&value, is_human_readable);
T::deserialize(value_deserializer)
}
SystemStreamItem::Value(value) => {
let value_deserializer = ValueDeserializer::new(&value, true);
T::deserialize(value_deserializer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ This old implementation would return an error if an LST preceded the first value.

@zslayton zslayton requested a review from popematt August 13, 2024 16:04
Base automatically changed from inspect-1_1 to main August 13, 2024 19:59
@zslayton zslayton merged commit a66ca87 into main Aug 15, 2024
29 of 32 checks passed
@zslayton zslayton deleted the inline-text-setting branch August 15, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants