Removed Byteorder now that rust supports it natively (#171)
* Removed byteorder now that from_le_bytes is stabilized * Rust fmt
This commit is contained in:
parent
23b054c0e5
commit
e88d5d32e5
|
@ -13,14 +13,13 @@ exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
# Disable for no_std support
|
# Disable for no_std support
|
||||||
std = ["parity-wasm/std", "byteorder/std"]
|
std = ["parity-wasm/std"]
|
||||||
# Enable for no_std support
|
# Enable for no_std support
|
||||||
# hashbrown only works on no_std
|
# hashbrown only works on no_std
|
||||||
core = ["hashbrown", "libm"]
|
core = ["hashbrown", "libm"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parity-wasm = { version = "0.31", default-features = false }
|
parity-wasm = { version = "0.31", default-features = false }
|
||||||
byteorder = { version = "1.0", default-features = false }
|
|
||||||
hashbrown = { version = "0.1.8", optional = true }
|
hashbrown = { version = "0.1.8", optional = true }
|
||||||
memory_units = "0.3.0"
|
memory_units = "0.3.0"
|
||||||
libm = { version = "0.1.2", optional = true }
|
libm = { version = "0.1.2", optional = true }
|
||||||
|
|
|
@ -115,7 +115,6 @@ extern crate wabt;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate assert_matches;
|
extern crate assert_matches;
|
||||||
|
|
||||||
extern crate byteorder;
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
extern crate hashbrown;
|
extern crate hashbrown;
|
||||||
extern crate memory_units as memory_units_crate;
|
extern crate memory_units as memory_units_crate;
|
||||||
|
|
57
src/value.rs
57
src/value.rs
|
@ -1,4 +1,3 @@
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
|
||||||
use core::{f32, i32, i64, u32, u64};
|
use core::{f32, i32, i64, u32, u64};
|
||||||
use nan_preserving_float::{F32, F64};
|
use nan_preserving_float::{F32, F64};
|
||||||
use types::ValueType;
|
use types::ValueType;
|
||||||
|
@ -601,91 +600,119 @@ impl LittleEndianConvert for u8 {
|
||||||
|
|
||||||
impl LittleEndianConvert for i16 {
|
impl LittleEndianConvert for i16 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_i16(buffer, self);
|
buffer.copy_from_slice(&self.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 2];
|
||||||
buffer
|
buffer
|
||||||
.get(0..2)
|
.get(0..2)
|
||||||
.map(LittleEndian::read_i16)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_le_bytes(res)
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for u16 {
|
impl LittleEndianConvert for u16 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_u16(buffer, self);
|
buffer.copy_from_slice(&self.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 2];
|
||||||
buffer
|
buffer
|
||||||
.get(0..2)
|
.get(0..2)
|
||||||
.map(LittleEndian::read_u16)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_le_bytes(res)
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for i32 {
|
impl LittleEndianConvert for i32 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_i32(buffer, self);
|
buffer.copy_from_slice(&self.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 4];
|
||||||
buffer
|
buffer
|
||||||
.get(0..4)
|
.get(0..4)
|
||||||
.map(LittleEndian::read_i32)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_le_bytes(res)
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for u32 {
|
impl LittleEndianConvert for u32 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_u32(buffer, self);
|
buffer.copy_from_slice(&self.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 4];
|
||||||
buffer
|
buffer
|
||||||
.get(0..4)
|
.get(0..4)
|
||||||
.map(LittleEndian::read_u32)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_le_bytes(res)
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for i64 {
|
impl LittleEndianConvert for i64 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_i64(buffer, self);
|
buffer.copy_from_slice(&self.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 8];
|
||||||
buffer
|
buffer
|
||||||
.get(0..8)
|
.get(0..8)
|
||||||
.map(LittleEndian::read_i64)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_le_bytes(res)
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for f32 {
|
impl LittleEndianConvert for f32 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_f32(buffer, self);
|
buffer.copy_from_slice(&self.to_bits().to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 4];
|
||||||
buffer
|
buffer
|
||||||
.get(0..4)
|
.get(0..4)
|
||||||
.map(LittleEndian::read_f32)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_bits(u32::from_le_bytes(res))
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LittleEndianConvert for f64 {
|
impl LittleEndianConvert for f64 {
|
||||||
fn into_little_endian(self, buffer: &mut [u8]) {
|
fn into_little_endian(self, buffer: &mut [u8]) {
|
||||||
LittleEndian::write_f64(buffer, self);
|
buffer.copy_from_slice(&self.to_bits().to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
let mut res = [0u8; 8];
|
||||||
buffer
|
buffer
|
||||||
.get(0..8)
|
.get(0..8)
|
||||||
.map(LittleEndian::read_f64)
|
.map(|s| {
|
||||||
|
res.copy_from_slice(s);
|
||||||
|
Self::from_bits(u64::from_le_bytes(res))
|
||||||
|
})
|
||||||
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue