supplyShard method

int supplyShard({
  1. required int sessionId,
  2. required Uint8List shardBytes,
  3. Uint8List? key,
})

Hands an open reader one content shard; returns its id.

Implementation

int supplyShard({
  required int sessionId,
  required Uint8List shardBytes,
  Uint8List? key,
}) {
  _validateId(sessionId, 'sessionId');
  _validateInput(shardBytes, 512 * 1024 * 1024, 'shard');
  _validateShardKey(key);
  final shard = _copyInput(shardBytes);
  final keyPointer = _copyInput(key ?? Uint8List(0));
  final shardIdOut = calloc<Uint32>();
  final errorOut = calloc<_RitoOwnedBuffer>();
  try {
    final status = _supplyShard(
      sessionId,
      shard,
      shardBytes.length,
      keyPointer,
      key?.length ?? 0,
      shardIdOut,
      errorOut,
    );
    if (status != 0) {
      throw _nativeError(status, errorOut);
    }
    return shardIdOut.value;
  } finally {
    _bufferFree(errorOut);
    calloc
      ..free(errorOut)
      ..free(shardIdOut)
      ..free(shard)
      ..free(keyPointer);
  }
}