kafka_api/schemata/response_header.rs
1// Copyright 2024 tison <wander4096@gmail.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use byteorder::WriteBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20// Version 1 is the first flexible version.
21
22#[derive(Debug, Default, Clone)]
23pub struct ResponseHeader {
24 /// The correlation ID of this response.
25 pub correlation_id: i32,
26 /// Unknown tagged fields.
27 pub unknown_tagged_fields: Vec<RawTaggedField>,
28}
29
30impl Encodable for ResponseHeader {
31 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
32 Int32.encode(buf, self.correlation_id)?;
33 if version >= 1 {
34 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
35 }
36 Ok(())
37 }
38
39 fn calculate_size(&self, version: i16) -> usize {
40 let mut res = 0;
41 res += Int32::SIZE; // self.correlation_id
42 if version >= 1 {
43 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
44 }
45 res
46 }
47}