asListView<TList extends List<num> > method
Returns a dart list view on the pointer.
The resulting list operates on the same memory. This means if you modify elements of the list, the data the pointer points to changes as well. You can either get a reference to the whole pointer, or use viewAt to select a specific portion of the pointer. All returned lists are guaranteed to also implement the TypedData interface.
Note: As the returned list is a reference, calling SodiumPointer.dispose is not allowed as long as you still use the returned list. If you still dispose of the pointer, any try to access the data will crash your application.
Implementation
TList asListView<TList extends List<num>>({
bool owned = false,
}) {
if (owned) {
memoryProtection = MemoryProtection.readWrite;
// ignore: unused_result
detach();
}
final signage = _StaticallyTypedSizeOf.signage<T>();
switch (signage) {
case _Signage.signed:
if (elementSize <= sizeOf<Int8>()) {
return ptr.cast<Int8>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Int16>()) {
return ptr.cast<Int16>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Int32>()) {
return ptr.cast<Int32>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Int64>()) {
return ptr.cast<Int64>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
}
case _Signage.unsigned:
if (elementSize <= sizeOf<Uint8>()) {
return ptr.cast<Uint8>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Uint16>()) {
return ptr.cast<Uint16>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Uint32>()) {
return ptr.cast<Uint32>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Uint64>()) {
return ptr.cast<Uint64>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
}
case _Signage.float:
if (elementSize <= sizeOf<Float>()) {
return ptr.cast<Float>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
} else if (elementSize <= sizeOf<Double>()) {
return ptr.cast<Double>().asTypedList(
count,
finalizer: owned ? sodium.sodium_freePtr : null,
) as TList;
}
}
// coverage:ignore-start
throw UnsupportedError(
'Cannot create a list view for a pointer of type $T',
);
// coverage:ignore-end
}