Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Can't display vector of structs with flatbuffers in datalayer browser

Can't display vector of structs with flatbuffers in datalayer browser

CodeRat
Member

Hello, I have a problem when displaying vectors of structs in the datalayer browser, see screenshot. I get the error Incorrect type. Expected "object". (json undefined) [1:1-1:5].

Screenshot from 2023-12-07 10-44-04.png

 

auto snapDir = snapPath();
    std::filesystem::path dir = "compiled"; // Build environment: Compiled files are stored into that sub directory
    if (snapDir != nullptr)
    {
        dir = snapDir; // Snap environment: Compiled files are stored into the $SNAP directory
    }

    std::filesystem::path fileBfbs1 = dir / "PointClusters.bfbs";

    result = provider->registerType("types/vectorData/PointClusters", fileBfbs1);
    if (STATUS_FAILED(result))
    {
        std::cout << "WARN Register type 'types/vectorData/PointClusters' " << fileBfbs1 << " failed with: " << result.toString() << std::endl;
    }

    std::filesystem::path fileMddb = dir / "metadata.mddb";
    result = provider->registerType("datalayer", fileMddb);
    if (STATUS_FAILED(result))
    {
        std::cout << "WARN Register " << fileBfbs1 << " failed with: " << result.toString() << std::endl;
    }

    result = provider->registerNode("/flatbuffers/meinPointCluster", m_locatorProviderNode);
    
    flatbuffers::FlatBufferBuilder builder1;
    
    auto flatbuffersPointClusters1 = binaryVectors::CreatePointClusters(builder1, 43.0, 4.0, 555.0, 4, 10);
    auto flatbuffersPointClusters2 = binaryVectors::CreatePointClusters(builder1, 44.0, 4.0, 555.0, 4, 10);
    auto flatbuffersPointClusters3 = binaryVectors::CreatePointClusters(builder1, 45.0, 4.0, 555.0, 4, 10);
    
    std::vector<flatbuffers::Offset<binaryVectors::PointClusters>> PointClusterVector;
    PointClusterVector.push_back(flatbuffersPointClusters1);
    PointClusterVector.push_back(flatbuffersPointClusters2);
    PointClusterVector.push_back(flatbuffersPointClusters3);
    
    auto pointClusterFinished = builder1.CreateVector(PointClusterVector);
    std::vector<flatbuffers::Offset<binaryVectors::Pose2D>> Pose2DVector;
    
    builder1.Finish(pointClusterFinished);
    
    meinPointCluster.shareFlatbuffers(builder1);

 

 Is displaying vectors of structs supported in the datalayer browser web ui?

2 REPLIES 2

nickH
Community Moderator
Community Moderator

Hi @CodeRat 

I made some changes to the C++ sample datalayer.register.node and tested the FlatBuffer schema you sent in your post. 

I managed to provide the FlatBuffer in the Data Layer with these lines:

// Register a node as flatbuffer value
  flatbuffers::FlatBufferBuilder builder;
  std::vector<flatbuffers::Offset<vectorPointClusters::PointClusters>> vecPointClusters;
  auto actPointClusters = vectorPointClusters::CreatePointClusters(builder, 43.0, 4.0, 555.0, 4, 10);
  vecPointClusters.push_back(actPointClusters);
  auto actPointClusters2 = vectorPointClusters::CreatePointClusters(builder, 2.0, 6.0, 222.0, 6, 7);
  vecPointClusters.push_back(actPointClusters2);
  auto pointClusterVec = builder.CreateVector(vecPointClusters);
  vectorPointClusters::PointClusterVecBuilder vecClusters(builder);
  vecClusters.add_pointcluster_vec(pointClusterVec);
  auto flattbufferFinished = vecClusters.Finish();
  builder.Finish(flattbufferFinished);
  
  comm::datalayer::Variant myFlatbuffer;
  myFlatbuffer.shareFlatbuffers(builder);
  std::cout << "INFO Register node 'sdk-cpp-registernode/myFlatbuffer'  " << std::endl;
  result = provider->registerNode("sdk-cpp-registernode/myFlatbuffer", new MyProviderNode(myFlatbuffer));

Thats what it looks like in the Data Layer: 

FlatBuffer in Data LayerFlatBuffer in Data Layer

 

I attached also the full project here, so you can test it yourself. 

Best regards, 

Nick

Thank you for the reply :). I have successfully implemented it in my version, howerver I was stuck for a long time figuring out why my nodes didn't have any values. It seems like the folder in /types has to have the same name as the fbs file.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist