github.com/koko1123/flow-go-1@v0.29.6/model/encoding/codec.go (about) 1 package encoding 2 3 import ( 4 "io" 5 ) 6 7 // Encodable is a type that defines a canonical encoding. 8 type Encodable interface { 9 Encode() []byte 10 } 11 12 // Marshaler marshals and unmarshals values to and from bytes. 13 type Marshaler interface { 14 // Marshaler marshals a value to bytes. 15 // 16 // This function returns an error if the value type is not supported by this marshaler. 17 Marshal(interface{}) ([]byte, error) 18 19 // Unmarshal unmarshals bytes to a value. 20 // 21 // This functions returns an error if the bytes do not fit the provided value type. 22 Unmarshal([]byte, interface{}) error 23 24 // MustMarshal marshals a value to bytes. 25 // 26 // This function panics if marshaling fails. 27 MustMarshal(interface{}) []byte 28 29 // MustUnmarshal unmarshals bytes to a value. 30 // 31 // This function panics if decoding fails. 32 MustUnmarshal([]byte, interface{}) 33 } 34 35 type Encoder interface { 36 Encode(interface{}) error 37 } 38 39 type Decoder interface { 40 Decode(interface{}) error 41 } 42 43 type Codec interface { 44 NewEncoder(w io.Writer) Encoder 45 NewDecoder(r io.Reader) Decoder 46 }