Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom encoder for latest maps #1709

Merged
merged 3 commits into from
Jul 21, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions report/latest_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,57 @@ func (m *LatestMap) CodecEncodeSelf(encoder *codec.Encoder) {
} else {
encoder.Encode(nil)
}

//_, r := codec.GenHelperEncoder(encoder)
//if m.Map == nil {
// r.EncodeNil()
// return
//}
//
//r.EncodeMapStart(m.Map.Size())
//m.Map.ForEach(func(key string, value interface{}) {
// r.EncodeString(1, key)
// encoder.Encode(value.(LatestEntry))
//})

This comment was marked as abuse.

}

const (
containerMapKey = 2
containerMapValue = 3
containerMapEnd = 4

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

)

// CodecDecodeSelf implements codec.Selfer
func (m *LatestMap) CodecDecodeSelf(decoder *codec.Decoder) {

This comment was marked as abuse.

in := map[string]LatestEntry{}
if err := decoder.Decode(&in); err != nil {
z, r := codec.GenHelperDecoder(decoder)
if r.TryDecodeAsNil() {
*m = LatestMap{}
return
}
*m = LatestMap{}.fromIntermediate(in)

length := r.ReadMapStart()

This comment was marked as abuse.

This comment was marked as abuse.

out := ps.NewMap()
for i := 0; length < 0 || i < length; i++ {
if length < 0 && r.CheckBreak() {
break
}

var key string
z.DecSendContainerState(containerMapKey)
if !r.TryDecodeAsNil() {
key = r.DecodeString()
}

var value LatestEntry
z.DecSendContainerState(containerMapValue)
if !r.TryDecodeAsNil() {
decoder.Decode(&value)
}

out = out.Set(key, value)
}
z.DecSendContainerState(containerMapEnd)
*m = LatestMap{out}
}

// MarshalJSON shouldn't be used, use CodecEncodeSelf instead
Expand Down