From bb41e396aca01fee9f81785681fac0a79d0fd9d8 Mon Sep 17 00:00:00 2001 From: zirkonya Date: Thu, 27 Aug 2026 09:45:12 +0200 Subject: split event and enhance context --- src/codec/decode.rs | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src/codec/decode.rs') diff --git a/src/codec/decode.rs b/src/codec/decode.rs index fa4ae95..39253a2 100644 --- a/src/codec/decode.rs +++ b/src/codec/decode.rs @@ -1,13 +1,14 @@ //! Decoding: reading protocol values from a byte stream. +use crate::context::Context; use std::{io::Read, sync::Arc}; use crate::{DEFAULT_BUFFER_LEN, codec::error::Result}; macro_rules! impl_decode { ($type: ty) => { - impl Decode for $type { + impl Decode for $type { // decode number using big endian - fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result + fn decode(reader: &mut dyn Read, _: &Context) -> Result where Self: Sized, { @@ -21,14 +22,14 @@ macro_rules! impl_decode { } /// Read a value from a byte stream -pub trait Decode { - fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result +pub trait Decode { + fn decode(reader: &mut dyn Read, ctx: &Context) -> Result where Self: Sized; } -impl Decode for bool { - fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result +impl Decode for bool { + fn decode(reader: &mut dyn Read, _: &Context) -> Result where Self: Sized, { @@ -38,8 +39,8 @@ impl Decode for bool { } } -impl> Decode for Option { - fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result +impl> Decode for Option { + fn decode(reader: &mut dyn Read, ctx: &Context) -> Result where Self: Sized, { @@ -52,8 +53,8 @@ impl> Decode for Option { } } -impl> Decode for Vec { - fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result +impl> Decode for Vec { + fn decode(reader: &mut dyn Read, ctx: &Context) -> Result where Self: Sized, { @@ -66,8 +67,8 @@ impl> Decode for Vec { } } -impl Decode for String { - fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result +impl Decode for String { + fn decode(reader: &mut dyn Read, _: &Context) -> Result where Self: Sized, { @@ -77,16 +78,16 @@ impl Decode for String { } } -impl Decode for Arc<[u8]> { - fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result { +impl Decode for Arc<[u8]> { + fn decode(reader: &mut dyn Read, _: &Context) -> Result { let mut buf = Vec::with_capacity(DEFAULT_BUFFER_LEN); reader.read_to_end(&mut buf)?; Ok(Arc::<[u8]>::from(buf.into_boxed_slice())) } } -impl Decode for [u8; S] { - fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result +impl Decode for [u8; S] { + fn decode(reader: &mut dyn Read, _: &Context) -> Result where Self: Sized, { @@ -110,8 +111,8 @@ impl_decode!(i64); impl_decode!(i128); impl_decode!(isize); -impl Decode for f64 { - fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result +impl Decode for f64 { + fn decode(reader: &mut dyn Read, ctx: &Context) -> Result where Self: Sized, { @@ -121,8 +122,8 @@ impl Decode for f64 { } } -impl Decode for f32 { - fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result +impl Decode for f32 { + fn decode(reader: &mut dyn Read, ctx: &Context) -> Result where Self: Sized, { -- cgit v1.2.3