Bytes class final

Immutable view over [offset, offset + length) of a Uint8List.

Implemented types
Available extensions

Constructors

Bytes.copyOf(Uint8List data, [int start = 0, int? end])
Copies a range of data.
factory
Bytes.fromByteBuffer(ByteBuffer buffer)
factory
Bytes.fromByteData(ByteData data)
Shares the underlying buffer of data (zero copy).
factory
Bytes.fromBytesLike(BytesLike data)
Zero-copy conversion from a BytesLike implementation.
factory
Bytes.fromList(List<int> data)
Copies data into a new buffer.
factory
Bytes.fromString(String value)
factory
Bytes.fromTypedData(TypedData data)
Zero-copy view over any Dart TypedData.
factory
Bytes.fromUint8List(Uint8List data)
Wraps data without copying. The caller must not mutate data while this view is alive.
factory
Bytes.view(Uint8List data, [int offsetInBytes = 0, int? length])
Wraps a Uint8List view starting at offsetInBytes.
factory

Properties

hashCode → int
The hash code for this object.
no setteroverride
isEmpty → bool
no setter
isNotEmpty → bool
no setter
length → int
Number of bytes in the view.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

asByteData() → ByteData
Zero-copy ByteData view.
asUint8List() → Uint8List
Zero-copy mutable view. Mutating it mutates the underlying buffer.
override
compareTo(Bytes other) → int
Lexicographic comparison.
override
copyTo(Uint8List dst, [int start = 0]) → void
Copies this view into dst starting at start.
getFloat32(int index, {Endian endian = Endian.big}) → double
getFloat32Unchecked(int index, {Endian endian = Endian.big}) → double
Reads a float32 without a bounds check.
getFloat64(int index, {Endian endian = Endian.big}) → double
getFloat64Unchecked(int index, {Endian endian = Endian.big}) → double
Reads a float64 without a bounds check.
getUint16(int index, {Endian endian = Endian.big}) → int
getUint16Unchecked(int index, {Endian endian = Endian.big}) → int
Reads two bytes without a bounds check.
getUint32(int index, {Endian endian = Endian.big}) → int
getUint32Unchecked(int index, {Endian endian = Endian.big}) → int
Reads four bytes without a bounds check.
getUint64(int index, {Endian endian = Endian.big}) → Uint64
getUint64Unchecked(int index, {Endian endian = Endian.big}) → Uint64
Reads eight bytes without a bounds check.
getUint8(int index) → int
getUint8Unchecked(int index) → int
Reads one byte without a bounds check.
indexOf(int value, [int start = 0, int? end]) → int
Returns the first index of value in [start, end), or -1.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
slice(int start, [int? end]) → Bytes
O(1) slice. start and end are relative to this view.
sublist(int start, [int? end]) → Bytes
Alias for slice.
toBytes() → Bytes

Available on BytesLike, provided by the BytesLikeBytes extension

Zero-copy conversion; returns the same instance when this is already a Bytes.
toString() → String
A string representation of this object.
override
toUint8List() → Uint8List
Explicit copy (Rust's to_vec).

Operators

operator ==(Object other) → bool
Content equality (O(n)).
override
operator [](int index) → int
Reads one byte.

Static Properties

empty → Bytes
An empty view (no allocation).
final