pub mod auth;
pub mod copy;
pub mod error;
pub mod extended;
pub mod query;
pub use auth::{
AuthenticationMessage, BackendKeyData, NegotiateProtocolVersion, NotificationResponse,
ParameterStatus, ReadyForQuery,
};
pub use copy::{CopyInResponse, CopyOutResponse};
pub use super::copy::{CopyData, CopyDone};
pub use error::{ErrorResponse, NoticeResponse};
pub use extended::{
BindComplete, CloseComplete, NoData, ParameterDescription, ParseComplete, PortalSuspended,
};
pub use query::{
CommandComplete, DataRow, EmptyQueryResponse, FieldDescriptionTail, RowDescription,
};
pub mod msg_type {
pub const AUTHENTICATION: u8 = b'R';
pub const BACKEND_KEY_DATA: u8 = b'K';
pub const PARAMETER_STATUS: u8 = b'S';
pub const READY_FOR_QUERY: u8 = b'Z';
pub const ROW_DESCRIPTION: u8 = b'T';
pub const DATA_ROW: u8 = b'D';
pub const COMMAND_COMPLETE: u8 = b'C';
pub const EMPTY_QUERY_RESPONSE: u8 = b'I';
pub const ERROR_RESPONSE: u8 = b'E';
pub const NOTICE_RESPONSE: u8 = b'N';
pub const NOTIFICATION_RESPONSE: u8 = b'A';
pub const PARSE_COMPLETE: u8 = b'1';
pub const BIND_COMPLETE: u8 = b'2';
pub const CLOSE_COMPLETE: u8 = b'3';
pub const PARAMETER_DESCRIPTION: u8 = b't';
pub const NO_DATA: u8 = b'n';
pub const PORTAL_SUSPENDED: u8 = b's';
pub const COPY_IN_RESPONSE: u8 = b'G';
pub const COPY_OUT_RESPONSE: u8 = b'H';
pub const COPY_BOTH_RESPONSE: u8 = b'W';
pub const COPY_DATA: u8 = b'd';
pub const COPY_DONE: u8 = b'c';
pub const FUNCTION_CALL_RESPONSE: u8 = b'V';
pub const NEGOTIATE_PROTOCOL_VERSION: u8 = b'v';
}
#[derive(Debug, Clone, Copy)]
pub struct RawMessage<'a> {
pub type_byte: u8,
pub payload: &'a [u8],
}
impl<'a> RawMessage<'a> {
pub fn new(type_byte: u8, payload: &'a [u8]) -> Self {
Self { type_byte, payload }
}
pub fn is_error(&self) -> bool {
self.type_byte == msg_type::ERROR_RESPONSE
}
pub fn is_notice(&self) -> bool {
self.type_byte == msg_type::NOTICE_RESPONSE
}
pub fn is_notification(&self) -> bool {
self.type_byte == msg_type::NOTIFICATION_RESPONSE
}
pub fn is_parameter_status(&self) -> bool {
self.type_byte == msg_type::PARAMETER_STATUS
}
pub fn is_async(&self) -> bool {
Self::is_async_type(self.type_byte)
}
pub fn is_async_type(type_byte: u8) -> bool {
matches!(
type_byte,
msg_type::NOTICE_RESPONSE
| msg_type::NOTIFICATION_RESPONSE
| msg_type::PARAMETER_STATUS
)
}
}