Skip to main content

zero_postgres/state/
action.rs

1//! Action types for state machine I/O requests.
2
3use crate::error::ServerError;
4
5/// Action requested by a state machine.
6///
7/// The caller should perform the requested I/O and then call the
8/// appropriate method to continue the state machine.
9#[derive(Debug)]
10pub enum Action {
11    /// Write `buffer_set.write_buffer` to the server, then read a single byte.
12    ///
13    /// Used for SSL negotiation: write SSL request, then read response ('S' or 'N').
14    WriteAndReadByte,
15
16    /// Read a PostgreSQL message from the server.
17    ///
18    /// The caller should:
19    /// 1. Read the message type byte (1 byte)
20    /// 2. Read the length (4 bytes, big-endian i32)
21    /// 3. Read (length - 4) bytes of payload into the buffer set
22    /// 4. Call the state machine's `step()` method again
23    ReadMessage,
24
25    /// Write `buffer_set.write_buffer` to the server.
26    ///
27    /// The caller should write all bytes to the socket and flush,
28    /// then call `step()` again.
29    Write,
30
31    /// Write `buffer_set.write_buffer` to the server, then read a message.
32    ///
33    /// Used for query operations: write query, then read response.
34    WriteAndReadMessage,
35
36    /// Perform TLS handshake.
37    ///
38    /// After successful handshake, call `step()` again.
39    TlsHandshake,
40
41    /// An asynchronous message was received.
42    ///
43    /// The caller should handle the message, read the next message,
44    /// then call `step()` again.
45    HandleAsyncMessageAndReadMessage(AsyncMessage),
46
47    /// A server error occurred, but the connection is clean (ReadyForQuery received).
48    /// The driver should return this error to the caller.
49    Error(crate::error::ServerError),
50
51    /// The state machine has finished successfully.
52    Finished,
53}
54
55/// Asynchronous message from the server.
56///
57/// These can arrive at any time during query execution.
58#[derive(Debug, Clone)]
59pub enum AsyncMessage {
60    /// Notification from LISTEN/NOTIFY.
61    Notification {
62        /// PID of the notifying backend process
63        pid: u32,
64        /// Channel name
65        channel: String,
66        /// Notification payload
67        payload: String,
68    },
69
70    /// Non-fatal notice/warning from server.
71    Notice(ServerError),
72
73    /// Server parameter value changed.
74    ParameterChanged {
75        /// Parameter name
76        name: String,
77        /// New value
78        value: String,
79    },
80}