feat(option): Add bool method option
This commit is contained in:
parent
0fe0e49401
commit
9938cbdf5a
@ -154,6 +154,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"leadingDetachedComments": leadingDetachedComments,
|
"leadingDetachedComments": leadingDetachedComments,
|
||||||
"stringFieldExtension": stringFieldExtension,
|
"stringFieldExtension": stringFieldExtension,
|
||||||
"stringMethodOptionsExtension": stringMethodOptionsExtension,
|
"stringMethodOptionsExtension": stringMethodOptionsExtension,
|
||||||
|
"boolMethodOptionsExtension": boolMethodOptionsExtension,
|
||||||
"boolFieldExtension": boolFieldExtension,
|
"boolFieldExtension": boolFieldExtension,
|
||||||
"isFieldMap": isFieldMap,
|
"isFieldMap": isFieldMap,
|
||||||
"fieldMapKeyType": fieldMapKeyType,
|
"fieldMapKeyType": fieldMapKeyType,
|
||||||
@ -351,6 +352,41 @@ func stringFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) str
|
|||||||
return *str
|
return *str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func boolMethodOptionsExtension(fieldID int32, f *descriptor.MethodDescriptorProto) bool {
|
||||||
|
if f == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if f.Options == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var extendedType *descriptor.MethodOptions
|
||||||
|
var extensionType *bool
|
||||||
|
|
||||||
|
eds := proto.RegisteredExtensions(f.Options)
|
||||||
|
if eds[fieldID] == nil {
|
||||||
|
ed := &proto.ExtensionDesc{
|
||||||
|
ExtendedType: extendedType,
|
||||||
|
ExtensionType: extensionType,
|
||||||
|
Field: fieldID,
|
||||||
|
Tag: fmt.Sprintf("bytes,%d", fieldID),
|
||||||
|
}
|
||||||
|
proto.RegisterExtension(ed)
|
||||||
|
eds = proto.RegisteredExtensions(f.Options)
|
||||||
|
}
|
||||||
|
|
||||||
|
ext, err := proto.GetExtension(f.Options, eds[fieldID])
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
b, ok := ext.(*bool)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return *b
|
||||||
|
}
|
||||||
|
|
||||||
func boolFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) bool {
|
func boolFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) bool {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return false
|
return false
|
||||||
@ -378,12 +414,12 @@ func boolFieldExtension(fieldID int32, f *descriptor.FieldDescriptorProto) bool
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
str, ok := ext.(*bool)
|
b, ok := ext.(*bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return *str
|
return *b
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user