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 support for reading binary Ion 1.1 timestamps. #640

Merged
merged 5 commits into from
Nov 20, 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
13 changes: 13 additions & 0 deletions src/com/amazon/ion/Timestamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ else if (shouldCheckFraction)
offset, APPLY_OFFSET_NO, CHECK_FRACTION_YES);
}

/**
* @return a new Timestamp from the given components in local time, without validating the fractional seconds.
*/
@Deprecated
public static Timestamp _private_createFromLocalTimeFieldsUnchecked(Precision p, int year, int month, int day,
int hour, int minute, int second,
BigDecimal frac, Integer offset)
{
return new Timestamp(p, year, month, day,
hour, minute, second, frac,
offset, APPLY_OFFSET_YES, CHECK_FRACTION_NO);
}

/**
* Creates a new Timestamp from a {@link Calendar}, preserving the
* {@link Calendar}'s precision and local offset from UTC.
Expand Down
20 changes: 14 additions & 6 deletions src/com/amazon/ion/impl/IonCursorBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,10 @@ private long uncheckedReadFlexUInt_1_1() {
*/
private long slowReadFlexUInt_1_1() {
// TODO perf: try 1-byte special case checks. Least-significant bits of 1 indicate 1-byte
int currentByte = slowPeekByte();
int currentByte = slowReadByte();
if (currentByte < 0) {
return -1;
}
if (currentByte == 0) {
throw new IonException("Found a VarUInt that was too large to fit in a `long`");
}
Expand Down Expand Up @@ -1262,6 +1265,9 @@ private boolean uncheckedReadHeader(final int typeIdByte, final boolean isAnnota
if (endIndex > limit) {
isValueIncomplete = true;
}
if (minorVersion == 1 && valueTid.isNull && valueTid.length > 0) {
valueTid = IonTypeID.NULL_TYPE_IDS_1_1[buffer[(int)(peekIndex++) & SINGLE_BYTE_MASK]];
}
}
markerToSet.typeId = valueTid;
if (event == Event.START_CONTAINER) {
Expand Down Expand Up @@ -1306,6 +1312,13 @@ private boolean slowReadHeader(final int typeIdByte, final boolean isAnnotated,
}
return true;
}
if (minorVersion == 1 && valueTid.isNull && valueTid.length > 0) {
int nullTypeIndex = slowReadByte();
if (nullTypeIndex < 0) {
return true;
}
valueTid = IonTypeID.NULL_TYPE_IDS_1_1[nullTypeIndex];
}
markerToSet.typeId = valueTid;
if (checkpointLocation == CheckpointLocation.AFTER_SCALAR_HEADER) {
return true;
Expand Down Expand Up @@ -1335,11 +1348,6 @@ private boolean slowReadValueHeader(IonTypeID valueTid, boolean isAnnotated, Mar
if (valueTid.isDelimited) {
endIndex = DELIMITED_MARKER;
} else if (valueTid.variableLength) {
// At this point the value must be at least 2 more bytes: 1 for the smallest-possible value length
// and 1 for the smallest-possible value representation.
if (!fillAt(peekIndex, 2)) {
return true;
}
valueLength = minorVersion == 0 ? slowReadVarUInt_1_0() : slowReadFlexUInt_1_1();
if (valueLength < 0) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ private enum State {
boolean startsWithIonSymbolTable() {
long savedPeekIndex = peekIndex;
peekIndex = annotationSequenceMarker.startIndex;
int sid = minorVersion == 0 ? readVarUInt_1_0() : readVarUInt_1_1();
int sid = minorVersion == 0 ? readVarUInt_1_0() : (int) readFlexUInt_1_1();
peekIndex = savedPeekIndex;
return ION_SYMBOL_TABLE_SID == sid;
}
Expand Down
Loading
Loading