-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Exposed more functions in FieldDescriptor and OneofDescriptor. #10102
Merged
haberman
merged 4 commits into
protocolbuffers:main
from
fiboknacky:update-fielddescriptor
Jun 13, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b27dd18
Exposed more functions in FieldDescriptor and OneofDescriptor.
fiboknacky 238331b
Added support for getRealContainingOneof() and getContainingOneof()
fiboknacky 594f2a9
Fixes bugs of isSynthetic and makes containing_oneof work
fiboknacky 0f1574a
Fixed bugs of OneofDescriptor.
fiboknacky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,11 @@ class FieldDescriptor | |
private $message_type; | ||
private $enum_type; | ||
private $packed; | ||
private $is_map; | ||
private $oneof_index = -1; | ||
private $proto3_optional; | ||
|
||
/** @var OneofDescriptor $containing_oneof */ | ||
private $containing_oneof; | ||
|
||
public function __construct() | ||
{ | ||
|
@@ -169,6 +172,32 @@ public function getPacked() | |
return $this->packed; | ||
} | ||
|
||
public function getProto3Optional() | ||
{ | ||
return $this->proto3_optional; | ||
} | ||
|
||
public function setProto3Optional($proto3_optional) | ||
{ | ||
$this->proto3_optional = $proto3_optional; | ||
} | ||
|
||
public function getContainingOneof() | ||
{ | ||
return $this->containing_oneof; | ||
} | ||
|
||
public function setContainingOneof($containing_oneof) | ||
{ | ||
$this->containing_oneof = $containing_oneof; | ||
} | ||
|
||
public function getRealContainingOneof() | ||
{ | ||
return !is_null($this->containing_oneof) && !$this->containing_oneof->isSynthetic() | ||
? $this->containing_oneof : null; | ||
} | ||
|
||
public function isPackable() | ||
{ | ||
return $this->isRepeated() && self::isTypePackable($this->type); | ||
|
@@ -214,6 +243,10 @@ private static function isTypePackable($field_type) | |
$field_type !== GPBType::BYTES); | ||
} | ||
|
||
/** | ||
* @param FieldDescriptorProto $proto | ||
* @return FieldDescriptor | ||
*/ | ||
public static function getFieldDescriptor($proto) | ||
{ | ||
$type_name = null; | ||
|
@@ -248,8 +281,6 @@ public static function getFieldDescriptor($proto) | |
$field = new FieldDescriptor(); | ||
$field->setName($proto->getName()); | ||
|
||
$json_name = $proto->hasJsonName() ? $proto->getJsonName() : | ||
lcfirst(implode('', array_map('ucwords', explode('_', $proto->getName())))); | ||
Comment on lines
-251
to
-252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant with the if clause below. |
||
if ($proto->hasJsonName()) { | ||
$json_name = $proto->getJsonName(); | ||
} else { | ||
|
@@ -269,6 +300,7 @@ public static function getFieldDescriptor($proto) | |
$field->setLabel($proto->getLabel()); | ||
$field->setPacked($packed); | ||
$field->setOneofIndex($oneof_index); | ||
$field->setProto3Optional($proto->getProto3Optional()); | ||
|
||
// At this time, the message/enum type may have not been added to pool. | ||
// So we use the type name as place holder and will replace it with the | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this function; it is useful.
You can implement it to match the C++ definition: http://google3/third_party/protobuf/descriptor.h;l=2387-2391;rcl=452188950
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the C++ implementation needs to rely on many fields and functions that don't exist here yet. I'll leave this function to you. I may get back here once I implement other functions that I need for my feature.
Having said that, IMHO, it's a broken function (for a while). Leaving it like this doesn't provide any good unless we provide the correct implementation soon.