mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-20 22:10:30 +00:00
Code Encode/Decode of StringSet so we can call it from Sets
Code-gen process refuses to generate them before compiling the call, which fails because they don't exist yet.
This commit is contained in:
@@ -87,6 +87,9 @@ const (
|
||||
containerMapKey = 2
|
||||
containerMapValue = 3
|
||||
containerMapEnd = 4
|
||||
|
||||
containerArrayElem = 6
|
||||
containerArrayEnd = 7
|
||||
// from https://github.com/ugorji/go/blob/master/codec/helper.go#L152
|
||||
cUTF8 = 2
|
||||
)
|
||||
|
||||
@@ -2,6 +2,8 @@ package report
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
// StringSet is a sorted set of unique strings. Clients must use the Add
|
||||
@@ -132,3 +134,41 @@ loop:
|
||||
result = append(result, other[j:]...)
|
||||
return result, false
|
||||
}
|
||||
|
||||
func (v StringSet) CodecEncodeSelf(encoder *codec.Encoder) {
|
||||
z, r := codec.GenHelperEncoder(encoder)
|
||||
if v == nil {
|
||||
r.EncodeNil()
|
||||
return
|
||||
}
|
||||
r.EncodeArrayStart(len(v))
|
||||
for _, yyv1 := range v {
|
||||
z.EncSendContainerState(containerArrayElem)
|
||||
r.EncodeString(cUTF8, yyv1)
|
||||
}
|
||||
z.EncSendContainerState(containerArrayEnd)
|
||||
}
|
||||
|
||||
// CodecDecodeSelf implements codec.Selfer
|
||||
func (v *StringSet) CodecDecodeSelf(decoder *codec.Decoder) {
|
||||
z, r := codec.GenHelperDecoder(decoder)
|
||||
yyh1, length := z.DecSliceHelperStart()
|
||||
if length == 0 {
|
||||
*v = []string{}
|
||||
return
|
||||
} else if length < 0 {
|
||||
*v = make([]string, 0, 8)
|
||||
} else {
|
||||
*v = make([]string, 0, length)
|
||||
}
|
||||
for i := 0; length < 0 || i < length; i++ {
|
||||
if length < 0 && r.CheckBreak() {
|
||||
break
|
||||
}
|
||||
yyh1.ElemContainerState(i)
|
||||
b := r.DecodeStringAsBytes()
|
||||
s := string(b)
|
||||
*v = append(*v, s)
|
||||
}
|
||||
yyh1.End()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user