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

Encode nil node id as zero #507

Closed
wants to merge 2 commits into from
Closed

Conversation

magiconair
Copy link
Member

@magiconair magiconair commented Nov 22, 2021

This patch encodes a nil NodeID as a two byte zero node id.

See #506

@magiconair magiconair force-pushed the encode-nil-nodeid-as-zero branch from a57c821 to eef5288 Compare November 22, 2021 10:53
This patch encodes a 'nil' NodeID as a two byte zero node id.

See #506
@magiconair magiconair changed the title Encode nil nodeid as zero Encode nil node id as zero Nov 22, 2021
@magiconair magiconair linked an issue Nov 22, 2021 that may be closed by this pull request
@magiconair
Copy link
Member Author

Pinging the other OPC/UA experts on the team about this change.

@magiconair magiconair added this to the v0.2.3 milestone Nov 22, 2021
@magiconair magiconair added the enhancement New feature or request label Nov 22, 2021
@kung-foo
Copy link
Member

not sure... seems like encoding a nil node id should panic. In other words, I would be surprised when it didn't panic since a nil node seems like an error on my part.

However, I see this:

A null NodeId has special meaning. For example, many services defined in OPC 10000-4 define special behaviour if a null NodeId is passed as a parameter. Each IdType has a set of identifier values that represent a null NodeId. These values are summarised in Table 24.

https://reference.opcfoundation.org/v104/Core/docs/Part3/8.2.4/

So maybe there is a valid reason. But in that case, I'd rather have a NewNullNodeID() func.

@magiconair
Copy link
Member Author

Having a function still means that you have to set it everywhere and Encode would still panic if you forget it. What would be the benefit of the function?

@kung-foo
Copy link
Member

It's the surprise factor. I'd be surprised if it didn't panic, and I might be surprised if it returned unexpected data because there was a special "null" node id generated (unexpectedly) behind the scenes. I just don't like surprises (birthday parties excepted). Where would we document that any where and for any reason a node id is nil, it will still (sorta) work? I would not expect a user to dig in and look at NodeID.Encode...

@magiconair
Copy link
Member Author

Since the concept of a nil NodeID doesn't exist and is sent as zero value I think this should be in the Encode method. This is how the protocol works and how we translate it to Go. TBH, I always considered it odd that I have to provide the zero value explicitly if all I want to do is to send the default and was usually surprised by the panic. Yes, setting the zero value is more explicit but it also feels like initialising a struct with 0 and false which you wouldn't do in Go.

What I'm struggling with is whether this should stop at the NodeID. The BrowseRequest for example also has an optional ViewDescription. Why do I have to provide a &ua.ViewDescription{ViewID: ua.NewTwoByteNodeID(0)}if all I want is to omit it? That's also exactly the thing the original author was struggling with and what the defaults helper functions provide. Maybe optional fields should be serialised to their zero value when set to nil.

@magiconair
Copy link
Member Author

magiconair commented Nov 23, 2021

But it is also this inconsistency which makes me a bit reluctant about this PR in particular since we should either address all optional fields or none of them but not just a select few.

@magiconair
Copy link
Member Author

Lets park this one.

@magiconair magiconair removed this from the v0.2.3 milestone Nov 24, 2021
@magiconair
Copy link
Member Author

I'll close this one since there is no agreement.

@magiconair magiconair closed this Jan 20, 2022
@magiconair magiconair deleted the encode-nil-nodeid-as-zero branch January 20, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants