title: C++ - Unable to get prefixed uint16_t header
body: <p>Here is how I form up my message with FlatBuffers and how I send it over via Boost ASIO.</p>
  <pre><code>enum ServerOpcode : uint16_t{
      SMSG_AUTH_CONNECTION_RESPONSE                    = 0x001,
      SMSG_LOGIN_REQUEST                               = 0x002,
      SMSG_LOGIN_REQUEST_RESPONSE_TEST                 = 0xA99,
  };
  
  ServerOpcode opc;
  opc = ServerOpcode::SMSG_LOGIN_REQUEST_RESPONSE_TEST;
  
  flatbuffers::FlatBufferBuilder builder;
  auto email = builder.CreateString(&quot;test@abv.bg&quot;);
  auto password = builder.CreateString(&quot;passHerepassHerepassHerepassHereZzpa&quot;);
  auto loginRequest = Vibranium::CreateLoginRequest(builder,email,password);
  builder.FinishSizePrefixed(loginRequest);
  size_t size = builder.GetSize();
  uint8_t *buf = builder.GetBufferPointer();
  
  uint8_t *actualBuffer = new uint8_t[size + 2];
  actualBuffer[1] = (opc &gt;&gt; 8);
  actualBuffer[0] = (opc&amp;0xFF);
  memcpy(actualBuffer + 2, buf, size);
  
  
  boost::asio::write(s, boost::asio::buffer(actualBuffer,size + 2));
  </code></pre>
  <p>So what I basically want to achieve is to prepend a uint16_t header infront of the flatbuffers message.</p>
  <p>Here is the structure I use.</p>
  <pre><code>class Packet {
  public:
      Packet()
      {
      }
      static const int header_size = 2;
      static const int body_size_in_bytes = 4;
      std::vector&lt;std::byte&gt; header_buffer;
      std::vector&lt;std::byte&gt; size_buffer;
      uint16_t headerCode{0};
      uint32_t body_size{0};
      std::vector&lt;std::byte&gt; body_buffer;
      void PreparePacket(ServerOpcode serverOpcode, std::string message);
  };
  </code></pre>
  <p>And here is how I try to read the header on server side:</p>
  <pre><code>void Vibranium::Client::read_header() {
      auto self(shared_from_this());
      _packet.header_buffer.resize(_packet.header_size);
      boost::asio::async_read(socket,
      boost::asio::buffer(_packet.header_buffer.data(), _packet.header_size),
      [this, self](boost::system::error_code ec,std::size_t bytes_transferred)
      {
          if ((boost::asio::error::eof == ec) || (boost::asio::error::connection_reset == ec))
          {
              Disconnect();
          }
          else
          {
              std::memcpy(&amp;_packet.header_buffer, &amp;_packet.header_buffer[0], sizeof (_packet.headerCode));
              std::cout &lt;&lt; &quot;Header Code: &quot; &lt;&lt; _packet.headerCode &lt;&lt; std::endl;
              //read_size();
          }
      });
  }
  </code></pre>
  <p>Unfortunately this gives me output of:</p>
  <pre><code>Header Code: 0
  </code></pre>
  <p>Why and how can I get the prepended 2 byte header correctly? Where is my mistake and how can I fix it?</p>