title: java protobuf how to create ByteString from int
body: <p>I would like to use google protobuf in my project.</p>
  
  <p>The point is that I have to set first byte of very message because of underlying code which rejects or accepts the message based on the first byte and it does not know about protobuf.</p>
  
  <p>So this page says 
  <a href="https://developers.google.com/protocol-buffers/docs/proto#scalar" rel="nofollow">https://developers.google.com/protocol-buffers/docs/proto#scalar</a>
  that I have to use bytes field that corresponds to ByteString in Java.</p>
  
  <blockquote>
    <p>bytes May contain any arbitrary sequence of bytes.    string  ByteString</p>
  </blockquote>
  
  <p>But I do not know how to create ByteString from int value. I have tried this way:</p>
  
  <pre><code>ByteBuffer eventTypeBuffer = ByteBuffer.allocate(1);
  eventTypeBuffer.put(0x1c);
  ByteString eventType = ByteString.copyFrom(eventTypeBuffer);
  System.out.println(eventType.size() + " " + eventTypeBuffer.array().length);
  
  Header.Builder mh = Header.newBuilder();
  mh.setEventType(eventType);
  </code></pre>
  
  <p>Does not work properly and println gives 0 1</p>