当前位置:网站首页>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
边栏推荐
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- 开关电源设计分享及电源设计技巧图解
- @Analysis of conditional on Web Application
- SSDB foundation 1
- Why is PostgreSQL about to surpass SQL Server?
- Matlab 2019 installation of deep learning toolbox model for googlenet network
- RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
- SQL Server database in clause and exists clause conversion
- No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
- How to uninstall easyton
猜你喜欢
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
Some records used by VS2010
5 minutes to achieve wechat cloud applet payment function (including source code)
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
Oracle配置st_geometry
NiO related Basics
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
MySQL syntax collation (4)
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
Prefer composition to inheritance
随机推荐
Client interns of a large factory share their experience face to face
[报告] Microsoft :Application of deep learning methods in speech enhancement
js上传文件时控制文件类型和大小
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
开关电源设计分享及电源设计技巧图解
Oracle configuration st_ geometry
Intuitive understanding of the essence of two-dimensional rotation
C1000k TCP connection upper limit test
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
On the forced conversion of C language pointer
【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
binlog2sql 工具安装使用及问题汇总
考试系统进入试卷优化思路
Thoughts on the optimization of examination papers in the examination system
Oracle配置st_geometry
Why is PostgreSQL about to surpass SQL Server?
openlayers 5.0 当地图容器大小改变时,重新加载地图
Class loading process of JVM
5 minutes to achieve wechat cloud applet payment function (including source code)
Matlab 2019 installation of deep learning toolbox model for googlenet network