当前位置:网站首页>How to use go code to compile Pb generated by proto file with protoc Compiler Go file
How to use go code to compile Pb generated by proto file with protoc Compiler Go file
2022-04-23 19:21:00 【Handsome that handsome】
package main
import (
"fmt"
"ProtocDemo/example"
"github.com/golang/protobuf/proto"
"os"
)
func main() {
fmt.Println("Hello World. \n")
msg_test := &example.Person{
Name: proto.String("Davie"),
Age: proto.Int(18),
From: proto.String("China"),
}
// serialize
msgDataEncoding, err := proto.Marshal(msg_test)
if err != nil {
panic(err.Error())
return
}
msgEntity := example.Person{
}
err = proto.Unmarshal(msgDataEncoding, &msgEntity)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
return
}
fmt.Printf(" full name :%s\n\n", msgEntity.GetName())
fmt.Printf(" Age :%d\n\n", msgEntity.GetAge())
fmt.Printf(" nationality :%s\n\n", msgEntity.GetFrom())
}
版权声明
本文为[Handsome that handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210557450913.html
边栏推荐
- Gossip: on greed
- Problems caused by flutter initialroute and home
- 机器学习目录
- SSDB Foundation
- Parsing headless jsonarray arrays
- Some speculation about the decline of adults' language learning ability
- MySQL syntax collation (2)
- ArcGIS JS API dojoconfig configuration
- Quick start to static class variables
- arcgis js api dojoConfig配置
猜你喜欢
MySQL syntax collation (3)
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
First experience of using fluent canvas
2022.04.23 (lc_763_divided into letter interval)
I just want to leave a note for myself
Intuitive understanding of the essence of two-dimensional rotation
开关电源设计分享及电源设计技巧图解
On the forced conversion of C language pointer
Prefer composition to inheritance
Application of DCT transform
随机推荐
Gossip: on greed
openlayers 5.0 两种居中方式
Translation of audio signal processing and coding: Preface
binlog2sql 工具安装使用及问题汇总
2022.04.23 (lc_763_divided into letter interval)
8266 obtain 18b20 temperature
Openlayers 5.0 thermal diagram
Zero base to build profit taking away CPS platform official account
Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es
openlayers 5.0 热力图
js上传文件时控制文件类型和大小
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
Steps to build a deep learning environment GPU
Speculation on the way to realize the smooth drag preview of video editing software
浅谈c语言指针的强制转换
Network protocol: SCTP flow control transmission protocol
c1000k TCP 连接上限测试
Codeworks round 783 (Div. 2) d problem solution
Circuit on-line simulation
[record] typeerror: this getOptions is not a function