diff --git a/encoding/textpb/encode.go b/encoding/textpb/encode.go index 77606dad..54f4f545 100644 --- a/encoding/textpb/encode.go +++ b/encoding/textpb/encode.go @@ -127,6 +127,11 @@ func (o MarshalOptions) marshalMessage(m pref.Message) (text.Value, error) { func (o MarshalOptions) appendField(msgFields [][2]text.Value, tname text.Value, pval pref.Value, fd pref.FieldDescriptor) ([][2]text.Value, error) { var nerr errors.NonFatal + // Use type name for group field name. + if fd.Kind() == pref.GroupKind { + tname = text.ValueOf(fd.MessageType().Name()) + } + if fd.Cardinality() == pref.Repeated { // Map or repeated fields. var items []text.Value @@ -153,10 +158,6 @@ func (o MarshalOptions) appendField(msgFields [][2]text.Value, tname text.Value, if !nerr.Merge(err) { return msgFields, err } - // Use type name for group field name. - if fd.Kind() == pref.GroupKind { - tname = text.ValueOf(fd.MessageType().Name()) - } msgFields = append(msgFields, [2]text.Value{tname, tval}) } diff --git a/encoding/textpb/encode_test.go b/encoding/textpb/encode_test.go index 15a54928..fe4271d8 100644 --- a/encoding/textpb/encode_test.go +++ b/encoding/textpb/encode_test.go @@ -537,11 +537,11 @@ rpt_nested: {} {}, }, }, - want: `rptgroup: { + want: `RptGroup: { rpt_bool: true rpt_bool: false } -rptgroup: {} +RptGroup: {} `, }, { desc: "map fields empty",