BcsReader class

Class used for reading BCS data chunk by chunk. Meant to be used by some wrapper, which will make sure that data is valid and is matching the desired format.

// data for this example is:
// { a: u8, b: u32, c: bool, d: u64 }

final reader = BcsReader(fromHEX("647f1a060001ffffe7890423c78a050102030405"));
final field1 = reader.read8();
final field2 = reader.read32();
final field3 = reader.read8() == 1; // bool
final field4 = reader.read64();
// ....

Reading vectors is another deal in bcs. To read a vector, you first need to read its length using {@link readULEB}. Here's an example:

// data encoded: { field: [1, 2, 3, 4, 5] }
final reader = BcsReader(fromHEX("050102030405"));
final vec_length = reader.readULEB();
final elements = [];
for (var i = 0; i < vec_length; i++) {
  elements.add(reader.read8());
}
print(elements); // [1,2,3,4,5]

Constructors

BcsReader(Uint8List data)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read128() BigInt
Read U128 value from the buffer and shift cursor by 16.
read16() int
Read U16 value from the buffer and shift cursor by 2.
read256() BigInt
Read U256 value from the buffer and shift cursor by 32.
read32() int
Read U32 value from the buffer and shift cursor by 4.
read64() BigInt
Read U64 value from the buffer and shift cursor by 8.
read8() int
Read U8 value from the buffer and shift cursor by 1.
readBytes(int num) Uint8List
Read num number of bytes from the buffer and shift cursor by num.
readFixedArray(int size, dynamic cb(BcsReader reader, int i, int length)) List
readULEB() int
Read ULEB value - an integer of varying size. Used for enum indexes and vector lengths.
readVec(dynamic cb(BcsReader reader, int i, int length)) List
Read a BCS vector: read a length and then apply function cb X times where X is the length of the vector, defined as ULEB in BCS bytes.
shift(int bytes) BcsReader
Shift current cursor position by bytes.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited