MCPcopy Create free account
hub / github.com/ElementsProject/lightning / encode_tu64

Function encode_tu64

plugins/lsps-plugin/src/core/tlv.rs:304–311  ·  view source on GitHub ↗

Encode a BOLT #1 `tu64`: big-endian, minimal length (no leading 0x00). Value 0 is encoded as zero-length.

(v: u64)

Source from the content-addressed store, hash-verified

302/// Encode a BOLT #1 `tu64`: big-endian, minimal length (no leading 0x00).
303/// Value 0 is encoded as zero-length.
304pub 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.

Callers 2

on_htlc_acceptedFunction · 0.85
set_tu64Method · 0.85

Calls 2

to_vecMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected