go使用msgpack

go使用msgpack

// test project main.go
package main

import (
    "fmt"

    "github.com/vmihailenco/msgpack"
)

type (
    Player struct {
        Id   int
        Name string
    }
)

func main() {
    var s [3]Player = [3]Player{
        Player{1, "李白"},
        Player{2, "赵四"},
        Player{3, "小白"}}
    fmt.Println(s)
    b, _ := msgpack.Marshal(s) //序列
    fmt.Println(b)
    var out []Player
    _ = msgpack.Unmarshal(b, &out) //还原
    fmt.Println(out)
}

 

posted @ 2021-12-01 10:44  delphi中间件  阅读(375)  评论(0编辑  收藏  举报