crabka-protocol 0.1.2

Apache Kafka wire-protocol codec (4.3.0), with typed RecordBatch and zero-copy borrowed decode
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.

use bytes::BufMut;

use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, put_bool, put_i16, put_i32};
use crate::primitives::string_bytes::{
    compact_nullable_string_len, compact_string_len, nullable_string_len,
    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
    string_len,
};
use crate::primitives::string_bytes_borrowed::{
    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
    get_nullable_string_borrowed, get_string_borrowed,
};
use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};

pub const API_KEY: i16 = 89;
pub const MIN_VERSION: i16 = 0;
pub const MAX_VERSION: i16 = 0;
pub const FLEXIBLE_MIN: i16 = 0;

#[inline]
fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StreamsGroupDescribeResponse<'a> {
    pub throttle_time_ms: i32,
    pub groups: Vec<DescribedGroup<'a>>,
    pub unknown_tagged_fields: UnknownTaggedFields,
}

impl<'a> Default for StreamsGroupDescribeResponse<'a> {
    fn default() -> Self {
        Self {
            throttle_time_ms: 0i32,
            groups: Vec::new(),
            unknown_tagged_fields: Default::default(),
        }
    }
}

impl<'a> StreamsGroupDescribeResponse<'a> {
    pub fn to_owned(&self) -> crate::owned::streams_group_describe_response::StreamsGroupDescribeResponse {
        crate::owned::streams_group_describe_response::StreamsGroupDescribeResponse {
            throttle_time_ms: (self.throttle_time_ms),
            groups: (self.groups).iter().map(|it| it.to_owned()).collect(),
            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
        }
    }
}

impl<'a> Encode for StreamsGroupDescribeResponse<'a> {
    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
        }
        let flex = is_flexible(version);
        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { it.encode(buf, version)?; } } }
        if flex {
            let tagged = WriteTaggedFields::new();
            tagged.write(buf, &self.unknown_tagged_fields);
        }
        Ok(())
    }
    fn encoded_len(&self, version: i16) -> usize {
        let flex = is_flexible(version);
        let mut n: usize = 0;
        if version >= 0 { n += 4; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups).len(), flex); let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if flex {
            let known_pairs: Vec<(u32, usize)> = Vec::new();
            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
        }
        n
    }
}

impl<'de> DecodeBorrow<'de> for StreamsGroupDescribeResponse<'de> {
    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
        }
        let flex = is_flexible(version);
        let mut out = Self::default();
        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
        if version >= 0 { out.groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribedGroup::decode_borrow(buf, version)?); } v }; }
        if flex {
            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
                Ok(false)
            })?;
        }
        Ok(out)
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DescribedGroup<'a> {
    pub error_code: i16,
    pub error_message: Option<&'a str>,
    pub group_id: &'a str,
    pub group_state: &'a str,
    pub group_epoch: i32,
    pub assignment_epoch: i32,
    pub topology: Option<Topology<'a>>,
    pub members: Vec<Member<'a>>,
    pub authorized_operations: i32,
    pub unknown_tagged_fields: UnknownTaggedFields,
}

impl<'a> Default for DescribedGroup<'a> {
    fn default() -> Self {
        Self {
            error_code: 0i16,
            error_message: None,
            group_id: "",
            group_state: "",
            group_epoch: 0i32,
            assignment_epoch: 0i32,
            topology: None,
            members: Vec::new(),
            authorized_operations: -2_147_483_648i32,
            unknown_tagged_fields: Default::default(),
        }
    }
}

impl<'a> DescribedGroup<'a> {
    pub fn to_owned(&self) -> crate::owned::streams_group_describe_response::DescribedGroup {
        crate::owned::streams_group_describe_response::DescribedGroup {
            error_code: (self.error_code),
            error_message: (self.error_message).map(|s| s.to_string()),
            group_id: (self.group_id).to_string(),
            group_state: (self.group_state).to_string(),
            group_epoch: (self.group_epoch),
            assignment_epoch: (self.assignment_epoch),
            topology: (self.topology).as_ref().map(|v| v.to_owned()),
            members: (self.members).iter().map(|it| it.to_owned()).collect(),
            authorized_operations: (self.authorized_operations),
            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
        }
    }
}

