contentShardsNear method

List<int> contentShardsNear({
  1. required int sessionId,
  2. required String href,
})

Every content shard id, ordered for supplying ahead of need from the chapter at href; empty for a session opened from an archive.

Implementation

List<int> contentShardsNear({required int sessionId, required String href}) {
  _validateId(sessionId, 'session id');
  final hrefBytes = Uint8List.fromList(utf8.encode(href));
  if (hrefBytes.isEmpty || hrefBytes.length > ritoMaxStringBytes) {
    throw ArgumentError.value(
      href,
      'href',
      'must be non-empty protocol UTF-8',
    );
  }
  final hrefInput = _copyInput(hrefBytes);
  final shardsOut = calloc<_RitoOwnedBuffer>();
  final errorOut = calloc<_RitoOwnedBuffer>();
  try {
    final status = _contentShardsNear(
      sessionId,
      hrefInput,
      hrefBytes.length,
      shardsOut,
      errorOut,
    );
    if (status != 0) {
      throw _nativeError(status, errorOut);
    }
    final bytes = _copyOutput(shardsOut, 'content shards');
    final view = ByteData.sublistView(bytes);
    return <int>[
      for (var offset = 0; offset + 4 <= bytes.length; offset += 4)
        view.getUint32(offset, Endian.little),
    ];
  } finally {
    _bufferFree(shardsOut);
    _bufferFree(errorOut);
    calloc
      ..free(shardsOut)
      ..free(errorOut)
      ..free(hrefInput);
  }
}