Skip to content

Commit bb4532d

Browse files
Shourya742plebhash
authored andcommitted
remove with_serde feature flag from framing-sv2
1 parent 646b56b commit bb4532d

File tree

6 files changed

+6
-43
lines changed

6 files changed

+6
-43
lines changed

protocols/v2/framing-sv2/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ rand = "0.8.3"
2525
secp256k1 = { version = "0.28.2", default-features = false, features =["alloc","rand","rand-std"] }
2626

2727
[features]
28-
with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2?/with_serde"]
2928
with_buffer_pool = ["binary_sv2/with_buffer_pool", "buffer_sv2"]
3029

3130
[package.metadata.docs.rs]

protocols/v2/framing-sv2/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ cargo add framing_sv2
5757
This crate can be built with the following feature flags:
5858

5959
- `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
60-
- `with_serde`: builds [`binary_sv2`](https://crates.io/crates/binary_sv2) and
61-
[`buffer_sv2`](https://crates.io/crates/buffer_sv2) crates with `serde`-based encoding and
62-
decoding. Note that this feature flag is only used for the Message Generator, and deprecated
63-
for any other kind of usage. It will likely be fully deprecated in the future.
6460

6561
### Examples
6662

6763
This crate provides an example demonstrating how to serialize and deserialize Sv2 message frames:
6864

6965
1. **[Sv2 Frame](https://github.com/stratum-mining/stratum/blob/main/protocols/v2/framing-sv2/examples/sv2_frame.rs)**:
70-
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).
66+
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).

protocols/v2/framing-sv2/examples/sv2_frame.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,22 @@
1414
// ## Run
1515
//
1616
// ```
17-
// cargo run --example sv2_frame --features with_serde
17+
// cargo run --example sv2_frame
1818
// ```
1919

20-
#[cfg(feature = "with_serde")]
21-
use binary_sv2::{GetSize, Serialize};
22-
#[cfg(feature = "with_serde")]
20+
use binary_sv2::{binary_codec_sv2, Serialize};
2321
use framing_sv2::framing::Sv2Frame;
2422

2523
// Example message type (e.g., SetupConnection)
26-
#[cfg(feature = "with_serde")]
2724
const MSG_TYPE: u8 = 1;
2825
// Example extension type (e.g., a standard Sv2 message)
29-
#[cfg(feature = "with_serde")]
3026
const EXT_TYPE: u16 = 0x0001;
3127

32-
#[cfg(feature = "with_serde")]
3328
#[derive(Serialize, Debug)]
34-
struct CustomMessage {
29+
pub struct CustomMessage {
3530
pub data: u32,
3631
}
3732

38-
// Implemented to help determine the size of the message when framing.
39-
#[cfg(feature = "with_serde")]
40-
impl GetSize for CustomMessage {
41-
fn get_size(&self) -> usize {
42-
4 // `data` is `u32`, which is 4 bytes
43-
}
44-
}
45-
46-
#[cfg(feature = "with_serde")]
4733
fn main() {
4834
// Create the message payload
4935
let message = CustomMessage { data: 42 };
@@ -67,11 +53,7 @@ fn main() {
6753
// Deserialize the frame from bytes back into an Sv2Frame
6854
let mut deserialized_frame = Sv2Frame::<CustomMessage, Vec<u8>>::from_bytes(serialized_frame)
6955
.expect("Failed to deserialize frame");
56+
7057
assert_eq!(deserialized_frame.encoded_length(), 10); // 6 header bytes + 4 payload bytes
7158
assert_eq!(deserialized_frame.payload(), [42, 0, 0, 0]);
7259
}
73-
74-
#[cfg(not(feature = "with_serde"))]
75-
fn main() {
76-
eprintln!("Serde feature not enabled. Skipping example.");
77-
}

protocols/v2/framing-sv2/src/framing.rs

-7
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,8 @@ impl<T: Serialize + GetSize, B: AsMut<[u8]> + AsRef<[u8]>> Sv2Frame<T, B> {
8282
dst.swap_with_slice(serialized.as_mut());
8383
Ok(())
8484
} else if let Some(payload) = self.payload {
85-
#[cfg(not(feature = "with_serde"))]
8685
to_writer(self.header, dst).map_err(Error::BinarySv2Error)?;
87-
#[cfg(not(feature = "with_serde"))]
8886
to_writer(payload, &mut dst[Header::SIZE..]).map_err(Error::BinarySv2Error)?;
89-
#[cfg(feature = "with_serde")]
90-
to_writer(&self.header, dst.as_mut()).map_err(Error::BinarySv2Error)?;
91-
#[cfg(feature = "with_serde")]
92-
to_writer(&payload, &mut dst.as_mut()[Header::SIZE..])
93-
.map_err(Error::BinarySv2Error)?;
9487
Ok(())
9588
} else {
9689
// Sv2Frame always has a payload or a serialized payload

protocols/v2/framing-sv2/src/header.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
//! header itself.
2121
2222
use crate::Error;
23-
#[cfg(not(feature = "with_serde"))]
2423
use alloc::vec::Vec;
25-
#[cfg(not(feature = "with_serde"))]
26-
use binary_sv2::binary_codec_sv2;
27-
use binary_sv2::{Deserialize, Serialize, U24};
24+
use binary_sv2::{binary_codec_sv2, Deserialize, Serialize, U24};
2825
use const_sv2::{AEAD_MAC_LEN, SV2_FRAME_CHUNK_SIZE};
2926
use core::convert::TryInto;
3027

protocols/v2/framing-sv2/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
//! This crate can be built with the following features:
4141
//!
4242
//! - `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
43-
//! - `with_serde`: builds [`binary_sv2`] and [`buffer_sv2`](https://crates.io/crates/buffer_sv2)
44-
//! crates with `serde`-based encoding and decoding. Note that this feature flag is only used for
45-
//! the Message Generator, and deprecated for any other kind of usage. It will likely be fully
46-
//! deprecated in the future.
4743
//!
4844
//! ## Examples
4945
//!

0 commit comments

Comments
 (0)