Skip to content

Conversation

@HeartLinked
Copy link
Contributor

Implements cross-platform endianness conversion utilities in src/iceberg/util/endian.h with full support for integer and floating-point types, including comprehensive test coverage.


/// \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>;
Copy link
Member

Choose a reason for hiding this comment

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

Why excluding bool?

Copy link
Contributor Author

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 .

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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.

Copy link
Member

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?

@HeartLinked HeartLinked force-pushed the endian branch 2 times, most recently from cffc99f to 8fa1e09 Compare August 27, 2025 10:16
Copy link
Collaborator

@zhjwpku zhjwpku left a comment

Choose a reason for hiding this comment

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

LGTM


/// \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>;
Copy link
Member

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?

@HeartLinked
Copy link
Contributor Author

@wgtmac I've updated the code to address the feedback from the review. Thank you.

Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

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

Thanks @HeartLinked!

Copy link
Contributor

@Fokko Fokko left a 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! 🙌

@Fokko Fokko merged commit 7595047 into apache:main Sep 1, 2025
7 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.

5 participants