diff --git a/src/cluster.rs b/src/cluster.rs index 8958749..6b26f58 100644 --- a/src/cluster.rs +++ b/src/cluster.rs @@ -7,7 +7,6 @@ use serde::Deserialize; use zstd::stream::decode_all; #[derive(Deserialize, Debug, Clone)] -#[serde(rename = "fileinfo")] pub struct SyncFile { pub path: String, pub hash: String, @@ -16,7 +15,7 @@ pub struct SyncFile { #[derive(Deserialize, Debug, Clone)] pub struct SyncFileList { - pub fileinfo: Vec, + pub file: Vec, } pub struct Cluster { diff --git a/src/utils.rs b/src/utils.rs index 9182587..4b9a589 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -59,7 +59,7 @@ pub const SYNC_FILE_LIST_SCHEMA: &str = r#" "type": "array", "items": { "type": "record", - "name": "SyncFile", + "name": "file", "fields": [ {"name": "path", "type": "string"}, {"name": "hash", "type": "string"}, @@ -78,29 +78,20 @@ pub fn avro_data_to_file_list(data: Vec) -> apache_avro::AvroResult { - println!("array len: {}", arr.len()); + let mut files = Vec::with_capacity(arr.len()); for i in 0..arr.len() { let item = &arr[i]; - let try_item = from_value::(item); - if try_item.is_err() { - println!("parse item error: {}", try_item.err().unwrap()); - } + let try_item = from_value::(item).unwrap(); + files.push(try_item); } + Ok(files) } _ => { - println!("not array"); + panic!("invalid avro data, expect array") } } - let files = from_value::(&value); - if files.is_err() { - // return Err(files.err().unwrap()); - panic!("parse file list error: "); - } - let files = files.unwrap(); - Ok(files.fileinfo) } #[test]