Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin_macro/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn impl_named_fields(fields: Fields) -> (Vec<TokenStream>, Vec<TokenStream>)
pub fn impl_streamable_lazy(name: &Ident, ty: &Type) -> (TokenStream, TokenStream) {
(
quote! { writer.write(&self.#name.parse()?[..])?; },
quote!(#name: #ty::compose(&source, position)?),
quote!(#name: <#ty>::compose(&source, position)?),
)
}

Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use binary_utils::*;

pub const EXPECTED_DEBUG: &[u8] = &[
// packet id
95, // u128 as LE
117, 215, 192, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];

#[derive(BinaryStream)]
pub struct TestPacket {
pub id: u8,
pub width: LE<u128>,
}

#[test]
fn test_varint() {
let test = TestPacket {
id: 95,
width: LE::<u128>(4206942069),
};
assert_eq!(&test.parse().unwrap()[..], EXPECTED_DEBUG);
}
2 changes: 1 addition & 1 deletion tests/macro_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn read_string() {

#[derive(BinaryStream)]
pub struct HelloWorld {
data: LE::<String>,
data: LE<String>,
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// make a test
mod enums;
mod format;
mod le_test;
mod lstring;
mod macro_tests;
Expand Down
4 changes: 2 additions & 2 deletions tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ fn test_le_vec() {

assert_eq!(str_bytes.fparse(), le_bytes_netrex);

let mut test: Vec<LE::<String>> = Vec::new();
let mut test: Vec<LE<String>> = Vec::new();
test.push(str_bytes.clone());

// Vectors store length {stream, stream }
// where "stream" in this case is [length, string bytes]
let vector = test.fparse();
println!("{:?}", vector);
let restored = Vec::<LE::<String>>::fcompose(&vector[..], &mut 0);
let restored = Vec::<LE<String>>::fcompose(&vector[..], &mut 0);
assert_eq!(restored[0].clone().inner(), str_bytes.inner())
}