inspect_proto/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! A generic protobuf service for inspect.
5
6#![expect(missing_docs)]
7#![forbid(unsafe_code)]
8
9// Crates used by generated code. Reference them explicitly to ensure that
10// automated tools do not remove them.
11
12use mesh_rpc as _;
13use prost as _;
14
15include!(concat!(env!("OUT_DIR"), "/inspect.rs"));
16
17/// Equivalent to [`InspectResponse`], but using [`inspect::Node`].
18/// These have equivalent encodings.
19#[derive(Debug, Clone, mesh::MeshPayload)]
20pub struct InspectResponse2 {
21    #[mesh(1)]
22    pub result: inspect::Node,
23}
24
25/// Equivalent to [`InspectResponse`], but using [`inspect::Value`].
26/// These have equivalent encodings.
27#[derive(Debug, Clone, mesh::MeshPayload)]
28pub struct UpdateResponse2 {
29    #[mesh(1)]
30    pub new_value: inspect::Value,
31}
32
33#[cfg(test)]
34mod tests {
35    use crate::InspectResponse;
36    use crate::InspectResponse2;
37    use inspect::Entry;
38    use inspect::Error;
39    use inspect::Node;
40    use inspect::SensitivityLevel;
41    use inspect::Value;
42    use inspect::ValueKind;
43    use mesh::Message;
44
45    #[test]
46    fn test() {
47        let response2 = InspectResponse2 {
48            result: Node::Dir(vec![
49                Entry {
50                    name: "a".to_string(),
51                    node: Node::Unevaluated,
52                    sensitivity: SensitivityLevel::Unspecified,
53                },
54                Entry {
55                    name: "b".to_string(),
56                    node: Node::Failed(Error::Update("foo".into())),
57                    sensitivity: SensitivityLevel::Safe,
58                },
59                Entry {
60                    name: "c".to_string(),
61                    node: Node::Value(Value::new(ValueKind::Signed(-1))),
62                    sensitivity: SensitivityLevel::Sensitive,
63                },
64                Entry {
65                    name: "d".to_string(),
66                    node: Node::Value(Value::new(ValueKind::Unsigned(2))),
67                    sensitivity: SensitivityLevel::Safe,
68                },
69                Entry {
70                    name: "e".to_string(),
71                    node: Node::Value(Value::new(ValueKind::Bool(true))),
72                    sensitivity: SensitivityLevel::Sensitive,
73                },
74                Entry {
75                    name: "f".to_string(),
76                    node: Node::Value(Value::new(ValueKind::String("foo".to_string()))),
77                    sensitivity: SensitivityLevel::Unspecified,
78                },
79            ]),
80        };
81
82        let response = Message::new(response2.clone())
83            .parse::<InspectResponse>()
84            .unwrap();
85
86        assert_eq!(
87            Message::new(response)
88                .parse::<InspectResponse2>()
89                .unwrap()
90                .result,
91            response2.result
92        );
93    }
94}