I am using FlatBuffers & Boost ASIO
I want to form a message with the following sequence:
- uint16_t Header identifier. (fixed size message)
- size_t body size <- so the reading part can know how long is the message that it needs to read. (fixed size message)
- Flatbuffers object. (dynamic size message, size of which is sent at 2)
So for the first two here is how I combine them to be sent:
size_t const header_length = 8;
size_t const body_size_b = 8;
ServerOpcode opc;
opc = ServerOpcode::SMSG_LOGIN_REQUEST_RESPONSE_TEST;
std::string header = std::to_string(opc);
flatbuffers::FlatBufferBuilder builder;
auto name = builder.CreateString("Orc MONSTER");
auto accountRole = Vibranium::CreateAccountRole_Packet(builder,1,name);
builder.Finish(accountRole);
size_t size = builder.GetSize();
uint8_t *buf = builder.GetBufferPointer();
std::array<char, header_length + body_size_b> buffer{};
std::copy(header.begin(), header.end(), buffer.begin());
std::copy(std::to_string(size).begin(), std::to_string(size).end(), buffer.begin() + header_length);
// How can I add builder here at third place ?
boost::asio::write(s, boost::asio::buffer(buffer,sizeof(buffer)));
I don't know how to append the flatbuffers buffer after the first two.
My question is:
How can I unify all three in sequence and send them in one boost::asio::write
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…