krabka_protocol/opt/rustwide/workdir/generated/
ProducerIdsRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::fixed::{get_i32, get_i64, put_i32, put_i64},
8 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13#[inline]
14#[must_use]
15pub fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct ProducerIdsRecord {
20 pub broker_id: i32,
21 pub broker_epoch: i64,
22 pub next_producer_id: i64,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Default for ProducerIdsRecord {
26 fn default() -> Self {
27 Self {
28 broker_id: 0i32,
29 broker_epoch: -1i64,
30 next_producer_id: 0i64,
31 unknown_tagged_fields: UnknownTaggedFields::default(),
32 }
33 }
34}
35impl Encode for ProducerIdsRecord {
36 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38 return Err(ProtocolError::SchemaMismatch(
39 "ProducerIdsRecord version out of range",
40 ));
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 put_i32(buf, self.broker_id);
45 }
46 if version >= 0 {
47 put_i64(buf, self.broker_epoch);
48 }
49 if version >= 0 {
50 put_i64(buf, self.next_producer_id);
51 }
52 if flex {
53 let tagged = WriteTaggedFields::new();
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 version >= 0 {
62 n += 4;
63 }
64 if version >= 0 {
65 n += 8;
66 }
67 if version >= 0 {
68 n += 8;
69 }
70 if flex {
71 let known_pairs: Vec<(u32, usize)> = Vec::new();
72 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73 }
74 n
75 }
76}
77impl Decode<'_> for ProducerIdsRecord {
78 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
79 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80 return Err(ProtocolError::SchemaMismatch(
81 "ProducerIdsRecord version out of range",
82 ));
83 }
84 let flex = is_flexible(version);
85 let mut out = Self::default();
86 if version >= 0 {
87 out.broker_id = get_i32(buf)?;
88 }
89 if version >= 0 {
90 out.broker_epoch = get_i64(buf)?;
91 }
92 if version >= 0 {
93 out.next_producer_id = get_i64(buf)?;
94 }
95 if flex {
96 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
97 }
98 Ok(out)
99 }
100}
101#[cfg(test)]
102impl ProducerIdsRecord {
103 #[must_use]
104 pub fn populated(version: i16) -> Self {
105 let mut m = Self::default();
106 if version >= 0 {
107 m.broker_id = 1i32;
108 }
109 if version >= 0 {
110 m.broker_epoch = 1i64;
111 }
112 if version >= 0 {
113 m.next_producer_id = 1i64;
114 }
115 m
116 }
117}
118#[must_use]
121#[allow(unused_comparisons)]
122pub fn default_json(_version: i16) -> ::serde_json::Value {
123 let mut obj = ::serde_json::Map::new();
124 obj.insert("brokerId".to_string(), ::serde_json::json!(0));
125 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
126 obj.insert("nextProducerId".to_string(), ::serde_json::json!(0));
127 ::serde_json::Value::Object(obj)
128}