summaryrefslogtreecommitdiff
path: root/src/codec/decode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec/decode.rs')
-rw-r--r--src/codec/decode.rs41
1 files changed, 21 insertions, 20 deletions
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<Ctx> Decode<Ctx> for $type {
+ impl<Data> Decode<Data> for $type {
// decode number using big endian
- fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result<Self>
+ fn decode(reader: &mut dyn Read, _: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -21,14 +22,14 @@ macro_rules! impl_decode {
}
/// Read a value from a byte stream
-pub trait Decode<Ctx> {
- fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result<Self>
+pub trait Decode<Data> {
+ fn decode(reader: &mut dyn Read, ctx: &Context<Data>) -> Result<Self>
where
Self: Sized;
}
-impl<Ctx> Decode<Ctx> for bool {
- fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result<Self>
+impl<Data> Decode<Data> for bool {
+ fn decode(reader: &mut dyn Read, _: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -38,8 +39,8 @@ impl<Ctx> Decode<Ctx> for bool {
}
}
-impl<Ctx, T: Decode<Ctx>> Decode<Ctx> for Option<T> {
- fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result<Self>
+impl<Data, T: Decode<Data>> Decode<Data> for Option<T> {
+ fn decode(reader: &mut dyn Read, ctx: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -52,8 +53,8 @@ impl<Ctx, T: Decode<Ctx>> Decode<Ctx> for Option<T> {
}
}
-impl<Ctx, T: Decode<Ctx>> Decode<Ctx> for Vec<T> {
- fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result<Self>
+impl<Data, T: Decode<Data>> Decode<Data> for Vec<T> {
+ fn decode(reader: &mut dyn Read, ctx: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -66,8 +67,8 @@ impl<Ctx, T: Decode<Ctx>> Decode<Ctx> for Vec<T> {
}
}
-impl<Ctx> Decode<Ctx> for String {
- fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result<Self>
+impl<Data> Decode<Data> for String {
+ fn decode(reader: &mut dyn Read, _: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -77,16 +78,16 @@ impl<Ctx> Decode<Ctx> for String {
}
}
-impl<Ctx> Decode<Ctx> for Arc<[u8]> {
- fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result<Self> {
+impl<Data> Decode<Data> for Arc<[u8]> {
+ fn decode(reader: &mut dyn Read, _: &Context<Data>) -> Result<Self> {
let mut buf = Vec::with_capacity(DEFAULT_BUFFER_LEN);
reader.read_to_end(&mut buf)?;
Ok(Arc::<[u8]>::from(buf.into_boxed_slice()))
}
}
-impl<Ctx, const S: usize> Decode<Ctx> for [u8; S] {
- fn decode(reader: &mut dyn Read, _: &mut Ctx) -> Result<Self>
+impl<Data, const S: usize> Decode<Data> for [u8; S] {
+ fn decode(reader: &mut dyn Read, _: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -110,8 +111,8 @@ impl_decode!(i64);
impl_decode!(i128);
impl_decode!(isize);
-impl<Ctx> Decode<Ctx> for f64 {
- fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result<Self>
+impl<Data> Decode<Data> for f64 {
+ fn decode(reader: &mut dyn Read, ctx: &Context<Data>) -> Result<Self>
where
Self: Sized,
{
@@ -121,8 +122,8 @@ impl<Ctx> Decode<Ctx> for f64 {
}
}
-impl<Ctx> Decode<Ctx> for f32 {
- fn decode(reader: &mut dyn Read, ctx: &mut Ctx) -> Result<Self>
+impl<Data> Decode<Data> for f32 {
+ fn decode(reader: &mut dyn Read, ctx: &Context<Data>) -> Result<Self>
where
Self: Sized,
{