Selaa lähdekoodia

internal/legacy, internal/encoding/tag: don't synthesize options

Stop adding options to legacy MessageDescriptors and FieldDescriptors.
We would synthesize options messages containing semantic options
(FieldOptions.is_packed, FieldOptions.is_weak, MessageOptions.map_entry).
This information is already contained in the protoreflect descriptors,
so there is no real need to define a correct options message.

If we do want to include options in legacy descriptors, then we should
get the original value out of the FileDescriptorProto, since it may
include additional extensions or other information.

This change completely removes the dependency from internal/legacy to
descriptor.proto.

Change-Id: Ib6bbe4ca6e0fe7ae501f3e9b11d5fa0222808410
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/171458
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Damien Neil 6 vuotta sitten
vanhempi
commit
fb8bd3a65a
2 muutettua tiedostoa jossa 3 lisäystä ja 11 poistoa
  1. 3 7
      internal/encoding/tag/tag.go
  2. 0 4
      internal/legacy/message.go

+ 3 - 7
internal/encoding/tag/tag.go

@@ -13,10 +13,7 @@ import (
 
 	defval "github.com/golang/protobuf/v2/internal/encoding/defval"
 	ptype "github.com/golang/protobuf/v2/internal/prototype"
-	scalar "github.com/golang/protobuf/v2/internal/scalar"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
-
-	descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
 )
 
 var byteType = reflect.TypeOf(byte(0))
@@ -31,8 +28,7 @@ var byteType = reflect.TypeOf(byte(0))
 //
 // This function is a best effort attempt; parsing errors are ignored.
 func Unmarshal(tag string, goType reflect.Type) ptype.Field {
-	opts := new(descriptorpb.FieldOptions)
-	f := ptype.Field{Options: opts}
+	f := ptype.Field{}
 	for len(tag) > 0 {
 		i := strings.IndexByte(tag, ',')
 		if i < 0 {
@@ -105,9 +101,9 @@ func Unmarshal(tag string, goType reflect.Type) ptype.Field {
 		case strings.HasPrefix(s, "json="):
 			f.JSONName = s[len("json="):]
 		case s == "packed":
-			opts.Packed = scalar.Bool(true)
+			f.IsPacked = ptype.True
 		case strings.HasPrefix(s, "weak="):
-			opts.Weak = scalar.Bool(true)
+			f.IsWeak = true
 			f.MessageType = ptype.PlaceholderMessage(pref.FullName(s[len("weak="):]))
 		case strings.HasPrefix(s, "def="):
 			// The default tag is special in that everything afterwards is the

+ 0 - 4
internal/legacy/message.go

@@ -14,10 +14,7 @@ import (
 	ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
 	pimpl "github.com/golang/protobuf/v2/internal/impl"
 	ptype "github.com/golang/protobuf/v2/internal/prototype"
-	scalar "github.com/golang/protobuf/v2/internal/scalar"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
-
-	descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
 )
 
 // wrapMessage wraps v as a protoreflect.ProtoMessage,
@@ -247,7 +244,6 @@ func (ms *messageDescSet) parseField(tag, tagKey, tagVal string, goType reflect.
 			m := &ptype.StandaloneMessage{
 				Syntax:     parent.Syntax,
 				FullName:   parent.FullName.Append(mapEntryName(f.Name)),
-				Options:    &descriptorpb.MessageOptions{MapEntry: scalar.Bool(true)},
 				IsMapEntry: true,
 				Fields: []ptype.Field{
 					ms.parseField(tagKey, "", "", t.Key(), nil),