amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package detectknown provides functionality for detecting well-known types |
| 6 | // and identifying them by name. |
| 7 | package detectknown |
| 8 | |
| 9 | import "google.golang.org/protobuf/reflect/protoreflect" |
| 10 | |
| 11 | type ProtoFile int |
| 12 | |
| 13 | const ( |
| 14 | Unknown ProtoFile = iota |
| 15 | AnyProto |
| 16 | TimestampProto |
| 17 | DurationProto |
| 18 | WrappersProto |
| 19 | StructProto |
| 20 | FieldMaskProto |
| 21 | EmptyProto |
| 22 | ) |
| 23 | |
| 24 | var wellKnownTypes = map[protoreflect.FullName]ProtoFile{ |
| 25 | "google.protobuf.Any": AnyProto, |
| 26 | "google.protobuf.Timestamp": TimestampProto, |
| 27 | "google.protobuf.Duration": DurationProto, |
| 28 | "google.protobuf.BoolValue": WrappersProto, |
| 29 | "google.protobuf.Int32Value": WrappersProto, |
| 30 | "google.protobuf.Int64Value": WrappersProto, |
| 31 | "google.protobuf.UInt32Value": WrappersProto, |
| 32 | "google.protobuf.UInt64Value": WrappersProto, |
| 33 | "google.protobuf.FloatValue": WrappersProto, |
| 34 | "google.protobuf.DoubleValue": WrappersProto, |
| 35 | "google.protobuf.BytesValue": WrappersProto, |
| 36 | "google.protobuf.StringValue": WrappersProto, |
| 37 | "google.protobuf.Struct": StructProto, |
| 38 | "google.protobuf.ListValue": StructProto, |
| 39 | "google.protobuf.Value": StructProto, |
| 40 | "google.protobuf.FieldMask": FieldMaskProto, |
| 41 | "google.protobuf.Empty": EmptyProto, |
| 42 | } |
| 43 | |
| 44 | // Which identifies the proto file that a well-known type belongs to. |
| 45 | func Which(s protoreflect.FullName) ProtoFile { |
| 46 | return wellKnownTypes[s] |
| 47 | } |