| 1 | use byteorderrust-analyzer cargo byteorder 1.5.0 crate/::{BigEndianrust-analyzer cargo byteorder 1.5.0 BigEndian#, ByteOrderrust-analyzer cargo byteorder 1.5.0 ByteOrder#}; |
| 2 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::bytesrust-analyzer cargo bytes 1.12.1 crate/::Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#; |
| 3 | |
| 4 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 5 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage#, BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#}; |
| 6 | |
| 7 | /// Contains cancellation key data. The frontend must save these values if it |
| 8 | /// wishes to be able to issue `CancelRequest` messages later. |
| 9 | #[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:)] |
| 10 | pub struct BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData# { |
| 11 | /// The process ID of this database. |
| 12 | pub process_idrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#process_id.: u32, |
| 13 | |
| 14 | /// The secret key of this database. |
| 15 | pub secret_keyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#secret_key.: u32, |
| 16 | } |
| 17 | |
| 18 | impl BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage# for BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData# { |
| 19 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/impl#[BackendKeyData][BackendMessage]FORMAT.: BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat# = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#BackendKeyData#; |
| 20 | |
| 21 | fn decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/impl#[BackendKeyData][BackendMessage]decode_body().(buf: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/impl#[BackendKeyData][BackendMessage], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 22 | let process_id = BigEndianrust-analyzer cargo byteorder 1.5.0 BigEndian#::read_u32rust-analyzer cargo byteorder 1.5.0 impl#[BigEndian][ByteOrder]read_u32().(&buf); |
| 23 | let secret_key = BigEndianrust-analyzer cargo byteorder 1.5.0 BigEndian#::read_u32rust-analyzer cargo byteorder 1.5.0 impl#[BigEndian][ByteOrder]read_u32().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 24 | |
| 25 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/impl#[BackendKeyData][BackendMessage] { |
| 26 | process_idrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#process_id., |
| 27 | secret_keyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#secret_key., |
| 28 | }) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 33 | fn test_decode_backend_key_datarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/test_decode_backend_key_data().() { |
| 34 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/DATA.: &[u8] = b"\0\0'\xc6\x89R\xc5+"; |
| 35 | |
| 36 | let m = BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/impl#[BackendKeyData][BackendMessage]decode_body().(DATArust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/DATA..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 37 | |
| 38 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.process_idrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#process_id., 10182); |
| 39 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.secret_keyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#secret_key., 2303903019); |
| 40 | } |
| 41 | |
| 42 | #[cfg(all(test, not(debug_assertions)))] |
| 43 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 44 | fn bench_decode_backend_key_data(b: &mut test::Bencher) { |
| 45 | const DATA: &[u8] = b"\0\0'\xc6\x89R\xc5+"; |
| 46 | |
| 47 | b.iter(|| { |
| 48 | BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#::decode_body(test::black_box(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA))).unwrap(); |
| 49 | }); |
| 50 | } |