-
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
Initial implementation of Ion 1.1 raw binary writer #660
Conversation
expected, actual, | ||
"Bytes don't match!\nEXPECTED:\n" + hexDump(expected) + "\nACTUAL:\n" + hexDump(actual) + "\n" |
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.
This is because of the change from org.junit.Assert
to org.junit.jupiter.api.Assertions
.
fun writeFlexIntOrUIntInto(data: ByteArray, offset: Int, value: Long, numBytes: Int) { | ||
var i = offset | ||
|
||
when (numBytes) { |
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 discovered that using when
to compare directly against some constants would allow the Kotlin compiler to generate a jump table, so I figured I'd just manually unroll the old loop based logic. Now the only branching in this method is the jump table for the when
, compared to the chained if
/else
falling back to the loop in the previous implementation.
src/main/java/com/amazon/ion/impl/bin/IonRawBinaryWriter_1_1.kt
Outdated
Show resolved
Hide resolved
// Just checking that data is written, not asserting the content. | ||
assertTrue(actual.isNotBlank()) |
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.
Note: it would also be correct for the output to be blank in this particular case, since no user values were written. This is true for all the tests that write only an IVM before finish/close.
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.
Is that the behavior we want for Ion 1.1, though? What if someone calls writeIVM()
and then finish()
(maybe they have logic that writes after every top level piece of "data") and then try to write Ion 1.1 data? I know it's a niche case, but that would cause invalid data to be written.
In addition, because emitting an IVM resets the encoding environment, I think the decision of when to write or not write the IVM belongs in a higher level writer that is aware of the encoding environment.
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.
writeIVM()
should be a raw-level API, not accessible to users of an application-level writer. Those users get IVMs written as a side effect of writing user values. The IVM that is written depends on the kind of writer the user selected (Ion 1.0 or Ion 1.1).
So, I think I'm saying I agree that for the purpose of these raw tests, the assertions of IVM writing are fine. The raw writer should always write an IVM when requested, but the user-level writer should only request one before writing a new encoding environment that precedes user values.
Issue #, if available:
None.
Description of changes:
IonWriter_1_1
with support for nulls, bools, and lists.WriteBuffer
toFlexInt
.WriteBuffer
so thatFlexInt
andFlexUInt
are written directly to the data array of the block instead of being indirected throughwriteByte()
.PatchPoint
to be a top level class so that it can be shared between writers.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.