Skip to content

Commit

Permalink
multi: Move each serializer into its own package (alecthomas#141)
Browse files Browse the repository at this point in the history
* baseline: Move to own pkg

* mus: Move to own pkg

* benc: Move to own pkg

* fastjson: Move to own pkg

* bebop_wellquite: Move to own pkg

* bebop200sc: Move to own pkg

* ssz: Move to own pkg

* shamaton: Move to own pkg

* ikea: Move to own pkg

* avro: Move to own pkg

* xdr_calmh: Move to own pkg

* gencode: Move to own pkg

* colfer: Move to own pkg

* gogo: Move to own pkg

* pulsar: Move to own pkg

* protobuf_dedis: Move to own pkg

* hprose: Move to own pkg

* capnproto: Move to own pkg

* flatbuffers: Move to own pkg

* binary: Move to own pkg

* sereal: Move to own pkg

* ugorji: Move to own pkg

* xdr_davecgh: Move to own pkg

* stdlib: Move to own pkg

* bson: Move to own pkg

* json: Move to own pkg

* msgpack_vmihailenco: Move to own pkg

* msgpack_tinylib: Move to own pkg

* gotiny: Move to own pkg

* fixup! colfer: Move to own pkg

* main: Remove unnecessary cruft
  • Loading branch information
matheusd authored Jun 9, 2024
1 parent dd04042 commit 1b2ac9c
Show file tree
Hide file tree
Showing 66 changed files with 278 additions and 473 deletions.
9 changes: 0 additions & 9 deletions adapter_interface.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package avro

import (
"bytes"
Expand Down Expand Up @@ -57,7 +57,7 @@ var avroSchemaJSON = `
}
`

func NewAvroA() Serializer {
func NewAvroA() goserbench.Serializer {
rec, err := goavro.NewRecord(goavro.RecordSchema(avroSchemaJSON))
if err != nil {
panic(err)
Expand Down Expand Up @@ -139,7 +139,7 @@ func avroUnmarshal(d []byte, o interface{}, unmarshalFunc func([]byte) (interfac
return nil
}

func NewAvro2Txt() Serializer {
func NewAvro2Txt() goserbench.Serializer {
codec, err := goavro2.NewCodec(avroSchemaJSON)
if err != nil {
panic(err)
Expand All @@ -159,7 +159,7 @@ func (a *Avro2Txt) String() string {
return "GoAvro2Text"
}

func NewAvro2Bin() Serializer {
func NewAvro2Bin() goserbench.Serializer {
codec, err := goavro2.NewCodec(avroSchemaJSON)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions baseline.go → internal/serializers/baseline/baseline.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package baseline

import (
"encoding/binary"
Expand Down Expand Up @@ -61,6 +61,6 @@ func (b *BaselineSerializer) Unmarshal(d []byte, o interface{}) error {
return nil
}

func NewBaselineSerializer() Serializer {
func NewBaselineSerializer() goserbench.Serializer {
return &BaselineSerializer{b: make([]byte, 47)}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package bebop200sc

import (
"time"
Expand Down Expand Up @@ -49,6 +49,6 @@ func (s *Bebop200ScSerializer) ForceUTC() bool {
return true
}

func NewBebop200ScSerializer() Serializer {
func NewBebop200ScSerializer() goserbench.Serializer {
return &Bebop200ScSerializer{buf: make([]byte, 1024)}
}
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package bebopwellquite

import (
"time"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (s *BebopWellquiteSerializer) TimePrecision() time.Duration {
return 100 * time.Nanosecond
}

func NewBebopWellquiteSerializer() Serializer {
func NewBebopWellquiteSerializer() goserbench.Serializer {
return &BebopWellquiteSerializer{
buf: make([]byte, 1024),
}
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions benc.go → internal/serializers/benc/benc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package benc

import (
"time"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (s BENCSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewBENCSerializer() Serializer {
func NewBENCSerializer() goserbench.Serializer {
return BENCSerializer{}
}

Expand Down Expand Up @@ -118,6 +118,6 @@ func (s BENCUnsafeSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewBENCUnsafeSerializer() Serializer {
func NewBENCUnsafeSerializer() goserbench.Serializer {
return BENCUnsafeSerializer{}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package goserbench
package binaryalecthomas

import "github.com/alecthomas/binary"
import (
"github.com/alecthomas/binary"
"github.com/alecthomas/go_serialization_benchmarks/goserbench"
)

type BinarySerializer struct{}

Expand All @@ -12,6 +15,6 @@ func (b BinarySerializer) Unmarshal(d []byte, o interface{}) error {
return binary.Unmarshal(d, o)
}

func NewBinarySerializer() Serializer {
func NewBinarySerializer() goserbench.Serializer {
return BinarySerializer{}
}
5 changes: 3 additions & 2 deletions bson.go → internal/serializers/bson/bson.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package goserbench
package bson

import (
"time"

"github.com/alecthomas/go_serialization_benchmarks/goserbench"
"gopkg.in/mgo.v2/bson"
)

Expand All @@ -20,6 +21,6 @@ func (m BsonSerializer) Unmarshal(d []byte, o interface{}) error {
return bson.Unmarshal(d, o)
}

func NewBsonSerializer() Serializer {
func NewBsonSerializer() goserbench.Serializer {
return BsonSerializer{}
}
4 changes: 2 additions & 2 deletions capnproto.go → internal/serializers/capnproto/capnproto.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package capnproto

import (
"bytes"
Expand Down Expand Up @@ -41,6 +41,6 @@ func (x CapNProtoSerializer) Unmarshal(d []byte, i interface{}) error {
return nil
}

func NewCapNProtoSerializer() Serializer {
func NewCapNProtoSerializer() goserbench.Serializer {
return CapNProtoSerializer{}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Go = import "/github.com/glycerine/go-capnproto/go.capnp";
$Go.package("goserbench");
$Go.import("github.com/alecthomas/go_serialization_benchmarks");
$Go.package("capnproto");
$Go.import("github.com/alecthomas/go_serialization_benchmarks/internal/capnproto");

@0x99ea7c74456111bd;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package capnproto

// AUTO GENERATED - DO NOT EDIT

Expand Down
4 changes: 2 additions & 2 deletions colfer.go → internal/serializers/colfer/colfer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package colfer

import "github.com/alecthomas/go_serialization_benchmarks/goserbench"

Expand Down Expand Up @@ -43,6 +43,6 @@ func (s *ColferSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewColferSerializer() Serializer {
func NewColferSerializer() goserbench.Serializer {
return &ColferSerializer{}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 2 additions & 2 deletions easyjson.go → internal/serializers/easyjson/easyjson.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package easyjson

import (
"github.com/alecthomas/go_serialization_benchmarks/goserbench"
Expand Down Expand Up @@ -38,6 +38,6 @@ func (m EasyJSONSerializer) Unmarshal(d []byte, o interface{}) error {
return nil
}

func NewEasyJSONSerializer() Serializer {
func NewEasyJSONSerializer() goserbench.Serializer {
return EasyJSONSerializer{}
}
5 changes: 4 additions & 1 deletion structdef.go → internal/serializers/easyjson/structdef.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package goserbench
package easyjson

import (
"time"
)

// This is a copy of the goserbench.SmallStruct because easyjson code generation
// adds methods to it.

//easyjson:json
type A struct {
Name string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fastjson.go → internal/serializers/fastjson/fastjson.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package fastjson

import (
"time"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (s *FastJSONSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return nil
}

func NewFastJSONSerializer() Serializer {
func NewFastJSONSerializer() goserbench.Serializer {
var arena fastjson.Arena
return &FastJSONSerializer{
object: arena.NewObject(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package flatbuffers

import (
"time"
Expand Down Expand Up @@ -44,6 +44,6 @@ func (s *FlatBufferSerializer) Unmarshal(d []byte, i interface{}) error {
return nil
}

func NewFlatBuffersSerializer() Serializer {
func NewFlatBuffersSerializer() goserbench.Serializer {
return &FlatBufferSerializer{flatbuffers.NewBuilder(0)}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package gencode

import (
"io"
Expand Down
6 changes: 3 additions & 3 deletions gencode.go → internal/serializers/gencode/gencode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package gencode

import (
"time"
Expand Down Expand Up @@ -40,7 +40,7 @@ func (s *GencodeSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewGencodeSerializer() Serializer {
func NewGencodeSerializer() goserbench.Serializer {
return &GencodeSerializer{buf: make([]byte, 0, 1024)}
}

Expand Down Expand Up @@ -78,6 +78,6 @@ func (s *GencodeUnsafeSerializer) Unmarshal(bs []byte, o interface{}) (err error
return
}

func NewGencodeUnsafeSerializer() Serializer {
func NewGencodeUnsafeSerializer() goserbench.Serializer {
return &GencodeUnsafeSerializer{buf: make([]byte, 0, 1024)}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package gencode

import (
"io"
Expand Down
6 changes: 3 additions & 3 deletions gogoprotobuf.go → internal/serializers/gogo/gogoprotobuf.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package gogo

import (
"bytes"
Expand Down Expand Up @@ -51,14 +51,14 @@ func (s *GogoProtoSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewGogoProtoSerializer() Serializer {
func NewGogoProtoSerializer() goserbench.Serializer {
return &GogoProtoSerializer{
marshaller: proto.Marshal,
unmarshaller: proto.Unmarshal,
}
}

func NewGogoJsonSerializer() Serializer {
func NewGogoJsonSerializer() goserbench.Serializer {
marshaller := &jsonpb.Marshaler{}
buf := bytes.NewBuffer(make([]byte, 0, 1024))

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto2";

package goserbench;

option go_package = "github.com/alecthomas/go_serialization_benchmarks;goserbench";
option go_package = "github.com/alecthomas/go_serialization_benchmarks/internal/gogo;gogo";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

Expand Down
7 changes: 4 additions & 3 deletions gotiny.go → internal/serializers/gotiny/gotiny.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package goserbench
package gotiny

import (
reflect "reflect"

"github.com/alecthomas/go_serialization_benchmarks/goserbench"
"github.com/cybriq/gotiny"
)

Expand All @@ -19,8 +20,8 @@ func (g GotinySerializer) Unmarshal(d []byte, o interface{}) error {
return nil
}

func NewGotinySerializer() Serializer {
ot := reflect.TypeOf(A{})
func NewGotinySerializer() goserbench.Serializer {
ot := reflect.TypeOf(goserbench.SmallStruct{})
return GotinySerializer{
dec: gotiny.NewDecoderWithType(ot),
}
Expand Down
4 changes: 2 additions & 2 deletions hprose.go → internal/serializers/hprose/hprose.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goserbench
package hprose

import (
"bytes"
Expand Down Expand Up @@ -54,7 +54,7 @@ func (s *HproseSerializer) Unmarshal(d []byte, i interface{}) (err error) {
return err
}

func NewHproseSerializer() Serializer {
func NewHproseSerializer() goserbench.Serializer {
buf := new(bytes.Buffer)
reader := hprose.NewReader(buf, true)
bufw := new(bytes.Buffer)
Expand Down
Loading

0 comments on commit 1b2ac9c

Please sign in to comment.