Skip to content
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

Merged
merged 4 commits into from
Mar 6, 2025
Merged

Custom structures client #15

merged 4 commits into from
Mar 6, 2025

Conversation

oroulet
Copy link
Member

@oroulet oroulet commented Jan 1, 2025

No description provided.

@oroulet oroulet changed the base branch from master to custom_example January 1, 2025 10:46
panic!("Unexpected variant type");
};
//dbg!(&val);
//let val: DynamicStructure = *val.into_inner_as().unwrap();
Copy link
Member Author

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();
Copy link
Member Author

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 ?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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

Base automatically changed from custom_example to master January 8, 2025 06:11
@oroulet oroulet force-pushed the custom-struc-client branch from 53da4a6 to de3cb20 Compare January 8, 2025 08:07
@oroulet oroulet changed the title Draft: Custom struc client Custom struc client Jan 8, 2025
@oroulet oroulet force-pushed the custom-struc-client branch 2 times, most recently from e54d13d to d29c249 Compare January 8, 2025 08:15
@oroulet
Copy link
Member Author

oroulet commented Jan 8, 2025

@einarmo ready now I think.

@svanharmelen svanharmelen changed the title Custom struc client Custom structures client Jan 8, 2025
Copy link
Contributor

@svanharmelen svanharmelen left a 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).

@oroulet
Copy link
Member Author

oroulet commented Jan 8, 2025

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 ;-)

@oroulet oroulet force-pushed the custom-struc-client branch from 761d55d to 9a32f59 Compare January 8, 2025 12:05
@oroulet oroulet requested a review from svanharmelen January 8, 2025 20:25
@svanharmelen
Copy link
Contributor

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!

@oroulet
Copy link
Member Author

oroulet commented Jan 9, 2025

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...

@oroulet oroulet force-pushed the custom-struc-client branch 2 times, most recently from 541695b to 1dd962c Compare January 11, 2025 12:31
@oroulet oroulet force-pushed the custom-struc-client branch from 1dd962c to 4a1e02f Compare January 12, 2025 14:56
@oroulet oroulet force-pushed the custom-struc-client branch 4 times, most recently from b0dc745 to d8c5449 Compare February 9, 2025 10:45
@einarmo einarmo force-pushed the custom-struc-client branch from d8c5449 to 93fdcea Compare March 6, 2025 06:52
@einarmo
Copy link
Contributor

einarmo commented Mar 6, 2025

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.

einarmo
einarmo previously approved these changes Mar 6, 2025
Copy link
Contributor

@einarmo einarmo left a 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.

@oroulet
Copy link
Member Author

oroulet commented Mar 6, 2025

I'm fine with this now if you're OK with my changes @oroulet.

Fine too but someone needs to approve. I cannot and maybe you cannot so @svanharmelen maybe?

@oroulet oroulet merged commit cc0209d into master Mar 6, 2025
6 checks passed
@oroulet oroulet deleted the custom-struc-client branch March 6, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants