当前位置:网站首页>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
边栏推荐
- openlayers 5.0 离散聚合点
- binlog2sql 工具安装使用及问题汇总
- 该买什么设备,Keysight 给你挑好了
- SSDB基础1
- Pit encountered using camera x_ When onpause, the camera is not released, resulting in a black screen when it comes back
- Switching power supply design sharing and power supply design skills diagram
- ArcMap connecting ArcGIS Server
- 优先使用组合而不使用继承
- [play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
- MySQL practical skills
猜你喜欢
MySQL restores or rolls back data through binlog
5 minutes to achieve wechat cloud applet payment function (including source code)
MySQL syntax collation (2)
JVM的类加载过程
2022.04.23 (lc_763_divided into letter interval)
FTP、ssh远程访问及控制
Network protocol: SCTP flow control transmission protocol
2021-2022-2 ACM training team weekly Programming Competition (8) problem solution
为何PostgreSQL即将超越SQL Server?
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
随机推荐
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
Oracle configuration st_ geometry
浅谈c语言指针的强制转换
C1000k TCP connection upper limit test 1
Zero base to build profit taking away CPS platform official account
Using Visual Studio code to develop Arduino
An 8266 crash
Redis optimization series (III) solve common problems after master-slave configuration
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
The most detailed network counting experiment in history (2) -- rip experiment of layer 3 switch
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
高层次人才一站式服务平台开发 人才综合服务平台系统
网络协议之:sctp流控制传输协议
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
Openlayers 5.0 discrete aggregation points
The difference between ordinary inner class and static inner class
An example of using JNI to directly access surface data
openlayers 5.0 两种居中方式
c1000k TCP 连接上限测试