my DDS writer works fine when write small-size data. However, when I send large-size data with DDS writer, I got this error at runtime.
DDS_OctetsPlugin_serialize:value length cannot be greater than alloc size
PRESWriterHistoryDriver_initializeSample:serialize sample error in topic 'xxxxx' with type 'DDS::Octets' and encapsulationId 1
WriterHistoryMemoryPlugin_addEntryToSession:!initialize sample
WriterHistoryMemoryPlugin_addEntryToSessions:!add entry to first session
WriterHistoryMemoryPlugin_getEntry:!add virtual sample to sessions
WriterHistoryMemoryPlugin_addSample:!get entry
PRESWriterHistoryDriver_addWrite:!add_sample in topic 'xxxxx'
PRESPsWriter_writeInternal:!collator addWrite
terminate called after throwing an instance of 'dds::core::Error'
what():
DDS_OctetsPlugin_serialize:value length cannot be greater than alloc size
PRESWriterHistoryDriver_initializeSample:serialize sample error in topic 'Pandar20P_BB_UdpPacketList' with type 'DDS::Octets' and encapsulationId 1
WriterHistoryMemoryPlugin_addEntryToSession:!initialize sample
WriterHistoryMemoryPlugin_addEntryToSessions:!add entry to first session
WriterHistoryMemoryPlugin_getEntry:!add virtual sample to sessions
WriterHistoryMemoryPlugin_addSample:!get entry
PRESWriterHistoryDriver_addWrite:!add_sample in topic 'xxxxx'
PRESPsWriter_writeInternal:!collator addWrite
Following is my code:
auto dp = dds::domain::DomainParticipant(1);
auto topic = dds::topic::Topic<dds::core::BytesTopicType>(dp, channelName);
auto qos = dds::core::QosProvider::Default().datawriter_qos();
writer = dds::pub::DataWriter<dds::core::BytesTopicType>(Publisher(dp), topic, qos, &writerListener);
writer.write(data);
Any help is appreciated.
It looks like you are using RTI's DDS and the type you selected for your Topic is one of the built-in types. The Connext User's Manual has a section 3.2.7 Managing Memory for Built-in Types which explains that the middleware pre-allocates its memory for your data samples according to a pre-defined maximum length. By default that is 2048
bytes for the octets type that you are using and your sequence seems to have exceeded that length. As explained in the manual, you can increase that value by setting the associated QoS property. For the C++ API specifically, you can find the instructions in the Built-in types section.
At the bottom of that section, the User's Manual also explains what to do in the case that you do not know in advance what your maximum size is going to be. For that situation, you can configure the built-in type to be unbounded by setting the property dds.builtin_type.*.alloc_size
to the maximum value of a 32-bit signed integer: 2,147,483,647
. Be aware that may result in dynamic allocation of memory, which may not be desirable.
By the way, are you sure that you want to use the BytesTopicType
and not the KeyedBytesTopicType
? In many cases, it is beneficial to have a key value identifying your sequence of bytes. The keyed version of the type allows you to maintain the value for several of them simultaneously by giving them different key values.