krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitKey.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i32, put_i32},
8 string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9 string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10 },
11};
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 32767;
15#[inline]
16#[must_use]
17pub fn is_flexible(version: i16) -> bool {
18 version == FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct OffsetCommitKey<'a> {
22 pub group: &'a str,
23 pub topic: &'a str,
24 pub partition: i32,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl OffsetCommitKey<'_> {
28 #[must_use]
32 pub fn to_owned(&self) -> crate::owned::offset_commit_key::OffsetCommitKey {
33 crate::owned::offset_commit_key::OffsetCommitKey {
34 group: (self.group).to_string(),
35 topic: (self.topic).to_string(),
36 partition: (self.partition),
37 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
38 }
39 }
40}
41impl Encode for OffsetCommitKey<'_> {
42 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
43 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
44 return Err(ProtocolError::SchemaMismatch(
45 "OffsetCommitKey version out of range",
46 ));
47 }
48 let flex = is_flexible(version);
49 if version == 0 {
50 if flex {
51 let () = put_compact_string(buf, self.group);
52 } else {
53 let () = put_string(buf, self.group);
54 }
55 }
56 if version == 0 {
57 if flex {
58 let () = put_compact_string(buf, self.topic);
59 } else {
60 let () = put_string(buf, self.topic);
61 }
62 }
63 if version == 0 {
64 put_i32(buf, self.partition);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version == 0 {
72 n += if flex {
73 compact_string_len(self.group)
74 } else {
75 string_len(self.group)
76 };
77 }
78 if version == 0 {
79 n += if flex {
80 compact_string_len(self.topic)
81 } else {
82 string_len(self.topic)
83 };
84 }
85 if version == 0 {
86 n += 4;
87 }
88 n
89 }
90}
91impl<'de> DecodeBorrow<'de> for OffsetCommitKey<'de> {
92 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94 return Err(ProtocolError::SchemaMismatch(
95 "OffsetCommitKey version out of range",
96 ));
97 }
98 let flex = is_flexible(version);
99 let mut out = Self::default();
100 if version == 0 {
101 out.group = if flex {
102 get_compact_string_borrowed(buf)?
103 } else {
104 get_string_borrowed(buf)?
105 };
106 }
107 if version == 0 {
108 out.topic = if flex {
109 get_compact_string_borrowed(buf)?
110 } else {
111 get_string_borrowed(buf)?
112 };
113 }
114 if version == 0 {
115 out.partition = get_i32(buf)?;
116 }
117 Ok(out)
118 }
119}
120#[cfg(test)]
121impl OffsetCommitKey<'_> {
122 #[must_use]
123 pub fn populated(version: i16) -> Self {
124 let mut m = Self::default();
125 if version == 0 {
126 m.group = "x";
127 }
128 if version == 0 {
129 m.topic = "x";
130 }
131 if version == 0 {
132 m.partition = 1i32;
133 }
134 m
135 }
136}