首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏code人生

    Go with Protobuf

    本教程为 Go 程序员提供了使用Protocol buffer的基本介绍。 本教程使用proto3向 Go 程序员介绍如何使用 protobuf。 syntax = "proto3"; package tutorial; import "google/protobuf/timestamp.proto"; go_package选项定义了包含此文件中所有生成代码的包的导入路径 option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb"; 接下来,需要定义 message 。 { string number = 1; PhoneType type = 2; } repeated PhoneNumber phones = 4; google.protobuf.Timestamp 生成的github.com/protocolbuffers/protobuf/examples/go/tutorialpb/addressbook.pb.go文件将保存在你指定的目录下。

    80630编辑于 2023-10-19
  • 来自专栏code人生

    Go with Protobuf

    本教程为 Go 程序员提供了使用Protocol buffer的基本介绍。 本教程使用proto3向 Go 程序员介绍如何使用 protobuf。 syntax = "proto3"; package tutorial; import "google/protobuf/timestamp.proto"; go_package选项定义了包含此文件中所有生成代码的包的导入路径 option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb"; 接下来,需要定义message。 使用如下命令按照Go protocol buffers插件:$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest protoc-gen-go 生成的github.com/protocolbuffers/protobuf/examples/go/tutorialpb/addressbook.pb.go文件将保存在你指定的目录下。

    68110编辑于 2023-10-09
  • 来自专栏晓晨的专栏

    Go 使用 protobuf

    访问 https://github.com/protocolbuffers/protobuf/releases 选择对应的系统进行下载。 安装 proto-gen go , 执行命令 go install github.com/golang/protobuf/protoc-gen-go@lates 安装完成后检查是否安装成功 ls $GOPATH { string name = 1; } 生成 pb.go protoc --go_out=. *.proto 生成 grpc 使用命令:protoc --go_out=plugins=grpc :. *.proto 安装依赖 go get github.com/golang/protobuf 序列化和反序列化 main.go package main import ( "fmt" " github.com/golang/protobuf/proto" "go-protobuf/pb" "log" ) func main() { p := &pb.Person{ Name:

    1.7K10编辑于 2022-05-07
  • 来自专栏仙士可博客

    go 安装protobuf

    简单来说就是:你可以通过protobuf,将不同语言的数据结构进行直接序列化传输,由其他语言接收 安装protobuf 下载地址:https://github.com/protocolbuffers/protobuf -3.19.3.tar.gz cd protobuf-3.19.3 . /configure make make install protoc --version 即可看到安装完成 安装 go-protobuf 安装插件 protoc-gen-go,它是一个go程序,编译它之后将可执行文件执行路径写入环境变量 go get github.com/golang/protobuf/protoc-gen-go 获取goprotobufgo get github.com/golang/protobuf/proto 输入命令 protoc-gen-go,如果没报错表示安装成功 使用 编写一个proto文件.

    2.5K10编辑于 2022-01-18
  • 来自专栏网管叨bi叨

    Protobuf生成Go代码指南

    这个教程中将会描述protocol buffer编译器通过给定的 .proto会编译生成什么Go代码。教程针对的是proto3版本的protobuf。 在阅读之前确保你已经阅读过Protobuf语言指南。 编译器调用 Protobuf核心的工具集是C++语言开发的,官方的protoc编译器中并不支持Go语言,需要安装一个插件才能生成Go代码。 用如下命令安装: $ go get github.com/golang/protobuf/protoc-gen-go 提供了一个 protoc-gen-go二进制文件,当编译器调用时传递了 --go_out WKT的预生成Go代码作为Go protobuf库的一部分进行分发,如果message中使用了WKT,则生成的消息的Go代码会引用此代码。 = 3;} 生成的Go代码将会像下面这样: import google_protobuf "github.com/golang/protobuf/ptypes/struct"import google_protobuf1

    6.1K40发布于 2019-10-13
  • 来自专栏Go语言指北

    Go语言,Protobuf 极速入门!

    Protobuf 中最基本的数据单元是 message,类似 Go 语言中的结构体。在 message 中可以嵌套 message 或其它的基础数据类型的成员。 syntax "proto3"; message Info { reserved 2, 9 to 11, 15; // ... } 生成相应的Go代码 Protobuf 核心的工具集是 安装针对Go语言的代码生成插件,通过 go get github.com/golang/protobuf/protoc-gen-go 命令安装。 基本数据类型 protobuf 所生成出来的数据类型并非与原始的类型完全一致,下面是一些常见的类型映射: 生成的 hello.pb.go 文件 pb.go 文件是对 proto 文件所生成的对应的 Go https://golang2.eddycjy.com/posts/ch3/01-simple-grpc-protobuf/ 《Go语言高级编程》

    1.2K30发布于 2021-11-12
  • 来自专栏网管叨bi叨

    Go中使用Protobuf

    Protobuf语言指南 Protobuf生成Go代码指南 为什么使用protocol buffer 我们将要使用的示例是一个非常简单的“地址簿”应用程序,可以在文件中读取和写入人员的联系人详细信息 syntax = "proto3";package tutorial; import "google/protobuf/timestamp.proto"; 在Go中,protocol buffer的包名称用作 go get -u github.com/golang/protobuf/protoc-gen-go 现在运行编译器,指定源目录(应用程序的源代码所在的位置 - 如果不提供值,则使用当前目录) 文件的路径是 pb"github.com/protocolbuffers/protobuf/examples/tutorial" 所以用protoc编译时使用的目标路径应该是 protoc --go_out =$GOPATH/src/github.com/protocolbuffers/protobuf/examples/tutorial .

    1.8K30发布于 2019-10-13
  • 来自专栏新亮笔记

    Go - 如何编写 ProtoBuf 插件 (三) ?

    文章目录: 前言 演示代码 小结 前言 上篇文章《Go - 如何编写 ProtoBuf 插件 (二) 》,分享了基于 自定义选项 定义了 interceptor 插件,然后在 helloworld.proto // 生成 helloworld.pb.go // 生成 helloworld_grpc.pb.go // 使用的 protoc --version 为 libprotoc 3.18.1 // 使用的 protoc-gen-go --version 为 protoc-gen-go v1.27.1 // 使用的 protoc-gen-go-grpc --version 为 protoc-gen-go-grpc 1.1.0 // 在根目录下执行 protoc 命令 protoc --go_out=helloworld/gen --go-grpc_out=helloworld/gen helloworld/helloworld.proto 小结 通过最近的 “如何编写 ProtoBuf 插件” 这三篇文章,相信你对编写 ProtoBuf 插件有一点小的认识,希望对你能够有所帮助。

    92240编辑于 2021-12-28
  • 来自专栏golang从入门到进阶

    Go使用Protobuf 避坑指南

    别把.pb.go当亲儿子养! ——一个Go工程师的血泪忏悔录“我的API层用Protobuf定义,Domain层也用Protobuf实现,连测试桩都靠proto.Clone()……直到某天,产品经理说:‘用户昵称要支持emoji表情前缀 本质:Protobuf强行用IDL的审美,覆盖了Go的惯用法(EffectiveGo:UseMixedCapsormixedCaps)。 正确姿势:Protobuf——只配待在「边境」网络是国界,Protobuf是外交文书;内部是国土,Gostruct是公民身份证。 当schema单元测试输入✅可用(边界层)在domain测试里mock.pb.go银行门口标语:“Protobuf只准在TransportLayer下车,违者罚款10个PR审查comment”结语:少一点

    11310编辑于 2026-01-24
  • Go Protobuf 参考教程 - Grpc Go C++ 通信

    官方参考文档: go install google.golang.org/protobuf/cmd/protoc-gen-go 安装protobuf go 插件 https://developers.google.com /protocolbuffers/protobuf-go protobuf-go模块 go get -u google.golang.org/protobuf 下载代码 go get -v go get google.golang.org/protobuf cd protobuf/cmd/protoc-gen-go go install # 进行安装 protoc-gen-go 命令; 3.安装protoc-gen-go-grpc 工具,注意命令之间版本的兼容性; 4.撰写protobuf 定义文件,生成代码; https://github.com/grpc/grpc-go/tree/master/examples grpc-go 我使用的版本: - gcc 7.5.0 - go 1.14.6 - grpc 1.27.2 - grpc-go 1.30.0 - protobuf 3.13.0 - protoc-gen-go-grpc

    1.3K10发布于 2020-12-30
  • 来自专栏新亮笔记

    Go - 如何编写 ProtoBuf 插件 (一) ?

    MessageOptions FieldOptions FileOptions OneofOptions ExtensionRangeOptions 具体写法可参考: import "google/protobuf /descriptor.proto"; extend google.protobuf.MessageOptions { optional string my_option = 51234; } extend google.protobuf.MethodOptions { ... } extend google.protobuf.ServiceOptions { ... } 大家有实现的思路吗

    73820编辑于 2021-12-06
  • 来自专栏王亚昌的专栏

    如何在Go中使用Protobuf

    下载并安装protobuf-go插件 从github上下载插件,并解压(https://github.com/golang/protobuf),得到以下的目录 drwxr-xr-x 6 root root /golang/protobuf/protoc-gen-go/generator" ) 因此,要求我们把当面下载的文件放到$GOROOT对应的目录下,并且把目录名改成指定的名称,比如我的GOROOT =/usr/local/go,那我就把解压后的目录改名为protobuf,并在/usr/local/go下创建/usr/local/go/src/github.com/golang/目录,把protobuf 目录整体mv过去,再执行make install,执行结果如下: [root@SH-todo-1412181717 /usr/local/go/src/github.com/golang/protobuf /golang/protobuf/proto" // test.pb.go 的路径 "example" ) func main() { // 创建一个消息 Test

    1.2K10发布于 2018-08-03
  • 来自专栏新亮笔记

    Go - 如何编写 ProtoBuf 插件(二)?

    文章目录: 前言 定义插件 使用插件 获取自定义选项 小结 推荐阅读 前言 上篇文章《Go - 如何编写 ProtoBuf 插件 (一) 》,分享了使用 proto3 的 自定义选项 可以实现插件的编写 /;interceptor/options"; import "google/protobuf/descriptor.proto"; extend google.protobuf.MethodOptions main.go // 演示代码 package main import ( "fmt" "strconv" _ "github.com/xinliangnote/protobuf/helloworld /gen" "github.com/xinliangnote/protobuf/plugin/interceptor/options" "google.golang.org/protobuf/proto " "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry

    81810编辑于 2021-12-20
  • 来自专栏传说之下的花儿的日常学习笔记

    Go微服务(二)——Protobuf详细入门

    Go 语言Protobuf开发环境搭建 Protobuf 编译器 : Protobuf的编译器叫做:protoc(protobuf compiler) Golang安装使用Protobuf: 1. 安装go protocol buffers的插件 protoc-gen-go Protobuf核⼼的⼯具集是C++语⾔开发的,在官⽅的protoc编译器中并不⽀持Go语⾔。 消息类型(message) Protobuf中定义一个消息类型是通过关键字message字段指定的,这个关键字可以理解为Go语言的stuct关键字,用protobuf编译器将proto编译成Go代码之后 这⾥我们尝试将Protobuf和RPC结合在 ⼀起使⽤,通过Protobuf来最终保证RPC的接⼝规范和安全。Protobuf中最基本的数据单元是 message,是类似Go语⾔中结构体的存在。 ,而使用了protobuf之后,这里的参数类型就需要引用我们通过protobuf生成的.pb.go文件里的结构体类型。

    4.8K20编辑于 2023-04-16
  • 来自专栏人人都是架构师

    Go每日一库之94:protobuf

    protobuf 在通信协议和数据存储等领域应用广泛。例如著名的分布式缓存工具 Memcached 的 Go 语言版本groupcache 就使用了 protobuf 作为其 RPC 数据格式。 $ protoc --version libprotoc 3.11.2 2.2 protoc-gen-go 我们需要在 Golang 中使用 protobuf,还需要安装 protoc-gen-go,这个工具用来将 // 最新版本 go install github.com/golang/protobuf/protoc-gen-go@latest // 指定版本 go install github.com/golang /protobuf/protoc-gen-go@v1.5.2 protoc-gen-go 将自动安装到 $GOPATH/bin 目录下,也需要将这个目录加入到环境变量中。 =. *.proto $ ls student.pb.go student.proto 即是,将该目录下的所有的 .proto 文件转换为 Go 代码,我们可以看到该目录下多出了一个 Go 文件 student.pb.go

    1.3K21编辑于 2023-09-30
  • 来自专栏01ZOO

    go-protobuf, go-grpc-gateway和代码生成

    如何实现一个类似的parser golang/protobuf 是golang对protobuf对支持对官方实现,用于从proto文件生成对应对go版本代码文件. 入口在protoc-gen-go/main.go, 本质是显示protoc对一个插件,而protoc对于插件对实现比较直接,protoc会按照protobuf的相关定义解析protoc文件,然后把解析的结果传入插件的 protobuf的方法,并不是parse .proto文件 proto-gen-go 插件部分 grpc // grpc/grpc.go // proto-gen-go 的plugin,生成go结构体的同时 -> go文件 引用 -> proto/lib grpc-ecosystem/grpc-gateway grpc-gateway是protoc的另一个插件,同时他对protobuf对描述也做了拓展,用于生成 protoc-gen-grpc-gateway/gengateway 比较重要的逻辑在generator.go // 这是核心的生成输入文件的语法结构定义,可以看出和golang/protobuf是类似的

    3.6K390发布于 2019-07-28
  • 来自专栏C/C++基础

    ProtoBuf 生成 Go 代码去掉 JSON tag omitempty

    其中option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb"用来指明生成的 Go 文件所属的包的导入路径 比如我们以 addressbook 作为包名: option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb 安装方式如下: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 编译器插件 protoc-gen-go.exe 将被安装在 /protobuf/gogoproto/gogo.proto"; option go_package = "github.com/protocolbuffers/protobuf/examples/go 参考文献 Language Guide (proto3) Protocol Buffer Basics: Gogoprotobuf中进行自定义json tag标记及使用

    6.7K20编辑于 2022-06-02
  • 来自专栏Golang语言社区

    【Golang语言社区】 Go语言中使用 Protobuf

    wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz tar zxvf protobuf /configure make make install protoc -h 复制代码 2.获取 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go(被放置于 go get github.com/golang/protobuf/protoc-gen-go cd github.com/golang/protobuf/protoc-gen-go go build )、解码(unmarshaling)等功能 go get github.com/golang/protobuf/proto cd github.com/golang/protobuf/proto go =. *.proto 复制代码 这里通过 –go_out 来使用 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go

    1.5K30发布于 2018-03-19
  • 来自专栏韩曙亮的移动开发专栏

    【Android Protobuf 序列化】Protobuf 简介 ( Protobuf 项目简介 | Protobuf 优缺点分析 )

    文章目录 一、Protobuf 简介 二、Protobuf 优缺点分析 1、Protobuf 优点 2、Protobuf 缺点 三、参考资料 一、Protobuf 简介 ---- Protobuf 是 使用场景 : 数据交换 : 从网络中下载数据 , 发送数据给服务器 ; 数据存储 : 获取或生成的数据 , 需要存储下来 ; Protobuf 语言特点 : Protobuf 包含一套 " 数据结构接口描述语言 ://github.com/protocolbuffers/protobuf Protobuf 当前支持的编程语言 , 平台 ; 一套 Protobuf 源文件 , 可以编译出不同的语言的源代码 , 支持的语言类型如下 : 二、Protobuf 优缺点分析 ---- 1、Protobuf 优点 性能方面 : 体积小 : Protobuf 序列化后 , 体积小 , 序列化后 , 大约是 JSON / XML 等文本方式的 Protobuf 参考资料 : Protobuf 官网主页 : https://developers.google.com/protocol-buffers Protobuf 语法指南 : https

    3.7K30编辑于 2023-03-29
  • 来自专栏韩曙亮的移动开发专栏

    【Android Protobuf 序列化】Protobuf 使用 ( Protobuf 使用文档 | 创建 Protobuf 源文件 | Protobuf 语法 )

    文章目录 一、Protobuf 使用文档 二、创建 Protobuf 源文件 三、Protobuf 语法 四、参考资料 一、Protobuf 使用文档 ---- Protobuf Java 语言对应用法 : https://developers.google.com/protocol-buffers/docs/javatutorial 使用时 , 参考上述页面的文档说明 , 进行开发 ; 二、创建 Protobuf 语法 ---- 设置 protobuf 语法版本 : Protocol Buffers 有 proto2 和 proto3 两个版本 , 这两个版本之间的 语法 , 与 底层实现 都有一定的不同 ; 参考资料 : Protobuf 官网主页 : https://developers.google.com/protocol-buffers Protobuf 语法指南 : https://developers.google.com /docs/javatutorial Protobuf 源码地址 : https://github.com/protocolbuffers/protobuf

    1.7K30编辑于 2023-03-29
领券