Skip to content

Commit 47f2674

Browse files
committed
Make unmarshal function associated
1 parent 06deb1e commit 47f2674

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

internal/api/lib.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313

1414
"golang.org/x/sys/unix"
1515

16-
"github.com/vmihailenco/msgpack/v5"
17-
1816
"github.com/CosmWasm/wasmvm/v2/types"
1917
)
2018

@@ -200,7 +198,7 @@ func GetPinnedMetrics(cache Cache) (*types.PinnedMetrics, error) {
200198
}
201199

202200
var pinnedMetrics types.PinnedMetrics
203-
if err := msgpack.Unmarshal(copyAndDestroyUnmanagedVector(metrics), &pinnedMetrics); err != nil {
201+
if err := pinnedMetrics.UnmarshalMessagePack(copyAndDestroyUnmanagedVector(metrics)); err != nil {
204202
return nil, err
205203
}
206204

types/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"fmt"
66
"strconv"
7+
8+
"github.com/vmihailenco/msgpack/v5"
79
)
810

911
// Uint64 is a wrapper for uint64, but it is marshalled to and from JSON as a string
@@ -198,6 +200,10 @@ type PinnedMetrics struct {
198200
PerModule PerModuleMetrics `json:"per_module"`
199201
}
200202

203+
func (pm *PinnedMetrics) UnmarshalMessagePack(data []byte) error {
204+
return msgpack.Unmarshal(data, pm)
205+
}
206+
201207
// Array is a wrapper around a slice that ensures that we get "[]" JSON for nil values.
202208
// When unmarshaling, we get an empty slice for "[]" and "null".
203209
//

0 commit comments

Comments
 (0)