Skip to content

Commit

Permalink
Use json no msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Jul 15, 2024
1 parent 50ed3a9 commit 41102a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/posener/h2conn v0.0.0-20231204025407-3997deeca0f0
github.com/stretchr/testify v1.9.0
github.com/vmihailenco/msgpack/v5 v5.4.1
golang.org/x/net v0.21.0
google.golang.org/protobuf v1.32.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ github.com/posener/h2conn v0.0.0-20231204025407-3997deeca0f0 h1:zZg03nifrj6ayWNa
github.com/posener/h2conn v0.0.0-20231204025407-3997deeca0f0/go.mod h1:bblJa8QcHntareAJYfLJUzLj42sUFBKCBeTDK5LyUrw=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
15 changes: 7 additions & 8 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/restatedev/sdk-go/internal"
"github.com/restatedev/sdk-go/internal/futures"
"github.com/restatedev/sdk-go/internal/rand"
"github.com/vmihailenco/msgpack/v5"
)

var (
Expand Down Expand Up @@ -244,7 +243,7 @@ func (r *ObjectRouter) Type() internal.ServiceType {
// GetAs helper function to get a key as specific type. Note that
// if there is no associated value with key, an error ErrKeyNotFound is
// returned
// it does encoding/decoding of bytes automatically using msgpack
// it does encoding/decoding of bytes automatically using json
func GetAs[T any](ctx ObjectContext, key string) (output T, err error) {
bytes, err := ctx.Get(key)
if err != nil {
Expand All @@ -256,15 +255,15 @@ func GetAs[T any](ctx ObjectContext, key string) (output T, err error) {
return output, ErrKeyNotFound
}

err = msgpack.Unmarshal(bytes, &output)
err = json.Unmarshal(bytes, &output)

return
}

// SetAs helper function to set a key value with a generic type T.
// it does encoding/decoding of bytes automatically using msgpack
// it does encoding/decoding of bytes automatically using json
func SetAs[T any](ctx ObjectContext, key string, value T) error {
bytes, err := msgpack.Marshal(value)
bytes, err := json.Marshal(value)
if err != nil {
return err
}
Expand All @@ -274,23 +273,23 @@ func SetAs[T any](ctx ObjectContext, key string, value T) error {
}

// RunAs helper function runs a run function with specific concrete type as a result
// it does encoding/decoding of bytes automatically using msgpack
// it does encoding/decoding of bytes automatically using json
func RunAs[T any](ctx Context, fn func(RunContext) (T, error)) (output T, err error) {
bytes, err := ctx.Run(func(ctx RunContext) ([]byte, error) {
out, err := fn(ctx)
if err != nil {
return nil, err
}

bytes, err := msgpack.Marshal(out)
bytes, err := json.Marshal(out)
return bytes, TerminalError(err)
})

if err != nil {
return output, err
}

err = msgpack.Unmarshal(bytes, &output)
err = json.Unmarshal(bytes, &output)

return output, TerminalError(err)
}
Expand Down

0 comments on commit 41102a4

Please sign in to comment.