w<T> method
void
w<
T>( - dynamic value, {
- int bytes = 0,
})
Implementation
void w<T>(dynamic value, {int bytes = 0}) {
var bytes0 = bytes;
var typename = T.toString();
if (typename == 'dynamic') {
typename = value.runtimeType.toString();
}
ByteData? byteData;
Uint8List? list;
switch (typename) {
case 'ByteData':
byteData = value;
}
if (bytes0 == 0) {
switch (typename) {
case 'String':
value as String;
bytes0 = value.length;
case 'Uint8':
case 'Int8':
bytes0 = 1;
case 'Uint16':
case 'Int16':
bytes0 = 2;
case 'Uint32':
case 'Int32':
case 'Float':
bytes0 = 4;
case 'Uint64':
case 'Int64':
bytes0 = 8;
}
}
byteData ??= ByteData(bytes0);
switch (typename) {
case 'Uint8List':
list = value;
case 'String':
value as String;
final codeUnits = value.codeUnits;
list = Uint8List.fromList(codeUnits);
case 'Uint8':
byteData.setUint8(0, value);
case 'Int8':
byteData.setInt8(0, value);
case 'Uint16':
value as int;
byteData.setUint16(0, value, Endian.little);
case 'Int16':
value as int;
byteData.setInt16(0, value, Endian.little);
case 'Uint32':
value as int;
byteData.setUint32(0, value, Endian.little);
case 'Int32':
value as int;
byteData.setInt32(0, value, Endian.little);
case 'Float':
value as double;
byteData.setFloat32(0, value, Endian.little);
case 'Uint64':
value as int;
byteData.setUint64(0, value, Endian.little);
case 'Int64':
value as int;
byteData.setInt64(0, value, Endian.little);
}
list ??= byteData.buffer.asUint8List();
_write(list);
}