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

protobuf: refactor proto visitor pattern. #9807

Closed
wants to merge 1 commit into from

Conversation

htuch
Copy link
Member

@htuch htuch commented Jan 23, 2020

Move the proto traversal handling in version_converter.cc to a
standalone library. This lets us replace existing proto visitor patterns in
common/protobuf/utility.cc for unexpected field checks.

The redaction code is actually a bit more involved, so I'm not
refactoring this; it needs to recurse through Any/TypedStruct.
Ultimately we might want something like this, but it doesn't seem super
helpful given we only have a the single instance of this right now.

Risk level: Low
Testing: Existing tests continue to pass.

Signed-off-by: Harvey Tuch htuch@google.com

Move the proto traversal handling in version_converter.cc to a
standalone library. This lets us replace existing proto visitor patterns in
common/protobuf/utility.cc for unexpected field checks.

The redaction code is actually a bit more involved, so I'm not
refactoring this; it needs to recurse through Any/TypedStruct.
Ultimately we might want something like this, but it doesn't seem super
helpful given we only have a the single instance of this right now.

Risk level: Low
Testing: Existing tests continue to pass.

Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch
Copy link
Member Author

htuch commented Jan 23, 2020

CC @mergeconflict not tackling redact here for reasons articulated in commit message.

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Cool, thanks for cleaning this up!
/wait

source/common/protobuf/visitor.cc Show resolved Hide resolved
(!field->is_repeated() && !reflection->HasField(message, field))) {
continue;
if ((field.is_repeated() && reflection->FieldSize(message, &field) == 0) ||
(!field.is_repeated() && !reflection->HasField(message, &field))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional, but it seems like this might be useful enough to make part of the onField call. I'd think folks would either want to be traversing structure (not care) or looking at valid fields (care) and if they care it's easy enough to get this wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Surprisingly tricky, since what is counted as used/unused is subtle for scalar fields. This can be seen in this code, since it first performs the scalar enum check before conditioning on whether the field is set in some sense.

continue;
if ((field.is_repeated() && reflection->FieldSize(message, &field) == 0) ||
(!field.is_repeated() && !reflection->HasField(message, &field))) {
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we ever return something which is used, or plan to?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, in TypeAnnotatingProtoVisitor::onField().

@stale
Copy link

stale bot commented Feb 3, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Feb 3, 2020
@junr03
Copy link
Member

junr03 commented Feb 7, 2020

not stale

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Feb 7, 2020
@stale
Copy link

stale bot commented Feb 14, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Feb 14, 2020
@stale
Copy link

stale bot commented Feb 21, 2020

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stalebot believes this issue/PR has not been touched recently waiting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants