From 85fe169fa297a21eaf31d1151d96e2a31a0b709b Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Tue, 3 Sep 2024 13:26:51 +0200 Subject: [PATCH] Fix get_serialized_size and serialize_into Signed-off-by: Erik Boasson --- .../org/eclipse/cyclonedds/topic/datatopic.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp b/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp index 419b5f50..6c5ffbd4 100644 --- a/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp +++ b/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp @@ -316,6 +316,7 @@ bool get_serialized_size(const T& sample, size_t &sz) return true; } + template bool serialize_into_impl(void *hdr, void *buffer, @@ -1041,17 +1042,21 @@ uint32_t sertype_hash(const ddsi_sertype* tpcmn) } template -size_t sertype_get_serialized_size(const ddsi_sertype*, const void * sample) +dds_return_t sertype_get_serialized_size(const ddsi_sertype*, const void * sample, size_t *size, uint16_t *enc_identifier) { const auto& msg = *static_cast(sample); // get the serialized size of the sample (without serializing) size_t sz = 0; if (!get_serialized_size(msg, sz)) { - // the max value is treated as an error in the Cyclone core - sz = SIZE_MAX; + return DDS_RETCODE_BAD_PARAMETER; } - return sz; + + uint16_t header[2]; + static_cast(write_header(header)); + *size = sz; + *enc_identifier = header[0]; + return DDS_RETCODE_OK; } template @@ -1062,8 +1067,9 @@ bool sertype_serialize_into(const ddsi_sertype*, { // cast to the type const auto& msg = *static_cast(sample); - - return serialize_into(dst_buffer, sz, msg, key_mode::not_key); + S str; + str.set_buffer(dst_buffer, sz); + return write(str, msg, key_mode::not_key); } template