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

Function encode_bigsize

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

BOLT #1 BigSize encoding

(x: u64)

Source from the content-addressed store, hash-verified

242
243/// BOLT #1 BigSize encoding
244fn encode_bigsize(x: u64) -> Vec<u8> {
245 let mut out = Vec::new();
246 if x < 0xfd {
247 out.push(x as u8);
248 } else if x <= 0xffff {
249 out.push(0xfd);
250 out.extend_from_slice(&(x as u16).to_be_bytes());
251 } else if x <= 0xffff_ffff {
252 out.push(0xfe);
253 out.extend_from_slice(&(x as u32).to_be_bytes());
254 } else {
255 out.push(0xff);
256 out.extend_from_slice(&x.to_be_bytes());
257 }
258 out
259}
260
261fn decode_bigsize(input: &[u8]) -> Result<(u64, usize)> {
262 if input.is_empty() {

Callers 3

to_bytesMethod · 0.85
build_bytesFunction · 0.85
decode_truncated_valueFunction · 0.85

Calls

no outgoing calls

Tested by 1

decode_truncated_valueFunction · 0.68