Skip to content

Commit 12b79b5

Browse files
committed
Update loans, serialize_into for Cyclone master
Signed-off-by: Erik Boasson <eb@ilities.com>
1 parent 2084f71 commit 12b79b5

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

rmw_cyclonedds_cpp/src/rmw_node.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,11 @@ static void * init_and_alloc_sample(
15831583
// the header will be initialized and the chunk pointer will be returned
15841584
auto chunk_ptr = dds_data_allocator_alloc(&entity->data_allocator, sample_size);
15851585
#else
1586-
auto chunk_ptr = dds_request_loan_of_size(entity->enth, sample_size);
1586+
static_cast<void>(alloc_on_heap);
1587+
void *chunk_ptr;
1588+
if (dds_request_loan_of_size(entity->enth, sample_size, &chunk_ptr) != DDS_RETCODE_OK) {
1589+
chunk_ptr = nullptr;
1590+
}
15871591
#endif
15881592
RMW_CHECK_FOR_NULL_WITH_MSG(
15891593
chunk_ptr,
@@ -1612,7 +1616,7 @@ static rmw_ret_t fini_and_free_sample(entityT & entity, void * loaned_message)
16121616
return RMW_RET_ERROR;
16131617
}
16141618
#else
1615-
if (dds_return_loan(entity->enth, loaned_message) != DDS_RETCODE_OK) {
1619+
if (dds_return_loan(entity->enth, 1, &loaned_message) != DDS_RETCODE_OK) {
16161620
RMW_SET_ERROR_MSG("Failed to free the loaned message");
16171621
return RMW_RET_ERROR;
16181622
}

rmw_cyclonedds_cpp/src/serdata.cpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ uint32_t sertype_rmw_hash(const struct ddsi_sertype * tpcmn)
730730
return h1 ^ h2;
731731
}
732732

733-
size_t sertype_get_serialized_size(const struct ddsi_sertype * d, const void * sample)
733+
static size_t sertype_get_serialized_size_impl(const struct ddsi_sertype * d, const void * sample)
734734
{
735735
const struct sertype_rmw * type = static_cast<const struct sertype_rmw *>(d);
736736
size_t serialized_size = 0;
@@ -750,16 +750,13 @@ size_t sertype_get_serialized_size(const struct ddsi_sertype * d, const void * s
750750
return serialized_size;
751751
}
752752

753-
bool sertype_serialize_into(
753+
static bool sertype_serialize_into_impl(
754754
const struct ddsi_sertype * d,
755755
const void * sample,
756-
void * dst_buffer,
757-
size_t dst_size)
756+
void * dst_buffer)
758757
{
759758
const struct sertype_rmw * type = static_cast<const struct sertype_rmw *>(d);
760759
try {
761-
// ignore destination size (assuming that the destination buffer is resized before correctly)
762-
static_cast<void>(dst_size);
763760
// ROS 2 doesn't support keys, so its all data (?)
764761
if (!type->is_request_header) {
765762
type->cdr_writer->serialize(dst_buffer, sample);
@@ -776,6 +773,53 @@ bool sertype_serialize_into(
776773
return true;
777774
}
778775

776+
#if CDDS_VERSION == CDDS_VERSION_0_10
777+
size_t sertype_get_serialized_size(const struct ddsi_sertype * d, const void * sample)
778+
{
779+
return sertype_get_serialized_size_impl(d, sample);
780+
}
781+
782+
bool sertype_serialize_into(
783+
const struct ddsi_sertype * d,
784+
const void * sample,
785+
void * dst_buffer,
786+
size_t dst_size)
787+
{
788+
static_cast<void>(dst_size);
789+
return sertype_serialize_into_impl(d, sample, dst_buffer);
790+
}
791+
#else
792+
dds_return_t sertype_get_serialized_size(
793+
const struct ddsi_sertype * d,
794+
enum ddsi_serdata_kind sdkind,
795+
const void * sample,
796+
size_t * size,
797+
uint16_t * enc_identifier)
798+
{
799+
static_cast<void>(sdkind);
800+
size_t serialized_size = sertype_get_serialized_size_impl(d, sample);
801+
// encoding identifier is always plain CDR for this serializer
802+
*enc_identifier = (native_endian() == endian::little) ? DDSI_RTPS_CDR_LE : DDSI_RTPS_CDR_BE;
803+
// Cyclone's including or excluding the CDR encoding header in the various situations is
804+
// painfully inconsistent ...
805+
assert (serialized_size >= 4);
806+
*size = serialized_size - 4;
807+
return DDS_RETCODE_OK;
808+
}
809+
810+
bool sertype_serialize_into(
811+
const struct ddsi_sertype * d,
812+
enum ddsi_serdata_kind sdkind,
813+
const void * sample,
814+
void * dst_buffer,
815+
size_t dst_size)
816+
{
817+
static_cast<void>(sdkind);
818+
static_cast<void>(dst_size);
819+
return sertype_serialize_into_impl(d, sample, dst_buffer);
820+
}
821+
#endif
822+
779823
#if DDS_HAS_TYPELIB
780824
static ddsi_typeid_t * sertype_rmw_typeid(const struct ddsi_sertype * d, ddsi_typeid_kind_t kind)
781825
{

0 commit comments

Comments
 (0)