welds_sqlx_mssql/protocol/
info.rs

1use bytes::{Buf, Bytes};
2
3use crate::error::Error;
4use crate::io::MssqlBufExt;
5
6#[allow(dead_code)]
7#[derive(Debug)]
8pub(crate) struct Info {
9    pub(crate) number: u32,
10    pub(crate) state: u8,
11    pub(crate) class: u8,
12    pub(crate) message: String,
13    pub(crate) server: String,
14    pub(crate) procedure: String,
15    pub(crate) line: u32,
16}
17
18impl Info {
19    pub(crate) fn get(buf: &mut Bytes) -> Result<Self, Error> {
20        let len = buf.get_u16_le();
21        let mut data = buf.split_to(len as usize);
22
23        let number = data.get_u32_le();
24        let state = data.get_u8();
25        let class = data.get_u8();
26        let message = data.get_us_varchar()?;
27        let server = data.get_b_varchar()?;
28        let procedure = data.get_b_varchar()?;
29        let line = data.get_u32_le();
30
31        Ok(Self {
32            number,
33            state,
34            class,
35            message,
36            server,
37            procedure,
38            line,
39        })
40    }
41}
42
43#[test]
44fn test_get() {
45    #[rustfmt::skip]
46    let mut buf = Bytes::from_static(&[
47        0x74, 0, 0x47, 0x16, 0, 0, 1, 0, 0x27, 0, 0x43, 0, 0x68, 0, 0x61, 0, 0x6e, 0, 0x67, 0, 0x65, 0, 0x64, 0, 0x20, 0, 0x6c, 0, 0x61, 0, 0x6e, 0, 0x67, 0, 0x75, 0, 0x61, 0, 0x67, 0, 0x65, 0, 0x20, 0, 0x73, 0, 0x65, 0, 0x74, 0, 0x74, 0, 0x69, 0, 0x6e, 0, 0x67, 0, 0x20, 0, 0x74, 0, 0x6f, 0, 0x20, 0, 0x75, 0, 0x73, 0, 0x5f, 0, 0x65, 0, 0x6e, 0, 0x67, 0, 0x6c, 0, 0x69, 0, 0x73, 0, 0x68, 0, 0x2e, 0, 0xc, 0x61, 0, 0x62, 0, 0x64, 0, 0x30, 0, 0x62, 0, 0x36, 0, 0x37, 0, 0x62, 0, 0x64, 0, 0x34, 0, 0x39, 0, 0x33, 0, 0, 1, 0, 0, 0, 0xad, 0x36, 0, 1, 0x74, 0, 0, 4, 0x16, 0x4d, 0, 0x69, 0, 0x63, 0, 0x72, 0, 0x6f, 0, 0x73, 0, 0x6f, 0, 0x66, 0, 0x74, 0, 0x20, 0, 0x53, 0, 0x51, 0, 0x4c, 0, 0x20, 0, 0x53, 0, 0x65, 0, 0x72, 0, 0x76, 0, 0x65, 0, 0x72, 0, 0, 0, 0, 0, 0xf, 0, 0x10, 0x7f, 0xe3, 0x13, 0, 4, 4, 0x34, 0, 0x30, 0, 0x39, 0, 0x36, 0, 4, 0x34, 0, 0x30, 0, 0x39, 0, 0x36, 0, 0xfd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
48    ]);
49
50    let info = Info::get(&mut buf).unwrap();
51
52    assert_eq!(info.number, 5703);
53    assert_eq!(info.state, 1);
54    assert_eq!(info.class, 0);
55    assert_eq!(info.message, "Changed language setting to us_english.");
56    assert_eq!(info.server, "abd0b67bd493");
57    assert_eq!(info.procedure, "");
58    assert_eq!(info.line, 1);
59}