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 API for getting endianness of a binary resource bundle #4804

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

leftmostcat
Copy link
Contributor

Resource bundles for time zone data are serialized with intvector fields containing 64-bit integers which are serialized in an ad hoc, endian-sensitive manner (due to lack of 64-bit integer support in resb). Since this isn't a part of the standard and is required for correct interpretation of time zone data, it's necessary to provide a means of determining bundle endianness for consumers using the serde deserializer.

Note that big endian resource bundles aren't presently supported, but this support is planned in order to support big endian systems or systems where resource bundles intended for use with icu4j are present.

@leftmostcat leftmostcat requested a review from a team as a code owner April 12, 2024 23:57
@sffc sffc self-requested a review April 18, 2024 17:53
sffc
sffc previously approved these changes Apr 19, 2024
@@ -152,7 +112,8 @@ primitive_enum!(
u8,
/// The endianness used to write a resource bundle.
#[derive(Clone, Copy, Debug, PartialEq)]
enum Endianness {
#[allow(clippy::exhaustive_enums, missing_docs)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[allow(clippy::exhaustive_enums, missing_docs)]
#[allow(clippy::exhaustive_enums)] // only two types of endianness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added missing_docs because otherwise it complains about a lack of documentation for the variants. In theory, I could put something there, but... what?

Comment on lines 444 to 449
let rest =
input
.get(core::mem::size_of::<u16>()..)
.ok_or(BinaryDeserializerError::invalid_data(
"unexpected end of input",
))?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: use your new helper function get_subslice

Comment on lines +436 to +439
// Safe to unwrap at the end of this because `try_into()` for arrays will
// only fail if the slice is the wrong size.
#[allow(clippy::unwrap_used)]
let bytes = get_subslice(input, ..core::mem::size_of::<u16>())?
Copy link
Member

Choose a reason for hiding this comment

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

Yet another use case for rust-lang/rust#119128

Suggested change
// Safe to unwrap at the end of this because `try_into()` for arrays will
// only fail if the slice is the wrong size.
#[allow(clippy::unwrap_used)]
let bytes = get_subslice(input, ..core::mem::size_of::<u16>())?
// Safe to unwrap at the end of this because `try_into()` for arrays will
// only fail if the slice is the wrong size.
// TODO: Use split_at_checked when available
// <https://github.com/rust-lang/rust/issues/119128>
#[allow(clippy::unwrap_used)]
let bytes = get_subslice(input, ..core::mem::size_of::<u16>())?

@sffc sffc merged commit ec7c792 into unicode-org:main Apr 25, 2024
30 checks passed
@leftmostcat leftmostcat deleted the resb-endianness-api branch September 6, 2024 16:42
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