|
1 | 1 | use log::debug; |
2 | 2 | use serde::de::{self, DeserializeSeed, MapAccess, SeqAccess, Visitor}; |
3 | 3 | use serde::forward_to_deserialize_any; |
4 | | -use serde::serde_if_integer128; |
5 | 4 | use std::convert::TryInto; |
6 | 5 |
|
7 | 6 | use super::MaxMindDbError; |
@@ -125,14 +124,7 @@ impl<'de> Decoder<'de> { |
125 | 124 | 7 => self.decode_map(size), |
126 | 125 | 8 => Value::I32(self.decode_int(size)?), |
127 | 126 | 9 => Value::U64(self.decode_uint64(size)?), |
128 | | - 10 => { |
129 | | - serde_if_integer128! { |
130 | | - return Ok(Value::U128(self.decode_uint128(size)?)); |
131 | | - } |
132 | | - |
133 | | - #[allow(unreachable_code)] |
134 | | - Value::Bytes(self.decode_bytes(size)?) |
135 | | - } |
| 127 | + 10 => Value::U128(self.decode_uint128(size)?), |
136 | 128 | 11 => self.decode_array(size), |
137 | 129 | 14 => Value::Bool(self.decode_bool(size)?), |
138 | 130 | 15 => Value::F32(self.decode_float(size)?), |
@@ -215,25 +207,20 @@ impl<'de> Decoder<'de> { |
215 | 207 | } |
216 | 208 | } |
217 | 209 |
|
218 | | - serde_if_integer128! { |
219 | | - fn decode_uint128( |
220 | | - &mut self, |
221 | | - size: usize, |
222 | | - ) -> DecodeResult<u128> { |
223 | | - match size { |
224 | | - s if s <= 16 => { |
225 | | - let new_offset = self.current_ptr + size; |
226 | | - |
227 | | - let value = self.buf[self.current_ptr..new_offset] |
228 | | - .iter() |
229 | | - .fold(0_u128, |acc, &b| (acc << 8) | u128::from(b)); |
230 | | - self.current_ptr = new_offset; |
231 | | - Ok(value) |
232 | | - } |
233 | | - s => Err(MaxMindDbError::InvalidDatabase(format!( |
234 | | - "u128 of size {s:?}" |
235 | | - ))), |
| 210 | + fn decode_uint128(&mut self, size: usize) -> DecodeResult<u128> { |
| 211 | + match size { |
| 212 | + s if s <= 16 => { |
| 213 | + let new_offset = self.current_ptr + size; |
| 214 | + |
| 215 | + let value = self.buf[self.current_ptr..new_offset] |
| 216 | + .iter() |
| 217 | + .fold(0_u128, |acc, &b| (acc << 8) | u128::from(b)); |
| 218 | + self.current_ptr = new_offset; |
| 219 | + Ok(value) |
236 | 220 | } |
| 221 | + s => Err(MaxMindDbError::InvalidDatabase(format!( |
| 222 | + "u128 of size {s:?}" |
| 223 | + ))), |
237 | 224 | } |
238 | 225 | } |
239 | 226 |
|
|
0 commit comments