package main
import (
"micro_service_project/protoBuf_test"
"fmt"
"github.com/golang/protobuf/proto"
)
func main() {
name := "zhiliao"
// 包名.结构体名
hello_data := &hello.Hello{Name:&name,Age:19,Addr:"xxxx",Price:[]int32{1,2,3,4,5}}
fmt.Println(hello_data)
fmt.Println(hello_data.Name)
fmt.Println(hello_data.Addr)
fmt.Println(hello_data.GetName())
// 编码
byte_data,_ := proto.Marshal(hello_data)
fmt.Println(byte_data)
hello2_data := &hello.Hello{}
// 解吗
proto.Unmarshal(byte_data,hello2_data)
fmt.Println(hello2_data)
fmt.Println(hello2_data.Name)
fmt.Println(*hello2_data.Name)
}
protoBuf组件小实战
最新推荐文章于 2023-03-09 23:26:19 发布