Debian Codegraph @

src/message/bind.rs

raw symbols SCIP
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 craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#;
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 /// <https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-BIND>
7 ///
8 /// ## Note:
9 ///
10 /// The integer values for number of bind parameters, number of parameter format codes,
11 /// and number of result format codes all are interpreted as *unsigned*!
12 #[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:)]
13 pub struct Bindrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#<'a> {
14 /// The ID of the destination portal (`PortalId::UNNAMED` selects the unnamed portal).
15 pub portalrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#portal.: PortalIdrust-analyzer cargo sqlx-postgres 0.8.3 io/PortalId#,
16
17 /// The id of the source prepared statement.
18 pub statementrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#statement.: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#,
19
20 /// The parameter format codes. Each must presently be zero (text) or one (binary).
21 ///
22 /// There can be zero to indicate that there are no parameters or that the parameters all use the
23 /// default format (text); or one, in which case the specified format code is applied to all
24 /// parameters; or it can equal the actual number of parameters.
25 pub formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats.: &'a [PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#],
26
27 // Note: interpreted as unsigned, as is `formats.len()` and `result_formats.len()`
28 /// The number of parameters.
29 ///
30 /// May be different from `formats.len()`
31 pub num_paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#num_params.: u16,
32
33 /// The value of each parameter, in the indicated format.
34 pub paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#params.: &'a [u8],
35
36 /// The result-column format codes. Each must presently be zero (text) or one (binary).
37 ///
38 /// There can be zero to indicate that there are no result columns or that the
39 /// result columns should all use the default format (text); or one, in which
40 /// case the specified format code is applied to all result columns (if any);
41 /// or it can equal the actual number of result columns of the query.
42 pub result_formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#result_formats.: &'a [PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#],
43 }
44
45 impl FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage# for Bindrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#<'_> {
46 const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/impl#[`Bind<'_>`][FrontendMessage]FORMAT.: FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat# = FrontendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#::Bindrust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessageFormat#Bind#;
47
48 fn body_size_hintrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/impl#[`Bind<'_>`][FrontendMessage]body_size_hint().(&self) -> Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#<usize> {
49 let mut size = Saturatingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/saturating/Saturating#(0);
50 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.portalrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#portal..name_lenrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[PortalId]name_len().();
51 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/bind/Bind#statement..name_lenrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]name_len().();
52
53 // Parameter formats and length prefix
54 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;
55 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.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
56
57 // `num_params`
58 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;
59
60 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.paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#params..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
61
62 // Result formats and length prefix
63 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;
64 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.result_formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#result_formats..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
65
66 size
67 }
68
69 fn encode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/impl#[`Bind<'_>`][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#<(), craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
70 buf.put_portal_namerust-analyzer cargo sqlx-postgres 0.8.3 io/buf_mut/impl#[`Vec<u8>`][PgBufMutExt]put_portal_name().(self.portalrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#portal.);
71
72 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/bind/Bind#statement.);
73
74 // NOTE: the integer values for the number of parameters and format codes in this message
75 // are all interpreted as *unsigned*!
76 //
77 // https://github.com/launchbadge/sqlx/issues/3464
78 let formats_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.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats..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().(|_| {
79 err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("too many parameter format codes ({})", self.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
80 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
81
82 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(formats_len.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_be_bytes().());
83
84 for &format in self.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats. {
85 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().((format as i16).to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]to_be_bytes().());
86 }
87
88 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(self.num_paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#num_params..to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_be_bytes().());
89
90 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(self.paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#params.);
91
92 let result_formats_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.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
93 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("too many result format codes ({})", self.formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#formats..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
94
95 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(result_formats_len.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_be_bytes().());
96
97 for &format in self.result_formatsrust-analyzer cargo sqlx-postgres 0.8.3 message/bind/Bind#result_formats. {
98 buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().((format as i16).to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]to_be_bytes().());
99 }
100
101 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
102 }
103 }
104
105 // TODO: Unit Test Bind
106 // TODO: Benchmark Bind