ReadWriteData extension
Extension on byte buffers, allowing to read and write pieces of the buffers as specific data types (numbers, strings, etc.).
Please note, that all offsets in reading and writing methods do not have to be aligned, i.e. for an N-byte numeric type, the offset doesn't need to be a multiplu of N. However, if it is, the methods are more efficient, as they can take advantage of typed_data routines (otherwise a byte-wise copying between native and Dart memory takes place).
Example:
final Pointer<Uint8> buf = malloc<Uint8>(50);
buf.setAllBytes(50, 0); // zeroes the buffer
buf.writeInt16(0, 100);
buf.writeInt16(2, 100);
buf.writeString(4, "Hello!");
final s = buf.readString(4);
final i16 = buf.readInt16(2);
// this is also possible, but will result in garbage:
final i32 = buf.readInt32(0);
Methods
-
readDouble(
int offset) → double -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as Double (64-bit) value. -
readFloat(
int offset) → double -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as Float (32-bit) value. -
readInt16(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Int16 value. -
readInt32(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Int32 value. -
readInt64(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Int64 value. -
readInt8(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Int8 value. -
readString(
int offset, [int? byteCnt, bool allowMalformed = true]) → String -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an UTF-8 encoded string. -
readUint16(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Uint16 value. -
readUint32(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Uint32 value. -
readUint64(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Uint64 value. -
readUint8(
int offset) → int -
Available on Pointer<
Reads a part of the buffer starting atUint8> , provided by the ReadWriteData extensionoffset
as an Uint8 value. -
readVarchar(
int offset, [bool allowMalformed = true]) → String -
Available on Pointer<
Reads a part of the buffer as a VARCHAR value (structure).Uint8> , provided by the ReadWriteData extension -
readVaxInt16(
int offset) → int -
Available on Pointer<
Reads a part of the buffer encoded as VAX integer.Uint8> , provided by the ReadWriteData extension -
readVaxInt32(
int offset) → int -
Available on Pointer<
Reads a part of the buffer encoded as VAX integer.Uint8> , provided by the ReadWriteData extension -
readVaxInt64(
int offset) → int -
Available on Pointer<
Reads a part of the buffer encoded as VAX integer.Uint8> , provided by the ReadWriteData extension -
writeDouble(
int offset, double value) → void -
Available on Pointer<
Writes a Double (64-bit) value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 8 bytes). -
writeFloat(
int offset, double value) → void -
Available on Pointer<
Writes a Float (32-bit) value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 4 bytes). -
writeInt16(
int offset, int value) → void -
Available on Pointer<
Writes an Int16 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 2 bytes). -
writeInt32(
int offset, int value) → void -
Available on Pointer<
Writes an Int32 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 4 bytes). -
writeInt64(
int offset, int value) → void -
Available on Pointer<
Writes an Int64 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 8 bytes). -
writeInt8(
int offset, int value) → void -
Available on Pointer<
Writes an Int8 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 1 byte). -
writeString(
int offset, String value, [bool includeNullTerm = true, int? maxLength]) → void -
Available on Pointer<
Writes a UTF-8 converted string to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
. -
writeUint16(
int offset, int value) → void -
Available on Pointer<
Writes an Uint16 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 2 bytes). -
writeUint32(
int offset, int value) → void -
Available on Pointer<
Writes an Uint32 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 4 bytes). -
writeUint64(
int offset, int value) → void -
Available on Pointer<
Writes an Uint64 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 8 bytes). -
writeUint8(
int offset, int value) → void -
Available on Pointer<
Writes an Uint8 value to the buffer at offsetUint8> , provided by the ReadWriteData extensionoffset
(writes 1 byte). -
writeVarchar(
int offset, String value, [int? maxLength]) → void -
Available on Pointer<
Writes a UTF-8 converted string to the buffer as VARCHAR.Uint8> , provided by the ReadWriteData extension