impl<'a> Encode for DescribedGroup<'a> {
    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
        let flex = version >= 0;
        if version >= 0 { put_i16(buf, self.error_code) }
        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
        if version >= 0 { if flex { put_compact_string(buf, self.group_state) } else { put_string(buf, self.group_state) } }
        if version >= 0 { put_i32(buf, self.group_epoch) }
        if version >= 0 { put_i32(buf, self.assignment_epoch) }
        if version >= 0 { match &self.topology { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
        if version >= 0 { put_i32(buf, self.authorized_operations) }
        if flex {
            let tagged = WriteTaggedFields::new();
            tagged.write(buf, &self.unknown_tagged_fields);
        }
        Ok(())
    }
    fn encoded_len(&self, version: i16) -> usize {
        let flex = version >= 0;
        let mut n: usize = 0;
        if version >= 0 { n += 2; }
        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
        if version >= 0 { n += if flex { compact_string_len(self.group_state) } else { string_len(self.group_state) }; }
        if version >= 0 { n += 4; }
        if version >= 0 { n += 4; }
        if version >= 0 { n += 1 + self.topology.as_ref().map_or(0, |v| v.encoded_len(version)); }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.members).len(), flex); let body: usize = (self.members).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if version >= 0 { n += 4; }
        if flex {
            let known_pairs: Vec<(u32, usize)> = Vec::new();
            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
        }
        n
    }
}

impl<'de> DecodeBorrow<'de> for DescribedGroup<'de> {
    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
        let flex = version >= 0;
        let mut out = Self::default();
        if version >= 0 { out.error_code = get_i16(buf)?; }
        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.group_state = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.group_epoch = get_i32(buf)?; }
        if version >= 0 { out.assignment_epoch = get_i32(buf)?; }
        if version >= 0 { out.topology = if get_i8(buf)? < 0 { None } else { Some(Topology::decode_borrow(buf, version)?) }; }
        if version >= 0 { out.members = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Member::decode_borrow(buf, version)?); } v }; }
        if version >= 0 { out.authorized_operations = get_i32(buf)?; }
        if flex {
            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
                Ok(false)
            })?;
        }
        Ok(out)
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Topology<'a> {
    pub epoch: i32,
    pub subtopologies: Option<Vec<Subtopology<'a>>>,
    pub unknown_tagged_fields: UnknownTaggedFields,
}

impl<'a> Default for Topology<'a> {
    fn default() -> Self {
        Self {
            epoch: 0i32,
            subtopologies: None,
            unknown_tagged_fields: Default::default(),
        }
    }
}

impl<'a> Topology<'a> {
    pub fn to_owned(&self) -> crate::owned::streams_group_describe_response::Topology {
        crate::owned::streams_group_describe_response::Topology {
            epoch: (self.epoch),
            subtopologies: (self.subtopologies).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
        }
    }
}

impl<'a> Encode for Topology<'a> {
    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
        let flex = version >= 0;
        if version >= 0 { put_i32(buf, self.epoch) }
        if version >= 0 { { let len = (self.subtopologies).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.subtopologies { for it in v { it.encode(buf, version)?; } } } }
        if flex {
            let tagged = WriteTaggedFields::new();
            tagged.write(buf, &self.unknown_tagged_fields);
        }
        Ok(())
    }
    fn encoded_len(&self, version: i16) -> usize {
        let flex = version >= 0;
        let mut n: usize = 0;
        if version >= 0 { n += 4; }
        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.subtopologies).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
        if flex {
            let known_pairs: Vec<(u32, usize)> = Vec::new();
            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
        }
        n
    }
}

impl<'de> DecodeBorrow<'de> for Topology<'de> {
    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
        let flex = version >= 0;
        let mut out = Self::default();
        if version >= 0 { out.epoch = get_i32(buf)?; }
        if version >= 0 { out.subtopologies = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Subtopology::decode_borrow(buf, version)?); } Some(v) } } }; }
        if flex {
            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
                Ok(false)
            })?;
        }
        Ok(out)
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Subtopology<'a> {
    pub subtopology_id: &'a str,
    pub source_topics: Vec<&'a str>,
    pub repartition_sink_topics: Vec<&'a str>,
    pub state_changelog_topics: Vec<super::common::topic_info::TopicInfo<'a>>,
    pub repartition_source_topics: Vec<super::common::topic_info::TopicInfo<'a>>,
    pub unknown_tagged_fields: UnknownTaggedFields,
}

impl<'a> Default for Subtopology<'a> {
    fn default() -> Self {
        Self {
            subtopology_id: "",
            source_topics: Vec::new(),
            repartition_sink_topics: Vec::new(),
            state_changelog_topics: Vec::new(),
            repartition_source_topics: Vec::new(),
            unknown_tagged_fields: Default::default(),
        }
    }
}

