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

add get_namespace_index to Session #16

Merged
merged 2 commits into from
Jan 5, 2025
Merged

add get_namespace_index to Session #16

merged 2 commits into from
Jan 5, 2025

Conversation

oroulet
Copy link
Member

@oroulet oroulet commented Jan 1, 2025

No description provided.

@oroulet oroulet force-pushed the ns_idx branch 3 times, most recently from e73b140 to d9f4a54 Compare January 1, 2025 15:35
@einarmo
Copy link
Contributor

einarmo commented Jan 1, 2025

Okay, this works, but the session actually contains a place where we store a NamespaceMap, and ways to set it, using set_namespace_map.

What if we did:

  • Let read_namespace_array store the read namespace map, and return a clone of the NamespaceMap (it already contains methods for working with namespaces that are easier to use than just Vec<String>, and can be extended).
  • Have get_namespace_index just always read from the cached namespace map, and return None if no namespace map is present.

That does mean the user must make a dedicated call to fetch the namespace array, but it resolves the question of what the return type from get_namespace_index should be (It'd just be an option).

@oroulet
Copy link
Member Author

oroulet commented Jan 1, 2025

I made get_namespace index update namespace in the background... not sure it is a good idea. sounds easier to me. but as you want. anyway who know what they do anyway would query directly the namespace map

@oroulet oroulet force-pushed the ns_idx branch 2 times, most recently from c8cead8 to 2039fa2 Compare January 2, 2025 11:52
@oroulet oroulet requested a review from einarmo January 2, 2025 12:05
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.

This works, just some nitpicks.

We can add methods for getting directly from the cache without retrieving it from the server later, or make it visible in some way.

opcua-client/src/session/mod.rs Outdated Show resolved Hide resolved
opcua-client/src/session/mod.rs Outdated Show resolved Hide resolved
@@ -26,6 +26,23 @@ impl NamespaceMap {
}
}

/// Create a new namespace map from a vec of variant as we get when reading
/// the namespace array from the server
pub fn new_from_variant_array(array: &[Variant]) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably return an error if any variant isn't a string, that is an error in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I think I originally copied that code from somewhere. Can fix now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but once again I need to know what kind of error we should return.
If the project does not define errors, we need to make our own or decide to return the error with statuscode that is used several places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case you can actually define a unit struct for it, or something like struct UnexpectedVariantType(usize) containing the index of the variant that failed or something like that. That's what we do some other places.

Copy link
Member Author

@oroulet oroulet Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But simple enums/structs are not compatible with stderror and create a lot t of issues isn't it?
Then I would rather use thiserror crate which is anyway a dependency

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an MR: As far as I know this is the correct way to do it, but I do not have so much experience with rust

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18

einarmo
einarmo previously approved these changes Jan 5, 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.

Looks good

@oroulet
Copy link
Member Author

oroulet commented Jan 5, 2025

@einarmo I pushed right after your approval... so you need to have a look and maybe approve again

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.

Still fine, provided everything passes 👍

@oroulet oroulet merged commit 65198b5 into master Jan 5, 2025
6 checks passed
@oroulet oroulet deleted the ns_idx branch January 5, 2025 19:43
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.

2 participants