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

Add 1.1 binary reader support for decimals #757

Merged
merged 4 commits into from
May 21, 2024

Conversation

nirosys
Copy link
Contributor

@nirosys nirosys commented May 1, 2024

Issue #, if available: #662

Description of changes:
Add support for decimals to the 1.1 binary raw reader.


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

@nirosys nirosys marked this pull request as ready for review May 1, 2024 22:38
@nirosys nirosys requested a review from zslayton May 6, 2024 19:47
// 0d3
0x61, 0x07,

// -0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// -0
// -0d3

use crate::types::decimal::Decimal;

#[rustfmt::skip]
let data: Vec<u8> = vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add additional test cases for op code 0xF7 and for over-padded exponents and coefficients. You can find a fairly complete set of test cases here and here, and I'd recommend using them rather than spending time coming up with your own.

Also, it would be nice if you could use #[rstest] for a parameterized test here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it would be nice if you could use #[rstest] for a parameterized test here.

I've been using the array-of-inputs approach a lot recently, largely because my IDE can't run #[rstest]s natively. I wish the Rust test harness would let you programmatically define a test (for individual PASS/FAIL indications) or Intellij would support macro-generated tests. 🫤

Comment on lines 242 to 250
let coefficient = if coefficient_size > 0 {
FixedInt::read(
&value_bytes[exponent.size_in_bytes()..],
coefficient_size,
0,
)?
} else {
0i64.into()
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me think that FixedInt::read should return zero if the size is zero. This seems like something that could come up in other places, and rather than handle this condition everywhere, we should probably just move it to FixedInt::read.

Copy link
Contributor

Choose a reason for hiding this comment

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

Matt made this change in PR #762.

Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

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

Looks good. Please address Matt's unit test comment before merging.

use crate::types::decimal::Decimal;

#[rustfmt::skip]
let data: Vec<u8> = vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it would be nice if you could use #[rstest] for a parameterized test here.

I've been using the array-of-inputs approach a lot recently, largely because my IDE can't run #[rstest]s natively. I wish the Rust test harness would let you programmatically define a test (for individual PASS/FAIL indications) or Intellij would support macro-generated tests. 🫤

Comment on lines 242 to 250
let coefficient = if coefficient_size > 0 {
FixedInt::read(
&value_bytes[exponent.size_in_bytes()..],
coefficient_size,
0,
)?
} else {
0i64.into()
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Matt made this change in PR #762.

@nirosys nirosys force-pushed the rgiliam/1_1_binary_reader_decimals branch from 1b4f4ed to 6d55b88 Compare May 9, 2024 23:24
@nirosys nirosys force-pushed the rgiliam/1_1_binary_reader_decimals branch from f6ed2e4 to 14fa06a Compare May 10, 2024 23:31
@nirosys nirosys merged commit fa11f26 into amazon-ion:main May 21, 2024
25 of 26 checks passed
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.

None yet

3 participants