1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// declare a [`cm_rust::ConfigValueType`] from a shorthand similar to the CML syntax
#[macro_export]
macro_rules! config_ty {
    (bool) => {
        cm_rust::ConfigValueType::Bool
    };
    (uint8) => {
        cm_rust::ConfigValueType::Uint8
    };
    (uint16) => {
        cm_rust::ConfigValueType::Uint16
    };
    (uint32) => {
        cm_rust::ConfigValueType::Uint32
    };
    (uint64) => {
        cm_rust::ConfigValueType::Uint64
    };
    (int8) => {
        cm_rust::ConfigValueType::Int8
    };
    (int16) => {
        cm_rust::ConfigValueType::Int16
    };
    (int32) => {
        cm_rust::ConfigValueType::Int32
    };
    (int64) => {
        cm_rust::ConfigValueType::Int64
    };
    (string, max_size: $size:expr ) => {
        cm_rust::ConfigValueType::String { max_size: $size }
    };
    (vector, element: bool, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Bool,
        }
    };
    (vector, element: uint8, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Uint8,
        }
    };
    (vector, element: uint16, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Uint16,
        }
    };
    (vector, element: uint32, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Uint32,
        }
    };
    (vector, element: uint64, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Uint64,
        }
    };
    (vector, element: int8, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Int8,
        }
    };
    (vector, element: int16, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Int16,
        }
    };
    (vector, element: int32, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Int32,
        }
    };
    (vector, element: int64, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::Int64,
        }
    };
    (vector, element: { string, max_size: $size:expr }, max_count: $count:expr ) => {
        cm_rust::ConfigValueType::Vector {
            max_count: $count,
            nested_type: cm_rust::ConfigNestedValueType::String { max_size: $size },
        }
    };
}

/// shorthand for declaring config decls since we don't want to depend on cmc here
#[macro_export]
macro_rules! config_decl {
    (ck@ $checksum:expr, $($key:ident: { $($type_toks:tt)+ },)*) => {{
        let mut fields = vec![];
        $(
            fields.push(cm_rust::ConfigField {
                key: stringify!($key).to_string(),
                type_: $crate::config_ty!($($type_toks)+ ),
                mutability: Default::default(),
            });
        )*
        cm_rust::ConfigDecl {
            fields,
            checksum: $checksum,
            value_source: cm_rust::ConfigValueSource::PackagePath("fake.cvf".to_string()),
        }
    }};
}

/// wraps a list of values in the verbose optional table elements
#[macro_export]
macro_rules! values_data {
    [ck@ $checksum:expr, $($value:expr,)*] => {{
        let mut values = vec![];
        $(
            values.push(cm_rust::ConfigValueSpec {
                value: $value,
            });
        )*
        cm_rust::ConfigValuesData {
            values,
            checksum: $checksum
        }
    }};
}