Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Byteorder now that rust supports it natively #171

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
[features]
default = ["std"]
# Disable for no_std support
std = ["parity-wasm/std", "byteorder/std"]
std = ["parity-wasm/std"]
# Enable for no_std support
# hashbrown only works on no_std
core = ["hashbrown", "libm"]

[dependencies]
parity-wasm = { version = "0.31", default-features = false }
byteorder = { version = "1.0", default-features = false }
hashbrown = { version = "0.1.8", optional = true }
memory_units = "0.3.0"
libm = { version = "0.1.2", optional = true }
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ extern crate wabt;
#[macro_use]
extern crate assert_matches;

extern crate byteorder;
#[cfg(not(feature = "std"))]
extern crate hashbrown;
extern crate memory_units as memory_units_crate;
Expand Down
57 changes: 42 additions & 15 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use byteorder::{ByteOrder, LittleEndian};
use core::{f32, i32, i64, u32, u64};
use nan_preserving_float::{F32, F64};
use types::ValueType;
Expand Down Expand Up @@ -601,91 +600,119 @@ impl LittleEndianConvert for u8 {

impl LittleEndianConvert for i16 {
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> {
let mut res = [0u8; 2];
buffer
.get(0..2)
.map(LittleEndian::read_i16)
.map(|s| {
res.copy_from_slice(s);
Self::from_le_bytes(res)
})
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
}
}

impl LittleEndianConvert for u16 {
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> {
let mut res = [0u8; 2];
buffer
.get(0..2)
.map(LittleEndian::read_u16)
.map(|s| {
res.copy_from_slice(s);
Self::from_le_bytes(res)
})
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
}
}

impl LittleEndianConvert for i32 {
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> {
let mut res = [0u8; 4];
buffer
.get(0..4)
.map(LittleEndian::read_i32)
.map(|s| {
res.copy_from_slice(s);
Self::from_le_bytes(res)
})
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
}
}

impl LittleEndianConvert for u32 {
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> {
let mut res = [0u8; 4];
buffer
.get(0..4)
.map(LittleEndian::read_u32)
.map(|s| {
res.copy_from_slice(s);
Self::from_le_bytes(res)
})
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
}
}

impl LittleEndianConvert for i64 {
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> {
let mut res = [0u8; 8];
buffer
.get(0..8)
.map(LittleEndian::read_i64)
.map(|s| {
res.copy_from_slice(s);
Self::from_le_bytes(res)
})
.ok_or_else(|| Error::InvalidLittleEndianBuffer)
}
}

impl LittleEndianConvert for f32 {
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> {
let mut res = [0u8; 4];
buffer
.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)
}
}

impl LittleEndianConvert for f64 {
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> {
let mut res = [0u8; 8];
buffer
.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)
}
}
Expand Down