encodeTo method
Convert self to a slice and append it to the destination.
Implementation
@override
void encodeTo(Map<String, int> value, Output output) {
if (value.isEmpty ||
(value['phase'] == null && value['period'] == null) ||
(value['phase'] == 0 && value['period'] == 0)) {
//
// Immortal
output.pushByte(0);
return;
}
final calPeriod = pow(2, (log(value['period']!) / log(2)).ceil());
final phase = value['phase']! % min(max(calPeriod, 4), 1 << 16);
final quantizeFactor = max(1, value['period']! >> 12);
final quantizedPhase = phase / quantizeFactor * quantizeFactor;
return output.write(_encode(quantizedPhase.toInt(), calPeriod as int));
}