Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/fix get_serialized_size #507

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ bool get_serialized_size(const T& sample, size_t &sz)

return true;
}

template<typename T, class S>
bool serialize_into_impl(void *hdr,
void *buffer,
Expand Down Expand Up @@ -1041,29 +1042,37 @@ uint32_t sertype_hash(const ddsi_sertype* tpcmn)
}

template <typename T, class S>
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<const T*>(sample);

// get the serialized size of the sample (without serializing)
size_t sz = 0;
if (!get_serialized_size<T,S,key_mode::not_key>(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<T,S,key_mode::unsorted>(msg, sz)) {
return DDS_RETCODE_BAD_PARAMETER;
}
} else {
if (!get_serialized_size<T,S,key_mode::not_key>(msg, sz)) {
return DDS_RETCODE_BAD_PARAMETER;
}
}
return sz;

uint16_t header[2];
static_cast<void>(write_header<T, S>(header));
*size = sz;
*enc_identifier = header[0];
return DDS_RETCODE_OK;
}

template <typename T, class S>
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<const T*>(sample);

return serialize_into<T,S>(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<typename T,
Expand Down
Loading