mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-11 08:09:55 +00:00
31 lines
784 B
Rust
31 lines
784 B
Rust
use super::Encode;
|
|
use crate::io::BufMut;
|
|
use byteorder::NetworkEndian;
|
|
|
|
pub struct Parse<'a> {
|
|
pub statement: &'a str,
|
|
pub query: &'a str,
|
|
pub param_types: &'a [u32],
|
|
}
|
|
|
|
impl Encode for Parse<'_> {
|
|
fn encode(&self, buf: &mut Vec<u8>) {
|
|
buf.push(b'P');
|
|
|
|
// len + statement + nul + query + null + len(param_types) + param_types
|
|
let len =
|
|
4 + self.statement.len() + 1 + self.query.len() + 1 + 2 + self.param_types.len() * 4;
|
|
|
|
buf.put_i32::<NetworkEndian>(len as i32);
|
|
|
|
buf.put_str_nul(self.statement);
|
|
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_);
|
|
}
|
|
}
|
|
}
|