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 data.asUnmodifiableView();

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

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