forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hybrid_codec.go
69 lines (53 loc) · 1.97 KB
/
hybrid_codec.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package codec
import "github.com/cosmos/cosmos-sdk/codec/types"
// HybridCodec defines a codec that utilizes Protobuf for binary encoding
// and Amino for JSON encoding.
type HybridCodec struct {
proto Marshaler
amino Marshaler
}
func NewHybridCodec(amino *Codec, unpacker types.AnyUnpacker) Marshaler {
return &HybridCodec{
proto: NewProtoCodec(unpacker),
amino: NewAminoCodec(amino),
}
}
func (hc *HybridCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) {
return hc.proto.MarshalBinaryBare(o)
}
func (hc *HybridCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte {
return hc.proto.MustMarshalBinaryBare(o)
}
func (hc *HybridCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) {
return hc.proto.MarshalBinaryLengthPrefixed(o)
}
func (hc *HybridCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte {
return hc.proto.MustMarshalBinaryLengthPrefixed(o)
}
func (hc *HybridCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error {
return hc.proto.UnmarshalBinaryBare(bz, ptr)
}
func (hc *HybridCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) {
hc.proto.MustUnmarshalBinaryBare(bz, ptr)
}
func (hc *HybridCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error {
return hc.proto.UnmarshalBinaryLengthPrefixed(bz, ptr)
}
func (hc *HybridCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) {
hc.proto.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
}
func (hc *HybridCodec) MarshalJSON(o interface{}) ([]byte, error) {
return hc.amino.MarshalJSON(o)
}
func (hc *HybridCodec) MustMarshalJSON(o interface{}) []byte {
return hc.amino.MustMarshalJSON(o)
}
func (hc *HybridCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
return hc.amino.UnmarshalJSON(bz, ptr)
}
func (hc *HybridCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) {
hc.amino.MustUnmarshalJSON(bz, ptr)
}
func (hc *HybridCodec) UnpackAny(any *types.Any, iface interface{}) error {
return hc.proto.UnpackAny(any, iface)
}