-
Notifications
You must be signed in to change notification settings - Fork 70
feat: implement endian conversion utilities #196
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
Conversation
src/iceberg/util/endian.h
Outdated
|
|
||
| /// \brief Concept for values that can be converted to/from another endian format. | ||
| template <typename T> | ||
| concept EndianConvertible = std::is_arithmetic_v<T> && !std::same_as<T, bool>; |
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.
Why excluding bool?
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.
Sizeof(bool) is 1 byte, and endianness is irrelevant for single-byte data types; a byte-swap is a no-op.
Also, according to the Iceberg specification, a boolean is represented as 0x00 for false and any non-zero byte for true. This definition is inherently independent of endianness, which is different from multi-byte types like int or double, where the specification explicitly defines the value as being stored in a particular endian format .
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.
What about char? There is a sizeof(T) <= 1 branch, so maybe treat bool the same.
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.
What about char? There is a
sizeof(T) <= 1branch, so maybe treat bool the same.
I see your point, but I think performing an endian conversion on a bool is semantically less reasonable. The main benefit of the current design is that it explicitly catches this kind of logical error at compile time.
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.
If we don't support bool here, users may need to special case bool to avoid passing it to ByteSwap. For simplicity, should we support bool as well?
cffc99f to
8fa1e09
Compare
zhjwpku
left a comment
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.
LGTM
src/iceberg/util/endian.h
Outdated
|
|
||
| /// \brief Concept for values that can be converted to/from another endian format. | ||
| template <typename T> | ||
| concept EndianConvertible = std::is_arithmetic_v<T> && !std::same_as<T, bool>; |
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.
If we don't support bool here, users may need to special case bool to avoid passing it to ByteSwap. For simplicity, should we support bool as well?
|
@wgtmac I've updated the code to address the feedback from the review. Thank you. |
wgtmac
left a comment
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.
Thanks @HeartLinked!
Fokko
left a comment
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.
Thanks for adding this @HeartLinked, and thanks for the review all! 🙌
Implements cross-platform endianness conversion utilities in
src/iceberg/util/endian.hwith full support for integer and floating-point types, including comprehensive test coverage.