1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::postgres::types::Oid;
pub trait PgBufMutExt {
fn put_length_prefixed<F>(&mut self, f: F)
where
F: FnOnce(&mut Vec<u8>);
fn put_statement_name(&mut self, id: Oid);
fn put_portal_name(&mut self, id: Option<Oid>);
}
impl PgBufMutExt for Vec<u8> {
fn put_length_prefixed<F>(&mut self, f: F)
where
F: FnOnce(&mut Vec<u8>),
{
let offset = self.len();
self.extend(&[0; 4]);
f(self);
let size = (self.len() - offset) as i32;
self[offset..(offset + 4)].copy_from_slice(&size.to_be_bytes());
}
#[inline]
fn put_statement_name(&mut self, id: Oid) {
self.extend(b"sqlx_s_");
self.extend(itoa::Buffer::new().format(id.0).as_bytes());
self.push(0);
}
#[inline]
fn put_portal_name(&mut self, id: Option<Oid>) {
if let Some(id) = id {
self.extend(b"sqlx_p_");
self.extend(itoa::Buffer::new().format(id.0).as_bytes());
}
self.push(0);
}
}