all: remove direct dependence on internal/legacy

Change-Id: Ic547a5edab4a1e7799c421b59ea78eca98534e96
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/171699
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-04-11 12:48:04 -07:00 committed by Joe Tsai
parent bc310b58c6
commit 5b9fa1f023
3 changed files with 6 additions and 46 deletions

View File

@ -21,9 +21,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
// This legacy package is still needed when importing legacy message.
_ "github.com/golang/protobuf/v2/internal/legacy"
"github.com/golang/protobuf/v2/encoding/testprotos/pb2"
"github.com/golang/protobuf/v2/encoding/testprotos/pb3"
knownpb "github.com/golang/protobuf/v2/types/known"

View File

@ -11,46 +11,15 @@ import (
protoV1 "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/v2/encoding/textpb"
"github.com/golang/protobuf/v2/internal/errors"
"github.com/golang/protobuf/v2/internal/legacy"
"github.com/golang/protobuf/v2/internal/scalar"
"github.com/golang/protobuf/v2/proto"
preg "github.com/golang/protobuf/v2/reflect/protoregistry"
"github.com/golang/protobuf/v2/runtime/protoiface"
"github.com/golang/protobuf/v2/encoding/testprotos/pb2"
"github.com/golang/protobuf/v2/encoding/testprotos/pb3"
knownpb "github.com/golang/protobuf/v2/types/known"
)
func init() {
// TODO: remove these registerExtension calls when generated code registers
// to V2 global registry.
registerExtension(pb2.E_OptExtBool)
registerExtension(pb2.E_OptExtString)
registerExtension(pb2.E_OptExtEnum)
registerExtension(pb2.E_OptExtNested)
registerExtension(pb2.E_RptExtFixed32)
registerExtension(pb2.E_RptExtEnum)
registerExtension(pb2.E_RptExtNested)
registerExtension(pb2.E_ExtensionsContainer_OptExtBool)
registerExtension(pb2.E_ExtensionsContainer_OptExtString)
registerExtension(pb2.E_ExtensionsContainer_OptExtEnum)
registerExtension(pb2.E_ExtensionsContainer_OptExtNested)
registerExtension(pb2.E_ExtensionsContainer_RptExtString)
registerExtension(pb2.E_ExtensionsContainer_RptExtEnum)
registerExtension(pb2.E_ExtensionsContainer_RptExtNested)
registerExtension(pb2.E_MessageSetExtension)
registerExtension(pb2.E_MessageSetExtension_MessageSetExtension)
registerExtension(pb2.E_MessageSetExtension_NotMessageSetExtension)
registerExtension(pb2.E_MessageSetExtension_ExtNested)
registerExtension(pb2.E_FakeMessageSetExtension_MessageSetExtension)
}
func registerExtension(xd *protoiface.ExtensionDescV1) {
xt := legacy.Export{}.ExtensionTypeFromDesc(xd)
preg.GlobalTypes.Register(xt)
}
func TestUnmarshal(t *testing.T) {
tests := []struct {
desc string

View File

@ -12,11 +12,9 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/golang/protobuf/v2/internal/legacy"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
preg "github.com/golang/protobuf/v2/reflect/protoregistry"
piface "github.com/golang/protobuf/v2/runtime/protoiface"
testpb "github.com/golang/protobuf/v2/reflect/protoregistry/testprotos"
)
@ -317,10 +315,6 @@ func TestFiles(t *testing.T) {
}
}
func extensionType(xd *piface.ExtensionDescV1) pref.ExtensionType {
return legacy.Export{}.ExtensionTypeFromDesc(xd)
}
func TestTypes(t *testing.T) {
// Suffix 1 in registry, 2 in parent, 3 in resolver.
mt1 := (&testpb.Message1{}).ProtoReflect().Type()
@ -330,12 +324,12 @@ func TestTypes(t *testing.T) {
et2 := testpb.Enum2_UNO.Type()
et3 := testpb.Enum3_YI.Type()
// Suffix indicates field number.
xt11 := extensionType(testpb.E_StringField)
xt12 := extensionType(testpb.E_EnumField)
xt13 := extensionType(testpb.E_MessageField)
xt21 := extensionType(testpb.E_Message4_MessageField)
xt22 := extensionType(testpb.E_Message4_EnumField)
xt23 := extensionType(testpb.E_Message4_StringField)
xt11 := testpb.E_StringField.Type
xt12 := testpb.E_EnumField.Type
xt13 := testpb.E_MessageField.Type
xt21 := testpb.E_Message4_MessageField.Type
xt22 := testpb.E_Message4_EnumField.Type
xt23 := testpb.E_Message4_StringField.Type
parent := &preg.Types{}
if err := parent.Register(mt2, et2, xt12, xt22); err != nil {
t.Fatalf("parent.Register() returns unexpected error: %v", err)