客户端与服务器通信的协议现在大部分都是使用google proto buffer规则,怎么在项目中使用gpb?本文对erlang项目旨在搭建使用gpb依赖,将.proto文件转化为.erl文件进行使用。
一、说明
- 本文环境:windows、idea、rebar3,搭建可以参考windows下idea使用rebar3
- rebar3依赖相关文档连接
- 本文使用的rebar3指令:rebar3 new app name、rebar3 compile、rebar3 shell、rebar3 deps
- 本文搭建内容为lager依赖后续,继续对test.app进行搭建,目的是使test.app能够使用proto文件
二、添加rebar3_gpb_plugin插件依赖
1、rebar3_gpb_plugin介绍
rebar3_gpb_plugin是用于自动转化使用gpb规则编写的.proto文件的插件,能将.proto文件转化为对应的.erl文件
2、rebar3_gpb_plugin下载
- reba3_gpb_plugin2.22.4版本地址
- 下载完压缩包,解压到项目deps文件夹下,改名为rebar3_gpb_plugin
3、rebar3_gpb_plugin依赖项拉取
- 偷懒方法:用rebar3 deps自动拉取依赖项
- 1、将rebar3、rebar3.cmd文件拷贝到在deps文件夹下,并创建rebar.config文件
rebar.config文件内容
{erl_opts, [debug_info]}.
{deps, [rebar3_gpb_plugin]}.