| 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/::BufExtrust-analyzer cargo sqlx-core 0.8.3 io/buf/BufExt#; |
| 5 | |
| 6 | pub trait MySqlBufExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt#: Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf# { |
| 7 | // Read a length-encoded integer. |
| 8 | // NOTE: 0xfb or NULL is only returned for binary value encoding to indicate NULL. |
| 9 | // NOTE: 0xff is only returned during a result set to indicate ERR. |
| 10 | // <https://dev.mysql.com/doc/internals/en/integer.html#packet-Protocol::LengthEncodedInteger> |
| 11 | fn get_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt#get_uint_lenenc().(&mut self) -> u64; |
| 12 | |
| 13 | // Read a length-encoded string. |
| 14 | #[allow(dead_code)] |
| 15 | fn get_str_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt#get_str_lenenc().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>; |
| 16 | |
| 17 | // Read a length-encoded byte sequence. |
| 18 | fn get_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt#get_bytes_lenenc().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>; |
| 19 | } |
| 20 | |
| 21 | impl MySqlBufExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/MySqlBufExt# for Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes# { |
| 22 | fn get_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_uint_lenenc().(&mut self) -> u64 { |
| 23 | match self.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().() { |
| 24 | 0xfc => u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(self.get_u16_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u16_le().()), |
| 25 | 0xfd => self.get_uint_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_uint_le().(3), |
| 26 | 0xfe => self.get_u64_lerust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u64_le().(), |
| 27 | |
| 28 | v => u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(v), |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn get_str_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_str_lenenc().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 33 | let size = self.get_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_uint_lenenc().(); |
| 34 | let size = 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) |
| 35 | .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!!("string length overflows usize: {size}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 36 | |
| 37 | self.get_strrust-analyzer cargo sqlx-core 0.8.3 io/buf/impl#[Bytes][BufExt]get_str().(size) |
| 38 | } |
| 39 | |
| 40 | fn get_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_bytes_lenenc().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 41 | let size = self.get_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf/impl#[Bytes][MySqlBufExt]get_uint_lenenc().(); |
| 42 | let size = 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) |
| 43 | .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!!("string length overflows usize: {size}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 44 | |
| 45 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.split_torust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]split_to().(size)) |
| 46 | } |
| 47 | } |