mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
Removed unused Decoder::decode_eof() method
This commit is contained in:
parent
fe3d48d8fd
commit
b5750c2e43
7 changed files with 91 additions and 117 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [0.6.1] - 2022-01-17
|
||||
|
||||
* Removed unused Decoder::decode_eof() method
|
||||
|
||||
## [0.6.0] - 2021-12-18
|
||||
|
||||
* Remove Framed type
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-codec"
|
||||
version = "0.6.0"
|
||||
version = "0.6.1"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "Utilities for encoding and decoding frames"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
use ntex_bytes::{Bytes, BytesMut};
|
||||
use std::io;
|
||||
|
||||
use super::{Decoder, Encoder};
|
||||
|
||||
/// Bytes codec.
|
||||
///
|
||||
/// Reads/Writes chunks of bytes from a stream.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct BytesCodec;
|
||||
|
||||
impl Encoder for BytesCodec {
|
||||
type Item = Bytes;
|
||||
type Error = io::Error;
|
||||
|
||||
#[inline]
|
||||
fn encode(&self, item: Bytes, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||
dst.extend_from_slice(&item[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for BytesCodec {
|
||||
type Item = BytesMut;
|
||||
type Error = io::Error;
|
||||
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
if src.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
let len = src.len();
|
||||
Ok(Some(src.split_to(len)))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
use ntex_bytes::BytesMut;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Decoding of frames via buffers.
|
||||
pub trait Decoder {
|
||||
/// The type of decoded frames.
|
||||
type Item;
|
||||
|
||||
/// The type of unrecoverable frame decoding errors.
|
||||
///
|
||||
/// If an individual message is ill-formed but can be ignored without
|
||||
/// interfering with the processing of future messages, it may be more
|
||||
/// useful to report the failure as an `Item`.
|
||||
type Error: std::fmt::Debug;
|
||||
|
||||
/// Attempts to decode a frame from the provided buffer of bytes.
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error>;
|
||||
|
||||
/// A default method available to be called when there are no more bytes
|
||||
/// available to be read from the underlying I/O.
|
||||
///
|
||||
/// This method defaults to calling `decode` and returns an error if
|
||||
/// `Ok(None)` is returned while there is unconsumed data in `buf`.
|
||||
/// Typically this doesn't need to be implemented unless the framing
|
||||
/// protocol differs near the end of the stream.
|
||||
fn decode_eof(&self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
match self.decode(buf)? {
|
||||
Some(frame) => Ok(Some(frame)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decoder for Rc<T>
|
||||
where
|
||||
T: Decoder,
|
||||
{
|
||||
type Item = T::Item;
|
||||
type Error = T::Error;
|
||||
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
(**self).decode(src)
|
||||
}
|
||||
|
||||
fn decode_eof(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
(**self).decode_eof(src)
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
use ntex_bytes::BytesMut;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Trait of helper objects to write out messages as bytes.
|
||||
pub trait Encoder {
|
||||
/// The type of items consumed by the `Encoder`
|
||||
type Item;
|
||||
|
||||
/// The type of encoding errors.
|
||||
type Error: std::fmt::Debug;
|
||||
|
||||
/// Encodes a frame into the buffer provided.
|
||||
fn encode(&self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
impl<T> Encoder for Rc<T>
|
||||
where
|
||||
T: Encoder,
|
||||
{
|
||||
type Item = T::Item;
|
||||
type Error = T::Error;
|
||||
|
||||
fn encode(&self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||
(**self).encode(item, dst)
|
||||
}
|
||||
}
|
|
@ -1,10 +1,89 @@
|
|||
#![deny(rust_2018_idioms, warnings)]
|
||||
//! Utilities for encoding and decoding frames.
|
||||
|
||||
mod bcodec;
|
||||
mod decoder;
|
||||
mod encoder;
|
||||
use std::{io, rc::Rc};
|
||||
|
||||
pub use self::bcodec::BytesCodec;
|
||||
pub use self::decoder::Decoder;
|
||||
pub use self::encoder::Encoder;
|
||||
use ntex_bytes::{Bytes, BytesMut};
|
||||
|
||||
/// Trait of helper objects to write out messages as bytes.
|
||||
pub trait Encoder {
|
||||
/// The type of items consumed by the `Encoder`
|
||||
type Item;
|
||||
|
||||
/// The type of encoding errors.
|
||||
type Error: std::fmt::Debug;
|
||||
|
||||
/// Encodes a frame into the buffer provided.
|
||||
fn encode(&self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
/// Decoding of frames via buffers.
|
||||
pub trait Decoder {
|
||||
/// The type of decoded frames.
|
||||
type Item;
|
||||
|
||||
/// The type of unrecoverable frame decoding errors.
|
||||
///
|
||||
/// If an individual message is ill-formed but can be ignored without
|
||||
/// interfering with the processing of future messages, it may be more
|
||||
/// useful to report the failure as an `Item`.
|
||||
type Error: std::fmt::Debug;
|
||||
|
||||
/// Attempts to decode a frame from the provided buffer of bytes.
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error>;
|
||||
}
|
||||
|
||||
impl<T> Encoder for Rc<T>
|
||||
where
|
||||
T: Encoder,
|
||||
{
|
||||
type Item = T::Item;
|
||||
type Error = T::Error;
|
||||
|
||||
fn encode(&self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||
(**self).encode(item, dst)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decoder for Rc<T>
|
||||
where
|
||||
T: Decoder,
|
||||
{
|
||||
type Item = T::Item;
|
||||
type Error = T::Error;
|
||||
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
(**self).decode(src)
|
||||
}
|
||||
}
|
||||
|
||||
/// Bytes codec.
|
||||
///
|
||||
/// Reads/Writes chunks of bytes from a stream.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct BytesCodec;
|
||||
|
||||
impl Encoder for BytesCodec {
|
||||
type Item = Bytes;
|
||||
type Error = io::Error;
|
||||
|
||||
#[inline]
|
||||
fn encode(&self, item: Bytes, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||
dst.extend_from_slice(&item[..]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for BytesCodec {
|
||||
type Item = BytesMut;
|
||||
type Error = io::Error;
|
||||
|
||||
fn decode(&self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
if src.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
let len = src.len();
|
||||
Ok(Some(src.split_to(len)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ glommio = ["ntex-rt/glommio", "ntex-glommio"]
|
|||
async-std = ["ntex-rt/async-std", "ntex-async-std"]
|
||||
|
||||
[dependencies]
|
||||
ntex-codec = "0.6.0"
|
||||
ntex-codec = "0.6.1"
|
||||
ntex-router = "0.5.1"
|
||||
ntex-service = "0.3.1"
|
||||
ntex-macros = "0.1.3"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue