Example #1
0
// EncodeDecimal encodes a decimal d into a byte slice which can be sorted lexicographically later.
func EncodeDecimal(b []byte, d types.Datum) []byte {
	dec := d.GetMysqlDecimal()
	precision := d.Length()
	frac := d.Frac()
	if precision == 0 {
		precision, frac = dec.PrecisionAndFrac()
	}
	b = append(b, byte(precision), byte(frac))
	bin, err := dec.ToBin(precision, frac)
	if err != nil {
		log.Errorf("should not happen, precision %d, frac %d %v", precision, frac, err)
		return b
	}
	b = append(b, bin...)
	return b
}