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

Issue #722: Set DataValue.Value to Variant(nil) for no value #756

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ua/datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type DataValue struct {
func (d *DataValue) Decode(b []byte) (int, error) {
buf := NewBuffer(b)
d.EncodingMask = buf.ReadByte()
d.Value = new(Variant)
if d.Has(DataValueValue) {
d.Value = new(Variant)
buf.ReadStruct(d.Value)
}
if d.Has(DataValueStatusCode) {
Expand Down
45 changes: 43 additions & 2 deletions ua/datatypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import (

func TestDataValue(t *testing.T) {
cases := []CodecTestCase{
{
Name: "no value",
Struct: &DataValue{
EncodingMask: 0x00,
Value: MustVariant(nil),
},
Bytes: []byte{
// EncodingMask
0x00,
},
},
{
Name: "value only",
Struct: &DataValue{
Expand Down Expand Up @@ -45,14 +56,31 @@ func TestDataValue(t *testing.T) {
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
},
},
{
Name: "source timestamp, server timestamp",
Struct: &DataValue{
EncodingMask: 0x0c,
Value: MustVariant(nil),
SourceTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
ServerTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
},
Bytes: []byte{
// EncodingMask
0x0c,
// SourceTimestamp
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
// SeverTimestamp
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
},
},
}
RunCodecTest(t, cases)
}

func TestDataValueArray(t *testing.T) {
cases := []CodecTestCase{
{
Name: "value only and value, source timestamp, server timestamp",
Name: "value only; value, source timestamp, server timestamp; source timestamp, server timestamp",
Struct: []*DataValue{
{
EncodingMask: 0x01,
Expand All @@ -64,10 +92,16 @@ func TestDataValueArray(t *testing.T) {
SourceTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
ServerTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
},
{
EncodingMask: 0x0c,
Value: MustVariant(nil),
SourceTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
ServerTimestamp: time.Date(2018, time.September, 17, 14, 28, 29, 112000000, time.UTC),
},
},
Bytes: []byte{
// length
0x02, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00,

// EncodingMask
0x01,
Expand All @@ -84,6 +118,13 @@ func TestDataValueArray(t *testing.T) {
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
// ServerTimestamp
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,

// EncodingMask
0x0c,
// SourceTimestamp
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
// ServerTimestamp
0x80, 0x3b, 0xe8, 0xb3, 0x92, 0x4e, 0xd4, 0x01,
},
},
}
Expand Down
Loading