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);
on

Methods

readDouble(int offset) double

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as Double (64-bit) value.
readFloat(int offset) double

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as Float (32-bit) value.
readInt16(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Int16 value.
readInt32(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Int32 value.
readInt64(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Int64 value.
readInt8(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Int8 value.
readString(int offset, [int? byteCnt, bool allowMalformed = true]) String

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an UTF-8 encoded string.
readUint16(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Uint16 value.
readUint32(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Uint32 value.
readUint64(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Uint64 value.
readUint8(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer starting at offset as an Uint8 value.
readVarchar(int offset, [bool allowMalformed = true]) String

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer as a VARCHAR value (structure).
readVaxInt16(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer encoded as VAX integer.
readVaxInt32(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer encoded as VAX integer.
readVaxInt64(int offset) int

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Reads a part of the buffer encoded as VAX integer.
writeDouble(int offset, double value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes a Double (64-bit) value to the buffer at offset offset (writes 8 bytes).
writeFloat(int offset, double value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes a Float (32-bit) value to the buffer at offset offset (writes 4 bytes).
writeInt16(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Int16 value to the buffer at offset offset (writes 2 bytes).
writeInt32(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Int32 value to the buffer at offset offset (writes 4 bytes).
writeInt64(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Int64 value to the buffer at offset offset (writes 8 bytes).
writeInt8(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Int8 value to the buffer at offset offset (writes 1 byte).
writeString(int offset, String value, [bool includeNullTerm = true, int? maxLength]) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes a UTF-8 converted string to the buffer at offset offset.
writeUint16(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Uint16 value to the buffer at offset offset (writes 2 bytes).
writeUint32(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Uint32 value to the buffer at offset offset (writes 4 bytes).
writeUint64(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Uint64 value to the buffer at offset offset (writes 8 bytes).
writeUint8(int offset, int value) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes an Uint8 value to the buffer at offset offset (writes 1 byte).
writeVarchar(int offset, String value, [int? maxLength]) → void

Available on Pointer<Uint8>, provided by the ReadWriteData extension

Writes a UTF-8 converted string to the buffer as VARCHAR.