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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package internal
import (
"errors"
"fmt"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
// GetOpExtension gets the OperationMsg from a method descriptor
func GetOpExtension(m *descriptor.MethodDescriptorProto) (*gitalypb.OperationMsg, error) {
options := m.GetOptions()
if !proto.HasExtension(options, gitalypb.E_OpType) {
return nil, errors.New("missing op_type option")
}
ext, err := proto.GetExtension(options, gitalypb.E_OpType)
if err != nil {
return nil, err
}
opMsg, ok := ext.(*gitalypb.OperationMsg)
if !ok {
return nil, fmt.Errorf("unable to obtain OperationMsg from %#v", ext)
}
return opMsg, nil
}
// GetStorageExtension gets the OperationMsg from a method descriptor
func GetStorageExtension(m *descriptor.FieldDescriptorProto) (bool, error) {
options := m.GetOptions()
if !proto.HasExtension(options, gitalypb.E_Storage) {
return false, nil
}
ext, err := proto.GetExtension(options, gitalypb.E_Storage)
if err != nil {
return false, err
}
storageMsg, ok := ext.(*bool)
if !ok {
return false, fmt.Errorf("unable to obtain bool from %#v", ext)
}
if storageMsg == nil {
return false, nil
}
return *storageMsg, nil
}
|