package main
/*
本文通过golang 实现msgpack字节流.
参见 : https://github.com/hashicorp/memberlist.git util.go decode() encode()
*/
import (
"bytes"
"fmt"
"github.com/hashicorp/go-msgpack/codec"
)
func main() {
msgType := 1
in := map[string]string{"": "b", "c": "d"}
buf := bytes.NewBuffer(nil)
buf.WriteByte(uint8(msgType))
hd := codec.MsgpackHandle{}
enc := codec.NewEncoder(buf, &hd)
_ = enc.Encode(in)
fmt.Println(fmt.Sprintf("%v", buf.Bytes()))
r := bytes.NewReader(buf.Bytes()[1:])
hd2 := codec.MsgpackHandle{}
dec := codec.NewDecoder(r, &hd2)
out := map[string]string{}
dec.Decode(out)
fmt.Println(fmt.Sprintf("%v", out))
}