Encode a BOLT #1 `tu64`: big-endian, minimal length (no leading 0x00). Value 0 is encoded as zero-length.
(v: u64)
| 302 | /// Encode a BOLT #1 `tu64`: big-endian, minimal length (no leading 0x00). |
| 303 | /// Value 0 is encoded as zero-length. |
| 304 | pub fn encode_tu64(v: u64) -> Vec<u8> { |
| 305 | if v == 0 { |
| 306 | return Vec::new(); |
| 307 | } |
| 308 | let bytes = v.to_be_bytes(); |
| 309 | let first = bytes.iter().position(|&b| b != 0).unwrap(); // safe: v != 0 |
| 310 | bytes[first..].to_vec() |
| 311 | } |
| 312 | |
| 313 | /// Decode a BOLT #1 `tu64`, enforcing minimal form. |
| 314 | /// Empty slice -> 0. Leading 0x00 or >8 bytes is invalid. |
no test coverage detected