class EventMessageEncoder {

  @Nullable
  public byte[] encode(EventMessage eventMessage) {
    byteArrayOutputStream.reset();
    try {
      writeNullTerminatedString(dataOutputStream, eventMessage.schemeIdUri);
      String nonNullValue = eventMessage.value != null ? eventMessage.value : "";
      writeNullTerminatedString(dataOutputStream, nonNullValue);
      writeUnsignedInt(dataOutputStream, 1000); // timescale
      writeUnsignedInt(dataOutputStream, 0); // presentation_time_delta
      writeUnsignedInt(dataOutputStream, eventMessage.durationMs);
      writeUnsignedInt(dataOutputStream, eventMessage.id);
      dataOutputStream.write(eventMessage.messageData);
      dataOutputStream.flush();
      return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
      // Should never happen.
      throw new RuntimeException(e);
    }
  }

  public  EventMessageEncoder();

}