如何在excel中使用sqlGo中使用Protobuf

在 Golang 中使用 Protobuf
- Go语言中文网 - Golang中文社区
<meta name="author" content="polaris ">
在 Golang 中使用 Protobuf
wangxusummer
· 14947 次点击 ·
开始浏览 & &
安装 goprotobuf
1.从 /google/protobuf/releases 获取 Protobuf 编译器 protoc(可下载到 Windows 下的二进制版本
wget https:///google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar zxvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
./configure
make install
2.获取 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go(被放置于 $GOPATH/bin 下,$GOPATH/bin 应该被加入 PATH 环境变量,以便 protoc 能够找到 protoc-gen-go)
此插件被 protoc 使用,用于编译 .proto 文件为 Golang 源文件,通过此源文件可以使用定义在 .proto 文件中的消息。
go get /golang/protobuf/protoc-gen-go
/golang/protobuf/protoc-gen-go
go install
vi /etc/profile 将$GOPATH/bin 加入环境变量
source profile
3.获取 goprotobuf 提供的支持库,包含诸如编码(marshaling)、解码(unmarshaling)等功能
go get /golang/protobuf/proto
/golang/protobuf/proto
go install
使用 goprotobuf这里通过一个例子来说明用法。先创建一个 .proto 文件 test.proto:
enum FOO { X = 17; };
message Test {
required string label = 1;
optional int32 type = 2 [default=77];
repeated int64 reps = 3;
optional group OptionalGroup = 4 {
required string RequiredField = 5;
编译此 .proto 文件:
protoc --go_out=. *.proto
这里通过 –go_out 来使用 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go。这时候我们会生成一个名为 test.pb.go 的源文件。
在使用之前,我们先了解一下每个 Protobuf 消息在 Golang 中有哪一些可用的接口:
每一个 Protobuf 消息对应一个 Golang 结构体
消息中域名字为 camel_case 在对应的 Golang 结构体中为 CamelCase
消息对应的 Golang 结构体中不存在 setter 方法,只需要直接对结构体赋值即可,赋值时可能使用到一些辅助函数,例如:
msg.Foo = proto.String(&#34;hello&#34;)
消息对应的 Golang 结构体中存在 getter 方法,用于返回域的值,如果域未设置值,则返回一个默认值
消息中非 repeated 的域都被实现为一个指针,指针为 nil 时表示域未设置
消息中 repeated 的域被实现为 slice
访问枚举值时,使用“枚举类型名_枚举名”的格式(更多内容可以直接阅读生成的源码)
使用 proto.Marshal 函数进行编码,使用 proto.Unmarshal 函数进行解码
现在我们编写一个小程序:
package main
&#34;log&#34;
&#34;/golang/protobuf/proto&#34;
// test.pb.go 的路径
&#34;example&#34;
func main() {
// 创建一个消息 Test
test := &example.Test{
// 使用辅助函数设置域的值
Label: proto.String(&#34;hello&#34;),
proto.Int32(17),
Optionalgroup: &example.Test_OptionalGroup{
RequiredField: proto.String(&#34;good bye&#34;),
// 进行编码
data, err := proto.Marshal(test)
if err != nil {
log.Fatal(&#34;marshaling error: &#34;, err)
// 进行解码
newTest := &example.Test{}
err = proto.Unmarshal(data, newTest)
if err != nil {
log.Fatal(&#34;unmarshaling error: &#34;, err)
// 测试结果
if test.GetLabel() != newTest.GetLabel() {
log.Fatalf(&#34;data mismatch %q != %q&#34;, test.GetLabel(), newTest.GetLabel())
14947 次点击 &
1 回复 &| &直到
请尽量让自己的回复能够对别人有帮助
支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
支持 @ 本站用户;支持表情(输入 : 提示),见
图片支持拖拽、截图粘贴等方式上传
记住登录状态
安装 goprotobuf
1.从 /google/protobuf/releases 获取 Protobuf 编译器 protoc(可下载到 Windows 下的二进制版本
wget https:///google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar zxvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
./configure
make install
2.获取 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go(被放置于 $GOPATH/bin 下,$GOPATH/bin 应该被加入 PATH 环境变量,以便 protoc 能够找到 protoc-gen-go)
此插件被 protoc 使用,用于编译 .proto 文件为 Golang 源文件,通过此源文件可以使用定义在 .proto 文件中的消息。
go get /golang/protobuf/protoc-gen-go
/golang/protobuf/protoc-gen-go
go install
vi /etc/profile 将$GOPATH/bin 加入环境变量
source profile
3.获取 goprotobuf 提供的支持库,包含诸如编码(marshaling)、解码(unmarshaling)等功能
go get /golang/protobuf/proto
/golang/protobuf/proto
go install
使用 goprotobuf这里通过一个例子来说明用法。先创建一个 .proto 文件 test.proto:
enum FOO { X = 17; };
message Test {
required string label = 1;
optional int32 type = 2 [default=77];
repeated int64 reps = 3;
optional group OptionalGroup = 4 {
required string RequiredField = 5;
编译此 .proto 文件:
protoc --go_out=. *.proto
这里通过 –go_out 来使用 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go。这时候我们会生成一个名为 test.pb.go 的源文件。
在使用之前,我们先了解一下每个 Protobuf 消息在 Golang 中有哪一些可用的接口:
每一个 Protobuf 消息对应一个 Golang 结构体
消息中域名字为 camel_case 在对应的 Golang 结构体中为 CamelCase
消息对应的 Golang 结构体中不存在 setter 方法,只需要直接对结构体赋值即可,赋值时可能使用到一些辅助函数,例如:
msg.Foo = proto.String(&#34;hello&#34;)
消息对应的 Golang 结构体中存在 getter 方法,用于返回域的值,如果域未设置值,则返回一个默认值
消息中非 repeated 的域都被实现为一个指针,指针为 nil 时表示域未设置
消息中 repeated 的域被实现为 slice
访问枚举值时,使用“枚举类型名_枚举名”的格式(更多内容可以直接阅读生成的源码)
使用 proto.Marshal 函数进行编码,使用 proto.Unmarshal 函数进行解码
现在我们编写一个小程序:
package main
&#34;log&#34;
&#34;/golang/protobuf/proto&#34;
// test.pb.go 的路径
&#34;example&#34;
func main() {
// 创建一个消息 Test
test := &example.Test{
// 使用辅助函数设置域的值
Label: proto.String(&#34;hello&#34;),
proto.Int32(17),
Optionalgroup: &example.Test_OptionalGroup{
RequiredField: proto.String(&#34;good bye&#34;),
// 进行编码
data, err := proto.Marshal(test)
if err != nil {
log.Fatal(&#34;marshaling error: &#34;, err)
// 进行解码
newTest := &example.Test{}
err = proto.Unmarshal(data, newTest)
if err != nil {
log.Fatal(&#34;unmarshaling error: &#34;, err)
// 测试结果
if test.GetLabel() != newTest.GetLabel() {
log.Fatalf(&#34;data mismatch %q != %q&#34;, test.GetLabel(), newTest.GetLabel())
&最高记录 1364
&2012- Go语言中文网,中国 Golang 社区,致力于构建完善的 Golang 中文社区,Go语言爱好者的学习家园。
Powered by
&o&服务器由
赞助 &·&CDN 由
VERSION: V3.0.0&·&4.498428ms&·&为了更好的体验,本站推荐使用 Chrome 或 Firefox 浏览器
登录和大家一起探讨吧
记住登录状态
还不是会员&&6542 阅读
Go语言版本的Protobuf-RPC基本算完成了. 现在简单说下使用方法.
安装测试环境
先下载代码(不支持go get):
hg clone https://bitbucket.org/chai2010/protorpc
然后下载后的目录设置为GOPATH, 并添加$GOPATH/bin到PATH环境变量.
在$GOPATH/bin中已经包含了Windows下的2.4.1版本的protoc.exe. 如果是Linux等系统, 请自行下载并安装protoc程序.
安装protoc.exe的Go语言插件:
go install encoding/protobuf/protoc-gen-go
该插件是基于/p/goprotobuf/protoc-gen-go实现, 主要增加了encoding/protobuf/protoc-gen-go/generator/service.go文件, 用于RPC的代码生成. 生成的RPC代码依赖net/rpc/protorpc, 这个包是Protobuf-RPC的底层实现, 可以单独使用.
现在可以运行一下测试程序:
C:\&go test net/rpc/protorpc/service.pb
net/rpc/protorpc/service.pb
测试通过, 继续.
编写 proto 文件
创建一个名为pbrpc的工作目录, 再创建pbrpc/arith.pb的子目录.
将net/rpc/protorpc/service.pb/service.proto文件复制到pbrpc/arith.pb的子目录.
包名字改为arith, 文件arith.proto的内容如下:
option cc_generic_services =
option java_generic_services =
option py_generic_services =
message ArithRequest {
optional int32 a = 1;
optional int32 b = 2;
message ArithResponse {
optional int32 c = 1;
service ArithService {
rpc add (ArithRequest) returns (ArithResponse);
rpc mul (ArithRequest) returns (ArithResponse);
rpc div (ArithRequest) returns (ArithResponse);
rpc error (ArithRequest) returns (ArithResponse);
主要是定义了一个ArithService接口. 要注意的是cc_generic_services/java_generic_services, py_generic_services几个选项.
我前提提到的protoc-gen-go在生成代码的时候, 这3个选项至少要有一个为true, 才会生成RPC的代码.
当然, 如果不生成RPC代码的话, 也是可以单独使用net/rpc/protorpc包的. 不过protoc-gen-go生成的代码会简便很多.
进入pbrpc/arith.pb的子目录, 编译arith.proto文件:
protoc --go_out=. arith.proto
生成 arith.pb.go 文件, 其中RPC的代码主要是下面这些:
type ArithService interface {
Add(in *ArithRequest, out *ArithResponse) error
Mul(in *ArithRequest, out *ArithResponse) error
Div(in *ArithRequest, out *ArithResponse) error
Error(in *ArithRequest, out *ArithResponse) error
// RegisterArithService publish the given ArithService implementation on the server.
func RegisterArithService(srv *rpc.Server, x ArithService) error {
if err := srv.RegisterName(&ArithService&, x); err != nil {
return err
return nil
// ServeArithService serves the given ArithService implementation on conn.
func ServeArithService(conn io.ReadWriteCloser, x ArithService) error {
srv := rpc.NewServer()
if err := srv.RegisterName(&ArithService&, x); err != nil {
return err
srv.ServeCodec(protorpc.NewServerCodec(conn))
return nil
// ListenAndServeArithService listen announces on the local network address laddr
// and serves the given ArithService implementation.
func ListenAndServeArithService(network, addr string, x ArithService) error {
clients, err := net.Listen(network, addr)
if err != nil {
return err
srv := rpc.NewServer()
if err := srv.RegisterName(&ArithService&, x); err != nil {
return err
conn, err := clients.Accept()
if err != nil {
return err
go srv.ServeCodec(protorpc.NewServerCodec(conn))
panic(&unreachable&)
type rpcArithServiceStub struct {
*rpc.Client
func (c *rpcArithServiceStub) Add(in *ArithRequest, out *ArithResponse) error {
return c.Call(&ArithService.Add&, in, out)
func (c *rpcArithServiceStub) Mul(in *ArithRequest, out *ArithResponse) error {
return c.Call(&ArithService.Mul&, in, out)
func (c *rpcArithServiceStub) Div(in *ArithRequest, out *ArithResponse) error {
return c.Call(&ArithService.Div&, in, out)
func (c *rpcArithServiceStub) Error(in *ArithRequest, out *ArithResponse) error {
return c.Call(&ArithService.Error&, in, out)
// DialArithService connects to an ArithService at the specified network address.
func DialArithService(network, addr string) (*rpc.Client, ArithService, error) {
conn, err := net.Dial(network, addr)
if err != nil {
return nil, nil, err
c, srv := NewArithServiceClient(conn)
return c, srv, nil
// NewArithServiceClient returns a ArithService rpc.Client and stub to handle
// requests to the set of ArithService at the other end of the connection.
func NewArithServiceClient(conn io.ReadWriteCloser) (*rpc.Client, ArithService) {
c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
return c, &rpcArithServiceStub{c}
// NewArithServiceStub returns a ArithService stub to handle rpc.Client.
func NewArithServiceStub(c *rpc.Client) ArithService {
return &rpcArithServiceStub{c}
其中生成的服务器端的代码有: ListenAndServeArithService, ServeArithService, RegisterArithService.
生成的客户端的接口有: DialArithService, NewArithServiceClient, NewArithServiceStub.
其中RPC接口对应ArithService接口.
编写测试代码
在pbrpc目录创建rpc_server.go文件, 代码如下:
package main
&encoding/protobuf/proto&
&./arith.pb&
type Arith int
func (t *Arith) Add(args *arith.ArithRequest, reply *arith.ArithResponse) error {
reply.C = proto.Int32(args.GetA() + args.GetB())
return nil
func (t *Arith) Mul(args *arith.ArithRequest, reply *arith.ArithResponse) error {
reply.C = proto.Int32(args.GetA() * args.GetB())
return nil
func (t *Arith) Div(args *arith.ArithRequest, reply *arith.ArithResponse) error {
if args.GetB() == 0 {
return errors.New(&divide by zero&)
reply.C = proto.Int32(args.GetA() / args.GetB())
return nil
func (t *Arith) Error(args *arith.ArithRequest, reply *arith.ArithResponse) error {
return errors.New(&ArithError&)
func main() {
arith.ListenAndServeArithService(&tcp&, &:1234&, new(Arith))
最关键的是arith.ListenAndServeArithService(&tcp&, &:1234&, new(Arith)). 当然, 也可以使用RegisterArithService或ServeArithService等接口进行定制.
然后在pbrpc创建rpc_client.go对应客户端, 代码如下:
package main
&encoding/protobuf/proto&
&./arith.pb&
func main() {
client, stub, err := arith.DialArithService(&tcp&, &127.0.0.1:1234&)
if err != nil {
log.Fatalf(`arith.DialArithService(&tcp&, &127.0.0.1:1234&): %v`, err)
defer client.Close()
var args arith.ArithRequest
var reply arith.ArithResponse
args.A = proto.Int32(1)
args.B = proto.Int32(2)
if err = stub.Add(&args, &reply); err != nil {
log.Fatalf(`arith.Add: %v`, err)
if reply.GetC() != 3 {
log.Fatalf(`arith.Add: expected = %d, got = %d`, 3, reply.GetC())
args.A = proto.Int32(2)
args.B = proto.Int32(3)
if err = stub.Mul(&args, &reply); err != nil {
log.Fatalf(`arith.Mul: %v`, err)
if reply.GetC() != 6 {
log.Fatalf(`arith.Mul: expected = %d, got = %d`, 6, reply.GetC())
args.A = proto.Int32(13)
args.B = proto.Int32(5)
if err = stub.Div(&args, &reply); err != nil {
log.Fatalf(`arith.Div: %v`, err)
if reply.GetC() != 2 {
log.Fatalf(`arith.Div: expected = %d, got = %d`, 2, reply.GetC())
// Div zero
args.A = proto.Int32(1)
args.B = proto.Int32(0)
if err = stub.Div(&args, &reply); err.Error() != &divide by zero& {
log.Fatalf(`arith.Error: expected = %s, got = %s`, &divide by zero&, err.Error())
args.A = proto.Int32(1)
args.B = proto.Int32(2)
if err = stub.Error(&args, &reply); err.Error() != &ArithError& {
log.Fatalf(`arith.Error: expected = %s, got = %s`, &ArithError&, err.Error())
log.Printf(&Done&)
然后就可以启动服务, 并测试客户端了.
PS: 看来图灵社区这类地方不是很喜欢技术类的文章, 以后技术文章就不发这里了. 以后来这里只看别人八卦灌水 :)
补充: 目前项目已经移到googlecode,
可以直接用go命令安装:
go get /p/protorpc
更多Go文章请访问:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&ubuntu下go语言使用protobuf
- Go语言中文网 - Golang中文社区
<meta name="author" content="polaris ">
ubuntu下go语言使用protobuf
· 189 次点击 ·
开始浏览 & &
1. 编译安装protobuf(protobuf 没有关于go的release)
为了从源码安装protobuf,先要安装一些工具:包括autoconf、automake、libtool、curl(用于下载gmock)、make、 g++、 unzip。
在ubuntu可以使用如下命令安装这些依赖:
sudo apt-get install autoconf automake libtool curl make g++ unzip
然后使用 git clone
/google/protobuf命令下载protobuf的源码包。
接者使用命令 cd protobuf进入源码库中
./autogen.sh运行脚本生成需要的配置脚本
接着执行如下的一系列命令来编译安装protocol buffer的complier
./configure
make check
sudo make install
sudo ldconfig
最后的一个命令是用于刷新共享库的缓存的。,最后一个命令我的ubuntu无法执行
2. 安装proto-gen-go
命令如下: go get -/golang/protobuf/proto
go get -/golang/protobuf/protoc-gen-go
然后将环境变量GOPATH定义的目录下的bin目录加入到环境变量PATH中。
命令如下:vi
然后在该文件最后加上:export PATH=&#34;$PATH:$GOPATH/bin&#34;即可。
然后调用 source ~/.bashrc
3.定义一个proto文件test.proto如下:
enum FOO { X = 17; };
message Test {
required string label = 1;
optional int32 type = 2 [default=77];
repeated int64 reps = 3;
optional group OptionalGroup = 4 {
required string RequiredField = 5;
在该文件对应的文件夹中执行命令:protoc --go_out=.
*.proto用于生成.pb.go文件。如果这个命令执行过程中出现 protoc-gen-go: program not found or is not executable 这个错误,表示该protoc-gen-go没有被加入到Path环境变量中,应该把该文件的所在目录加入Path变量中。该文件存放在环境变量GOPATH目录下的bin子目录里。
4.编写测试代码:
首先要将上一节生成的example包放入GOPATH目录下的src文件夹下:
然后建立如下的测试代码:
package main
&#34;fmt&#34;
&#/golang/protobuf/proto&#34;
// test.pb.go 的路径
&#34;example&#34;
func main() {
// 创建一个消息 Test
test := &example.Test{
// 使用辅助函数设置域的值
Label: proto.String(&#34;hello&#34;),
proto.Int32(17),
Optionalgroup: &example.Test_OptionalGroup{
RequiredField: proto.String(&#34;good bye&#34;),
// 进行编码
data, err := proto.Marshal(test)
if err != nil {
fmt.Println(&#34;marshaling error: &#34;, err)
// 进行解码
newTest := &example.Test{}
err = proto.Unmarshal(data, newTest)
if err != nil {
fmt.Println(&#34;unmarshaling error: &#34;, err)
// 测试结果
if test.GetLabel() != newTest.GetLabel() {
fmt.Println(&#34;data mismatch %q != %q&#34;, test.GetLabel(), newTest.GetLabel())
fmt.Printf(&#34;%+v&#34;, newTest)
5 golang中可用的protobuf的接口:
在使用之前,我们先了解一下每个 Protobuf 消息在 Golang 中有哪一些可用的接口:
每一个 Protobuf 消息对应一个 Golang 结构体
2. 消息中域名字为 camel_case 在对应的 Golang 结构体中为 CamelCase
3. 消息对应的 Golang 结构体中不存在 setter 方法,只需要直接对结构体赋值即可,赋值时可能使用到一些辅助函数,例如:
msg.Foo = proto.String(&#34;hello&#34;)
4. 消息对应的 Golang 结构体中存在 getter 方法,用于返回域的值,如果域未设置值,则返回一个默认值
5. 消息中非 repeated 的域都被实现为一个指针,指针为 nil 时表示域未设置消息中 repeated 的域被实现为 slice
6. 访问枚举值时,使用“枚举类型名_枚举名”的格式(更多内容可以直接阅读生成的源码)
7. 使用 proto.Marshal 函数进行编码,使用 proto.Unmarshal 函数进行解码
参考链接:
189 次点击 &
请尽量让自己的回复能够对别人有帮助
支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
支持 @ 本站用户;支持表情(输入 : 提示),见
图片支持拖拽、截图粘贴等方式上传
记住登录状态
1. 编译安装protobuf(protobuf 没有关于go的release)
为了从源码安装protobuf,先要安装一些工具:包括autoconf、automake、libtool、curl(用于下载gmock)、make、 g++、 unzip。
在ubuntu可以使用如下命令安装这些依赖:
sudo apt-get install autoconf automake libtool curl make g++ unzip
然后使用 git clone
/google/protobuf命令下载protobuf的源码包。
接者使用命令 cd protobuf进入源码库中
./autogen.sh运行脚本生成需要的配置脚本
接着执行如下的一系列命令来编译安装protocol buffer的complier
./configure
make check
sudo make install
sudo ldconfig
最后的一个命令是用于刷新共享库的缓存的。,最后一个命令我的ubuntu无法执行
2. 安装proto-gen-go
命令如下: go get -/golang/protobuf/proto
go get -/golang/protobuf/protoc-gen-go
然后将环境变量GOPATH定义的目录下的bin目录加入到环境变量PATH中。
命令如下:vi
然后在该文件最后加上:export PATH=&#34;$PATH:$GOPATH/bin&#34;即可。
然后调用 source ~/.bashrc
3.定义一个proto文件test.proto如下:
enum FOO { X = 17; };
message Test {
required string label = 1;
optional int32 type = 2 [default=77];
repeated int64 reps = 3;
optional group OptionalGroup = 4 {
required string RequiredField = 5;
在该文件对应的文件夹中执行命令:protoc --go_out=.
*.proto用于生成.pb.go文件。如果这个命令执行过程中出现 protoc-gen-go: program not found or is not executable 这个错误,表示该protoc-gen-go没有被加入到Path环境变量中,应该把该文件的所在目录加入Path变量中。该文件存放在环境变量GOPATH目录下的bin子目录里。
4.编写测试代码:
首先要将上一节生成的example包放入GOPATH目录下的src文件夹下:
然后建立如下的测试代码:
package main
&#34;fmt&#34;
&#/golang/protobuf/proto&#34;
// test.pb.go 的路径
&#34;example&#34;
func main() {
// 创建一个消息 Test
test := &example.Test{
// 使用辅助函数设置域的值
Label: proto.String(&#34;hello&#34;),
proto.Int32(17),
Optionalgroup: &example.Test_OptionalGroup{
RequiredField: proto.String(&#34;good bye&#34;),
// 进行编码
data, err := proto.Marshal(test)
if err != nil {
fmt.Println(&#34;marshaling error: &#34;, err)
// 进行解码
newTest := &example.Test{}
err = proto.Unmarshal(data, newTest)
if err != nil {
fmt.Println(&#34;unmarshaling error: &#34;, err)
// 测试结果
if test.GetLabel() != newTest.GetLabel() {
fmt.Println(&#34;data mismatch %q != %q&#34;, test.GetLabel(), newTest.GetLabel())
fmt.Printf(&#34;%+v&#34;, newTest)
5 golang中可用的protobuf的接口:
在使用之前,我们先了解一下每个 Protobuf 消息在 Golang 中有哪一些可用的接口:
每一个 Protobuf 消息对应一个 Golang 结构体
2. 消息中域名字为 camel_case 在对应的 Golang 结构体中为 CamelCase
3. 消息对应的 Golang 结构体中不存在 setter 方法,只需要直接对结构体赋值即可,赋值时可能使用到一些辅助函数,例如:
msg.Foo = proto.String(&#34;hello&#34;)
4. 消息对应的 Golang 结构体中存在 getter 方法,用于返回域的值,如果域未设置值,则返回一个默认值
5. 消息中非 repeated 的域都被实现为一个指针,指针为 nil 时表示域未设置消息中 repeated 的域被实现为 slice
6. 访问枚举值时,使用“枚举类型名_枚举名”的格式(更多内容可以直接阅读生成的源码)
7. 使用 proto.Marshal 函数进行编码,使用 proto.Unmarshal 函数进行解码
参考链接:
&最高记录 1364
&2012- Go语言中文网,中国 Golang 社区,致力于构建完善的 Golang 中文社区,Go语言爱好者的学习家园。
Powered by
&o&服务器由
赞助 &·&CDN 由
VERSION: V3.0.0&·&4.563747ms&·&为了更好的体验,本站推荐使用 Chrome 或 Firefox 浏览器
登录和大家一起探讨吧
记住登录状态
还不是会员

我要回帖

更多关于 如何在微信中使用麦客 的文章

 

随机推荐