crabka_protocol/opt/rustwide/workdir/generated/
BeginTransactionRecord.owned.rs1use crate::primitives::string_bytes::{
4 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
5 nullable_string_len, put_compact_nullable_string, put_nullable_string,
6};
7use crate::tagged_fields::{
8 WriteTaggedFields, encode_to_bytes, read_tagged_fields, tagged_fields_len,
9};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15
16#[inline]
17fn is_flexible(version: i16) -> bool {
18 version >= FLEXIBLE_MIN
19}
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_none()) {
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 put_compact_nullable_string(b, self.name.as_deref());
46 } else {
47 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_none()) {
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
122#[must_use]
125#[allow(unused_comparisons)]
126pub fn default_json(version: i16) -> ::serde_json::Value {
127 let mut obj = ::serde_json::Map::new();
128 obj.insert("name".to_string(), ::serde_json::Value::Null);
129 ::serde_json::Value::Object(obj)
130}