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

Commit

Permalink
remove byteorder dependency, use std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Jan 18, 2019
1 parent 0385a1e commit 252821a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#![warn(missing_docs)]

extern crate byteorder;

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

0 comments on commit 252821a

Please sign in to comment.