-
Notifications
You must be signed in to change notification settings - Fork 111
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 writing binary Ion 1.1 timestamps #618
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.amazon.ion.impl.bin; | ||
|
||
/** | ||
* Contains constants (other than OpCodes) which are generally applicable to both reading and writing binary Ion 1.1 | ||
*/ | ||
public class Ion_1_1_Constants { | ||
private Ion_1_1_Constants() {} | ||
|
||
//////// Timestamp Field Constants //////// | ||
|
||
// S_TIMESTAMP_* is applicable to all short-form timestamps | ||
static final int S_TIMESTAMP_MONTH_BIT_OFFSET = 7; | ||
static final int S_TIMESTAMP_DAY_BIT_OFFSET = 11; | ||
static final int S_TIMESTAMP_HOUR_BIT_OFFSET = 16; | ||
static final int S_TIMESTAMP_MINUTE_BIT_OFFSET = 21; | ||
// S_U_TIMESTAMP_* is applicable to all short-form timestamps with a `U` bit | ||
static final int S_U_TIMESTAMP_UTC_FLAG = 1 << 27; | ||
static final int S_U_TIMESTAMP_SECOND_BIT_OFFSET = 28; | ||
static final int S_U_TIMESTAMP_FRACTION_BIT_OFFSET = 34; | ||
// S_O_TIMESTAMP_* is applicable to all short-form timestamps with `o` (offset) bits | ||
static final int S_O_TIMESTAMP_OFFSET_BIT_OFFSET = 27; | ||
static final int S_O_TIMESTAMP_SECOND_BIT_OFFSET = 34; | ||
|
||
// L_TIMESTAMP_* is applicable to all long-form timestamps | ||
static final int L_TIMESTAMP_MONTH_BIT_OFFSET = 14; | ||
static final int L_TIMESTAMP_DAY_BIT_OFFSET = 18; | ||
static final int L_TIMESTAMP_HOUR_BIT_OFFSET = 23; | ||
static final int L_TIMESTAMP_MINUTE_BIT_OFFSET = 28; | ||
static final int L_TIMESTAMP_OFFSET_BIT_OFFSET = 34; | ||
static final int L_TIMESTAMP_SECOND_BIT_OFFSET = 46; | ||
static final int L_TIMESTAMP_UNKNOWN_OFFSET_VALUE = 0b111111111111; | ||
|
||
//////// Bit masks //////// | ||
|
||
static final long LEAST_SIGNIFICANT_7_BITS = 0b01111111L; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1437,7 +1437,7 @@ public static int fixedIntLength(final long value) { | |
*/ | ||
public int writeFixedInt(final long value) { | ||
int numBytes = fixedIntLength(value); | ||
return writeFixedIntOrUInt(value, numBytes); | ||
return _writeFixedIntOrUInt(value, numBytes); | ||
} | ||
|
||
/** Get the length of FixedUInt for the provided value. */ | ||
|
@@ -1453,17 +1453,40 @@ public static int fixedUIntLength(final long value) { | |
*/ | ||
public int writeFixedUInt(final long value) { | ||
if (value < 0) { | ||
throw new IllegalArgumentException("Attempted to write a FlexUInt for " + value); | ||
throw new IllegalArgumentException("Attempted to write a FixedUInt for " + value); | ||
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. Just fixing a typo that I noticed while working on Timestamps. |
||
} | ||
int numBytes = fixedUIntLength(value); | ||
return writeFixedIntOrUInt(value, numBytes); | ||
return _writeFixedIntOrUInt(value, numBytes); | ||
} | ||
|
||
/** | ||
* Because the fixed int and fixed uint encodings are so similar, we can use this method to write either one as long | ||
* as we provide the correct number of bytes needed to encode the value. | ||
* Writes the bytes of a {@code long} as a {@code FixedInt} or {@code FixedUInt} using {@code numBytes} bytes. | ||
* <p> | ||
* {@code numBytes} should be an integer from 1 to 8 inclusive. If {@code numBytes} is out of bounds, that is a | ||
* programmer error and will result in an IllegalArgumentException. | ||
* <p> | ||
* Because the {@code FixedInt} and {@code FixedUInt} encodings are so similar, we can use this method to write | ||
* either one as long as we provide the correct number of bytes needed to encode the value. | ||
* <p> | ||
* Most of the time, you should not use this method. Instead, use {@link WriteBuffer#writeFixedInt} or | ||
* {@link WriteBuffer#writeFixedUInt}, which calculate the minimum number of required bytes to represent the value. | ||
* <p> | ||
* You <i>should</i> use this method when the spec requires a {@code FixedInt} or {@code FixedUInt} of a specific | ||
* size when it's possible that the value could fit in a smaller FixedInt or FixedUInt than the size required in | ||
* the spec. | ||
*/ | ||
public int writeFixedIntOrUInt(final long value, final int numBytes) { | ||
if (0 > numBytes || numBytes > 8) { | ||
throw new IllegalArgumentException("numBytes is out of bounds; was " + numBytes); | ||
} | ||
return _writeFixedIntOrUInt(value, numBytes); | ||
} | ||
|
||
/** | ||
* Because the {@code FixedInt} and {@code FixedUInt} encodings are so similar, we can use this method to write | ||
* either one as long as we provide the correct number of bytes needed to encode the value. | ||
*/ | ||
private int writeFixedIntOrUInt(final long value, final int numBytes) { | ||
private int _writeFixedIntOrUInt(final long value, final int numBytes) { | ||
writeByte((byte) value); | ||
if (numBytes > 1) { | ||
writeByte((byte) (value >> 8)); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These were unused imports.