Normalize FieldDescriptor#type; add #json_name and #default_value#17
Merged
Conversation
96d2709 to
e60793e
Compare
e60793e to
2d84690
Compare
- #type: override the delegated type enum to a plain symbol for every field, dropping the TYPE_ prefix and downcasing (:TYPE_INT32 -> :int32, :TYPE_MESSAGE -> :message). descriptor.type is read in exactly one place (the normalization); the type predicates and map detection are defined in terms of #type. - #json_name: the protoc-computed JSON name. - #default_value: the proto2 default as a string, or nil when absent.
2d84690 to
69d56ca
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Three small
FieldDescriptorconveniences for codegen.Changes
#type— overrides the delegatedtypeenum to a plain symbol for every field: theTYPE_prefix is dropped and the rest downcased (:TYPE_INT32→:int32,:TYPE_MESSAGE→:message,:TYPE_ENUM→:enum). For:message/:enumfields use#type_descriptor(or#key/#valuefor maps) to resolve the referenced type.descriptor.typeis read in exactly one place — the normalization itself — and the type predicates (#message?/#enum?/#group?) and map detection are all defined in terms of#type.#json_name— the JSON name computed by protoc (lowerCamelCase unless overridden with thejson_nameoption).#default_value— the explicit proto2 default as a string, ornilwhen none was declared (proto3 fields never carry defaults).Testing
#typenormalizes across scalar and message fields;#json_nameincluding a camelCased case (published_at→publishedAt);#default_valuevia a synthetic proto2-style field, andnilwhen absent.bin/rake(test + rubocop): 80 runs, 208 assertions, 0 failures, rubocop clean.