func (e *basicEncoderImpl) encodeBytes(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetBytesValue(input.([]byte))
	return encoder
}
encodeBytes encode []byte to PrimitivePacketEncoder
package y3
import (
	"bytes"
	"fmt"
	"reflect"
	"github.com/yomorun/y3-codec-golang/internal/utils"
)
type basicEncoder interface {
	Encode(input interface{}, signals ...*signal) (buf []byte, err error)
}
type basicEncoderImpl struct {
	observe        byte
	root           byte
	forbidUserKey  func(key byte) bool
	allowSignalKey func(key byte) bool
}
type basicEncoderOption func(*basicEncoderImpl)
func basicEncoderOptionRoot(root byte) basicEncoderOption {
	return func(b *basicEncoderImpl) {
		b.root = root
	}
}
func basicEncoderOptionForbidUserKey(f func(key byte) bool) basicEncoderOption {
	return func(b *basicEncoderImpl) {
		b.forbidUserKey = f
	}
}
func basicEncoderOptionAllowSignalKey(f func(key byte) bool) basicEncoderOption {
	return func(b *basicEncoderImpl) {
		b.allowSignalKey = f
	}
}
func newBasicEncoder(observe byte, options ...func(*basicEncoderImpl)) basicEncoder {
	encoder := &basicEncoderImpl{observe: observe, root: utils.EmptyKey}
	for _, option := range options {
		option(encoder)
	}
	if encoder.forbidUserKey != nil && encoder.forbidUserKey(observe) {
		panic(fmt.Errorf("prohibit the use of this key: %#x", observe))
	}
	return encoder
}
func (e *basicEncoderImpl) Encode(input interface{}, signals ...*signal) (buf []byte, err error) {
	encoders := make([]*PrimitivePacketEncoder, 0)
	for _, signal := range signals {
		encoders = append(encoders, signal.ToEncoder(e.allowSignalKey))
	}
	return e.encodeBasic(input, encoders)
}
func (e *basicEncoderImpl) encodeBasic(input interface{}, signals []*PrimitivePacketEncoder) ([]byte, error) {
	if e.observe == 0 {
		panic(fmt.Errorf("observe cannot be 0"))
	}
	var primitiveEncoder *PrimitivePacketEncoder
	value := reflect.ValueOf(input)
	if value.Type() == utils.TypeOfByteSlice {
		primitiveEncoder = e.encodeBytes(input)
	} else {
		switch value.Kind() {
		case reflect.String:
			primitiveEncoder = e.encodeBasicString(input)
		case reflect.Int32:
			primitiveEncoder = e.encodeBasicInt32(input)
		case reflect.Uint32:
			primitiveEncoder = e.encodeBasicUint32(input)
		case reflect.Int64:
			primitiveEncoder = e.encodeBasicInt64(input)
		case reflect.Uint64:
			primitiveEncoder = e.encodeBasicUint64(input)
		case reflect.Float32:
			primitiveEncoder = e.encodeBasicFloat32(input)
		case reflect.Float64:
			primitiveEncoder = e.encodeBasicFloat64(input)
		case reflect.Bool:
			primitiveEncoder = e.encodeBasicBool(input)
		case reflect.Array, reflect.Slice:
			return e.encodeBasicSlice(value, signals)
		default:
			panic(fmt.Errorf("marshal error, no matching type: %v", value.Kind()))
		}
	}
	if primitiveEncoder == nil {
		panic("PrimitivePacketEncoder is nil")
	}
	if !utils.IsEmptyKey(e.root) {
		root := NewNodePacketEncoder(int(e.root))
		for _, signal := range signals {
			root.AddPrimitivePacket(signal)
		}
		root.AddPrimitivePacket(primitiveEncoder)
		return root.Encode(), nil
	}
	buf := make([][]byte, 0)
	for _, signal := range signals {
		buf = append(buf, signal.Encode())
	}
	buf = append(buf, primitiveEncoder.Encode())
	return bytes.Join(buf, []byte{}), nil
}
func (e *basicEncoderImpl) encodeBasicSlice(value reflect.Value, signals []*PrimitivePacketEncoder) ([]byte, error) {
	var nodeEncoder *NodePacketEncoder
	switch value.Type() {
	case utils.TyeOfStringSlice:
		nodeEncoder = e.encodeBasicStringSlice(value)
	case utils.TyeOfInt32Slice:
		nodeEncoder = e.encodeBasicInt32Slice(value)
	case utils.TyeOfUint32Slice:
		nodeEncoder = e.encodeBasicUint32Slice(value)
	case utils.TyeOfInt64Slice:
		nodeEncoder = e.encodeBasicInt64Slice(value)
	case utils.TyeOfUint64Slice:
		nodeEncoder = e.encodeBasicUint64Slice(value)
	case utils.TyeOfFloat32Slice:
		nodeEncoder = e.encodeBasicFloat32Slice(value)
	case utils.TyeOfFloat64Slice:
		nodeEncoder = e.encodeBasicFloat64Slice(value)
	case utils.TyeOfBoolSlice:
		nodeEncoder = e.encodeBasicBoolSlice(value)
	default:
		panic(fmt.Errorf("marshal error, no matching type in SliceTestData: %v", value.Index(0).Kind()))
	}
	if nodeEncoder == nil {
		panic("NodePacketEncoder is nil")
	}
	if !utils.IsEmptyKey(e.root) {
		root := NewNodePacketEncoder(int(e.root))
		for _, signal := range signals {
			root.AddPrimitivePacket(signal)
		}
		root.AddNodePacket(nodeEncoder)
		return root.Encode(), nil
	}
	buf := make([][]byte, 0)
	for _, signal := range signals {
		buf = append(buf, signal.Encode())
	}
	buf = append(buf, nodeEncoder.Encode())
	return bytes.Join(buf, []byte{}), nil
}
func (e *basicEncoderImpl) encodeBasicString(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetStringValue(fmt.Sprintf("%v", input))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicInt32(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetInt32Value(input.(int32))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicUint32(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetUInt32Value(input.(uint32))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicInt64(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetInt64Value(input.(int64))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicUint64(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetUInt64Value(input.(uint64))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicFloat32(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetFloat32Value(input.(float32))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicFloat64(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetFloat64Value(input.(float64))
	return encoder
}
func (e *basicEncoderImpl) encodeBasicBool(input interface{}) *PrimitivePacketEncoder {
	var encoder = NewPrimitivePacketEncoder(int(e.observe))
	encoder.SetBoolValue(input.(bool))
	return encoder
}