class EventMessageDecoder implements MetadataDecoder {

  @SuppressWarnings("ByteBufferBackingArray")
  @Override
  public Metadata decode(MetadataInputBuffer inputBuffer) {
    ByteBuffer buffer = inputBuffer.data;
    byte[] data = buffer.array();
    int size = buffer.limit();
    ParsableByteArray emsgData = new ParsableByteArray(data, size);
    String schemeIdUri = Assertions.checkNotNull(emsgData.readNullTerminatedString());
    String value = Assertions.checkNotNull(emsgData.readNullTerminatedString());
    long timescale = emsgData.readUnsignedInt();
    long presentationTimeDelta = emsgData.readUnsignedInt();
    if (presentationTimeDelta != 0) {
      // We expect the source to have accounted for presentation_time_delta by adjusting the sample
      // timestamp and zeroing the field in the sample data. Log a warning if the field is non-zero.
      Log.w(TAG, "Ignoring non-zero presentation_time_delta: " + presentationTimeDelta);
    }
    long durationMs = Util.scaleLargeTimestamp(emsgData.readUnsignedInt(), 1000, timescale);
    long id = emsgData.readUnsignedInt();
    byte[] messageData = Arrays.copyOfRange(data, emsgData.getPosition(), size);
    return new Metadata(new EventMessage(schemeIdUri, value, durationMs, id, messageData));
  }

}