Cache serialization info when CDRWriter is constructed (#80)

1. Make CDRWriter remember its top level struct value type
2. Populate the trivially serializable cache when CDRWriter is created instead of waiting until the first time a message is sent.
3. Speed up arrays/sequences of trivially serializable structs

Signed-off-by: Dan Rose <dan@digilabs.io>
This commit is contained in:
Dan Rose 2019-12-13 11:05:58 -05:00 committed by GitHub
parent c25f22e565
commit c0af9d898b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 114 deletions

View file

@ -172,18 +172,17 @@ static struct ddsi_serdata * serdata_rmw_from_sample(
if (kind != SDK_DATA) {
/* ROS2 doesn't do keys, so SDK_KEY is trivial */
} else if (!topic->is_request_header) {
size_t sz = rmw_cyclonedds_cpp::get_serialized_size(sample, topic->value_type.get());
size_t sz = topic->cdr_writer->get_serialized_size(sample);
d->resize(sz);
rmw_cyclonedds_cpp::serialize(d->data(), sample, topic->value_type.get());
topic->cdr_writer->serialize(d->data(), sample);
} else {
/* inject the service invocation header data into the CDR stream --
* I haven't checked how it is done in the official RMW implementations, so it is
* probably incompatible. */
auto wrap = *static_cast<const cdds_request_wrapper_t *>(sample);
size_t sz = rmw_cyclonedds_cpp::get_serialized_size(wrap, topic->value_type.get());
size_t sz = topic->cdr_writer->get_serialized_size(wrap);
d->resize(sz);
rmw_cyclonedds_cpp::serialize(d->data(), wrap, topic->value_type.get());
topic->cdr_writer->serialize(d->data(), wrap);
}
return d.release();
} catch (std::exception & e) {
@ -490,7 +489,7 @@ struct sertopic_rmw * create_sertopic(
st->type_support.typesupport_identifier_ = type_support_identifier;
st->type_support.type_support_ = type_support;
st->is_request_header = is_request_header;
st->value_type = std::move(message_type);
st->cdr_writer = rmw_cyclonedds_cpp::make_cdr_writer(std::move(message_type));
return st;
}