PixaRuntimePluginRegistryStats.decode constructor

PixaRuntimePluginRegistryStats.decode(
  1. Uint8List bytes
)

Decodes the internal PXM2 binary diagnostics payload.

Implementation

factory PixaRuntimePluginRegistryStats.decode(Uint8List bytes) {
  if (bytes.length > _pxm2MaxPayloadBytes) {
    throw const FormatException('PXM2 payload exceeds byte limit.');
  }
  final PixaRuntimeBinaryReader reader = PixaRuntimeBinaryReader(bytes);
  if (!reader.readMagic(
    _pxm2Magic[0],
    _pxm2Magic[1],
    _pxm2Magic[2],
    _pxm2Magic[3],
  )) {
    throw const FormatException('Invalid runtime plugin stats payload.');
  }
  final int modules = reader.readUint64();
  if (modules > _pxm2MaxModules) {
    throw const FormatException('PXM2 module count exceeds item limit.');
  }
  final PixaRuntimePluginRegistryStats stats = PixaRuntimePluginRegistryStats(
    modules: modules,
    builtInModules: reader.readUint64(),
    hostLinkedModules: reader.readUint64(),
    assetModules: reader.readUint64(),
    linkableModules: reader.readUint64(),
    fetchers: reader.readUint64(),
    videoFrameFetchers: reader.readUint64(),
    videoFrameEncodedOutputFetchers: reader.readUint64(),
    decoders: reader.readUint64(),
    processors: reader.readUint64(),
    cacheStores: reader.readUint64(),
    videoFrameSourceKinds: _readStringList(reader),
    videoFrameOutputMimeTypes: _readStringList(reader),
    moduleSnapshots: _readPluginModuleSnapshots(reader),
  );
  if (stats.moduleSnapshots.length != stats.modules) {
    throw const FormatException(
      'Runtime plugin module count does not match its snapshots.',
    );
  }
  if (!reader.isComplete) {
    throw const FormatException('Trailing runtime plugin stats bytes.');
  }
  return stats;
}