Debian Codegraph @

src/protocol/statement/row.rs

raw symbols SCIP
1 use 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-mysql 0.8.3 crate/::errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
4 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::iorust-analyzer cargo sqlx-mysql 0.8.3 io/::MySqlBufExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt#;
5 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::iorust-analyzer cargo sqlx-mysql 0.8.3 io/::{BufExtrust-analyzer cargo sqlx-core 0.8.3 io/buf/BufExt#, ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#};
6 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::textrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/::ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#;
7 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::Rowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/row/Row#;
8 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::MySqlColumnrust-analyzer cargo sqlx-mysql 0.8.3 column/MySqlColumn#;
9
10 // https://dev.mysql.com/doc/internals/en/binary-protocol-resultset-row.html#packet-ProtocolBinary::ResultsetRow
11 // https://dev.mysql.com/doc/internals/en/binary-protocol-value.html
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(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) struct BinaryRowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/statement/row/BinaryRow#(pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) Rowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/row/Row#);
15
16 impl<'de> ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#<'de, &'de [MySqlColumnrust-analyzer cargo sqlx-mysql 0.8.3 column/MySqlColumn#]> for BinaryRowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/statement/row/BinaryRow# {
17 fn decode_withrust-analyzer cargo sqlx-mysql 0.8.3 protocol/statement/row/impl#[BinaryRow][`ProtocolDecode<'de, &'de [MySqlColumn]>`]decode_with().(mut buf: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, columns: &'de [MySqlColumnrust-analyzer cargo sqlx-mysql 0.8.3 column/MySqlColumn#]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 protocol/statement/row/impl#[BinaryRow][`ProtocolDecode<'de, &'de [MySqlColumn]>`], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
18 let header = buf.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().();
19 if header rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 {
20 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!!(
21 "exepcted 0x00 (ROW) but found 0x{:02x}",
22 header
23 ));
24 }
25
26 let storage = buf.clonerust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes][Clone]clone().();
27 let offset = buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().();
28
29 let null_bitmap_len = (columns.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 ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().9) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().8;
30 let null_bitmap = buf.get_bytesrust-analyzer cargo sqlx-core 0.8.3 io/buf/impl#[Bytes][BufExt]get_bytes().(null_bitmap_len);
31
32 let mut values = 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().(columns.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
33
34 for (column_idx, column) in columns.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
35 // NOTE: the column index starts at the 3rd bit
36 let column_null_idx = column_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2;
37
38 let byte_idx = column_null_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().8;
39 let bit_idx = column_null_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8;
40
41 let is_null = null_bitmap[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().byte_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().(1u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<usize>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<usize>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<usize>`]shl().bit_idx) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0;
42
43 if is_null {
44 values.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
45 continue;
46 }
47
48 // NOTE: MySQL will never generate NULL types for non-NULL values
49 let type_info = &column.type_inforust-analyzer cargo sqlx-mysql 0.8.3 column/MySqlColumn#type_info.;
50
51 // Unlike Postgres, MySQL does not length-prefix every value in a binary row.
52 // Values are *either* fixed-length or length-prefixed,
53 // so we need to inspect the type code to be sure.
54 let size: usize = match type_info.r#typerust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#`r#type`. {
55 // All fixed-length types.
56 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::LongLongrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#LongLong# => 8,
57 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Longrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Long# | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Int24rust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Int24# => 4,
58 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Shortrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Short# | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Yearrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Year# => 2,
59 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Tinyrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Tiny# => 1,
60 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Floatrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Float# => 4,
61 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Doublerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Double# => 8,
62
63 // Blobs and strings are prefixed with their length,
64 // which is itself a length-encoded integer.
65 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Stringrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#String#
66 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::VarCharrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#VarChar#
67 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::VarStringrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#VarString#
68 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Enumrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Enum#
69 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Setrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Set#
70 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::LongBlobrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#LongBlob#
71 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::MediumBlobrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#MediumBlob#
72 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Blobrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Blob#
73 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::TinyBlobrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#TinyBlob#
74 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Geometryrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Geometry#
75 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Bitrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Bit#
76 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Decimalrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Decimal#
77 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Jsonrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Json#
78 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::NewDecimalrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#NewDecimal# => {
79 let size = buf.get_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_uint_lenenc().();
80 usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u64>`]try_from().(size)
81 .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!!("BLOB length out of range: {size}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
82 }
83
84 // Like strings and blobs, these values are variable-length.
85 // Unlike strings and blobs, however, they exclusively use one byte for length.
86 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Timerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Time#
87 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Timestamprust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Timestamp#
88 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Daterust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Date#
89 | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Datetimerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Datetime# => {
90 // Leave the length byte on the front of the value because decoding uses it.
91 buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1
92 }
93
94 // NOTE: MySQL will never generate NULL types for non-NULL values
95 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Nullrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Null# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
96 };
97
98 let offset = offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().buf.lenrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]len().();
99
100 values.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().size)));
101
102 buf.advancerust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes][Buf]advance().(size);
103 }
104
105 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BinaryRowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/statement/row/BinaryRow#(Rowrust-analyzer cargo sqlx-mysql 0.8.3 protocol/row/Row# { valuesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/row/Row#values., storagerust-analyzer cargo sqlx-mysql 0.8.3 protocol/row/Row#storage. }))
106 }
107 }