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 decimals. #653

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

tgregg
Copy link
Contributor

@tgregg tgregg commented Nov 21, 2023

Description of changes:

Read Ion 1.1 decimals as BigDecimal or Decimal. Only the latter supports negative zero. The changes to IonTypeID are to comply with amazon-ion/ion-docs#286.

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

@tgregg tgregg requested a review from popematt November 21, 2023 16:59
/**
* Reads into a BigDecimal the decimal value that begins at `peekIndex` and ends at `valueMarker.endIndex`.
* @return the value.
*/
private BigDecimal readBigDecimal_1_1() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need this, given that Decimal extends BigDecimal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only for performance reasons. See the comment in readDecimal_1_1().

}

@ParameterizedTest
@CsvSource({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a few test cases for reading numbers that are encoded with a longer-than-necessary length or using the variable length op code for a small number? E.g.

  • 14, 64 01 0E 00 00
  • 14, F6 05 01 0E
  • 0., F6 03 01

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 next test covers the latter two. I can add some overpadded examples too.

" 3.141592653589793238462643383, F6 1B CB B7 3C 92 86 40 9F 1B 01 1F AA 26 0A",
" 3.14159265358979323846264338327950, F6 1F C1 8E 29 E5 E3 56 D5 DF C5 10 8F 55 3F 7D 0F",
})
public void readDecimalValue(@ConvertWith(TestUtils.StringToDecimal.class) Decimal expectedValue, String inputBytes) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test has only variable-length encoding cases. Did the test names get swapped by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@tgregg tgregg force-pushed the ion-11-read-decimals branch from 92365d7 to d749378 Compare November 21, 2023 19:29
@tgregg tgregg merged commit 4b6aa34 into ion-11-encoding Nov 21, 2023
15 of 27 checks passed
@tgregg tgregg deleted the ion-11-read-decimals branch November 21, 2023 19:48
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