Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 1 | // Copyright 2018 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 legacy |
| 6 | |
| 7 | import ( |
| 8 | "reflect" |
| 9 | |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 10 | pimpl "google.golang.org/protobuf/internal/impl" |
| 11 | pvalue "google.golang.org/protobuf/internal/value" |
| 12 | pref "google.golang.org/protobuf/reflect/protoreflect" |
| 13 | piface "google.golang.org/protobuf/runtime/protoiface" |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 14 | ) |
| 15 | |
| 16 | // Export is a zero-length named type that exists only to export a set of |
| 17 | // functions that we do not want to appear in godoc. |
| 18 | type Export struct{} |
| 19 | |
| 20 | func (Export) EnumOf(e interface{}) pvalue.LegacyEnum { |
Damien Neil | a8593ba | 2019-01-08 16:18:07 -0800 | [diff] [blame] | 21 | return wrapEnum(reflect.ValueOf(e)).(pvalue.LegacyEnum) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | func (Export) EnumTypeOf(e interface{}) pref.EnumType { |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 25 | return loadEnumType(reflect.TypeOf(e)) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 26 | } |
| 27 | |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 28 | func (Export) EnumDescriptorOf(e interface{}) pref.EnumDescriptor { |
| 29 | return LoadEnumDesc(reflect.TypeOf(e)) |
| 30 | } |
| 31 | |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 32 | func (Export) MessageOf(m interface{}) pvalue.LegacyMessage { |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 33 | return wrapMessage(reflect.ValueOf(m)).ProtoReflect().(pvalue.LegacyMessage) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | func (Export) MessageTypeOf(m interface{}) pref.MessageType { |
Joe Tsai | 4fe9663 | 2019-05-22 05:12:36 -0400 | [diff] [blame^] | 37 | return loadMessageInfo(reflect.TypeOf(m)).PBType |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 40 | func (Export) MessageDescriptorOf(m interface{}) pref.MessageDescriptor { |
| 41 | return LoadMessageDesc(reflect.TypeOf(m)) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 44 | func (Export) ExtensionDescFromType(t pref.ExtensionType) *piface.ExtensionDescV1 { |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 45 | return extensionDescFromType(t) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 48 | func (Export) ExtensionTypeFromDesc(d *piface.ExtensionDescV1) pref.ExtensionType { |
Joe Tsai | 6dbffb7 | 2018-12-04 14:06:19 -0800 | [diff] [blame] | 49 | return extensionTypeFromDesc(d) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | func init() { |
| 53 | pimpl.RegisterLegacyWrapper(Export{}) |
| 54 | } |