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