代码演示
加密 解密
/**
* Created by GoLand.
* User: 清行
* Contact: 66500852@qq.com
* Date: 2021/6/2
* Time: 23:29
*/
package main
import (
"com.rpc/protobuf"
"fmt"
"github.com/golang/protobuf/proto"
)
func main() {
msg_test := &protobuf.OrderRequest{
OrderId: "asd123123123",
TimeStamp:123,
}
// 加密protobuf数据
msgDataEncoding,err := proto.Marshal(msg_test)
if err != nil {
panic(err)
}
fmt.Println(msgDataEncoding)
// 解析protobuf数据
msgDataDecoding := protobuf.OrderInfo{}
err = proto.Unmarshal(msgDataEncoding,&msgDataDecoding)
if err != nil {
panic(err)
}
fmt.Println(&msgDataDecoding)
}