Skip to content

Commit fff45dd

Browse files
committed
add assert
1 parent d4af609 commit fff45dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/iceberg/util/endian.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ constexpr T ToLittleEndian(T value) {
4242
return std::byteswap(value);
4343
} else if constexpr (std::is_floating_point_v<T>) {
4444
// For floats, use the bit_cast -> byteswap -> bit_cast pattern.
45+
// We only support 32-bit and 64-bit floats.
4546
if constexpr (sizeof(T) == sizeof(uint32_t)) {
4647
uint32_t int_representation = std::bit_cast<uint32_t>(value);
4748
int_representation = std::byteswap(int_representation);
@@ -50,6 +51,8 @@ constexpr T ToLittleEndian(T value) {
5051
uint64_t int_representation = std::bit_cast<uint64_t>(value);
5152
int_representation = std::byteswap(int_representation);
5253
return std::bit_cast<T>(int_representation);
54+
} else {
55+
static_assert(false, "Unsupported floating-point size for endian conversion.");
5356
}
5457
}
5558
}
@@ -65,6 +68,7 @@ constexpr T FromLittleEndian(T value) {
6568
return std::byteswap(value);
6669
} else if constexpr (std::is_floating_point_v<T>) {
6770
// For floats, use the bit_cast -> byteswap -> bit_cast pattern.
71+
// We only support 32-bit and 64-bit floats.
6872
if constexpr (sizeof(T) == sizeof(uint32_t)) {
6973
uint32_t int_representation = std::bit_cast<uint32_t>(value);
7074
int_representation = std::byteswap(int_representation);
@@ -73,6 +77,8 @@ constexpr T FromLittleEndian(T value) {
7377
uint64_t int_representation = std::bit_cast<uint64_t>(value);
7478
int_representation = std::byteswap(int_representation);
7579
return std::bit_cast<T>(int_representation);
80+
} else {
81+
static_assert(false, "Unsupported floating-point size for endian conversion.");
7682
}
7783
}
7884
}
@@ -95,6 +101,8 @@ constexpr T ToBigEndian(T value) {
95101
uint64_t int_representation = std::bit_cast<uint64_t>(value);
96102
int_representation = std::byteswap(int_representation);
97103
return std::bit_cast<T>(int_representation);
104+
} else {
105+
static_assert(false, "Unsupported floating-point size for endian conversion.");
98106
}
99107
}
100108
}
@@ -117,6 +125,8 @@ constexpr T FromBigEndian(T value) {
117125
uint64_t int_representation = std::bit_cast<uint64_t>(value);
118126
int_representation = std::byteswap(int_representation);
119127
return std::bit_cast<T>(int_representation);
128+
} else {
129+
static_assert(false, "Unsupported floating-point size for endian conversion.");
120130
}
121131
}
122132
}

0 commit comments

Comments
 (0)