file.go 5.69 KB
Newer Older
Jeromy's avatar
Jeromy committed
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
// Extensions for Protocol Buffers to create more go like structures.
//
// Copyright (c) 2015, Vastech SA (PTY) LTD. All rights reserved.
// http://github.com/gogo/protobuf/gogoproto
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package vanity

import (
32
33
34
	"gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/gogoproto"
	"gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/proto"
	descriptor "gx/QmchriuyWMcqHha3dG86rQyxoswSUpmLUBjuJ2kotB65qR/gogo-protobuf/protoc-gen-gogo/descriptor"
Jeromy's avatar
Jeromy committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	"strings"
)

func NotInPackageGoogleProtobuf(file *descriptor.FileDescriptorProto) bool {
	return !strings.HasPrefix(file.GetPackage(), "google.protobuf")
}

func FilterFiles(files []*descriptor.FileDescriptorProto, f func(file *descriptor.FileDescriptorProto) bool) []*descriptor.FileDescriptorProto {
	filtered := make([]*descriptor.FileDescriptorProto, 0, len(files))
	for i := range files {
		if !f(files[i]) {
			continue
		}
		filtered = append(filtered, files[i])
	}
	return filtered
}

func FileHasBoolExtension(file *descriptor.FileDescriptorProto, extension *proto.ExtensionDesc) bool {
	if file.Options == nil {
		return false
	}
	value, err := proto.GetExtension(file.Options, extension)
	if err != nil {
		return false
	}
	if value == nil {
		return false
	}
	if value.(*bool) == nil {
		return false
	}
	return true
}

func SetBoolFileOption(extension *proto.ExtensionDesc, value bool) func(file *descriptor.FileDescriptorProto) {
	return func(file *descriptor.FileDescriptorProto) {
		if FileHasBoolExtension(file, extension) {
			return
		}
		if file.Options == nil {
			file.Options = &descriptor.FileOptions{}
		}
		if err := proto.SetExtension(file.Options, extension, &value); err != nil {
			panic(err)
		}
	}
}

func TurnOffGoGettersAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoGettersAll, false)(file)
}

func TurnOffGoEnumPrefixAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoEnumPrefixAll, false)(file)
}

func TurnOffGoStringerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoStringerAll, false)(file)
}

func TurnOnVerboseEqualAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_VerboseEqualAll, true)(file)
}

func TurnOnFaceAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_FaceAll, true)(file)
}

func TurnOnGoStringAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GostringAll, true)(file)
}

func TurnOnPopulateAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_PopulateAll, true)(file)
}

func TurnOnStringerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_StringerAll, true)(file)
}

func TurnOnEqualAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_EqualAll, true)(file)
}

func TurnOnDescriptionAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_DescriptionAll, true)(file)
}

func TurnOnTestGenAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_TestgenAll, true)(file)
}

func TurnOnBenchGenAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_BenchgenAll, true)(file)
}

func TurnOnMarshalerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_MarshalerAll, true)(file)
}

func TurnOnUnmarshalerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_UnmarshalerAll, true)(file)
}

func TurnOnSizerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_SizerAll, true)(file)
}

func TurnOffGoEnumStringerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoEnumStringerAll, false)(file)
}

func TurnOnEnumStringerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_EnumStringerAll, true)(file)
}

func TurnOnUnsafeUnmarshalerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_UnsafeUnmarshalerAll, true)(file)
}

func TurnOnUnsafeMarshalerAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_UnsafeMarshalerAll, true)(file)
}

func TurnOffGoExtensionsMapAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoExtensionsMapAll, false)(file)
}

func TurnOffGoUnrecognizedAll(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GoprotoUnrecognizedAll, false)(file)
}

func TurnOffGogoImport(file *descriptor.FileDescriptorProto) {
	SetBoolFileOption(gogoproto.E_GogoprotoImport, false)(file)
}