Comments (6)
For input data validation, you might want to try the verify option.
Here's an example trying to encode -1 for an unsigned int:
$ cat m.proto
syntax='proto3';
message Msg { uint32 f = 1; }
$
$ erl
1> gpb_compile:file("m.proto", [maps,{verify,always}]).
...
3> m:encode_msg(#{f => -1}, 'Msg').
m:encode_msg(#{f => -1}, 'Msg').
** exception error: {gpb_type_error,{{value_out_of_range,uint32,unsigned,32},
[{value,-1},{path,"Msg.f"}]}}
in function m:mk_type_error/3 (m.erl, line 353)
in call from m:v_msg_Msg/3 (m.erl, line 332)
in call from m:encode_msg/3 (m.erl, line 70)
For range checking for the output data, I'm not sure I follow. Could you explain more what you mean by this?
from gpb.
$ cat ts.proto
import "t1.proto"
message video_c
{
required uint32 id = 1; // id
optional bytes name = 2; // name
repeated uint32 terms = 3; // terms
}
Administrator@PC-20170610DFEC MINGW64 /g/zzwz/proto/gpb (master)
$ erl -pa ebin
Eshell V8.3 (abort with ^G)
1> ts:decode_msg(<<>>, video_c).
{video_c,undefined,undefined,[]}
2>
from gpb.
Another problem is that the generated code is too redundant, especially when a file is referenced multiple times, and there are N copies of the parsing code for that file.I don't know if there's a solution out there.
from gpb.
I assume you did expect some kind of decoding error when the binary is missing required fields? Maybe that is a good addition, but it would need to be enabled by an option for backwards compatibility.
... too redundant when a file is referenced multiple times...
There is no option to generate one .erl per .proto. Some redesign would be needed for that. Some areas that may need thinking is extend
and (proto3) defaults.
Is your case that you have a few top-level .proto
, some 2nd-level .proto
s that are import
ed from the top-levels, and some 3rd or deeper level .proto
s? If so, do you generate .erls
for all of these? If yes, then maybe you could reduce the overhead of duplication by generating only for the top-level .proto
s.
from gpb.
thank you
from gpb.
In 4.18.0, which i just pushed, I added an option, verify_decode_required_present
(cmd-line: -vdrp
) for generating code that checks that required
fields are present in the input binary to decode, so I'm closing this issue. If there's anything more, feel free to re-open or open another issue.
from gpb.
Related Issues (20)
- 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.