forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
57 lines (45 loc) · 1.69 KB
/
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
package codec
import (
"github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec/types"
)
type (
// Marshaler defines the interface module codecs must implement in order to support
// backwards compatibility with Amino while allowing custom Protobuf-based
// serialization. Note, Amino can still be used without any dependency on
// Protobuf. There are three typical implementations that fulfill this contract:
//
// 1. AminoCodec: Provides full Amino serialization compatibility.
// 2. ProtoCodec: Provides full Protobuf serialization compatibility.
Marshaler interface {
BinaryMarshaler
JSONMarshaler
}
BinaryMarshaler interface {
MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)
MustMarshalBinaryBare(o ProtoMarshaler) []byte
MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)
MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte
UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error
MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)
UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)
types.AnyUnpacker
}
JSONMarshaler interface {
MarshalJSON(o interface{}) ([]byte, error)
MustMarshalJSON(o interface{}) []byte
UnmarshalJSON(bz []byte, ptr interface{}) error
MustUnmarshalJSON(bz []byte, ptr interface{})
}
// ProtoMarshaler defines an interface a type must implement as protocol buffer
// defined message.
ProtoMarshaler interface {
proto.Message // for JSON serialization
Marshal() ([]byte, error)
MarshalTo(data []byte) (n int, err error)
MarshalToSizedBuffer(dAtA []byte) (int, error)
Size() int
Unmarshal(data []byte) error
}
)