mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-02-22 21:40:42 +00:00
In order to generate descriptor.proto, the generated code would want to depend on the prototype package to construct the reflection data structures. However, this is a problem since descriptor itself is one of the dependencies for prototype. To break this dependency, we do the following: * Avoid using concrete *descriptorpb.XOptions messages in the public API, and instead just use protoreflect.ProtoMessage. We do lose some type safety here as a result. * Use protobuf reflection to interpret the Options message. * Split out NewFileFromDescriptorProto into a separate protodesc package since constructing protobuf reflection from the descriptor proto obviously depends on the descriptor protos themselves. As part of this CL, we check in a pre-generated version of descriptor and plugin that supports protobuf reflection natively and switchover all usages of those protos to the new definitions. These files were generated by protoc-gen-go from CL/150074, but hand-modified to remove dependencies on the v1 proto runtime. Change-Id: I81e03c42eeab480b03764e2fcbe1aae0e058fc57 Reviewed-on: https://go-review.googlesource.com/c/152020 Reviewed-by: Damien Neil <dneil@google.com>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package legacy
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
papi "github.com/golang/protobuf/protoapi"
|
|
pimpl "github.com/golang/protobuf/v2/internal/impl"
|
|
pvalue "github.com/golang/protobuf/v2/internal/value"
|
|
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
|
|
)
|
|
|
|
// Export is a zero-length named type that exists only to export a set of
|
|
// functions that we do not want to appear in godoc.
|
|
type Export struct{}
|
|
|
|
func (Export) EnumOf(e interface{}) pvalue.LegacyEnum {
|
|
return wrapEnum(reflect.ValueOf(e)).ProtoReflect().(pvalue.LegacyEnum)
|
|
}
|
|
|
|
func (Export) EnumTypeOf(e interface{}) pref.EnumType {
|
|
return loadEnumType(reflect.TypeOf(e))
|
|
}
|
|
|
|
func (Export) MessageOf(m interface{}) pvalue.LegacyMessage {
|
|
return wrapMessage(reflect.ValueOf(m)).ProtoReflect().(pvalue.LegacyMessage)
|
|
}
|
|
|
|
func (Export) MessageTypeOf(m interface{}) pref.MessageType {
|
|
return loadMessageType(reflect.TypeOf(m)).Type
|
|
}
|
|
|
|
func (Export) ExtensionTypeOf(d pref.ExtensionDescriptor, t interface{}) pref.ExtensionType {
|
|
return extensionTypeOf(d, reflect.TypeOf(t))
|
|
}
|
|
|
|
func (Export) ExtensionDescFromType(t pref.ExtensionType) *papi.ExtensionDesc {
|
|
return extensionDescFromType(t)
|
|
}
|
|
|
|
func (Export) ExtensionTypeFromDesc(d *papi.ExtensionDesc) pref.ExtensionType {
|
|
return extensionTypeFromDesc(d)
|
|
}
|
|
|
|
func init() {
|
|
pimpl.RegisterLegacyWrapper(Export{})
|
|
}
|