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

A macro for safely accessing fields deep in protobufs #5164

Open
mbautin opened this issue Jul 20, 2020 · 1 comment
Open

A macro for safely accessing fields deep in protobufs #5164

mbautin opened this issue Jul 20, 2020 · 1 comment
Assignees

Comments

@mbautin
Copy link
Collaborator

mbautin commented Jul 20, 2020

It would be good to have a macro to replace something like

        replicate->has_write_request() &&
            replicate->write_request().has_write_batch() &&
            replicate->write_request().write_batch().has_transaction());

with

PB_HAS_NESTED_FIELD(replicate, write_request, write_batch, transaction)

and similarly PB_NESTED_FIELD and PB_MUTABLE_NESTED_FIELD to get the actual field.

We can even avoid repeated function calls (in the example above, to replicate->write_request()) in this macro's implementation.

@mbautin mbautin self-assigned this Jul 20, 2020
@robertsami
Copy link
Contributor

@mbautin might be missing something here, but wouldn't the following two always evaluate to the same value?

replicate->has_write_request() &&
            replicate->write_request().has_write_batch() &&
            replicate->write_request().write_batch().has_transaction();

vs.

replicate->write_request().write_batch().has_transaction();

since replicate->write_request() would return a default value if not present, which would lead to replicate->write_request().write_batch() returning default value as well, which would lead to replicate->write_request().write_batch().has_transaction() returning false

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

No branches or pull requests

2 participants