sqlx_core_oldapi/postgres/message/
close.rs

1use crate::io::Encode;
2use crate::postgres::io::PgBufMutExt;
3use crate::postgres::types::Oid;
4
5const CLOSE_PORTAL: u8 = b'P';
6const CLOSE_STATEMENT: u8 = b'S';
7
8#[derive(Debug)]
9#[allow(dead_code)]
10pub enum Close {
11    Statement(Oid),
12    // None selects the unnamed portal
13    Portal(Option<Oid>),
14}
15
16impl Encode<'_> for Close {
17    fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
18        // 15 bytes for 1-digit statement/portal IDs
19        buf.reserve(20);
20        buf.push(b'C');
21
22        buf.put_length_prefixed(|buf| match self {
23            Close::Statement(id) => {
24                buf.push(CLOSE_STATEMENT);
25                buf.put_statement_name(*id);
26            }
27
28            Close::Portal(id) => {
29                buf.push(CLOSE_PORTAL);
30                buf.put_portal_name(*id);
31            }
32        })
33    }
34}