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>
This commit is contained in:
Joe Tsai 2019-07-09 13:35:31 -07:00
parent e5900a6a90
commit ace50e2b5e
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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
}