From 11d279a1b60cff60c3be150bb8dd1213d8b3946b Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 26 Jul 2021 13:07:07 +0200 Subject: [PATCH] StreamFormat -> Into --- scripts/stream_throughput.py | 150 +++++++++++++---------------------- src/net/data_stream.rs | 16 ++-- src/net/mod.rs | 5 +- 3 files changed, 68 insertions(+), 103 deletions(-) diff --git a/scripts/stream_throughput.py b/scripts/stream_throughput.py index 5d6aa16..94bcf66 100644 --- a/scripts/stream_throughput.py +++ b/scripts/stream_throughput.py @@ -14,19 +14,50 @@ import logging # Representation of a single data batch transmitted by Stabilizer. Packet = collections.namedtuple('Packet', ['index', 'data']) -# Specifies a known format for incoming packets. -# -# * `sample_size_bytes` is the number of bytes required for each sample in the batch. -# * `batch_format` is a `struct` format string that will be provided the `batch_size` as an named -# argument. This format string will be used to deserialize each batch of data from the frame. -Format = collections.namedtuple('Format', ['sample_size_bytes', 'batch_format']) +# The magic header half-word at the start of each packet. +MAGIC_HEADER = 0x057B + +# The struct format of the header. +HEADER_FORMAT = ' for u8 { + fn from(format: StreamFormat) -> u8 { + format as u8 + } +} + impl From for SocketAddr { fn from(target: StreamTarget) -> SocketAddr { SocketAddr::new( @@ -184,7 +190,7 @@ pub struct FrameGenerator { pool: &'static Pool<[u8; FRAME_SIZE]>, current_frame: Option, sequence_number: u32, - format: StreamFormat, + format: u8, } impl FrameGenerator { @@ -195,7 +201,7 @@ impl FrameGenerator { Self { queue, pool, - format: StreamFormat::Unknown, + format: StreamFormat::Unknown.into(), current_frame: None, sequence_number: 0, } @@ -209,10 +215,8 @@ impl FrameGenerator { /// # Args /// * `format` - The desired format of the stream. #[doc(hidden)] - pub(crate) fn set_format(&mut self, format: StreamFormat) { - assert!(self.format == StreamFormat::Unknown); - assert!(format != StreamFormat::Unknown); - self.format = format; + pub(crate) fn set_format(&mut self, format: impl Into) { + self.format = format.into(); } /// Add a batch to the current stream frame. diff --git a/src/net/mod.rs b/src/net/mod.rs index fe0a7e9..ca1bb3d 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -113,9 +113,12 @@ where } /// Enable live data streaming. + /// + /// # Args + /// * `format` - A unique u8 code indicating the format of the data. pub fn enable_streaming( &mut self, - format: data_stream::StreamFormat, + format: impl Into, ) -> FrameGenerator { let mut generator = self.generator.take().unwrap(); generator.set_format(format);