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:
Bryan Boreham
2017-10-13 20:38:50 +00:00
parent c33c91c265
commit 4adc44e788
2 changed files with 43 additions and 0 deletions

View File

@@ -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
)

View File

@@ -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()
}