tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/duplex/codec/codec.go (about)

     1  package codec
     2  
     3  import (
     4  	"io"
     5  )
     6  
     7  type Encoder interface {
     8  	// Encode writes an encoding of v to its Writer.
     9  	Encode(v interface{}) error
    10  }
    11  
    12  type Decoder interface {
    13  	// Decode reads the next encoded value from its Reader and stores it in the value pointed to by v.
    14  	Decode(v interface{}) error
    15  }
    16  
    17  // Codec returns an Encoder or Decoder given a Writer or Reader.
    18  type Codec interface {
    19  	Encoder(w io.Writer) Encoder
    20  	Decoder(r io.Reader) Decoder
    21  }