| 1 | package yarpcproto |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | |
| 6 | proto "github.com/gogo/protobuf/proto" |
| 7 | google_protobuf "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" |
| 8 | ) |
| 9 | |
| 10 | func GetServiceIndex(service *google_protobuf.ServiceDescriptorProto) int { |
| 11 | return GetIntExtension(service.Options, E_YarpcServiceIndex, -1) |
| 12 | } |
| 13 | |
| 14 | func GetMethodIndex(service *google_protobuf.MethodDescriptorProto) int { |
| 15 | return GetIntExtension(service.Options, E_YarpcMethodIndex, -1) |
| 16 | } |
| 17 | |
| 18 | func GetIntExtension(pb proto.Message, extension *proto.ExtensionDesc, ifnotset int) int { |
| 19 | if reflect.ValueOf(pb).IsNil() { |
| 20 | return ifnotset |
| 21 | } |
| 22 | value, err := proto.GetExtension(pb, extension) |
| 23 | if err != nil { |
| 24 | return ifnotset |
| 25 | } |
| 26 | if value == nil { |
| 27 | return ifnotset |
| 28 | } |
| 29 | if value.(*uint32) == nil { |
| 30 | return ifnotset |
| 31 | } |
| 32 | return int(*(value.(*uint32))) |
| 33 | } |