tarantool / tarantool-python

Python client library for Tarantool
https://www.tarantool.io
BSD 2-Clause "Simplified" License
100 stars 48 forks source link

msgpack: support decimals with negative scale #298

Closed DifferentialOrange closed 1 year ago

DifferentialOrange commented 1 year ago

Current decimal external type parser do not expect negative scale in decimal payload. Negative scale is a positive exponent. It seems that the only way to obtain positive exponent is to use E-notation since Tarantool library do not truncate trailing zeroes before decimal point:

tarantool> msgpack.encode(decimal.new('1e33')):hex()
---
- c70301d0df1c
...

tarantool> msgpack.encode(decimal.new('1000000000000000000000000000000000')):hex()
---
- c713010001000000000000000000000000000000000c
...

There are two different bugs in current implementation:

This patch fixes both of them. See also [3].

  1. https://github.com/tarantool/tarantool/blob/ba749e820bf0638aa3f79f266848590f9713c1cf/src/lib/core/decimal.c#L432-L450
  2. https://github.com/msgpack/msgpack/blob/master/spec.md
  3. https://github.com/tarantool/go-tarantool/pull/314