Skip to main content

kacrab_protocol/generated/
snapshot_header_record.rs

1//! Generated from SnapshotHeaderRecord.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct SnapshotHeaderRecordData {
17    /// The version of the snapshot header record.
18    pub version: i16,
19    /// The append time of the last record from the log contained in this snapshot.
20    pub last_contained_log_timestamp: i64,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for SnapshotHeaderRecordData {
24    fn default() -> Self {
25        Self {
26            version: 0_i16,
27            last_contained_log_timestamp: 0_i64,
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl SnapshotHeaderRecordData {
33    pub fn with_version(mut self, value: i16) -> Self {
34        self.version = value;
35        self
36    }
37    pub fn with_last_contained_log_timestamp(mut self, value: i64) -> Self {
38        self.last_contained_log_timestamp = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
42        let version_;
43        let last_contained_log_timestamp;
44        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
45        version_ = read_i16(buf)?;
46        last_contained_log_timestamp = read_i64(buf)?;
47        let tagged_fields = read_tagged_fields(buf)?;
48        for field in &tagged_fields {
49            match field.tag {
50                _ => {
51                    _unknown_tagged_fields.push(field.clone());
52                },
53            }
54        }
55        Ok(Self {
56            version: version_,
57            last_contained_log_timestamp,
58            _unknown_tagged_fields,
59        })
60    }
61    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
62        write_i16(buf, self.version);
63        write_i64(buf, self.last_contained_log_timestamp);
64        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
65        all_tags.sort_by_key(|f| f.tag);
66        write_tagged_fields(buf, &all_tags)?;
67        Ok(())
68    }
69    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
70        let mut len: usize = 0;
71        len += 2;
72        len += 8;
73        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
74        all_tags.sort_by_key(|f| f.tag);
75        len += tagged_fields_len(&all_tags)?;
76        Ok(len)
77    }
78}