zero_postgres/protocol/backend/
mod.rs1pub mod auth;
4pub mod copy;
5pub mod error;
6pub mod extended;
7pub mod query;
8
9pub use auth::{
10 AuthenticationMessage, BackendKeyData, NegotiateProtocolVersion, NotificationResponse,
11 ParameterStatus, ReadyForQuery,
12};
13pub use copy::{CopyInResponse, CopyOutResponse};
14pub use super::copy::{CopyData, CopyDone};
16pub use error::{ErrorResponse, NoticeResponse};
17pub use extended::{
18 BindComplete, CloseComplete, NoData, ParameterDescription, ParseComplete, PortalSuspended,
19};
20pub use query::{
21 CommandComplete, DataRow, EmptyQueryResponse, FieldDescriptionTail, RowDescription,
22};
23
24pub mod msg_type {
26 pub const AUTHENTICATION: u8 = b'R';
28 pub const BACKEND_KEY_DATA: u8 = b'K';
30 pub const PARAMETER_STATUS: u8 = b'S';
32 pub const READY_FOR_QUERY: u8 = b'Z';
34 pub const ROW_DESCRIPTION: u8 = b'T';
36 pub const DATA_ROW: u8 = b'D';
38 pub const COMMAND_COMPLETE: u8 = b'C';
40 pub const EMPTY_QUERY_RESPONSE: u8 = b'I';
42 pub const ERROR_RESPONSE: u8 = b'E';
44 pub const NOTICE_RESPONSE: u8 = b'N';
46 pub const NOTIFICATION_RESPONSE: u8 = b'A';
48 pub const PARSE_COMPLETE: u8 = b'1';
50 pub const BIND_COMPLETE: u8 = b'2';
52 pub const CLOSE_COMPLETE: u8 = b'3';
54 pub const PARAMETER_DESCRIPTION: u8 = b't';
56 pub const NO_DATA: u8 = b'n';
58 pub const PORTAL_SUSPENDED: u8 = b's';
60 pub const COPY_IN_RESPONSE: u8 = b'G';
62 pub const COPY_OUT_RESPONSE: u8 = b'H';
64 pub const COPY_BOTH_RESPONSE: u8 = b'W';
66 pub const COPY_DATA: u8 = b'd';
68 pub const COPY_DONE: u8 = b'c';
70 pub const FUNCTION_CALL_RESPONSE: u8 = b'V';
72 pub const NEGOTIATE_PROTOCOL_VERSION: u8 = b'v';
74}
75
76#[derive(Debug, Clone, Copy)]
81pub struct RawMessage<'a> {
82 pub type_byte: u8,
84 pub payload: &'a [u8],
86}
87
88impl<'a> RawMessage<'a> {
89 pub fn new(type_byte: u8, payload: &'a [u8]) -> Self {
91 Self { type_byte, payload }
92 }
93
94 pub fn is_error(&self) -> bool {
96 self.type_byte == msg_type::ERROR_RESPONSE
97 }
98
99 pub fn is_notice(&self) -> bool {
101 self.type_byte == msg_type::NOTICE_RESPONSE
102 }
103
104 pub fn is_notification(&self) -> bool {
106 self.type_byte == msg_type::NOTIFICATION_RESPONSE
107 }
108
109 pub fn is_parameter_status(&self) -> bool {
111 self.type_byte == msg_type::PARAMETER_STATUS
112 }
113
114 pub fn is_async(&self) -> bool {
116 Self::is_async_type(self.type_byte)
117 }
118
119 pub fn is_async_type(type_byte: u8) -> bool {
121 matches!(
122 type_byte,
123 msg_type::NOTICE_RESPONSE
124 | msg_type::NOTIFICATION_RESPONSE
125 | msg_type::PARAMETER_STATUS
126 )
127 }
128}