Skip to content

Commit

Permalink
serdect: use serialize_bytes() for serializing bytestrings
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Jun 21, 2023
1 parent 9139bdc commit 02993bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions serdect/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
if serializer.is_human_readable() {
crate::serialize_hex::<_, _, false>(value, serializer)
} else {
value.as_ref().serialize(serializer)
serializer.serialize_bytes(value.as_ref())
}
}

Expand All @@ -35,7 +35,7 @@ where
if serializer.is_human_readable() {
crate::serialize_hex::<_, _, true>(value, serializer)
} else {
value.as_ref().serialize(serializer)
serializer.serialize_bytes(value.as_ref())
}
}

Expand Down
6 changes: 4 additions & 2 deletions serdect/tests/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use serdect::{array, slice};
const EXAMPLE_BYTES: [u8; 16] = hex!("000102030405060708090A0B0C0D0E0F");

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

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

#[test]
fn deserialize_slice() {
Expand Down

0 comments on commit 02993bc

Please sign in to comment.