This commit is contained in:
shenjack 2024-01-27 01:03:33 +08:00
parent a9d8ed9817
commit 8ece5d8211
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 4 additions and 9 deletions

View File

@ -86,12 +86,7 @@ impl Cluster {
panic!("decompress file list error: {:?}", raw_data.err()); panic!("decompress file list error: {:?}", raw_data.err());
} }
let raw_data = raw_data.unwrap(); let raw_data = raw_data.unwrap();
let file_list = avro_data_to_file_list(raw_data); avro_data_to_file_list(raw_data)
if file_list.is_err() {
panic!("parse file list error: {:?}", file_list.err());
}
let file_list = file_list.unwrap();
file_list
} }
_ => { _ => {
panic!("error status: {:?}", res.status()); panic!("error status: {:?}", res.status());

View File

@ -70,12 +70,12 @@ pub const SYNC_FILE_LIST_SCHEMA: &str = r#"
"#; "#;
/// 用来将 BYD avro 格式的数据转换成文件列表 /// 用来将 BYD avro 格式的数据转换成文件列表
pub fn avro_data_to_file_list(data: Vec<u8>) -> apache_avro::AvroResult<Vec<SyncFile>> { pub fn avro_data_to_file_list(data: Vec<u8>) -> Vec<SyncFile> {
let chema = apache_avro::Schema::parse_str(SYNC_FILE_LIST_SCHEMA).unwrap(); let chema = apache_avro::Schema::parse_str(SYNC_FILE_LIST_SCHEMA).unwrap();
let mut cur = Cursor::new(data); let mut cur = Cursor::new(data);
let reader = from_avro_datum(&chema, &mut cur, Some(&chema)); let reader = from_avro_datum(&chema, &mut cur, Some(&chema));
if reader.is_err() { if reader.is_err() {
return Err(reader.err().unwrap()); panic!("parse avro data error: {:?}", reader.err());
} }
let value = reader.unwrap(); let value = reader.unwrap();
match &value { match &value {
@ -86,7 +86,7 @@ pub fn avro_data_to_file_list(data: Vec<u8>) -> apache_avro::AvroResult<Vec<Sync
let try_item = from_value::<SyncFile>(item).unwrap(); let try_item = from_value::<SyncFile>(item).unwrap();
files.push(try_item); files.push(try_item);
} }
Ok(files) files
} }
_ => { _ => {
panic!("invalid avro data, expect array") panic!("invalid avro data, expect array")