mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-04-14 00:10:13 +00:00
refactor(postgres): make better use of traits to improve protocol handling
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use sqlx_core::bytes::{Buf, Bytes};
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::io::{BufExt, Decode};
|
||||
use crate::io::BufExt;
|
||||
use crate::message::{BackendMessage, BackendMessageFormat};
|
||||
use crate::types::Oid;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -40,13 +41,30 @@ pub struct Field {
|
||||
pub format: i16,
|
||||
}
|
||||
|
||||
impl Decode<'_> for RowDescription {
|
||||
fn decode_with(mut buf: Bytes, _: ()) -> Result<Self, Error> {
|
||||
impl BackendMessage for RowDescription {
|
||||
const FORMAT: BackendMessageFormat = BackendMessageFormat::RowDescription;
|
||||
|
||||
fn decode_body(mut buf: Bytes) -> Result<Self, Error> {
|
||||
if buf.len() < 2 {
|
||||
return Err(err_protocol!(
|
||||
"expected at least 2 bytes, got {}",
|
||||
buf.len()
|
||||
));
|
||||
}
|
||||
|
||||
let cnt = buf.get_u16();
|
||||
let mut fields = Vec::with_capacity(cnt as usize);
|
||||
|
||||
for _ in 0..cnt {
|
||||
let name = buf.get_str_nul()?.to_owned();
|
||||
|
||||
if buf.len() < 18 {
|
||||
return Err(err_protocol!(
|
||||
"expected at least 18 bytes after field name {name:?}, got {}",
|
||||
buf.len()
|
||||
));
|
||||
}
|
||||
|
||||
let relation_id = buf.get_i32();
|
||||
let relation_attribute_no = buf.get_i16();
|
||||
let data_type_id = Oid(buf.get_u32());
|
||||
|
||||
Reference in New Issue
Block a user