Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ConfigRecord.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i8, put_i8},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ConfigRecord {
28    pub resource_type: i8,
29    pub resource_name: String,
30    pub name: String,
31    pub value: Option<String>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for ConfigRecord {
35    fn default() -> Self {
36        Self {
37            resource_type: 0i8,
38            resource_name: String::new(),
39            name: String::new(),
40            value: Some(String::new()),
41            unknown_tagged_fields: UnknownTaggedFields::default(),
42        }
43    }
44}
45impl Encode for ConfigRecord {
46    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48            return Err(ProtocolError::SchemaMismatch(
49                "ConfigRecord version out of range",
50            ));
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            put_i8(buf, self.resource_type);
55        }
56        if version >= 0 {
57            if flex {
58                let () = put_compact_string(buf, &self.resource_name);
59            } else {
60                let () = put_string(buf, &self.resource_name);
61            }
62        }
63        if version >= 0 {
64            if flex {
65                let () = put_compact_string(buf, &self.name);
66            } else {
67                let () = put_string(buf, &self.name);
68            }
69        }
70        if version >= 0 {
71            if flex {
72                let () = put_compact_nullable_string(buf, self.value.as_deref());
73            } else {
74                let () = put_nullable_string(buf, self.value.as_deref());
75            }
76        }
77        if flex {
78            let tagged = WriteTaggedFields::new();
79            tagged.write(buf, &self.unknown_tagged_fields);
80        }
81        Ok(())
82    }
83    fn encoded_len(&self, version: i16) -> usize {
84        let flex = is_flexible(version);
85        let mut n: usize = 0;
86        if version >= 0 {
87            n += 1;
88        }
89        if version >= 0 {
90            n += if flex {
91                compact_string_len(&self.resource_name)
92            } else {
93                string_len(&self.resource_name)
94            };
95        }
96        if version >= 0 {
97            n += if flex {
98                compact_string_len(&self.name)
99            } else {
100                string_len(&self.name)
101            };
102        }
103        if version >= 0 {
104            n += if flex {
105                compact_nullable_string_len(self.value.as_deref())
106            } else {
107                nullable_string_len(self.value.as_deref())
108            };
109        }
110        if flex {
111            let known_pairs: Vec<(u32, usize)> = Vec::new();
112            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
113        }
114        n
115    }
116}
117impl Decode<'_> for ConfigRecord {
118    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
119        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
120            return Err(ProtocolError::SchemaMismatch(
121                "ConfigRecord version out of range",
122            ));
123        }
124        let flex = is_flexible(version);
125        let mut out = Self::default();
126        if version >= 0 {
127            out.resource_type = get_i8(buf)?;
128        }
129        if version >= 0 {
130            out.resource_name = if flex {
131                get_compact_string_owned(buf)?
132            } else {
133                get_string_owned(buf)?
134            };
135        }
136        if version >= 0 {
137            out.name = if flex {
138                get_compact_string_owned(buf)?
139            } else {
140                get_string_owned(buf)?
141            };
142        }
143        if version >= 0 {
144            out.value = if flex {
145                get_compact_nullable_string_owned(buf)?
146            } else {
147                get_nullable_string_owned(buf)?
148            };
149        }
150        if flex {
151            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
152        }
153        Ok(out)
154    }
155}
156#[cfg(test)]
157impl ConfigRecord {
158    #[must_use]
159    pub fn populated(version: i16) -> Self {
160        let mut m = Self::default();
161        if version >= 0 {
162            m.resource_type = 1i8;
163        }
164        if version >= 0 {
165            m.resource_name = "x".to_string();
166        }
167        if version >= 0 {
168            m.name = "x".to_string();
169        }
170        if version >= 0 {
171            m.value = Some("x".to_string());
172        }
173        m
174    }
175}
176/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
177/// Only includes fields valid for the given version.
178#[must_use]
179#[allow(unused_comparisons)]
180pub fn default_json(_version: i16) -> ::serde_json::Value {
181    let mut obj = ::serde_json::Map::new();
182    obj.insert("resourceType".to_string(), ::serde_json::json!(0));
183    obj.insert(
184        "resourceName".to_string(),
185        ::serde_json::Value::String(String::new()),
186    );
187    obj.insert(
188        "name".to_string(),
189        ::serde_json::Value::String(String::new()),
190    );
191    obj.insert(
192        "value".to_string(),
193        ::serde_json::Value::String(String::new()),
194    );
195    ::serde_json::Value::Object(obj)
196}