gitee.com/quant1x/gox@v1.21.2/encoding/binary/struc/custom.go (about)

     1  package struc
     2  
     3  import (
     4  	"io"
     5  	"reflect"
     6  )
     7  
     8  type Custom interface {
     9  	Pack(p []byte, opt *Options) (int, error)
    10  	Unpack(r io.Reader, length int, opt *Options) error
    11  	Size(opt *Options) int
    12  	String() string
    13  }
    14  
    15  type customFallback struct {
    16  	custom Custom
    17  }
    18  
    19  func (c customFallback) Pack(p []byte, val reflect.Value, opt *Options) (int, error) {
    20  	return c.custom.Pack(p, opt)
    21  }
    22  
    23  func (c customFallback) Unpack(r io.Reader, val reflect.Value, opt *Options) error {
    24  	return c.custom.Unpack(r, 1, opt)
    25  }
    26  
    27  func (c customFallback) Sizeof(val reflect.Value, opt *Options) int {
    28  	return c.custom.Size(opt)
    29  }
    30  
    31  func (c customFallback) String() string {
    32  	return c.custom.String()
    33  }