9
9
// except according to those terms.
10
10
11
11
use std;
12
- use std:: num:: { One , Zero , CheckedAdd } ;
12
+ use std:: num:: { One , Zero , Int , CheckedAdd } ;
13
13
use std:: slice:: bytes:: { MutableByteVector , copy_memory} ;
14
14
15
15
use buffer:: { ReadBuffer , WriteBuffer , BufferResult , BufferUnderflow , BufferOverflow } ;
@@ -19,48 +19,44 @@ use symmetriccipher::{SynchronousStreamCipher, SymmetricCipherError};
19
19
/// format.
20
20
pub fn write_u64_be ( dst : & mut [ u8 ] , input : u64 ) {
21
21
use std:: mem:: transmute;
22
- use std:: mem:: to_be64;
23
22
assert ! ( dst. len( ) == 8 ) ;
24
23
unsafe {
25
24
let x: * mut u64 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
26
- * x = to_be64 ( input) ;
25
+ * x = input. to_be ( ) ;
27
26
}
28
27
}
29
28
30
29
/// Write a u32 into a vector, which must be 4 bytes long. The value is written in big-endian
31
30
/// format.
32
31
pub fn write_u32_be ( dst : & mut [ u8 ] , input : u32 ) {
33
32
use std:: mem:: transmute;
34
- use std:: mem:: to_be32;
35
33
assert ! ( dst. len( ) == 4 ) ;
36
34
unsafe {
37
35
let x: * mut u32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
38
- * x = to_be32 ( input) ;
36
+ * x = input. to_be ( ) ;
39
37
}
40
38
}
41
39
42
40
/// Write a u32 into a vector, which must be 4 bytes long. The value is written in little-endian
43
41
/// format.
44
42
pub fn write_u32_le ( dst : & mut [ u8 ] , input : u32 ) {
45
43
use std:: mem:: transmute;
46
- use std:: mem:: to_le32;
47
44
assert ! ( dst. len( ) == 4 ) ;
48
45
unsafe {
49
46
let x: * mut u32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
50
- * x = to_le32 ( input) ;
47
+ * x = input. to_le ( ) ;
51
48
}
52
49
}
53
50
54
51
/// Read a vector of bytes into a vector of u64s. The values are read in big-endian format.
55
52
pub fn read_u64v_be ( dst : & mut [ u64 ] , input : & [ u8 ] ) {
56
53
use std:: mem:: transmute;
57
- use std:: mem:: to_be64;
58
54
assert ! ( dst. len( ) * 8 == input. len( ) ) ;
59
55
unsafe {
60
56
let mut x: * mut u64 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
61
57
let mut y: * u64 = transmute ( input. unsafe_ref ( 0 ) ) ;
62
58
for _ in range ( 0 , dst. len ( ) ) {
63
- * x = to_be64 ( * y) ;
59
+ * x = ( * y) . to_be ( ) ;
64
60
x = x. offset ( 1 ) ;
65
61
y = y. offset ( 1 ) ;
66
62
}
@@ -70,13 +66,12 @@ pub fn read_u64v_be(dst: &mut[u64], input: &[u8]) {
70
66
/// Read a vector of bytes into a vector of u32s. The values are read in big-endian format.
71
67
pub fn read_u32v_be ( dst : & mut [ u32 ] , input : & [ u8 ] ) {
72
68
use std:: mem:: transmute;
73
- use std:: mem:: to_be32;
74
69
assert ! ( dst. len( ) * 4 == input. len( ) ) ;
75
70
unsafe {
76
71
let mut x: * mut u32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
77
72
let mut y: * u32 = transmute ( input. unsafe_ref ( 0 ) ) ;
78
73
for _ in range ( 0 , dst. len ( ) ) {
79
- * x = to_be32 ( * y) ;
74
+ * x = ( * y) . to_be ( ) ;
80
75
x = x. offset ( 1 ) ;
81
76
y = y. offset ( 1 ) ;
82
77
}
@@ -86,13 +81,12 @@ pub fn read_u32v_be(dst: &mut[u32], input: &[u8]) {
86
81
/// Read a vector of bytes into a vector of u32s. The values are read in little-endian format.
87
82
pub fn read_u32v_le ( dst : & mut [ u32 ] , input : & [ u8 ] ) {
88
83
use std:: mem:: transmute;
89
- use std:: mem:: to_le32;
90
84
assert ! ( dst. len( ) * 4 == input. len( ) ) ;
91
85
unsafe {
92
86
let mut x: * mut u32 = transmute ( dst. unsafe_mut_ref ( 0 ) ) ;
93
87
let mut y: * u32 = transmute ( input. unsafe_ref ( 0 ) ) ;
94
88
for _ in range ( 0 , dst. len ( ) ) {
95
- * x = to_le32 ( * y) ;
89
+ * x = ( * y) . to_le ( ) ;
96
90
x = x. offset ( 1 ) ;
97
91
y = y. offset ( 1 ) ;
98
92
}
@@ -102,22 +96,20 @@ pub fn read_u32v_le(dst: &mut[u32], input: &[u8]) {
102
96
/// Read the value of a vector of bytes as a u32 value in little-endian format.
103
97
pub fn read_u32_le ( input : & [ u8 ] ) -> u32 {
104
98
use std:: mem:: transmute;
105
- use std:: mem:: to_le32;
106
99
assert ! ( input. len( ) == 4 ) ;
107
100
unsafe {
108
101
let tmp: * u32 = transmute ( input. unsafe_ref ( 0 ) ) ;
109
- return to_le32 ( * tmp) ;
102
+ return ( * tmp) . to_le ( ) ;
110
103
}
111
104
}
112
105
113
106
/// Read the value of a vector of bytes as a u32 value in big-endian format.
114
107
pub fn read_u32_be ( input : & [ u8 ] ) -> u32 {
115
108
use std:: mem:: transmute;
116
- use std:: mem:: to_be32;
117
109
assert ! ( input. len( ) == 4 ) ;
118
110
unsafe {
119
111
let tmp: * u32 = transmute ( input. unsafe_ref ( 0 ) ) ;
120
- return to_be32 ( * tmp) ;
112
+ return ( * tmp) . to_be ( ) ;
121
113
}
122
114
}
123
115
0 commit comments