-
Notifications
You must be signed in to change notification settings - Fork 182
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
Conversation
utils/resb/src/binary.rs
Outdated
@@ -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)] |
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.
#[allow(clippy::exhaustive_enums, missing_docs)] | |
#[allow(clippy::exhaustive_enums)] // only two types of endianness |
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 added missing_docs
because otherwise it complains about a lack of documentation for the variants. In theory, I could put something there, but... what?
utils/resb/src/binary.rs
Outdated
let rest = | ||
input | ||
.get(core::mem::size_of::<u16>()..) | ||
.ok_or(BinaryDeserializerError::invalid_data( | ||
"unexpected end of input", | ||
))?; |
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.
Suggestion: use your new helper function get_subslice
// 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>())? |
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.
Yet another use case for rust-lang/rust#119128
// 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>())? |
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.