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

Function read_codec

avro/src/reader/block.rs:298–355  ·  view source on GitHub ↗
(metadata: &HashMap<String, Value>)

Source from the content-addressed store, hash-verified

296 }
297 Ok(())
298 }
299}
300
301fn read_codec(metadata: &mut HashMap<String, Value>) -> AvroResult<Codec> {
302 let result = metadata
303 .remove("avro.codec")
304 .map(|codec| {
305 if let Value::Bytes(bytes) = codec {
306 match String::from_utf8(bytes) {
307 Ok(utf8) => Ok(utf8),
308 Err(utf8_error) => Err(Details::ConvertToUtf8(utf8_error).into()),
309 }
310 } else {
311 unreachable!("Metadata would fail to decode if it is not Value::Bytes")
312 }
313 })
314 .map(|codec_res| match codec_res {
315 Ok(codec) => match Codec::from_str(&codec) {
316 Ok(codec) => match codec {
317 #[cfg(feature = "bzip")]
318 Codec::Bzip2(_) => {
319 use crate::Bzip2Settings;
320 if let Some(Value::Bytes(bytes)) =
321 metadata.remove("avro.codec.compression_level")
322 {
323 match bytes.first() {
324 Some(&level) => Ok(Codec::Bzip2(Bzip2Settings::new(level))),
325 None => Err(Details::BadCodecMetadata.into()),
326 }
327 } else {
328 Ok(codec)
329 }
330 }
331 #[cfg(feature = "xz")]
332 Codec::Xz(_) => {
333 use crate::XzSettings;
334 if let Some(Value::Bytes(bytes)) =
335 metadata.remove("avro.codec.compression_level")
336 {
337 match bytes.first() {
338 Some(&level) => Ok(Codec::Xz(XzSettings::new(level))),
339 None => Err(Details::BadCodecMetadata.into()),
340 }
341 } else {
342 Ok(codec)
343 }
344 }
345 #[cfg(feature = "zstandard")]
346 Codec::Zstandard(_) => {
347 use crate::ZstandardSettings;
348 if let Some(Value::Bytes(bytes)) =
349 metadata.remove("avro.codec.compression_level")
350 {
351 match bytes.first() {
352 Some(&level) => Ok(Codec::Zstandard(ZstandardSettings::new(level))),
353 None => Err(Details::BadCodecMetadata.into()),
354 }
355 } else {

Callers 1

read_headerMethod · 0.85

Calls 3

getMethod · 0.80
as_refMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected