toBytes method
(List<int> , FloatLength)
toBytes(
- FloatLength? decodFloatType, {
- Endian? endianness,
- bool allowFloat16 = true,
Encode the floating-point value into a byte representation using the specified floating-point format. Returns a tuple containing the encoded bytes and the format used.
Implementation
(List<int>, FloatLength) toBytes(
FloatLength? decodFloatType, {
Endian? endianness,
bool allowFloat16 = true,
}) {
if (decodFloatType == null) {
if (allowFloat16 && isLessThan16) {
return (_encodeFloat16(endianness), FloatLength.bytes16);
} else if (isLessThan32) {
return (_encodeFloat32(endianness), FloatLength.bytes32);
}
return (_encodeFloat64(endianness), FloatLength.bytes64);
}
final List<int> bytes;
switch (decodFloatType) {
case FloatLength.bytes16:
if (!isLessThan16) {
throw CborException("Float value is larger that float 16.");
}
bytes = _encodeFloat16(endianness);
break;
case FloatLength.bytes32:
if (!isLessThan32) {
throw CborException("Float value is larger that float 32.");
}
bytes = _encodeFloat32(endianness);
break;
default:
bytes = _encodeFloat64(endianness);
break;
}
return (bytes, decodFloatType);
}