| 1 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::bytesrust-analyzer cargo bytes 1.12.1 crate/::{Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#, Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#}; |
| 2 | |
| 3 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 4 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::BufExtrust-analyzer cargo sqlx-core 0.8.3 io/buf/BufExt#; |
| 5 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage#, BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#}; |
| 6 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#; |
| 7 | |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 9 | pub struct RowDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/RowDescription# { |
| 10 | pub fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/RowDescription#fields.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Fieldrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#>, |
| 11 | } |
| 12 | |
| 13 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 14 | pub struct Fieldrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field# { |
| 15 | /// The name of the field. |
| 16 | pub namerust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 17 | |
| 18 | /// If the field can be identified as a column of a specific table, the |
| 19 | /// object ID of the table; otherwise zero. |
| 20 | pub relation_idrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#relation_id.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#>, |
| 21 | |
| 22 | /// If the field can be identified as a column of a specific table, the attribute number of |
| 23 | /// the column; otherwise zero. |
| 24 | pub relation_attribute_norust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#relation_attribute_no.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i16>, |
| 25 | |
| 26 | /// The object ID of the field's data type. |
| 27 | pub data_type_idrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#data_type_id.: Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#, |
| 28 | |
| 29 | /// The data type size (see pg_type.typlen). Note that negative values denote |
| 30 | /// variable-width types. |
| 31 | #[allow(dead_code)] |
| 32 | pub data_type_sizerust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#data_type_size.: i16, |
| 33 | |
| 34 | /// The type modifier (see pg_attribute.atttypmod). The meaning of the |
| 35 | /// modifier is type-specific. |
| 36 | #[allow(dead_code)] |
| 37 | pub type_modifierrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#type_modifier.: i32, |
| 38 | |
| 39 | /// The format code being used for the field. |
| 40 | #[allow(dead_code)] |
| 41 | pub formatrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#format.: i16, |
| 42 | } |
| 43 | |
| 44 | impl BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage# for RowDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/RowDescription# { |
| 45 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/impl#[RowDescription][BackendMessage]FORMAT.: BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat# = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::RowDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#RowDescription#; |
| 46 | |
| 47 | fn decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/impl#[RowDescription][BackendMessage]decode_body().(mut buf: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/impl#[RowDescription][BackendMessage], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 48 | if buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 { |
| 49 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!( |
| 50 | "expected at least 2 bytes, got {}", |
| 51 | buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().() |
| 52 | )); |
| 53 | } |
| 54 | |
| 55 | let cnt = buf.get_u16rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u16().(); |
| 56 | let mut fields = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(cnt as usize); |
| 57 | |
| 58 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#cnt { |
| 59 | let name = buf.get_str_nulrust-analyzer cargo sqlx-core 0.8.3 io/buf/impl#[Bytes][BufExt]get_str_nul().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(); |
| 60 | |
| 61 | if buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().18 { |
| 62 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!( |
| 63 | "expected at least 18 bytes after field name {name:?}, got {}", |
| 64 | buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().() |
| 65 | )); |
| 66 | } |
| 67 | |
| 68 | let relation_id = buf.get_u32rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u32().(); |
| 69 | let relation_attribute_no = buf.get_i16rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_i16().(); |
| 70 | let data_type_id = Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#(buf.get_u32rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u32().()); |
| 71 | let data_type_size = buf.get_i16rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_i16().(); |
| 72 | let type_modifier = buf.get_i32rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_i32().(); |
| 73 | let format = buf.get_i16rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_i16().(); |
| 74 | |
| 75 | fields.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Fieldrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field# { |
| 76 | namerust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#name., |
| 77 | relation_idrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#relation_id.: if relation_id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 { |
| 78 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 79 | } else { |
| 80 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#(relation_id)) |
| 81 | }, |
| 82 | relation_attribute_norust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#relation_attribute_no.: if relation_attribute_no rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0 { |
| 83 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 84 | } else { |
| 85 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(relation_attribute_no) |
| 86 | }, |
| 87 | data_type_idrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#data_type_id., |
| 88 | data_type_sizerust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#data_type_size., |
| 89 | type_modifierrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#type_modifier., |
| 90 | formatrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/Field#format., |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/impl#[RowDescription][BackendMessage] { fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/row_description/RowDescription#fields. }) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // TODO: Unit Test RowDescription |
| 99 | // TODO: Benchmark RowDescription |