kafka_wire_protocol/schema/end_txn_request/
v3.rs

1// This file was generated. Do not edit.
2
3use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::markers::{ApiMessage, Request};
9use crate::readable_writable::{Readable, Writable};
10use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
11#[cfg(test)] use crate::test_utils::proptest_strategies;
12
13/// EndTxnRequest, version 3.
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct EndTxnRequest {
17    /// The ID of the transaction to end.
18    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
19    pub transactional_id: String,
20    /// The producer ID.
21    pub producer_id: i64,
22    /// The current epoch associated with the producer.
23    pub producer_epoch: i16,
24    /// True if the transaction was committed, false if it was aborted.
25    pub committed: bool,
26    /// Unknown tagged fields.
27    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
28    pub _unknown_tagged_fields: Vec<RawTaggedField>,
29}
30
31impl ApiMessage for EndTxnRequest {
32    fn api_key(&self) -> i16 {
33        26
34    }
35    
36    fn version(&self) -> i16 {
37        3
38    }
39}
40
41impl Request for EndTxnRequest { }
42
43impl Default for EndTxnRequest {
44    fn default() -> Self {
45        EndTxnRequest {
46            transactional_id: String::from(""),
47            producer_id: 0_i64,
48            producer_epoch: 0_i16,
49            committed: false,
50            _unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl EndTxnRequest {
56    pub fn new<S1: AsRef<str>>(transactional_id: S1, producer_id: i64, producer_epoch: i16, committed: bool) -> Self {
57        Self {
58            transactional_id: transactional_id.as_ref().to_string(),
59            producer_id,
60            producer_epoch,
61            committed,
62            _unknown_tagged_fields: vec![],
63        }
64    }
65}
66
67#[cfg(test)]
68mod tests_end_txn_request_new_and_default {
69    use super::*;
70    
71    #[test]
72    fn test() {
73        let d = EndTxnRequest::new(
74            String::from(""),
75            0_i64,
76            0_i16,
77            false,
78        );
79        assert_eq!(d, EndTxnRequest::default());
80    }
81}
82
83impl Readable for EndTxnRequest {
84    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
85        let transactional_id = String::read_ext(input, "transactional_id", true)?;
86        let producer_id = i64::read(input)?;
87        let producer_epoch = i16::read(input)?;
88        let committed = bool::read(input)?;
89        let tagged_fields_callback = |tag: i32, _: &[u8]| {
90            match tag {
91                _ => Ok(false)
92            }
93        };
94        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
95        Ok(EndTxnRequest {
96            transactional_id, producer_id, producer_epoch, committed, _unknown_tagged_fields
97        })
98    }
99}
100
101impl Writable for EndTxnRequest {
102    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
103        self.transactional_id.write_ext(output, "self.transactional_id", true)?;
104        self.producer_id.write(output)?;
105        self.producer_epoch.write(output)?;
106        self.committed.write(output)?;
107        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
108        Ok(())
109    }
110}
111
112#[cfg(test)]
113mod tests {
114    use super::*;
115    use proptest::prelude::*;
116    
117    #[test]
118    fn test_java_default() {
119        crate::test_utils::test_java_default::<EndTxnRequest>("EndTxnRequest", 3);
120    }
121    
122    proptest! {
123        #[test]
124        fn test_serde(data: EndTxnRequest) {
125            crate::test_utils::test_serde(&data)?;
126        }
127    }
128    
129    proptest! {
130        #[test]
131        fn test_java_arbitrary(data: EndTxnRequest) {
132            crate::test_utils::test_java_arbitrary(&data, "EndTxnRequest", 3);
133        }
134    }
135}