encoding/prototext: add MarshalOptions.EmitUnknown
This changes text marshaling to avoid unknown fields by default
and instead adds an option so that unknown fields be emitted.
This ensures that the default marshal/unknown can round-trip.
Change-Id: I85c84ba6ab7916d538ec6bfd4e9d399a8fcba14e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/195778
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/impl/api_export.go b/internal/impl/api_export.go
index 95e7846..6dcf85a 100644
--- a/internal/impl/api_export.go
+++ b/internal/impl/api_export.go
@@ -134,7 +134,10 @@
// MessageStringOf returns the message value as a string,
// which is the message serialized in the protobuf text format.
func (Export) MessageStringOf(m pref.ProtoMessage) string {
- b, _ := prototext.MarshalOptions{AllowPartial: true}.Marshal(m)
+ b, _ := prototext.MarshalOptions{
+ AllowPartial: true,
+ EmitUnknown: true,
+ }.Marshal(m)
return string(b)
}