toBuffer function

Uint8List toBuffer(
  1. dynamic v
)

Implementation

Uint8List toBuffer(v) {
  if (v is! Uint8List) {
    if (v is List<int>) {
      v = Uint8List.fromList(v);
    } else if (v is String) {
      if (isHexString(v)) {
        v = Uint8List.fromList(hex.decode(padToEven(stripHexPrefix(v))));
      } else {
        v = Uint8List.fromList(utf8.encode(v));
      }
    } else if (v is int) {
      v = intToBuffer(v);
    } else if (v == null) {
      v = Uint8List(0);
    } else if (v is BigInt) {
      v = Uint8List.fromList(encodeBigInt(v));
    } else {
      throw 'invalid type';
    }
  }

  return v;
}