2015-12-30 17:06:48 -05:00
|
|
|
use std::mem;
|
|
|
|
use std::ptr::copy_nonoverlapping;
|
|
|
|
|
2016-01-06 23:37:18 -05:00
|
|
|
use ::byte_sized::ByteSized;
|
|
|
|
use ::byte_sized::{U16_BYTES, U32_BYTES, U64_BYTES};
|
2016-01-05 17:46:31 -05:00
|
|
|
use ::converter::Converter;
|
|
|
|
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// Defines the current platforms endianess.
|
|
|
|
/// This is can only be big endian or little endian.
|
|
|
|
/// This library does not support a mixed endian setting.
|
|
|
|
#[cfg(target_endian="big")]
|
|
|
|
pub type PlatformEndian = BigEndian;
|
|
|
|
|
|
|
|
/// Defines the current platforms endianess.
|
|
|
|
/// This is can only be BigEndian or LittleEndian.
|
|
|
|
/// This library does not support a mixed endian setting.
|
|
|
|
///
|
|
|
|
/// Defaults to LittleEndian.
|
|
|
|
//#[cfg(target_endian="little")]
|
|
|
|
#[cfg(not(target_endian="big"))]
|
|
|
|
pub type PlatformEndian = LittleEndian;
|
|
|
|
|
2016-01-19 12:02:53 -05:00
|
|
|
/// Handles serialization where the most
|
|
|
|
/// significant byte is stored at the lowest address.
|
|
|
|
pub enum BigEndian
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handles serialization where the most
|
|
|
|
/// significant byte is stored at the lowest address.
|
|
|
|
pub enum LittleEndian
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-05 17:46:31 -05:00
|
|
|
/// Create an enumeration of the different
|
|
|
|
/// available endianesses.
|
2016-01-06 23:37:18 -05:00
|
|
|
#[derive(Clone, Copy)]
|
2016-01-05 17:46:31 -05:00
|
|
|
pub enum Endianess
|
|
|
|
{
|
|
|
|
/// Referes to BigEndian.
|
2016-04-14 15:08:31 -04:00
|
|
|
Big,
|
2016-01-05 17:46:31 -05:00
|
|
|
|
|
|
|
/// Referes to LittleEndian.
|
2016-04-14 15:08:31 -04:00
|
|
|
Little,
|
2016-01-05 17:46:31 -05:00
|
|
|
|
|
|
|
/// Referes to PlatformEndian. This can be anyone
|
|
|
|
/// of the other available endians depending on
|
|
|
|
/// the platform you are on.
|
2016-04-14 15:08:31 -04:00
|
|
|
Platform
|
2016-01-05 17:46:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
/// Handles reading bytes from a given buffer
|
|
|
|
/// and turning them into the requested type.
|
|
|
|
macro_rules! read_bytes
|
|
|
|
{
|
2016-01-02 14:54:03 -05:00
|
|
|
($buffer: expr, $returnType: ident, $convertFunc: ident) =>
|
2015-12-30 17:06:48 -05:00
|
|
|
({
|
2016-01-03 03:22:21 -05:00
|
|
|
// Make sure that there is enough space to read
|
|
|
|
// a value from the buffer.
|
|
|
|
assert!($buffer.len() == $returnType::BYTES);
|
|
|
|
|
2015-12-30 17:06:48 -05:00
|
|
|
unsafe
|
|
|
|
{
|
2016-01-02 14:54:03 -05:00
|
|
|
(*($buffer.as_ptr() as *const $returnType)).$convertFunc()
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handles turning a given number into bytes
|
|
|
|
/// and writing them to a buffer.
|
|
|
|
macro_rules! write_bytes
|
|
|
|
{
|
2016-04-13 23:57:40 -04:00
|
|
|
($buffer: expr, $valueType: ident, $numBytes: expr,
|
|
|
|
$num: expr, $convertFunc: ident) =>
|
2015-12-30 17:06:48 -05:00
|
|
|
({
|
|
|
|
unsafe
|
|
|
|
{
|
2016-01-06 23:37:18 -05:00
|
|
|
let bytes: [u8; $numBytes];
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
bytes =
|
2016-01-06 23:37:18 -05:00
|
|
|
mem::transmute::<_, [u8; $numBytes]>($num.$convertFunc());
|
2016-04-14 13:33:07 -04:00
|
|
|
$buffer.extend_from_slice(&bytes);
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-05 17:46:31 -05:00
|
|
|
impl Converter for BigEndian
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
fn bytes_to_u16(buffer: &[u8]) -> u16
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u16, to_be)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bytes_to_u32(buffer: &[u8]) -> u32
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u32, to_be)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bytes_to_u64(buffer: &[u8]) -> u64
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u64, to_be)
|
|
|
|
}
|
|
|
|
|
2016-01-02 14:54:03 -05:00
|
|
|
fn bytes_to_usize(buffer: &[u8]) -> usize
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
let mut out: [u8; 8];
|
|
|
|
let ptr_out: *mut u8;
|
|
|
|
|
2016-01-02 23:16:39 -05:00
|
|
|
assert!(buffer.len() >= 1 && buffer.len() <= 8);
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
out = [0u8; 8];
|
|
|
|
ptr_out = out.as_mut_ptr();
|
|
|
|
unsafe
|
|
|
|
{
|
2016-01-02 14:54:03 -05:00
|
|
|
copy_nonoverlapping::<u8>(buffer.as_ptr(),
|
|
|
|
ptr_out.offset((8 - buffer.len()) as isize),
|
|
|
|
buffer.len());
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
(*(ptr_out as *const u64)).to_be() as usize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u16_to_bytes(num: u16) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u16::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u16, U16_BYTES, num, to_be);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u32_to_bytes(num: u32) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u32::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u32, U32_BYTES, num, to_be);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u64_to_bytes(num: u64) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u64::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u64, U64_BYTES, num, to_be);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn usize_to_bytes(num: usize) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
let bytes: [u8; 8];
|
2016-01-02 14:54:03 -05:00
|
|
|
let num_bytes: u8;
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
2016-01-02 14:54:03 -05:00
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
num_bytes = usize::BYTES as u8;
|
|
|
|
|
|
|
|
// Create a buffer with enough space for this type.
|
|
|
|
buffer = Vec::with_capacity(usize::BYTES);
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
assert!(determine_size(num as u64) <= num_bytes && num_bytes <= 8);
|
2016-01-02 14:54:03 -05:00
|
|
|
|
2015-12-30 17:06:48 -05:00
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
bytes = mem::transmute::<usize, [u8; 8]>(num.to_be());
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.extend_from_slice(&bytes);
|
|
|
|
//copy_nonoverlapping::<u8>(
|
|
|
|
// bytes.as_ptr().offset((8 - num_bytes) as isize),
|
|
|
|
// buffer.as_mut_ptr(), num_bytes as usize);
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
fn bytes_to_string(buffer: &[u8]) -> String
|
|
|
|
{
|
|
|
|
let byte_count: u64;
|
|
|
|
let new_string: String;
|
|
|
|
|
|
|
|
// A string array should have atleast a u64 size byte count.
|
|
|
|
assert!(buffer.len() >= U64_BYTES);
|
|
|
|
|
|
|
|
// Strings start with the size of bytes to read as
|
|
|
|
// a u64. So read that in and then we know how many
|
|
|
|
// bytes make up the string.
|
|
|
|
byte_count = BigEndian::bytes_to_u64(buffer);
|
|
|
|
|
|
|
|
if byte_count > 0
|
|
|
|
{
|
|
|
|
match String::from_utf8(buffer[U64_BYTES..(buffer.len()-1)].to_vec())
|
|
|
|
{
|
|
|
|
Ok(string) =>
|
|
|
|
{
|
|
|
|
new_string = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
error!("{}", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_string = String::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
new_string
|
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn string_to_bytes(string: String) -> Vec<u8>
|
2016-04-13 23:57:40 -04:00
|
|
|
{
|
|
|
|
let bytes: &[u8];
|
|
|
|
let byte_count: u64;
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Turn the string into a byte array.
|
|
|
|
bytes = string.as_bytes();
|
|
|
|
|
|
|
|
// Determine how many bytes will be written
|
|
|
|
// for this string.
|
|
|
|
byte_count = bytes.len() as u64;
|
|
|
|
|
|
|
|
// Make sure the buffer has enough space for this string.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer = Vec::with_capacity(bytes.len() + U64_BYTES);
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Add the count to the buffer.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.append(&mut BigEndian::u64_to_bytes(byte_count));
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Add each byte of the string to the buffer.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.extend_from_slice(bytes);
|
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2016-04-13 23:57:40 -04:00
|
|
|
}
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-01-05 17:46:31 -05:00
|
|
|
impl Converter for LittleEndian
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
fn bytes_to_u16(buffer: &[u8]) -> u16
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u16, to_le)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bytes_to_u32(buffer: &[u8]) -> u32
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u32, to_le)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bytes_to_u64(buffer: &[u8]) -> u64
|
|
|
|
{
|
|
|
|
read_bytes!(buffer, u64, to_le)
|
|
|
|
}
|
|
|
|
|
2016-01-02 14:54:03 -05:00
|
|
|
fn bytes_to_usize(buffer: &[u8]) -> usize
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
let mut out: [u8; 8];
|
|
|
|
let ptr_out: *mut u8;
|
|
|
|
|
2016-01-02 23:16:39 -05:00
|
|
|
assert!(buffer.len() >= 1 && buffer.len() <= 8);
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
out = [0u8; 8];
|
|
|
|
ptr_out = out.as_mut_ptr();
|
|
|
|
unsafe
|
|
|
|
{
|
2016-01-02 14:54:03 -05:00
|
|
|
copy_nonoverlapping::<u8>(buffer.as_ptr(), ptr_out, buffer.len());
|
2015-12-30 17:06:48 -05:00
|
|
|
(*(ptr_out as *const u64)).to_le() as usize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u16_to_bytes(num: u16) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u16::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u16, U16_BYTES, num, to_le);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u32_to_bytes(num: u32) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u32::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u32, U32_BYTES, num, to_le);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn u64_to_bytes(num: u64) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
// Create the Vector to hold the bytes
|
|
|
|
// from this type.
|
|
|
|
buffer = Vec::with_capacity(u64::BYTES);
|
|
|
|
|
|
|
|
// Write the bytes to the Vector.
|
2016-01-06 23:37:18 -05:00
|
|
|
write_bytes!(buffer, u64, U64_BYTES, num, to_le);
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn usize_to_bytes(num: usize) -> Vec<u8>
|
2015-12-30 17:06:48 -05:00
|
|
|
{
|
|
|
|
let bytes: [u8; 8];
|
2016-01-02 14:54:03 -05:00
|
|
|
let num_bytes: u8;
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
|
|
|
|
|
|
|
num_bytes = usize::BYTES as u8;
|
2016-01-02 14:54:03 -05:00
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
// Create a buffer with enough space for this type.
|
|
|
|
buffer = Vec::with_capacity(usize::BYTES);
|
2015-12-30 17:06:48 -05:00
|
|
|
|
|
|
|
assert!(determine_size(num as u64) <= num_bytes && num_bytes <= 8);
|
2016-01-02 14:54:03 -05:00
|
|
|
|
2015-12-30 17:06:48 -05:00
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
bytes = mem::transmute::<usize, [u8; 8]>(num.to_le());
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.extend_from_slice(&bytes);
|
|
|
|
//copy_nonoverlapping::<u8>(bytes.as_ptr(), buffer.as_mut_ptr(),
|
|
|
|
// num_bytes as usize);
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
2016-04-14 13:33:07 -04:00
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
fn bytes_to_string(buffer: &[u8]) -> String
|
|
|
|
{
|
|
|
|
let byte_count: u64;
|
|
|
|
let new_string: String;
|
|
|
|
|
|
|
|
// A string array should have atleast a u64 size byte count.
|
|
|
|
assert!(buffer.len() >= U64_BYTES);
|
|
|
|
|
|
|
|
// Strings start with the size of bytes to read as
|
|
|
|
// a u64. So read that in and then we know how many
|
|
|
|
// bytes make up the string.
|
|
|
|
byte_count = BigEndian::bytes_to_u64(buffer);
|
|
|
|
|
|
|
|
if byte_count > 0
|
|
|
|
{
|
|
|
|
match String::from_utf8(buffer[U64_BYTES..(buffer.len()-1)].to_vec())
|
|
|
|
{
|
|
|
|
Ok(string) =>
|
|
|
|
{
|
|
|
|
new_string = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
error!("{}", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_string = String::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
new_string
|
|
|
|
}
|
|
|
|
|
2016-04-14 13:33:07 -04:00
|
|
|
fn string_to_bytes(string: String) -> Vec<u8>
|
2016-04-13 23:57:40 -04:00
|
|
|
{
|
|
|
|
let bytes: &[u8];
|
|
|
|
let byte_count: u64;
|
2016-04-14 13:33:07 -04:00
|
|
|
let mut buffer: Vec<u8>;
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Turn the string into a byte array.
|
|
|
|
bytes = string.as_bytes();
|
|
|
|
|
|
|
|
// Determine how many bytes will be written
|
|
|
|
// for this string.
|
2016-04-14 13:33:07 -04:00
|
|
|
byte_count = bytes.len() as u64;
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Make sure the buffer has enough space for this string.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer = Vec::with_capacity(bytes.len() + U64_BYTES);
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Add the count to the buffer.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.append(&mut LittleEndian::u64_to_bytes(byte_count));
|
2016-04-13 23:57:40 -04:00
|
|
|
|
|
|
|
// Add each byte of the string to the buffer.
|
2016-04-14 13:33:07 -04:00
|
|
|
buffer.extend_from_slice(bytes);
|
|
|
|
|
|
|
|
// Return the byte buffer.
|
|
|
|
buffer
|
2016-04-13 23:57:40 -04:00
|
|
|
}
|
2015-12-30 17:06:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Determine the amount of bytes required to
|
|
|
|
/// represent the given number.
|
|
|
|
fn determine_size(num: u64) -> u8
|
|
|
|
{
|
|
|
|
if num < (1 << 8)
|
|
|
|
{
|
|
|
|
1
|
|
|
|
}
|
|
|
|
else if num < (1 << 16)
|
|
|
|
{
|
|
|
|
2
|
|
|
|
}
|
|
|
|
else if num < (1 << 24)
|
|
|
|
{
|
|
|
|
3
|
|
|
|
}
|
|
|
|
else if num < (1 << 32)
|
|
|
|
{
|
|
|
|
4
|
|
|
|
}
|
|
|
|
else if num < (1 << 40)
|
|
|
|
{
|
|
|
|
5
|
|
|
|
}
|
|
|
|
else if num < (1 << 48)
|
|
|
|
{
|
|
|
|
6
|
|
|
|
}
|
|
|
|
else if num < (1 << 56)
|
|
|
|
{
|
|
|
|
7
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
8
|
|
|
|
}
|
|
|
|
}
|