Move decoding code next to encoding code

This commit is contained in:
Bryan Boreham authored and Matthias Radestock committed 2015-11-02 20:01:40 +00:00
1 parent ed9ade05ea
commit 35f57b3ed2
2 files changed
+10 -7

No files matched your search

+9
View File
@@ -241,6 +241,15 @@ func (g *GossipData) Merge(o router.GossipData) {
}
}
func (g *GossipData) Decode(msg []byte) error {
if err := gob.NewDecoder(bytes.NewReader(msg)).Decode(g); err != nil {
return err
}
sort.Sort(CaseInsensitive(g.Entries))
return nil
}
func (g *GossipData) Encode() [][]byte {
// Make a copy so we can sort: all outgoing data is sent in case-sensitive order
g2 := GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}