发送大尺寸数据导致`DDS_OctetsPlugin_serialize:value length cannot be greater than alloc size`

sending data with large size cause `DDS_OctetsPlugin_serialize:value length cannot be greater than alloc size`

我的 DDS writer 在写入小数据时工作正常。但是,当我用DDS writer发送大数据时,在运行时出现了这个错误。

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

以下是我的代码:

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);

感谢任何帮助。

看起来您正在使用 RTI 的 DDS,并且您为主题选择的类型是 built-in 类型之一。 Connext 用户手册有一节 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 节。

在该部分的底部,用户手册还解释了在您事先不知道最大尺寸是多少的情况下该怎么做。对于这种情况,您可以通过将 属性 dds.builtin_type.*.alloc_size 设置为 32 位有符号整数的最大值来将 built-in 类型配置为无界:2,147,483,647。请注意,这可能会导致内存的动态分配,这可能是不可取的。

顺便问一下,您确定要使用 BytesTopicType 而不是 KeyedBytesTopicType 吗?在许多情况下,使用一个键值来标识您的字节序列是有益的。该类型的键控版本允许您通过为它们提供不同的键值来同时维护其中几个的值。