From 0997b3533c06973c4ea5649f319a2dd29ffcedcb Mon Sep 17 00:00:00 2001 From: Lakshmi Narayanan Sreethar Date: Wed, 20 Aug 2025 22:13:29 +0530 Subject: [PATCH] types/comparable_bytes: support empty type Signed-off-by: Lakshmi Narayanan Sreethar --- test/boost/comparable_bytes_test.cc | 7 +++++++ types/comparable_bytes.cc | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/boost/comparable_bytes_test.cc b/test/boost/comparable_bytes_test.cc index 397506c3ad..917682e575 100644 --- a/test/boost/comparable_bytes_test.cc +++ b/test/boost/comparable_bytes_test.cc @@ -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: diff --git a/types/comparable_bytes.cc b/types/comparable_bytes.cc index 5c20ad230b..301601d2ca 100644 --- a/types/comparable_bytes.cc +++ b/types/comparable_bytes.cc @@ -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(); }