A fixed-length, random-access sequence of bytes that also provides random and unaligned access to the fixed-width integers and floating point numbers represented by those bytes. ByteData may be used to pack and unpack data from external sources (such as networks or files systems), and to process large quantities of numerical data more efficiently than would be possible with ordinary List implementations. ByteData can save space, by eliminating the need for object headers, and time, by eliminating the need for data copies. Finally, ByteData may be used to intentionally reinterpret the bytes representing one arithmetic type as another. For example this code fragment determine what 32-bit signed integer is represented by the bytes of a 32-bit floating point number:
var buffer = new Uint8List(8).buffer;
var bdata = new ByteData.view(buffer);
bdata.setFloat32(0, 3.04);
int huh = bdata.getInt32(0);
- Implements
Properties
- buffer → ByteBuffer
-
read-only, inherited
Returns the byte buffer associated with this object.
- elementSizeInBytes → int
-
read-only, inherited
Returns the number of bytes in the representation of each element in this list.
- lengthInBytes → int
-
read-only, inherited
Returns the length of this view, in bytes.
- offsetInBytes → int
-
read-only, inherited
Returns the offset in bytes into the underlying byte buffer of this view.
Constructors
- ByteData(int length)
-
Creates a ByteData of the specified length (in elements), all of whose elements are initially zero.
- ByteData.view(ByteBuffer buffer, [int offsetInBytes = 0, int length])
-
Creates an ByteData view of the specified region in the specified byte buffer. Changes in the ByteData will be visible in the byte buffer and vice versa. If the
offsetInBytes
index of the region is not specified, it defaults to zero (the first byte in the byte buffer). If the length is not specified, it defaults to null, which indicates that the view extends to the end of the byte buffer.…
Methods
-
getFloat32(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → double -
Returns the floating point number represented by the four bytes at the specified
byteOffset
in this object, in IEEE 754 single-precision binary floating-point format (binary32).… -
getFloat64(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → double -
Returns the floating point number represented by the eight bytes at the specified
byteOffset
in this object, in IEEE 754 double-precision binary floating-point format (binary64).… -
getInt16(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the (possibly negative) integer represented by the two bytes at the specified
byteOffset
in this object, in two's complement binary form. The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.… -
getInt32(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the (possibly negative) integer represented by the four bytes at the specified
byteOffset
in this object, in two's complement binary form. The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.… -
getInt64(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the (possibly negative) integer represented by the eight bytes at the specified
byteOffset
in this object, in two's complement binary form. The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.… -
getInt8(
int byteOffset) → int -
Returns the (possibly negative) integer represented by the byte at the specified
byteOffset
in this object, in two's complement binary representation. The return value will be between -128 and 127, inclusive.… -
getUint16(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the positive integer represented by the two bytes starting at the specified
byteOffset
in this object, in unsigned binary form. The return value will be between 0 and 2<sup>16</sup> - 1, inclusive.… -
getUint32(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the positive integer represented by the four bytes starting at the specified
byteOffset
in this object, in unsigned binary form. The return value will be between 0 and 2<sup>32</sup> - 1, inclusive.… -
getUint64(
int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) → int -
Returns the positive integer represented by the eight bytes starting at the specified
byteOffset
in this object, in unsigned binary form. The return value will be between 0 and 2<sup>64</sup> - 1, inclusive.… -
getUint8(
int byteOffset) → int -
Returns the positive integer represented by the byte at the specified
byteOffset
in this object, in unsigned binary form. The return value will be between 0 and 255, inclusive.… -
setFloat32(
int byteOffset, double value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the four bytes starting at the specified
byteOffset
in this object to the IEEE 754 single-precision binary floating-point (binary32) representation of the specifiedvalue
.… -
setFloat64(
int byteOffset, double value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the eight bytes starting at the specified
byteOffset
in this object to the IEEE 754 double-precision binary floating-point (binary64) representation of the specifiedvalue
.… -
setInt16(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the two bytes starting at the specified
byteOffset
in this object to the two's complement binary representation of the specifiedvalue
, which must fit in two bytes. In other words,value
must lie between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.… -
setInt32(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the four bytes starting at the specified
byteOffset
in this object to the two's complement binary representation of the specifiedvalue
, which must fit in four bytes. In other words,value
must lie between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.… -
setInt64(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the eight bytes starting at the specified
byteOffset
in this object to the two's complement binary representation of the specifiedvalue
, which must fit in eight bytes. In other words,value
must lie between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.… -
setInt8(
int byteOffset, int value) → void -
Sets the byte at the specified
byteOffset
in this object to the two's complement binary representation of the specifiedvalue
, which must fit in a single byte. In other words,value
must be between -128 and 127, inclusive.… -
setUint16(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the two bytes starting at the specified
byteOffset
in this object to the unsigned binary representation of the specifiedvalue
, which must fit in two bytes. in other words,value
must be between 0 and 2<sup>16</sup> - 1, inclusive.… -
setUint32(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the four bytes starting at the specified
byteOffset
in this object to the unsigned binary representation of the specifiedvalue
, which must fit in four bytes. in other words,value
must be between 0 and 2<sup>32</sup> - 1, inclusive.… -
setUint64(
int byteOffset, int value, [Endianness endian = Endianness.BIG_ENDIAN]) → void -
Sets the eight bytes starting at the specified
byteOffset
in this object to the unsigned binary representation of the specifiedvalue
, which must fit in eight bytes. in other words,value
must be between 0 and 2<sup>64</sup> - 1, inclusive.… -
setUint8(
int byteOffset, int value) → void -
Sets the byte at the specified
byteOffset
in this object to the unsigned binary representation of the specifiedvalue
, which must fit in a single byte. in other words,value
must be between 0 and 255, inclusive.…