Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Remove byteorder dependency, use std lib for dealing with endianness #262

Merged
merged 1 commit into from Jan 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Expand Up @@ -12,12 +12,9 @@ keywords = ["wasm", "webassembly", "bytecode", "serde", "interpreter"]
categories = ["wasm", "parser-implementations"]
exclude = [ "res/*", "spec/*" ]

[dependencies]
byteorder = { version = "1.0", default-features = false }

[dev-dependencies]
time = "0.1"

[features]
default = ["std"]
std = ["byteorder/std"]
std = []
5 changes: 2 additions & 3 deletions src/elements/module.rs
Expand Up @@ -2,7 +2,6 @@ use io;
use std::vec::Vec;
use std::borrow::ToOwned;
use std::string::String;
use byteorder::{LittleEndian, ByteOrder};

use super::{Deserialize, Serialize, Error, Uint32, External};
use super::section::{
Expand Down Expand Up @@ -39,7 +38,7 @@ pub enum ImportCountType {
impl Default for Module {
fn default() -> Self {
Module {
magic: LittleEndian::read_u32(&WASM_MAGIC_NUMBER),
magic: u32::from_le_bytes(WASM_MAGIC_NUMBER),
version: 1,
sections: Vec::with_capacity(16),
}
Expand Down Expand Up @@ -504,7 +503,7 @@ impl Deserialize for Module {
}

let module = Module {
magic: LittleEndian::read_u32(&magic),
magic: u32::from_le_bytes(magic),
version: version,
sections: sections,
};
Expand Down
13 changes: 4 additions & 9 deletions src/elements/primitives.rs
@@ -1,7 +1,6 @@
use io;
use std::vec::Vec;
use std::string::String;
use byteorder::{LittleEndian, ByteOrder};
use super::{Error, Deserialize, Serialize};

/// Unsigned variable-length integer, limited to 32 bits,
Expand Down Expand Up @@ -417,7 +416,7 @@ impl Deserialize for Uint32 {
let mut buf = [0u8; 4];
reader.read(&mut buf)?;
// todo check range
Ok(Uint32(LittleEndian::read_u32(&buf)))
Ok(u32::from_le_bytes(buf).into())
}
}

Expand All @@ -431,9 +430,7 @@ impl Serialize for Uint32 {
type Error = Error;

fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
let mut buf = [0u8; 4];
LittleEndian::write_u32(&mut buf, self.0);
writer.write(&buf)?;
writer.write(&self.0.to_le_bytes())?;
Ok(())
}
}
Expand All @@ -453,17 +450,15 @@ impl Deserialize for Uint64 {
let mut buf = [0u8; 8];
reader.read(&mut buf)?;
// todo check range
Ok(Uint64(LittleEndian::read_u64(&buf)))
Ok(u64::from_le_bytes(buf).into())
}
}

impl Serialize for Uint64 {
type Error = Error;

fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
let mut buf = [0u8; 8];
LittleEndian::write_u64(&mut buf, self.0);
writer.write(&buf)?;
writer.write(&self.0.to_le_bytes())?;
Ok(())
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Expand Up @@ -5,8 +5,6 @@

#![warn(missing_docs)]

extern crate byteorder;

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
Expand Down