Skip to content

Commit acd2c02

Browse files
Replace byteorder with std APIs
1 parent 8a0de53 commit acd2c02

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ exclude = ["/assets"]
1616
description = "Fast and memory saving bsdiff 4.x compatible delta compressor and patcher."
1717

1818
[dependencies]
19-
byteorder = "1.5"
2019
bzip2 = "0.6.0"
2120
clap = { optional = true, version = "4.5", features = ["derive"] }
2221
rayon = "1.10"

src/utils.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![forbid(unsafe_code)]
22

3-
use byteorder::{ByteOrder, LE};
4-
53
/// Single bsdiff control instruction.
64
#[derive(Debug)]
75
pub struct Control {
@@ -13,7 +11,7 @@ pub struct Control {
1311
/// Decodes integer.
1412
#[inline]
1513
pub fn decode_int(b: &[u8]) -> i64 {
16-
let x = LE::read_u64(b);
14+
let x = u64::from_le_bytes(b.try_into().unwrap());
1715
if x >> 63 == 0 || x == 1 << 63 {
1816
x as i64
1917
} else {
@@ -24,9 +22,12 @@ pub fn decode_int(b: &[u8]) -> i64 {
2422
/// Encodes integer.
2523
#[inline]
2624
pub fn encode_int(x: i64, b: &mut [u8]) {
27-
if x < 0 {
28-
LE::write_u64(b, x.wrapping_neg() as u64 | (1 << 63));
25+
let n = if x < 0 {
26+
x.wrapping_neg() as u64 | (1 << 63)
2927
} else {
30-
LE::write_u64(b, x as u64);
31-
}
28+
x as u64
29+
};
30+
31+
let buf = n.to_le_bytes();
32+
b[..8].copy_from_slice(&buf);
3233
}

0 commit comments

Comments
 (0)