types/comparable_bytes: support empty type

Signed-off-by: Lakshmi Narayanan Sreethar <lakshmi.sreethar@scylladb.com>
This commit is contained in:
Lakshmi Narayanan Sreethar
2025-08-20 22:13:29 +05:30
parent b799101a09
commit 0997b3533c
2 changed files with 10 additions and 3 deletions

View File

@@ -793,6 +793,13 @@ BOOST_AUTO_TEST_CASE(test_reversed) {
byte_comparable_test(std::move(collection_test_data), true);
}
BOOST_AUTO_TEST_CASE(test_empty) {
auto test_data = data_value(empty_type_representation{});
auto test_data_cb = comparable_bytes::from_data_value(test_data);
BOOST_REQUIRE(test_data_cb->size() == 0);
BOOST_REQUIRE(test_data == test_data_cb->to_data_value(empty_type));
}
// Test Scylla's byte-comparable encoding compatibility with Cassandra's implementation by
// verifying that serialized values produce the same comparable bytes as those generated by Cassandra.
// The test data was generated using the cassandra unit test pushed to the following branch:

View File

@@ -1229,7 +1229,7 @@ struct to_comparable_bytes_visitor {
encode_reversed(type, serialized_bytes_view, out);
}
// TODO: Handle other types
void operator()(const empty_type_impl&) {}
void operator()(const abstract_type& type) {
// Unimplemented
@@ -1351,7 +1351,7 @@ struct from_comparable_bytes_visitor {
decode_reversed(type, comparable_bytes_view, out);
}
// TODO: Handle other types
void operator()(const empty_type_impl&) {}
void operator()(const abstract_type& type) {
// Unimplemented
@@ -1364,7 +1364,7 @@ void from_comparable_bytes(const abstract_type& type, managed_bytes_view& compar
}
managed_bytes_opt comparable_bytes::to_serialized_bytes(const abstract_type& type) const {
if (_encoded_bytes.empty()) {
if (_encoded_bytes.empty() && type != *empty_type) {
return managed_bytes_opt();
}