Explorar o código

proto: remove conversions between Extension{Desc,Type}

This is change 4/5 in a series of commits changing protoV1.ExtensionDesc
to directly implement protoreflect.ExtensionType.

1. [v2] Add protoimpl.ExtensionInfo as an alias for
   protoiface.ExtensionDescV1.

2. [v1] Update references to protoimpl.ExtensionInfo to use
   protoiface.ExtensionInfo.

3. [v2] Create protoimpl.ExtensionInfo (an alias to a new type in
   the impl package) and remove protoiface.ExtensionDescV1.

4. [v1] Remove unneeded explicit conversions between ExtensionDesc and
   ExtensionType (since the former now directly implements the latter).

5. [v2] Remove stub conversion functions.

Change-Id: I75368109db70d2f39b0e7595496b863dffc95f88
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189678
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Damien Neil %!s(int64=6) %!d(string=hai) anos
pai
achega
ae1d65bc54
Modificáronse 6 ficheiros con 8 adicións e 12 borrados
  1. 1 1
      go.mod
  2. 3 0
      go.sum
  3. 1 2
      internal/proto/registry.go
  4. 2 2
      proto/extensions.go
  5. 0 5
      proto/registry.go
  6. 1 2
      proto/table_unmarshal.go

+ 1 - 1
go.mod

@@ -2,4 +2,4 @@ module github.com/golang/protobuf
 
 go 1.9
 
-require google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece
+require google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207

+ 3 - 0
go.sum

@@ -7,6 +7,7 @@ github.com/golang/protobuf v1.2.1-0.20190605195750-76c9e09470ba/go.mod h1:S1YIJX
 github.com/golang/protobuf v1.2.1-0.20190617175902-f94016f5239f/go.mod h1:G+HpKX7pYZAVkElkAWZkr08MToW6pTp/vs+E9osFfbg=
 github.com/golang/protobuf v1.2.1-0.20190620192300-1ee46dfd80dd/go.mod h1:+CMAsi9jpYf/wAltLUKlg++CWXqxCJyD8iLDbQONsJs=
 github.com/golang/protobuf v1.2.1-0.20190806214225-7037721e6de0/go.mod h1:tDQPRlaHYu9yt1wPgdx85inRiLvUCuJZXsYjC0mwc1c=
+github.com/golang/protobuf v1.2.1-0.20190820204156-2da1b93405dd/go.mod h1:x87I3ou7ehf/yR6iQ88MkyDogdxXN04TELJ7HVy7V7I=
 github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 google.golang.org/protobuf v0.0.0-20190514172829-e89e6244e0e8/go.mod h1:791zQGC15vDqjpmPRn1uGPu5oHy/Jzw/Q1n5JsgIIcY=
@@ -23,3 +24,5 @@ google.golang.org/protobuf v0.0.0-20190808204900-1799d1111a45 h1:SZXAIsI6RiG0T8b
 google.golang.org/protobuf v0.0.0-20190808204900-1799d1111a45/go.mod h1:tRqhEyKwbKqwt5CQZAuOtj09RfhLNklDOhndhYA9blU=
 google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece h1:AFYGmds8FWBGNw0zddlFiGtDvkVFSnQ7J2bAdH4X9Xk=
 google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece/go.mod h1:tRqhEyKwbKqwt5CQZAuOtj09RfhLNklDOhndhYA9blU=
+google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207 h1:ulV4hvtdAg7XsymkxyxHtKYxQoSq88XU1bmtCELxG38=
+google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207/go.mod h1:UJqt2ZERO8/qk5A9t8Ujq6OJ+MNvOQpg9X4RKyYz9Ho=

+ 1 - 2
internal/proto/registry.go

@@ -312,8 +312,7 @@ func MessageName(m Message) messageName {
 //
 // Deprecated: Use protoregistry.GlobalTypes.Register instead.
 func RegisterExtension(d *ExtensionDesc) {
-	xt := protoimpl.X.ExtensionTypeFromDesc(d)
-	if err := protoregistry.GlobalTypes.Register(xt); err != nil {
+	if err := protoregistry.GlobalTypes.Register(d); err != nil {
 		panic(err)
 	}
 }

+ 2 - 2
proto/extensions.go

@@ -289,7 +289,7 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
 
 	// Remember the decoded version and drop the encoded version.
 	// That way it is safe to mutate what we return.
-	e.SetType(protoimpl.X.ExtensionTypeFromDesc(extension))
+	e.SetType(extension)
 	e.SetEagerValue(extensionAsStorageType(v))
 	unrecognized.SetBytes(removeRawFields(unrecognized.Bytes(), fnum))
 	epb.Set(protoreflect.FieldNumber(extension.Field), e)
@@ -459,7 +459,7 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
 	}
 
 	var x Extension
-	x.SetType(protoimpl.X.ExtensionTypeFromDesc(extension))
+	x.SetType(extension)
 	x.SetEagerValue(extensionAsStorageType(value))
 	epb.Set(protoreflect.FieldNumber(extension.Field), x)
 	return nil

+ 0 - 5
proto/registry.go

@@ -9,8 +9,6 @@ import (
 	"log"
 	"reflect"
 	"strconv"
-
-	"google.golang.org/protobuf/runtime/protoimpl"
 )
 
 var enumValueMaps = make(map[string]map[string]int32)
@@ -141,9 +139,6 @@ var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
 
 // RegisterExtension is called from the generated code.
 func RegisterExtension(desc *ExtensionDesc) {
-	if desc.Type == nil {
-		desc.Type = protoimpl.X.ExtensionTypeFromDesc(desc)
-	}
 	if registerExtensionAlt != nil {
 		registerExtensionAlt(desc) // populated by hooks_enabled.go
 		return

+ 1 - 2
proto/table_unmarshal.go

@@ -17,7 +17,6 @@ import (
 	"unicode/utf8"
 
 	"github.com/golang/protobuf/internal/wire"
-	"google.golang.org/protobuf/runtime/protoimpl"
 )
 
 // Unmarshal is the entry point from the generated .pb.go files.
@@ -276,7 +275,7 @@ func unmarshalExtensions(mi Message, unrecognized *[]byte) error {
 
 		// Store the value into the extension field.
 		var x Extension
-		x.SetType(protoimpl.X.ExtensionTypeFromDesc(extDesc))
+		x.SetType(extDesc)
 		x.SetEagerValue(extensionAsStorageType(fieldVal.Interface()))
 		extFields.Set(fieldNum, x)
 	}