MCPcopy Create free account
hub / github.com/apache/avro-rs / validate

Function validate

avro/src/types.rs:1303–1456  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1301 Value::Long(n) => Ok(Value::Long(n)),
1302 other => Err(Details::GetLong(other).into()),
1303 }
1304 }
1305
1306 fn resolve_float(self) -> Result<Self, Error> {
1307 match self {
1308 Value::Int(n) => Ok(Value::Float(n as f32)),
1309 Value::Long(n) => Ok(Value::Float(n as f32)),
1310 Value::Float(x) => Ok(Value::Float(x)),
1311 Value::Double(x) => Ok(Value::Float(x as f32)),
1312 Value::String(ref x) => match Self::parse_special_float(x) {
1313 Some(f) => Ok(Value::Float(f)),
1314 None => Err(Details::GetFloat(self).into()),
1315 },
1316 other => Err(Details::GetFloat(other).into()),
1317 }
1318 }
1319
1320 fn resolve_double(self) -> Result<Self, Error> {
1321 match self {
1322 Value::Int(n) => Ok(Value::Double(f64::from(n))),
1323 Value::Long(n) => Ok(Value::Double(n as f64)),
1324 Value::Float(x) => Ok(Value::Double(f64::from(x))),
1325 Value::Double(x) => Ok(Value::Double(x)),
1326 Value::String(ref x) => match Self::parse_special_float(x) {
1327 Some(f) => Ok(Value::Double(f64::from(f))),
1328 None => Err(Details::GetDouble(self).into()),
1329 },
1330 other => Err(Details::GetDouble(other).into()),
1331 }
1332 }
1333
1334 /// IEEE 754 NaN and infinities are not valid JSON numbers.
1335 /// So they are represented in JSON as strings.
1336 fn parse_special_float(value: &str) -> Option<f32> {
1337 match value {
1338 "NaN" => Some(f32::NAN),
1339 "INF" | "Infinity" => Some(f32::INFINITY),
1340 "-INF" | "-Infinity" => Some(f32::NEG_INFINITY),
1341 _ => None,
1342 }
1343 }
1344
1345 fn resolve_bytes(self) -> Result<Self, Error> {
1346 match self {
1347 Value::Bytes(bytes) => Ok(Value::Bytes(bytes)),
1348 Value::String(s) => Ok(Value::Bytes(s.into_bytes())),
1349 Value::Array(items) => Ok(Value::Bytes(
1350 items
1351 .into_iter()
1352 .map(Value::try_u8)
1353 .collect::<Result<Vec<_>, _>>()?,
1354 )),
1355 other => Err(Details::GetBytes(other).into()),
1356 }
1357 }
1358
1359 fn resolve_string(self) -> Result<Self, Error> {
1360 match self {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected