internal/encoding/tag: support marshaling weak fields
We already support unmarshaling weak fields, support the other direction.
Change-Id: I514e6b7b18cf9a3567fb1775a1e389fe64f22d22
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185340
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/encoding/tag/tag.go b/internal/encoding/tag/tag.go
index 80e8488..948ca8b 100644
--- a/internal/encoding/tag/tag.go
+++ b/internal/encoding/tag/tag.go
@@ -170,7 +170,9 @@
if fd.IsPacked() {
tag = append(tag, "packed")
}
- // TODO: Weak fields?
+ if fd.IsWeak() {
+ tag = append(tag, "weak="+string(fd.Message().FullName()))
+ }
name := string(fd.Name())
if fd.Kind() == pref.GroupKind {
// The name of the FieldDescriptor for a group field is
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index bae3e17..f8c7e8c 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -1469,7 +1469,7 @@
}
type TestWeak struct {
- WeakMessage *weak.WeakImportMessage `protobuf:"bytes,1,opt,name=weak_message,json=weakMessage" json:"weak_message,omitempty"`
+ WeakMessage *weak.WeakImportMessage `protobuf:"bytes,1,opt,weak=goproto.proto.test.weak.WeakImportMessage,name=weak_message,json=weakMessage" json:"weak_message,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}