Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept 0 and 1 as boolean values #64

Conversation

lukebakken
Copy link
Contributor

Accept 0 and 1 for false / true boolean values.

Related to #63

Questions -

  • These changes will also allow 0 and 1 as default values, which isn't part of the PB spec. This doesn't seem to be the end of the world, though. What do you think @tomas-abrahamsson ?
  • Could you point me to the tests to show binary data being decoded to true and false atoms? I couldn't find them, and just wanted to verify.

Thanks!

@tomas-abrahamsson
Copy link
Owner

  • These changes will also allow 0 and 1 as default values, which isn't part of the PB spec. This doesn't seem to be the end of the world, though. What do you think @tomas-abrahamsson ?

I agree, there are more issues like this, where gpb is overly generous, and there's also a general note in the README that

You might want to first verify with protoc that the .proto files
are valid before feeding them to gpb.

About

  • Could you point me to the tests to show binary data being decoded to true and false atoms? I couldn't find them, and just wanted to verify.

Take a look at gpb_tests:decode_msg_with_bool_field_test This test is one of those that are executed for both the decoder in gpb and for the code generated by gpb_compile, due to (the somewhat un-orthodox procedure of) gpb_compile_tests.erl including gpb_tests.erl

@lukebakken
Copy link
Contributor Author

Thanks. This PR is ready for review 😄

@tomas-abrahamsson
Copy link
Owner

Looks fine. I just came to think of one more thing: The README.md has a section on Erlang-internal types and values that each protobuf language type maps to, it would be nice if 0 and 1 was described there too. I can do it, if you like, or if you would force-push an updated branch, then that's fine too.

@lukebakken lukebakken force-pushed the feature/lrb/epb-boolean-compat branch from e0b2f32 to 3946d4c Compare July 20, 2016 14:25
@lukebakken
Copy link
Contributor Author

@tomas-abrahamsson - good catch, I'll make sure to update the README.md file in my other pull requests.

I re-formatted the table to use markdown syntax. The output looks good, but the source got uglier. What do you think?

@lukebakken lukebakken force-pushed the feature/lrb/epb-boolean-compat branch from 3946d4c to 00fdbaa Compare July 20, 2016 14:34
@tomas-abrahamsson
Copy link
Owner

Nice table! The source definitely got a bit worse with super long lines, but I figure the table is read by people many more times than it is edited, so I'd say it is a change for the better anyway.

@lukebakken
Copy link
Contributor Author

OK, great. I think this PR should be all set then. Thank you for your assistance.

GMDecoded = gpb:decode_msg(MEncoded, ntest3, Defs),
MGDecoded = M:decode_msg(GEncoded, ntest3),
?assertEqual(OrigMsgAtom, MMDecoded),
?assertEqual(OrigMsgInt, GMDecoded),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should read: ?assertEqual(OrigMsgAtom, GMDecoded),
(Ie OrigMsgAtom instead of OrigMsgInt, making the OrigMsgInt variable unused)

I found this out during a test merge I did of all epb compat branches, it probably went unnoticed earlier due to the other bug of not catching bugs in from the separate vm stage, sorry about that :/

@tomas-abrahamsson
Copy link
Owner

Found one issue during a test merge

@lukebakken lukebakken force-pushed the feature/lrb/epb-boolean-compat branch from 00fdbaa to a10c34e Compare July 22, 2016 16:29
@lukebakken
Copy link
Contributor Author

lukebakken commented Jul 22, 2016

@tomas-abrahamsson the boolean nif test is fixed, and the failure exposed a bug.

I'm making one more small change, stay tuned...

Add NIF test for 0/1 booleans, fix function_clause error in format_bool_encoder

Expand section about booleans in types table. Convert to markdown table

Fix boolean nif test

Make gpb_true_int a one-time initialized ERL_NIF_TERM
@lukebakken lukebakken force-pushed the feature/lrb/epb-boolean-compat branch from 04850f5 to 38fef38 Compare July 22, 2016 16:44
@lukebakken
Copy link
Contributor Author

OK now I think it's all set 😄

@tomas-abrahamsson
Copy link
Owner

Perfect, up for merge, and will be included in the next release.

@tomas-abrahamsson tomas-abrahamsson merged commit 38fef38 into tomas-abrahamsson:master Jul 23, 2016
@tomas-abrahamsson
Copy link
Owner

This is now included in 3.24.0

@lukebakken lukebakken deleted the feature/lrb/epb-boolean-compat branch July 25, 2016 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants