Debian Codegraph @

src/io/buf_mut.rs

raw symbols SCIP
1 use bytesrust-analyzer cargo bytes 1.12.1 crate/::BufMutrust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut#;
2
3 pub trait MySqlBufMutExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt#: BufMutrust-analyzer cargo bytes 1.12.1 buf/buf_mut/BufMut# {
4 fn put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt#put_uint_lenenc().(&mut self, v: u64);
5
6 fn put_str_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt#put_str_lenenc().(&mut self, v: &str);
7
8 fn put_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt#put_bytes_lenenc().(&mut self, v: &[u8]);
9 }
10
11 impl MySqlBufMutExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
12 fn put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(&mut self, v: u64) {
13 // https://dev.mysql.com/doc/internals/en/integer.html
14 // https://mariadb.com/kb/en/library/protocol-data-types/#length-encoded-integers
15
16 let encoded_le = v.to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_le_bytes().();
17
18 match v {
19 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#250 => self.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(encoded_le[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().),
20 251..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0xFF_FF => {
21 self.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0xfc);
22 self.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&encoded_le[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/range/RangeTo#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
23 }
24 0x1_00_00..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0xFF_FF_FF => {
25 self.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0xfd);
26 self.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&encoded_le[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/range/RangeTo#3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
27 }
28 _ => {
29 self.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0xfe);
30 self.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&encoded_le);
31 }
32 }
33 }
34
35 fn put_str_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_str_lenenc().(&mut self, v: &str) {
36 self.put_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_bytes_lenenc().(v.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
37 }
38
39 fn put_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_bytes_lenenc().(&mut self, v: &[u8]) {
40 self.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64);
41 self.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(v);
42 }
43 }
44
45 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
46 fn test_encodes_int_lenenc_u8rust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_u8().() {
47 let mut buf = 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().(1024);
48 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFA as u64);
49
50 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFA");
51 }
52
53 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
54 fn test_encodes_int_lenenc_u16rust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_u16().() {
55 let mut buf = 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().(1024);
56 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::u16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u16/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u16/MAX. as u64);
57
58 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFF\xFF");
59 }
60
61 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
62 fn test_encodes_int_lenenc_u24rust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_u24().() {
63 let mut buf = 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().(1024);
64 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFF_FF_FF as u64);
65
66 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFD\xFF\xFF\xFF");
67 }
68
69 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
70 fn test_encodes_int_lenenc_u64rust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_u64().() {
71 let mut buf = 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().(1024);
72 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::u64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/MAX.);
73
74 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
75 }
76
77 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
78 fn test_encodes_int_lenenc_fbrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_fb().() {
79 let mut buf = 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().(1024);
80 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFB as u64);
81
82 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFB\x00");
83 }
84
85 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
86 fn test_encodes_int_lenenc_fcrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_fc().() {
87 let mut buf = 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().(1024);
88 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFC as u64);
89
90 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFC\x00");
91 }
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn test_encodes_int_lenenc_fdrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_fd().() {
95 let mut buf = 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().(1024);
96 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFD as u64);
97
98 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFD\x00");
99 }
100
101 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
102 fn test_encodes_int_lenenc_ferust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_fe().() {
103 let mut buf = 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().(1024);
104 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFE as u64);
105
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFE\x00");
107 }
108
109 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
110 fn test_encodes_int_lenenc_ffrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_int_lenenc_ff().() {
111 let mut buf = 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().(1024);
112 buf.put_uint_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_uint_lenenc().(0xFF as u64);
113
114 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\xFC\xFF\x00");
115 }
116
117 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
118 fn test_encodes_string_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_string_lenenc().() {
119 let mut buf = 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().(1024);
120 buf.put_str_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_str_lenenc().("random_string");
121
122 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\x0Drandom_string");
123 }
124
125 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
126 fn test_encodes_byte_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/test_encodes_byte_lenenc().() {
127 let mut buf = 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().(1024);
128 buf.put_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_bytes_lenenc().(b"random_string");
129
130 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buf[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\x0Drandom_string");
131 }