-
Notifications
You must be signed in to change notification settings - Fork 76
/
wkt.go
73 lines (64 loc) · 2.38 KB
/
wkt.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package pgs
// WellKnownTypePackage is the proto package name where all Well Known Types
// currently reside.
const WellKnownTypePackage Name = "google.protobuf"
// WellKnownType (WKT) encapsulates the Name of a Message from the
// `google.protobuf` package. Most official protoc plugins special case code
// generation on these messages.
type WellKnownType Name
// 1-to-1 mapping of the WKT names to WellKnownTypes.
const (
// UnknownWKT indicates that the type is not a known WKT. This value may be
// returned erroneously mapping a Name to a WellKnownType or if a WKT is
// added to the `google.protobuf` package but this library is outdated.
UnknownWKT WellKnownType = "Unknown"
AnyWKT WellKnownType = "Any"
DurationWKT WellKnownType = "Duration"
EmptyWKT WellKnownType = "Empty"
StructWKT WellKnownType = "Struct"
TimestampWKT WellKnownType = "Timestamp"
ValueWKT WellKnownType = "Value"
ListValueWKT WellKnownType = "ListValue"
DoubleValueWKT WellKnownType = "DoubleValue"
FloatValueWKT WellKnownType = "FloatValue"
Int64ValueWKT WellKnownType = "Int64Value"
UInt64ValueWKT WellKnownType = "UInt64Value"
Int32ValueWKT WellKnownType = "Int32Value"
UInt32ValueWKT WellKnownType = "UInt32Value"
BoolValueWKT WellKnownType = "BoolValue"
StringValueWKT WellKnownType = "StringValue"
BytesValueWKT WellKnownType = "BytesValue"
)
var wktLookup = map[Name]WellKnownType{
"Any": AnyWKT,
"Duration": DurationWKT,
"Empty": EmptyWKT,
"Struct": StructWKT,
"Timestamp": TimestampWKT,
"Value": ValueWKT,
"ListValue": ListValueWKT,
"DoubleValue": DoubleValueWKT,
"FloatValue": FloatValueWKT,
"Int64Value": Int64ValueWKT,
"UInt64Value": UInt64ValueWKT,
"Int32Value": Int32ValueWKT,
"UInt32Value": UInt32ValueWKT,
"BoolValue": BoolValueWKT,
"StringValue": StringValueWKT,
"BytesValue": BytesValueWKT,
}
// LookupWKT returns the WellKnownType related to the provided Name. If the
// name is not recognized, UnknownWKT is returned.
func LookupWKT(n Name) WellKnownType {
if wkt, ok := wktLookup[n]; ok {
return wkt
}
return UnknownWKT
}
// Name converts the WellKnownType to a Name. This is a convenience method.
func (wkt WellKnownType) Name() Name { return Name(wkt) }
// Valid returns true if the WellKnownType is recognized by this library.
func (wkt WellKnownType) Valid() bool {
_, ok := wktLookup[wkt.Name()]
return ok
}