Skip to content

Commit

Permalink
serdect: test that no packing is happening for byte values
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Jun 21, 2023
1 parent abe13c5 commit 6b6ca2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions serdect/tests/bincode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use proptest::{array::*, collection::vec, prelude::*};
use serdect::{array, slice};

/// Example input to be serialized.
const EXAMPLE_BYTES: [u8; 16] = hex!("000102030405060708090A0B0C0D0E0F");
/// Last byte is `0xFF` to test that no packing is performed for values under 128.
const EXAMPLE_BYTES: [u8; 16] = hex!("000102030405060708090A0B0C0D0EFF");

/// bincode serialization of [`EXAMPLE_BYTES`] as a slice.
const BINCODE_SLICE: [u8; 24] = hex!("1000000000000000000102030405060708090A0B0C0D0E0F");
const BINCODE_SLICE: [u8; 24] = hex!("1000000000000000000102030405060708090A0B0C0D0EFF");

/// bincode serialization of [`EXAMPLE_BYTES`] as an array.
const BINCODE_ARRAY: [u8; 16] = EXAMPLE_BYTES;
Expand Down
7 changes: 4 additions & 3 deletions serdect/tests/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ use serde::Serialize;
use serdect::{array, slice};

/// Example input to be serialized.
const EXAMPLE_BYTES: [u8; 16] = hex!("000102030405060708090A0B0C0D0E0F");
/// Last byte is `0xFF` to test that no packing is performed for values under 128.
const EXAMPLE_BYTES: [u8; 16] = hex!("000102030405060708090A0B0C0D0EFF");

/// CBOR serialization of [`EXAMPLE_BYTES`] as a slice.
/// (first three bits, `0b010` denote a byte string, and the last five, `0b10000` denote the length)
const CBOR_SLICE: [u8; 17] = hex!("50000102030405060708090A0B0C0D0E0F");
const CBOR_SLICE: [u8; 17] = hex!("50000102030405060708090A0B0C0D0EFF");

/// CBOR serialization of [`EXAMPLE_BYTES`] as an array.
/// (first three bits, `0b100` denote an array, and the last five, `0b10000` denote the length)
const CBOR_ARRAY: [u8; 17] = hex!("90000102030405060708090A0B0C0D0E0F");
const CBOR_ARRAY: [u8; 17] = hex!("90000102030405060708090A0B0C0D0EFF");

#[test]
fn deserialize_slice() {
Expand Down

0 comments on commit 6b6ca2f

Please sign in to comment.