Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from azastrael/max-message-len
Browse files Browse the repository at this point in the history
Added the max_receive_msg_len and max_send_msg_len methods to ChannelBuilder
  • Loading branch information
ccc authored Sep 20, 2019
2 parents d6f94be + 7f1d9ae commit cdc3a7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ impl Client {
ClientBuilder {
endpoints: Default::default(),
auth: None,
max_receive_msg_len: None,
max_send_msg_len: None,
}
}
}

pub struct ClientBuilder {
endpoints: Vec<String>,
auth: Option<(String, String)>,
max_receive_msg_len: Option<i32>,
max_send_msg_len: Option<i32>,
}

impl ClientBuilder {
Expand All @@ -80,10 +84,31 @@ impl ClientBuilder {
self
}

pub fn max_receive_msg_len(mut self, len: i32) -> Self {
self.max_receive_msg_len = Some(len);
self
}

pub fn max_send_msg_len(mut self, len: i32) -> Self {
self.max_send_msg_len = Some(len);
self
}

pub fn build(self) -> Client {
let env = Arc::new(EnvBuilder::new().build());
let addrs = self.endpoints.join(",");
let channel = ChannelBuilder::new(env).connect(&addrs);

let mut channel = ChannelBuilder::new(env);

if let Some(len) = self.max_receive_msg_len {
channel = channel.max_receive_message_len(len);
}

if let Some(len) = self.max_send_msg_len {
channel = channel.max_send_message_len(len);
}

let channel = channel.connect(&addrs);

let (username, password) = match self.auth {
Some((username, password)) => (Some(username), Some(password)),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub mod lock;
pub mod watch;

pub use crate::{
client::Client, cluster::ClusterClient, error::Error, kv::KvClient, lease::LeaseClient,
lock::LockClient, response_header::ResponseHeader, watch::WatchClient,
client::Client, client::ClientBuilder, cluster::ClusterClient, error::Error, kv::KvClient,
lease::LeaseClient, lock::LockClient, response_header::ResponseHeader, watch::WatchClient,
};

pub mod prelude {
Expand Down

0 comments on commit cdc3a7f

Please sign in to comment.