From ace50e2b5e566c138ca3016c139ca2534945cdd2 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Tue, 9 Jul 2019 13:35:31 -0700 Subject: [PATCH] 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 --- internal/encoding/tag/tag.go | 4 +++- internal/testprotos/test/test.pb.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/encoding/tag/tag.go b/internal/encoding/tag/tag.go index 80e8488b..948ca8b2 100644 --- a/internal/encoding/tag/tag.go +++ b/internal/encoding/tag/tag.go @@ -170,7 +170,9 @@ func Marshal(fd pref.FieldDescriptor, enumName string) string { 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 bae3e177..f8c7e8cd 100644 --- a/internal/testprotos/test/test.pb.go +++ b/internal/testprotos/test/test.pb.go @@ -1469,7 +1469,7 @@ func (x *TestRequiredGroupFields) GetRepeatedgroup() []*TestRequiredGroupFields_ } 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 }