decode method

  1. @override
DecoderResult<List<int>> decode(
  1. AbiParameter params,
  2. List<int> bytes
)
override

Decodes a byte array from the given ABI-encoded bytes.

Implementation

@override
DecoderResult<List<int>> decode(AbiParameter params, List<int> bytes) {
  int partsCount = 1;
  int consumed = 0;
  List<int> remainingBytes = List<int>.from(bytes);
  int? size = _ABIUtils.bytesSize(params.type);
  if (size == null) {
    final decode =
        const NumbersCoder().decode(AbiParameter.uint32, remainingBytes);
    consumed = decode.consumed;
    size = decode.result.toInt();
    partsCount = (size / ABIConst.uintBytesLength).ceil();
    remainingBytes = bytes.sublist(decode.consumed);
  }
  _ABIValidator.validateBytesLength(bytes, size);
  return DecoderResult(
      result: remainingBytes.sublist(0, size),
      consumed: consumed + partsCount * ABIConst.uintBytesLength,
      name: params.name);
}