-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom structures client #15
Conversation
panic!("Unexpected variant type"); | ||
}; | ||
//dbg!(&val); | ||
//let val: DynamicStructure = *val.into_inner_as().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that one works fine
//dbg!(&val); | ||
//let val: DynamicStructure = *val.into_inner_as().unwrap(); | ||
//dbg!(val.values()); | ||
let val: ErrorData = *val.into_inner_as().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that possible at all? how? @einarmo ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just taking the value stored in the extension object and downcasting it to the type it really is. Getting it as ErrorData
would require somehow deserializing from a DynamicStructure
to a specific struct. I suppose something like that could be implemented, but not trivially.
into_inner_as
will only return Some
if the type stored inside the extension object is the type you're calling it with. It won't do any clever conversions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to actually deserialize to an ErrorData
you need to create a type loader for that type, like you did on the server side. DynamicStructure
is primarily intended to be used when you can't do that. For example if you are creating a generic client like UAExpert, and you want to support custom structures, you need some way to deserialize from OPC-UA binary using only runtime information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@einarmo I tried to look around in code but could not find how to deserialize to ErrorData. Any pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@einarmo If you know something I would really appreciate. I really feel I am overlooking something not that hard here that should should be documented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. You have two real options here.
First, you can do like you do on the server and create a TypeLoader
that supports ErrorData
instead of using DynamicStructure
.
Your other option is to do something like this:
ErrorData {
message: dyn_structure.get_value_by_name("Message").unwrap().clone().try_cast_to().unwrap(),
error_id: dyn_structure.get_value_by_name("ErrorId").unwrap().clone().try_cast_to().unwrap(),
...
}
In theory we could make a macro to implement that automatically, and maybe have a way to consume a DynamicStructure
and return its values so we can drop the clone.
Part of your problem here is that you are really meant to use only one of the two methods:
- Either you know the types you need at compile time, so you make a
TypeLoader
to convert directly to those. - Or you don't, so you use
DynamicStructure
.
You are kinda trying to do both at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. made decoding works now.
Next is to look at encoding
but all these hardcoded node ids is not that great. need a closer look at it later
263146b
to
1f27e9b
Compare
53da4a6
to
de3cb20
Compare
e54d13d
to
d29c249
Compare
@einarmo ready now I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Al lot of nitpicking, but I think good readable code is important (especially in an example, but in general as well).
@svanharmelen not problem. I like feedback ;-) |
761d55d
to
9a32f59
Compare
Noticed the changes (looks much better already), but there are still an number (4 or 5) of unresolved comments. Could you check those as well? Thanks! |
OK I see that maybe I should show how to do automatic serialization to rust objects too or remove code related to that here. I jsut need to find out how to do that... |
541695b
to
1dd962c
Compare
1dd962c
to
4a1e02f
Compare
b0dc745
to
d8c5449
Compare
d8c5449
to
93fdcea
Compare
I made some final tidying up, and moved some of the write logic into a dedicated utility method. Small changes, mostly, but in a recent change I added a new way to define type loaders that is a lot less verbose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this now if you're OK with my changes @oroulet.
93fdcea
to
824cc72
Compare
824cc72
to
505d91b
Compare
Fine too but someone needs to approve. I cannot and maybe you cannot so @svanharmelen maybe? |
No description provided.