BOLT #1 BigSize encoding
(x: u64)
| 242 | |
| 243 | /// BOLT #1 BigSize encoding |
| 244 | fn 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 | |
| 261 | fn decode_bigsize(input: &[u8]) -> Result<(u64, usize)> { |
| 262 | if input.is_empty() { |
no outgoing calls