serializeVectorWithFunc function

Uint8List serializeVectorWithFunc(
  1. List value,
  2. String func
)

Implementation

Uint8List serializeVectorWithFunc(List<dynamic> value, String func) {
  final serializer = Serializer();
  serializer.serializeU32AsUleb128(value.length);

  Function fn;
  switch (func) {
    case "serializeStr":
      fn = serializer.serializeStr;
      break;
    case "serializeBytes":
      fn = serializer.serializeBytes;
      break;
    case "serializeFixedBytes":
      fn = serializer.serializeFixedBytes;
      break;
    case "serializeBool":
      fn = serializer.serializeBool;
      break;
    case "serializeU8":
      fn = serializer.serializeU8;
      break;
    case "serializeU16":
      fn = serializer.serializeU16;
      break;
    case "serializeU32":
      fn = serializer.serializeU32;
      break;
    case "serializeU64":
      fn = serializer.serializeU64;
      break;
    case "serializeU128":
      fn = serializer.serializeU128;
      break;
    default:
      throw ArgumentError("Cannot found $func in Serializer");
  }

  for (var item in value) {
    fn.call(item);
  }
  return serializer.getBytes();
}