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

Function decode_tu64

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

Decode a BOLT #1 `tu64`, enforcing minimal form. Empty slice -> 0. Leading 0x00 or >8 bytes is invalid.

(raw: &[u8])

Source from the content-addressed store, hash-verified

313/// Decode a BOLT #1 `tu64`, enforcing minimal form.
314/// Empty slice -> 0. Leading 0x00 or >8 bytes is invalid.
315fn decode_tu64(raw: &[u8]) -> Result<u64> {
316 if raw.is_empty() {
317 return Ok(0);
318 }
319 if raw.len() > 8 {
320 return Err(TlvError::Overflow);
321 }
322 if raw[0] == 0 {
323 return Err(TlvError::LeadingZero);
324 }
325 let mut buf = [0u8; 8];
326 buf[8 - raw.len()..].copy_from_slice(raw);
327 Ok(u64::from_be_bytes(buf))
328}
329
330#[cfg(test)]
331mod tests {

Callers 1

get_tu64Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected