Exemple #1
0
func WriteDecimal(value *big.Decimal, buffer *bytes.Buffer) {
	buffer.WriteByte('\x01')
	left, right := value.Components()
	positive := writeBigInt(left, buffer, bigintMagicNumber1)
	if right != nil {
		if positive {
			buffer.WriteByte('\x00')
		} else {
			buffer.WriteByte('\xff')
		}
		writeBigInt(right, buffer, bigintMagicNumber2)
	}
}
Exemple #2
0
func EncodeBigDecimal(value *big.Decimal) []byte {
	left, right := value.Components()
	encoding := encodeBigInt(left, bigintMagicNumber1)
	if right != nil {
		if left.IsNegative() {
			encoding = append(encoding, '\xff')
		} else {
			encoding = append(encoding, '\x00')
		}
		encoding = append(encoding, encodeBigInt(right, bigintMagicNumber2)...)
	}
	return encoding
}