diff options
author | Alexander Pevzner <pzz@apevzner.com> | 2020-01-25 15:07:21 +0300 |
---|---|---|
committer | Alexander Pevzner <pzz@apevzner.com> | 2020-01-25 15:07:21 +0300 |
commit | 25288c22aba683812ad50376ce167bff7974775a (patch) | |
tree | 019c7e2a9ed8db60eea2a2584190966a2a4692dc | |
parent | 47cb8cd46533ec50e323cc360b60e145d31743c9 (diff) |
Fixed (Value) Equal()
-rw-r--r-- | goipp_test.go | 4 | ||||
-rw-r--r-- | value.go | 16 |
2 files changed, 19 insertions, 1 deletions
diff --git a/goipp_test.go b/goipp_test.go index 094b7da..1f9acd9 100644 --- a/goipp_test.go +++ b/goipp_test.go @@ -179,6 +179,10 @@ func testDecode(t *testing.T, data []byte, mustFail bool) { return } + if !m.Equal(m) { + t.Errorf("Message is not equal to itself") + } + buf, err := m.EncodeBytes() assertNoError(t, err) @@ -85,6 +85,10 @@ func ValueEqual(v1, v2 Value) bool { return v1.(Time).Equal(v2.(Time).Time) case TypeBinary: return bytes.Equal(v1.(Binary), v2.(Binary)) + case TypeCollection: + c1 := Attributes(v1.(Collection)) + c2 := Attributes(v2.(Collection)) + return c1.Equal(c2) } return v1 == v2 @@ -511,7 +515,17 @@ func (Binary) decode(data []byte) (Value, error) { // Collection represents a collection of attributes // // Use with: TagBeginCollection -type Collection []Attribute +type Collection Attributes + +// Add Attribute to Attributes +func (collection *Collection) Add(attr Attribute) { + *collection = append(*collection, attr) +} + +// Equal checks that two collections are equal +func (c1 Collection) Equal(c2 Attributes) bool { + return Attributes(c1).Equal(Attributes(c2)) +} // String() converts Collection to string func (v Collection) String() string { |