use crate::wire::DEFAULT_MAX_FRAME_BYTES;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Handshake {
None,
AuthCommand,
HelloMandatory,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HelloStyle {
NotUsed,
ArgLess,
MapPayload,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PushPolicy {
Reserved,
Enabled,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorConvention {
None,
Resp3Prefixes,
BracketCode,
Both,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TlsPolicy {
Off,
Optional,
Reserved,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Config {
pub scheme: &'static str,
pub default_port: u16,
pub handshake: Handshake,
pub hello_style: HelloStyle,
pub push: PushPolicy,
pub max_frame_bytes: usize,
pub max_in_flight: usize,
pub error_codes: ErrorConvention,
pub tls: TlsPolicy,
}
impl Config {
pub const fn standard() -> Self {
Self {
scheme: "",
default_port: 0,
handshake: Handshake::HelloMandatory,
hello_style: HelloStyle::MapPayload,
push: PushPolicy::Reserved,
max_frame_bytes: DEFAULT_MAX_FRAME_BYTES,
max_in_flight: 256,
error_codes: ErrorConvention::Both,
tls: TlsPolicy::Off,
}
}
#[must_use]
pub const fn scheme(mut self, scheme: &'static str) -> Self {
self.scheme = scheme;
self
}
#[must_use]
pub const fn port(mut self, port: u16) -> Self {
self.default_port = port;
self
}
#[must_use]
pub const fn handshake(mut self, handshake: Handshake) -> Self {
self.handshake = handshake;
self
}
#[must_use]
pub const fn hello_style(mut self, hello_style: HelloStyle) -> Self {
self.hello_style = hello_style;
self
}
#[must_use]
pub const fn push(mut self, push: PushPolicy) -> Self {
self.push = push;
self
}
#[must_use]
pub const fn max_frame_bytes(mut self, max_frame_bytes: usize) -> Self {
self.max_frame_bytes = max_frame_bytes;
self
}
#[must_use]
pub const fn max_in_flight(mut self, max_in_flight: usize) -> Self {
self.max_in_flight = max_in_flight;
self
}
#[must_use]
pub const fn error_codes(mut self, error_codes: ErrorConvention) -> Self {
self.error_codes = error_codes;
self
}
#[must_use]
pub const fn tls(mut self, tls: TlsPolicy) -> Self {
self.tls = tls;
self
}
}
impl Default for Config {
fn default() -> Self {
Self::standard()
}
}