impl<'a> Subtopology<'a> {
    pub fn to_owned(&self) -> crate::owned::streams_group_describe_response::Subtopology {
        crate::owned::streams_group_describe_response::Subtopology {
            subtopology_id: (self.subtopology_id).to_string(),
            source_topics: (self.source_topics).iter().map(|s| s.to_string()).collect(),
            repartition_sink_topics: (self.repartition_sink_topics).iter().map(|s| s.to_string()).collect(),
            state_changelog_topics: (self.state_changelog_topics).iter().map(|it| it.to_owned()).collect(),
            repartition_source_topics: (self.repartition_source_topics).iter().map(|it| it.to_owned()).collect(),
            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
        }
    }
}

impl<'a> Encode for Subtopology<'a> {
    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
        let flex = version >= 0;
        if version >= 0 { if flex { put_compact_string(buf, self.subtopology_id) } else { put_string(buf, self.subtopology_id) } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.source_topics).len(), flex); for it in &self.source_topics { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.repartition_sink_topics).len(), flex); for it in &self.repartition_sink_topics { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.state_changelog_topics).len(), flex); for it in &self.state_changelog_topics { it.encode(buf, version)?; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.repartition_source_topics).len(), flex); for it in &self.repartition_source_topics { it.encode(buf, version)?; } } }
        if flex {
            let tagged = WriteTaggedFields::new();
            tagged.write(buf, &self.unknown_tagged_fields);
        }
        Ok(())
    }
    fn encoded_len(&self, version: i16) -> usize {
        let flex = version >= 0;
        let mut n: usize = 0;
        if version >= 0 { n += if flex { compact_string_len(self.subtopology_id) } else { string_len(self.subtopology_id) }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.source_topics).len(), flex); let body: usize = (self.source_topics).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.repartition_sink_topics).len(), flex); let body: usize = (self.repartition_sink_topics).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.state_changelog_topics).len(), flex); let body: usize = (self.state_changelog_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.repartition_source_topics).len(), flex); let body: usize = (self.repartition_source_topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if flex {
            let known_pairs: Vec<(u32, usize)> = Vec::new();
            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
        }
        n
    }
}

impl<'de> DecodeBorrow<'de> for Subtopology<'de> {
    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
        let flex = version >= 0;
        let mut out = Self::default();
        if version >= 0 { out.subtopology_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
        if version >= 0 { out.repartition_sink_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
        if version >= 0 { out.state_changelog_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_info::TopicInfo::decode_borrow(buf, version)?); } v }; }
        if version >= 0 { out.repartition_source_topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_info::TopicInfo::decode_borrow(buf, version)?); } v }; }
        if flex {
            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
                Ok(false)
            })?;
        }
        Ok(out)
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Member<'a> {
    pub member_id: &'a str,
    pub member_epoch: i32,
    pub instance_id: Option<&'a str>,
    pub rack_id: Option<&'a str>,
    pub client_id: &'a str,
    pub client_host: &'a str,
    pub topology_epoch: i32,
    pub process_id: &'a str,
    pub user_endpoint: Option<super::common::endpoint::Endpoint<'a>>,
    pub client_tags: Vec<super::common::key_value::KeyValue<'a>>,
    pub task_offsets: Vec<super::common::task_offset::TaskOffset<'a>>,
    pub task_end_offsets: Vec<super::common::task_offset::TaskOffset<'a>>,
    pub assignment: super::common::assignment::Assignment<'a>,
    pub target_assignment: super::common::assignment::Assignment<'a>,
    pub is_classic: bool,
    pub unknown_tagged_fields: UnknownTaggedFields,
}

impl<'a> Default for Member<'a> {
    fn default() -> Self {
        Self {
            member_id: "",
            member_epoch: 0i32,
            instance_id: None,
            rack_id: None,
            client_id: "",
            client_host: "",
            topology_epoch: 0i32,
            process_id: "",
            user_endpoint: None,
            client_tags: Vec::new(),
            task_offsets: Vec::new(),
            task_end_offsets: Vec::new(),
            assignment: Default::default(),
            target_assignment: Default::default(),
            is_classic: false,
            unknown_tagged_fields: Default::default(),
        }
    }
}

impl<'a> Member<'a> {
    pub fn to_owned(&self) -> crate::owned::streams_group_describe_response::Member {
        crate::owned::streams_group_describe_response::Member {
            member_id: (self.member_id).to_string(),
            member_epoch: (self.member_epoch),
            instance_id: (self.instance_id).map(|s| s.to_string()),
            rack_id: (self.rack_id).map(|s| s.to_string()),
            client_id: (self.client_id).to_string(),
            client_host: (self.client_host).to_string(),
            topology_epoch: (self.topology_epoch),
            process_id: (self.process_id).to_string(),
            user_endpoint: (self.user_endpoint).as_ref().map(|v| v.to_owned()),
            client_tags: (self.client_tags).iter().map(|it| it.to_owned()).collect(),
            task_offsets: (self.task_offsets).iter().map(|it| it.to_owned()).collect(),
            task_end_offsets: (self.task_end_offsets).iter().map(|it| it.to_owned()).collect(),
            assignment: (self.assignment).to_owned(),
            target_assignment: (self.target_assignment).to_owned(),
            is_classic: (self.is_classic),
            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
        }
    }
}

