centos 7.2 下为erlang添加protobuffs

安装前提:
1.已经安装好erlang otp 
3.安装git  (centos:yum install git           ubantu:sudo apt install git)
 
 
在rebar.config中的deps中加入protobuffs
 
{deps, [{protobuffs,".*",{git,"https://github.com/basho/erlang_protobuffs.git",""}},
         {'goldrush',".*",{git,"https://github.com/extend/goldrush.git","mastter"}},
         {'proper', ".*", {git,"https://github.com/manopapad/proper.git", "master"}},
         {'lager',".*",{git, "https://github.com/erlang-lager/lager.git","master"}}]}.

  

然后执行 ./rebar get-deps
在get-deps过程中会下载 meck(protobuffs的依赖库)和protobuffs两个依赖库。
 
到这里之后你可以在src下新建一个test.proto文件
 
test.proto文件:
 
message Person {
     required int32 age = 1;
     required string name = 2;
 }
 
 message Family {
     repeated Person person =1;
 }

  

然后执行编译命令   ./rebar clean compile
会发现在rebar 同级目录生成了一个include文件夹,里面包含一个test.hrl的文件,打开会看到如下:
这就是proto编译生成头文件。
其实到这里整个protobuffs就算可以用了,但我们为了结构的清晰不希望所有的文件都放在src中,(我希望我的协议文件都在在和src同级的proto文件夹下)。
 
因为rebar的文档中并没有写如何配置,只是给出了src_dirs这个参数可以设置其他的源文件的地址,但直接在rebar.config中加入{src_dirs,["proto"]}并没有用,然后在rebar源码中找到关于对protobuffs的编译代码,rebar_proto_comiler.erl文件

  

这里设置了读取config的proto_opts项,然后下面会有src_dirs,这里的如果没有配置的时候默认是src文件夹,所以其实src_dirs是配在proto_opts下的,参照rebar.config.sample,
这是例子中给出的配置:
  

然后我将自己的也配置成了下面这样, 

   

完成之后,在src同级目录下新建一个proto文件夹,然后在里面创建*.proto文件,再执行./rebar compile 的时候就会编译proto下的协议文件。 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/ACshasow/p/6964512.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值