-
Notifications
You must be signed in to change notification settings - Fork 2
/
proto.go
50 lines (40 loc) · 1.07 KB
/
proto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package utils
import (
queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1"
"github.com/cosmos/cosmos-sdk/types/query"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/proto"
)
func GogoPageReqToPulsarPageReq(from *query.PageRequest) (*queryv1beta1.PageRequest, error) {
if from == nil {
return &queryv1beta1.PageRequest{Limit: query.DefaultLimit}, nil
}
to := &queryv1beta1.PageRequest{}
err := GogoToPulsarSlow(from, to)
return to, err
}
func PulsarPageResToGogoPageRes(from *queryv1beta1.PageResponse) (*query.PageResponse, error) {
if from == nil {
return nil, nil
}
to := &query.PageResponse{}
err := PulsarToGogoSlow(from, to)
return to, err
}
func PulsarToGogoSlow(from proto.Message, to gogoproto.Message) error {
if from == nil {
return nil
}
bz, err := proto.Marshal(from)
if err != nil {
return err
}
return gogoproto.Unmarshal(bz, to)
}
func GogoToPulsarSlow(from gogoproto.Message, to proto.Message) error {
bz, err := gogoproto.Marshal(from)
if err != nil {
return err
}
return proto.Unmarshal(bz, to)
}