pub const REPE_SPEC: u16 = 0x1507;
pub const REPE_VERSION: u8 = 1;
pub const HEADER_SIZE: usize = 48;
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum ErrorCode {
Ok = 0,
VersionMismatch = 1,
InvalidHeader = 2,
InvalidQuery = 3,
InvalidBody = 4,
ParseError = 5,
MethodNotFound = 6,
Timeout = 7,
ResourceExhausted = 8,
InternalError = 9,
ApplicationErrorBase = 4096,
}
impl From<ErrorCode> for u32 {
fn from(v: ErrorCode) -> Self {
v as u32
}
}
impl core::convert::TryFrom<u32> for ErrorCode {
type Error = u32;
fn try_from(value: u32) -> Result<Self, Self::Error> {
let res = match value {
0 => ErrorCode::Ok,
1 => ErrorCode::VersionMismatch,
2 => ErrorCode::InvalidHeader,
3 => ErrorCode::InvalidQuery,
4 => ErrorCode::InvalidBody,
5 => ErrorCode::ParseError,
6 => ErrorCode::MethodNotFound,
7 => ErrorCode::Timeout,
8 => ErrorCode::ResourceExhausted,
9 => ErrorCode::InternalError,
4096 => ErrorCode::ApplicationErrorBase,
_ => return Err(value),
};
Ok(res)
}
}
#[repr(u16)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum QueryFormat {
RawBinary = 0,
JsonPointer = 1,
}
impl From<QueryFormat> for u16 {
fn from(v: QueryFormat) -> Self {
v as u16
}
}
impl core::convert::TryFrom<u16> for QueryFormat {
type Error = u16;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Ok(match value {
0 => QueryFormat::RawBinary,
1 => QueryFormat::JsonPointer,
other => return Err(other),
})
}
}
#[repr(u16)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum BodyFormat {
RawBinary = 0,
Beve = 1, Json = 2,
Utf8 = 3,
}
impl From<BodyFormat> for u16 {
fn from(v: BodyFormat) -> Self {
v as u16
}
}
impl core::convert::TryFrom<u16> for BodyFormat {
type Error = u16;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Ok(match value {
0 => BodyFormat::RawBinary,
1 => BodyFormat::Beve,
2 => BodyFormat::Json,
3 => BodyFormat::Utf8,
other => return Err(other),
})
}
}
impl std::fmt::Display for ErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
ErrorCode::Ok => "OK",
ErrorCode::VersionMismatch => "Version mismatch",
ErrorCode::InvalidHeader => "Invalid header",
ErrorCode::InvalidQuery => "Invalid query",
ErrorCode::InvalidBody => "Invalid body",
ErrorCode::ParseError => "Parse error",
ErrorCode::MethodNotFound => "Method not found",
ErrorCode::Timeout => "Timeout",
ErrorCode::ResourceExhausted => "Resource exhausted",
ErrorCode::InternalError => "Internal error",
ErrorCode::ApplicationErrorBase => "Application error",
};
f.write_str(s)
}
}