diff --git a/integration_test.go b/integration_test.go index f62e072d..7dd6b240 100644 --- a/integration_test.go +++ b/integration_test.go @@ -66,6 +66,7 @@ func Test(t *testing.T) { runGo("Build", workDir, "go", "build", "./...") runGo("TestNormal", workDir, "go", "test", "-race", "./...") runGo("TestPureGo", workDir, "go", "test", "-race", "-tags", "purego", "./...") + runGo("TestReflect", workDir, "go", "test", "-race", "-tags", "protoreflect", "./...") if v == golangLatest { runGo("TestProto1Legacy", workDir, "go", "test", "-race", "-tags", "proto1_legacy", "./...") runGo("TestProtocGenGo", "cmd/protoc-gen-go/testdata", "go", "test") diff --git a/proto/decode.go b/proto/decode.go index 11fed46b..3e00074d 100644 --- a/proto/decode.go +++ b/proto/decode.go @@ -25,10 +25,6 @@ type UnmarshalOptions struct { // If DiscardUnknown is set, unknown fields are ignored. DiscardUnknown bool - // Reflection forces use of the reflection-based decoder, even for - // messages which implement fast-path deserialization. - Reflection bool - pragma.NoUnkeyedLiterals } @@ -57,9 +53,6 @@ func (o UnmarshalOptions) Unmarshal(b []byte, m Message) error { } func (o UnmarshalOptions) unmarshalMessageFast(b []byte, m Message) error { - if o.Reflection { - return errInternalNoFast - } methods := protoMethods(m) if methods == nil || methods.Unmarshal == nil { return errInternalNoFast diff --git a/proto/encode.go b/proto/encode.go index fc3ce923..1626c3f3 100644 --- a/proto/encode.go +++ b/proto/encode.go @@ -47,10 +47,6 @@ type MarshalOptions struct { // detail and subject to change. Deterministic bool - // Reflection forces use of the reflection-based encoder, even for - // messages which implement fast-path serialization. - Reflection bool - pragma.NoUnkeyedLiterals } @@ -84,9 +80,6 @@ func (o MarshalOptions) MarshalAppend(b []byte, m Message) ([]byte, error) { } func (o MarshalOptions) marshalMessageFast(b []byte, m Message) ([]byte, error) { - if o.Reflection { - return nil, errInternalNoFast - } methods := protoMethods(m) if methods == nil || methods.MarshalAppend == nil || diff --git a/proto/proto.go b/proto/proto.go index 96dac1c8..da2a22c1 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -7,7 +7,6 @@ package proto import ( "github.com/golang/protobuf/v2/internal/errors" "github.com/golang/protobuf/v2/reflect/protoreflect" - "github.com/golang/protobuf/v2/runtime/protoiface" ) // Message is the top-level interface that all messages must implement. @@ -15,10 +14,3 @@ type Message = protoreflect.ProtoMessage // errInternalNoFast indicates that fast-path operations are not available for a message. var errInternalNoFast = errors.New("BUG: internal error (errInternalNoFast)") - -func protoMethods(m Message) *protoiface.Methods { - if x, ok := m.(protoiface.Methoder); ok { - return x.XXX_Methods() - } - return nil -} diff --git a/proto/proto_methods.go b/proto/proto_methods.go new file mode 100644 index 00000000..360a1ee1 --- /dev/null +++ b/proto/proto_methods.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The protoreflect build tag disables use of fast-path methods. +// +build !protoreflect + +package proto + +import "github.com/golang/protobuf/v2/runtime/protoiface" + +func protoMethods(m Message) *protoiface.Methods { + if x, ok := m.(protoiface.Methoder); ok { + return x.XXX_Methods() + } + return nil +} diff --git a/proto/proto_reflect.go b/proto/proto_reflect.go new file mode 100644 index 00000000..b282f3cf --- /dev/null +++ b/proto/proto_reflect.go @@ -0,0 +1,14 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The protoreflect build tag disables use of fast-path methods. +// +build protoreflect + +package proto + +import "github.com/golang/protobuf/v2/runtime/protoiface" + +func protoMethods(m Message) *protoiface.Methods { + return nil +} diff --git a/runtime/protoiface/methods.go b/runtime/protoiface/methods.go index dda5e491..e7d92db2 100644 --- a/runtime/protoiface/methods.go +++ b/runtime/protoiface/methods.go @@ -55,7 +55,6 @@ const ( type MarshalOptions struct { AllowPartial bool Deterministic bool - Reflection bool pragma.NoUnkeyedLiterals } @@ -66,7 +65,6 @@ type MarshalOptions struct { type UnmarshalOptions struct { AllowPartial bool DiscardUnknown bool - Reflection bool pragma.NoUnkeyedLiterals }