File: helper.go

package info (click to toggle)
golang-github-influxdata-yarpc 0.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package yarpcproto

import (
	"reflect"

	proto "github.com/gogo/protobuf/proto"
	google_protobuf "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
)

func GetServiceIndex(service *google_protobuf.ServiceDescriptorProto) int {
	return GetIntExtension(service.Options, E_YarpcServiceIndex, -1)
}

func GetMethodIndex(service *google_protobuf.MethodDescriptorProto) int {
	return GetIntExtension(service.Options, E_YarpcMethodIndex, -1)
}

func GetIntExtension(pb proto.Message, extension *proto.ExtensionDesc, ifnotset int) int {
	if reflect.ValueOf(pb).IsNil() {
		return ifnotset
	}
	value, err := proto.GetExtension(pb, extension)
	if err != nil {
		return ifnotset
	}
	if value == nil {
		return ifnotset
	}
	if value.(*uint32) == nil {
		return ifnotset
	}
	return int(*(value.(*uint32)))
}