Skip to content

Commit

Permalink
Update mus to v0.3.0 (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymz-ncnk authored Jul 6, 2024
1 parent a57448d commit 64af440
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 353 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/minio/sha256-simd v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mus-format/mus-go v0.2.3
github.com/mus-format/mus-go v0.3.0
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/protolambda/zssz v0.1.1 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/calmh/xdr v1.1.0 h1:U/Dd4CXNLoo8EiQ4ulJUXkgO1/EyQLgDKLgpY1SOoJE=
github.com/calmh/xdr v1.1.0/go.mod h1:E8sz2ByAdXC8MbANf1LCRYzedSnnc+/sXXJs/PVqoeg=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f h1:fxT+cPh0H+xo8ojX5O1zt/o/vTf7oeKdpk7r7asg2fs=
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd h1:ImEBzQdUJ6jx65nsFrBlNNV8um9lW4ApGEa+mIjXOZQ=
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down Expand Up @@ -200,8 +198,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mus-format/common-go v0.0.0-20240427160332-fda7f59c1da2 h1:VlQlK11OtURHQ1VsdHcp9OFq56i8HEIHURgfEtP9Jek=
github.com/mus-format/common-go v0.0.0-20240427160332-fda7f59c1da2/go.mod h1:1hTb8w0YdSGIOU6wNY+e9uXnDZ9OQnUivNtd8cPSdoU=
github.com/mus-format/mus-go v0.2.3 h1:HZ4NqdThMV2js9/goQueFqxAHaMBZDGBPwOwFv5f3LA=
github.com/mus-format/mus-go v0.2.3/go.mod h1:uRQAo0t2WbvKZ9Iz5wdZV4s5eq1LsTS9dSizQeV9s+M=
github.com/mus-format/mus-go v0.3.0 h1:OUBb/uWaaVPVpmyOo+DUVdjw5dkxQ1TCG3HO8q/Gyq8=
github.com/mus-format/mus-go v0.3.0/go.mod h1:uRQAo0t2WbvKZ9Iz5wdZV4s5eq1LsTS9dSizQeV9s+M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b h1:Roh7HBLqAxLpo/qxWztQlzt6QUBGTCX9AXxCaJf+pB8=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b/go.mod h1:F54tpGg4uMgsYNUqD07iNENNGcS2GJobr+td/iZ5Xm4=
Expand Down
43 changes: 21 additions & 22 deletions internal/serializers/mus/mus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,63 @@ import (
"github.com/mus-format/mus-go/ord"
"github.com/mus-format/mus-go/raw"
"github.com/mus-format/mus-go/unsafe"
"github.com/mus-format/mus-go/varint"
)

type MUSSerializer struct{}

func (s MUSSerializer) Marshal(o interface{}) ([]byte, error) {
v := o.(*goserbench.SmallStruct)
n := ord.SizeString(v.Name)
n += raw.SizeInt64(v.BirthDay.UnixNano())
n += ord.SizeString(v.Phone)
n += varint.SizeInt32(int32(v.Siblings))
n += ord.SizeBool(v.Spouse)
n += raw.SizeFloat64(v.Money)
n := ord.SizeString(v.Name, nil)
n += unsafe.SizeInt64(v.BirthDay.UnixNano())
n += ord.SizeString(v.Phone, nil)
n += unsafe.SizeInt32(int32(v.Siblings))
n += unsafe.SizeBool(v.Spouse)
n += unsafe.SizeFloat64(v.Money)
buf := make([]byte, n)
n = ord.MarshalString(v.Name, buf)
n += raw.MarshalInt64(v.BirthDay.UnixNano(), buf[n:])
n += ord.MarshalString(v.Phone, buf[n:])
n += varint.MarshalInt32(int32(v.Siblings), buf[n:])
n += ord.MarshalBool(v.Spouse, buf[n:])
n = ord.MarshalString(v.Name, nil, buf)
n += unsafe.MarshalInt64(v.BirthDay.UnixNano(), buf[n:])
n += ord.MarshalString(v.Phone, nil, buf[n:])
n += unsafe.MarshalInt32(int32(v.Siblings), buf[n:])
n += unsafe.MarshalBool(v.Spouse, buf[n:])
raw.MarshalFloat64(v.Money, buf[n:])
return buf, nil
}

func (s MUSSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)
var n int
v.Name, n, err = ord.UnmarshalString(bs)
v.Name, n, err = ord.UnmarshalString(nil, bs)
if err != nil {
return
}
var (
n1 int
birthDay64 int64
)
birthDay64, n1, err = raw.UnmarshalInt64(bs[n:])
birthDay64, n1, err = unsafe.UnmarshalInt64(bs[n:])
n += n1
if err != nil {
return
}
v.BirthDay = time.Unix(0, birthDay64)
v.Phone, n1, err = ord.UnmarshalString(bs[n:])
v.Phone, n1, err = ord.UnmarshalString(nil, bs[n:])
n += n1
if err != nil {
return
}
var siblings32 int32
siblings32, n1, err = varint.UnmarshalInt32(bs[n:])
siblings32, n1, err = unsafe.UnmarshalInt32(bs[n:])
n += n1
if err != nil {
return
}
v.Siblings = int(siblings32)
v.Spouse, n1, err = ord.UnmarshalBool(bs[n:])
v.Spouse, n1, err = unsafe.UnmarshalBool(bs[n:])
n += n1
if err != nil {
return
}
v.Money, n1, err = raw.UnmarshalFloat64(bs[n:])
v.Money, n1, err = unsafe.UnmarshalFloat64(bs[n:])
n += n1
return
}
Expand All @@ -79,9 +78,9 @@ type MUSUnsafeReuseSerializer struct {

func (s MUSUnsafeReuseSerializer) Marshal(o interface{}) ([]byte, error) {
v := o.(*goserbench.SmallStruct)
n := unsafe.MarshalString(v.Name, s.buf)
n := unsafe.MarshalString(v.Name, nil, s.buf)
n += unsafe.MarshalInt64(v.BirthDay.UnixNano(), s.buf[n:])
n += unsafe.MarshalString(v.Phone, s.buf[n:])
n += unsafe.MarshalString(v.Phone, nil, s.buf[n:])
n += unsafe.MarshalInt32(int32(v.Siblings), s.buf[n:])
n += unsafe.MarshalBool(v.Spouse, s.buf[n:])
n += unsafe.MarshalFloat64(v.Money, s.buf[n:])
Expand All @@ -91,7 +90,7 @@ func (s MUSUnsafeReuseSerializer) Marshal(o interface{}) ([]byte, error) {
func (s MUSUnsafeReuseSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)
var n int
v.Name, n, err = unsafe.UnmarshalString(bs)
v.Name, n, err = unsafe.UnmarshalString(nil, bs)
if err != nil {
return
}
Expand All @@ -105,7 +104,7 @@ func (s MUSUnsafeReuseSerializer) Unmarshal(bs []byte, o interface{}) (err error
return
}
v.BirthDay = time.Unix(0, birthDay64)
v.Phone, n1, err = unsafe.UnmarshalString(bs[n:])
v.Phone, n1, err = unsafe.UnmarshalString(nil, bs[n:])
n += n1
if err != nil {
return
Expand Down
Loading

0 comments on commit 64af440

Please sign in to comment.