forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.rs
More file actions
32 lines (24 loc) 路 827 Bytes
/
Copy pathparse.rs
File metadata and controls
32 lines (24 loc) 路 827 Bytes
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
use crate::io::BufMut;
use crate::postgres::protocol::{StatementId, Write};
use byteorder::{ByteOrder, NetworkEndian};
pub struct Parse<'a> {
pub statement: StatementId,
pub query: &'a str,
pub param_types: &'a [u32],
}
impl Write for Parse<'_> {
fn write(&self, buf: &mut Vec<u8>) {
buf.push(b'P');
let pos = buf.len();
buf.put_i32::<NetworkEndian>(0); // skip over len
self.statement.write(buf);
buf.put_str_nul(self.query);
buf.put_i16::<NetworkEndian>(self.param_types.len() as i16);
for &type_ in self.param_types {
buf.put_u32::<NetworkEndian>(type_);
}
// Write-back the len to the beginning of this frame
let len = buf.len() - pos;
NetworkEndian::write_i32(&mut buf[pos..], len as i32);
}
}