node_types: fix uint types for the int_to_from_bytes feature

This commit is contained in:
Matt Bilker
2018-08-17 21:37:10 -04:00
parent fe3675ad24
commit 6ba459ec9a
2 changed files with 5 additions and 31 deletions

View File

@@ -80,7 +80,7 @@ fn display_buf(buf: &[u8]) -> Result<(), IoError> {
fn compare_slice(left: &[u8], right: &[u8]) {
let mut buf = [0; 4];
buf.clone_from_slice(&left[4..8]);
let node_buf_length = u32::from_be(u32::from_bytes(buf));
let node_buf_length = u32::from_be_bytes(buf);
//println!("node_buf_length: {}", node_buf_length);
let data_buf_start = 8 + node_buf_length as usize;

View File

@@ -12,32 +12,6 @@ trait KbinWrapperType<T> {
}
macro_rules! number_impl {
(uint; $($inner_type:ident),*) => {
$(
impl KbinWrapperType<$inner_type> for $inner_type {
fn from_kbin_bytes(output: &mut String, input: &[u8]) -> Result<(), KbinError> {
trace!("KbinWrapperType<{}> from bytes => input: {:02x?}", stringify!($inner_type), input);
let mut data = [0; ::std::mem::size_of::<$inner_type>()];
data.clone_from_slice(input);
write!(output, "{}", $inner_type::from_be($inner_type::from_bytes(data)))
.context(KbinErrorKind::ByteParse(stringify!($inner_type)))?;
Ok(())
}
fn to_kbin_bytes(output: &mut Vec<u8>, input: &str) -> Result<(), KbinError> {
let num = input.parse::<$inner_type>().context(KbinErrorKind::StringParse(stringify!($inner_type)))?;
trace!("KbinWrapperType<{}> to bytes => input: '{}', output: {}", stringify!($inner_type), input, num);
let data = $inner_type::to_bytes($inner_type::to_be(num));
output.extend_from_slice(&data);
Ok(())
}
}
)*
};
(int; $($inner_type:ident),*) => {
$(
impl KbinWrapperType<$inner_type> for $inner_type {
@@ -72,7 +46,7 @@ macro_rules! number_impl {
let mut data = [0; ::std::mem::size_of::<$inner_type>()];
data.clone_from_slice(input);
let bits = $intermediate::from_be($intermediate::from_bytes(data));
let bits = $intermediate::from_be_bytes(data);
write!(output, "{:.6}", $inner_type::from_bits(bits))
.context(KbinErrorKind::ByteParse(stringify!($inner_type)))?;
@@ -84,7 +58,7 @@ macro_rules! number_impl {
let num = input.parse::<$inner_type>().context(KbinErrorKind::StringParse(stringify!($inner_type)))?;
trace!("KbinWrapperType<{}> to bytes => input: '{}', output: {}", stringify!($inner_type), input, num);
let data = $intermediate::to_bytes($intermediate::to_be(num.to_bits()));
let data = $intermediate::to_be_bytes(num.to_bits());
output.extend_from_slice(&data);
Ok(())
@@ -94,8 +68,8 @@ macro_rules! number_impl {
};
}
number_impl!(uint; u8, u16, u32, u64);
number_impl!(int; i8, i16, i32, i64);
number_impl!(int; u8, u16, u32, u64);
number_impl!(int; i8, i16, i32, i64);
number_impl!(float; u32 => f32, u64 => f64);
impl KbinWrapperType<bool> for bool {