diff --git a/hash/hashserializer/hashserializer.go b/hash/hashserializer/hashserializer.go index b134146d7..01c5ecfce 100644 --- a/hash/hashserializer/hashserializer.go +++ b/hash/hashserializer/hashserializer.go @@ -179,6 +179,9 @@ type StringSlice []string // HashSerialize returns the hash-serialized string of this type. func (s StringSlice) HashSerialize() string { + if s == nil || len(s) == 0 { + return "" + } ser := New() for i, value := range s { ser.AddString(strconv.Itoa(i), value) diff --git a/process/serialize.go b/process/serialize.go index 73e6d2c9a..fd89e0bb1 100644 --- a/process/serialize.go +++ b/process/serialize.go @@ -81,12 +81,15 @@ type mapProcessNodeMapOutput map[string]*Process_Node_Map_Output // HashSerialize returns the hashserialized string of this type func (data mapProcessNodeMapOutput) HashSerialize() string { - ser := hashserializer.New() + if data == nil || len(data) == 0 { + return "" + } keys := make([]string, 0, len(data)) for k := range data { keys = append(keys, k) } sort.Strings(keys) + ser := hashserializer.New() for _, key := range keys { ser.Add(key, data[key]) } @@ -133,7 +136,7 @@ type processNodeMapOutputs []*Process_Node_Map_Output // HashSerialize returns the hashserialized string of this type func (data processNodeMapOutputs) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -180,7 +183,7 @@ type processNodeFilterConditions []Process_Node_Filter_Condition // HashSerialize returns the hashserialized string of this type func (data processNodeFilterConditions) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -214,7 +217,7 @@ type processNodes []*Process_Node // HashSerialize returns the hashserialized string of this type func (data processNodes) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -228,7 +231,7 @@ type processEdges []*Process_Edge // HashSerialize returns the hashserialized string of this type func (data processEdges) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() diff --git a/protobuf/types/serialize.go b/protobuf/types/serialize.go index 3789fc41b..9a8b000be 100644 --- a/protobuf/types/serialize.go +++ b/protobuf/types/serialize.go @@ -21,12 +21,15 @@ type mapValue map[string]*Value // HashSerialize returns the hashserialized string of this type func (data mapValue) HashSerialize() string { - ser := hashserializer.New() + if data == nil || len(data) == 0 { + return "" + } keys := make([]string, 0, len(data)) for k := range data { keys = append(keys, k) } sort.Strings(keys) + ser := hashserializer.New() for _, key := range keys { ser.Add(key, data[key]) } @@ -62,7 +65,7 @@ type values []*Value // HashSerialize returns the hashserialized string of this type func (data values) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() diff --git a/service/serialize.go b/service/serialize.go index 62e7e1fd9..cf5627fa4 100644 --- a/service/serialize.go +++ b/service/serialize.go @@ -100,7 +100,7 @@ type serviceTasks []*Service_Task // HashSerialize returns the hashserialized string of this type func (data serviceTasks) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -114,7 +114,7 @@ type serviceParameters []*Service_Parameter // HashSerialize returns the hashserialized string of this type func (data serviceParameters) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -128,7 +128,7 @@ type serviceEvents []*Service_Event // HashSerialize returns the hashserialized string of this type func (data serviceEvents) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New() @@ -142,7 +142,7 @@ type serviceDependencies []*Service_Dependency // HashSerialize returns the hashserialized string of this type func (data serviceDependencies) HashSerialize() string { - if data == nil { + if data == nil || len(data) == 0 { return "" } ser := hashserializer.New()