#[cfg(feature = "encryption")]
use crate::cfb8::{setup_craft_cipher, CipherError, CraftCipher};
use crate::util::{get_sized_buf, VAR_INT_BUF_SIZE};
use crate::wrapper::{CraftIo, CraftWrapper};
#[cfg(feature = "compression")]
use flate2::{DecompressError, FlushDecompress, Status};
use mcproto_rs::protocol::{Id, PacketDirection, RawPacket, State};
#[cfg(feature = "gat")]
use mcproto_rs::protocol::PacketKind;
use mcproto_rs::types::VarInt;
use mcproto_rs::{Deserialize, Deserialized};
#[cfg(feature = "backtrace")]
use std::backtrace::Backtrace;
use std::io;
use thiserror::Error;
#[cfg(any(feature = "futures-io", feature = "tokio-io"))]
use async_trait::async_trait;
pub const DEAFULT_MAX_PACKET_SIZE: usize = 32 * 1000 * 1000; // 32MB
#[derive(Debug, Error)]
pub enum ReadError {
#[error("i/o failure during read")]
IoFailure {
#[from]
err: io::Error,
#[cfg(feature = "backtrace")]
backtrace: Backtrace,
},
#[error("failed to read header VarInt")]
PacketHeaderErr {
#[from]
err: mcproto_rs::DeserializeErr,
#[cfg(feature = "backtrace")]
backtrace: Backtrace,
},
#[error("failed to read packet")]
PacketErr {
#[from]
err: mcproto_rs::protocol::PacketErr,
#[cfg(feature = "backtrace")]
backtrace: Backtrace,
},
#[cfg(feature = "compression")]
#[error("failed to decompress packet")]
DecompressFailed {
#[from]
err: DecompressErr,
#[cfg(feature = "backtrace")]
backtrace: Backtrace,
},
#[error("{size} exceeds max size of {max_size}")]
PacketTooLarge {
size: usize,
max_size: usize,
#[cfg(feature = "backtrace")]
backtrace: Backtrace,
}
}
#[cfg(feature = "compression")]
#[derive(Debug, Error)]
pub enum DecompressErr {
#[error("buf error")]
BufError,
#[error("failure while decompressing")]
Failure(#[from] DecompressError),
}
pub type ReadResult
= Result