Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get correct set data #8331

Open
Chenmo128 opened this issue Jun 13, 2024 · 0 comments
Open

Unable to get correct set data #8331

Chenmo128 opened this issue Jun 13, 2024 · 0 comments

Comments

@Chenmo128
Copy link

I'm having an issue where the field values I get after deserialisation don't match the values I've set.
environments :[C++, gcc 9.3, aarch64, FlatBuffers:23.5.26]

Here is my code, you can see that I set: obstacles_builder.add_confScale(63246); but these two lines of code prints 0 instead:

 auto test = message->confScale(); //test
    std::cout << test << std::endl; 

I think it's the code I bolded that's the problem, because if I remove this code it prints correctly, but I don't understand why

my code:

void GetObstacles(flatbuffers::FlatBufferBuilder& builder, int obstacle_num) {
    HeaderBuilder header_builder(builder);
    header_builder.add_time_stamp(123456789);
    header_builder.add_frame_id(1);
    ObstaclesBuilder obstacles_builder(builder);
    obstacles_builder.add_header(header_builder.Finish());
    obstacles_builder.add_confScale(63246);

    **std::vector<flatbuffers::Offset<Obstacle>> obstacles_vector;
    for(int i = 0; i < obstacle_num; ++i) {
        ObstacleBuilder obstacle_builder(builder);
        obstacle_builder.add_id(i);
        ......
        obstacles_vector.push_back(obstacle_builder.Finish());
    }

    auto obstacles_offset = builder.CreateVector(obstacles_vector);
    obstacles_builder.add_obstacle(obstacles_offset);**

    auto obstacles = obstacles_builder.Finish();
    builder.Finish(obstacles);

    size_t size = builder.GetSize();
    std::vector<uint8_t> serialized_data(size);
    std::memcpy(serialized_data.data(), builder.GetBufferPointer(), size);

    const Obstacles* message = 
            flatbuffers::GetRoot<Obstacles>(serialized_data.data());
    auto test = message->confScale(); //test
    std::cout << test << std::endl;
}

my .fbs file:

table Obstacles {
  header : Header;
  confScale : float;
  obstacle : [Obstacle];
   ....
}

table Obstacle {
  id : int;
  ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant