Here is my code:
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);
std::cout << "Size of buff before memcpy" << buffer.size() << std::endl;
memcpy(&buffer+size, &buf, size);
std::cout << "Size of buff after memcpy" << buffer.size() << std::endl;
The output when I run this code gives me:
Size of buff before memcpy16
Size of buff after memcpy16
That means I haven't copied buf
into buffer
. Why is that? How can I unify header
, size
and buf
all in one std::array<char>
?
I want to do that because I want to send them all three in specific sequence with Boost ASIO.