-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) struct HexoFile {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
pub(crate) struct ByteBuffer { | ||
inner: Vec<u8>, | ||
} | ||
|
||
impl ByteBuffer { | ||
pub(crate) fn new() -> Self { | ||
ByteBuffer { | ||
inner: Vec::new() | ||
} | ||
} | ||
|
||
pub(crate) fn push_byte(&mut self, byte: u8) { | ||
self.inner.push(byte); | ||
} | ||
|
||
pub(crate) fn push_string(&mut self, string: String) { | ||
self.inner.extend_from_slice(string.as_bytes()); | ||
} | ||
|
||
pub(crate) fn push_u32(&mut self, num: u32) { | ||
self.inner.extend_from_slice(num.to_be_bytes().as_slice()); | ||
} | ||
|
||
pub(crate) fn len(&self) -> usize { | ||
self.inner.len() | ||
} | ||
|
||
pub(crate) fn as_vec(&self) -> Vec<u8> { | ||
self.inner.clone() | ||
} | ||
} | ||
|
||
mod test { | ||
use crate::util::ByteBuffer; | ||
|
||
#[test] | ||
fn byte_push() { | ||
let mut buffer = ByteBuffer::new(); | ||
buffer.push_byte(0x01); | ||
buffer.push_byte(0x02); | ||
|
||
assert_eq!(buffer.len(), 2); | ||
|
||
assert_eq!(buffer.as_vec(), vec![0x01, 0x02]); | ||
} | ||
|
||
#[test] | ||
fn string_push() { | ||
let mut buffer = ByteBuffer::new(); | ||
buffer.push_string("hello world".to_string()); | ||
|
||
assert_eq!(buffer.len(), 11); | ||
|
||
assert_eq!( | ||
buffer.as_vec(), | ||
vec![104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] | ||
); | ||
} | ||
|
||
#[test] | ||
fn u32_push() { | ||
let mut buffer = ByteBuffer::new(); | ||
buffer.push_u32(13); | ||
|
||
assert_eq!(buffer.len(), 4); | ||
|
||
assert_eq!( | ||
buffer.as_vec(), | ||
vec![0, 0, 0, 13] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod byte_buffer; | ||
|
||
pub(crate) use byte_buffer::ByteBuffer; |