Skip to content

Commit 00caf84

Browse files
committed
proto: revert strict erroring of deterministic and custom marshalers
PR #650 added strict checking of the use of deterministic with custom marshalers since it is impossible to know whether a custom marshalers actually do produce deterministic output or not. However, this check is breaking hundreds of targets that already rely on determinism along with custom marshalers. In every case, the custom marshaler already produced deterministic output, so it did not really matter. If deterministic is specified *and* a custom marshaler is not actually deterministic, then the output is obviously not deterministic, and setting the flag was a lie. However, there is not much we can do with the current API. A redesign of the proto API will resolve this tension.
1 parent 93b26e6 commit 00caf84

File tree

2 files changed

+0
-24
lines changed

2 files changed

+0
-24
lines changed

proto/all_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,25 +2303,6 @@ func TestInvalidUTF8(t *testing.T) {
23032303
}
23042304
}
23052305

2306-
type CustomRawMessage []byte
2307-
2308-
func (m *CustomRawMessage) Marshal() ([]byte, error) {
2309-
return []byte(*m), nil
2310-
}
2311-
func (m *CustomRawMessage) Reset() { *m = nil }
2312-
func (m *CustomRawMessage) String() string { return fmt.Sprintf("%x", *m) }
2313-
func (m *CustomRawMessage) ProtoMessage() {}
2314-
2315-
func TestDeterministicErrorOnCustomMarshaler(t *testing.T) {
2316-
in := CustomRawMessage{1, 2, 3}
2317-
var b1 Buffer
2318-
b1.SetDeterministic(true)
2319-
err := b1.Marshal(&in)
2320-
if err == nil || !strings.Contains(err.Error(), "deterministic") {
2321-
t.Fatalf("Marshal error:\ngot %v\nwant deterministic not supported error", err)
2322-
}
2323-
}
2324-
23252306
// Benchmarks
23262307

23272308
func testMsg() *GoTest {

proto/table_marshal.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,11 +2715,6 @@ func Marshal(pb Message) ([]byte, error) {
27152715
// a Buffer for most applications.
27162716
func (p *Buffer) Marshal(pb Message) error {
27172717
var err error
2718-
if p.deterministic {
2719-
if _, ok := pb.(Marshaler); ok {
2720-
return fmt.Errorf("proto: deterministic not supported by the Marshal method of %T", pb)
2721-
}
2722-
}
27232718
if m, ok := pb.(newMarshaler); ok {
27242719
siz := m.XXX_Size()
27252720
p.grow(siz) // make sure buf has enough capacity

0 commit comments

Comments
 (0)