-
Notifications
You must be signed in to change notification settings - Fork 271
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
ua: add support for encoding null variants #364
Conversation
if v.Kind() == reflect.Invalid { | ||
return nil, nil, 0, nil | ||
} | ||
|
||
// ByteString is its own type | ||
if v.Type() == reflect.TypeOf([]byte{}) { |
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.
v.Type()
causes a panic when v is the zero value (reflect.ValueOf(nil)
). We use the Kind
method prior to checking Type
here to handle zero value. See https://pkg.go.dev/reflect?tab=doc#Value.
Which codepath does the test check? |
Encoding a NULL variant. The following program: package main
import (
"github.com/gopcua/opcua/ua"
)
func main() {
v := ua.Variant{}
_, err := v.Decode([]byte{0x0})
if err != nil {
panic(err)
}
v.Encode()
} Causes a run-time panic when calling
|
But this doesn't cover the |
13aa006
to
4b132d7
Compare
Ah, yeah. That was unclear. The codepath was implicitly tested via the codec test case that uses I added two additional tests now to make it more explicit, one for |
Thank you |
Follow-up to #284, add a codec test case for a variant with a value of zero and ensure that it can be encoded without yielding a run-time panic.
What do you think @kung-foo, @magiconair?