encode method
Encode values with ABI rules based on the ABI type schemes @return byte[] of ABI encoding @throws IllegalArgumentException if encoder cannot infer the type from obj
Implementation
@override
Uint8List encode(dynamic obj) {
if (obj is! String) {
throw ArgumentError('cannot infer type for string abi value encode');
}
final value = obj;
final buffer = utf8.encode(value);
if (buffer.length >= (1 << 16)) {
throw ArgumentError('string casted to byte exceeds uint16 maximum');
}
final encodedLength = BigIntEncoder.encodeUintToBytes(
BigInt.from(buffer.length), AbiType.ABI_DYNAMIC_HEAD_BYTE_LEN);
final castedBytes =
AbiType.castToTupleType(buffer.length, TypeByte()).encode(buffer);
final bf = <int>[];
bf.addAll(encodedLength);
bf.addAll(castedBytes);
return Uint8List.fromList(bf);
}