Giter VIP home page Giter VIP logo

Comments (8)

Keam avatar Keam commented on July 30, 2024

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.

tomas-abrahamsson avatar tomas-abrahamsson commented on July 30, 2024

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.

Keam avatar Keam commented on July 30, 2024

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.

tomas-abrahamsson avatar tomas-abrahamsson commented on July 30, 2024

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.

Keam avatar Keam commented on July 30, 2024

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.

tomas-abrahamsson avatar tomas-abrahamsson commented on July 30, 2024

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.

tomas-abrahamsson avatar tomas-abrahamsson commented on July 30, 2024

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.

Keam avatar Keam commented on July 30, 2024

thanks!

from gpb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.