impl<'a> Encode for Member<'a> {
    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
        let flex = version >= 0;
        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
        if version >= 0 { put_i32(buf, self.member_epoch) }
        if version >= 0 { if flex { put_compact_nullable_string(buf, self.instance_id) } else { put_nullable_string(buf, self.instance_id) } }
        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id) } else { put_nullable_string(buf, self.rack_id) } }
        if version >= 0 { if flex { put_compact_string(buf, self.client_id) } else { put_string(buf, self.client_id) } }
        if version >= 0 { if flex { put_compact_string(buf, self.client_host) } else { put_string(buf, self.client_host) } }
        if version >= 0 { put_i32(buf, self.topology_epoch) }
        if version >= 0 { if flex { put_compact_string(buf, self.process_id) } else { put_string(buf, self.process_id) } }
        if version >= 0 { match &self.user_endpoint { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.client_tags).len(), flex); for it in &self.client_tags { it.encode(buf, version)?; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.task_offsets).len(), flex); for it in &self.task_offsets { it.encode(buf, version)?; } } }
        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.task_end_offsets).len(), flex); for it in &self.task_end_offsets { it.encode(buf, version)?; } } }
        if version >= 0 { self.assignment.encode(buf, version)? }
        if version >= 0 { self.target_assignment.encode(buf, version)? }
        if version >= 0 { put_bool(buf, self.is_classic) }
        if flex {
            let tagged = WriteTaggedFields::new();
            tagged.write(buf, &self.unknown_tagged_fields);
        }
        Ok(())
    }
    fn encoded_len(&self, version: i16) -> usize {
        let flex = version >= 0;
        let mut n: usize = 0;
        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
        if version >= 0 { n += 4; }
        if version >= 0 { n += if flex { compact_nullable_string_len(self.instance_id) } else { nullable_string_len(self.instance_id) }; }
        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id) } else { nullable_string_len(self.rack_id) }; }
        if version >= 0 { n += if flex { compact_string_len(self.client_id) } else { string_len(self.client_id) }; }
        if version >= 0 { n += if flex { compact_string_len(self.client_host) } else { string_len(self.client_host) }; }
        if version >= 0 { n += 4; }
        if version >= 0 { n += if flex { compact_string_len(self.process_id) } else { string_len(self.process_id) }; }
        if version >= 0 { n += 1 + self.user_endpoint.as_ref().map_or(0, |v| v.encoded_len(version)); }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.client_tags).len(), flex); let body: usize = (self.client_tags).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.task_offsets).len(), flex); let body: usize = (self.task_offsets).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.task_end_offsets).len(), flex); let body: usize = (self.task_end_offsets).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
        if version >= 0 { n += self.assignment.encoded_len(version); }
        if version >= 0 { n += self.target_assignment.encoded_len(version); }
        if version >= 0 { n += 1; }
        if flex {
            let known_pairs: Vec<(u32, usize)> = Vec::new();
            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
        }
        n
    }
}

impl<'de> DecodeBorrow<'de> for Member<'de> {
    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
        let flex = version >= 0;
        let mut out = Self::default();
        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.member_epoch = get_i32(buf)?; }
        if version >= 0 { out.instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
        if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
        if version >= 0 { out.client_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.client_host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.topology_epoch = get_i32(buf)?; }
        if version >= 0 { out.process_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
        if version >= 0 { out.user_endpoint = if get_i8(buf)? < 0 { None } else { Some(super::common::endpoint::Endpoint::decode_borrow(buf, version)?) }; }
        if version >= 0 { out.client_tags = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::key_value::KeyValue::decode_borrow(buf, version)?); } v }; }
        if version >= 0 { out.task_offsets = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_offset::TaskOffset::decode_borrow(buf, version)?); } v }; }
        if version >= 0 { out.task_end_offsets = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_offset::TaskOffset::decode_borrow(buf, version)?); } v }; }
        if version >= 0 { out.assignment = super::common::assignment::Assignment::decode_borrow(buf, version)?; }
        if version >= 0 { out.target_assignment = super::common::assignment::Assignment::decode_borrow(buf, version)?; }
        if version >= 0 { out.is_classic = get_bool(buf)?; }
        if flex {
            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
                Ok(false)
            })?;
        }
        Ok(out)
    }
}