@@ -20,6 +20,7 @@ import (
20
20
"github.com/gogo/protobuf/proto"
21
21
flatbuffers "github.com/google/flatbuffers/go"
22
22
"github.com/hprose/hprose-go"
23
+ hprose2 "github.com/hprose/hprose-golang/io"
23
24
jsoniter "github.com/json-iterator/go"
24
25
"github.com/ikkerens/ikeapack"
25
26
"github.com/tinylib/msgp/msgp"
@@ -667,6 +668,54 @@ func BenchmarkHproseUnmarshal(b *testing.B) {
667
668
benchUnmarshal (b , & HproseSerializer {writer : writer , reader : reader })
668
669
}
669
670
671
+ // github.com/hprose/hprose-golang/io
672
+
673
+ type Hprose2Serializer struct {
674
+ writer * hprose2.Writer
675
+ reader * hprose2.Reader
676
+ }
677
+
678
+ func (s Hprose2Serializer ) Marshal (o interface {}) []byte {
679
+ a := o .(* A )
680
+ writer := s .writer
681
+ writer .Clear ()
682
+ writer .WriteString (a .Name )
683
+ writer .WriteTime (& a .BirthDay )
684
+ writer .WriteString (a .Phone )
685
+ writer .WriteInt (int64 (a .Siblings ))
686
+ writer .WriteBool (a .Spouse )
687
+ writer .WriteFloat (a .Money , 64 )
688
+ return writer .Bytes ()
689
+ }
690
+
691
+ func (s Hprose2Serializer ) Unmarshal (d []byte , i interface {}) error {
692
+ o := i .(* A )
693
+ reader := s .reader
694
+ reader .Init (d )
695
+ o .Name = reader .ReadString ()
696
+ o .BirthDay = reader .ReadTime ()
697
+ o .Phone = reader .ReadString ()
698
+ o .Siblings = int (reader .ReadInt ())
699
+ o .Spouse = reader .ReadBool ()
700
+ o .Money = reader .ReadFloat64 ()
701
+ return nil
702
+ }
703
+
704
+ func (s Hprose2Serializer ) String () string {
705
+ return "Hprose2"
706
+ }
707
+
708
+ func BenchmarkHprose2Marshal (b * testing.B ) {
709
+ writer := hprose2 .NewWriter (true )
710
+ benchMarshal (b , Hprose2Serializer {writer : writer })
711
+ }
712
+
713
+ func BenchmarkHprose2Unmarshal (b * testing.B ) {
714
+ writer := hprose2 .NewWriter (true )
715
+ reader := hprose2 .NewReader (nil , true )
716
+ benchUnmarshal (b , & Hprose2Serializer {writer : writer , reader : reader })
717
+ }
718
+
670
719
// github.com/DeDiS/protobuf
671
720
672
721
type ProtobufSerializer struct {}
0 commit comments