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 /// The state machine has finished successfully.
48 Finished,
49}
50
51/// Asynchronous message from the server.
52///
53/// These can arrive at any time during query execution.
54#[derive(Debug, Clone)]
55pub enum AsyncMessage {
56 /// Notification from LISTEN/NOTIFY.
57 Notification {
58 /// PID of the notifying backend process
59 pid: u32,
60 /// Channel name
61 channel: String,
62 /// Notification payload
63 payload: String,
64 },
65
66 /// Non-fatal notice/warning from server.
67 Notice(ServerError),
68
69 /// Server parameter value changed.
70 ParameterChanged {
71 /// Parameter name
72 name: String,
73 /// New value
74 value: String,
75 },
76}