Add support for Binary and Decimal encodings
Decimal serialization (outside of write_decimal_bytes_vartime) is currently only supported when the alloc flag is enabled, as the encoded length is potentially unbounded for Uint<L> and digits are produced in reverse. In practice anything up to U8192 can be encoded without allocating. Note that unlike the other encodings, decimal encoding is not constant-time.
Unresolved questions:
- Add a trait for encoding numbers as decimal, to match
FromDecimal? This is a bit tricky as it would require theallocfeature (or gain additional methods when the feature is enabled). - Implement
ErrorforParseDecimalError? This would require astdflag. - Add an error type for encoding errors?
Sorry for taking awhile to review this. The implementation is somewhat complex which makes it difficult, but I also have some initial thoughts.
The existing support for hex encoding is implemented in a constant-timeish manner, avoiding branches on the inputs in favor of arithmetic operations.
This implementation appears to branch on the input in several places. That's okay, but the corresponding functions should be marked as *_vartime to reflect that, per this crate's constant-time-by-default policy.
Closing as stale