asBytes method

ByteBuffer asBytes()

Converts the array to a ByteBuffer.

Returns a ByteBuffer containing the array data.

Implementation

ByteBuffer asBytes() {
  const size = 10; // Fixed size for now, can be made dynamic later
  final buffer = calloc<Int32>(size);
  for (var i = 0; i < size; i++) {
    buffer[i] = this[i];
  }
  final bytes = buffer.cast<Uint8>().asTypedList(size * sizeOf<Int32>());
  final result = bytes.buffer;
  calloc.free(buffer);
  return result;
}