Skip to content

Commit

Permalink
Added Equals method to StructureInterface and required types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed May 21, 2023
1 parent 63f6a23 commit 0801d75
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nex

import (
"bytes"
"errors"
"fmt"
"reflect"
Expand All @@ -15,6 +16,7 @@ type StructureInterface interface {
ExtractFromStream(*StreamIn) error
Bytes(*StreamOut) []byte
Copy() StructureInterface
Equals(StructureInterface) bool
}

// Structure represents a nex Structure type
Expand Down Expand Up @@ -53,7 +55,12 @@ func (data *Data) Bytes(stream *StreamOut) []byte {

// Copy returns a new copied instance of Data
func (data *Data) Copy() StructureInterface {
return NewData()
return NewData() // * Has no fields, nothing to copy
}

// Equals checks if the passed Structure contains the same data as the current instance
func (data *Data) Equals(structure StructureInterface) bool {
return true // * Has no fields, always equal
}

// NewData returns a new Data Structure
Expand Down Expand Up @@ -204,6 +211,29 @@ func (rvConnectionData *RVConnectionData) Copy() StructureInterface {
return copied
}

// Equals checks if the passed Structure contains the same data as the current instance
func (rvConnectionData *RVConnectionData) Equals(structure StructureInterface) bool {
other := structure.(*RVConnectionData)

if rvConnectionData.stationURL != other.stationURL {
return false
}

if !bytes.Equal(rvConnectionData.specialProtocols, other.specialProtocols) {
return false
}

if rvConnectionData.stationURLSpecialProtocols != other.stationURLSpecialProtocols {
return false
}

if rvConnectionData.time != other.time {
return false
}

return true
}

// NewRVConnectionData returns a new RVConnectionData
func NewRVConnectionData() *RVConnectionData {
rvConnectionData := &RVConnectionData{}
Expand Down Expand Up @@ -661,6 +691,21 @@ func (resultRange *ResultRange) Copy() StructureInterface {
return copied
}

// Equals checks if the passed Structure contains the same data as the current instance
func (resultRange *ResultRange) Equals(structure StructureInterface) bool {
other := structure.(*ResultRange)

if resultRange.Offset != other.Offset {
return false
}

if resultRange.Length != other.Length {
return false
}

return true
}

// NewResultRange returns a new ResultRange
func NewResultRange() *ResultRange {
return &ResultRange{}
Expand Down

0 comments on commit 0801d75

Please sign in to comment.