accept string for channel capacity

This commit is contained in:
Kirill Fomichev 2022-10-19 14:41:03 -03:00
parent 6541ee7754
commit c7de7fae09
No known key found for this signature in database
GPG Key ID: 6AA0144D5E0C0C0A
2 changed files with 38 additions and 2 deletions

View File

@ -5,7 +5,7 @@
},
"grpc": {
"address": "0.0.0.0:10000",
"channel_capacity": 100000
"channel_capacity": "100_000"
},
"prometheus": {
"address": "0.0.0.0:8999"

View File

@ -1,5 +1,5 @@
use {
serde::Deserialize,
serde::{de, Deserialize, Deserializer},
solana_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPluginError, Result as PluginResult,
},
@ -57,9 +57,45 @@ pub struct ConfigGrpc {
/// Address of Grpc service.
pub address: SocketAddr,
/// Capacity of the channel per connection
#[serde(deserialize_with = "deserialize_channel_capacity")]
pub channel_capacity: usize,
}
fn deserialize_channel_capacity<'de, D>(deserializer: D) -> Result<usize, D::Error>
where
D: Deserializer<'de>,
{
Ok(UsizeStr::deserialize(deserializer)?.value)
}
#[derive(Debug, Default, PartialEq, Eq, Hash)]
struct UsizeStr {
value: usize,
}
impl<'de> Deserialize<'de> for UsizeStr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum Value {
Integer(usize),
String(String),
}
match Value::deserialize(deserializer)? {
Value::Integer(value) => Ok(UsizeStr { value }),
Value::String(value) => value
.replace('_', "")
.parse::<usize>()
.map_err(de::Error::custom)
.map(|value| UsizeStr { value }),
}
}
}
#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConfigPrometheus {