X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Fbyte_utils.rs;h=7230a4e1ce187e2eb1ff4f2c8f68dc9d6301b2ef;hb=09c7f2f641d2496c2a6280b032f62b6249298a0f;hp=b9ca3f6b650a19c2e14380493f4e7bf0f1e9da90;hpb=155f2ef1881ab8f28563c0342ee19499a6682dba;p=rust-lightning diff --git a/src/util/byte_utils.rs b/src/util/byte_utils.rs index b9ca3f6b..7230a4e1 100644 --- a/src/util/byte_utils.rs +++ b/src/util/byte_utils.rs @@ -11,6 +11,13 @@ pub fn slice_to_be32(v: &[u8]) -> u32 { ((v[3] as u32) << 8*0) } #[inline] +pub fn slice_to_le32(v: &[u8]) -> u32 { + ((v[0] as u32) << 8*0) | + ((v[1] as u32) << 8*1) | + ((v[2] as u32) << 8*2) | + ((v[3] as u32) << 8*3) +} +#[inline] pub fn slice_to_be48(v: &[u8]) -> u64 { ((v[0] as u64) << 8*5) | ((v[1] as u64) << 8*4) | @@ -48,6 +55,15 @@ pub fn be32_to_array(u: u32) -> [u8; 4] { v } #[inline] +pub fn le32_to_array(u: u32) -> [u8; 4] { + let mut v = [0; 4]; + v[0] = ((u >> 8*0) & 0xff) as u8; + v[1] = ((u >> 8*1) & 0xff) as u8; + v[2] = ((u >> 8*2) & 0xff) as u8; + v[3] = ((u >> 8*3) & 0xff) as u8; + v +} +#[inline] pub fn be48_to_array(u: u64) -> [u8; 6] { assert!(u & 0xffff_0000_0000_0000 == 0); let mut v = [0; 6];