codecs/decoding/framing/
mod.rs1#![deny(missing_docs)]
5
6mod bytes;
7mod character_delimited;
8mod chunked_gelf;
9mod length_delimited;
10mod newline_delimited;
11mod octet_counting;
12mod varint_length_delimited;
13
14use std::{any::Any, fmt::Debug};
15
16use ::bytes::Bytes;
17pub use character_delimited::{
18 CharacterDelimitedDecoder, CharacterDelimitedDecoderConfig, CharacterDelimitedDecoderOptions,
19 OversizedAction,
20};
21pub use chunked_gelf::{ChunkedGelfDecoder, ChunkedGelfDecoderConfig, ChunkedGelfDecoderOptions};
22use dyn_clone::DynClone;
23pub use length_delimited::{LengthDelimitedDecoder, LengthDelimitedDecoderConfig};
24pub use newline_delimited::{
25 NewlineDelimitedDecoder, NewlineDelimitedDecoderConfig, NewlineDelimitedDecoderOptions,
26};
27pub use octet_counting::{
28 OctetCountingDecoder, OctetCountingDecoderConfig, OctetCountingDecoderOptions,
29};
30use tokio_util::codec::LinesCodecError;
31pub use varint_length_delimited::{
32 VarintLengthDelimitedDecoder, VarintLengthDelimitedDecoderConfig,
33};
34
35pub use self::bytes::{BytesDecoder, BytesDecoderConfig};
36use super::StreamDecodingError;
37
38pub trait FramingError: std::error::Error + StreamDecodingError + Send + Sync + Any {
45 fn as_any(&self) -> &dyn Any;
48}
49
50impl std::error::Error for BoxedFramingError {}
51
52impl FramingError for std::io::Error {
53 fn as_any(&self) -> &dyn Any {
54 self as &dyn Any
55 }
56}
57
58impl FramingError for LinesCodecError {
59 fn as_any(&self) -> &dyn Any {
60 self as &dyn Any
61 }
62}
63
64impl<T> From<T> for BoxedFramingError
65where
66 T: FramingError + 'static,
67{
68 fn from(value: T) -> Self {
69 Box::new(value)
70 }
71}
72
73pub type BoxedFramingError = Box<dyn FramingError>;
75
76impl StreamDecodingError for BoxedFramingError {
77 fn can_continue(&self) -> bool {
78 self.as_ref().can_continue()
79 }
80}
81
82pub trait Framer:
84 tokio_util::codec::Decoder<Item = Bytes, Error = BoxedFramingError> + DynClone + Debug + Send + Sync
85{
86}
87
88impl<Decoder> Framer for Decoder where
91 Decoder: tokio_util::codec::Decoder<Item = Bytes, Error = BoxedFramingError>
92 + Clone
93 + Debug
94 + Send
95 + Sync
96{
97}
98
99dyn_clone::clone_trait_object!(Framer);
100
101pub type BoxedFramer = Box<dyn Framer>;