Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
BeginTransactionRecord.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::string_bytes::{
8        compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
9        nullable_string_len, put_compact_nullable_string, put_nullable_string,
10    },
11    tagged_fields::{WriteTaggedFields, encode_to_bytes, read_tagged_fields, tagged_fields_len},
12};
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17#[must_use]
18pub fn is_flexible(version: i16) -> bool {
19    version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct BeginTransactionRecord {
23    pub name: Option<String>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for BeginTransactionRecord {
27    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29            return Err(ProtocolError::SchemaMismatch(
30                "BeginTransactionRecord version out of range",
31            ));
32        }
33        let flex = is_flexible(version);
34        if flex {
35            let mut tagged = WriteTaggedFields::new();
36            if self.name.is_some() {
37                let payload = encode_to_bytes(
38                    if flex {
39                        compact_nullable_string_len(self.name.as_deref())
40                    } else {
41                        nullable_string_len(self.name.as_deref())
42                    },
43                    |b| {
44                        if flex {
45                            let () = put_compact_nullable_string(b, self.name.as_deref());
46                        } else {
47                            let () = put_nullable_string(b, self.name.as_deref());
48                        }
49                        Ok(())
50                    },
51                );
52                tagged.add(0, payload);
53            }
54            tagged.write(buf, &self.unknown_tagged_fields);
55        }
56        Ok(())
57    }
58    fn encoded_len(&self, version: i16) -> usize {
59        let flex = is_flexible(version);
60        let mut n: usize = 0;
61        if flex {
62            let mut known_pairs: Vec<(u32, usize)> = Vec::new();
63            if self.name.is_some() {
64                known_pairs.push((
65                    0,
66                    if flex {
67                        compact_nullable_string_len(self.name.as_deref())
68                    } else {
69                        nullable_string_len(self.name.as_deref())
70                    },
71                ));
72            }
73            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
74        }
75        n
76    }
77}
78impl Decode<'_> for BeginTransactionRecord {
79    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
80        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
81            return Err(ProtocolError::SchemaMismatch(
82                "BeginTransactionRecord version out of range",
83            ));
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if flex {
88            let mut tag_name = None;
89            out.unknown_tagged_fields = read_tagged_fields(buf, |tag, payload| match tag {
90                0 => {
91                    tag_name = Some({
92                        let b: &mut &[u8] = payload;
93                        if flex {
94                            get_compact_nullable_string_owned(b)?
95                        } else {
96                            get_nullable_string_owned(b)?
97                        }
98                    });
99                    Ok(true)
100                }
101                _ => Ok(false),
102            })?;
103            if let Some(v) = tag_name {
104                out.name = v;
105            }
106        }
107        Ok(out)
108    }
109}
110#[cfg(test)]
111impl BeginTransactionRecord {
112    #[must_use]
113    pub fn populated(version: i16) -> Self {
114        let mut m = Self::default();
115        if version >= 0 {
116            m.name = Some("x".to_string());
117        }
118        m
119    }
120}
121/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
122/// Only includes fields valid for the given version.
123#[must_use]
124#[allow(unused_comparisons)]
125pub fn default_json(_version: i16) -> ::serde_json::Value {
126    let mut obj = ::serde_json::Map::new();
127    obj.insert("name".to_string(), ::serde_json::Value::Null);
128    ::serde_json::Value::Object(obj)
129}
130/// A message with a non-default value in every tagged field, at every depth, for
131/// the JVM oracle differential sweep. The value is the same at every version.
132#[must_use]
133pub fn tagged_fixture() -> BeginTransactionRecord {
134    BeginTransactionRecord {
135        name: Some("x".to_string()),
136        ..BeginTransactionRecord::default()
137    }
138}
139/// The JSON form of `tagged_fixture()` that Kafka's JSON converter reads at
140/// `version`. It holds only the fields that the schema declares at that version.
141#[must_use]
142pub fn tagged_fixture_json(_version: i16) -> ::serde_json::Value {
143    let mut m = ::serde_json::Map::new();
144    m.insert(
145        "name".to_string(),
146        ::serde_json::Value::String("x".to_string()),
147    );
148    ::serde_json::Value::Object(m)
149}