blob: 091c4233d1e95376bc7fdf42c4539f39e66c494d [file] [log] [blame]
Andrea Campanella3614a922021-02-25 12:40:42 +01001// 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.
7package detectknown
8
9import "google.golang.org/protobuf/reflect/protoreflect"
10
11type ProtoFile int
12
13const (
14 Unknown ProtoFile = iota
15 AnyProto
16 TimestampProto
17 DurationProto
18 WrappersProto
19 StructProto
20 FieldMaskProto
21 EmptyProto
22)
23
24var 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.
45func Which(s protoreflect.FullName) ProtoFile {
46 return wellKnownTypes[s]
47}