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 impl |
| 6 | |
Joe Tsai | b2f66be | 2019-05-22 00:42:45 -0400 | [diff] [blame^] | 7 | import ( |
| 8 | "reflect" |
| 9 | |
| 10 | pvalue "google.golang.org/protobuf/internal/value" |
| 11 | pref "google.golang.org/protobuf/reflect/protoreflect" |
| 12 | piface "google.golang.org/protobuf/runtime/protoiface" |
| 13 | ) |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 14 | |
| 15 | // TODO: Add a default LegacyWrapper that panics with a more helpful message? |
Joe Tsai | b2f66be | 2019-05-22 00:42:45 -0400 | [diff] [blame^] | 16 | var legacyWrapper LegacyWrapper |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 17 | |
| 18 | // RegisterLegacyWrapper registers a set of constructor functions that are |
| 19 | // called when a legacy enum or message is encountered that does not natively |
| 20 | // support the protobuf reflection APIs. |
Joe Tsai | b2f66be | 2019-05-22 00:42:45 -0400 | [diff] [blame^] | 21 | func RegisterLegacyWrapper(w LegacyWrapper) { |
Joe Tsai | 08e0030 | 2018-11-26 22:32:06 -0800 | [diff] [blame] | 22 | legacyWrapper = w |
| 23 | } |
Joe Tsai | b2f66be | 2019-05-22 00:42:45 -0400 | [diff] [blame^] | 24 | |
| 25 | // LegacyWrapper is a set of wrapper methods that wraps legacy v1 Go types |
| 26 | // to implement the v2 reflection APIs. |
| 27 | type LegacyWrapper interface { |
| 28 | NewConverter(reflect.Type, pref.Kind) pvalue.Converter |
| 29 | |
| 30 | EnumOf(interface{}) pref.Enum |
| 31 | EnumTypeOf(interface{}) pref.EnumType |
| 32 | EnumDescriptorOf(interface{}) pref.EnumDescriptor |
| 33 | |
| 34 | MessageOf(interface{}) pref.Message |
| 35 | MessageTypeOf(interface{}) pref.MessageType |
| 36 | MessageDescriptorOf(interface{}) pref.MessageDescriptor |
| 37 | |
| 38 | // TODO: Remove these eventually. |
| 39 | // See the TODOs in internal/impl/legacy_extension.go. |
| 40 | ExtensionDescFromType(pref.ExtensionType) *piface.ExtensionDescV1 |
| 41 | ExtensionTypeFromDesc(*piface.ExtensionDescV1) pref.ExtensionType |
| 42 | } |