kafka_wire_protocol/schema/create_delegation_token_response/
v3.rs1use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::bytes::{read_bytes, write_bytes};
9use crate::markers::{ApiMessage, Response};
10use crate::readable_writable::{Readable, Writable};
11use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
12#[cfg(test)] use crate::test_utils::{proptest_strategies, serde_bytes};
13
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
16#[cfg_attr(test, derive(Arbitrary))]
17pub struct CreateDelegationTokenResponse {
18 pub error_code: i16,
20 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
22 pub principal_type: String,
23 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
25 pub principal_name: String,
26 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
28 pub token_requester_principal_type: String,
29 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
31 pub token_requester_principal_name: String,
32 pub issue_timestamp_ms: i64,
34 pub expiry_timestamp_ms: i64,
36 pub max_timestamp_ms: i64,
38 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
40 pub token_id: String,
41 #[cfg_attr(test, proptest(strategy = "proptest_strategies::bytes()"))]
43 #[cfg_attr(test, serde(with="serde_bytes"))]
44 pub hmac: Vec<u8>,
45 pub throttle_time_ms: i32,
47 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
49 pub _unknown_tagged_fields: Vec<RawTaggedField>,
50}
51
52impl ApiMessage for CreateDelegationTokenResponse {
53 fn api_key(&self) -> i16 {
54 38
55 }
56
57 fn version(&self) -> i16 {
58 3
59 }
60}
61
62impl Response for CreateDelegationTokenResponse { }
63
64impl Default for CreateDelegationTokenResponse {
65 fn default() -> Self {
66 CreateDelegationTokenResponse {
67 error_code: 0_i16,
68 principal_type: String::from(""),
69 principal_name: String::from(""),
70 token_requester_principal_type: String::from(""),
71 token_requester_principal_name: String::from(""),
72 issue_timestamp_ms: 0_i64,
73 expiry_timestamp_ms: 0_i64,
74 max_timestamp_ms: 0_i64,
75 token_id: String::from(""),
76 hmac: Vec::new(),
77 throttle_time_ms: 0_i32,
78 _unknown_tagged_fields: Vec::new(),
79 }
80 }
81}
82
83impl CreateDelegationTokenResponse {
84 pub fn new<S1: AsRef<str>, S2: AsRef<str>, S3: AsRef<str>, S4: AsRef<str>, S5: AsRef<str>>(error_code: i16, principal_type: S1, principal_name: S2, token_requester_principal_type: S3, token_requester_principal_name: S4, issue_timestamp_ms: i64, expiry_timestamp_ms: i64, max_timestamp_ms: i64, token_id: S5, hmac: Vec<u8>, throttle_time_ms: i32) -> Self {
85 Self {
86 error_code,
87 principal_type: principal_type.as_ref().to_string(),
88 principal_name: principal_name.as_ref().to_string(),
89 token_requester_principal_type: token_requester_principal_type.as_ref().to_string(),
90 token_requester_principal_name: token_requester_principal_name.as_ref().to_string(),
91 issue_timestamp_ms,
92 expiry_timestamp_ms,
93 max_timestamp_ms,
94 token_id: token_id.as_ref().to_string(),
95 hmac,
96 throttle_time_ms,
97 _unknown_tagged_fields: vec![],
98 }
99 }
100}
101
102#[cfg(test)]
103mod tests_create_delegation_token_response_new_and_default {
104 use super::*;
105
106 #[test]
107 fn test() {
108 let d = CreateDelegationTokenResponse::new(
109 0_i16,
110 String::from(""),
111 String::from(""),
112 String::from(""),
113 String::from(""),
114 0_i64,
115 0_i64,
116 0_i64,
117 String::from(""),
118 Vec::new(),
119 0_i32,
120 );
121 assert_eq!(d, CreateDelegationTokenResponse::default());
122 }
123}
124
125impl Readable for CreateDelegationTokenResponse {
126 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
127 let error_code = i16::read(input)?;
128 let principal_type = String::read_ext(input, "principal_type", true)?;
129 let principal_name = String::read_ext(input, "principal_name", true)?;
130 let token_requester_principal_type = String::read_ext(input, "token_requester_principal_type", true)?;
131 let token_requester_principal_name = String::read_ext(input, "token_requester_principal_name", true)?;
132 let issue_timestamp_ms = i64::read(input)?;
133 let expiry_timestamp_ms = i64::read(input)?;
134 let max_timestamp_ms = i64::read(input)?;
135 let token_id = String::read_ext(input, "token_id", true)?;
136 let hmac = read_bytes(input, "hmac", true)?;
137 let throttle_time_ms = i32::read(input)?;
138 let tagged_fields_callback = |tag: i32, _: &[u8]| {
139 match tag {
140 _ => Ok(false)
141 }
142 };
143 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
144 Ok(CreateDelegationTokenResponse {
145 error_code, principal_type, principal_name, token_requester_principal_type, token_requester_principal_name, issue_timestamp_ms, expiry_timestamp_ms, max_timestamp_ms, token_id, hmac, throttle_time_ms, _unknown_tagged_fields
146 })
147 }
148}
149
150impl Writable for CreateDelegationTokenResponse {
151 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
152 self.error_code.write(output)?;
153 self.principal_type.write_ext(output, "self.principal_type", true)?;
154 self.principal_name.write_ext(output, "self.principal_name", true)?;
155 self.token_requester_principal_type.write_ext(output, "self.token_requester_principal_type", true)?;
156 self.token_requester_principal_name.write_ext(output, "self.token_requester_principal_name", true)?;
157 self.issue_timestamp_ms.write(output)?;
158 self.expiry_timestamp_ms.write(output)?;
159 self.max_timestamp_ms.write(output)?;
160 self.token_id.write_ext(output, "self.token_id", true)?;
161 write_bytes(output, "self.hmac", &self.hmac, true)?;
162 self.throttle_time_ms.write(output)?;
163 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
164 Ok(())
165 }
166}
167
168#[cfg(test)]
169mod tests {
170 use super::*;
171 use proptest::prelude::*;
172
173 #[test]
174 fn test_java_default() {
175 crate::test_utils::test_java_default::<CreateDelegationTokenResponse>("CreateDelegationTokenResponse", 3);
176 }
177
178 proptest! {
179 #[test]
180 fn test_serde(data: CreateDelegationTokenResponse) {
181 crate::test_utils::test_serde(&data)?;
182 }
183 }
184
185 proptest! {
186 #[test]
187 fn test_java_arbitrary(data: CreateDelegationTokenResponse) {
188 crate::test_utils::test_java_arbitrary(&data, "CreateDelegationTokenResponse", 3);
189 }
190 }
191}