title: How to represent data in one byte array using Byte Buffer?
body: <p>I have my below layout in which I need to represent my data and then finally I need to make one byte array out of that.</p>
  
  <pre><code>// below is my data layout -
  // data key type which is 1 byte
  // data key len which is 1 byte
  // data key (variable size which is a key_len)
  // timestamp (sizeof uint64_t)
  // data size (sizeof uint16_t)
  // data (variable size = data size)
  </code></pre>
  
  <p>So I started like this but I am having some confusion so got stuck - </p>
  
  <pre><code>// data layout
  byte dataKeyType = 101;
  byte dataKeyLength = 3;
  
  // not sure how to represent key here
  
  long timestamp = System.currentTimeMillis(); // which is 64 bit
  short dataSize = 320; // what does this mean? it means size of data is 320 bytes?
  
  // and now confuse as well how to represent data here, we can have any string data which can be converted to bytes
  
  
  // and then make final byte array out of that
  </code></pre>
  
  <p>How do I represent this in one byte array using Byte Buffer? Any simple example will help me to understand better.</p>