ValueSimilar checks if two values are **logically** equal, which means the following: - If values are equal (i.e., ValueEqual() returns true), they are similar. - Binary and String values are similar, if they represent the same sequence of bytes. - Two collections are similar, if they contain the sa
(v1, v2 Value)
| 190 | // set of attributes (but may be differently ordered) and |
| 191 | // values of these attributes are similar. |
| 192 | func ValueSimilar(v1, v2 Value) bool { |
| 193 | if ValueEqual(v1, v2) { |
| 194 | return true |
| 195 | } |
| 196 | |
| 197 | t1 := v1.Type() |
| 198 | t2 := v2.Type() |
| 199 | |
| 200 | switch { |
| 201 | case t1 == TypeBinary && t2 == TypeString: |
| 202 | return bytes.Equal(v1.(Binary), []byte(v2.(String))) |
| 203 | |
| 204 | case t1 == TypeString && t2 == TypeBinary: |
| 205 | return bytes.Equal([]byte(v1.(String)), v2.(Binary)) |
| 206 | |
| 207 | case t1 == TypeCollection && t2 == TypeCollection: |
| 208 | return Attributes(v1.(Collection)).Similar( |
| 209 | Attributes(v2.(Collection))) |
| 210 | } |
| 211 | |
| 212 | return false |
| 213 | } |
| 214 | |
| 215 | // Void is the Value that represents "no value" |
| 216 | // |