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

Makes the binary reader set the encoding version when seeked to a span. #622

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/com/amazon/ion/impl/IonCursorBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.amazon.ion.IonCursor;
import com.amazon.ion.IonType;
import com.amazon.ion.IvmNotificationConsumer;
import com.amazon.ion.SystemSymbols;

import java.io.ByteArrayInputStream;
import java.io.EOFException;
Expand Down Expand Up @@ -1786,15 +1787,24 @@
* can be used to seek the reader to a "span" of bytes that represent a value in the stream.
* @param offset the offset at which the slice will begin.
* @param limit the slice's limit.
* @param ionVersionId the Ion version ID for the slice, e.g. $ion_1_0 for Ion 1.0.
*/
void slice(long offset, long limit) {
void slice(long offset, long limit, String ionVersionId) {
peekIndex = offset;
this.limit = limit;
setCheckpointBeforeUnannotatedTypeId();
valueMarker.endIndex = -1;
event = Event.NEEDS_DATA;
valueTid = null;
containerIndex = -1; // Slices are treated as if they were at the top level.
if (SystemSymbols.ION_1_0.equals(ionVersionId)) {
typeIds = IonTypeID.TYPE_IDS_1_0;
majorVersion = 1;
minorVersion = 0;
} else {
// TODO changes are needed here to support Ion 1.1.
throw new IonException(String.format("Attempted to seek using an unsupported Ion version %s.", ionVersionId));

Check warning on line 1806 in src/com/amazon/ion/impl/IonCursorBinary.java

View check run for this annotation

Codecov / codecov/patch

src/com/amazon/ion/impl/IonCursorBinary.java#L1806

Added line #L1806 was not covered by tests
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public void hoist(Span span) {
// of the value to be the end of the stream, in order to comply with the SeekableReader contract. From
// an implementation perspective, this is not necessary; if we leave the buffer's limit unchanged, the
// reader can continue after processing the hoisted value.
slice(binarySpan.bufferOffset, binarySpan.bufferLimit);
restoreSymbolTable(binarySpan.symbolTable);
slice(binarySpan.bufferOffset, binarySpan.bufferLimit, binarySpan.symbolTable.getIonVersionId());
type = null;
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/com/amazon/ion/streaming/SeekableReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.amazon.ion.IonType;
import com.amazon.ion.IonWriter;
import com.amazon.ion.ReaderMaker;
import com.amazon.ion.SeekableReader;
import com.amazon.ion.Span;
import com.amazon.ion.TestUtils;
import com.amazon.ion.impl._Private_Utils;
Expand Down Expand Up @@ -327,6 +328,22 @@ public void testHoistingAcrossSymbolTableBoundary()
expectTopEof();
}

@Test
public void testHoistingFromSpanCreatedByDifferentReaderBeforeNext()
{
read("foo bar");
in.next();
in.next();
Span barSpan = sr.currentSpan();

read("foo bar"); // Creates a new reader
initFacets();

hoist(barSpan);
assertSame(IonType.SYMBOL, in.next());
assertEquals("bar", in.stringValue());
}


//========================================================================
// Failure cases
Expand Down
Loading