From 3d1dd875f376cf60305c17c9d09f069a873dcb94 Mon Sep 17 00:00:00 2001 From: Phil Pearl Date: Mon, 2 Dec 2019 13:28:04 +0000 Subject: [PATCH] Easyjson test should not interfere with json test Tests generated standard JSON marshaler/unmarshaler interfaces for easyjson. These will have been picked up by the encoding/json code and thrown off the result for encoding/json. Better for easyjson test to use its own specific (un)marshaling interfaces only, which easyjson claim are better than the standard ones --- Makefile | 2 +- serialization_benchmarks_test.go | 5 ++-- structdef_easyjson.go | 42 -------------------------------- 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index a7743f8..beaf9b7 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ msgp_gen.go: structdef.go go run github.com/tinylib/msgp -o msgp_gen.go -file structdef.go -io=false -tests=false structdef_easyjson.go: structdef.go - go run github.com/mailru/easyjson/easyjson -all structdef.go + go run github.com/mailru/easyjson/easyjson -no_std_marshalers -all structdef.go structdef-gogo.pb.go: structdef-gogo.proto protoc --gogofaster_out=. -I. -I${GOPATH}/src -I${GOPATH}/src/github.com/gogo/protobuf/protobuf structdef-gogo.proto diff --git a/serialization_benchmarks_test.go b/serialization_benchmarks_test.go index 6aa82cb..a2f6a7b 100644 --- a/serialization_benchmarks_test.go +++ b/serialization_benchmarks_test.go @@ -22,6 +22,7 @@ import ( hprose2 "github.com/hprose/hprose-golang/io" ikea "github.com/ikkerens/ikeapack" jsoniter "github.com/json-iterator/go" + easyjson "github.com/mailru/easyjson" "github.com/niubaoshu/gotiny" ssz "github.com/prysmaticlabs/go-ssz" shamaton "github.com/shamaton/msgpack" @@ -339,11 +340,11 @@ func BenchmarkJsonIterUnmarshal(b *testing.B) { type EasyJSONSerializer struct{} func (m EasyJSONSerializer) Marshal(o interface{}) ([]byte, error) { - return o.(*A).MarshalJSON() + return easyjson.Marshal(o.(easyjson.Marshaler)) } func (m EasyJSONSerializer) Unmarshal(d []byte, o interface{}) error { - return o.(*A).UnmarshalJSON(d) + return easyjson.Unmarshal(d, o.(*A)) } func BenchmarkEasyJsonMarshal(b *testing.B) { diff --git a/structdef_easyjson.go b/structdef_easyjson.go index 71a19ed..d1e8c28 100644 --- a/structdef_easyjson.go +++ b/structdef_easyjson.go @@ -105,25 +105,11 @@ func easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks(out *jwr out.RawByte('}') } -// MarshalJSON supports json.Marshaler interface -func (v NoTimeNoStringNoFloatA) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - // MarshalEasyJSON supports easyjson.Marshaler interface func (v NoTimeNoStringNoFloatA) MarshalEasyJSON(w *jwriter.Writer) { easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks(w, v) } -// UnmarshalJSON supports json.Unmarshaler interface -func (v *NoTimeNoStringNoFloatA) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks(&r, v) - return r.Error() -} - // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *NoTimeNoStringNoFloatA) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks(l, v) @@ -206,25 +192,11 @@ func easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks1(out *jw out.RawByte('}') } -// MarshalJSON supports json.Marshaler interface -func (v NoTimeA) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks1(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - // MarshalEasyJSON supports easyjson.Marshaler interface func (v NoTimeA) MarshalEasyJSON(w *jwriter.Writer) { easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks1(w, v) } -// UnmarshalJSON supports json.Unmarshaler interface -func (v *NoTimeA) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks1(&r, v) - return r.Error() -} - // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *NoTimeA) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks1(l, v) @@ -309,25 +281,11 @@ func easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks2(out *jw out.RawByte('}') } -// MarshalJSON supports json.Marshaler interface -func (v A) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks2(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - // MarshalEasyJSON supports easyjson.Marshaler interface func (v A) MarshalEasyJSON(w *jwriter.Writer) { easyjsonB0f55b16EncodeGithubComAlecthomasGoSerializationBenchmarks2(w, v) } -// UnmarshalJSON supports json.Unmarshaler interface -func (v *A) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks2(&r, v) - return r.Error() -} - // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *A) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjsonB0f55b16DecodeGithubComAlecthomasGoSerializationBenchmarks2(l, v)