// TryToUint8 casts an empty interface to an uint8.
480104
func TryToUint8(i interface{}) (r uint8, err error) {
	switch t := i.(type) {
	case nil:
		r = 0
	case uint:
		r = uint8(t)
	case uint8:
		r = t
	case *uint8:
		r = *t
	case uint16:
		r = uint8(t)
	case uint32:
		r = uint8(t)
	case uint64:
		r = uint8(t)
	case int:
		r = uint8(t)
	case int8:
		r = uint8(t)
	case int16:
		r = uint8(t)
	case int32:
		r = uint8(t)
	case int64:
		r = uint8(t)
	case float32:
		r = uint8(t)
	case float64:
		r = uint8(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		var v uint64
		if v, err = strconv.ParseUint(t, 10, 8); err == nil {
			r = uint8(v)
		}
	default:
		err = castError(i, "uint8")
	}
	return
}
734704
func bigintToUint64(i *big.Int) (uint64, big.Accuracy) {
	sign := i.Sign()
	if sign > 0 {
		if i.BitLen() > 64 {
			return math.MaxUint64, big.Below
		}
	} else if sign < 0 {
		return 0, big.Above
	}
	return i.Uint64(), big.Exact
}
805739
func AtomToUint(ids []xproto.Atom) []uint {
	ids32 := make([]uint, len(ids))
	for i, v := range ids {
		ids32[i] = uint(v)
	}
	return ids32
}
87581
func (enc *Encoder) WriteInt8(val int8) error {
	return enc.WriteInt(int(val))
}
310875
func TryToFloat64(i interface{}) (r float64, err error) {
	switch t := i.(type) {
	case float32:
		r = float64(t)
	case float64:
		r = t
	case *float64:
		r = *t
	case int:
		r = float64(t)
	case int8:
		r = float64(t)
	case int16:
		r = float64(t)
	case int32:
		r = float64(t)
	case int64:
		r = float64(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		r, err = strconv.ParseFloat(t, 64)
	default:
		err = castError(i, "float64")
	}
	return
}
203548
func ConvertIntToUint(sc *stmtctx.StatementContext, val int64, upperBound uint64, tp byte) (uint64, error) {
	if sc.ShouldClipToZero() && val < 0 {
		return 0, overflow(val, tp)
	}

	if uint64(val) > upperBound {
		return upperBound, overflow(val, tp)
	}

	return uint64(val), nil
}
103831
func toInt64(v reflect.Value) int64 {
	i, _ := tryToInt64(v)
	return i
}
1230916
func NewInt8(v int8) Value {
	return MakeTrusted(Int8, strconv.AppendInt(nil, int64(v), 10))
}
529140
func StringToUint32(from string) (uint32, error) {
	val, err := strconv.ParseUint(from, DefeultNumericBase, 32)
	return uint32(val), err
}
755311
func (p *parserMixin) Uint8() (target *uint8) {
	target = new(uint8)
	p.Uint8Var(target)
	return
}
554938
func Uint32toUint24Bytes(n uint32) []byte {
	bytes := make([]byte, 3)
	bytes[0] = byte(n >> 16)
	bytes[1] = byte(n >> 8)
	bytes[2] = byte(n >> 0)

	return bytes
}
908065
func stringValToUint(val string) (uint, error) {
	parsedField, err := strconv.ParseUint(val, 10, 64)
	if err != nil {
		splitErr := strings.Split(err.Error(), ": ")
		errStr := splitErr[len(splitErr)-1]
		// return a value of zero and the error encountered during string parsing
		return 0, fmt.Errorf("Value '%v' cannot be parsed as an unsigned integer (%v)", val, errStr)
	}
	// return the unsigned integer equivalent of the input string and a nil error (indicating success)
	return uint(parsedField), nil
}
1259386
func (stream *Stream) WriteUint8(val uint8) {
	stream.buf = writeFirstBuf(stream.buf, digits[val])
}
1324228
func (a *Array) Uint8(i uint8) *Array {
	a.buf = enc.AppendUint8(enc.AppendArrayDelim(a.buf), i)
	return a
}
557376
func ConvertUint8(str string) (uint8, error) {
	i, err := strconv.ParseUint(str, 10, 8)
	if err != nil {
		return 0, err
	}
	return uint8(i), nil
}
775082
func (dec *Decoder) Int8Null(v **int8) error {
	err := dec.decodeInt8Null(v)
	if err != nil {
		return err
	}
	dec.called |= 1
	return nil
}
516443
func TryToBool(i interface{}) (b bool, err error) {
	switch v := i.(type) {
	case nil:
	case bool:
		b = v
	case *bool:
		b = *v
	case string:
		b, err = strconv.ParseBool(v)
	case *string:
		b, err = strconv.ParseBool(*v)
	case int, int8, int16, int32, int64:
		b = v != 0
	default:
		err = castError(i, "bool")
	}
	return
}