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 | |
| 10 | protoV1 "github.com/golang/protobuf/proto" |
| 11 | pimpl "github.com/golang/protobuf/v2/internal/impl" |
| 12 | pvalue "github.com/golang/protobuf/v2/internal/value" |
| 13 | pref "github.com/golang/protobuf/v2/reflect/protoreflect" |
| 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 { |
| 21 | return legacyWrapEnum(reflect.ValueOf(e)).ProtoReflect().(pvalue.LegacyEnum) |
| 22 | } |
| 23 | |
| 24 | func (Export) EnumTypeOf(e interface{}) pref.EnumType { |
| 25 | return legacyLoadEnumType(reflect.TypeOf(e)) |
| 26 | } |
| 27 | |
| 28 | func (Export) MessageOf(m interface{}) pvalue.LegacyMessage { |
| 29 | return legacyWrapMessage(reflect.ValueOf(m)).ProtoReflect().(pvalue.LegacyMessage) |
| 30 | } |
| 31 | |
| 32 | func (Export) MessageTypeOf(m interface{}) pref.MessageType { |
| 33 | return legacyLoadMessageType(reflect.TypeOf(m)).Type |
| 34 | } |
| 35 | |
| 36 | func (Export) ExtensionTypeOf(d pref.ExtensionDescriptor, t interface{}) pref.ExtensionType { |
| 37 | return legacyExtensionTypeOf(d, reflect.TypeOf(t)) |
| 38 | } |
| 39 | |
| 40 | func (Export) ExtensionDescFromType(t pref.ExtensionType) *protoV1.ExtensionDesc { |
| 41 | return legacyExtensionDescFromType(t) |
| 42 | } |
| 43 | |
| 44 | func (Export) ExtensionTypeFromDesc(d *protoV1.ExtensionDesc) pref.ExtensionType { |
| 45 | return legacyExtensionTypeFromDesc(d) |
| 46 | } |
| 47 | |
| 48 | func init() { |
| 49 | pimpl.RegisterLegacyWrapper(Export{}) |
| 50 | } |