Comments (8)
Me again,
First, thank you for all your hard work.
Second, after reading your gpb_compile.erl
specifically,
doc
Compile a .proto file to a .erl file and to a .hrl file.
The File must not include path to the .proto file. Example: "SomeDefinitions.proto" is ok, while > >"/path/to/SomeDefinitions.proto" is not ok.
The .proto file is expected to be found in a directories specified by an
{i,directory()}
option. It is possible to specify{i,directory()}
several times, they will be searched in the order specified.
Do I need to manually create the directory mkdir -p
? or does
{gpb_opts, [
{i, "../_build/proto_dir"},
{module_name_suffix, "_pb"},
{o_erl, "../_build/out_src"},
{o_hrl, "../_build/out_include"},
{strings_as_binaries, true},
type_specs]}.
create the directory by rebar3 compile
? I tried the rebar3 compile
option and directories were not created.
Sorry if this is a real newbie questions.
from gpb.
I think you're missing rebar3 protobuf compile
before rebar3 compile
.
I think this is actually more of a rebar3_gpb_plugin question than a gpb
question, but here's some guidance.
I set up an example app, mylib
using just rebar3 new app
.
I had the following relevant lines in rebar.config
:
{erl_opts, [debug_info, {i, "./_build/default/plugins/gpb/include"}]}.
...
{gpb_opts, [{i, "src"},
{o_hrl, "include"},
{o_erl, "src"},
{module_name_suffix, "_pb"},
{strings_as_binaries, true},
type_specs]}.
{provider_hooks, [
{pre, [{compile, {protobuf, compile}},
{clean, {protobuf, clean}}]}]}.
And this in src/mylib_x.proto
:
message m {
required uint32 f = 1;
}
I generated mylib_x_pb.erl
and mylib_x_pb.hrl
into the _build/...
dir from src/mylib_x.proto
using: rebar3 protobuf compile
The rebar3_gpb_plugin
compiles .proto
files it finds in the directories from the {i,Dir}
option(s), and internally prepends the dest build directory to any o_erl
and o_hrl
options. Directory creation is automatic.
Then I compiled these using rebar3 compile
.
To use the generated code, I could call mylib_x_pb:decode_msg(Bin,m)
where Bin is some http POSTed data I've got via cowboy. Decoding would give me an #m{}
. Or I could call Bin = mylib_x_pb:encode_msg(#m{f=4711})
to get me a binary I could send to cowboy for shipping over http.
Hope this is useful for you
from gpb.
Thank you Tomas, that worked. You were correct I was missing the rebar3 protobuf compile
step. I check the directories and it appears all the proper files have been created.
To test,
$ cd myapp
$ rebar3 shell
1> myapp_pb:
At this point, the decode or encode functions are not available. I understand your instructions but I'm I loading the myapp_pb incorrectly?
Thank you again for your help
from gpb.
You might need to load the module into the shell before it can expand. For example l(myapp_pb).
or m(myapp_pb).
The former will load the module. The latter will print some info about it, and to do that, as a side-effect, it will first load the module.
from gpb.
Thank you again!
However, I did learned that using a hyphen -
in the file name is a no no
This didn't work:
$ rebar3 shell
1> m(rtb-myapp_pb).
** exception error: an error occurred when evaluating an arithmetic expression
in operator -/2
called as rtb - myapp_pb
This did work
rebar3 shell
1> m(rtb_pb).
Module: rtb_pb
MD5: 819507be6604e......
from gpb.
Yes :) It is possible to have "funny" characters in module names (which are just atoms). You have to quote the atoms, like this: 'rtb-myapp_pb'
. But it is generally easier and more common to go with underscores instead of dashes.
from gpb.
I take it your issue with gpb is solved, and we can close this? For general questions about Erlang itself, I thought I should hint about subscribing to the erlang-questions mailing list over at http://www.erlang.org/community/mailinglists
from gpb.
thanks!
from gpb.
Related Issues (20)
- There are many deficiencies HOT 6
- Hitting `no case clause matching: :group_end` in Elixir app using Exprotobuf/gpb HOT 8
- Add preprocessor check around no_underspec? HOT 3
- Optional added back to proto3 HOT 3
- Outdated example HOT 3
- Unset `google.protobuf.StringValue` map values are decoded as empty strings instead of empty values HOT 3
- proposal for performance improvements HOT 9
- Performance improvement for encoding protos with unchanged data HOT 7
- -spec for enum generated code is incorrect HOT 3
- For gpb 5: Drop support for Erlang versions before 19
- How can i call gpb from my rebar.config? HOT 2
- [enhancement] support for gpb text format HOT 1
- I think the generated file is too big HOT 7
- -mapfields-as-maps and -json possible incompability HOT 2
- Trying to ecode a float into a uint64 field results in a badarith exception instead of gpb_type_error HOT 2
- Enums are not defined as macros HOT 7
- Fix for warning on float 0.0 HOT 5
- to_json encodes `uint64` as an integer instead of a string HOT 1
- Add a @generated tag HOT 1
- Excessive File Size in Generated Protobuf Files HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpb.