1use mz_proto::{ProtoType, RustType, TryFromProtoError};
11use proptest_derive::Arbitrary;
12use serde::{Deserialize, Serialize};
13use std::time::Duration;
14
15include!(concat!(env!("OUT_DIR"), "/mz_service.params.rs"));
16
17#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, Arbitrary)]
19pub struct GrpcClientParameters {
20 pub connect_timeout: Option<Duration>,
22 pub http2_keep_alive_interval: Option<Duration>,
26 pub http2_keep_alive_timeout: Option<Duration>,
29}
30
31impl GrpcClientParameters {
32 pub fn update(&mut self, other: Self) {
34 let Self {
35 connect_timeout,
36 http2_keep_alive_interval,
37 http2_keep_alive_timeout,
38 } = self;
39 let Self {
40 connect_timeout: other_connect_timeout,
41 http2_keep_alive_interval: other_http2_keep_alive_interval,
42 http2_keep_alive_timeout: other_http2_keep_alive_timeout,
43 } = other;
44
45 if let Some(v) = other_connect_timeout {
46 *connect_timeout = Some(v);
47 }
48 if let Some(v) = other_http2_keep_alive_interval {
49 *http2_keep_alive_interval = Some(v);
50 }
51 if let Some(v) = other_http2_keep_alive_timeout {
52 *http2_keep_alive_timeout = Some(v);
53 }
54 }
55
56 pub fn all_unset(&self) -> bool {
58 *self == Self::default()
59 }
60}
61
62impl RustType<ProtoGrpcClientParameters> for GrpcClientParameters {
63 fn into_proto(&self) -> ProtoGrpcClientParameters {
64 ProtoGrpcClientParameters {
65 connect_timeout: self.connect_timeout.into_proto(),
66 http2_keep_alive_interval: self.http2_keep_alive_interval.into_proto(),
67 http2_keep_alive_timeout: self.http2_keep_alive_timeout.into_proto(),
68 }
69 }
70
71 fn from_proto(proto: ProtoGrpcClientParameters) -> Result<Self, TryFromProtoError> {
72 Ok(Self {
73 connect_timeout: proto.connect_timeout.into_rust()?,
74 http2_keep_alive_interval: proto.http2_keep_alive_interval.into_rust()?,
75 http2_keep_alive_timeout: proto.http2_keep_alive_timeout.into_rust()?,
76 })
77 }
78}