GithubHelp home page GithubHelp logo

Comments (16)

jinganix avatar jinganix commented on September 15, 2024 1

tomas-abrahamsson/gpb#184 (comment)

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024 1

@dogtapdsd Please try the new commit

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

https://github.com/jg513/enif_protobuf/blob/459a5c7056a977ed9751e6662ef49c8f953b1409/c_src/ep_decoder.c#L835

pseudo-code maybe added as following:

else if (field->type == field_enum && field->proto_v == 3) {
*t++ = field->sub_node->v_fields[0]->name
}

Hope this helps

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024

Thanks, I got it working.. however.. the proto_v is 2 in my case for some reason.. I use gpb to compile and obtain the msg definitions and then I load it using enif_protobuf.

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

https://github.com/jg513/enif_protobuf/blob/459a5c7056a977ed9751e6662ef49c8f953b1409/c_src/enif_protobuf.c#L184

There is a function get_msg_defs in the generated erl.

Is there any proto3 or proto3_msgs words in the definition?

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024

No, I do not see one in the get_msg_defs function in the generated erl file.
However, my .proto files have the line syntax=proto3.

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024

thank you!

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024
syntax="proto3";

message Person {
    string name = 1;
    int32 id = 2;
    optional string email = 3;
}
erl -pa ebin
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]

Eshell V11.0.3  (abort with ^G)
1> gpb_compile:file("x.proto",[to_proto_defs,{proto_defs_version,2}]).
{ok,[{proto_defs_version,2},
     {file,{"x","x.proto"}},
     {{msg_containment,"x"},['Person']},
     {{enum_containment,"x"},[]},
     {syntax,"proto3"},
     {{msg,'Person'},
      [{field,name,1,2,string,defaulty,[]},
       {field,id,2,3,int32,defaulty,[]},
       {field,email,3,4,string,optional,[]}]},
     {proto3_msgs,['Person']}]}

Try to load_cache with the definitions

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024

I am trying to run load_cache inside my application after it starts. I use rebar to compile my proto files.. Although It works in the erl shell as you show, adding proto_defs_version or the to_proto_defs options to my rebar.config does not help.

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

Could you share the snippet in your rebar.config?

erl -noshell -pa GPB/ebin -eval 'io:format("-module(x).\n-export([get_msg_defs/0]).\nget_msg_defs() ->\n~p.",[case gpb_compile:file("x.proto",[to_proto_defs,{proto_defs_version,2}]) of {ok,V} -> V end])' -eval 'init:stop()' > defs.erl

The shell command will generate a defs file.

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024
{proto_opts, [
              {compiler, gpb},
              {src_dirs, ["proto"]}
             ]}.


{gpb_opts, [{msg_name_prefix, "pb_"},
            {o_erl, "src/proto/"},
            {o_hrl, "include/proto/"},
            {to_proto_defs},
            {proto_defs_version, 2}]}.

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

https://github.com/tomas-abrahamsson/gpb/blob/87abc9cf9ee613ac1068b2e02f54eb48e9862d39/src/gpb_compile.erl#L1246

It seems when set to_proto_defs, no files will be generated.

from enif_protobuf.

balusu-murali avatar balusu-murali commented on September 15, 2024

sorry for the delay in getting back.
I removed to_proto_defs and use this now: it still does not help!

{gpb_opts, [{msg_name_prefix, "pb_"},
            {o_erl, "src/proto/"},
            {o_hrl, "include/proto/"},
            {strings_as_binaries, true},
            {proto_defs_version, 2}]}.

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

We must compile proto files with to_proto_defs option.

But with the option, we can just get the output from shell, no file will be generated.

So I think we should generate another defs file, and load the defs.

This is one possible way, I posted before:

#11 (comment)

from enif_protobuf.

jinganix avatar jinganix commented on September 15, 2024

tomas-abrahamsson/gpb#184 (comment)
There is a new option introspect_get_proto_defs, please take a look.

from enif_protobuf.

dogtapdsd avatar dogtapdsd commented on September 15, 2024

when I use gpb 4.18.0 with -introspect-get_proto_defs option, generate get_proto_defs like

get_proto_defs() ->
[{proto_defs_version, 2},
{file, {"proto3_180", "proto3_180.proto"}},
{{msg_containment, "proto3_180"}, [pro_180_all_prop, pro_180_items_list]},
{{enum_containment, "proto3_180"}, []},
{syntax, "proto3"},
{{msg, pro_180_items_list},
[#field{name = id, fnum = 1, rnum = 2, type = uint32, occurrence = defaulty, opts = []},
#field{name = num, fnum = 2, rnum = 3, type = uint32, occurrence = defaulty, opts = []},
#field{name = text, fnum = 3, rnum = 4, type = string, occurrence = defaulty, opts = []}]},
{{msg, pro_180_all_prop},
[#field{name = key, fnum = 1, rnum = 2, type = uint32, occurrence = defaulty, opts = []},
#field{name = value, fnum = 2, rnum = 3, type = uint32, occurrence = defaulty, opts = []},
#field{name = incval, fnum = 3, rnum = 4, type = uint32, occurrence = defaulty, opts = []}]},
{proto3_msgs, [pro_180_all_prop, pro_180_items_list]}].

but after execute code enif_protobuf:load_cache(proto3_180:get_proto_defs()). in eshell, it crash immidiately. error like “start.sh: line 2: 24780 Segmentation fault ”
here is
proto3_180.proto

syntax = "proto3";
message Pro_180_Items_List {
uint32 id = 1;
uint32 num = 2;
string text = 3;
}
message Pro_180_All_Prop {
uint32 key = 1;
uint32 value = 2;
uint32 incval = 3;
}

from enif_protobuf.

Related Issues (19)

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.