Revert "msgpack incompatible with Go 1, try to use json instead."

This reverts commit 807bcc77f9.
This commit is contained in:
Andrey Smirnov
2013-12-17 12:20:45 +04:00
parent f01bc162fd
commit b48ae09ee7
+12 -6
View File
@@ -1,8 +1,9 @@
package debian package debian
import ( import (
"encoding/json" "bytes"
debc "github.com/smira/godebiancontrol" debc "github.com/smira/godebiancontrol"
"github.com/ugorji/go/codec"
"strings" "strings"
) )
@@ -61,13 +62,18 @@ func (p *Package) Key() []byte {
return []byte(p.Name + " " + p.Version + " " + p.Architecture) return []byte(p.Name + " " + p.Version + " " + p.Architecture)
} }
// Encode does serializing of Package // Encode does msgpack encoding of Package
func (p *Package) Encode() []byte { func (p *Package) Encode() []byte {
result, _ := json.Marshal(p) var buf bytes.Buffer
return result
encoder := codec.NewEncoder(&buf, &codec.MsgpackHandle{})
encoder.Encode(p)
return buf.Bytes()
} }
// Decode unserializes representation into Package // Decode decodes msgpack representation into Package
func (p *Package) Decode(input []byte) error { func (p *Package) Decode(input []byte) error {
return json.Unmarshal(input, p) decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
return decoder.Decode(p)
} }