pub fn get_schema_data_map<'a>(
    serialized_data: &'a Vec<u8>,
    schema: &'a Schema
) -> Result<HashMap<String, SchemaValue>, AvroError>
Expand description

Function to get serialized datum data for a given schema into hashmap.

Examples

use common_helpers::avro;
use common_helpers::types::*;
use std::{collections::HashMap};
let raw_schema = r#"
{
   "type": "record",
  "name": "test",
 "fields": [
   {"name": "a", "type": "long", "default": 42},
  {"name": "b", "type": "string"}
]
}
"#;
let schema_fingerprint = avro::fingerprint_raw_schema(raw_schema);
let mut hashmap_data = HashMap::new();
let mut name = "name".to_string();
let mut name_field = SchemaValue::String("John".to_string());
hashmap_data.insert("a".to_string(), SchemaValue::Long(27i64));
hashmap_data.insert("b".to_string(), SchemaValue::String("foo".to_string()));
assert!(schema_fingerprint.is_ok());
let data_schema = schema_fingerprint.unwrap().0;
let serialized_record = avro::populate_schema_and_serialize(&data_schema, &hashmap_data);
assert!(serialized_record.is_ok());
let serialized_data = serialized_record.unwrap();
let deserialized_data = avro::get_schema_data_map(&serialized_data, &data_schema);
assert!(deserialized_data.is_ok());