Skip to content

Commit ae1d65b

Browse files
committed
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 <[email protected]>
1 parent 2da1b93 commit ae1d65b

File tree

6 files changed

+8
-12
lines changed

6 files changed

+8
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/golang/protobuf
22

33
go 1.9
44

5-
require google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece
5+
require google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ github.com/golang/protobuf v1.2.1-0.20190605195750-76c9e09470ba/go.mod h1:S1YIJX
77
github.com/golang/protobuf v1.2.1-0.20190617175902-f94016f5239f/go.mod h1:G+HpKX7pYZAVkElkAWZkr08MToW6pTp/vs+E9osFfbg=
88
github.com/golang/protobuf v1.2.1-0.20190620192300-1ee46dfd80dd/go.mod h1:+CMAsi9jpYf/wAltLUKlg++CWXqxCJyD8iLDbQONsJs=
99
github.com/golang/protobuf v1.2.1-0.20190806214225-7037721e6de0/go.mod h1:tDQPRlaHYu9yt1wPgdx85inRiLvUCuJZXsYjC0mwc1c=
10+
github.com/golang/protobuf v1.2.1-0.20190820204156-2da1b93405dd/go.mod h1:x87I3ou7ehf/yR6iQ88MkyDogdxXN04TELJ7HVy7V7I=
1011
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
1112
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
1213
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
2324
google.golang.org/protobuf v0.0.0-20190808204900-1799d1111a45/go.mod h1:tRqhEyKwbKqwt5CQZAuOtj09RfhLNklDOhndhYA9blU=
2425
google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece h1:AFYGmds8FWBGNw0zddlFiGtDvkVFSnQ7J2bAdH4X9Xk=
2526
google.golang.org/protobuf v0.0.0-20190820203659-c0f8c0a24ece/go.mod h1:tRqhEyKwbKqwt5CQZAuOtj09RfhLNklDOhndhYA9blU=
27+
google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207 h1:ulV4hvtdAg7XsymkxyxHtKYxQoSq88XU1bmtCELxG38=
28+
google.golang.org/protobuf v0.0.0-20190820213257-f1e905b04207/go.mod h1:UJqt2ZERO8/qk5A9t8Ujq6OJ+MNvOQpg9X4RKyYz9Ho=

internal/proto/registry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ func MessageName(m Message) messageName {
312312
//
313313
// Deprecated: Use protoregistry.GlobalTypes.Register instead.
314314
func RegisterExtension(d *ExtensionDesc) {
315-
xt := protoimpl.X.ExtensionTypeFromDesc(d)
316-
if err := protoregistry.GlobalTypes.Register(xt); err != nil {
315+
if err := protoregistry.GlobalTypes.Register(d); err != nil {
317316
panic(err)
318317
}
319318
}

proto/extensions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
289289

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

461461
var x Extension
462-
x.SetType(protoimpl.X.ExtensionTypeFromDesc(extension))
462+
x.SetType(extension)
463463
x.SetEagerValue(extensionAsStorageType(value))
464464
epb.Set(protoreflect.FieldNumber(extension.Field), x)
465465
return nil

proto/registry.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"log"
1010
"reflect"
1111
"strconv"
12-
13-
"google.golang.org/protobuf/runtime/protoimpl"
1412
)
1513

1614
var enumValueMaps = make(map[string]map[string]int32)
@@ -141,9 +139,6 @@ var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
141139

142140
// RegisterExtension is called from the generated code.
143141
func RegisterExtension(desc *ExtensionDesc) {
144-
if desc.Type == nil {
145-
desc.Type = protoimpl.X.ExtensionTypeFromDesc(desc)
146-
}
147142
if registerExtensionAlt != nil {
148143
registerExtensionAlt(desc) // populated by hooks_enabled.go
149144
return

proto/table_unmarshal.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"unicode/utf8"
1818

1919
"github.com/golang/protobuf/internal/wire"
20-
"google.golang.org/protobuf/runtime/protoimpl"
2120
)
2221

2322
// Unmarshal is the entry point from the generated .pb.go files.
@@ -276,7 +275,7 @@ func unmarshalExtensions(mi Message, unrecognized *[]byte) error {
276275

277276
// Store the value into the extension field.
278277
var x Extension
279-
x.SetType(protoimpl.X.ExtensionTypeFromDesc(extDesc))
278+
x.SetType(extDesc)
280279
x.SetEagerValue(extensionAsStorageType(fieldVal.Interface()))
281280
extFields.Set(fieldNum, x)
282281
}

0 commit comments

Comments
 (0)