diff --git a/lading_payload/proptest-regressions/dogstatsd.txt b/lading_payload/proptest-regressions/dogstatsd.txt index 67c691387..9b9fecdc8 100644 --- a/lading_payload/proptest-regressions/dogstatsd.txt +++ b/lading_payload/proptest-regressions/dogstatsd.txt @@ -5,3 +5,4 @@ # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. cc 97158e48115dce6b53c08d3f3744ebd92cb711273b19aee225daa774f71f6e23 # shrinks to seed = 0, max_bytes = 0 +cc 077dc27bd44ddd568537d3742556e1a422619e126a2fbf86c7e7f54374780baf # shrinks to seed = 11798065272331789525, max_bytes = 3627 diff --git a/lading_payload/src/apache_common.rs b/lading_payload/src/apache_common.rs index 13f356247..305ef4d23 100644 --- a/lading_payload/src/apache_common.rs +++ b/lading_payload/src/apache_common.rs @@ -341,7 +341,7 @@ impl<'a> Generator<'a> for ApacheCommon { } impl crate::Serialize for ApacheCommon { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -377,7 +377,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let apache = ApacheCommon::new(&mut rng); + let mut apache = ApacheCommon::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); apache.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/ascii.rs b/lading_payload/src/ascii.rs index 4ead56175..a1847f071 100644 --- a/lading_payload/src/ascii.rs +++ b/lading_payload/src/ascii.rs @@ -29,7 +29,7 @@ impl Ascii { } impl crate::Serialize for Ascii { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -69,7 +69,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let ascii = Ascii::new(&mut rng); + let mut ascii = Ascii::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); ascii.to_bytes(rng, max_bytes, &mut bytes)?; diff --git a/lading_payload/src/block.rs b/lading_payload/src/block.rs index ee4d4828d..c8778ea87 100644 --- a/lading_payload/src/block.rs +++ b/lading_payload/src/block.rs @@ -192,7 +192,7 @@ impl Cache { let blocks = match payload { crate::Config::TraceAgent(enc) => { - let ta = match enc { + let mut ta = match enc { crate::Encoding::Json => crate::TraceAgent::json(&mut rng), crate::Encoding::MsgPack => crate::TraceAgent::msg_pack(&mut rng), }; @@ -200,15 +200,21 @@ impl Cache { let span = span!(Level::INFO, "fixed", payload = "trace-agent"); let _guard = span.enter(); - construct_block_cache_inner(&mut rng, &ta, maximum_block_bytes, total_bytes.get())? + construct_block_cache_inner( + &mut rng, + &mut ta, + maximum_block_bytes, + total_bytes.get(), + )? } crate::Config::Syslog5424 => { let span = span!(Level::INFO, "fixed", payload = "syslog5424"); let _guard = span.enter(); + let mut syslog = crate::Syslog5424::default(); construct_block_cache_inner( &mut rng, - &crate::Syslog5424::default(), + &mut syslog, maximum_block_bytes, total_bytes.get(), )? @@ -221,25 +227,25 @@ impl Cache { return Err(Error::InvalidConfig(e)); } } - let serializer = crate::DogStatsD::new(*conf, &mut rng)?; + let mut serializer = crate::DogStatsD::new(*conf, &mut rng)?; let span = span!(Level::INFO, "fixed", payload = "dogstatsd"); let _guard = span.enter(); construct_block_cache_inner( &mut rng, - &serializer, + &mut serializer, maximum_block_bytes, total_bytes.get(), )? } crate::Config::Fluent => { - let pyld = crate::Fluent::new(&mut rng); + let mut pyld = crate::Fluent::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "fluent"); let _guard = span.enter(); construct_block_cache_inner( &mut rng, - &pyld, + &mut pyld, maximum_block_bytes, total_bytes.get(), )? @@ -247,42 +253,43 @@ impl Cache { crate::Config::SplunkHec { encoding } => { let span = span!(Level::INFO, "fixed", payload = "splunkHec"); let _guard = span.enter(); + let mut splunk_hec = crate::SplunkHec::new(*encoding); construct_block_cache_inner( &mut rng, - &crate::SplunkHec::new(*encoding), + &mut splunk_hec, maximum_block_bytes, total_bytes.get(), )? } crate::Config::ApacheCommon => { - let pyld = crate::ApacheCommon::new(&mut rng); + let mut pyld = crate::ApacheCommon::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "apache-common"); let _guard = span.enter(); construct_block_cache_inner( &mut rng, - &pyld, + &mut pyld, maximum_block_bytes, total_bytes.get(), )? } crate::Config::Ascii => { - let pyld = crate::Ascii::new(&mut rng); + let mut pyld = crate::Ascii::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "ascii"); let _guard = span.enter(); construct_block_cache_inner( &mut rng, - &pyld, + &mut pyld, maximum_block_bytes, total_bytes.get(), )? } crate::Config::DatadogLog => { - let serializer = crate::DatadogLog::new(&mut rng); + let mut serializer = crate::DatadogLog::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "datadog-log"); let _guard = span.enter(); construct_block_cache_inner( &mut rng, - &serializer, + &mut serializer, maximum_block_bytes, total_bytes.get(), )? @@ -290,9 +297,10 @@ impl Cache { crate::Config::Json => { let span = span!(Level::INFO, "fixed", payload = "json"); let _guard = span.enter(); + let mut json = crate::Json; construct_block_cache_inner( &mut rng, - &crate::Json, + &mut json, maximum_block_bytes, total_bytes.get(), )? @@ -300,30 +308,31 @@ impl Cache { crate::Config::Static { static_path } => { let span = span!(Level::INFO, "fixed", payload = "static"); let _guard = span.enter(); + let mut static_serializer = crate::Static::new(static_path)?; construct_block_cache_inner( &mut rng, - &crate::Static::new(static_path)?, + &mut static_serializer, maximum_block_bytes, total_bytes.get(), )? } crate::Config::OpentelemetryTraces => { - let pyld = crate::OpentelemetryTraces::new(&mut rng); + let mut pyld = crate::OpentelemetryTraces::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "otel-traces"); let _guard = span.enter(); - construct_block_cache_inner(rng, &pyld, maximum_block_bytes, total_bytes.get())? + construct_block_cache_inner(rng, &mut pyld, maximum_block_bytes, total_bytes.get())? } crate::Config::OpentelemetryLogs => { - let pyld = crate::OpentelemetryLogs::new(&mut rng); + let mut pyld = crate::OpentelemetryLogs::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "otel-logs"); let _guard = span.enter(); - construct_block_cache_inner(rng, &pyld, maximum_block_bytes, total_bytes.get())? + construct_block_cache_inner(rng, &mut pyld, maximum_block_bytes, total_bytes.get())? } crate::Config::OpentelemetryMetrics => { - let pyld = crate::OpentelemetryMetrics::new(&mut rng); + let mut pyld = crate::OpentelemetryMetrics::new(&mut rng); let span = span!(Level::INFO, "fixed", payload = "otel-metrics"); let _guard = span.enter(); - construct_block_cache_inner(rng, &pyld, maximum_block_bytes, total_bytes.get())? + construct_block_cache_inner(rng, &mut pyld, maximum_block_bytes, total_bytes.get())? } }; @@ -467,7 +476,7 @@ impl Cache { #[allow(clippy::cast_sign_loss)] fn construct_block_cache_inner( mut rng: &mut R, - serializer: &S, + serializer: &mut S, max_block_size: u32, total_bytes: u32, ) -> Result, SpinError> @@ -573,7 +582,7 @@ where #[inline] fn construct_block( mut rng: &mut R, - serializer: &S, + serializer: &mut S, chunk_size: u32, ) -> Result where diff --git a/lading_payload/src/datadog_logs.rs b/lading_payload/src/datadog_logs.rs index e6299e5d4..625d4784c 100644 --- a/lading_payload/src/datadog_logs.rs +++ b/lading_payload/src/datadog_logs.rs @@ -126,7 +126,7 @@ impl<'a> Generator<'a> for DatadogLog { } impl crate::Serialize for DatadogLog { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where W: Write, R: Rng + Sized, @@ -178,7 +178,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let ddlogs = DatadogLog::new(&mut rng); + let mut ddlogs = DatadogLog::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); ddlogs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -197,7 +197,7 @@ mod test { fn every_payload_deserializes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let ddlogs = DatadogLog::new(&mut rng); + let mut ddlogs = DatadogLog::new(&mut rng); let mut bytes: Vec = Vec::with_capacity(max_bytes); ddlogs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/dogstatsd.rs b/lading_payload/src/dogstatsd.rs index fc6938caa..046cde193 100644 --- a/lading_payload/src/dogstatsd.rs +++ b/lading_payload/src/dogstatsd.rs @@ -663,7 +663,12 @@ impl DogStatsD { } impl Serialize for DogStatsD { - fn to_bytes(&self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), crate::Error> + fn to_bytes( + &mut self, + rng: R, + max_bytes: usize, + writer: &mut W, + ) -> Result<(), crate::Error> where R: Rng + Sized, W: Write, @@ -671,7 +676,7 @@ impl Serialize for DogStatsD { if self.length_prefix_framed { self.to_bytes_length_prefix_framed(rng, max_bytes, writer) } else { - self.to_bytes(rng, max_bytes, writer) + self.to_bytes_unframed(rng, max_bytes, writer) } } } @@ -686,7 +691,7 @@ impl DogStatsD { R: Rng + Sized, W: Write, { - let mut bytes_remaining = max_bytes; + let mut bytes_remaining = max_bytes.saturating_sub(std::mem::size_of::()); let mut members = Vec::new(); // generate as many messages as we can fit loop { @@ -733,7 +738,8 @@ impl DogStatsD { Ok(()) } - fn to_bytes( + + fn to_bytes_unframed( &self, mut rng: R, max_bytes: usize, @@ -775,7 +781,7 @@ mod test { use proptest::prelude::*; use rand::{SeedableRng, rngs::SmallRng}; - use crate::DogStatsD; + use crate::{DogStatsD, Serialize}; // We want to be sure that the serialized size of the payload does not // exceed `max_bytes`. @@ -786,11 +792,11 @@ mod test { let mut rng = SmallRng::seed_from_u64(seed); let dogstatsd_config = Config::default(); - let dogstatsd = DogStatsD::new(dogstatsd_config, &mut rng)?; + let mut dogstatsd = DogStatsD::new(dogstatsd_config, &mut rng)?; let mut bytes = Vec::with_capacity(max_bytes); dogstatsd.to_bytes(rng, max_bytes, &mut bytes)?; - debug_assert!( + prop_assert!( bytes.len() <= max_bytes, "{:?}", std::str::from_utf8(&bytes).expect("failed to convert from utf-8 to str") @@ -807,14 +813,15 @@ mod test { let mut rng = SmallRng::seed_from_u64(seed); let dogstatsd_config = Config { length_prefix_framed: true, ..Default::default() }; - let dogstatsd = DogStatsD::new(dogstatsd_config, &mut rng).expect("failed to create DogStatsD"); + let mut dogstatsd = DogStatsD::new(dogstatsd_config, &mut rng).expect("failed to create DogStatsD"); let mut bytes = Vec::with_capacity(max_bytes); dogstatsd.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); - debug_assert!( + prop_assert!( bytes.len() <= max_bytes, - "{:?}", - std::str::from_utf8(&bytes).expect("failed to convert from utf-8 to str") + "{l} <= {max_bytes}, {pyld:?}", + l = bytes.len(), + pyld = std::str::from_utf8(&bytes).expect("failed to convert from utf-8 to str") ); } } diff --git a/lading_payload/src/fluent.rs b/lading_payload/src/fluent.rs index d2279d735..7ff7b71de 100644 --- a/lading_payload/src/fluent.rs +++ b/lading_payload/src/fluent.rs @@ -152,7 +152,7 @@ struct Entry<'a> { } impl crate::Serialize for Fluent { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where W: Write, R: Rng + Sized, @@ -218,7 +218,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let fluent = Fluent::new(&mut rng); + let mut fluent = Fluent::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); fluent.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/json.rs b/lading_payload/src/json.rs index 98f9ef2dd..a3d133ffb 100644 --- a/lading_payload/src/json.rs +++ b/lading_payload/src/json.rs @@ -57,7 +57,7 @@ impl<'a> Generator<'a> for Json { } impl crate::Serialize for Json { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -96,7 +96,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let rng = SmallRng::seed_from_u64(seed); - let json = Json; + let mut json = Json; let mut bytes = Vec::with_capacity(max_bytes); json.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -111,7 +111,7 @@ mod test { fn every_payload_deserializes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let rng = SmallRng::seed_from_u64(seed); - let json = Json; + let mut json = Json; let mut bytes: Vec = Vec::with_capacity(max_bytes); json.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/lib.rs b/lading_payload/src/lib.rs index 3621c9841..b327f030a 100644 --- a/lading_payload/src/lib.rs +++ b/lading_payload/src/lib.rs @@ -91,7 +91,7 @@ pub trait Serialize { /// /// Most implementations are serializing data in some way. The errors that /// result come from serialization crackups. - fn to_bytes(&self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write; @@ -171,7 +171,7 @@ pub(crate) enum Payload { } impl Serialize for Payload { - fn to_bytes(&self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where W: Write, R: Rng + Sized, diff --git a/lading_payload/src/opentelemetry_log.rs b/lading_payload/src/opentelemetry_log.rs index d5a123966..15e3caced 100644 --- a/lading_payload/src/opentelemetry_log.rs +++ b/lading_payload/src/opentelemetry_log.rs @@ -95,7 +95,7 @@ impl<'a> Generator<'a> for OpentelemetryLogs { } impl crate::Serialize for OpentelemetryLogs { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -143,7 +143,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryLogs::new(&mut rng); + let mut logs = OpentelemetryLogs::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -157,7 +157,7 @@ mod test { fn payload_is_at_least_half_of_max_bytes(seed: u64, max_bytes in 16u16..u16::MAX) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryLogs::new(&mut rng); + let mut logs = OpentelemetryLogs::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -173,7 +173,7 @@ mod test { fn payload_deserializes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryLogs::new(&mut rng); + let mut logs = OpentelemetryLogs::new(&mut rng); let mut bytes: Vec = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/opentelemetry_metric.rs b/lading_payload/src/opentelemetry_metric.rs index 47b6698b2..b8feab876 100644 --- a/lading_payload/src/opentelemetry_metric.rs +++ b/lading_payload/src/opentelemetry_metric.rs @@ -167,7 +167,7 @@ impl<'a> Generator<'a> for OpentelemetryMetrics { } impl crate::Serialize for OpentelemetryMetrics { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -213,7 +213,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryMetrics::new(&mut rng); + let mut logs = OpentelemetryMetrics::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -227,7 +227,7 @@ mod test { fn payload_is_at_least_half_of_max_bytes(seed: u64, max_bytes in 16u16..u16::MAX) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryMetrics::new(&mut rng); + let mut logs = OpentelemetryMetrics::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -243,7 +243,7 @@ mod test { fn payload_deserializes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let logs = OpentelemetryMetrics::new(&mut rng); + let mut logs = OpentelemetryMetrics::new(&mut rng); let mut bytes: Vec = Vec::with_capacity(max_bytes); logs.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/opentelemetry_trace.rs b/lading_payload/src/opentelemetry_trace.rs index 990bd0baf..faca7dbd2 100644 --- a/lading_payload/src/opentelemetry_trace.rs +++ b/lading_payload/src/opentelemetry_trace.rs @@ -105,7 +105,7 @@ impl<'a> Generator<'a> for OpentelemetryTraces { } impl crate::Serialize for OpentelemetryTraces { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -152,7 +152,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let traces = OpentelemetryTraces::new(&mut rng); + let mut traces = OpentelemetryTraces::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); traces.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -166,7 +166,7 @@ mod test { fn payload_is_at_least_half_of_max_bytes(seed: u64, max_bytes in 16u16..u16::MAX) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let traces = OpentelemetryTraces::new(&mut rng); + let mut traces = OpentelemetryTraces::new(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); traces.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -182,7 +182,7 @@ mod test { fn payload_deserializes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let traces = OpentelemetryTraces::new(&mut rng); + let mut traces = OpentelemetryTraces::new(&mut rng); let mut bytes: Vec = Vec::with_capacity(max_bytes); traces.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/splunk_hec.rs b/lading_payload/src/splunk_hec.rs index ff92e6c44..d2d82e7d3 100644 --- a/lading_payload/src/splunk_hec.rs +++ b/lading_payload/src/splunk_hec.rs @@ -152,7 +152,7 @@ impl SplunkHec { } impl crate::Serialize for SplunkHec { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -200,7 +200,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let rng = SmallRng::seed_from_u64(seed); - let hec = SplunkHec::default(); + let mut hec = SplunkHec::default(); let mut bytes = Vec::with_capacity(max_bytes); hec.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); @@ -215,7 +215,7 @@ mod test { fn every_payload_deserializes(seed: u64, max_bytes in 0..u16::MAX) { let max_bytes = max_bytes as usize; let rng = SmallRng::seed_from_u64(seed); - let hec = SplunkHec::default(); + let mut hec = SplunkHec::default(); let mut bytes: Vec = Vec::with_capacity(max_bytes); hec.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/statik.rs b/lading_payload/src/statik.rs index da4ed5652..6c3cc598d 100644 --- a/lading_payload/src/statik.rs +++ b/lading_payload/src/statik.rs @@ -69,7 +69,7 @@ impl Static { impl crate::Serialize for Static { fn to_bytes( - &self, + &mut self, mut rng: R, max_bytes: usize, writer: &mut W, diff --git a/lading_payload/src/syslog.rs b/lading_payload/src/syslog.rs index 728c4ae5c..ca52ba1c6 100644 --- a/lading_payload/src/syslog.rs +++ b/lading_payload/src/syslog.rs @@ -100,7 +100,7 @@ impl Member { } impl crate::Serialize for Syslog5424 { - fn to_bytes(&self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -142,7 +142,7 @@ mod test { fn payload_not_exceed_max_bytes(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let rng = SmallRng::seed_from_u64(seed); - let syslog = Syslog5424::default(); + let mut syslog = Syslog5424::default(); let mut bytes = Vec::with_capacity(max_bytes); syslog.to_bytes(rng, max_bytes, &mut bytes).expect("failed to convert to bytes"); diff --git a/lading_payload/src/trace_agent.rs b/lading_payload/src/trace_agent.rs index 2f8dde01d..da5157c2f 100644 --- a/lading_payload/src/trace_agent.rs +++ b/lading_payload/src/trace_agent.rs @@ -194,7 +194,7 @@ impl<'a> Generator<'a> for TraceAgent { } impl crate::Serialize for TraceAgent { - fn to_bytes(&self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> + fn to_bytes(&mut self, mut rng: R, max_bytes: usize, writer: &mut W) -> Result<(), Error> where R: Rng + Sized, W: Write, @@ -279,7 +279,7 @@ mod test { fn payload_not_exceed_max_bytes_json(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let trace_agent = TraceAgent::json(&mut rng); + let mut trace_agent = TraceAgent::json(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); trace_agent.to_bytes(rng, max_bytes, &mut bytes)?; @@ -296,7 +296,7 @@ mod test { fn payload_not_exceed_max_bytes_msg_pack(seed: u64, max_bytes: u16) { let max_bytes = max_bytes as usize; let mut rng = SmallRng::seed_from_u64(seed); - let trace_agent = TraceAgent::json(&mut rng); + let mut trace_agent = TraceAgent::json(&mut rng); let mut bytes = Vec::with_capacity(max_bytes); trace_agent.to_bytes(rng, max_bytes, &mut bytes)?;