Closed jimy-byerley closed 1 year ago
I forgot to add the xml files I was using for tests: xml.zip
This is duplicate of #510 and the error is generated by this (and the others Option<Vec<T>>
) piece of code:
https://github.com/ethercat-rs/ethercat-esi/blob/3d295ca4c1f8c86f1046a85ce93d14b5d85dcc04/src/parser/mod.rs#L43-L46
This is already fixed in master and I plan to release soon (I think in week or two). You can also change the definition to Vec<T>
with the default value as suggested here.
Thank you very much for your quick answer
I tried both the solutions you proposed, but I still get the missing field
issue
Here are the branches where I put the modifications you suggested
ethercat-esi
to use quick-xml master
branch (commit https://github.com/tafia/quick-xml/commit/40b14489f0cd6ada136f11ae7aceecced1a82f9d)ethercat-esi
to use quick-xml = 1.27.1
and remove mentions of Option<Vec>
Is there something I missed ? :thinking:
Yeah, forgot to mention that you should also tweak your mappings, because quick-xml expect that attributes are named starting from @
. Check out the reference.
Indeed, I didn't paid pattention to the fact that quick-xml wasn't implicitely using attributes instead of fields when they were missing. Sorry for that.
I tweaked it as you said. It does find more fields, but now it it gets an even stranger error: missing field '@StartAddress'
Probably that attribute is really missed? Check the all Sm
elements in your XML to see if that true.
Unfortunately it is not missing :thinking:
The same error happens with the unit tests of ethercat-esi
, those fields are not missing either but what is strange is that only @StartAddress
is not found whereas before a lot of fields where. I wonder if there is something special about it. I double checked for mistypes but it appears to be fine ...
Maybe it will be easier to reproduce the issue using the unit tests rather than using my xml files.
those are the failing unit tests in ethercat-esi
:
Ok, there is a bug when you have a list in the enum variant:
#[test]
fn issue567() {
#[derive(Debug, Deserialize, PartialEq)]
struct Device {
#[serde(rename = "$value")]
items: Vec<DeviceProperty>,
}
#[derive(Debug, Deserialize, PartialEq)]
enum DeviceProperty {
Sm(Vec<()>),
}
assert_eq!(// currently failed with Unexpected::End
Device {
items: vec![
DeviceProperty::Sm(vec![]),
]
},
// Currently failed at unwrap() with UnexpectedEnd(b"Device")
from_str("<Device><Sm/></Device>").unwrap()
);
}
Hum, like for Option<Vec>
I guess :thinking:
The error probably in the line 2723:
https://github.com/tafia/quick-xml/blob/642de0a28721447822867ec966c79437c1dc1436/src/de/mod.rs#L2715-L2725
We should pass the deserializer with another implementation of deserialize_seq
method here. The implementation should be similar to
https://github.com/tafia/quick-xml/blob/642de0a28721447822867ec966c79437c1dc1436/src/de/map.rs#L708-L715
but with de: &Deserializer
instead of map: &MapAccess
.
Hello dear maintainers
I'm trying to alter
ethercat-esi
to usequick_xml
instead ofserde-xml-rs
. This is pretty straight forward asethercat-esi
crate is only using theserde
macros and calling the xml parser at one place.Running this code (in lib or in a test file of that crate) gives me the following output on both xml files
These fields and the Groups markups are good in the xml files. And it doesn't seems to come from the serde declarations of the xml data (in
ethercat-esi/src/mod.rs
), so I suggest there is an issue with the way thequick_xml
functions are calling or checking results of the serde deserialization functions. (especially since the error is not the same depending on the version ofquick_xml
) How do you think I could solve this problem ?