@@ -36,6 +36,18 @@ pub fn write_u32_be(dst: &mut[u8], input: u32) {
36
36
}
37
37
}
38
38
39
+ /// Write a u32 into a vector, which must be 4 bytes long. The value is written in little-endian
40
+ /// format.
41
+ pub fn write_u32_le ( dst : & mut [ u8 ] , input : u32 ) {
42
+ use std:: cast:: transmute;
43
+ use std:: unstable:: intrinsics:: to_le32;
44
+ assert ! ( dst. len( ) == 4 ) ;
45
+ unsafe {
46
+ let x: * mut i32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
47
+ * x = to_le32 ( input as i32 ) ;
48
+ }
49
+ }
50
+
39
51
/// Read a vector of bytes into a vector of u64s. The values are read in big-endian format.
40
52
pub fn read_u64v_be ( dst : & mut [ u64 ] , input : & [ u8 ] ) {
41
53
use std:: cast:: transmute;
@@ -68,6 +80,22 @@ pub fn read_u32v_be(dst: &mut[u32], input: &[u8]) {
68
80
}
69
81
}
70
82
83
+ /// Read a vector of bytes into a vector of u32s. The values are read in little-endian format.
84
+ pub fn read_u32v_le ( dst : & mut [ u32 ] , input : & [ u8 ] ) {
85
+ use std:: cast:: transmute;
86
+ use std:: unstable:: intrinsics:: to_le32;
87
+ assert ! ( dst. len( ) * 4 == input. len( ) ) ;
88
+ unsafe {
89
+ let mut x: * mut i32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
90
+ let mut y: * i32 = transmute ( input. unsafe_ref ( 0 ) ) ;
91
+ do dst. len ( ) . times ( ) {
92
+ * x = to_le32 ( * y) ;
93
+ x = x. offset ( 1 ) ;
94
+ y = y. offset ( 1 ) ;
95
+ }
96
+ }
97
+ }
98
+
71
99
72
100
/// Returns true if adding the two parameters will result in integer overflow
73
101
pub fn will_add_overflow < T : Int + Unsigned > ( x : T , y : T ) -> bool {
0 commit comments