Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ macro_rules! test_datatype_roundtrip {
// Ensure serialization is canonical: re-encoding must match the consumed input.
assert_eq!(
encoded,
input[..encoded.get_size()],
input[..encoded.len()],
"Serialization is not stable"
);
}
Expand Down Expand Up @@ -162,7 +162,7 @@ macro_rules! test_datatype_roundtrip {
// reserialization must match the consumed input bytes.
assert_eq!(
encoded,
input[..encoded.get_size()],
input[..encoded.len()],
"{}: Serialization is not stable",
stringify!($datatype)
);
Expand Down
20 changes: 0 additions & 20 deletions sv2/binary-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,3 @@ pub enum Error {
/// elements.
Sv2OptionHaveMoreThenOneElement(u8),
}

/// Vec<u8> is used as the Sv2 type Bytes
impl GetSize for Vec<u8> {
fn get_size(&self) -> usize {
self.len()
}
}

impl From<Vec<u8>> for EncodableField<'_> {
fn from(v: Vec<u8>) -> Self {
EncodableField::Struct(v.into_iter().map(Into::into).collect())
}
}

#[cfg(feature = "with_buffer_pool")]
impl From<buffer_sv2::Slice> for EncodableField<'_> {
fn from(_v: buffer_sv2::Slice) -> Self {
unreachable!()
}
}
15 changes: 9 additions & 6 deletions sv2/framing-sv2/benches/framing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Performance benchmarks for SV2 framing layer operations
//! Tests both Vec and buffer_pool backends across different message sizes

use binary_sv2::Serialize;
use binary_sv2::{B016MOwned, Serialize};
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use framing_sv2::{framing::Sv2Frame, header::Header};

Expand Down Expand Up @@ -42,12 +42,15 @@ fn frame_from_payload_size(size: usize) -> Vec<u8> {

#[derive(Serialize, Clone)]
struct Test {
_a: Vec<u8>,
_a: B016MOwned,
}

impl Test {
// `size` is the total encoded message size: 3-byte B016M length prefix + data
fn new(size: usize) -> Self {
Test { _a: vec![2; size] }
Test {
_a: vec![2; size - 3].try_into().unwrap(),
}
}
}

Expand All @@ -71,7 +74,7 @@ fn bench_serialize(c: &mut Criterion) {

for &size in PAYLOAD_SIZES {
let frame =
Sv2Frame::<Vec<u8>, Slice>::from_bytes(frame_from_payload_size(size).into()).unwrap();
Sv2Frame::<Test, Slice>::from_bytes(frame_from_payload_size(size).into()).unwrap();

let mut buf = vec![0u8; frame.encoded_length()];

Expand All @@ -92,7 +95,7 @@ fn bench_from_bytes(c: &mut Criterion) {
for &size in PAYLOAD_SIZES {
let frame = frame_from_payload_size(size);
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, _| {
b.iter(|| Sv2Frame::<Vec<u8>, _>::from_bytes(black_box(frame.clone())).unwrap())
b.iter(|| Sv2Frame::<Test, _>::from_bytes(black_box(frame.clone())).unwrap())
});
}

Expand All @@ -106,7 +109,7 @@ fn bench_size_hint(c: &mut Criterion) {
for &size in PAYLOAD_SIZES {
let frame = frame_from_payload_size(size);
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, _| {
b.iter(|| Sv2Frame::<Vec<u8>, Slice>::size_hint(black_box(&frame)))
b.iter(|| Sv2Frame::<Test, Slice>::size_hint(black_box(&frame)))
});
}

Expand Down
8 changes: 5 additions & 3 deletions sv2/framing-sv2/src/framing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn update_extension_type(extension_type: u16, channel_msg: bool) -> u16 {
mod tests {
use super::*;
use alloc::vec;
use binary_sv2::Serialize;
use binary_sv2::{B064KOwned, Serialize};
use quickcheck::{Arbitrary, Gen};
use quickcheck_macros::quickcheck;

Expand All @@ -325,7 +325,7 @@ mod tests {

#[derive(Debug, Clone, PartialEq, Serialize)]
struct TestMessage {
data: Vec<u8>,
data: B064KOwned,
}

impl Arbitrary for TestMessage {
Expand Down Expand Up @@ -394,7 +394,9 @@ mod tests {
#[quickcheck]
fn prop_sv2frame_serialization_roundtrip_small(data: Vec<u8>) {
let data: Vec<u8> = data.iter().take(1000).copied().collect();
let msg = TestMessage { data };
let msg = TestMessage {
data: data.try_into().unwrap(),
};
let msg_type = 0x01u8;
let extension_type = 0x0000u16;

Expand Down
Loading