crabka_protocol/opt/rustwide/workdir/generated/
AddOffsetsToTxnRequest.owned.rs1use crate::primitives::fixed::{get_i16, get_i64, put_i16, put_i64};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6 string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 25;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 4;
14pub const FLEXIBLE_MIN: i16 = 3;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17 version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct AddOffsetsToTxnRequest {
21 pub transactional_id: String,
22 pub producer_id: i64,
23 pub producer_epoch: i16,
24 pub group_id: String,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl Encode for AddOffsetsToTxnRequest {
28 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30 return Err(ProtocolError::UnsupportedVersion {
31 api_key: API_KEY,
32 version,
33 });
34 }
35 let flex = is_flexible(version);
36 if version >= 0 {
37 if flex {
38 put_compact_string(buf, &self.transactional_id);
39 } else {
40 put_string(buf, &self.transactional_id);
41 }
42 }
43 if version >= 0 {
44 put_i64(buf, self.producer_id);
45 }
46 if version >= 0 {
47 put_i16(buf, self.producer_epoch);
48 }
49 if version >= 0 {
50 if flex {
51 put_compact_string(buf, &self.group_id);
52 } else {
53 put_string(buf, &self.group_id);
54 }
55 }
56 if flex {
57 let tagged = WriteTaggedFields::new();
58 tagged.write(buf, &self.unknown_tagged_fields);
59 }
60 Ok(())
61 }
62 fn encoded_len(&self, version: i16) -> usize {
63 let flex = is_flexible(version);
64 let mut n: usize = 0;
65 if version >= 0 {
66 n += if flex {
67 compact_string_len(&self.transactional_id)
68 } else {
69 string_len(&self.transactional_id)
70 };
71 }
72 if version >= 0 {
73 n += 8;
74 }
75 if version >= 0 {
76 n += 2;
77 }
78 if version >= 0 {
79 n += if flex {
80 compact_string_len(&self.group_id)
81 } else {
82 string_len(&self.group_id)
83 };
84 }
85 if flex {
86 let known_pairs: Vec<(u32, usize)> = Vec::new();
87 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88 }
89 n
90 }
91}
92impl Decode<'_> for AddOffsetsToTxnRequest {
93 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
94 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95 return Err(ProtocolError::UnsupportedVersion {
96 api_key: API_KEY,
97 version,
98 });
99 }
100 let flex = is_flexible(version);
101 let mut out = Self::default();
102 if version >= 0 {
103 out.transactional_id = if flex {
104 get_compact_string_owned(buf)?
105 } else {
106 get_string_owned(buf)?
107 };
108 }
109 if version >= 0 {
110 out.producer_id = get_i64(buf)?;
111 }
112 if version >= 0 {
113 out.producer_epoch = get_i16(buf)?;
114 }
115 if version >= 0 {
116 out.group_id = if flex {
117 get_compact_string_owned(buf)?
118 } else {
119 get_string_owned(buf)?
120 };
121 }
122 if flex {
123 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
124 }
125 Ok(out)
126 }
127}
128#[cfg(test)]
129impl AddOffsetsToTxnRequest {
130 #[must_use]
131 pub fn populated(version: i16) -> Self {
132 let mut m = Self::default();
133 if version >= 0 {
134 m.transactional_id = "x".to_string();
135 }
136 if version >= 0 {
137 m.producer_id = 1i64;
138 }
139 if version >= 0 {
140 m.producer_epoch = 1i16;
141 }
142 if version >= 0 {
143 m.group_id = "x".to_string();
144 }
145 m
146 }
147}
148#[must_use]
151#[allow(unused_comparisons)]
152pub fn default_json(version: i16) -> ::serde_json::Value {
153 let mut obj = ::serde_json::Map::new();
154 obj.insert(
155 "transactionalId".to_string(),
156 ::serde_json::Value::String(String::new()),
157 );
158 obj.insert("producerId".to_string(), ::serde_json::json!(0));
159 obj.insert("producerEpoch".to_string(), ::serde_json::json!(0));
160 obj.insert(
161 "groupId".to_string(),
162 ::serde_json::Value::String(String::new()),
163 );
164 ::serde_json::Value::Object(obj)
165}
166impl crate::ProtocolRequest for AddOffsetsToTxnRequest {
167 const API_KEY: i16 = API_KEY;
168 const MIN_VERSION: i16 = MIN_VERSION;
169 const MAX_VERSION: i16 = MAX_VERSION;
170 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
171 type Response = super::add_offsets_to_txn_response::AddOffsetsToTxnResponse;
172}