rawEncode static method

Uint8List rawEncode(
  1. List<String> types,
  2. dynamic values
)

Implementation

static Uint8List rawEncode(List<String> types, values) {
  var output = BytesBuffer();
  var data = BytesBuffer();

  var headLength = 0;

  types.forEach((type) {
    if (isArray(type)) {
      var size = parseTypeArray(type);

      if (size != null && size is int) {
        headLength += 32 * size;
      } else {
        headLength += 32;
      }
    } else {
      headLength += 32;
    }
  });

  for (var i = 0; i < types.length; i++) {
    var type = elementaryName(types[i]);
    var value = values[i];
    var cur = encodeSingle(type, value);

    // Use the head/tail method for storing dynamic data
    if (isDynamic(type)) {
      output.add(encodeSingle('uint256', headLength));
      data.add(cur);
      headLength += cur.length;
    } else {
      output.add(cur);
    }
  }

  output.add(data.toBytes());
  return output.toBytes();
}