asCopy<T extends TypedDataList> method

  1. @override
T asCopy<T extends TypedDataList>(
  1. int length
)
override

Copies length bytes, viewed as T.

T must be a concrete TypedDataList type: Uint8List, Int32List, Float32List, etc. Throws if T isn't one of those.

Implementation

@override
T asCopy<T extends TypedDataList>(int length) {
  MemoryDebug.checkPointer(this, 'to', T, length);
  return switch (T) {
    const (Uint8List) => Uint8List.fromList(_ptr.cast<Uint8>().asTypedList(length)) as T,
    const (Int8List) => Int8List.fromList(_ptr.cast<Int8>().asTypedList(length)) as T,
    const (Uint16List) => Uint16List.fromList(_ptr.cast<Uint16>().asTypedList(length)) as T,
    const (Int16List) => Int16List.fromList(_ptr.cast<Int16>().asTypedList(length)) as T,
    const (Uint32List) => Uint32List.fromList(_ptr.cast<Uint32>().asTypedList(length)) as T,
    const (Int32List) => Int32List.fromList(_ptr.cast<Int32>().asTypedList(length)) as T,
    const (Uint64List) => Uint64List.fromList(_ptr.cast<Uint64>().asTypedList(length)) as T,
    const (Int64List) => Int64List.fromList(_ptr.cast<Int64>().asTypedList(length)) as T,
    const (Float32List) => Float32List.fromList(_ptr.cast<Float>().asTypedList(length)) as T,
    const (Float64List) => Float64List.fromList(_ptr.cast<Double>().asTypedList(length)) as T,
    _ => throw UnsupportedError('NativeMemoryPointer.to<$T> not implemented'),
  };
}