| 1 | use smallvecrust-analyzer cargo smallvec 1.15.2 crate/::SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#; |
| 2 | 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#}; |
| 3 | |
| 4 | 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#; |
| 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 ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription# { |
| 10 | pub typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#<[Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#; 6]>, |
| 11 | } |
| 12 | |
| 13 | impl BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage# for ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription# { |
| 14 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/impl#[ParameterDescription][BackendMessage]FORMAT.: BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat# = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#ParameterDescription#; |
| 15 | |
| 16 | fn decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/impl#[ParameterDescription][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/parameter_description/impl#[ParameterDescription][BackendMessage], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 17 | // Note: this is correct, max parameters is 65535, not 32767 |
| 18 | // https://github.com/launchbadge/sqlx/issues/3464 |
| 19 | let cnt = buf.get_u16rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u16().(); |
| 20 | let mut types = SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#::with_capacityrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]with_capacity().(cnt as usize); |
| 21 | |
| 22 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#cnt { |
| 23 | types.pushrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]push().(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().())); |
| 24 | } |
| 25 | |
| 26 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/impl#[ParameterDescription][BackendMessage] { typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types. }) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 31 | fn test_decode_parameter_descriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/test_decode_parameter_description().() { |
| 32 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/DATA.: &[u8] = b"\x00\x02\x00\x00\x00\x00\x00\x00\x05\x00"; |
| 33 | |
| 34 | let m = ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/impl#[ParameterDescription][BackendMessage]decode_body().(DATArust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/DATA..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 35 | |
| 36 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types..lenrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]len().(), 2); |
| 37 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types.[rust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`][`Index<I>`]index().0]rust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`][`Index<I>`]index()., Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#(0x0000_0000)); |
| 38 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types.[rust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`][`Index<I>`]index().1]rust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`][`Index<I>`]index()., Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#(0x0000_0500)); |
| 39 | } |
| 40 | |
| 41 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 42 | fn test_decode_empty_parameter_descriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/test_decode_empty_parameter_description().() { |
| 43 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/DATA.: &[u8] = b"\x00\x00"; |
| 44 | |
| 45 | let m = ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/impl#[ParameterDescription][BackendMessage]decode_body().(DATArust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/DATA..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 46 | |
| 47 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(m.typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#types..is_emptyrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]is_empty().()); |
| 48 | } |
| 49 | |
| 50 | #[cfg(all(test, not(debug_assertions)))] |
| 51 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 52 | fn bench_decode_parameter_description(b: &mut test::Bencher) { |
| 53 | const DATA: &[u8] = b"\x00\x02\x00\x00\x00\x00\x00\x00\x05\x00"; |
| 54 | |
| 55 | b.iter(|| { |
| 56 | ParameterDescriptionrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_description/ParameterDescription#::decode_body(test::black_box(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA))).unwrap(); |
| 57 | }); |
| 58 | } |