1
This commit is contained in:
parent
706be6c8fa
commit
c8ca016ae7
@ -5,7 +5,10 @@ use protobuf::Message;
|
|||||||
use protobuf::descriptor::FieldDescriptorProto_Type;
|
use protobuf::descriptor::FieldDescriptorProto_Type;
|
||||||
|
|
||||||
pub trait ProtoMsg {
|
pub trait ProtoMsg {
|
||||||
fn get_proto(&self) -> &dyn Message;
|
fn deserialize(&self,
|
||||||
|
obj: &serde_json::Map<String, serde_json::Value>,
|
||||||
|
id_key: &mut i64,
|
||||||
|
name_key: &mut String) {}
|
||||||
fn init1(&self) {}
|
fn init1(&self) {}
|
||||||
fn init2(&self) {}
|
fn init2(&self) {}
|
||||||
fn init3(&self) {}
|
fn init3(&self) {}
|
||||||
@ -26,19 +29,22 @@ pub struct MetaMgr<T> {
|
|||||||
meta_classes: Vec<MetaClass::<T>>,
|
meta_classes: Vec<MetaClass::<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_to_pb(obj: &serde_json::Map<String, serde_json::Value>, pb: &dyn protobuf::Message) {
|
fn json_to_pb(obj: &serde_json::Map<String, serde_json::Value>, pb: &mut dyn protobuf::Message) {
|
||||||
|
let mut v = Vec::<u8>::new();
|
||||||
let desc = pb.descriptor();
|
let desc = pb.descriptor();
|
||||||
for field in desc.fields() {
|
for field in desc.fields() {
|
||||||
let field_desc = field.proto();
|
let field_desc = field.proto();
|
||||||
match obj.get(field.name()) {
|
match obj.get(field.name()) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut slice: &[u8] = v.as_slice();
|
||||||
|
let is = &mut ::protobuf::CodedInputStream::new(&mut slice);
|
||||||
|
pb.merge_from(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + ProtoMsg> MetaMgr<T> {
|
impl<T: Clone + ProtoMsg> MetaMgr<T> {
|
||||||
@ -69,7 +75,9 @@ impl<T: Clone + ProtoMsg> MetaMgr<T> {
|
|||||||
},
|
},
|
||||||
serde_json::Value::Object(obj) =>{
|
serde_json::Value::Object(obj) =>{
|
||||||
let msg = Rc::new(meta.dummy.clone());
|
let msg = Rc::new(meta.dummy.clone());
|
||||||
json_to_pb(&obj, msg.get_proto());
|
let id_key = &mut 0;
|
||||||
|
let name_key = &mut String::new();
|
||||||
|
msg.deserialize(&obj, id_key, name_key);
|
||||||
meta.wrap_list.push(msg);
|
meta.wrap_list.push(msg);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user