Skip to content

feat: implement endian conversion utilities#196

Merged
Fokko merged 4 commits into
apache:mainfrom
HeartLinked:endian
Sep 1, 2025
Merged

feat: implement endian conversion utilities#196
Fokko merged 4 commits into
apache:mainfrom
HeartLinked:endian

Conversation

@HeartLinked

Copy link
Copy Markdown
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.

Comment thread src/iceberg/util/endian.h Outdated
Comment thread 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>;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread src/iceberg/util/endian.h Outdated
Comment thread test/CMakeLists.txt Outdated
Comment thread src/iceberg/util/endian.h Outdated
Comment thread src/iceberg/util/endian.h
@HeartLinked HeartLinked force-pushed the endian branch 2 times, most recently from cffc99f to 8fa1e09 Compare August 27, 2025 10:16

@zhjwpku zhjwpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread 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>;

Copy link
Copy Markdown
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?

Comment thread src/iceberg/util/endian.h Outdated
Comment thread test/endian_test.cc Outdated
Comment thread src/iceberg/util/endian.h
Comment thread src/iceberg/util/endian.h Outdated
Comment thread test/endian_test.cc Outdated
Comment thread test/endian_test.cc Outdated
Comment thread test/endian_test.cc Outdated
Comment thread test/endian_test.cc
Comment thread test/endian_test.cc
@HeartLinked

Copy link
Copy Markdown
Contributor Author

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

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @HeartLinked!

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

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