class CameraStreamAdapter extends TypeAdapter<CameraServerData> {

  @Override
  public CameraServerData deserialize(byte[] buffer, int bufferPosition) {
    int cursor = bufferPosition;
    final String name = readString(buffer, cursor);
    cursor += name.length() + SIZE_OF_INT;
    final byte fileNum = buffer[cursor];
    cursor++;
    final short frameNum = readShort(buffer, cursor);
    cursor += SIZE_OF_SHORT;
    final int bandwidth = readInt(buffer, cursor);
    cursor += SIZE_OF_INT;
    final double fps = readShort(buffer, cursor) / 100.0;

    CameraStreamReader reader = readers.computeIfAbsent(name, __ -> new CameraStreamReader(__, getCurrentFile()));

    return new LazyCameraServerData(name, fileNum, frameNum, () -> {
      try {
        reader.setFileNumber(fileNum);
        return reader.readFrame(frameNum);
      } catch (IOException e) {
        log.log(Level.WARNING, "Could not read frame " + frameNum, e);
        return null;
      }
    }, fps, bandwidth);
  }

  public  CameraStreamAdapter();

}