Comments (16)
tomas-abrahamsson/gpb#184 (comment)
from enif_protobuf.
@dogtapdsd Please try the new commit
from enif_protobuf.
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.
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.
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.
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.
thank you!
from enif_protobuf.
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.
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.
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.
{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.
It seems when set to_proto_defs
, no files will be generated.
from enif_protobuf.
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.
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:
from enif_protobuf.
tomas-abrahamsson/gpb#184 (comment)
There is a new option introspect_get_proto_defs
, please take a look.
from enif_protobuf.
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)
- mac环境下编译报错 HOT 2
- Compilation Failed with OTP-23 and rebar 3.11.1 HOT 2
- Issue with oneof fields HOT 12
- proto3: field specific custom options HOT 11
- rebar compile issue HOT 8
- uint64 decode fail HOT 9
- 支持encode map么 HOT 1
- combine two protobuf 3.0's defs, only one {proto3_msgs, [...]} works, other sill packed like protobuf 2.0, preset default value in binary. HOT 1
- load_cache/1 segfaults on non-trivial maps HOT 1
- Does not skip encoding "empty" fields HOT 5
- load_cache_1: random Segmentation faults HOT 3
- building for macos m1
- make failed on OTP 25 project HOT 1
- What does tid_not_found mean and how to avoid it? HOT 11
- 协议循环引用触发加载死循环
- load_cache crash if there are other fields after oneof HOT 2
- decoding of some msg fails HOT 3
- {error, tid_not_found} when encoding/decoding HOT 6
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 enif_protobuf.