gitee.com/h79/goutils@v1.22.10/common/coder/coder.go (about)

     1  package coder
     2  
     3  import "io"
     4  
     5  type Decoder interface {
     6  	Decode(dest string) string
     7  }
     8  
     9  type DecodeFunc func(dest string) string
    10  
    11  func (f DecodeFunc) Decode(dest string) string {
    12  	return f(dest)
    13  }
    14  
    15  type Encoder interface {
    16  	Encode(src string) string
    17  }
    18  
    19  type EncoderFunc func(dest string) string
    20  
    21  func (f EncoderFunc) Encode(dest string) string {
    22  	return f(dest)
    23  }
    24  
    25  type DecoderReader interface {
    26  	Decode(data any, r io.Reader) error
    27  }
    28  
    29  type DecodeReaderFunc func(data any, r io.Reader) error
    30  
    31  func (f DecodeReaderFunc) Decode(data any, r io.Reader) error {
    32  	return f(data, r)
    33  }
    34  
    35  type EncoderWriter interface {
    36  	Encode(data any, r io.Writer) error
    37  }
    38  
    39  type EncoderWriterFunc func(data any, r io.Writer) error
    40  
    41  func (f EncoderWriterFunc) Encode(data any, r io.Writer) error {
    42  	return f(data, r)
    43  }
    44  
    45  type Unmarshal interface {
    46  	Unmarshal(content []byte, v interface{}) error
    47  }
    48  
    49  type UnmarshalFunc func(content []byte, v interface{}) error
    50  
    51  func (f UnmarshalFunc) Unmarshal(content []byte, v interface{}) error {
    52  	return f(content, v)
    53  }
    54  
    55  type Marshal interface {
    56  	Marshal(v interface{}) ([]byte, error)
    57  }
    58  type MarshalFunc func(v interface{}) ([]byte, error)
    59  
    60  func (f MarshalFunc) Marshal(v interface{}) ([]byte, error) {
    61  	return f(v)
    62  }
    63  
    64  type Coder interface {
    65  	Unmarshal
    66  	Marshal
    67  }