sqlx_core_guts/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    Portal(Oid),
13}
14
15impl Encode<'_> for Close {
16    fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
17        // 15 bytes for 1-digit statement/portal IDs
18        buf.reserve(20);
19        buf.push(b'C');
20
21        buf.put_length_prefixed(|buf| match self {
22            Close::Statement(id) => {
23                buf.push(CLOSE_STATEMENT);
24                buf.put_statement_name(*id);
25            }
26
27            Close::Portal(id) => {
28                buf.push(CLOSE_PORTAL);
29                buf.put_portal_name(Some(*id));
30            }
31        })
32    }
33}