| 1 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::BufMutExtrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/BufMutExt#; |
| 2 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::{PgBufMutExtrust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/PgBufMutExt#, StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#}; |
| 3 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage#, FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#}; |
| 4 | 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#; |
| 5 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#; |
| 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 Parserust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#<'a> { |
| 10 | /// The ID of the destination prepared statement. |
| 11 | pub statementrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#statement.: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#, |
| 12 | |
| 13 | /// The query string to be parsed. |
| 14 | pub queryrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#query.: &'a str, |
| 15 | |
| 16 | /// The parameter data types specified (could be zero). Note that this is not an |
| 17 | /// indication of the number of parameters that might appear in the query string, |
| 18 | /// only the number that the frontend wants to pre-specify types for. |
| 19 | pub param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types.: &'a [Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#], |
| 20 | } |
| 21 | |
| 22 | impl FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage# for Parserust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#<'_> { |
| 23 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/impl#[`Parse<'_>`][FrontendMessage]FORMAT.: FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat# = FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#::Parserust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#Parse#; |
| 24 | |
| 25 | fn body_size_hintrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/impl#[`Parse<'_>`][FrontendMessage]body_size_hint().(&self) -> Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#<usize> { |
| 26 | let mut size = Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#(0); |
| 27 | |
| 28 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<Self>`]add_assign().self.statementrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#statement..name_lenrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]name_len().(); |
| 29 | |
| 30 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().self.queryrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#query..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(); |
| 31 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().1; // NUL terminator |
| 32 | |
| 33 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().2; // param_types_len |
| 34 | |
| 35 | // `param_types` |
| 36 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/impl#[`Saturating<usize>`][`AddAssign<usize>`]add_assign().self.param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().().saturating_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_mul().(4); |
| 37 | |
| 38 | size |
| 39 | } |
| 40 | |
| 41 | fn encode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/impl#[`Parse<'_>`][FrontendMessage]encode_body().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 42 | buf.put_statement_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_statement_name().(self.statementrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#statement.); |
| 43 | |
| 44 | buf.put_str_nulrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/impl#[`Vec<u8>`][BufMutExt]put_str_nul().(self.queryrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#query.); |
| 45 | |
| 46 | // Note: actually interpreted as unsigned |
| 47 | // https://github.com/launchbadge/sqlx/issues/3464 |
| 48 | let param_types_len = u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u16][`TryFrom<usize>`]try_from().(self.param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 49 | err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!( |
| 50 | "param_types.len() too large for binary protocol: {}", |
| 51 | self.param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 52 | ) |
| 53 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 54 | |
| 55 | buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(param_types_len.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_be_bytes().()); |
| 56 | |
| 57 | for &oid in self.param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types. { |
| 58 | buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(oid.0rust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#0..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().()); |
| 59 | } |
| 60 | |
| 61 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 66 | fn test_encode_parserust-analyzer cargo sqlx-postgres 0.8.3 message/parse/test_encode_parse().() { |
| 67 | const EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/EXPECTED.: &[u8] = b"P\0\0\0\x26sqlx_s_1234567890\0SELECT $1\0\0\x01\0\0\0\x19"; |
| 68 | |
| 69 | let mut buf = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 70 | let m = Parserust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse# { |
| 71 | statementrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#statement.: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#::TEST_VALrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]TEST_VAL., |
| 72 | queryrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#query.: "SELECT $1", |
| 73 | param_typesrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/Parse#param_types.: &[Oidrust-analyzer cargo sqlx-postgres 0.8.3 types/oid/Oid#(25)], |
| 74 | }; |
| 75 | |
| 76 | m.encode_msgrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage#encode_msg().(&mut buf).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 77 | |
| 78 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf, EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/parse/EXPECTED.); |
| 79 | } |