Skip to content

Commit

Permalink
use released byteorder for now
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Apr 16, 2020
1 parent 6f7685b commit 55ded81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ parallel = ["rayon"]
#cbindgen = "~0.6.7"

[dependencies]
#byteorder = "1.3.2"
byteorder = { git = "https://github.com/luizirber/byteorder", branch="write_u32_from" }
byteorder = "1.3.2"
cfg-if = "0.1.10"
failure = "0.1.6"
failure_derive = "0.1.6"
Expand Down
15 changes: 14 additions & 1 deletion src/core/src/sketch/nodegraph.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs::File;
use std::io;
use std::path::Path;
use std::slice;

use byteorder::{BigEndian, ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt};
use failure::Error;
Expand Down Expand Up @@ -175,8 +176,20 @@ impl Nodegraph {
let byte_size = tablesize / 8 + 1;
let (div, rem) = (byte_size / 4, byte_size % 4);

// Once this issue and PR are solved, this is a one liner:
// https://github.com/BurntSushi/byteorder/issues/155
wtr.write_u32_from::<LittleEndian>(&count.as_slice()[..div])?;
// https://github.com/BurntSushi/byteorder/pull/166
//wtr.write_u32_from::<LittleEndian>(&count.as_slice()[..div])?;
let slice = &count.as_slice()[..div];
let buf = unsafe {
use std::mem::size_of;

let len = size_of::<u32>() * slice.len();
slice::from_raw_parts(slice.as_ptr() as *const u8, len)
};
wtr.write_all(&buf)?;
// Replace when byteorder PR is released

if rem != 0 {
let mut cursor = [0u8; 4];
LittleEndian::write_u32(&mut cursor, count.as_slice()[div]);
Expand Down

0 comments on commit 55ded81

Please sign in to comment.