| 1 | 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#, PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#, StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#}; |
| 2 | 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#}; |
| 3 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 4 | 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#; |
| 5 | |
| 6 | const DESCRIBE_PORTALrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/DESCRIBE_PORTAL.: u8 = b'P'; |
| 7 | const DESCRIBE_STATEMENTrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/DESCRIBE_STATEMENT.: u8 = b'S'; |
| 8 | |
| 9 | /// Note: will emit both a RowDescription and a ParameterDescription message |
| 10 | #[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:)] |
| 11 | #[allow(dead_code)] |
| 12 | pub enum Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe# { |
| 13 | Statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Statement#(StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#), |
| 14 | Portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Portal#(PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#), |
| 15 | } |
| 16 | |
| 17 | impl FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage# for Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe# { |
| 18 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/impl#[Describe][FrontendMessage]FORMAT.: FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat# = FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#::Describerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#Describe#; |
| 19 | |
| 20 | fn body_size_hintrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/impl#[Describe][FrontendMessage]body_size_hint().(&self) -> Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#<usize> { |
| 21 | // Either `DESCRIBE_PORTAL` or `DESCRIBE_STATEMENT` |
| 22 | let mut size = Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#(1); |
| 23 | |
| 24 | match self { |
| 25 | Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Statement#(id) => 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().id.name_lenrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]name_len().(), |
| 26 | Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Portal#(id) => 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().id.name_lenrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[PortalId]name_len().(), |
| 27 | } |
| 28 | |
| 29 | size |
| 30 | } |
| 31 | |
| 32 | fn encode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/impl#[Describe][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#> { |
| 33 | match self { |
| 34 | // #[likely] |
| 35 | Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Statement#(id) => { |
| 36 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DESCRIBE_STATEMENTrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/DESCRIBE_STATEMENT.); |
| 37 | buf.put_statement_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_statement_name().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().id); |
| 38 | } |
| 39 | |
| 40 | Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Portal#(id) => { |
| 41 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DESCRIBE_PORTALrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/DESCRIBE_PORTAL.); |
| 42 | buf.put_portal_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_portal_name().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().id); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | #[cfg(test)] |
| 51 | mod testsrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/ { |
| 52 | 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#; |
| 53 | |
| 54 | use superrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/::{Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#, PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#, StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#}; |
| 55 | |
| 56 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 57 | fn test_encode_describe_portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/test_encode_describe_portal().() { |
| 58 | const EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/EXPECTED.: &[u8] = b"D\0\0\0\x17Psqlx_p_1234567890\0"; |
| 59 | |
| 60 | 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().(); |
| 61 | let m = Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Portal#(PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#::TEST_VALrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[PortalId]TEST_VAL.); |
| 62 | |
| 63 | 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().(); |
| 64 | |
| 65 | 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/describe/tests/EXPECTED.); |
| 66 | } |
| 67 | |
| 68 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 69 | fn test_encode_describe_unnamed_portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/test_encode_describe_unnamed_portal().() { |
| 70 | const EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/EXPECTED.: &[u8] = b"D\0\0\0\x06P\0"; |
| 71 | |
| 72 | 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().(); |
| 73 | let m = Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Portalrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Portal#(PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#::UNNAMEDrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[PortalId]UNNAMED.); |
| 74 | |
| 75 | 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().(); |
| 76 | |
| 77 | 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/describe/tests/EXPECTED.); |
| 78 | } |
| 79 | |
| 80 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 81 | fn test_encode_describe_statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/test_encode_describe_statement().() { |
| 82 | const EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/EXPECTED.: &[u8] = b"D\0\0\0\x17Ssqlx_s_1234567890\0"; |
| 83 | |
| 84 | 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().(); |
| 85 | let m = Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#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.); |
| 86 | |
| 87 | 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().(); |
| 88 | |
| 89 | 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/describe/tests/EXPECTED.); |
| 90 | } |
| 91 | |
| 92 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 93 | fn test_encode_describe_unnamed_statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/test_encode_describe_unnamed_statement().() { |
| 94 | const EXPECTEDrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/tests/EXPECTED.: &[u8] = b"D\0\0\0\x06S\0"; |
| 95 | |
| 96 | 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().(); |
| 97 | let m = Describerust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#::Statementrust-analyzer cargo sqlx-postgres 0.8.3 message/describe/Describe#Statement#(StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#::UNNAMEDrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]UNNAMED.); |
| 98 | |
| 99 | 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().(); |
| 100 | |
| 101 | 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/describe/tests/EXPECTED.); |
| 102 | } |
| 103 | } |