This commit is contained in:
2024-12-18 22:13:41 -06:00
parent e9a4f3de75
commit f59b164095
5 changed files with 374 additions and 237 deletions
+130 -185
View File
@@ -10,92 +10,15 @@ use std::{
use anyhow::anyhow; use anyhow::anyhow;
use anyhow::Result; use anyhow::Result;
use connector::{Connector, UdpConnector}; use connector::{Connector, UdpConnector};
use egui::Ui;
use log::*; use log::*;
use msg::DsTlmSet; use msg::{DsTlmSet, Msg, TargetMsg, TlmSetItem};
use reflect::*; use reflect::*;
use rfe::macros::Reflect; use rfe::macros::Reflect;
use rfe::*; use rfe::*;
use serde::{Deserialize, Serialize}; extern crate alloc;
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct TreeNode {
name: String,
children: Vec<TreeNode>,
}
impl TreeNode {
pub fn new<T: ToString>(name: T, children: Vec<TreeNode>) -> Self {
Self {
name: name.to_string(),
children,
}
}
pub fn add_child<T: ToString>(&mut self, name: T) -> &mut TreeNode {
self.children.push(TreeNode::new(name, Vec::new()));
let i = self.children.len() - 1;
return &mut self.children[i];
}
pub fn get_add_path(&mut self, path: &str) -> &mut TreeNode {
if !path.starts_with(&format!("{}.", self.name)) {
return self;
}
let path = path.replace(&format!("{}.", self.name), "");
let names = path.split(".");
let mut working_tree = self;
for name in names {
let mut index = None;
for (i, child) in &mut working_tree.children.iter().enumerate() {
if child.name == name {
index = Some(i);
break;
}
}
if let Some(index) = index {
working_tree = &mut working_tree.children[index];
} else {
working_tree = working_tree.add_child(name);
}
}
working_tree
}
pub fn is_last(&self) -> bool {
self.children.len() == 0
}
}
fn to_tree(msg_enum: Vec<String>) -> TreeNode {
let mut t = TreeNode::new("Msg", Vec::new());
for p in msg_enum {
let mut x = p
.split(" = ")
.map(|x| x.split("."))
.flatten()
.collect::<Vec<_>>()
.join(".");
if x.starts_with(".") {
x.remove(0);
} else {
x = format!("Msg.{}", x);
}
let s = x.rsplitn(2, ".").collect::<Vec<_>>();
if s.len() == 2 {
t.get_add_path(s[1]).add_child(s[0]);
} else {
t.add_child(s[0]);
}
}
t
}
#[derive(Debug, Default, Reflect)] #[derive(Debug, Default, Reflect)]
struct TestStruct { struct TestStruct {
counter: i8, counter: i8,
@@ -114,116 +37,138 @@ fn main() -> Result<()> {
.init() .init()
.unwrap(); .unwrap();
info!( spawn(|| {
"{:?}", let mut udp = UdpConnector::new("127.0.0.1", 7011, "127.0.0.1", 7010).unwrap();
msg::Msg::DsCmd(msg::DsCmd::AddTlmSet(DsTlmSet::default()))
);
info!(
"json {}",
serde_json::to_string(&msg::Msg::DsCmd(msg::DsCmd::Noop)).unwrap()
);
let mut test = TestStruct::default(); let mut next_time = Instant::now() + Duration::from_millis(10);
info!("{:?}", test.fields()); loop {
reflect::path_set(&mut test, "counter", ReflectValue::I64(1)); sleep(next_time - Instant::now());
info!("{:?}", test.fields());
let mut test2 = EnumTest::None; while let Some(msgs) = udp.recv() {
for msg in msgs {
info!("got msg {:?}", msg);
}
}
next_time += Duration::from_millis(10);
}
});
// info!("{:?}", test2); let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([560.0, 480.0]),
// let testref = test2.as_variant(1).unwrap(); ..Default::default()
};
// test2.as_variant(1).unwrap().fields()[0] eframe::run_native(
// .1 "RFE Ground",
// .set_value(ReflectValue::I64(3)); options,
// info!("{:?}", test2); Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
// spawn(|| { .or(Err(anyhow!("eframe failed")))?;
// let mut udp = UdpConnector::new("127.0.0.1", 7011, "127.0.0.1", 7010).unwrap();
// let mut next_time = Instant::now() + Duration::from_millis(10);
// loop {
// sleep(next_time - Instant::now());
// while let Some(msgs) = udp.recv() {
// for msg in msgs {
// info!("got msg {:?}", msg);
// }
// }
// next_time += Duration::from_millis(10);
// }
// });
// let options = eframe::NativeOptions {
// viewport: egui::ViewportBuilder::default().with_inner_size([560.0, 480.0]),
// ..Default::default()
// };
// eframe::run_native(
// "RFE Ground",
// options,
// Box::new(|_cc| Ok(Box::<MyApp>::default())),
// )
// .or(Err(anyhow!("eframe failed")))?;
return Ok(()); return Ok(());
} }
// struct MyApp { struct MyApp {
// command_path: String, command: Msg,
// tree: TreeNode, values: HashMap<String, String>,
// values: HashMap<String, String>, }
// }
// impl Default for MyApp { impl Default for MyApp {
// fn default() -> Self { fn default() -> Self {
// let tree = to_tree(msg::Msg::None.enumerate_clean()); Self {
// Self { command: Msg::None,
// command_path: "Msg".to_string(), values: HashMap::new(),
// tree, }
// values: HashMap::new(), }
// } }
// }
// }
// impl eframe::App for MyApp { fn build_command_ui_value_number(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { let mut r = cmd.get_value().str();
// egui::CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui| {
// ui.heading(format!("Commands: {}", self.command_path)); ui.label(name);
// if ui.button("X").clicked() { ui.text_edit_singleline(&mut r);
// self.command_path = "Msg".to_string(); cmd.set_value(ReflectValue::Str(r));
// } });
// if self }
// .command_path
// .as_bytes() fn build_command_ui(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
// .iter() match cmd.reflect_type() {
// .filter(|x| **x == b'.') ReflectType::Value => match cmd.get_value() {
// .count() ReflectValue::None => {}
// >= 2 ReflectValue::U8(_) => build_command_ui_value_number(ui, name, cmd),
// { ReflectValue::U16(_) => build_command_ui_value_number(ui, name, cmd),
// for item in &self.tree.get_add_path(&self.command_path).children { ReflectValue::U32(_) => build_command_ui_value_number(ui, name, cmd),
// for c in &item.children { ReflectValue::U64(_) => build_command_ui_value_number(ui, name, cmd),
// if c.is_last() { ReflectValue::I8(_) => build_command_ui_value_number(ui, name, cmd),
// if !self.values.contains_key(&c.name) { ReflectValue::I16(_) => build_command_ui_value_number(ui, name, cmd),
// self.values.insert(c.name.clone(), String::new()); ReflectValue::I32(_) => build_command_ui_value_number(ui, name, cmd),
// } ReflectValue::I64(_) => build_command_ui_value_number(ui, name, cmd),
// let sref = self.values.get_mut(&c.name).unwrap(); ReflectValue::Vec(_vec) => {}
// ui.horizontal(|ui| { ReflectValue::Str(_) => {}
// ui.label(format!("{} : {}", item.name, c.name.clone())); ReflectValue::Bool(_) => {}
// ui.text_edit_singleline(sref); },
// }); ReflectType::Enumeration => {
// } // variants
// }
// } for (i, (name, _v)) in cmd.variants().into_iter().enumerate() {
// if ui.button("send").clicked() { if ui.button(name).clicked() {
// info!("sending {}", self.command_path); cmd.convert_variant(i);
// } }
// } else { }
// for item in &self.tree.get_add_path(&self.command_path).children {
// if ui.button(item.name.clone()).clicked() { // values
// self.command_path = format!("{}.{}", self.command_path, item.name); if let Some((name, cmd)) = cmd.unwrap_variant() {
// } build_command_ui(ui, name, cmd);
// } }
// } }
// }); ReflectType::Structure => {
// } for (name, cmd) in cmd.fields().into_iter() {
// } build_command_ui(ui, name, cmd);
}
}
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading(format!("Command: {:?}", self.command));
if ui.button("X").clicked() {
self.command = Msg::None;
}
build_command_ui(ui, "Msg", &mut self.command);
// if self
// .command_path
// .as_bytes()
// .iter()
// .filter(|x| **x == b'.')
// .count()
// >= 2
// {
// for item in &self.tree.get_add_path(&self.command_path).children {
// for c in &item.children {
// if c.is_last() {
// if !self.values.contains_key(&c.name) {
// self.values.insert(c.name.clone(), String::new());
// }
// let sref = self.values.get_mut(&c.name).unwrap();
// ui.horizontal(|ui| {
// ui.label(format!("{} : {}", item.name, c.name.clone()));
// ui.text_edit_singleline(sref);
// });
// }
// }
// }
// if ui.button("send").clicked() {
// info!("sending {}", self.command_path);
// }
// } else {
// for item in &self.tree.get_add_path(&self.command_path).children {
// if ui.button(item.name.clone()).clicked() {
// self.command_path = format!("{}.{}", self.command_path, item.name);
// }
// }
// }
});
}
}
+46 -12
View File
@@ -147,11 +147,17 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
rfe::reflect::ReflectValue::None rfe::reflect::ReflectValue::None
} }
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> { fn variants(&self) -> alloc::vec::Vec<(&'static str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
alloc::vec::Vec::new() alloc::vec::Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn rfe::reflect::Reflect)> {
None
}
fn as_vec(&mut self) -> Option<alloc::vec::Vec<&mut dyn rfe::reflect::Reflect>> {
None None
} }
} }
@@ -162,7 +168,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
Data::Enum(data_enum) => { Data::Enum(data_enum) => {
let variants = data_enum.variants; let variants = data_enum.variants;
let as_arms = variants.iter().enumerate().map(|(i, variant)| { let convert_arms = variants.iter().enumerate().map(|(i, variant)| {
let variant_name = &variant.ident; let variant_name = &variant.ident;
match &variant.fields { match &variant.fields {
@@ -170,7 +176,6 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
quote! { quote! {
if _i == #i { if _i == #i {
*self = Self::#variant_name; *self = Self::#variant_name;
return Some(self);
} }
} }
} }
@@ -178,11 +183,29 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
quote! { quote! {
if _i == #i { if _i == #i {
*self = Self::#variant_name(Default::default()); *self = Self::#variant_name(Default::default());
if let Self::#variant_name(r) = self {
return Some(r);
} }
} }
} }
Fields::Named(_) => {
panic!("Named fields not supported by Reflect");
}
}
});
let unwrap_arms = variants.iter().enumerate().map(|(_i, variant)| {
let variant_name = &variant.ident;
let variant_name_s = variant_name.to_string();
match &variant.fields {
Fields::Unit => {
quote! {
Self::#variant_name => None,
}
}
Fields::Unnamed(_) => {
quote! {
Self::#variant_name(v) => Some((#variant_name_s, v)),
}
} }
Fields::Named(_) => { Fields::Named(_) => {
panic!("Named fields not supported by Reflect"); panic!("Named fields not supported by Reflect");
@@ -198,16 +221,18 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
Fields::Unit => { Fields::Unit => {
quote! { quote! {
{ {
let name: &'static str = #variant_name_s;
let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name); let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name);
variants.push((#variant_name_s, value)); variants.push((name, value));
} }
} }
} }
Fields::Unnamed(_) => { Fields::Unnamed(_) => {
quote! { quote! {
{ {
let name: &'static str = #variant_name_s;
let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name(Default::default())); let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name(Default::default()));
variants.push((#variant_name_s, value)); variants.push((name, value));
} }
} }
@@ -239,15 +264,24 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
rfe::reflect::ReflectValue::None rfe::reflect::ReflectValue::None
} }
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> { fn variants(&self) -> alloc::vec::Vec<(&'static str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
let mut variants = alloc::vec::Vec::new(); let mut variants = alloc::vec::Vec::new();
#(#variant_arms)* #(#variant_arms)*
variants variants
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> { fn convert_variant(&mut self, _i: usize) {
#(#as_arms)* #(#convert_arms)*
panic!("variant incorrect"); }
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn rfe::reflect::Reflect)> {
match self {
#(#unwrap_arms)*
}
}
fn as_vec(&mut self) -> Option<alloc::vec::Vec<&mut dyn rfe::reflect::Reflect>> {
None
} }
} }
} }
+1
View File
@@ -111,6 +111,7 @@ pub type TlmSetId = u16;
#[cfg_attr(feature = "reflect", derive(Reflect))] #[cfg_attr(feature = "reflect", derive(Reflect))]
pub struct TlmSetItem { pub struct TlmSetItem {
pub target: TargetMsg, pub target: TargetMsg,
/// decimation 0 means sends every msg, decimation 1 means sends every other, etc
pub decimation: u16, pub decimation: u16,
pub counter: u16, pub counter: u16,
} }
+196 -38
View File
@@ -1,10 +1,25 @@
extern crate alloc; extern crate alloc;
use core::mem::zeroed;
use std::string::ToString; use std::string::ToString;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::string::String; use alloc::string::String;
use alloc::vec::Vec; use alloc::vec::Vec;
use hashbrown::HashMap;
pub trait Reflect: std::fmt::Debug {
fn reflect_type(&self) -> ReflectType;
fn type_name(&self) -> &str;
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)>;
fn set_value(&mut self, value: ReflectValue);
fn get_value(&self) -> ReflectValue;
fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)>;
fn convert_variant(&mut self, i: usize);
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)>;
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReflectType { pub enum ReflectType {
Value, Value,
Enumeration, Enumeration,
@@ -39,7 +54,13 @@ impl ReflectValue {
ReflectValue::I32(v) => *v as i64, ReflectValue::I32(v) => *v as i64,
ReflectValue::I64(v) => *v as i64, ReflectValue::I64(v) => *v as i64,
ReflectValue::Vec(_) => 0, ReflectValue::Vec(_) => 0,
ReflectValue::Str(_) => 0, ReflectValue::Str(s) => {
if let Ok(v) = s.parse() {
v
} else {
0
}
}
ReflectValue::Bool(b) => { ReflectValue::Bool(b) => {
if *b { if *b {
1 1
@@ -62,7 +83,13 @@ impl ReflectValue {
ReflectValue::I32(v) => *v as u64, ReflectValue::I32(v) => *v as u64,
ReflectValue::I64(v) => *v as u64, ReflectValue::I64(v) => *v as u64,
ReflectValue::Vec(_) => 0, ReflectValue::Vec(_) => 0,
ReflectValue::Str(_) => 0, ReflectValue::Str(s) => {
if let Ok(v) = s.parse() {
v
} else {
0
}
}
ReflectValue::Bool(b) => { ReflectValue::Bool(b) => {
if *b { if *b {
1 1
@@ -76,7 +103,17 @@ impl ReflectValue {
pub fn str(self) -> String { pub fn str(self) -> String {
match self { match self {
ReflectValue::Str(s) => s, ReflectValue::Str(s) => s,
_ => "".to_string(), ReflectValue::None => "".to_string(),
ReflectValue::U8(v) => v.to_string(),
ReflectValue::U16(v) => v.to_string(),
ReflectValue::U32(v) => v.to_string(),
ReflectValue::U64(v) => v.to_string(),
ReflectValue::I8(v) => v.to_string(),
ReflectValue::I16(v) => v.to_string(),
ReflectValue::I32(v) => v.to_string(),
ReflectValue::I64(v) => v.to_string(),
ReflectValue::Vec(_v) => "".to_string(),
ReflectValue::Bool(v) => v.to_string(),
} }
} }
@@ -98,18 +135,12 @@ impl ReflectValue {
} }
pub fn vec(self) -> Vec<ReflectValue> { pub fn vec(self) -> Vec<ReflectValue> {
if let ReflectValue::Vec(v) = self {
v
} else {
Vec::new()
}
} }
}
pub trait Reflect: std::fmt::Debug {
fn reflect_type(&self) -> ReflectType;
fn type_name(&self) -> &str;
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)>;
fn set_value(&mut self, value: ReflectValue);
fn get_value(&self) -> ReflectValue;
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)>;
fn as_variant(&mut self, i: usize) -> Option<&mut dyn Reflect>;
} }
pub fn path_set(reflect: &mut dyn Reflect, path: &str, value: ReflectValue) { pub fn path_set(reflect: &mut dyn Reflect, path: &str, value: ReflectValue) {
@@ -148,6 +179,51 @@ pub fn path_get<'a>(reflect: &'a mut dyn Reflect, path: &str) -> Option<&'a mut
Some(next) Some(next)
} }
fn _flatten<'a>(reflect: &'a mut dyn Reflect) -> HashMap<String, &'a mut dyn Reflect> {
let mut list = HashMap::new();
match reflect.reflect_type() {
ReflectType::Value => match reflect.get_value() {
ReflectValue::Vec(_) => {
for (i, r) in reflect.as_vec().unwrap().into_iter().enumerate() {
let map = _flatten(r);
for (sn, v) in map {
list.insert(alloc::format!("[{i}].{}", sn), v);
}
}
}
_ => {
list.insert("".to_string(), reflect);
}
},
ReflectType::Enumeration => {
if let Some((name, r)) = reflect.unwrap_variant() {
let map = _flatten(r);
for (sn, v) in map {
list.insert(alloc::format!("{}.{}", name, sn), v);
}
}
}
ReflectType::Structure => {
for (name, r) in reflect.fields() {
let map = _flatten(r);
for (sn, v) in map {
list.insert(alloc::format!("{}.{}", name, sn), v);
}
}
}
}
list
}
pub fn flatten<'a>(reflect: &'a mut dyn Reflect) -> HashMap<String, &'a mut dyn Reflect> {
_flatten(reflect)
.into_iter()
.map(|(k, v)| (k[..k.len() - 1].to_string().replace(".[", "["), v))
.collect()
}
impl Reflect for u8 { impl Reflect for u8 {
fn reflect_type(&self) -> ReflectType { fn reflect_type(&self) -> ReflectType {
ReflectType::Value ReflectType::Value
@@ -169,11 +245,17 @@ impl Reflect for u8 {
ReflectValue::U8(*self) ReflectValue::U8(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -199,11 +281,17 @@ impl Reflect for u16 {
ReflectValue::U16(*self) ReflectValue::U16(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -229,11 +317,17 @@ impl Reflect for u32 {
ReflectValue::U32(*self) ReflectValue::U32(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -259,11 +353,17 @@ impl Reflect for u64 {
ReflectValue::U64(*self) ReflectValue::U64(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -289,11 +389,17 @@ impl Reflect for i8 {
ReflectValue::I8(*self) ReflectValue::I8(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -319,11 +425,17 @@ impl Reflect for i16 {
ReflectValue::I16(*self) ReflectValue::I16(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -349,11 +461,17 @@ impl Reflect for i32 {
ReflectValue::I32(*self) ReflectValue::I32(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -379,11 +497,17 @@ impl Reflect for i64 {
ReflectValue::I64(*self) ReflectValue::I64(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -409,11 +533,17 @@ impl Reflect for String {
ReflectValue::Str(self.to_string()) ReflectValue::Str(self.to_string())
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -439,11 +569,17 @@ impl Reflect for bool {
ReflectValue::Bool(*self) ReflectValue::Bool(*self)
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None
}
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>> {
None None
} }
} }
@@ -462,18 +598,40 @@ impl<T: Reflect> Reflect for Vec<T> {
} }
fn set_value(&mut self, value: ReflectValue) { fn set_value(&mut self, value: ReflectValue) {
*self = value.vec(); if let ReflectValue::Vec(v) = value {
*self = v
.into_iter()
.map(|x| {
let mut t: T = unsafe { zeroed() };
t.set_value(x);
t
})
.collect();
}
} }
fn get_value(&self) -> ReflectValue { fn get_value(&self) -> ReflectValue {
ReflectValue::Bool(*self) ReflectValue::Vec(self.iter().map(|x| x.get_value()).collect())
} }
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> { fn variants(&self) -> Vec<(&'static str, Box<dyn Reflect>)> {
Vec::new() Vec::new()
} }
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { fn convert_variant(&mut self, _i: usize) {}
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)> {
None None
} }
fn as_vec<'a>(&'a mut self) -> Option<Vec<&'a mut dyn Reflect>> {
Some(
self.iter_mut()
.map(|x| {
let v: &mut dyn Reflect = x;
v
})
.collect(),
)
}
} }
-1
View File
@@ -12,7 +12,6 @@ use std::{
use anyhow::Result; use anyhow::Result;
use bincode::decode_from_std_read; use bincode::decode_from_std_read;
use log::*; use log::*;
use rfe::to_csv::ToCsvClean;
use rfe::{msg::MsgPacket, BINCODE_CONFIG}; use rfe::{msg::MsgPacket, BINCODE_CONFIG};
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;