-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the AnyMetadata class and use free functions instead.
The way AnyMetadata works is by holding two pointers to the fields of google.protobuf.Any, and its methods `PackFrom` and `UnpackTo` mutates these pointers directly. This works but is a bit overcomplicated. A whole new object is created to mutate members of Any directly, breaking isolation. Each Any object will also need to unnecessarily create room to hold an AnyMetadata object, which is at minimum the size of two pointers. By removing AnyMetadata and using free functions, the call site passes `const Value& foo()` and `Value* mutable_foo()` directly into `PackFrom` and `UnpackTo`. This is more idiomatic and will play well with hasbits. The only catch here is that in some templated implementations of `PackFrom` and `UnpackTo`, caller will need access to T::FullMessageName(), which is in private scope. The workaround here is to have a single templated helper function that is made into a friend of google.protobuf.Any, so that it has the right visibility. PiperOrigin-RevId: 670722407
- Loading branch information
1 parent
1f237ef
commit 920d5c3
Showing
10 changed files
with
333 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.