Skip to content

Commit c2a26e7

Browse files
adggopherbot
authored andcommitted
encoding/{protojson,prototext}: strengthen wording on stability
Because these encoders use internal/detrand to make their output nondeterministic across builds, use stronger wording to warn users of their instability. Updates golang/protobuf#1121 Change-Id: Ia809e5c26ce24d17f602e7fbae26d9df2b57d05b Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/579895 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Lasse Folger <[email protected]> Reviewed-by: Lasse Folger <[email protected]> Reviewed-by: Michael Stapelberg <[email protected]>
1 parent d0f77ae commit c2a26e7

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

encoding/protojson/encode.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ const defaultIndent = " "
2525

2626
// Format formats the message as a multiline string.
2727
// This function is only intended for human consumption and ignores errors.
28-
// Do not depend on the output being stable. It may change over time across
29-
// different versions of the program.
28+
// Do not depend on the output being stable. Its output will change across
29+
// different builds of your program, even when using the same version of the
30+
// protobuf module.
3031
func Format(m proto.Message) string {
3132
return MarshalOptions{Multiline: true}.Format(m)
3233
}
3334

3435
// Marshal writes the given [proto.Message] in JSON format using default options.
35-
// Do not depend on the output being stable. It may change over time across
36-
// different versions of the program.
36+
// Do not depend on the output being stable. Its output will change across
37+
// different builds of your program, even when using the same version of the
38+
// protobuf module.
3739
func Marshal(m proto.Message) ([]byte, error) {
3840
return MarshalOptions{}.Marshal(m)
3941
}
@@ -110,8 +112,9 @@ type MarshalOptions struct {
110112

111113
// Format formats the message as a string.
112114
// This method is only intended for human consumption and ignores errors.
113-
// Do not depend on the output being stable. It may change over time across
114-
// different versions of the program.
115+
// Do not depend on the output being stable. Its output will change across
116+
// different builds of your program, even when using the same version of the
117+
// protobuf module.
115118
func (o MarshalOptions) Format(m proto.Message) string {
116119
if m == nil || !m.ProtoReflect().IsValid() {
117120
return "<nil>" // invalid syntax, but okay since this is for debugging
@@ -122,8 +125,9 @@ func (o MarshalOptions) Format(m proto.Message) string {
122125
}
123126

124127
// Marshal marshals the given [proto.Message] in the JSON format using options in
125-
// MarshalOptions. Do not depend on the output being stable. It may change over
126-
// time across different versions of the program.
128+
// Do not depend on the output being stable. Its output will change across
129+
// different builds of your program, even when using the same version of the
130+
// protobuf module.
127131
func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
128132
return o.marshal(nil, m)
129133
}

encoding/prototext/encode.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ const defaultIndent = " "
2727

2828
// Format formats the message as a multiline string.
2929
// This function is only intended for human consumption and ignores errors.
30-
// Do not depend on the output being stable. It may change over time across
31-
// different versions of the program.
30+
// Do not depend on the output being stable. Its output will change across
31+
// different builds of your program, even when using the same version of the
32+
// protobuf module.
3233
func Format(m proto.Message) string {
3334
return MarshalOptions{Multiline: true}.Format(m)
3435
}
3536

3637
// Marshal writes the given [proto.Message] in textproto format using default
37-
// options. Do not depend on the output being stable. It may change over time
38-
// across different versions of the program.
38+
// options. Do not depend on the output being stable. Its output will change
39+
// across different builds of your program, even when using the same version of
40+
// the protobuf module.
3941
func Marshal(m proto.Message) ([]byte, error) {
4042
return MarshalOptions{}.Marshal(m)
4143
}
@@ -84,8 +86,9 @@ type MarshalOptions struct {
8486

8587
// Format formats the message as a string.
8688
// This method is only intended for human consumption and ignores errors.
87-
// Do not depend on the output being stable. It may change over time across
88-
// different versions of the program.
89+
// Do not depend on the output being stable. Its output will change across
90+
// different builds of your program, even when using the same version of the
91+
// protobuf module.
8992
func (o MarshalOptions) Format(m proto.Message) string {
9093
if m == nil || !m.ProtoReflect().IsValid() {
9194
return "<nil>" // invalid syntax, but okay since this is for debugging
@@ -98,8 +101,9 @@ func (o MarshalOptions) Format(m proto.Message) string {
98101
}
99102

100103
// Marshal writes the given [proto.Message] in textproto format using options in
101-
// MarshalOptions object. Do not depend on the output being stable. It may
102-
// change over time across different versions of the program.
104+
// MarshalOptions object. Do not depend on the output being stable. Its output
105+
// will change across different builds of your program, even when using the
106+
// same version of the protobuf module.
103107
func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
104108
return o.marshal(nil, m)
105109
}

0 commit comments

Comments
 (0)