Skip to content

A rebar3 plugin generates protocolbuf description file to erlang file using leex and yecc to generate.

License

Notifications You must be signed in to change notification settings

xlkness/rebar3_pb_msgdesc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rebar3_pb_msgdesc

A rebar plugin generates protocolbuf description file to an erlang file.

Build

rebar3 compile

Use

Configuration

Add the plugin to your rebar config:

{plugins, [
    { rebar3_pb_msgdesc, {git, "https://github.com/xlkness/rebar3_pb_msgdesc", {branch, "master"}}}
]}.

Configuration in rebar.config

{msgdesc_opt, [
    {desc_file, "./test.csv"},
    {out_put_file, "test_pb_desc.erl"}
]}.
{provider_hooks, [
    {pre, [
        {compile, {msgdesc, compile}}
    ]}
]}.

Description file

Add some protocolbuf descriptions content to a file, format type_id,type_name,module, i.e:

10000,Request,test_proto
10001,Response,test_proto

Compile

Then just call your plugin directly in an existing application:

rebar3 msgdesc compile

And you can find an out_file_name file in the out_dir, the content are as follows:

msg_type(10000) -> Request;
msg_type(10001) -> Response;
msg_type(Other) -> {error, msgdesc, msg_type, Other}.
msg_code('Request') -> 10000;
msg_code('Response') -> 10001;
msg_code(Other) -> {error, msgdesc, msg_code, Other).
decode_for(10000) -> test_proto;
decode_for(10001) -> test_proto;
decode_for(Other) -> {error, msgdesc, decode_for, Other).

Clean

rebar3 msgdesc clean

Note

A simple plugin, but i use lexer and yecc syntax tool to accomplish. Just for studying.

File rebar3_pb_msgdesc_lexer.xrl and rebar3_pb_msgdesc_parser.yrl are the most important files.

About

A rebar3 plugin generates protocolbuf description file to erlang file using leex and yecc to generate.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages