(value: serde_json::Value)
| 1657 | } |
| 1658 | |
| 1659 | fn json_to_protobuf_value(value: serde_json::Value) -> Result<prost_types::Value> { |
| 1660 | use prost_types::{ListValue, Struct, Value, value::Kind}; |
| 1661 | |
| 1662 | let kind = match value { |
| 1663 | serde_json::Value::Null => Kind::NullValue(0), |
| 1664 | serde_json::Value::Bool(value) => Kind::BoolValue(value), |
| 1665 | serde_json::Value::Number(value) => Kind::NumberValue(value.as_f64().ok_or_else(|| { |
| 1666 | miette!("--driver-config-json contains a number that cannot be represented") |
| 1667 | })?), |
| 1668 | serde_json::Value::String(value) => Kind::StringValue(value), |
| 1669 | serde_json::Value::Array(values) => Kind::ListValue(ListValue { |
| 1670 | values: values |
| 1671 | .into_iter() |
| 1672 | .map(json_to_protobuf_value) |
| 1673 | .collect::<Result<_>>()?, |
| 1674 | }), |
| 1675 | serde_json::Value::Object(fields) => Kind::StructValue(Struct { |
| 1676 | fields: fields |
| 1677 | .into_iter() |
| 1678 | .map(|(key, value)| json_to_protobuf_value(value).map(|value| (key, value))) |
| 1679 | .collect::<Result<_>>()?, |
| 1680 | }), |
| 1681 | }; |
| 1682 | |
| 1683 | Ok(Value { kind: Some(kind) }) |
| 1684 | } |
| 1685 | |
| 1686 | fn validate_cpu_quantity(value: &str) -> Result<String> { |
| 1687 | let value = value.trim(); |
no outgoing calls
no test coverage detected