|
|
@@ -6,9 +6,9 @@ package text
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
- "math/rand"
|
|
|
"strings"
|
|
|
|
|
|
+ "github.com/golang/protobuf/v2/internal/detrand"
|
|
|
"github.com/golang/protobuf/v2/internal/errors"
|
|
|
)
|
|
|
|
|
|
@@ -105,7 +105,6 @@ func (p *encoder) marshalMessage(v Value, emitDelims bool) error {
|
|
|
p.out = append(p.out, p.newline...)
|
|
|
}
|
|
|
}
|
|
|
- spaceAdded := false
|
|
|
for i, item := range items {
|
|
|
p.out = append(p.out, p.indents...)
|
|
|
if err := p.marshalKey(item[0]); !p.nerr.Merge(err) {
|
|
|
@@ -117,9 +116,8 @@ func (p *encoder) marshalMessage(v Value, emitDelims bool) error {
|
|
|
}
|
|
|
// For multi-line output, add a random extra space after key: per message to
|
|
|
// make output unstable.
|
|
|
- if !spaceAdded && len(p.indent) > 0 && rand.Intn(2) == 1 {
|
|
|
+ if len(p.indent) > 0 && detrand.Bool() {
|
|
|
p.out = append(p.out, ' ')
|
|
|
- spaceAdded = true
|
|
|
}
|
|
|
|
|
|
if err := p.marshalValue(item[1]); !p.nerr.Merge(err) {
|
|
|
@@ -130,9 +128,8 @@ func (p *encoder) marshalMessage(v Value, emitDelims bool) error {
|
|
|
}
|
|
|
// For single-line output, add a random extra space after a field per message to
|
|
|
// make output unstable.
|
|
|
- if !spaceAdded && len(p.indent) == 0 && i != len(items)-1 && rand.Intn(2) == 1 {
|
|
|
+ if len(p.indent) == 0 && detrand.Bool() && i != len(items)-1 {
|
|
|
p.out = append(p.out, ' ')
|
|
|
- spaceAdded = true
|
|
|
}
|
|
|
p.out = append(p.out, p.newline...)
|
|
|
}
|