diff --git a/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp b/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp index 419b5f50..1d95df6d 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,29 +1042,37 @@ 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*, enum ddsi_serdata_kind sdkind, 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; + if (sdkind == SDK_KEY) { + if (!get_serialized_size(msg, sz)) { + return DDS_RETCODE_BAD_PARAMETER; + } + } else { + if (!get_serialized_size(msg, sz)) { + 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 -bool sertype_serialize_into(const ddsi_sertype*, - const void * sample, - void * dst_buffer, - size_t sz) +bool sertype_serialize_into(const ddsi_sertype*, enum ddsi_serdata_kind sdkind, const void * sample, void * dst_buffer, size_t sz) { // 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, (sdkind == SDK_KEY) ? key_mode::unsorted : key_mode::not_key); } template