toBytes static method

Object toBytes(
  1. Object data
)

Implementation

static Object toBytes(Object data) {
  if (data is DataProvider) return data;
  if (data is Uint8List) return UnmodifiableUint8ListView(data);

  if (data is Iterable<int>) {
    return UnmodifiableUint8ListView(Uint8List.fromList(data.toList()));
  }

  var s = data.toString();
  var encoded = dart_convert.utf8.encode(s).asUint8List;
  return UnmodifiableUint8ListView(encoded);
}