NB
This commit is contained in:
parent
72eb29244c
commit
a9d8ed9817
@ -7,7 +7,6 @@ use serde::Deserialize;
|
|||||||
use zstd::stream::decode_all;
|
use zstd::stream::decode_all;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
#[serde(rename = "fileinfo")]
|
|
||||||
pub struct SyncFile {
|
pub struct SyncFile {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub hash: String,
|
pub hash: String,
|
||||||
@ -16,7 +15,7 @@ pub struct SyncFile {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct SyncFileList {
|
pub struct SyncFileList {
|
||||||
pub fileinfo: Vec<SyncFile>,
|
pub file: Vec<SyncFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Cluster {
|
pub struct Cluster {
|
||||||
|
21
src/utils.rs
21
src/utils.rs
@ -59,7 +59,7 @@ pub const SYNC_FILE_LIST_SCHEMA: &str = r#"
|
|||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "record",
|
"type": "record",
|
||||||
"name": "SyncFile",
|
"name": "file",
|
||||||
"fields": [
|
"fields": [
|
||||||
{"name": "path", "type": "string"},
|
{"name": "path", "type": "string"},
|
||||||
{"name": "hash", "type": "string"},
|
{"name": "hash", "type": "string"},
|
||||||
@ -78,29 +78,20 @@ pub fn avro_data_to_file_list(data: Vec<u8>) -> apache_avro::AvroResult<Vec<Sync
|
|||||||
return Err(reader.err().unwrap());
|
return Err(reader.err().unwrap());
|
||||||
}
|
}
|
||||||
let value = reader.unwrap();
|
let value = reader.unwrap();
|
||||||
println!("{:?}", value.validate(&chema));
|
|
||||||
match &value {
|
match &value {
|
||||||
Value::Array(arr) => {
|
Value::Array(arr) => {
|
||||||
println!("array len: {}", arr.len());
|
let mut files = Vec::with_capacity(arr.len());
|
||||||
for i in 0..arr.len() {
|
for i in 0..arr.len() {
|
||||||
let item = &arr[i];
|
let item = &arr[i];
|
||||||
let try_item = from_value::<SyncFile>(item);
|
let try_item = from_value::<SyncFile>(item).unwrap();
|
||||||
if try_item.is_err() {
|
files.push(try_item);
|
||||||
println!("parse item error: {}", try_item.err().unwrap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Ok(files)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("not array");
|
panic!("invalid avro data, expect array")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let files = from_value::<SyncFileList>(&value);
|
|
||||||
if files.is_err() {
|
|
||||||
// return Err(files.err().unwrap());
|
|
||||||
panic!("parse file list error: ");
|
|
||||||
}
|
|
||||||
let files = files.unwrap();
|
|
||||||
Ok(files.fileinfo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user