Skip to content

Commit

Permalink
Try to use encoding/gob.Register() to avoid intermediate representati…
Browse files Browse the repository at this point in the history
…ons of ps.Map
  • Loading branch information
Alfonso Acosta committed Feb 12, 2016
1 parent 27b5339 commit 11d517a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
22 changes: 5 additions & 17 deletions report/latest_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type LatestEntry struct {
Value string `json:"value"`
}

func init() {
gob.Register(LatestMap{})
gob.Register(LatestEntry{})
}

func (e LatestEntry) String() string {
return fmt.Sprintf("\"%s\" (%s)", e.Value, e.Timestamp.String())
}
Expand Down Expand Up @@ -200,20 +205,3 @@ func (m *LatestMap) UnmarshalJSON(input []byte) error {
*m = LatestMap{}.fromIntermediate(in)
return nil
}

// GobEncode implements gob.Marshaller
func (m LatestMap) GobEncode() ([]byte, error) {
buf := bytes.Buffer{}
err := gob.NewEncoder(&buf).Encode(m.toIntermediate())
return buf.Bytes(), err
}

// GobDecode implements gob.Unmarshaller
func (m *LatestMap) GobDecode(input []byte) error {
in := map[string]LatestEntry{}
if err := gob.NewDecoder(bytes.NewBuffer(input)).Decode(&in); err != nil {
return err
}
*m = LatestMap{}.fromIntermediate(in)
return nil
}
77 changes: 41 additions & 36 deletions vendor/github.com/mndrix/ps/map.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11d517a

Please sign in to comment.