gdritter repos thermidor / 8641c47
Added full suite of unsigned int parsers Getty Ritter 7 years ago
1 changed file(s) with 42 addition(s) and 0 deletion(s). Collapse all Expand all
9292 Ok(b as f32 / 255.0)
9393 }
9494
95 pub fn read_u64be(&mut self) -> Result<u64, String> {
96 let a = try!(self.next());
97 let b = try!(self.next());
98 let c = try!(self.next());
99 let d = try!(self.next());
100 let e = try!(self.next());
101 let f = try!(self.next());
102 let g = try!(self.next());
103 let h = try!(self.next());
104 let rs = [ h, g, f, e, d, c, b, a ];
105 unsafe { Ok(mem::transmute::<[u8;8],u64>(rs)) }
106 }
107
108 pub fn read_u64le(&mut self) -> Result<u64, String> {
109 let a = try!(self.next());
110 let b = try!(self.next());
111 let c = try!(self.next());
112 let d = try!(self.next());
113 let e = try!(self.next());
114 let f = try!(self.next());
115 let g = try!(self.next());
116 let h = try!(self.next());
117 let rs = [ a, b, c, d, e, f, g, h ];
118 unsafe { Ok(mem::transmute::<[u8;8],u64>(rs)) }
119 }
120
95121 pub fn read_u32be(&mut self) -> Result<u32, String> {
96122 let a = try!(self.next());
97123 let b = try!(self.next());
101127 unsafe { Ok(mem::transmute::<[u8;4],u32>(rs)) }
102128 }
103129
130 pub fn read_u32le(&mut self) -> Result<u32, String> {
131 let a = try!(self.next());
132 let b = try!(self.next());
133 let c = try!(self.next());
134 let d = try!(self.next());
135 let rs = [ a, b, c, d ];
136 unsafe { Ok(mem::transmute::<[u8;4],u32>(rs)) }
137 }
138
104139 pub fn read_u16be(&mut self) -> Result<u16, String> {
105140 let a = try!(self.next());
106141 let b = try!(self.next());
107142 let rs = [ b, a ];
143 unsafe { Ok(mem::transmute::<[u8;2],u16>(rs)) }
144 }
145
146 pub fn read_u16le(&mut self) -> Result<u16, String> {
147 let a = try!(self.next());
148 let b = try!(self.next());
149 let rs = [ a, b ];
108150 unsafe { Ok(mem::transmute::<[u8;2],u16>(rs)) }
109151 }
110152