Time.fromBytes constructor
Time.fromBytes(
- List<int> bytes, {
- bool allowParseString = true,
})
Parses bytes
to Time. See toBytes32 and toBytes64.
Implementation
factory Time.fromBytes(List<int> bytes, {bool allowParseString = true}) {
var length = bytes.length;
if (length == 4) {
var milliseconds = bytes.asUint8List.getInt32(0);
if (milliseconds >= 0) {
var time = Time.fromMilliseconds(milliseconds);
return time;
}
}
// Postgres encoding:
else if (length == 7 && !_bytesInStringFormat(bytes)) {
bytes = [...bytes, 0];
length = bytes.length;
}
if (length >= 8 && !_bytesInStringFormat(bytes)) {
var microseconds = bytes.asUint8List.getInt64();
if (microseconds >= 0) {
var time = Time.fromMicroseconds(microseconds);
return time;
}
} else if (allowParseString) {
try {
var s = String.fromCharCodes(bytes);
return Time.parse(s, allowFromBytes: false);
} catch (_) {
throw FormatException(
'Invalid bytes or string format: ${bytes.runtimeTypeNameUnsafe}:${bytes.toList()}');
}
}
throw FormatException(
'Invalid bytes format: ${bytes.runtimeTypeNameUnsafe}:${bytes.toList()}');
}