Skip to content

proto: revert strict erroring of deterministic and custom marshalers #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions proto/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2303,25 +2303,6 @@ func TestInvalidUTF8(t *testing.T) {
}
}

type CustomRawMessage []byte

func (m *CustomRawMessage) Marshal() ([]byte, error) {
return []byte(*m), nil
}
func (m *CustomRawMessage) Reset() { *m = nil }
func (m *CustomRawMessage) String() string { return fmt.Sprintf("%x", *m) }
func (m *CustomRawMessage) ProtoMessage() {}

func TestDeterministicErrorOnCustomMarshaler(t *testing.T) {
in := CustomRawMessage{1, 2, 3}
var b1 Buffer
b1.SetDeterministic(true)
err := b1.Marshal(&in)
if err == nil || !strings.Contains(err.Error(), "deterministic") {
t.Fatalf("Marshal error:\ngot %v\nwant deterministic not supported error", err)
}
}

// Benchmarks

func testMsg() *GoTest {
Expand Down
5 changes: 0 additions & 5 deletions proto/table_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2715,11 +2715,6 @@ func Marshal(pb Message) ([]byte, error) {
// a Buffer for most applications.
func (p *Buffer) Marshal(pb Message) error {
var err error
if p.deterministic {
if _, ok := pb.(Marshaler); ok {
return fmt.Errorf("proto: deterministic not supported by the Marshal method of %T", pb)
}
}
if m, ok := pb.(newMarshaler); ok {
siz := m.XXX_Size()
p.grow(siz) // make sure buf has enough capacity
Expand Down