RTI Connext Modern C++ API  Version 7.0.0
Topic-type serialization and deserialization

Provides functions to serialize and deserialize user data types to and from CDR format. More...

Functions

template<typename TopicType >
void rti::topic::from_cdr_buffer_no_alloc (TopicType &sample, const std::vector< char > &buffer)
 Deserializes a sample from a buffer of bytes in CDR format. More...
 
template<typename TopicType >
TopicType rti::topic::from_cdr_buffer (const std::vector< char > &buffer)
 Creates a sample by deserializing a buffer of bytes in CDR format. More...
 
template<typename TopicType >
std::vector< char > & rti::topic::to_cdr_buffer (std::vector< char > &buffer, const TopicType &sample, dds::core::policy::DataRepresentationId representation)
 Serializes a sample into a buffer of octets in CDR format. More...
 
template<typename TopicType >
std::vector< char > & rti::topic::to_cdr_buffer (std::vector< char > &buffer, const TopicType &sample)
 Serializes a sample into a buffer of octets in CDR format. More...
 

Detailed Description

Provides functions to serialize and deserialize user data types to and from CDR format.

DDS serializes topic-types into bytes in CDR format to transmit them between DataWriters and DataReaders. The functions rti::topic::to_cdr() and rti::topic::from_cdr() expose this functionality so applications can take advantage of this capability.

Function Documentation

◆ from_cdr_buffer_no_alloc()

template<typename TopicType >
void rti::topic::from_cdr_buffer_no_alloc ( TopicType &  sample,
const std::vector< char > &  buffer 
)

Deserializes a sample from a buffer of bytes in CDR format.

Precondition
sample must have been created by a previous call to from_cdr_buffer(). This precondition doesn't apply if TopicType is dds::core::xtypes::DynamicData

This function does the same as from_cdr_buffer() but it doesn't create a new sample. When deserializing multiple samples this operation will be more efficient.

Template Parameters
TopicTypeA valid topic-type. Valid types are IDL-generated types, the built-in types and dds::core::xtypes::DynamicData.
Parameters
sampleThe destination (see precondition)
bufferThe CDR buffer to deserialize

References rti::topic::from_cdr_buffer().

Referenced by rti::topic::from_cdr_buffer().

◆ from_cdr_buffer()

template<typename TopicType >
TopicType rti::topic::from_cdr_buffer ( const std::vector< char > &  buffer)

Creates a sample by deserializing a buffer of bytes in CDR format.

Template Parameters
TopicTypeA valid topic-type. Valid types are IDL-generated types, the built-in types and dds::core::xtypes::DynamicData.
Parameters
bufferThe CDR buffer to desrialize
Returns
The deserialized sample
See also
from_cdr_buffer_no_alloc()
Examples:
Foo.hpp.

References rti::topic::from_cdr_buffer_no_alloc().

Referenced by rti::topic::from_cdr_buffer_no_alloc().

◆ to_cdr_buffer() [1/2]

template<typename TopicType >
std::vector<char>& rti::topic::to_cdr_buffer ( std::vector< char > &  buffer,
const TopicType &  sample,
dds::core::policy::DataRepresentationId  representation 
)

Serializes a sample into a buffer of octets in CDR format.

Template Parameters
TopicTypeA valid topic-type. Valid types are IDL-generated types, the built-in types and dds::core::xtypes::DynamicData.
Parameters
bufferThe destination buffer. It will be resized to fit the serialized sample
sampleThe sample to serialize
representationThe representation to serialize the data into
Returns
A reference to the parameter buffer
Examples:
Foo.hpp.

References rti::topic::to_cdr_buffer().

◆ to_cdr_buffer() [2/2]

template<typename TopicType >
std::vector<char>& rti::topic::to_cdr_buffer ( std::vector< char > &  buffer,
const TopicType &  sample 
)

Serializes a sample into a buffer of octets in CDR format.

This overload uses dds::core::policy::DataRepresentationId::auto_id() as the data representation.

Referenced by rti::topic::to_cdr_buffer().