func analyzeAlphaNum(byt byte) bool {
	if (byt >= '0' && byt <= '9') || (byt >= 'A' && byt <= 'Z') {
		return true
	}
	switch byt {
	case ' ', '$', '%', '*', '+', '-', '.', '/', ':':
		return true
	}
	return false
}
analyzeAlphaNum is byt in alpha number
package qrcode
import (
	"fmt"
	"log"
	"github.com/yeqown/reedsolomon/binary"
)
type encMode uint
const (
	EncModeAuto = 0
	EncModeNone encMode = 1 << iota
	EncModeNumeric
	EncModeAlphanumeric
	EncModeByte
	EncModeJP
)
var (
	paddingByte1, _ = binary.NewFromBinaryString("11101100")
	paddingByte2, _ = binary.NewFromBinaryString("00010001")
)
func getEncModeName(mode encMode) string {
	switch mode {
	case EncModeNone:
		return "none"
	case EncModeNumeric:
		return "numeric"
	case EncModeAlphanumeric:
		return "alphanumeric"
	case EncModeByte:
		return "byte"
	case EncModeJP:
		return "japan"
	default:
		return "unknown"
	}
}
func getEncodeModeIndicator(mode encMode) *binary.Binary {
	switch mode {
	case EncModeNumeric:
		return binary.New(false, false, false, true)
	case EncModeAlphanumeric:
		return binary.New(false, false, true, false)
	case EncModeByte:
		return binary.New(false, true, false, false)
	case EncModeJP:
		return binary.New(true, false, false, false)
	default:
		panic("no indicator")
	}
}
type encoder struct {
	dst  *binary.Binary
	data []byte  
	mode encMode  
	ecLv ecLevel  
	version version  
}
func (e *encoder) Encode(byts []byte) (*binary.Binary, error) {
	e.dst = binary.New()
	e.data = byts
	indicator := getEncodeModeIndicator(e.mode)
	e.dst.Append(indicator)
	e.dst.AppendUint32(uint32(len(byts)), e.charCountBits())
	switch e.mode {
	case EncModeNumeric:
		e.encodeNumeric()
	case EncModeAlphanumeric:
		e.encodeAlphanumeric()
	case EncModeByte:
		e.encodeByte()
	case EncModeJP:
		panic("this has not been finished")
	}
	e.breakUpInto8bit()
	return e.dst, nil
}
func (e *encoder) encodeNumeric() {
	if e.dst == nil {
		log.Println("e.dst is nil")
		return
	}
	for i := 0; i < len(e.data); i += 3 {
		charsRemaining := len(e.data) - i
		var value uint32
		bitsUsed := 1
		for j := 0; j < charsRemaining && j < 3; j++ {
			value *= 10
			value += uint32(e.data[i+j] - 0x30)
			bitsUsed += 3
		}
		e.dst.AppendUint32(value, bitsUsed)
	}
}
func (e *encoder) encodeAlphanumeric() {
	if e.dst == nil {
		log.Println("e.dst is nil")
		return
	}
	for i := 0; i < len(e.data); i += 2 {
		charsRemaining := len(e.data) - i
		var value uint32
		for j := 0; j < charsRemaining && j < 2; j++ {
			value *= 45
			value += encodeAlphanumericCharacter(e.data[i+j])
		}
		bitsUsed := 6
		if charsRemaining > 1 {
			bitsUsed = 11
		}
		e.dst.AppendUint32(value, bitsUsed)
	}
}
func (e *encoder) encodeByte() {
	if e.dst == nil {
		log.Println("e.dst is nil")
		return
	}
	for _, b := range e.data {
		_ = e.dst.AppendByte(b, 8)
	}
}
func (e *encoder) breakUpInto8bit() {
	maxCap := e.version.NumTotalCodewrods() * 8
	if less := maxCap - e.dst.Len(); less < 0 {
		err := fmt.Errorf(
			"wrong version(%d) cap(%d bits) and could not contain all bits: %d bits",
			e.version.Ver, maxCap, e.dst.Len(),
		)
		panic(err)
	} else if less < 4 {
		e.dst.AppendNumBools(less, false)
	} else {
		e.dst.AppendNumBools(4, false)
	}
	if mod := e.dst.Len() % 8; mod != 0 {
		e.dst.AppendNumBools(8-mod, false)
	}
	if n := maxCap - e.dst.Len(); n > 0 {
		debugLogf("maxCap: %d, len: %d, less: %d", maxCap, e.dst.Len(), n)
		for i := 1; i <= (n / 8); i++ {
			if i%2 == 1 {
				e.dst.Append(paddingByte1)
			} else {
				e.dst.Append(paddingByte2)
			}
		}
	}
}
var charCountMap = map[string]int{
	"9_numeric":       10,
	"9_alphanumeric":  9,
	"9_byte":          8,
	"9_japan":         8,
	"26_numeric":      12,
	"26_alphanumeric": 11,
	"26_byte":         16,
	"26_japan":        10,
	"40_numeric":      14,
	"40_alphanumeric": 13,
	"40_byte":         16,
	"40_japan":        12,
}
func (e *encoder) charCountBits() int {
	var lv int
	if v := e.version.Ver; v <= 9 {
		lv = 9
	} else if v <= 26 {
		lv = 26
	} else {
		lv = 40
	}
	pos := fmt.Sprintf("%d_%s", lv, getEncModeName(e.mode))
	return charCountMap[pos]
}
func encodeAlphanumericCharacter(v byte) uint32 {
	c := uint32(v)
	switch {
	case c >= '0' && c <= '9':
		return c - '0'
	case c >= 'A' && c <= 'Z':
		return c - 'A' + 10
	case c == ' ':
		return 36
	case c == '$':
		return 37
	case c == '%':
		return 38
	case c == '*':
		return 39
	case c == '+':
		return 40
	case c == '-':
		return 41
	case c == '.':
		return 42
	case c == '/':
		return 43
	case c == ':':
		return 44
	default:
		log.Panicf("encodeAlphanumericCharacter() with non alphanumeric char %c", v)
	}
	return 0
}
type analyzeEncFunc func(byte) bool
func analyzeEncodeModeFromRaw(raw []byte) encMode {
	analyzeFnMapping := map[encMode]analyzeEncFunc{
		EncModeNumeric:      analyzeNum,
		EncModeAlphanumeric: analyzeAlphaNum,
		EncModeByte:         nil,
		EncModeJP:           nil,
	}
	var (
		f    analyzeEncFunc
		mode                     = EncModeNumeric
	)
	for _, byt := range raw {
	reAnalyze:
		if f = analyzeFnMapping[mode]; f == nil {
			break
		}
		if !f(byt) {
			mode <<= 1
			goto reAnalyze
		}
	}
	return mode
}
func analyzeNum(byt byte) bool {
	return byt >= '0' && byt <= '9'
}