google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.56k stars 3.19k forks source link

Assertion `!nested' failed. #8219

Open palan1204 opened 5 months ago

palan1204 commented 5 months ago

I am getting Notnested assertion when i try to serialization of vector of vectors Here is my serialization code Not sure what went wrong.

const auto bufferSize = static_cast<uint32_t>(bufferEnd - bufferStart);
flatbuffers::FlatBufferBuilder builder;
bool isSerialised = false;

try
{
    const AABMessageNewBaseTablesNotification& msg = dynamic_cast<const AABMessageNewBaseTablesNotification&>(message);

    // Move the creation of sub-objects above the FlatBufferBuilder construction
    std::vector<flatbuffers::Offset<AAB::UpdatedBDTList>> updatedBDTListVector;
    const auto& updatedBDTList = msg.GetUpdatedBDTList();

    for (const auto& pair : updatedBDTList)
    {
        auto TableList = VectorToFlatBufferVector(pair.second, builder);
        auto ServiceName  = builder.CreateString(pair.first);
        updatedBDTListVector.push_back(AAB::CreateUpdatedBDTList(builder, ServiceName, TableList));
    }

    AAB::AABMessageNewBaseDataTablesNotificationBuilder messageBuilder(builder);
    messageBuilder.add_type(msg.Type());
    messageBuilder.add_version(msg.Version());
    messageBuilder.add_updatedBDTList(builder.CreateVector(updatedBDTListVector));

    auto messageOffset = messageBuilder.Finish();
    builder.Finish(messageOffset);

    auto size = builder.GetSize();
    messageSize = size;

    if (size <= bufferSize) {
        auto span = builder.GetBufferPointer();  // Use GetBufferPointer instead of GetBufferSpan
        std::copy(span, span + size, bufferStart);
        isSerialised = (size != 0);
    }
}
catch (const std::bad_cast&)
{
}

builder.Clear();
return isSerialised;

Thank you for submitting an issue!

Please make sure you include the names of the affected language(s), compiler version(s), operating system version(s), and FlatBuffers version(s) in your issue title.

This helps us get the correct maintainers to look at your issue. Here are examples of good titles:

Include other details as appropriate.

Thanks!