Added full suite of unsigned int parsers
Getty Ritter
9 years ago
| 92 | 92 | Ok(b as f32 / 255.0) |
| 93 | 93 | } |
| 94 | 94 | |
| 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 | ||
| 95 | 121 | pub fn read_u32be(&mut self) -> Result<u32, String> { |
| 96 | 122 | let a = try!(self.next()); |
| 97 | 123 | let b = try!(self.next()); |
| 101 | 127 | unsafe { Ok(mem::transmute::<[u8;4],u32>(rs)) } |
| 102 | 128 | } |
| 103 | 129 | |
| 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 | ||
| 104 | 139 | pub fn read_u16be(&mut self) -> Result<u16, String> { |
| 105 | 140 | let a = try!(self.next()); |
| 106 | 141 | let b = try!(self.next()); |
| 107 | 142 | 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 ]; | |
| 108 | 150 | unsafe { Ok(mem::transmute::<[u8;2],u16>(rs)) } |
| 109 | 151 | } |
| 110 | 152 | |