Skip to content

Commit

Permalink
Remove byteorder, use bytes::Buf::get_uint instead (#477)
Browse files Browse the repository at this point in the history
* Remove byteorder, use bytes::Buf::get_uint instead

* avoid unecessary copy inside bytes::Buf::get_uint

* use assert! to verify length number
  • Loading branch information
nylonicious authored Jan 8, 2025
1 parent 7632848 commit c167787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ __rustls-tls = ["rustls", "rustls-pki-types"]

[dependencies]
data-encoding = { version = "2", optional = true }
byteorder = "1.3.2"
bytes = "1.9.0"
http = { version = "1.0", optional = true }
httparse = { version = "1.3.4", optional = true }
Expand Down
17 changes: 8 additions & 9 deletions src/protocol/frame/frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use byteorder::{NetworkEndian, ReadBytesExt};
use log::*;
use std::{
default::Default,
Expand Down Expand Up @@ -161,14 +160,14 @@ impl FrameHeader {
let length_byte = second & 0x7F;
let length_length = LengthFormat::for_byte(length_byte).extra_bytes();
if length_length > 0 {
match cursor.read_uint::<NetworkEndian>(length_length) {
Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => {
return Ok(None);
}
Err(err) => {
return Err(err.into());
}
Ok(read) => read,
const SIZE: usize = mem::size_of::<u64>();
assert!(length_length <= SIZE, "length exceeded size of u64");
let start = SIZE - length_length;
let mut buffer = [0; SIZE];
match cursor.read_exact(&mut buffer[start..]) {
Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => return Ok(None),
Err(err) => return Err(err.into()),
Ok(()) => u64::from_be_bytes(buffer),
}
} else {
u64::from(length_byte)
Expand Down

0 comments on commit c167787

Please sign in to comment.