viewAt method

SodiumPointer<T> viewAt(
  1. int offset, [
  2. int? length
])

Returns a view of a subset of the memory the pointer is pointing to.

offset specifies the number of elements that should be skipped at the beginning, length controls how many elements are selected.

Important: This method works with elements, not bytes. This means, an offset of 1 on a SodiumPointer<Uint32> will advance one element, which is equivalent to sizeOf<Uint32>(), i.e. 4 bytes.

Implementation

SodiumPointer<T> viewAt(int offset, [int? length]) {
  if (offset > count) {
    throw ArgumentError.value(
      offset,
      'offset',
      'cannot be bigger than count ($count)',
    );
  }

  if (length != null && length > count - offset) {
    throw ArgumentError.value(
      length,
      'length',
      'cannot be bigger than count - offset (${count - offset})',
    );
  }

  return SodiumPointer._view(
    this,
    sodium,
    ptr.dynamicElementAt(offset),
    length ?? count - offset,
    _locked,
    _memoryProtection,
  );
}