Appearance
ByteBuffer abstract final
abstract final class ByteBufferA sequence of bytes underlying a typed data object.
Used to process large quantities of binary or numerical data more efficiently using a typed view.
It is a compile-time error for a class to attempt to extend or implement ByteBuffer.
Available Extensions
Properties
hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
dart
external int get hashCode;lengthInBytes no setter
int get lengthInBytesThe length of this byte buffer, in bytes.
Implementation
dart
int get lengthInBytes;runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
dart
external Type get runtimeType;toJS extension no setter
JSArrayBuffer get toJSConverts this ByteBuffer to a JSArrayBuffer by either casting, unwrapping, or cloning the ByteBuffer.
Throws if the ByteBuffer is backed by a JS SharedArrayBuffer.
INFO
Depending on whether code is compiled to JavaScript or Wasm, this conversion will have different semantics.
When compiling to JavaScript, ByteBuffers are either ArrayBuffers or SharedArrayBuffers so this will just check the type and cast, throwing if it's a SharedArrayBuffer.
When compiling to Wasm, this ByteBuffer is a wrapper around an ArrayBuffer if it was converted via JSArrayBufferToByteBuffer.toDart. If it is a wrapper, this getter unwraps it and either returns the ArrayBuffer or throws if the unwrapped buffer was a SharedArrayBuffer. If it's instantiated in Dart, this getter clones this ByteBuffer's values into a new JSArrayBuffer.
Avoid assuming that modifications to this ByteBuffer will affect the returned JSArrayBuffer and vice versa on all compilers unless it was first converted via JSArrayBufferToByteBuffer.toDart.
Available on ByteBuffer, provided by the ByteBufferToJSArrayBuffer extension
Implementation
dart
external JSArrayBuffer get toJS;Methods
asByteData()
Creates a ByteData view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the ByteData will also change the buffer, and vice versa.
The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.
The start index and length must describe a valid range of the buffer:
offsetInBytesmust not be negative,lengthmust not be negative, andoffsetInBytes + lengthmust not be greater than lengthInBytes.
Implementation
dart
ByteData asByteData([int offsetInBytes = 0, int? length]);asFloat32List()
Float32List asFloat32List([int offsetInBytes = 0, int? length])Creates a Float32List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Float32List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.
The start index and length must describe a valid 32-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by four,lengthmust not be negative, andoffsetInBytes + length * 4must not be greater than lengthInBytes.
Implementation
dart
Float32List asFloat32List([int offsetInBytes = 0, int? length]);asFloat32x4List()
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length])Creates a Float32x4List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Float32x4List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.
The start index and length must describe a valid 128-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by sixteen,lengthmust not be negative, andoffsetInBytes + length * 16must not be greater than lengthInBytes.
Implementation
dart
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]);asFloat64List()
Float64List asFloat64List([int offsetInBytes = 0, int? length])Creates a Float64List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Float64List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.
The start index and length must describe a valid 64-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by eight,lengthmust not be negative, andoffsetInBytes + length * 8must not be greater than lengthInBytes.
Implementation
dart
Float64List asFloat64List([int offsetInBytes = 0, int? length]);asFloat64x2List()
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length])Creates a Float64x2List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Float64x2List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.
The start index and length must describe a valid 128-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by sixteen,lengthmust not be negative, andoffsetInBytes + length * 16must not be greater than lengthInBytes.
Implementation
dart
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]);asInt16List()
Creates a Int16List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Int16List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 16-bit aligned, and contains length 16-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not even, the last byte can't be part of the view.
The start index and length must describe a valid 16-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by two,lengthmust not be negative, andoffsetInBytes + length * 2must not be greater than lengthInBytes.
Implementation
dart
Int16List asInt16List([int offsetInBytes = 0, int? length]);asInt32List()
Creates a Int32List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Int32List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.
The start index and length must describe a valid 32-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by four,lengthmust not be negative, andoffsetInBytes + length * 4must not be greater than lengthInBytes.
Implementation
dart
Int32List asInt32List([int offsetInBytes = 0, int? length]);asInt32x4List()
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length])Creates a Int32x4List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Int32x4List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 128-bit aligned, and contains length 128-bit integers. If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by 16, the last bytes can't be part of the view.
The start index and length must describe a valid 128-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by sixteen,lengthmust not be negative, andoffsetInBytes + length * 16must not be greater than lengthInBytes.
Implementation
dart
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]);asInt64List()
Creates a Int64List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Int64List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.
The start index and length must describe a valid 64-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by eight,lengthmust not be negative, andoffsetInBytes + length * 8must not be greater than lengthInBytes.
Implementation
dart
Int64List asInt64List([int offsetInBytes = 0, int? length]);asInt8List()
Creates a Int8List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Int8List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.
The start index and length must describe a valid range of the buffer:
offsetInBytesmust not be negative,lengthmust not be negative, andoffsetInBytes + lengthmust not be greater than lengthInBytes.
Implementation
dart
Int8List asInt8List([int offsetInBytes = 0, int? length]);asUint16List()
Uint16List asUint16List([int offsetInBytes = 0, int? length])Creates a Uint16List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Uint16List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 16-bit aligned, and contains length 16-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not even, the last byte can't be part of the view.
The start index and length must describe a valid 16-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by two,lengthmust not be negative, andoffsetInBytes + length * 2must not be greater than lengthInBytes.
Implementation
dart
Uint16List asUint16List([int offsetInBytes = 0, int? length]);asUint32List()
Uint32List asUint32List([int offsetInBytes = 0, int? length])Creates a Uint32List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Uint32List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 32-bit aligned, and contains length 32-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by four, the last bytes can't be part of the view.
The start index and length must describe a valid 32-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by four,lengthmust not be negative, andoffsetInBytes + length * 4must not be greater than lengthInBytes.
Implementation
dart
Uint32List asUint32List([int offsetInBytes = 0, int? length]);asUint64List()
Uint64List asUint64List([int offsetInBytes = 0, int? length])Creates a Uint64List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Uint64List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes, which must be 64-bit aligned, and contains length 64-bit integers with the same endianness as the host (Endian.host). If length is omitted, the range extends as far towards the end of the buffer as possible - if lengthInBytes is not divisible by eight, the last bytes can't be part of the view.
The start index and length must describe a valid 64-bit aligned range of the buffer:
offsetInBytesmust not be negative,offsetInBytesmust be divisible by eight,lengthmust not be negative, andoffsetInBytes + length * 8must not be greater than lengthInBytes.
Implementation
dart
Uint64List asUint64List([int offsetInBytes = 0, int? length]);asUint8ClampedList()
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length])Creates a Uint8ClampedList view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Uint8ClampedList will also change the buffer, and vice versa.
The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.
The start index and length must describe a valid range of the buffer:
offsetInBytesmust not be negative,lengthmust not be negative, andoffsetInBytes + lengthmust not be greater than lengthInBytes.
Implementation
dart
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]);asUint8List()
Creates a Uint8List view of a region of this byte buffer.
The view is backed by the bytes of this byte buffer. Any changes made to the Uint8List will also change the buffer, and vice versa.
The viewed region start at offsetInBytes and contains length bytes. If length is omitted, the range extends to the end of the buffer.
The start index and length must describe a valid range of the buffer:
offsetInBytesmust not be negative,lengthmust not be negative, andoffsetInBytes + lengthmust not be greater than lengthInBytes.
Implementation
dart
Uint8List asUint8List([int offsetInBytes = 0, int? length]);noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
dart
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);toString() inherited
String toString()A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Object.
Implementation
dart
external String toString();Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
dart
external bool operator ==(Object other);