blob: 054108afda52ee7f855933052076cde40ec82533 [file] [log] [blame]
Joe Tsai08e00302018-11-26 22:32:06 -08001// 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
5package legacy
6
7import (
8 "reflect"
9
Joe Tsai08e00302018-11-26 22:32:06 -080010 pimpl "github.com/golang/protobuf/v2/internal/impl"
11 pvalue "github.com/golang/protobuf/v2/internal/value"
12 pref "github.com/golang/protobuf/v2/reflect/protoreflect"
Joe Tsai4fddeba2019-03-20 18:29:32 -070013 piface "github.com/golang/protobuf/v2/runtime/protoiface"
Joe Tsai08e00302018-11-26 22:32:06 -080014)
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.
18type Export struct{}
19
20func (Export) EnumOf(e interface{}) pvalue.LegacyEnum {
Damien Neila8593ba2019-01-08 16:18:07 -080021 return wrapEnum(reflect.ValueOf(e)).(pvalue.LegacyEnum)
Joe Tsai08e00302018-11-26 22:32:06 -080022}
23
24func (Export) EnumTypeOf(e interface{}) pref.EnumType {
Joe Tsai6dbffb72018-12-04 14:06:19 -080025 return loadEnumType(reflect.TypeOf(e))
Joe Tsai08e00302018-11-26 22:32:06 -080026}
27
28func (Export) MessageOf(m interface{}) pvalue.LegacyMessage {
Joe Tsai6dbffb72018-12-04 14:06:19 -080029 return wrapMessage(reflect.ValueOf(m)).ProtoReflect().(pvalue.LegacyMessage)
Joe Tsai08e00302018-11-26 22:32:06 -080030}
31
32func (Export) MessageTypeOf(m interface{}) pref.MessageType {
Damien Neil8012b442019-01-18 09:32:24 -080033 return loadMessageType(reflect.TypeOf(m)).PBType
Joe Tsai08e00302018-11-26 22:32:06 -080034}
35
36func (Export) ExtensionTypeOf(d pref.ExtensionDescriptor, t interface{}) pref.ExtensionType {
Joe Tsai6dbffb72018-12-04 14:06:19 -080037 return extensionTypeOf(d, reflect.TypeOf(t))
Joe Tsai08e00302018-11-26 22:32:06 -080038}
39
Joe Tsai4fddeba2019-03-20 18:29:32 -070040func (Export) ExtensionDescFromType(t pref.ExtensionType) *piface.ExtensionDescV1 {
Joe Tsai6dbffb72018-12-04 14:06:19 -080041 return extensionDescFromType(t)
Joe Tsai08e00302018-11-26 22:32:06 -080042}
43
Joe Tsai4fddeba2019-03-20 18:29:32 -070044func (Export) ExtensionTypeFromDesc(d *piface.ExtensionDescV1) pref.ExtensionType {
Joe Tsai6dbffb72018-12-04 14:06:19 -080045 return extensionTypeFromDesc(d)
Joe Tsai08e00302018-11-26 22:32:06 -080046}
47
48func init() {
49 pimpl.RegisterLegacyWrapper(Export{})
50}