Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH 0/3] decimal. Add internal methods to encode/decode decimals to msgpack.
@ 2019-06-21  9:02 Serge Petrenko
  2019-06-21  9:02 ` [PATCH 1/3] lib: update msgpuck library Serge Petrenko
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Serge Petrenko @ 2019-06-21  9:02 UTC (permalink / raw)
  To: vdavydov.dev; +Cc: tarantool-patches, Serge Petrenko

https://github.com/tarantool/tarantool/issues/692
https://github.com/tarantool/tarantool/tree/sp/gh-692-mp-decimal-new

This patchset add the methods necessary to encode/decode decimals as msgpack.
The methods have the similar API to the existing mp methods:
mp_encode_.../mp_decode_...

The first patch updates the msgpuck library to introduce EXT types.
The second path fixes a couple of places in decimal_pack() and decimal_len()
nethods, where const qualifiers were forgotten.
The third patch adds the new methods: mp_encode_decimal(), mp_decode_decimal()
and mp_sizeof_decimal(), and updates the decimal unit test to test them.


Serge Petrenko (3):
  lib: update msgpuck library
  decimal: add const qualifiers for decimal_pack() and decimal_len()
  decimal: allow to encode/decode decimals as MsgPack

 src/lib/core/CMakeLists.txt  |   1 +
 src/lib/core/decimal.c       |   4 +-
 src/lib/core/decimal.h       |   4 +-
 src/lib/core/mp_decimal.c    |  72 ++++++
 src/lib/core/mp_decimal.h    |  62 +++++
 src/lib/core/mp_user_types.h |  38 +++
 src/lib/msgpuck              |   2 +-
 test/unit/decimal.c          |  33 ++-
 test/unit/decimal.result     | 476 ++++++++++++++++++++++++----------
 test/unit/msgpack.result     | 480 ++++++++++++++++++++++++++++++++++-
 10 files changed, 1014 insertions(+), 158 deletions(-)
 create mode 100644 src/lib/core/mp_decimal.c
 create mode 100644 src/lib/core/mp_decimal.h
 create mode 100644 src/lib/core/mp_user_types.h

-- 
2.20.1 (Apple Git-117)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] lib: update msgpuck library
  2019-06-21  9:02 [PATCH 0/3] decimal. Add internal methods to encode/decode decimals to msgpack Serge Petrenko
@ 2019-06-21  9:02 ` Serge Petrenko
  2019-06-21 16:00   ` Vladimir Davydov
  2019-06-21  9:02 ` [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len() Serge Petrenko
  2019-06-21  9:02 ` [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack Serge Petrenko
  2 siblings, 1 reply; 7+ messages in thread
From: Serge Petrenko @ 2019-06-21  9:02 UTC (permalink / raw)
  To: vdavydov.dev; +Cc: tarantool-patches, Serge Petrenko

The ability to encode/decode ext types is added to msgpuck.
These types will be used for decimal encoding/decoding in tarantool.

Needed for #692
---
 src/lib/msgpuck          |   2 +-
 test/unit/msgpack.result | 480 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 468 insertions(+), 14 deletions(-)

diff --git a/src/lib/msgpuck b/src/lib/msgpuck
index 22f3fc901..8ae606a16 160000
--- a/src/lib/msgpuck
+++ b/src/lib/msgpuck
@@ -1 +1 @@
-Subproject commit 22f3fc901baf13fc9e8563e6fe0242b9f352114b
+Subproject commit 8ae606a1636dd89b2d61b154e5a1db03dce91657
diff --git a/test/unit/msgpack.result b/test/unit/msgpack.result
index 385e7da0e..02c0b05fd 100644
--- a/test/unit/msgpack.result
+++ b/test/unit/msgpack.result
@@ -1,4 +1,4 @@
-1..20
+1..22
     1..135
     # *** test_uints ***
     # uint 0U
@@ -620,6 +620,206 @@ ok 7 - subtests
     ok 78 - mp_encode(0xffffffffU) == "\xc6\xff\xff\xff\xff"
     # *** test_binls: done ***
 ok 8 - subtests
+    1..168
+    # *** test_extls ***
+    # extl 0x01U
+    ok 1 - mp_check_extl(0x01U) == 0
+    ok 2 - mp_decode(mp_encode(0x01U)) == 0x01U
+    ok 3 - len(mp_encode_extl(0x01U)
+    ok 4 - len(mp_decode_extl(0x01U))
+    ok 5 - mp_sizeof_extl(0x01U)
+    ok 6 - mp_encode(0x01U) == "\xd4\x00"
+    # extl 0x02U
+    ok 7 - mp_check_extl(0x02U) == 0
+    ok 8 - mp_decode(mp_encode(0x02U)) == 0x02U
+    ok 9 - len(mp_encode_extl(0x02U)
+    ok 10 - len(mp_decode_extl(0x02U))
+    ok 11 - mp_sizeof_extl(0x02U)
+    ok 12 - mp_encode(0x02U) == "\xd5\x00"
+    # extl 0x04U
+    ok 13 - mp_check_extl(0x04U) == 0
+    ok 14 - mp_decode(mp_encode(0x04U)) == 0x04U
+    ok 15 - len(mp_encode_extl(0x04U)
+    ok 16 - len(mp_decode_extl(0x04U))
+    ok 17 - mp_sizeof_extl(0x04U)
+    ok 18 - mp_encode(0x04U) == "\xd6\x00"
+    # extl 0x08U
+    ok 19 - mp_check_extl(0x08U) == 0
+    ok 20 - mp_decode(mp_encode(0x08U)) == 0x08U
+    ok 21 - len(mp_encode_extl(0x08U)
+    ok 22 - len(mp_decode_extl(0x08U))
+    ok 23 - mp_sizeof_extl(0x08U)
+    ok 24 - mp_encode(0x08U) == "\xd7\x00"
+    # extl 0x10U
+    ok 25 - mp_check_extl(0x10U) == 0
+    ok 26 - mp_decode(mp_encode(0x10U)) == 0x10U
+    ok 27 - len(mp_encode_extl(0x10U)
+    ok 28 - len(mp_decode_extl(0x10U))
+    ok 29 - mp_sizeof_extl(0x10U)
+    ok 30 - mp_encode(0x10U) == "\xd8\x00"
+    # extl 0x11U
+    ok 31 - mp_check_extl(0x11U) == 0
+    ok 32 - mp_decode(mp_encode(0x11U)) == 0x11U
+    ok 33 - len(mp_encode_extl(0x11U)
+    ok 34 - len(mp_decode_extl(0x11U))
+    ok 35 - mp_sizeof_extl(0x11U)
+    ok 36 - mp_encode(0x11U) == "\xc7\x11\x00"
+    # extl 0xfeU
+    ok 37 - mp_check_extl(0xfeU) == 0
+    ok 38 - mp_decode(mp_encode(0xfeU)) == 0xfeU
+    ok 39 - len(mp_encode_extl(0xfeU)
+    ok 40 - len(mp_decode_extl(0xfeU))
+    ok 41 - mp_sizeof_extl(0xfeU)
+    ok 42 - mp_encode(0xfeU) == "\xc7\xfe\x00"
+    # extl 0xffU
+    ok 43 - mp_check_extl(0xffU) == 0
+    ok 44 - mp_decode(mp_encode(0xffU)) == 0xffU
+    ok 45 - len(mp_encode_extl(0xffU)
+    ok 46 - len(mp_decode_extl(0xffU))
+    ok 47 - mp_sizeof_extl(0xffU)
+    ok 48 - mp_encode(0xffU) == "\xc7\xff\x00"
+    # extl 0x00U
+    ok 49 - mp_check_extl(0x00U) == 0
+    ok 50 - mp_decode(mp_encode(0x00U)) == 0x00U
+    ok 51 - len(mp_encode_extl(0x00U)
+    ok 52 - len(mp_decode_extl(0x00U))
+    ok 53 - mp_sizeof_extl(0x00U)
+    ok 54 - mp_encode(0x00U) == "\xc7\x00\x00"
+    # extl 0x03U
+    ok 55 - mp_check_extl(0x03U) == 0
+    ok 56 - mp_decode(mp_encode(0x03U)) == 0x03U
+    ok 57 - len(mp_encode_extl(0x03U)
+    ok 58 - len(mp_decode_extl(0x03U))
+    ok 59 - mp_sizeof_extl(0x03U)
+    ok 60 - mp_encode(0x03U) == "\xc7\x03\x00"
+    # extl 0x05U
+    ok 61 - mp_check_extl(0x05U) == 0
+    ok 62 - mp_decode(mp_encode(0x05U)) == 0x05U
+    ok 63 - len(mp_encode_extl(0x05U)
+    ok 64 - len(mp_decode_extl(0x05U))
+    ok 65 - mp_sizeof_extl(0x05U)
+    ok 66 - mp_encode(0x05U) == "\xc7\x05\x00"
+    # extl 0x06U
+    ok 67 - mp_check_extl(0x06U) == 0
+    ok 68 - mp_decode(mp_encode(0x06U)) == 0x06U
+    ok 69 - len(mp_encode_extl(0x06U)
+    ok 70 - len(mp_decode_extl(0x06U))
+    ok 71 - mp_sizeof_extl(0x06U)
+    ok 72 - mp_encode(0x06U) == "\xc7\x06\x00"
+    # extl 0x07U
+    ok 73 - mp_check_extl(0x07U) == 0
+    ok 74 - mp_decode(mp_encode(0x07U)) == 0x07U
+    ok 75 - len(mp_encode_extl(0x07U)
+    ok 76 - len(mp_decode_extl(0x07U))
+    ok 77 - mp_sizeof_extl(0x07U)
+    ok 78 - mp_encode(0x07U) == "\xc7\x07\x00"
+    # extl 0x09U
+    ok 79 - mp_check_extl(0x09U) == 0
+    ok 80 - mp_decode(mp_encode(0x09U)) == 0x09U
+    ok 81 - len(mp_encode_extl(0x09U)
+    ok 82 - len(mp_decode_extl(0x09U))
+    ok 83 - mp_sizeof_extl(0x09U)
+    ok 84 - mp_encode(0x09U) == "\xc7\x09\x00"
+    # extl 0x0aU
+    ok 85 - mp_check_extl(0x0aU) == 0
+    ok 86 - mp_decode(mp_encode(0x0aU)) == 0x0aU
+    ok 87 - len(mp_encode_extl(0x0aU)
+    ok 88 - len(mp_decode_extl(0x0aU))
+    ok 89 - mp_sizeof_extl(0x0aU)
+    ok 90 - mp_encode(0x0aU) == "\xc7\x0a\x00"
+    # extl 0x0bU
+    ok 91 - mp_check_extl(0x0bU) == 0
+    ok 92 - mp_decode(mp_encode(0x0bU)) == 0x0bU
+    ok 93 - len(mp_encode_extl(0x0bU)
+    ok 94 - len(mp_decode_extl(0x0bU))
+    ok 95 - mp_sizeof_extl(0x0bU)
+    ok 96 - mp_encode(0x0bU) == "\xc7\x0b\x00"
+    # extl 0x0cU
+    ok 97 - mp_check_extl(0x0cU) == 0
+    ok 98 - mp_decode(mp_encode(0x0cU)) == 0x0cU
+    ok 99 - len(mp_encode_extl(0x0cU)
+    ok 100 - len(mp_decode_extl(0x0cU))
+    ok 101 - mp_sizeof_extl(0x0cU)
+    ok 102 - mp_encode(0x0cU) == "\xc7\x0c\x00"
+    # extl 0x0dU
+    ok 103 - mp_check_extl(0x0dU) == 0
+    ok 104 - mp_decode(mp_encode(0x0dU)) == 0x0dU
+    ok 105 - len(mp_encode_extl(0x0dU)
+    ok 106 - len(mp_decode_extl(0x0dU))
+    ok 107 - mp_sizeof_extl(0x0dU)
+    ok 108 - mp_encode(0x0dU) == "\xc7\x0d\x00"
+    # extl 0x0eU
+    ok 109 - mp_check_extl(0x0eU) == 0
+    ok 110 - mp_decode(mp_encode(0x0eU)) == 0x0eU
+    ok 111 - len(mp_encode_extl(0x0eU)
+    ok 112 - len(mp_decode_extl(0x0eU))
+    ok 113 - mp_sizeof_extl(0x0eU)
+    ok 114 - mp_encode(0x0eU) == "\xc7\x0e\x00"
+    # extl 0x0fU
+    ok 115 - mp_check_extl(0x0fU) == 0
+    ok 116 - mp_decode(mp_encode(0x0fU)) == 0x0fU
+    ok 117 - len(mp_encode_extl(0x0fU)
+    ok 118 - len(mp_decode_extl(0x0fU))
+    ok 119 - mp_sizeof_extl(0x0fU)
+    ok 120 - mp_encode(0x0fU) == "\xc7\x0f\x00"
+    # extl 0x0100U
+    ok 121 - mp_check_extl(0x0100U) == 0
+    ok 122 - mp_decode(mp_encode(0x0100U)) == 0x0100U
+    ok 123 - len(mp_encode_extl(0x0100U)
+    ok 124 - len(mp_decode_extl(0x0100U))
+    ok 125 - mp_sizeof_extl(0x0100U)
+    ok 126 - mp_encode(0x0100U) == "\xc8\x01\x00\x00"
+    # extl 0x0101U
+    ok 127 - mp_check_extl(0x0101U) == 0
+    ok 128 - mp_decode(mp_encode(0x0101U)) == 0x0101U
+    ok 129 - len(mp_encode_extl(0x0101U)
+    ok 130 - len(mp_decode_extl(0x0101U))
+    ok 131 - mp_sizeof_extl(0x0101U)
+    ok 132 - mp_encode(0x0101U) == "\xc8\x01\x01\x00"
+    # extl 0xfffeU
+    ok 133 - mp_check_extl(0xfffeU) == 0
+    ok 134 - mp_decode(mp_encode(0xfffeU)) == 0xfffeU
+    ok 135 - len(mp_encode_extl(0xfffeU)
+    ok 136 - len(mp_decode_extl(0xfffeU))
+    ok 137 - mp_sizeof_extl(0xfffeU)
+    ok 138 - mp_encode(0xfffeU) == "\xc8\xff\xfe\x00"
+    # extl 0xffffU
+    ok 139 - mp_check_extl(0xffffU) == 0
+    ok 140 - mp_decode(mp_encode(0xffffU)) == 0xffffU
+    ok 141 - len(mp_encode_extl(0xffffU)
+    ok 142 - len(mp_decode_extl(0xffffU))
+    ok 143 - mp_sizeof_extl(0xffffU)
+    ok 144 - mp_encode(0xffffU) == "\xc8\xff\xff\x00"
+    # extl 0x00010000U
+    ok 145 - mp_check_extl(0x00010000U) == 0
+    ok 146 - mp_decode(mp_encode(0x00010000U)) == 0x00010000U
+    ok 147 - len(mp_encode_extl(0x00010000U)
+    ok 148 - len(mp_decode_extl(0x00010000U))
+    ok 149 - mp_sizeof_extl(0x00010000U)
+    ok 150 - mp_encode(0x00010000U) == "\xc9\x00\x01\x00\x00\x00"
+    # extl 0x00010001U
+    ok 151 - mp_check_extl(0x00010001U) == 0
+    ok 152 - mp_decode(mp_encode(0x00010001U)) == 0x00010001U
+    ok 153 - len(mp_encode_extl(0x00010001U)
+    ok 154 - len(mp_decode_extl(0x00010001U))
+    ok 155 - mp_sizeof_extl(0x00010001U)
+    ok 156 - mp_encode(0x00010001U) == "\xc9\x00\x01\x00\x01\x00"
+    # extl 0xfffffffeU
+    ok 157 - mp_check_extl(0xfffffffeU) == 0
+    ok 158 - mp_decode(mp_encode(0xfffffffeU)) == 0xfffffffeU
+    ok 159 - len(mp_encode_extl(0xfffffffeU)
+    ok 160 - len(mp_decode_extl(0xfffffffeU))
+    ok 161 - mp_sizeof_extl(0xfffffffeU)
+    ok 162 - mp_encode(0xfffffffeU) == "\xc9\xff\xff\xff\xfe\x00"
+    # extl 0xffffffffU
+    ok 163 - mp_check_extl(0xffffffffU) == 0
+    ok 164 - mp_decode(mp_encode(0xffffffffU)) == 0xffffffffU
+    ok 165 - len(mp_encode_extl(0xffffffffU)
+    ok 166 - len(mp_decode_extl(0xffffffffU))
+    ok 167 - mp_sizeof_extl(0xffffffffU)
+    ok 168 - mp_encode(0xffffffffU) == "\xc9\xff\xff\xff\xff\x00"
+    # *** test_extls: done ***
+ok 9 - subtests
     1..96
     # *** test_strs ***
     # str len=0x01
@@ -731,7 +931,7 @@ ok 8 - subtests
     ok 95 - mp_sizeof_str(0x10001)
     ok 96 - mp_encode_str(x, 0x10001) == x
     # *** test_strs: done ***
-ok 9 - subtests
+ok 10 - subtests
     1..96
     # *** test_bins ***
     # bin len=0x01
@@ -843,7 +1043,261 @@ ok 9 - subtests
     ok 95 - mp_sizeof_bin(0x10001)
     ok 96 - mp_encode_bin(x, 0x10001) == x
     # *** test_bins: done ***
-ok 10 - subtests
+ok 11 - subtests
+    1..225
+    # *** test_exts ***
+    # ext len=0x01
+    ok 1 - len(mp_decode_ext(x, 1))
+    ok 2 - type(mp_decode_ext(x))
+    ok 3 - len(mp_decode_strbin(x, 1))
+    ok 4 - mp_check_ext(mp_encode_ext(x, 0x01))
+    ok 5 - len(mp_decode_ext(x, 0x01)
+    ok 6 - len(mp_next_ext(x, 0x01)
+    ok 7 - len(mp_check_ext(x, 0x01)
+    ok 8 - mp_sizeof_ext(0x01)
+    ok 9 - mp_encode_ext(x, 0x01) == x
+    # ext len=0x02
+    ok 10 - len(mp_decode_ext(x, 2))
+    ok 11 - type(mp_decode_ext(x))
+    ok 12 - len(mp_decode_strbin(x, 2))
+    ok 13 - mp_check_ext(mp_encode_ext(x, 0x02))
+    ok 14 - len(mp_decode_ext(x, 0x02)
+    ok 15 - len(mp_next_ext(x, 0x02)
+    ok 16 - len(mp_check_ext(x, 0x02)
+    ok 17 - mp_sizeof_ext(0x02)
+    ok 18 - mp_encode_ext(x, 0x02) == x
+    # ext len=0x03
+    ok 19 - len(mp_decode_ext(x, 3))
+    ok 20 - type(mp_decode_ext(x))
+    ok 21 - len(mp_decode_strbin(x, 3))
+    ok 22 - mp_check_ext(mp_encode_ext(x, 0x03))
+    ok 23 - len(mp_decode_ext(x, 0x03)
+    ok 24 - len(mp_next_ext(x, 0x03)
+    ok 25 - len(mp_check_ext(x, 0x03)
+    ok 26 - mp_sizeof_ext(0x03)
+    ok 27 - mp_encode_ext(x, 0x03) == x
+    # ext len=0x04
+    ok 28 - len(mp_decode_ext(x, 4))
+    ok 29 - type(mp_decode_ext(x))
+    ok 30 - len(mp_decode_strbin(x, 4))
+    ok 31 - mp_check_ext(mp_encode_ext(x, 0x04))
+    ok 32 - len(mp_decode_ext(x, 0x04)
+    ok 33 - len(mp_next_ext(x, 0x04)
+    ok 34 - len(mp_check_ext(x, 0x04)
+    ok 35 - mp_sizeof_ext(0x04)
+    ok 36 - mp_encode_ext(x, 0x04) == x
+    # ext len=0x05
+    ok 37 - len(mp_decode_ext(x, 5))
+    ok 38 - type(mp_decode_ext(x))
+    ok 39 - len(mp_decode_strbin(x, 5))
+    ok 40 - mp_check_ext(mp_encode_ext(x, 0x05))
+    ok 41 - len(mp_decode_ext(x, 0x05)
+    ok 42 - len(mp_next_ext(x, 0x05)
+    ok 43 - len(mp_check_ext(x, 0x05)
+    ok 44 - mp_sizeof_ext(0x05)
+    ok 45 - mp_encode_ext(x, 0x05) == x
+    # ext len=0x06
+    ok 46 - len(mp_decode_ext(x, 6))
+    ok 47 - type(mp_decode_ext(x))
+    ok 48 - len(mp_decode_strbin(x, 6))
+    ok 49 - mp_check_ext(mp_encode_ext(x, 0x06))
+    ok 50 - len(mp_decode_ext(x, 0x06)
+    ok 51 - len(mp_next_ext(x, 0x06)
+    ok 52 - len(mp_check_ext(x, 0x06)
+    ok 53 - mp_sizeof_ext(0x06)
+    ok 54 - mp_encode_ext(x, 0x06) == x
+    # ext len=0x07
+    ok 55 - len(mp_decode_ext(x, 7))
+    ok 56 - type(mp_decode_ext(x))
+    ok 57 - len(mp_decode_strbin(x, 7))
+    ok 58 - mp_check_ext(mp_encode_ext(x, 0x07))
+    ok 59 - len(mp_decode_ext(x, 0x07)
+    ok 60 - len(mp_next_ext(x, 0x07)
+    ok 61 - len(mp_check_ext(x, 0x07)
+    ok 62 - mp_sizeof_ext(0x07)
+    ok 63 - mp_encode_ext(x, 0x07) == x
+    # ext len=0x08
+    ok 64 - len(mp_decode_ext(x, 8))
+    ok 65 - type(mp_decode_ext(x))
+    ok 66 - len(mp_decode_strbin(x, 8))
+    ok 67 - mp_check_ext(mp_encode_ext(x, 0x08))
+    ok 68 - len(mp_decode_ext(x, 0x08)
+    ok 69 - len(mp_next_ext(x, 0x08)
+    ok 70 - len(mp_check_ext(x, 0x08)
+    ok 71 - mp_sizeof_ext(0x08)
+    ok 72 - mp_encode_ext(x, 0x08) == x
+    # ext len=0x09
+    ok 73 - len(mp_decode_ext(x, 9))
+    ok 74 - type(mp_decode_ext(x))
+    ok 75 - len(mp_decode_strbin(x, 9))
+    ok 76 - mp_check_ext(mp_encode_ext(x, 0x09))
+    ok 77 - len(mp_decode_ext(x, 0x09)
+    ok 78 - len(mp_next_ext(x, 0x09)
+    ok 79 - len(mp_check_ext(x, 0x09)
+    ok 80 - mp_sizeof_ext(0x09)
+    ok 81 - mp_encode_ext(x, 0x09) == x
+    # ext len=0x0a
+    ok 82 - len(mp_decode_ext(x, 10))
+    ok 83 - type(mp_decode_ext(x))
+    ok 84 - len(mp_decode_strbin(x, 10))
+    ok 85 - mp_check_ext(mp_encode_ext(x, 0x0a))
+    ok 86 - len(mp_decode_ext(x, 0x0a)
+    ok 87 - len(mp_next_ext(x, 0x0a)
+    ok 88 - len(mp_check_ext(x, 0x0a)
+    ok 89 - mp_sizeof_ext(0x0a)
+    ok 90 - mp_encode_ext(x, 0x0a) == x
+    # ext len=0x0b
+    ok 91 - len(mp_decode_ext(x, 11))
+    ok 92 - type(mp_decode_ext(x))
+    ok 93 - len(mp_decode_strbin(x, 11))
+    ok 94 - mp_check_ext(mp_encode_ext(x, 0x0b))
+    ok 95 - len(mp_decode_ext(x, 0x0b)
+    ok 96 - len(mp_next_ext(x, 0x0b)
+    ok 97 - len(mp_check_ext(x, 0x0b)
+    ok 98 - mp_sizeof_ext(0x0b)
+    ok 99 - mp_encode_ext(x, 0x0b) == x
+    # ext len=0x0c
+    ok 100 - len(mp_decode_ext(x, 12))
+    ok 101 - type(mp_decode_ext(x))
+    ok 102 - len(mp_decode_strbin(x, 12))
+    ok 103 - mp_check_ext(mp_encode_ext(x, 0x0c))
+    ok 104 - len(mp_decode_ext(x, 0x0c)
+    ok 105 - len(mp_next_ext(x, 0x0c)
+    ok 106 - len(mp_check_ext(x, 0x0c)
+    ok 107 - mp_sizeof_ext(0x0c)
+    ok 108 - mp_encode_ext(x, 0x0c) == x
+    # ext len=0x0d
+    ok 109 - len(mp_decode_ext(x, 13))
+    ok 110 - type(mp_decode_ext(x))
+    ok 111 - len(mp_decode_strbin(x, 13))
+    ok 112 - mp_check_ext(mp_encode_ext(x, 0x0d))
+    ok 113 - len(mp_decode_ext(x, 0x0d)
+    ok 114 - len(mp_next_ext(x, 0x0d)
+    ok 115 - len(mp_check_ext(x, 0x0d)
+    ok 116 - mp_sizeof_ext(0x0d)
+    ok 117 - mp_encode_ext(x, 0x0d) == x
+    # ext len=0x0e
+    ok 118 - len(mp_decode_ext(x, 14))
+    ok 119 - type(mp_decode_ext(x))
+    ok 120 - len(mp_decode_strbin(x, 14))
+    ok 121 - mp_check_ext(mp_encode_ext(x, 0x0e))
+    ok 122 - len(mp_decode_ext(x, 0x0e)
+    ok 123 - len(mp_next_ext(x, 0x0e)
+    ok 124 - len(mp_check_ext(x, 0x0e)
+    ok 125 - mp_sizeof_ext(0x0e)
+    ok 126 - mp_encode_ext(x, 0x0e) == x
+    # ext len=0x0f
+    ok 127 - len(mp_decode_ext(x, 15))
+    ok 128 - type(mp_decode_ext(x))
+    ok 129 - len(mp_decode_strbin(x, 15))
+    ok 130 - mp_check_ext(mp_encode_ext(x, 0x0f))
+    ok 131 - len(mp_decode_ext(x, 0x0f)
+    ok 132 - len(mp_next_ext(x, 0x0f)
+    ok 133 - len(mp_check_ext(x, 0x0f)
+    ok 134 - mp_sizeof_ext(0x0f)
+    ok 135 - mp_encode_ext(x, 0x0f) == x
+    # ext len=0x10
+    ok 136 - len(mp_decode_ext(x, 16))
+    ok 137 - type(mp_decode_ext(x))
+    ok 138 - len(mp_decode_strbin(x, 16))
+    ok 139 - mp_check_ext(mp_encode_ext(x, 0x10))
+    ok 140 - len(mp_decode_ext(x, 0x10)
+    ok 141 - len(mp_next_ext(x, 0x10)
+    ok 142 - len(mp_check_ext(x, 0x10)
+    ok 143 - mp_sizeof_ext(0x10)
+    ok 144 - mp_encode_ext(x, 0x10) == x
+    # ext len=0x11
+    ok 145 - len(mp_decode_ext(x, 17))
+    ok 146 - type(mp_decode_ext(x))
+    ok 147 - len(mp_decode_strbin(x, 17))
+    ok 148 - mp_check_ext(mp_encode_ext(x, 0x11))
+    ok 149 - len(mp_decode_ext(x, 0x11)
+    ok 150 - len(mp_next_ext(x, 0x11)
+    ok 151 - len(mp_check_ext(x, 0x11)
+    ok 152 - mp_sizeof_ext(0x11)
+    ok 153 - mp_encode_ext(x, 0x11) == x
+    # ext len=0xfe
+    ok 154 - len(mp_decode_ext(x, 254))
+    ok 155 - type(mp_decode_ext(x))
+    ok 156 - len(mp_decode_strbin(x, 254))
+    ok 157 - mp_check_ext(mp_encode_ext(x, 0xfe))
+    ok 158 - len(mp_decode_ext(x, 0xfe)
+    ok 159 - len(mp_next_ext(x, 0xfe)
+    ok 160 - len(mp_check_ext(x, 0xfe)
+    ok 161 - mp_sizeof_ext(0xfe)
+    ok 162 - mp_encode_ext(x, 0xfe) == x
+    # ext len=0xff
+    ok 163 - len(mp_decode_ext(x, 255))
+    ok 164 - type(mp_decode_ext(x))
+    ok 165 - len(mp_decode_strbin(x, 255))
+    ok 166 - mp_check_ext(mp_encode_ext(x, 0xff))
+    ok 167 - len(mp_decode_ext(x, 0xff)
+    ok 168 - len(mp_next_ext(x, 0xff)
+    ok 169 - len(mp_check_ext(x, 0xff)
+    ok 170 - mp_sizeof_ext(0xff)
+    ok 171 - mp_encode_ext(x, 0xff) == x
+    # ext len=0x0100
+    ok 172 - len(mp_decode_ext(x, 256))
+    ok 173 - type(mp_decode_ext(x))
+    ok 174 - len(mp_decode_strbin(x, 256))
+    ok 175 - mp_check_ext(mp_encode_ext(x, 0x0100))
+    ok 176 - len(mp_decode_ext(x, 0x0100)
+    ok 177 - len(mp_next_ext(x, 0x0100)
+    ok 178 - len(mp_check_ext(x, 0x0100)
+    ok 179 - mp_sizeof_ext(0x0100)
+    ok 180 - mp_encode_ext(x, 0x0100) == x
+    # ext len=0x0101
+    ok 181 - len(mp_decode_ext(x, 257))
+    ok 182 - type(mp_decode_ext(x))
+    ok 183 - len(mp_decode_strbin(x, 257))
+    ok 184 - mp_check_ext(mp_encode_ext(x, 0x0101))
+    ok 185 - len(mp_decode_ext(x, 0x0101)
+    ok 186 - len(mp_next_ext(x, 0x0101)
+    ok 187 - len(mp_check_ext(x, 0x0101)
+    ok 188 - mp_sizeof_ext(0x0101)
+    ok 189 - mp_encode_ext(x, 0x0101) == x
+    # ext len=0xfffe
+    ok 190 - len(mp_decode_ext(x, 65534))
+    ok 191 - type(mp_decode_ext(x))
+    ok 192 - len(mp_decode_strbin(x, 65534))
+    ok 193 - mp_check_ext(mp_encode_ext(x, 0xfffe))
+    ok 194 - len(mp_decode_ext(x, 0xfffe)
+    ok 195 - len(mp_next_ext(x, 0xfffe)
+    ok 196 - len(mp_check_ext(x, 0xfffe)
+    ok 197 - mp_sizeof_ext(0xfffe)
+    ok 198 - mp_encode_ext(x, 0xfffe) == x
+    # ext len=0xffff
+    ok 199 - len(mp_decode_ext(x, 65535))
+    ok 200 - type(mp_decode_ext(x))
+    ok 201 - len(mp_decode_strbin(x, 65535))
+    ok 202 - mp_check_ext(mp_encode_ext(x, 0xffff))
+    ok 203 - len(mp_decode_ext(x, 0xffff)
+    ok 204 - len(mp_next_ext(x, 0xffff)
+    ok 205 - len(mp_check_ext(x, 0xffff)
+    ok 206 - mp_sizeof_ext(0xffff)
+    ok 207 - mp_encode_ext(x, 0xffff) == x
+    # ext len=0x00010000
+    ok 208 - len(mp_decode_ext(x, 65536))
+    ok 209 - type(mp_decode_ext(x))
+    ok 210 - len(mp_decode_strbin(x, 65536))
+    ok 211 - mp_check_ext(mp_encode_ext(x, 0x00010000))
+    ok 212 - len(mp_decode_ext(x, 0x00010000)
+    ok 213 - len(mp_next_ext(x, 0x00010000)
+    ok 214 - len(mp_check_ext(x, 0x00010000)
+    ok 215 - mp_sizeof_ext(0x00010000)
+    ok 216 - mp_encode_ext(x, 0x00010000) == x
+    # ext len=0x00010001
+    ok 217 - len(mp_decode_ext(x, 65537))
+    ok 218 - type(mp_decode_ext(x))
+    ok 219 - len(mp_decode_strbin(x, 65537))
+    ok 220 - mp_check_ext(mp_encode_ext(x, 0x00010001))
+    ok 221 - len(mp_decode_ext(x, 0x00010001)
+    ok 222 - len(mp_next_ext(x, 0x00010001)
+    ok 223 - len(mp_check_ext(x, 0x00010001)
+    ok 224 - mp_sizeof_ext(0x00010001)
+    ok 225 - mp_encode_ext(x, 0x00010001) == x
+    # *** test_exts: done ***
+ok 12 - subtests
     1..54
     # *** test_arrays ***
     # array 0
@@ -910,7 +1364,7 @@ ok 10 - subtests
     ok 53 - mp_sizeof_array(0xffffffffU)
     ok 54 - mp_encode(0xffffffffU) == "\xdd\xff\xff\xff\xff"
     # *** test_arrays: done ***
-ok 11 - subtests
+ok 13 - subtests
     1..54
     # *** test_maps ***
     # map 0
@@ -977,7 +1431,7 @@ ok 11 - subtests
     ok 53 - mp_sizeof_map(0xffffffffU)
     ok 54 - mp_encode(0xffffffffU) == "\xdf\xff\xff\xff\xff"
     # *** test_maps: done ***
-ok 12 - subtests
+ok 14 - subtests
     1..52
     # *** test_next_on_arrays ***
     # next/check on array(0)
@@ -1046,7 +1500,7 @@ ok 12 - subtests
     ok 51 - len(mp_check(array 65537)) == 65542
     ok 52 - len(mp_next(array 65537)) == 65542
     # *** test_next_on_arrays: done ***
-ok 13 - subtests
+ok 15 - subtests
     1..52
     # *** test_next_on_maps ***
     # next/check on map(0)
@@ -1115,7 +1569,7 @@ ok 13 - subtests
     ok 51 - len(mp_check(map 65537)) == 131079
     ok 52 - len(mp_next(map 65537)) == 131079
     # *** test_next_on_maps: done ***
-ok 14 - subtests
+ok 16 - subtests
     1..227
     # *** test_compare_uints ***
     ok 1 - mp_compare_uint(0, 0) == 0
@@ -1346,7 +1800,7 @@ ok 14 - subtests
     ok 226 - mp_compare_uint(18446744073709551615, 18446744073709551614) > 0
     ok 227 - mp_compare_uint(18446744073709551615, 18446744073709551615) == 0
     # *** test_compare_uints: done ***
-ok 15 - subtests
+ok 17 - subtests
     1..282
     # *** test_format ***
     ok 1 - Test type on step 0
@@ -1632,7 +2086,7 @@ ok 15 - subtests
     ok 281 - return value on step 70
     ok 282 - buffer overflow on step 70
     # *** test_format: done ***
-ok 16 - subtests
+ok 18 - subtests
     1..12
     # *** test_mp_print ***
     ok 1 - mp_snprint return value
@@ -1648,7 +2102,7 @@ ok 16 - subtests
     ok 11 - mp_snprint max nesting depth return value
     ok 12 - mp_snprint max nesting depth result
     # *** test_mp_print: done ***
-ok 17 - subtests
+ok 19 - subtests
     1..65
     # *** test_mp_check ***
     ok 1 - invalid fixmap 1
@@ -1717,7 +2171,7 @@ ok 17 - subtests
     ok 64 - invalid map32 2
     ok 65 - invalid map32 3
     # *** test_mp_check: done ***
-ok 18 - subtests
+ok 20 - subtests
     1..96
     # *** test_numbers ***
     ok 1 - mp_read_int32(mp_encode_uint(123)) check success
@@ -1817,7 +2271,7 @@ ok 18 - subtests
     ok 95 - mp_read_double(mp_encode_strl(100)) check fail
     ok 96 - mp_read_double(mp_encode_strl(100)) check pos unchanged
     # *** test_numbers: done ***
-ok 19 - subtests
+ok 21 - subtests
     1..4
     # *** test_overflow ***
     ok 1 - mp_check array overflow
@@ -1825,4 +2279,4 @@ ok 19 - subtests
     ok 3 - mp_check str overflow
     ok 4 - mp_check bin overflow
     # *** test_overflow: done ***
-ok 20 - subtests
+ok 22 - subtests
-- 
2.20.1 (Apple Git-117)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len()
  2019-06-21  9:02 [PATCH 0/3] decimal. Add internal methods to encode/decode decimals to msgpack Serge Petrenko
  2019-06-21  9:02 ` [PATCH 1/3] lib: update msgpuck library Serge Petrenko
@ 2019-06-21  9:02 ` Serge Petrenko
  2019-06-21 16:00   ` Vladimir Davydov
  2019-06-21  9:02 ` [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack Serge Petrenko
  2 siblings, 1 reply; 7+ messages in thread
From: Serge Petrenko @ 2019-06-21  9:02 UTC (permalink / raw)
  To: vdavydov.dev; +Cc: tarantool-patches, Serge Petrenko

The const qualifiers weren't there initially for some reason.
Fix this.

Part of #692
---
 src/lib/core/decimal.c | 4 ++--
 src/lib/core/decimal.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lib/core/decimal.c b/src/lib/core/decimal.c
index 8f7ca3fbe..1f9b5838d 100644
--- a/src/lib/core/decimal.c
+++ b/src/lib/core/decimal.c
@@ -310,14 +310,14 @@ decimal_sqrt(decimal_t *res, const decimal_t *lhs)
 }
 
 uint32_t
-decimal_len(decimal_t *dec)
+decimal_len(const decimal_t *dec)
 {
 	/* 1  + ceil((digits + 1) / 2) */
 	return 2 + dec->digits / 2;
 }
 
 char *
-decimal_pack(char *data, decimal_t *dec)
+decimal_pack(char *data, const decimal_t *dec)
 {
 	uint32_t len = decimal_len(dec);
 	*data++ = decimal_scale(dec);
diff --git a/src/lib/core/decimal.h b/src/lib/core/decimal.h
index 0c7b16098..1d0f2582e 100644
--- a/src/lib/core/decimal.h
+++ b/src/lib/core/decimal.h
@@ -173,7 +173,7 @@ decimal_sqrt(decimal_t *res, const decimal_t *lhs);
 
 /** @return The length in bytes decimal packed representation will take. */
 uint32_t
-decimal_len(decimal_t *dec);
+decimal_len(const decimal_t *dec);
 
 /**
  * Convert a decimal \a dec to its packed representation.
@@ -181,7 +181,7 @@ decimal_len(decimal_t *dec);
  * @return data + decimal_len(dec);
  */
 char *
-decimal_pack(char *data, decimal_t *dec);
+decimal_pack(char *data, const decimal_t *dec);
 
 /**
  * Using a packed representation of size \a len pointed to by
-- 
2.20.1 (Apple Git-117)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack
  2019-06-21  9:02 [PATCH 0/3] decimal. Add internal methods to encode/decode decimals to msgpack Serge Petrenko
  2019-06-21  9:02 ` [PATCH 1/3] lib: update msgpuck library Serge Petrenko
  2019-06-21  9:02 ` [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len() Serge Petrenko
@ 2019-06-21  9:02 ` Serge Petrenko
  2019-06-24  8:35   ` Vladimir Davydov
  2 siblings, 1 reply; 7+ messages in thread
From: Serge Petrenko @ 2019-06-21  9:02 UTC (permalink / raw)
  To: vdavydov.dev; +Cc: tarantool-patches, Serge Petrenko

This patch adds the methods necessary to encode and decode decimals to
MsgPack. MsgPack EXT type (MP_EXT) together with a new extension type
MP_DECIMAL is used as a record header.

The decimal MsgPack representation looks like this:
+--------+-------------------+------------+===============+
| MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
+--------+-------------------+------------+===============+
The whole record may be encoded and decoded with
mp_encode_decimal() and mp_decode_decimal(). This is equivalent to
performing mp_encode_extl()/mp_decode_extl() on the first 3 fields and
decimal_pack/unpack() on the PackedDecimal field.

Part of #692
---
 src/lib/core/CMakeLists.txt  |   1 +
 src/lib/core/mp_decimal.c    |  72 ++++++
 src/lib/core/mp_decimal.h    |  62 +++++
 src/lib/core/mp_user_types.h |  38 +++
 test/unit/decimal.c          |  33 ++-
 test/unit/decimal.result     | 476 +++++++++++++++++++++++++----------
 6 files changed, 542 insertions(+), 140 deletions(-)
 create mode 100644 src/lib/core/mp_decimal.c
 create mode 100644 src/lib/core/mp_decimal.h
 create mode 100644 src/lib/core/mp_user_types.h

diff --git a/src/lib/core/CMakeLists.txt b/src/lib/core/CMakeLists.txt
index 66e430a25..e0a717aa3 100644
--- a/src/lib/core/CMakeLists.txt
+++ b/src/lib/core/CMakeLists.txt
@@ -27,6 +27,7 @@ set(core_sources
     mpstream.c
     port.c
     decimal.c
+    mp_decimal.c
 )
 
 if (TARGET_OS_NETBSD)
diff --git a/src/lib/core/mp_decimal.c b/src/lib/core/mp_decimal.c
new file mode 100644
index 000000000..1bcf316fa
--- /dev/null
+++ b/src/lib/core/mp_decimal.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "mp_decimal.h"
+#include "mp_user_types.h"
+#include "msgpuck.h"
+#include "decimal.h"
+
+uint32_t
+mp_sizeof_decimal(const decimal_t *dec)
+{
+	return mp_sizeof_ext(decimal_len(dec));
+}
+
+decimal_t *
+mp_decode_decimal(const char **data, decimal_t *dec)
+{
+	if (mp_typeof(**data) != MP_EXT)
+		return NULL;
+
+	int8_t type;
+	uint32_t len;
+	const char *const svp = *data;
+
+	len = mp_decode_extl(data, &type);
+
+	if (type != MP_DECIMAL || len == 0) {
+		*data = svp;
+		return NULL;
+	}
+	decimal_t *res = decimal_unpack(data,  len, dec);
+	if (!res)
+		*data = svp;
+	return res;
+}
+
+char *
+mp_encode_decimal(char *data, const decimal_t *dec)
+{
+	uint32_t len = decimal_len(dec);
+	data = mp_encode_extl(data, MP_DECIMAL, len);
+	data = decimal_pack(data, dec);
+	return data;
+}
diff --git a/src/lib/core/mp_decimal.h b/src/lib/core/mp_decimal.h
new file mode 100644
index 000000000..a991a5f16
--- /dev/null
+++ b/src/lib/core/mp_decimal.h
@@ -0,0 +1,62 @@
+#ifndef TARANTOOL_LIB_CORE_MP_DECIMAL_INCLUDED
+#define TARANTOOL_LIB_CORE_MP_DECIMAL_INCLUDED
+/*
+ * Copyright 2019, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "decimal.h"
+#include <stdint.h>
+
+/**
+ * \brief Calculate exact buffer size needed to store a decimal
+ * pointed to by \a dec.
+ */
+uint32_t
+mp_sizeof_decimal(const decimal_t *dec);
+
+/**
+ * \brief Decode a decimal from MsgPack \a data
+ * \param data - buffer pointer
+ * \return the decoded decimal
+ * \post *data = *data + mp_sizeof_decimal(retval)
+ */
+decimal_t *
+mp_decode_decimal(const char **data, decimal_t *dec);
+
+/**
+ * \brief Encode a decimal pointed to by \a dec.
+ * \parad dec - decimal pointer
+ * \param data - a buffer
+ * \return \a data + mp_sizeof_decimal(\a dec)
+ */
+char *
+mp_encode_decimal(char *data, const decimal_t *dec);
+
+#endif
diff --git a/src/lib/core/mp_user_types.h b/src/lib/core/mp_user_types.h
new file mode 100644
index 000000000..9158b40d3
--- /dev/null
+++ b/src/lib/core/mp_user_types.h
@@ -0,0 +1,38 @@
+#ifndef TARANTOOL_LIB_CORE_MP_USER_TYPES_H_INCLUDED
+#define TARANTOOL_LIB_CORE_MP_USER_TYPES_H_INCLUDED
+/*
+ * Copyright 2019, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+enum mp_user_type {
+    MP_DECIMAL = 0
+};
+
+#endif
diff --git a/test/unit/decimal.c b/test/unit/decimal.c
index 7453d13ca..db5a29449 100644
--- a/test/unit/decimal.c
+++ b/test/unit/decimal.c
@@ -1,5 +1,8 @@
 #include "unit.h"
 #include "decimal.h"
+#include "mp_decimal.h"
+#include "mp_user_types.h"
+#include "msgpuck.h"
 #include <limits.h>
 #include <string.h>
 #include <float.h> /* DBL_DIG */
@@ -64,6 +67,32 @@
 
 char buf[32];
 
+#define test_mpdec(str) ({\
+	decimal_t dec;\
+	decimal_from_string(&dec, str);\
+	uint32_t l1 = mp_sizeof_decimal(&dec);\
+	ok(l1 <= 25 && l1 >= 4, "mp_sizeof_decimal("str")");\
+	char *b1 = mp_encode_decimal(buf, &dec);\
+	is(b1, buf + l1, "mp_sizeof_decimal("str") == len(mp_encode_decimal("str"))");\
+	const char *b2 = buf;\
+	const char *b3 = buf;\
+	decimal_t d2;\
+	mp_next(&b3);\
+	is(b3, b1, "mp_next(mp_encode("str"))");\
+	mp_decode_decimal(&b2, &d2);\
+	is(b1, b2, "mp_decode(mp_encode("str") len");\
+	is(decimal_compare(&dec, &d2), 0, "mp_decode(mp_encode("str")) value");\
+	is(decimal_scale(&dec), decimal_scale(&d2), "mp_decode(mp_encode("str")) scale");\
+	is(strcmp(decimal_to_string(&d2), str), 0, "str(mp_decode(mp_encode("str"))) == "str);\
+	b2 = buf;\
+	int8_t type;\
+	uint32_t l2 = mp_decode_extl(&b2, &type);\
+	is(type, MP_DECIMAL, "mp_ext_type is MP_DECIMAL");\
+	is(&d2, decimal_unpack(&b2, l2, &d2), "decimal_unpack() after mp_decode_extl()");\
+	is(decimal_compare(&dec, &d2), 0, "decimal_unpack() after mp_decode_extl() value");\
+	is(b2, buf + l1, "decimal_unpack() after mp_decode_extl() len");\
+})
+
 #define test_decpack(str) ({\
 	decimal_t dec;\
 	decimal_from_string(&dec, str);\
@@ -79,12 +108,14 @@ char buf[32];
 	is(decimal_scale(&dec), decimal_scale(&d2), "decimal_unpack(decimal_pack("str")) scale");\
 	is(decimal_precision(&dec), decimal_precision(&d2), "decimal_unpack(decimal_pack("str")) precision");\
 	is(strcmp(decimal_to_string(&d2), str), 0, "str(decimal_unpack(decimal_pack("str")) == "str);\
+	test_mpdec(str);\
 })
 
+
 static int
 test_pack_unpack(void)
 {
-	plan(146);
+	plan(344);
 
 	test_decpack("0");
 	test_decpack("-0");
diff --git a/test/unit/decimal.result b/test/unit/decimal.result
index 051dc7960..21df301b9 100644
--- a/test/unit/decimal.result
+++ b/test/unit/decimal.result
@@ -256,7 +256,7 @@ ok 254 - decimal_mul(1e19, 1e19) - overflow
 ok 255 - decimal_from_string(1e19)
 ok 256 - decimal_from_string(1e-19)
 ok 257 - decimal_div(1e19, 1e-19) - overflow
-    1..146
+    1..344
     ok 1 - decimal_len(0)
     ok 2 - decimal_len(0) == len(decimal_pack(0)
     ok 3 - decimal_unpack(decimal_pack(0))
@@ -265,142 +265,340 @@ ok 257 - decimal_div(1e19, 1e-19) - overflow
     ok 6 - decimal_unpack(decimal_pack(0)) scale
     ok 7 - decimal_unpack(decimal_pack(0)) precision
     ok 8 - str(decimal_unpack(decimal_pack(0)) == 0
-    ok 9 - decimal_len(-0)
-    ok 10 - decimal_len(-0) == len(decimal_pack(-0)
-    ok 11 - decimal_unpack(decimal_pack(-0))
-    ok 12 - decimal_unpack(decimal_pack(-0)) len
-    ok 13 - decimal_unpack(decimal_pack(-0)) value
-    ok 14 - decimal_unpack(decimal_pack(-0)) scale
-    ok 15 - decimal_unpack(decimal_pack(-0)) precision
-    ok 16 - str(decimal_unpack(decimal_pack(-0)) == -0
-    ok 17 - decimal_len(1)
-    ok 18 - decimal_len(1) == len(decimal_pack(1)
-    ok 19 - decimal_unpack(decimal_pack(1))
-    ok 20 - decimal_unpack(decimal_pack(1)) len
-    ok 21 - decimal_unpack(decimal_pack(1)) value
-    ok 22 - decimal_unpack(decimal_pack(1)) scale
-    ok 23 - decimal_unpack(decimal_pack(1)) precision
-    ok 24 - str(decimal_unpack(decimal_pack(1)) == 1
-    ok 25 - decimal_len(-1)
-    ok 26 - decimal_len(-1) == len(decimal_pack(-1)
-    ok 27 - decimal_unpack(decimal_pack(-1))
-    ok 28 - decimal_unpack(decimal_pack(-1)) len
-    ok 29 - decimal_unpack(decimal_pack(-1)) value
-    ok 30 - decimal_unpack(decimal_pack(-1)) scale
-    ok 31 - decimal_unpack(decimal_pack(-1)) precision
-    ok 32 - str(decimal_unpack(decimal_pack(-1)) == -1
-    ok 33 - decimal_len(0.1)
-    ok 34 - decimal_len(0.1) == len(decimal_pack(0.1)
-    ok 35 - decimal_unpack(decimal_pack(0.1))
-    ok 36 - decimal_unpack(decimal_pack(0.1)) len
-    ok 37 - decimal_unpack(decimal_pack(0.1)) value
-    ok 38 - decimal_unpack(decimal_pack(0.1)) scale
-    ok 39 - decimal_unpack(decimal_pack(0.1)) precision
-    ok 40 - str(decimal_unpack(decimal_pack(0.1)) == 0.1
-    ok 41 - decimal_len(-0.1)
-    ok 42 - decimal_len(-0.1) == len(decimal_pack(-0.1)
-    ok 43 - decimal_unpack(decimal_pack(-0.1))
-    ok 44 - decimal_unpack(decimal_pack(-0.1)) len
-    ok 45 - decimal_unpack(decimal_pack(-0.1)) value
-    ok 46 - decimal_unpack(decimal_pack(-0.1)) scale
-    ok 47 - decimal_unpack(decimal_pack(-0.1)) precision
-    ok 48 - str(decimal_unpack(decimal_pack(-0.1)) == -0.1
-    ok 49 - decimal_len(2.718281828459045)
-    ok 50 - decimal_len(2.718281828459045) == len(decimal_pack(2.718281828459045)
-    ok 51 - decimal_unpack(decimal_pack(2.718281828459045))
-    ok 52 - decimal_unpack(decimal_pack(2.718281828459045)) len
-    ok 53 - decimal_unpack(decimal_pack(2.718281828459045)) value
-    ok 54 - decimal_unpack(decimal_pack(2.718281828459045)) scale
-    ok 55 - decimal_unpack(decimal_pack(2.718281828459045)) precision
-    ok 56 - str(decimal_unpack(decimal_pack(2.718281828459045)) == 2.718281828459045
-    ok 57 - decimal_len(-2.718281828459045)
-    ok 58 - decimal_len(-2.718281828459045) == len(decimal_pack(-2.718281828459045)
-    ok 59 - decimal_unpack(decimal_pack(-2.718281828459045))
-    ok 60 - decimal_unpack(decimal_pack(-2.718281828459045)) len
-    ok 61 - decimal_unpack(decimal_pack(-2.718281828459045)) value
-    ok 62 - decimal_unpack(decimal_pack(-2.718281828459045)) scale
-    ok 63 - decimal_unpack(decimal_pack(-2.718281828459045)) precision
-    ok 64 - str(decimal_unpack(decimal_pack(-2.718281828459045)) == -2.718281828459045
-    ok 65 - decimal_len(3.141592653589793)
-    ok 66 - decimal_len(3.141592653589793) == len(decimal_pack(3.141592653589793)
-    ok 67 - decimal_unpack(decimal_pack(3.141592653589793))
-    ok 68 - decimal_unpack(decimal_pack(3.141592653589793)) len
-    ok 69 - decimal_unpack(decimal_pack(3.141592653589793)) value
-    ok 70 - decimal_unpack(decimal_pack(3.141592653589793)) scale
-    ok 71 - decimal_unpack(decimal_pack(3.141592653589793)) precision
-    ok 72 - str(decimal_unpack(decimal_pack(3.141592653589793)) == 3.141592653589793
-    ok 73 - decimal_len(-3.141592653589793)
-    ok 74 - decimal_len(-3.141592653589793) == len(decimal_pack(-3.141592653589793)
-    ok 75 - decimal_unpack(decimal_pack(-3.141592653589793))
-    ok 76 - decimal_unpack(decimal_pack(-3.141592653589793)) len
-    ok 77 - decimal_unpack(decimal_pack(-3.141592653589793)) value
-    ok 78 - decimal_unpack(decimal_pack(-3.141592653589793)) scale
-    ok 79 - decimal_unpack(decimal_pack(-3.141592653589793)) precision
-    ok 80 - str(decimal_unpack(decimal_pack(-3.141592653589793)) == -3.141592653589793
-    ok 81 - decimal_len(1234567891234567890.0987654321987654321)
-    ok 82 - decimal_len(1234567891234567890.0987654321987654321) == len(decimal_pack(1234567891234567890.0987654321987654321)
-    ok 83 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321))
-    ok 84 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) len
-    ok 85 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) value
-    ok 86 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) scale
-    ok 87 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) precision
-    ok 88 - str(decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) == 1234567891234567890.0987654321987654321
-    ok 89 - decimal_len(-1234567891234567890.0987654321987654321)
-    ok 90 - decimal_len(-1234567891234567890.0987654321987654321) == len(decimal_pack(-1234567891234567890.0987654321987654321)
-    ok 91 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321))
-    ok 92 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) len
-    ok 93 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) value
-    ok 94 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) scale
-    ok 95 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) precision
-    ok 96 - str(decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) == -1234567891234567890.0987654321987654321
-    ok 97 - decimal_len(0.0000000000000000000000000000000000001)
-    ok 98 - decimal_len(0.0000000000000000000000000000000000001) == len(decimal_pack(0.0000000000000000000000000000000000001)
-    ok 99 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001))
-    ok 100 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) len
-    ok 101 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) value
-    ok 102 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) scale
-    ok 103 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) precision
-    ok 104 - str(decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) == 0.0000000000000000000000000000000000001
-    ok 105 - decimal_len(-0.0000000000000000000000000000000000001)
-    ok 106 - decimal_len(-0.0000000000000000000000000000000000001) == len(decimal_pack(-0.0000000000000000000000000000000000001)
-    ok 107 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001))
-    ok 108 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) len
-    ok 109 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) value
-    ok 110 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) scale
-    ok 111 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) precision
-    ok 112 - str(decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) == -0.0000000000000000000000000000000000001
-    ok 113 - decimal_len(0.00000000000000000000000000000000000001)
-    ok 114 - decimal_len(0.00000000000000000000000000000000000001) == len(decimal_pack(0.00000000000000000000000000000000000001)
-    ok 115 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001))
-    ok 116 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) len
-    ok 117 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) value
-    ok 118 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) scale
-    ok 119 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) precision
-    ok 120 - str(decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) == 0.00000000000000000000000000000000000001
-    ok 121 - decimal_len(-0.00000000000000000000000000000000000001)
-    ok 122 - decimal_len(-0.00000000000000000000000000000000000001) == len(decimal_pack(-0.00000000000000000000000000000000000001)
-    ok 123 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001))
-    ok 124 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) len
-    ok 125 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) value
-    ok 126 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) scale
-    ok 127 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) precision
-    ok 128 - str(decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) == -0.00000000000000000000000000000000000001
-    ok 129 - decimal_len(99999999999999999999999999999999999999)
-    ok 130 - decimal_len(99999999999999999999999999999999999999) == len(decimal_pack(99999999999999999999999999999999999999)
-    ok 131 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999))
-    ok 132 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) len
-    ok 133 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) value
-    ok 134 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) scale
-    ok 135 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) precision
-    ok 136 - str(decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) == 99999999999999999999999999999999999999
-    ok 137 - decimal_len(-99999999999999999999999999999999999999)
-    ok 138 - decimal_len(-99999999999999999999999999999999999999) == len(decimal_pack(-99999999999999999999999999999999999999)
-    ok 139 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999))
-    ok 140 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) len
-    ok 141 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) value
-    ok 142 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) scale
-    ok 143 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) precision
-    ok 144 - str(decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) == -99999999999999999999999999999999999999
-    ok 145 - unpack malformed decimal fails
-    ok 146 - decode malformed decimal preserves buffer position
+    ok 9 - mp_sizeof_decimal(0)
+    ok 10 - mp_sizeof_decimal(0) == len(mp_encode_decimal(0))
+    ok 11 - mp_next(mp_encode(0))
+    ok 12 - mp_decode(mp_encode(0) len
+    ok 13 - mp_decode(mp_encode(0)) value
+    ok 14 - mp_decode(mp_encode(0)) scale
+    ok 15 - str(mp_decode(mp_encode(0))) == 0
+    ok 16 - mp_ext_type is MP_DECIMAL
+    ok 17 - decimal_unpack() after mp_decode_extl()
+    ok 18 - decimal_unpack() after mp_decode_extl() value
+    ok 19 - decimal_unpack() after mp_decode_extl() len
+    ok 20 - decimal_len(-0)
+    ok 21 - decimal_len(-0) == len(decimal_pack(-0)
+    ok 22 - decimal_unpack(decimal_pack(-0))
+    ok 23 - decimal_unpack(decimal_pack(-0)) len
+    ok 24 - decimal_unpack(decimal_pack(-0)) value
+    ok 25 - decimal_unpack(decimal_pack(-0)) scale
+    ok 26 - decimal_unpack(decimal_pack(-0)) precision
+    ok 27 - str(decimal_unpack(decimal_pack(-0)) == -0
+    ok 28 - mp_sizeof_decimal(-0)
+    ok 29 - mp_sizeof_decimal(-0) == len(mp_encode_decimal(-0))
+    ok 30 - mp_next(mp_encode(-0))
+    ok 31 - mp_decode(mp_encode(-0) len
+    ok 32 - mp_decode(mp_encode(-0)) value
+    ok 33 - mp_decode(mp_encode(-0)) scale
+    ok 34 - str(mp_decode(mp_encode(-0))) == -0
+    ok 35 - mp_ext_type is MP_DECIMAL
+    ok 36 - decimal_unpack() after mp_decode_extl()
+    ok 37 - decimal_unpack() after mp_decode_extl() value
+    ok 38 - decimal_unpack() after mp_decode_extl() len
+    ok 39 - decimal_len(1)
+    ok 40 - decimal_len(1) == len(decimal_pack(1)
+    ok 41 - decimal_unpack(decimal_pack(1))
+    ok 42 - decimal_unpack(decimal_pack(1)) len
+    ok 43 - decimal_unpack(decimal_pack(1)) value
+    ok 44 - decimal_unpack(decimal_pack(1)) scale
+    ok 45 - decimal_unpack(decimal_pack(1)) precision
+    ok 46 - str(decimal_unpack(decimal_pack(1)) == 1
+    ok 47 - mp_sizeof_decimal(1)
+    ok 48 - mp_sizeof_decimal(1) == len(mp_encode_decimal(1))
+    ok 49 - mp_next(mp_encode(1))
+    ok 50 - mp_decode(mp_encode(1) len
+    ok 51 - mp_decode(mp_encode(1)) value
+    ok 52 - mp_decode(mp_encode(1)) scale
+    ok 53 - str(mp_decode(mp_encode(1))) == 1
+    ok 54 - mp_ext_type is MP_DECIMAL
+    ok 55 - decimal_unpack() after mp_decode_extl()
+    ok 56 - decimal_unpack() after mp_decode_extl() value
+    ok 57 - decimal_unpack() after mp_decode_extl() len
+    ok 58 - decimal_len(-1)
+    ok 59 - decimal_len(-1) == len(decimal_pack(-1)
+    ok 60 - decimal_unpack(decimal_pack(-1))
+    ok 61 - decimal_unpack(decimal_pack(-1)) len
+    ok 62 - decimal_unpack(decimal_pack(-1)) value
+    ok 63 - decimal_unpack(decimal_pack(-1)) scale
+    ok 64 - decimal_unpack(decimal_pack(-1)) precision
+    ok 65 - str(decimal_unpack(decimal_pack(-1)) == -1
+    ok 66 - mp_sizeof_decimal(-1)
+    ok 67 - mp_sizeof_decimal(-1) == len(mp_encode_decimal(-1))
+    ok 68 - mp_next(mp_encode(-1))
+    ok 69 - mp_decode(mp_encode(-1) len
+    ok 70 - mp_decode(mp_encode(-1)) value
+    ok 71 - mp_decode(mp_encode(-1)) scale
+    ok 72 - str(mp_decode(mp_encode(-1))) == -1
+    ok 73 - mp_ext_type is MP_DECIMAL
+    ok 74 - decimal_unpack() after mp_decode_extl()
+    ok 75 - decimal_unpack() after mp_decode_extl() value
+    ok 76 - decimal_unpack() after mp_decode_extl() len
+    ok 77 - decimal_len(0.1)
+    ok 78 - decimal_len(0.1) == len(decimal_pack(0.1)
+    ok 79 - decimal_unpack(decimal_pack(0.1))
+    ok 80 - decimal_unpack(decimal_pack(0.1)) len
+    ok 81 - decimal_unpack(decimal_pack(0.1)) value
+    ok 82 - decimal_unpack(decimal_pack(0.1)) scale
+    ok 83 - decimal_unpack(decimal_pack(0.1)) precision
+    ok 84 - str(decimal_unpack(decimal_pack(0.1)) == 0.1
+    ok 85 - mp_sizeof_decimal(0.1)
+    ok 86 - mp_sizeof_decimal(0.1) == len(mp_encode_decimal(0.1))
+    ok 87 - mp_next(mp_encode(0.1))
+    ok 88 - mp_decode(mp_encode(0.1) len
+    ok 89 - mp_decode(mp_encode(0.1)) value
+    ok 90 - mp_decode(mp_encode(0.1)) scale
+    ok 91 - str(mp_decode(mp_encode(0.1))) == 0.1
+    ok 92 - mp_ext_type is MP_DECIMAL
+    ok 93 - decimal_unpack() after mp_decode_extl()
+    ok 94 - decimal_unpack() after mp_decode_extl() value
+    ok 95 - decimal_unpack() after mp_decode_extl() len
+    ok 96 - decimal_len(-0.1)
+    ok 97 - decimal_len(-0.1) == len(decimal_pack(-0.1)
+    ok 98 - decimal_unpack(decimal_pack(-0.1))
+    ok 99 - decimal_unpack(decimal_pack(-0.1)) len
+    ok 100 - decimal_unpack(decimal_pack(-0.1)) value
+    ok 101 - decimal_unpack(decimal_pack(-0.1)) scale
+    ok 102 - decimal_unpack(decimal_pack(-0.1)) precision
+    ok 103 - str(decimal_unpack(decimal_pack(-0.1)) == -0.1
+    ok 104 - mp_sizeof_decimal(-0.1)
+    ok 105 - mp_sizeof_decimal(-0.1) == len(mp_encode_decimal(-0.1))
+    ok 106 - mp_next(mp_encode(-0.1))
+    ok 107 - mp_decode(mp_encode(-0.1) len
+    ok 108 - mp_decode(mp_encode(-0.1)) value
+    ok 109 - mp_decode(mp_encode(-0.1)) scale
+    ok 110 - str(mp_decode(mp_encode(-0.1))) == -0.1
+    ok 111 - mp_ext_type is MP_DECIMAL
+    ok 112 - decimal_unpack() after mp_decode_extl()
+    ok 113 - decimal_unpack() after mp_decode_extl() value
+    ok 114 - decimal_unpack() after mp_decode_extl() len
+    ok 115 - decimal_len(2.718281828459045)
+    ok 116 - decimal_len(2.718281828459045) == len(decimal_pack(2.718281828459045)
+    ok 117 - decimal_unpack(decimal_pack(2.718281828459045))
+    ok 118 - decimal_unpack(decimal_pack(2.718281828459045)) len
+    ok 119 - decimal_unpack(decimal_pack(2.718281828459045)) value
+    ok 120 - decimal_unpack(decimal_pack(2.718281828459045)) scale
+    ok 121 - decimal_unpack(decimal_pack(2.718281828459045)) precision
+    ok 122 - str(decimal_unpack(decimal_pack(2.718281828459045)) == 2.718281828459045
+    ok 123 - mp_sizeof_decimal(2.718281828459045)
+    ok 124 - mp_sizeof_decimal(2.718281828459045) == len(mp_encode_decimal(2.718281828459045))
+    ok 125 - mp_next(mp_encode(2.718281828459045))
+    ok 126 - mp_decode(mp_encode(2.718281828459045) len
+    ok 127 - mp_decode(mp_encode(2.718281828459045)) value
+    ok 128 - mp_decode(mp_encode(2.718281828459045)) scale
+    ok 129 - str(mp_decode(mp_encode(2.718281828459045))) == 2.718281828459045
+    ok 130 - mp_ext_type is MP_DECIMAL
+    ok 131 - decimal_unpack() after mp_decode_extl()
+    ok 132 - decimal_unpack() after mp_decode_extl() value
+    ok 133 - decimal_unpack() after mp_decode_extl() len
+    ok 134 - decimal_len(-2.718281828459045)
+    ok 135 - decimal_len(-2.718281828459045) == len(decimal_pack(-2.718281828459045)
+    ok 136 - decimal_unpack(decimal_pack(-2.718281828459045))
+    ok 137 - decimal_unpack(decimal_pack(-2.718281828459045)) len
+    ok 138 - decimal_unpack(decimal_pack(-2.718281828459045)) value
+    ok 139 - decimal_unpack(decimal_pack(-2.718281828459045)) scale
+    ok 140 - decimal_unpack(decimal_pack(-2.718281828459045)) precision
+    ok 141 - str(decimal_unpack(decimal_pack(-2.718281828459045)) == -2.718281828459045
+    ok 142 - mp_sizeof_decimal(-2.718281828459045)
+    ok 143 - mp_sizeof_decimal(-2.718281828459045) == len(mp_encode_decimal(-2.718281828459045))
+    ok 144 - mp_next(mp_encode(-2.718281828459045))
+    ok 145 - mp_decode(mp_encode(-2.718281828459045) len
+    ok 146 - mp_decode(mp_encode(-2.718281828459045)) value
+    ok 147 - mp_decode(mp_encode(-2.718281828459045)) scale
+    ok 148 - str(mp_decode(mp_encode(-2.718281828459045))) == -2.718281828459045
+    ok 149 - mp_ext_type is MP_DECIMAL
+    ok 150 - decimal_unpack() after mp_decode_extl()
+    ok 151 - decimal_unpack() after mp_decode_extl() value
+    ok 152 - decimal_unpack() after mp_decode_extl() len
+    ok 153 - decimal_len(3.141592653589793)
+    ok 154 - decimal_len(3.141592653589793) == len(decimal_pack(3.141592653589793)
+    ok 155 - decimal_unpack(decimal_pack(3.141592653589793))
+    ok 156 - decimal_unpack(decimal_pack(3.141592653589793)) len
+    ok 157 - decimal_unpack(decimal_pack(3.141592653589793)) value
+    ok 158 - decimal_unpack(decimal_pack(3.141592653589793)) scale
+    ok 159 - decimal_unpack(decimal_pack(3.141592653589793)) precision
+    ok 160 - str(decimal_unpack(decimal_pack(3.141592653589793)) == 3.141592653589793
+    ok 161 - mp_sizeof_decimal(3.141592653589793)
+    ok 162 - mp_sizeof_decimal(3.141592653589793) == len(mp_encode_decimal(3.141592653589793))
+    ok 163 - mp_next(mp_encode(3.141592653589793))
+    ok 164 - mp_decode(mp_encode(3.141592653589793) len
+    ok 165 - mp_decode(mp_encode(3.141592653589793)) value
+    ok 166 - mp_decode(mp_encode(3.141592653589793)) scale
+    ok 167 - str(mp_decode(mp_encode(3.141592653589793))) == 3.141592653589793
+    ok 168 - mp_ext_type is MP_DECIMAL
+    ok 169 - decimal_unpack() after mp_decode_extl()
+    ok 170 - decimal_unpack() after mp_decode_extl() value
+    ok 171 - decimal_unpack() after mp_decode_extl() len
+    ok 172 - decimal_len(-3.141592653589793)
+    ok 173 - decimal_len(-3.141592653589793) == len(decimal_pack(-3.141592653589793)
+    ok 174 - decimal_unpack(decimal_pack(-3.141592653589793))
+    ok 175 - decimal_unpack(decimal_pack(-3.141592653589793)) len
+    ok 176 - decimal_unpack(decimal_pack(-3.141592653589793)) value
+    ok 177 - decimal_unpack(decimal_pack(-3.141592653589793)) scale
+    ok 178 - decimal_unpack(decimal_pack(-3.141592653589793)) precision
+    ok 179 - str(decimal_unpack(decimal_pack(-3.141592653589793)) == -3.141592653589793
+    ok 180 - mp_sizeof_decimal(-3.141592653589793)
+    ok 181 - mp_sizeof_decimal(-3.141592653589793) == len(mp_encode_decimal(-3.141592653589793))
+    ok 182 - mp_next(mp_encode(-3.141592653589793))
+    ok 183 - mp_decode(mp_encode(-3.141592653589793) len
+    ok 184 - mp_decode(mp_encode(-3.141592653589793)) value
+    ok 185 - mp_decode(mp_encode(-3.141592653589793)) scale
+    ok 186 - str(mp_decode(mp_encode(-3.141592653589793))) == -3.141592653589793
+    ok 187 - mp_ext_type is MP_DECIMAL
+    ok 188 - decimal_unpack() after mp_decode_extl()
+    ok 189 - decimal_unpack() after mp_decode_extl() value
+    ok 190 - decimal_unpack() after mp_decode_extl() len
+    ok 191 - decimal_len(1234567891234567890.0987654321987654321)
+    ok 192 - decimal_len(1234567891234567890.0987654321987654321) == len(decimal_pack(1234567891234567890.0987654321987654321)
+    ok 193 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321))
+    ok 194 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) len
+    ok 195 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) value
+    ok 196 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) scale
+    ok 197 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) precision
+    ok 198 - str(decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) == 1234567891234567890.0987654321987654321
+    ok 199 - mp_sizeof_decimal(1234567891234567890.0987654321987654321)
+    ok 200 - mp_sizeof_decimal(1234567891234567890.0987654321987654321) == len(mp_encode_decimal(1234567891234567890.0987654321987654321))
+    ok 201 - mp_next(mp_encode(1234567891234567890.0987654321987654321))
+    ok 202 - mp_decode(mp_encode(1234567891234567890.0987654321987654321) len
+    ok 203 - mp_decode(mp_encode(1234567891234567890.0987654321987654321)) value
+    ok 204 - mp_decode(mp_encode(1234567891234567890.0987654321987654321)) scale
+    ok 205 - str(mp_decode(mp_encode(1234567891234567890.0987654321987654321))) == 1234567891234567890.0987654321987654321
+    ok 206 - mp_ext_type is MP_DECIMAL
+    ok 207 - decimal_unpack() after mp_decode_extl()
+    ok 208 - decimal_unpack() after mp_decode_extl() value
+    ok 209 - decimal_unpack() after mp_decode_extl() len
+    ok 210 - decimal_len(-1234567891234567890.0987654321987654321)
+    ok 211 - decimal_len(-1234567891234567890.0987654321987654321) == len(decimal_pack(-1234567891234567890.0987654321987654321)
+    ok 212 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321))
+    ok 213 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) len
+    ok 214 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) value
+    ok 215 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) scale
+    ok 216 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) precision
+    ok 217 - str(decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) == -1234567891234567890.0987654321987654321
+    ok 218 - mp_sizeof_decimal(-1234567891234567890.0987654321987654321)
+    ok 219 - mp_sizeof_decimal(-1234567891234567890.0987654321987654321) == len(mp_encode_decimal(-1234567891234567890.0987654321987654321))
+    ok 220 - mp_next(mp_encode(-1234567891234567890.0987654321987654321))
+    ok 221 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321) len
+    ok 222 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321)) value
+    ok 223 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321)) scale
+    ok 224 - str(mp_decode(mp_encode(-1234567891234567890.0987654321987654321))) == -1234567891234567890.0987654321987654321
+    ok 225 - mp_ext_type is MP_DECIMAL
+    ok 226 - decimal_unpack() after mp_decode_extl()
+    ok 227 - decimal_unpack() after mp_decode_extl() value
+    ok 228 - decimal_unpack() after mp_decode_extl() len
+    ok 229 - decimal_len(0.0000000000000000000000000000000000001)
+    ok 230 - decimal_len(0.0000000000000000000000000000000000001) == len(decimal_pack(0.0000000000000000000000000000000000001)
+    ok 231 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001))
+    ok 232 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) len
+    ok 233 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) value
+    ok 234 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) scale
+    ok 235 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) precision
+    ok 236 - str(decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) == 0.0000000000000000000000000000000000001
+    ok 237 - mp_sizeof_decimal(0.0000000000000000000000000000000000001)
+    ok 238 - mp_sizeof_decimal(0.0000000000000000000000000000000000001) == len(mp_encode_decimal(0.0000000000000000000000000000000000001))
+    ok 239 - mp_next(mp_encode(0.0000000000000000000000000000000000001))
+    ok 240 - mp_decode(mp_encode(0.0000000000000000000000000000000000001) len
+    ok 241 - mp_decode(mp_encode(0.0000000000000000000000000000000000001)) value
+    ok 242 - mp_decode(mp_encode(0.0000000000000000000000000000000000001)) scale
+    ok 243 - str(mp_decode(mp_encode(0.0000000000000000000000000000000000001))) == 0.0000000000000000000000000000000000001
+    ok 244 - mp_ext_type is MP_DECIMAL
+    ok 245 - decimal_unpack() after mp_decode_extl()
+    ok 246 - decimal_unpack() after mp_decode_extl() value
+    ok 247 - decimal_unpack() after mp_decode_extl() len
+    ok 248 - decimal_len(-0.0000000000000000000000000000000000001)
+    ok 249 - decimal_len(-0.0000000000000000000000000000000000001) == len(decimal_pack(-0.0000000000000000000000000000000000001)
+    ok 250 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001))
+    ok 251 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) len
+    ok 252 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) value
+    ok 253 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) scale
+    ok 254 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) precision
+    ok 255 - str(decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) == -0.0000000000000000000000000000000000001
+    ok 256 - mp_sizeof_decimal(-0.0000000000000000000000000000000000001)
+    ok 257 - mp_sizeof_decimal(-0.0000000000000000000000000000000000001) == len(mp_encode_decimal(-0.0000000000000000000000000000000000001))
+    ok 258 - mp_next(mp_encode(-0.0000000000000000000000000000000000001))
+    ok 259 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001) len
+    ok 260 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001)) value
+    ok 261 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001)) scale
+    ok 262 - str(mp_decode(mp_encode(-0.0000000000000000000000000000000000001))) == -0.0000000000000000000000000000000000001
+    ok 263 - mp_ext_type is MP_DECIMAL
+    ok 264 - decimal_unpack() after mp_decode_extl()
+    ok 265 - decimal_unpack() after mp_decode_extl() value
+    ok 266 - decimal_unpack() after mp_decode_extl() len
+    ok 267 - decimal_len(0.00000000000000000000000000000000000001)
+    ok 268 - decimal_len(0.00000000000000000000000000000000000001) == len(decimal_pack(0.00000000000000000000000000000000000001)
+    ok 269 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001))
+    ok 270 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) len
+    ok 271 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) value
+    ok 272 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) scale
+    ok 273 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) precision
+    ok 274 - str(decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) == 0.00000000000000000000000000000000000001
+    ok 275 - mp_sizeof_decimal(0.00000000000000000000000000000000000001)
+    ok 276 - mp_sizeof_decimal(0.00000000000000000000000000000000000001) == len(mp_encode_decimal(0.00000000000000000000000000000000000001))
+    ok 277 - mp_next(mp_encode(0.00000000000000000000000000000000000001))
+    ok 278 - mp_decode(mp_encode(0.00000000000000000000000000000000000001) len
+    ok 279 - mp_decode(mp_encode(0.00000000000000000000000000000000000001)) value
+    ok 280 - mp_decode(mp_encode(0.00000000000000000000000000000000000001)) scale
+    ok 281 - str(mp_decode(mp_encode(0.00000000000000000000000000000000000001))) == 0.00000000000000000000000000000000000001
+    ok 282 - mp_ext_type is MP_DECIMAL
+    ok 283 - decimal_unpack() after mp_decode_extl()
+    ok 284 - decimal_unpack() after mp_decode_extl() value
+    ok 285 - decimal_unpack() after mp_decode_extl() len
+    ok 286 - decimal_len(-0.00000000000000000000000000000000000001)
+    ok 287 - decimal_len(-0.00000000000000000000000000000000000001) == len(decimal_pack(-0.00000000000000000000000000000000000001)
+    ok 288 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001))
+    ok 289 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) len
+    ok 290 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) value
+    ok 291 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) scale
+    ok 292 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) precision
+    ok 293 - str(decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) == -0.00000000000000000000000000000000000001
+    ok 294 - mp_sizeof_decimal(-0.00000000000000000000000000000000000001)
+    ok 295 - mp_sizeof_decimal(-0.00000000000000000000000000000000000001) == len(mp_encode_decimal(-0.00000000000000000000000000000000000001))
+    ok 296 - mp_next(mp_encode(-0.00000000000000000000000000000000000001))
+    ok 297 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001) len
+    ok 298 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001)) value
+    ok 299 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001)) scale
+    ok 300 - str(mp_decode(mp_encode(-0.00000000000000000000000000000000000001))) == -0.00000000000000000000000000000000000001
+    ok 301 - mp_ext_type is MP_DECIMAL
+    ok 302 - decimal_unpack() after mp_decode_extl()
+    ok 303 - decimal_unpack() after mp_decode_extl() value
+    ok 304 - decimal_unpack() after mp_decode_extl() len
+    ok 305 - decimal_len(99999999999999999999999999999999999999)
+    ok 306 - decimal_len(99999999999999999999999999999999999999) == len(decimal_pack(99999999999999999999999999999999999999)
+    ok 307 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999))
+    ok 308 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) len
+    ok 309 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) value
+    ok 310 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) scale
+    ok 311 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) precision
+    ok 312 - str(decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) == 99999999999999999999999999999999999999
+    ok 313 - mp_sizeof_decimal(99999999999999999999999999999999999999)
+    ok 314 - mp_sizeof_decimal(99999999999999999999999999999999999999) == len(mp_encode_decimal(99999999999999999999999999999999999999))
+    ok 315 - mp_next(mp_encode(99999999999999999999999999999999999999))
+    ok 316 - mp_decode(mp_encode(99999999999999999999999999999999999999) len
+    ok 317 - mp_decode(mp_encode(99999999999999999999999999999999999999)) value
+    ok 318 - mp_decode(mp_encode(99999999999999999999999999999999999999)) scale
+    ok 319 - str(mp_decode(mp_encode(99999999999999999999999999999999999999))) == 99999999999999999999999999999999999999
+    ok 320 - mp_ext_type is MP_DECIMAL
+    ok 321 - decimal_unpack() after mp_decode_extl()
+    ok 322 - decimal_unpack() after mp_decode_extl() value
+    ok 323 - decimal_unpack() after mp_decode_extl() len
+    ok 324 - decimal_len(-99999999999999999999999999999999999999)
+    ok 325 - decimal_len(-99999999999999999999999999999999999999) == len(decimal_pack(-99999999999999999999999999999999999999)
+    ok 326 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999))
+    ok 327 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) len
+    ok 328 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) value
+    ok 329 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) scale
+    ok 330 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) precision
+    ok 331 - str(decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) == -99999999999999999999999999999999999999
+    ok 332 - mp_sizeof_decimal(-99999999999999999999999999999999999999)
+    ok 333 - mp_sizeof_decimal(-99999999999999999999999999999999999999) == len(mp_encode_decimal(-99999999999999999999999999999999999999))
+    ok 334 - mp_next(mp_encode(-99999999999999999999999999999999999999))
+    ok 335 - mp_decode(mp_encode(-99999999999999999999999999999999999999) len
+    ok 336 - mp_decode(mp_encode(-99999999999999999999999999999999999999)) value
+    ok 337 - mp_decode(mp_encode(-99999999999999999999999999999999999999)) scale
+    ok 338 - str(mp_decode(mp_encode(-99999999999999999999999999999999999999))) == -99999999999999999999999999999999999999
+    ok 339 - mp_ext_type is MP_DECIMAL
+    ok 340 - decimal_unpack() after mp_decode_extl()
+    ok 341 - decimal_unpack() after mp_decode_extl() value
+    ok 342 - decimal_unpack() after mp_decode_extl() len
+    ok 343 - unpack malformed decimal fails
+    ok 344 - decode malformed decimal preserves buffer position
 ok 258 - subtests
-- 
2.20.1 (Apple Git-117)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] lib: update msgpuck library
  2019-06-21  9:02 ` [PATCH 1/3] lib: update msgpuck library Serge Petrenko
@ 2019-06-21 16:00   ` Vladimir Davydov
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Davydov @ 2019-06-21 16:00 UTC (permalink / raw)
  To: Serge Petrenko; +Cc: tarantool-patches

Pushed to master.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len()
  2019-06-21  9:02 ` [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len() Serge Petrenko
@ 2019-06-21 16:00   ` Vladimir Davydov
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Davydov @ 2019-06-21 16:00 UTC (permalink / raw)
  To: Serge Petrenko; +Cc: tarantool-patches

Pushed to master.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack
  2019-06-21  9:02 ` [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack Serge Petrenko
@ 2019-06-24  8:35   ` Vladimir Davydov
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Davydov @ 2019-06-24  8:35 UTC (permalink / raw)
  To: Serge Petrenko; +Cc: tarantool-patches

On Fri, Jun 21, 2019 at 12:02:07PM +0300, Serge Petrenko wrote:
> This patch adds the methods necessary to encode and decode decimals to
> MsgPack. MsgPack EXT type (MP_EXT) together with a new extension type
> MP_DECIMAL is used as a record header.
> 
> The decimal MsgPack representation looks like this:
> +--------+-------------------+------------+===============+
> | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
> +--------+-------------------+------------+===============+
> The whole record may be encoded and decoded with
> mp_encode_decimal() and mp_decode_decimal(). This is equivalent to
> performing mp_encode_extl()/mp_decode_extl() on the first 3 fields and
> decimal_pack/unpack() on the PackedDecimal field.
> 
> Part of #692
> ---
>  src/lib/core/CMakeLists.txt  |   1 +
>  src/lib/core/mp_decimal.c    |  72 ++++++
>  src/lib/core/mp_decimal.h    |  62 +++++
>  src/lib/core/mp_user_types.h |  38 +++
>  test/unit/decimal.c          |  33 ++-
>  test/unit/decimal.result     | 476 +++++++++++++++++++++++++----------
>  6 files changed, 542 insertions(+), 140 deletions(-)
>  create mode 100644 src/lib/core/mp_decimal.c
>  create mode 100644 src/lib/core/mp_decimal.h
>  create mode 100644 src/lib/core/mp_user_types.h
> 
> diff --git a/src/lib/core/CMakeLists.txt b/src/lib/core/CMakeLists.txt
> index 66e430a25..e0a717aa3 100644
> --- a/src/lib/core/CMakeLists.txt
> +++ b/src/lib/core/CMakeLists.txt
> @@ -27,6 +27,7 @@ set(core_sources
>      mpstream.c
>      port.c
>      decimal.c
> +    mp_decimal.c
>  )
>  
>  if (TARGET_OS_NETBSD)
> diff --git a/src/lib/core/mp_decimal.c b/src/lib/core/mp_decimal.c
> new file mode 100644
> index 000000000..1bcf316fa
> --- /dev/null
> +++ b/src/lib/core/mp_decimal.c
> @@ -0,0 +1,72 @@
> +/*
> + * Copyright 2019, Tarantool AUTHORS, please see AUTHORS file.
> + *
> + * Redistribution and use in source and binary forms, with or
> + * without modification, are permitted provided that the following
> + * conditions are met:
> + *
> + * 1. Redistributions of source code must retain the above
> + *    copyright notice, this list of conditions and the
> + *    following disclaimer.
> + *
> + * 2. Redistributions in binary form must reproduce the above
> + *    copyright notice, this list of conditions and the following
> + *    disclaimer in the documentation and/or other materials
> + *    provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
> + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
> + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
> + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include "mp_decimal.h"
> +#include "mp_user_types.h"
> +#include "msgpuck.h"
> +#include "decimal.h"
> +
> +uint32_t
> +mp_sizeof_decimal(const decimal_t *dec)

I think we should make all these functions inline - when we introduce
decimal indexing they will be used pretty often.

> +{
> +	return mp_sizeof_ext(decimal_len(dec));
> +}
> +
> +decimal_t *
> +mp_decode_decimal(const char **data, decimal_t *dec)
> +{
> +	if (mp_typeof(**data) != MP_EXT)
> +		return NULL;

Hmm, other mp_ methods use assertions instead. Shouldn't we?

Anyway, come to think of it, without seeing how these functions are
actually used, I can't say whether the API is good or bad. Let's
postpone this patch until we introduce decimal field comparators.

> diff --git a/test/unit/decimal.result b/test/unit/decimal.result
> index 051dc7960..21df301b9 100644
> --- a/test/unit/decimal.result
> +++ b/test/unit/decimal.result
> @@ -256,7 +256,7 @@ ok 254 - decimal_mul(1e19, 1e19) - overflow
>  ok 255 - decimal_from_string(1e19)
>  ok 256 - decimal_from_string(1e-19)
>  ok 257 - decimal_div(1e19, 1e-19) - overflow
> -    1..146
> +    1..344
>      ok 1 - decimal_len(0)
>      ok 2 - decimal_len(0) == len(decimal_pack(0)
>      ok 3 - decimal_unpack(decimal_pack(0))
> @@ -265,142 +265,340 @@ ok 257 - decimal_div(1e19, 1e-19) - overflow
>      ok 6 - decimal_unpack(decimal_pack(0)) scale
>      ok 7 - decimal_unpack(decimal_pack(0)) precision
>      ok 8 - str(decimal_unpack(decimal_pack(0)) == 0
> -    ok 9 - decimal_len(-0)
> -    ok 10 - decimal_len(-0) == len(decimal_pack(-0)
> -    ok 11 - decimal_unpack(decimal_pack(-0))
> -    ok 12 - decimal_unpack(decimal_pack(-0)) len
> -    ok 13 - decimal_unpack(decimal_pack(-0)) value
> -    ok 14 - decimal_unpack(decimal_pack(-0)) scale
> -    ok 15 - decimal_unpack(decimal_pack(-0)) precision
> -    ok 16 - str(decimal_unpack(decimal_pack(-0)) == -0
> -    ok 17 - decimal_len(1)

When you submit the patch next time, please rework the test so that you
don't have to delete half of the result file. Design it in such a way
that you only add new lines.

> -    ok 18 - decimal_len(1) == len(decimal_pack(1)
> -    ok 19 - decimal_unpack(decimal_pack(1))
> -    ok 20 - decimal_unpack(decimal_pack(1)) len
> -    ok 21 - decimal_unpack(decimal_pack(1)) value
> -    ok 22 - decimal_unpack(decimal_pack(1)) scale
> -    ok 23 - decimal_unpack(decimal_pack(1)) precision
> -    ok 24 - str(decimal_unpack(decimal_pack(1)) == 1
> -    ok 25 - decimal_len(-1)
> -    ok 26 - decimal_len(-1) == len(decimal_pack(-1)
> -    ok 27 - decimal_unpack(decimal_pack(-1))
> -    ok 28 - decimal_unpack(decimal_pack(-1)) len
> -    ok 29 - decimal_unpack(decimal_pack(-1)) value
> -    ok 30 - decimal_unpack(decimal_pack(-1)) scale
> -    ok 31 - decimal_unpack(decimal_pack(-1)) precision
> -    ok 32 - str(decimal_unpack(decimal_pack(-1)) == -1
> -    ok 33 - decimal_len(0.1)
> -    ok 34 - decimal_len(0.1) == len(decimal_pack(0.1)
> -    ok 35 - decimal_unpack(decimal_pack(0.1))
> -    ok 36 - decimal_unpack(decimal_pack(0.1)) len
> -    ok 37 - decimal_unpack(decimal_pack(0.1)) value
> -    ok 38 - decimal_unpack(decimal_pack(0.1)) scale
> -    ok 39 - decimal_unpack(decimal_pack(0.1)) precision
> -    ok 40 - str(decimal_unpack(decimal_pack(0.1)) == 0.1
> -    ok 41 - decimal_len(-0.1)
> -    ok 42 - decimal_len(-0.1) == len(decimal_pack(-0.1)
> -    ok 43 - decimal_unpack(decimal_pack(-0.1))
> -    ok 44 - decimal_unpack(decimal_pack(-0.1)) len
> -    ok 45 - decimal_unpack(decimal_pack(-0.1)) value
> -    ok 46 - decimal_unpack(decimal_pack(-0.1)) scale
> -    ok 47 - decimal_unpack(decimal_pack(-0.1)) precision
> -    ok 48 - str(decimal_unpack(decimal_pack(-0.1)) == -0.1
> -    ok 49 - decimal_len(2.718281828459045)
> -    ok 50 - decimal_len(2.718281828459045) == len(decimal_pack(2.718281828459045)
> -    ok 51 - decimal_unpack(decimal_pack(2.718281828459045))
> -    ok 52 - decimal_unpack(decimal_pack(2.718281828459045)) len
> -    ok 53 - decimal_unpack(decimal_pack(2.718281828459045)) value
> -    ok 54 - decimal_unpack(decimal_pack(2.718281828459045)) scale
> -    ok 55 - decimal_unpack(decimal_pack(2.718281828459045)) precision
> -    ok 56 - str(decimal_unpack(decimal_pack(2.718281828459045)) == 2.718281828459045
> -    ok 57 - decimal_len(-2.718281828459045)
> -    ok 58 - decimal_len(-2.718281828459045) == len(decimal_pack(-2.718281828459045)
> -    ok 59 - decimal_unpack(decimal_pack(-2.718281828459045))
> -    ok 60 - decimal_unpack(decimal_pack(-2.718281828459045)) len
> -    ok 61 - decimal_unpack(decimal_pack(-2.718281828459045)) value
> -    ok 62 - decimal_unpack(decimal_pack(-2.718281828459045)) scale
> -    ok 63 - decimal_unpack(decimal_pack(-2.718281828459045)) precision
> -    ok 64 - str(decimal_unpack(decimal_pack(-2.718281828459045)) == -2.718281828459045
> -    ok 65 - decimal_len(3.141592653589793)
> -    ok 66 - decimal_len(3.141592653589793) == len(decimal_pack(3.141592653589793)
> -    ok 67 - decimal_unpack(decimal_pack(3.141592653589793))
> -    ok 68 - decimal_unpack(decimal_pack(3.141592653589793)) len
> -    ok 69 - decimal_unpack(decimal_pack(3.141592653589793)) value
> -    ok 70 - decimal_unpack(decimal_pack(3.141592653589793)) scale
> -    ok 71 - decimal_unpack(decimal_pack(3.141592653589793)) precision
> -    ok 72 - str(decimal_unpack(decimal_pack(3.141592653589793)) == 3.141592653589793
> -    ok 73 - decimal_len(-3.141592653589793)
> -    ok 74 - decimal_len(-3.141592653589793) == len(decimal_pack(-3.141592653589793)
> -    ok 75 - decimal_unpack(decimal_pack(-3.141592653589793))
> -    ok 76 - decimal_unpack(decimal_pack(-3.141592653589793)) len
> -    ok 77 - decimal_unpack(decimal_pack(-3.141592653589793)) value
> -    ok 78 - decimal_unpack(decimal_pack(-3.141592653589793)) scale
> -    ok 79 - decimal_unpack(decimal_pack(-3.141592653589793)) precision
> -    ok 80 - str(decimal_unpack(decimal_pack(-3.141592653589793)) == -3.141592653589793
> -    ok 81 - decimal_len(1234567891234567890.0987654321987654321)
> -    ok 82 - decimal_len(1234567891234567890.0987654321987654321) == len(decimal_pack(1234567891234567890.0987654321987654321)
> -    ok 83 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321))
> -    ok 84 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) len
> -    ok 85 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) value
> -    ok 86 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) scale
> -    ok 87 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) precision
> -    ok 88 - str(decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) == 1234567891234567890.0987654321987654321
> -    ok 89 - decimal_len(-1234567891234567890.0987654321987654321)
> -    ok 90 - decimal_len(-1234567891234567890.0987654321987654321) == len(decimal_pack(-1234567891234567890.0987654321987654321)
> -    ok 91 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321))
> -    ok 92 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) len
> -    ok 93 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) value
> -    ok 94 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) scale
> -    ok 95 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) precision
> -    ok 96 - str(decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) == -1234567891234567890.0987654321987654321
> -    ok 97 - decimal_len(0.0000000000000000000000000000000000001)
> -    ok 98 - decimal_len(0.0000000000000000000000000000000000001) == len(decimal_pack(0.0000000000000000000000000000000000001)
> -    ok 99 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001))
> -    ok 100 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) len
> -    ok 101 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) value
> -    ok 102 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) scale
> -    ok 103 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) precision
> -    ok 104 - str(decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) == 0.0000000000000000000000000000000000001
> -    ok 105 - decimal_len(-0.0000000000000000000000000000000000001)
> -    ok 106 - decimal_len(-0.0000000000000000000000000000000000001) == len(decimal_pack(-0.0000000000000000000000000000000000001)
> -    ok 107 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001))
> -    ok 108 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) len
> -    ok 109 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) value
> -    ok 110 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) scale
> -    ok 111 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) precision
> -    ok 112 - str(decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) == -0.0000000000000000000000000000000000001
> -    ok 113 - decimal_len(0.00000000000000000000000000000000000001)
> -    ok 114 - decimal_len(0.00000000000000000000000000000000000001) == len(decimal_pack(0.00000000000000000000000000000000000001)
> -    ok 115 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001))
> -    ok 116 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) len
> -    ok 117 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) value
> -    ok 118 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) scale
> -    ok 119 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) precision
> -    ok 120 - str(decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) == 0.00000000000000000000000000000000000001
> -    ok 121 - decimal_len(-0.00000000000000000000000000000000000001)
> -    ok 122 - decimal_len(-0.00000000000000000000000000000000000001) == len(decimal_pack(-0.00000000000000000000000000000000000001)
> -    ok 123 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001))
> -    ok 124 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) len
> -    ok 125 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) value
> -    ok 126 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) scale
> -    ok 127 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) precision
> -    ok 128 - str(decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) == -0.00000000000000000000000000000000000001
> -    ok 129 - decimal_len(99999999999999999999999999999999999999)
> -    ok 130 - decimal_len(99999999999999999999999999999999999999) == len(decimal_pack(99999999999999999999999999999999999999)
> -    ok 131 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999))
> -    ok 132 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) len
> -    ok 133 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) value
> -    ok 134 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) scale
> -    ok 135 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) precision
> -    ok 136 - str(decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) == 99999999999999999999999999999999999999
> -    ok 137 - decimal_len(-99999999999999999999999999999999999999)
> -    ok 138 - decimal_len(-99999999999999999999999999999999999999) == len(decimal_pack(-99999999999999999999999999999999999999)
> -    ok 139 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999))
> -    ok 140 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) len
> -    ok 141 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) value
> -    ok 142 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) scale
> -    ok 143 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) precision
> -    ok 144 - str(decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) == -99999999999999999999999999999999999999
> -    ok 145 - unpack malformed decimal fails
> -    ok 146 - decode malformed decimal preserves buffer position
> +    ok 9 - mp_sizeof_decimal(0)
> +    ok 10 - mp_sizeof_decimal(0) == len(mp_encode_decimal(0))
> +    ok 11 - mp_next(mp_encode(0))
> +    ok 12 - mp_decode(mp_encode(0) len
> +    ok 13 - mp_decode(mp_encode(0)) value
> +    ok 14 - mp_decode(mp_encode(0)) scale
> +    ok 15 - str(mp_decode(mp_encode(0))) == 0
> +    ok 16 - mp_ext_type is MP_DECIMAL
> +    ok 17 - decimal_unpack() after mp_decode_extl()
> +    ok 18 - decimal_unpack() after mp_decode_extl() value
> +    ok 19 - decimal_unpack() after mp_decode_extl() len
> +    ok 20 - decimal_len(-0)
> +    ok 21 - decimal_len(-0) == len(decimal_pack(-0)
> +    ok 22 - decimal_unpack(decimal_pack(-0))
> +    ok 23 - decimal_unpack(decimal_pack(-0)) len
> +    ok 24 - decimal_unpack(decimal_pack(-0)) value
> +    ok 25 - decimal_unpack(decimal_pack(-0)) scale
> +    ok 26 - decimal_unpack(decimal_pack(-0)) precision
> +    ok 27 - str(decimal_unpack(decimal_pack(-0)) == -0
> +    ok 28 - mp_sizeof_decimal(-0)
> +    ok 29 - mp_sizeof_decimal(-0) == len(mp_encode_decimal(-0))
> +    ok 30 - mp_next(mp_encode(-0))
> +    ok 31 - mp_decode(mp_encode(-0) len
> +    ok 32 - mp_decode(mp_encode(-0)) value
> +    ok 33 - mp_decode(mp_encode(-0)) scale
> +    ok 34 - str(mp_decode(mp_encode(-0))) == -0
> +    ok 35 - mp_ext_type is MP_DECIMAL
> +    ok 36 - decimal_unpack() after mp_decode_extl()
> +    ok 37 - decimal_unpack() after mp_decode_extl() value
> +    ok 38 - decimal_unpack() after mp_decode_extl() len
> +    ok 39 - decimal_len(1)
> +    ok 40 - decimal_len(1) == len(decimal_pack(1)
> +    ok 41 - decimal_unpack(decimal_pack(1))
> +    ok 42 - decimal_unpack(decimal_pack(1)) len
> +    ok 43 - decimal_unpack(decimal_pack(1)) value
> +    ok 44 - decimal_unpack(decimal_pack(1)) scale
> +    ok 45 - decimal_unpack(decimal_pack(1)) precision
> +    ok 46 - str(decimal_unpack(decimal_pack(1)) == 1
> +    ok 47 - mp_sizeof_decimal(1)
> +    ok 48 - mp_sizeof_decimal(1) == len(mp_encode_decimal(1))
> +    ok 49 - mp_next(mp_encode(1))
> +    ok 50 - mp_decode(mp_encode(1) len
> +    ok 51 - mp_decode(mp_encode(1)) value
> +    ok 52 - mp_decode(mp_encode(1)) scale
> +    ok 53 - str(mp_decode(mp_encode(1))) == 1
> +    ok 54 - mp_ext_type is MP_DECIMAL
> +    ok 55 - decimal_unpack() after mp_decode_extl()
> +    ok 56 - decimal_unpack() after mp_decode_extl() value
> +    ok 57 - decimal_unpack() after mp_decode_extl() len
> +    ok 58 - decimal_len(-1)
> +    ok 59 - decimal_len(-1) == len(decimal_pack(-1)
> +    ok 60 - decimal_unpack(decimal_pack(-1))
> +    ok 61 - decimal_unpack(decimal_pack(-1)) len
> +    ok 62 - decimal_unpack(decimal_pack(-1)) value
> +    ok 63 - decimal_unpack(decimal_pack(-1)) scale
> +    ok 64 - decimal_unpack(decimal_pack(-1)) precision
> +    ok 65 - str(decimal_unpack(decimal_pack(-1)) == -1
> +    ok 66 - mp_sizeof_decimal(-1)
> +    ok 67 - mp_sizeof_decimal(-1) == len(mp_encode_decimal(-1))
> +    ok 68 - mp_next(mp_encode(-1))
> +    ok 69 - mp_decode(mp_encode(-1) len
> +    ok 70 - mp_decode(mp_encode(-1)) value
> +    ok 71 - mp_decode(mp_encode(-1)) scale
> +    ok 72 - str(mp_decode(mp_encode(-1))) == -1
> +    ok 73 - mp_ext_type is MP_DECIMAL
> +    ok 74 - decimal_unpack() after mp_decode_extl()
> +    ok 75 - decimal_unpack() after mp_decode_extl() value
> +    ok 76 - decimal_unpack() after mp_decode_extl() len
> +    ok 77 - decimal_len(0.1)
> +    ok 78 - decimal_len(0.1) == len(decimal_pack(0.1)
> +    ok 79 - decimal_unpack(decimal_pack(0.1))
> +    ok 80 - decimal_unpack(decimal_pack(0.1)) len
> +    ok 81 - decimal_unpack(decimal_pack(0.1)) value
> +    ok 82 - decimal_unpack(decimal_pack(0.1)) scale
> +    ok 83 - decimal_unpack(decimal_pack(0.1)) precision
> +    ok 84 - str(decimal_unpack(decimal_pack(0.1)) == 0.1
> +    ok 85 - mp_sizeof_decimal(0.1)
> +    ok 86 - mp_sizeof_decimal(0.1) == len(mp_encode_decimal(0.1))
> +    ok 87 - mp_next(mp_encode(0.1))
> +    ok 88 - mp_decode(mp_encode(0.1) len
> +    ok 89 - mp_decode(mp_encode(0.1)) value
> +    ok 90 - mp_decode(mp_encode(0.1)) scale
> +    ok 91 - str(mp_decode(mp_encode(0.1))) == 0.1
> +    ok 92 - mp_ext_type is MP_DECIMAL
> +    ok 93 - decimal_unpack() after mp_decode_extl()
> +    ok 94 - decimal_unpack() after mp_decode_extl() value
> +    ok 95 - decimal_unpack() after mp_decode_extl() len
> +    ok 96 - decimal_len(-0.1)
> +    ok 97 - decimal_len(-0.1) == len(decimal_pack(-0.1)
> +    ok 98 - decimal_unpack(decimal_pack(-0.1))
> +    ok 99 - decimal_unpack(decimal_pack(-0.1)) len
> +    ok 100 - decimal_unpack(decimal_pack(-0.1)) value
> +    ok 101 - decimal_unpack(decimal_pack(-0.1)) scale
> +    ok 102 - decimal_unpack(decimal_pack(-0.1)) precision
> +    ok 103 - str(decimal_unpack(decimal_pack(-0.1)) == -0.1
> +    ok 104 - mp_sizeof_decimal(-0.1)
> +    ok 105 - mp_sizeof_decimal(-0.1) == len(mp_encode_decimal(-0.1))
> +    ok 106 - mp_next(mp_encode(-0.1))
> +    ok 107 - mp_decode(mp_encode(-0.1) len
> +    ok 108 - mp_decode(mp_encode(-0.1)) value
> +    ok 109 - mp_decode(mp_encode(-0.1)) scale
> +    ok 110 - str(mp_decode(mp_encode(-0.1))) == -0.1
> +    ok 111 - mp_ext_type is MP_DECIMAL
> +    ok 112 - decimal_unpack() after mp_decode_extl()
> +    ok 113 - decimal_unpack() after mp_decode_extl() value
> +    ok 114 - decimal_unpack() after mp_decode_extl() len
> +    ok 115 - decimal_len(2.718281828459045)
> +    ok 116 - decimal_len(2.718281828459045) == len(decimal_pack(2.718281828459045)
> +    ok 117 - decimal_unpack(decimal_pack(2.718281828459045))
> +    ok 118 - decimal_unpack(decimal_pack(2.718281828459045)) len
> +    ok 119 - decimal_unpack(decimal_pack(2.718281828459045)) value
> +    ok 120 - decimal_unpack(decimal_pack(2.718281828459045)) scale
> +    ok 121 - decimal_unpack(decimal_pack(2.718281828459045)) precision
> +    ok 122 - str(decimal_unpack(decimal_pack(2.718281828459045)) == 2.718281828459045
> +    ok 123 - mp_sizeof_decimal(2.718281828459045)
> +    ok 124 - mp_sizeof_decimal(2.718281828459045) == len(mp_encode_decimal(2.718281828459045))
> +    ok 125 - mp_next(mp_encode(2.718281828459045))
> +    ok 126 - mp_decode(mp_encode(2.718281828459045) len
> +    ok 127 - mp_decode(mp_encode(2.718281828459045)) value
> +    ok 128 - mp_decode(mp_encode(2.718281828459045)) scale
> +    ok 129 - str(mp_decode(mp_encode(2.718281828459045))) == 2.718281828459045
> +    ok 130 - mp_ext_type is MP_DECIMAL
> +    ok 131 - decimal_unpack() after mp_decode_extl()
> +    ok 132 - decimal_unpack() after mp_decode_extl() value
> +    ok 133 - decimal_unpack() after mp_decode_extl() len
> +    ok 134 - decimal_len(-2.718281828459045)
> +    ok 135 - decimal_len(-2.718281828459045) == len(decimal_pack(-2.718281828459045)
> +    ok 136 - decimal_unpack(decimal_pack(-2.718281828459045))
> +    ok 137 - decimal_unpack(decimal_pack(-2.718281828459045)) len
> +    ok 138 - decimal_unpack(decimal_pack(-2.718281828459045)) value
> +    ok 139 - decimal_unpack(decimal_pack(-2.718281828459045)) scale
> +    ok 140 - decimal_unpack(decimal_pack(-2.718281828459045)) precision
> +    ok 141 - str(decimal_unpack(decimal_pack(-2.718281828459045)) == -2.718281828459045
> +    ok 142 - mp_sizeof_decimal(-2.718281828459045)
> +    ok 143 - mp_sizeof_decimal(-2.718281828459045) == len(mp_encode_decimal(-2.718281828459045))
> +    ok 144 - mp_next(mp_encode(-2.718281828459045))
> +    ok 145 - mp_decode(mp_encode(-2.718281828459045) len
> +    ok 146 - mp_decode(mp_encode(-2.718281828459045)) value
> +    ok 147 - mp_decode(mp_encode(-2.718281828459045)) scale
> +    ok 148 - str(mp_decode(mp_encode(-2.718281828459045))) == -2.718281828459045
> +    ok 149 - mp_ext_type is MP_DECIMAL
> +    ok 150 - decimal_unpack() after mp_decode_extl()
> +    ok 151 - decimal_unpack() after mp_decode_extl() value
> +    ok 152 - decimal_unpack() after mp_decode_extl() len
> +    ok 153 - decimal_len(3.141592653589793)
> +    ok 154 - decimal_len(3.141592653589793) == len(decimal_pack(3.141592653589793)
> +    ok 155 - decimal_unpack(decimal_pack(3.141592653589793))
> +    ok 156 - decimal_unpack(decimal_pack(3.141592653589793)) len
> +    ok 157 - decimal_unpack(decimal_pack(3.141592653589793)) value
> +    ok 158 - decimal_unpack(decimal_pack(3.141592653589793)) scale
> +    ok 159 - decimal_unpack(decimal_pack(3.141592653589793)) precision
> +    ok 160 - str(decimal_unpack(decimal_pack(3.141592653589793)) == 3.141592653589793
> +    ok 161 - mp_sizeof_decimal(3.141592653589793)
> +    ok 162 - mp_sizeof_decimal(3.141592653589793) == len(mp_encode_decimal(3.141592653589793))
> +    ok 163 - mp_next(mp_encode(3.141592653589793))
> +    ok 164 - mp_decode(mp_encode(3.141592653589793) len
> +    ok 165 - mp_decode(mp_encode(3.141592653589793)) value
> +    ok 166 - mp_decode(mp_encode(3.141592653589793)) scale
> +    ok 167 - str(mp_decode(mp_encode(3.141592653589793))) == 3.141592653589793
> +    ok 168 - mp_ext_type is MP_DECIMAL
> +    ok 169 - decimal_unpack() after mp_decode_extl()
> +    ok 170 - decimal_unpack() after mp_decode_extl() value
> +    ok 171 - decimal_unpack() after mp_decode_extl() len
> +    ok 172 - decimal_len(-3.141592653589793)
> +    ok 173 - decimal_len(-3.141592653589793) == len(decimal_pack(-3.141592653589793)
> +    ok 174 - decimal_unpack(decimal_pack(-3.141592653589793))
> +    ok 175 - decimal_unpack(decimal_pack(-3.141592653589793)) len
> +    ok 176 - decimal_unpack(decimal_pack(-3.141592653589793)) value
> +    ok 177 - decimal_unpack(decimal_pack(-3.141592653589793)) scale
> +    ok 178 - decimal_unpack(decimal_pack(-3.141592653589793)) precision
> +    ok 179 - str(decimal_unpack(decimal_pack(-3.141592653589793)) == -3.141592653589793
> +    ok 180 - mp_sizeof_decimal(-3.141592653589793)
> +    ok 181 - mp_sizeof_decimal(-3.141592653589793) == len(mp_encode_decimal(-3.141592653589793))
> +    ok 182 - mp_next(mp_encode(-3.141592653589793))
> +    ok 183 - mp_decode(mp_encode(-3.141592653589793) len
> +    ok 184 - mp_decode(mp_encode(-3.141592653589793)) value
> +    ok 185 - mp_decode(mp_encode(-3.141592653589793)) scale
> +    ok 186 - str(mp_decode(mp_encode(-3.141592653589793))) == -3.141592653589793
> +    ok 187 - mp_ext_type is MP_DECIMAL
> +    ok 188 - decimal_unpack() after mp_decode_extl()
> +    ok 189 - decimal_unpack() after mp_decode_extl() value
> +    ok 190 - decimal_unpack() after mp_decode_extl() len
> +    ok 191 - decimal_len(1234567891234567890.0987654321987654321)
> +    ok 192 - decimal_len(1234567891234567890.0987654321987654321) == len(decimal_pack(1234567891234567890.0987654321987654321)
> +    ok 193 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321))
> +    ok 194 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) len
> +    ok 195 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) value
> +    ok 196 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) scale
> +    ok 197 - decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) precision
> +    ok 198 - str(decimal_unpack(decimal_pack(1234567891234567890.0987654321987654321)) == 1234567891234567890.0987654321987654321
> +    ok 199 - mp_sizeof_decimal(1234567891234567890.0987654321987654321)
> +    ok 200 - mp_sizeof_decimal(1234567891234567890.0987654321987654321) == len(mp_encode_decimal(1234567891234567890.0987654321987654321))
> +    ok 201 - mp_next(mp_encode(1234567891234567890.0987654321987654321))
> +    ok 202 - mp_decode(mp_encode(1234567891234567890.0987654321987654321) len
> +    ok 203 - mp_decode(mp_encode(1234567891234567890.0987654321987654321)) value
> +    ok 204 - mp_decode(mp_encode(1234567891234567890.0987654321987654321)) scale
> +    ok 205 - str(mp_decode(mp_encode(1234567891234567890.0987654321987654321))) == 1234567891234567890.0987654321987654321
> +    ok 206 - mp_ext_type is MP_DECIMAL
> +    ok 207 - decimal_unpack() after mp_decode_extl()
> +    ok 208 - decimal_unpack() after mp_decode_extl() value
> +    ok 209 - decimal_unpack() after mp_decode_extl() len
> +    ok 210 - decimal_len(-1234567891234567890.0987654321987654321)
> +    ok 211 - decimal_len(-1234567891234567890.0987654321987654321) == len(decimal_pack(-1234567891234567890.0987654321987654321)
> +    ok 212 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321))
> +    ok 213 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) len
> +    ok 214 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) value
> +    ok 215 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) scale
> +    ok 216 - decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) precision
> +    ok 217 - str(decimal_unpack(decimal_pack(-1234567891234567890.0987654321987654321)) == -1234567891234567890.0987654321987654321
> +    ok 218 - mp_sizeof_decimal(-1234567891234567890.0987654321987654321)
> +    ok 219 - mp_sizeof_decimal(-1234567891234567890.0987654321987654321) == len(mp_encode_decimal(-1234567891234567890.0987654321987654321))
> +    ok 220 - mp_next(mp_encode(-1234567891234567890.0987654321987654321))
> +    ok 221 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321) len
> +    ok 222 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321)) value
> +    ok 223 - mp_decode(mp_encode(-1234567891234567890.0987654321987654321)) scale
> +    ok 224 - str(mp_decode(mp_encode(-1234567891234567890.0987654321987654321))) == -1234567891234567890.0987654321987654321
> +    ok 225 - mp_ext_type is MP_DECIMAL
> +    ok 226 - decimal_unpack() after mp_decode_extl()
> +    ok 227 - decimal_unpack() after mp_decode_extl() value
> +    ok 228 - decimal_unpack() after mp_decode_extl() len
> +    ok 229 - decimal_len(0.0000000000000000000000000000000000001)
> +    ok 230 - decimal_len(0.0000000000000000000000000000000000001) == len(decimal_pack(0.0000000000000000000000000000000000001)
> +    ok 231 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001))
> +    ok 232 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) len
> +    ok 233 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) value
> +    ok 234 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) scale
> +    ok 235 - decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) precision
> +    ok 236 - str(decimal_unpack(decimal_pack(0.0000000000000000000000000000000000001)) == 0.0000000000000000000000000000000000001
> +    ok 237 - mp_sizeof_decimal(0.0000000000000000000000000000000000001)
> +    ok 238 - mp_sizeof_decimal(0.0000000000000000000000000000000000001) == len(mp_encode_decimal(0.0000000000000000000000000000000000001))
> +    ok 239 - mp_next(mp_encode(0.0000000000000000000000000000000000001))
> +    ok 240 - mp_decode(mp_encode(0.0000000000000000000000000000000000001) len
> +    ok 241 - mp_decode(mp_encode(0.0000000000000000000000000000000000001)) value
> +    ok 242 - mp_decode(mp_encode(0.0000000000000000000000000000000000001)) scale
> +    ok 243 - str(mp_decode(mp_encode(0.0000000000000000000000000000000000001))) == 0.0000000000000000000000000000000000001
> +    ok 244 - mp_ext_type is MP_DECIMAL
> +    ok 245 - decimal_unpack() after mp_decode_extl()
> +    ok 246 - decimal_unpack() after mp_decode_extl() value
> +    ok 247 - decimal_unpack() after mp_decode_extl() len
> +    ok 248 - decimal_len(-0.0000000000000000000000000000000000001)
> +    ok 249 - decimal_len(-0.0000000000000000000000000000000000001) == len(decimal_pack(-0.0000000000000000000000000000000000001)
> +    ok 250 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001))
> +    ok 251 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) len
> +    ok 252 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) value
> +    ok 253 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) scale
> +    ok 254 - decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) precision
> +    ok 255 - str(decimal_unpack(decimal_pack(-0.0000000000000000000000000000000000001)) == -0.0000000000000000000000000000000000001
> +    ok 256 - mp_sizeof_decimal(-0.0000000000000000000000000000000000001)
> +    ok 257 - mp_sizeof_decimal(-0.0000000000000000000000000000000000001) == len(mp_encode_decimal(-0.0000000000000000000000000000000000001))
> +    ok 258 - mp_next(mp_encode(-0.0000000000000000000000000000000000001))
> +    ok 259 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001) len
> +    ok 260 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001)) value
> +    ok 261 - mp_decode(mp_encode(-0.0000000000000000000000000000000000001)) scale
> +    ok 262 - str(mp_decode(mp_encode(-0.0000000000000000000000000000000000001))) == -0.0000000000000000000000000000000000001
> +    ok 263 - mp_ext_type is MP_DECIMAL
> +    ok 264 - decimal_unpack() after mp_decode_extl()
> +    ok 265 - decimal_unpack() after mp_decode_extl() value
> +    ok 266 - decimal_unpack() after mp_decode_extl() len
> +    ok 267 - decimal_len(0.00000000000000000000000000000000000001)
> +    ok 268 - decimal_len(0.00000000000000000000000000000000000001) == len(decimal_pack(0.00000000000000000000000000000000000001)
> +    ok 269 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001))
> +    ok 270 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) len
> +    ok 271 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) value
> +    ok 272 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) scale
> +    ok 273 - decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) precision
> +    ok 274 - str(decimal_unpack(decimal_pack(0.00000000000000000000000000000000000001)) == 0.00000000000000000000000000000000000001
> +    ok 275 - mp_sizeof_decimal(0.00000000000000000000000000000000000001)
> +    ok 276 - mp_sizeof_decimal(0.00000000000000000000000000000000000001) == len(mp_encode_decimal(0.00000000000000000000000000000000000001))
> +    ok 277 - mp_next(mp_encode(0.00000000000000000000000000000000000001))
> +    ok 278 - mp_decode(mp_encode(0.00000000000000000000000000000000000001) len
> +    ok 279 - mp_decode(mp_encode(0.00000000000000000000000000000000000001)) value
> +    ok 280 - mp_decode(mp_encode(0.00000000000000000000000000000000000001)) scale
> +    ok 281 - str(mp_decode(mp_encode(0.00000000000000000000000000000000000001))) == 0.00000000000000000000000000000000000001
> +    ok 282 - mp_ext_type is MP_DECIMAL
> +    ok 283 - decimal_unpack() after mp_decode_extl()
> +    ok 284 - decimal_unpack() after mp_decode_extl() value
> +    ok 285 - decimal_unpack() after mp_decode_extl() len
> +    ok 286 - decimal_len(-0.00000000000000000000000000000000000001)
> +    ok 287 - decimal_len(-0.00000000000000000000000000000000000001) == len(decimal_pack(-0.00000000000000000000000000000000000001)
> +    ok 288 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001))
> +    ok 289 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) len
> +    ok 290 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) value
> +    ok 291 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) scale
> +    ok 292 - decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) precision
> +    ok 293 - str(decimal_unpack(decimal_pack(-0.00000000000000000000000000000000000001)) == -0.00000000000000000000000000000000000001
> +    ok 294 - mp_sizeof_decimal(-0.00000000000000000000000000000000000001)
> +    ok 295 - mp_sizeof_decimal(-0.00000000000000000000000000000000000001) == len(mp_encode_decimal(-0.00000000000000000000000000000000000001))
> +    ok 296 - mp_next(mp_encode(-0.00000000000000000000000000000000000001))
> +    ok 297 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001) len
> +    ok 298 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001)) value
> +    ok 299 - mp_decode(mp_encode(-0.00000000000000000000000000000000000001)) scale
> +    ok 300 - str(mp_decode(mp_encode(-0.00000000000000000000000000000000000001))) == -0.00000000000000000000000000000000000001
> +    ok 301 - mp_ext_type is MP_DECIMAL
> +    ok 302 - decimal_unpack() after mp_decode_extl()
> +    ok 303 - decimal_unpack() after mp_decode_extl() value
> +    ok 304 - decimal_unpack() after mp_decode_extl() len
> +    ok 305 - decimal_len(99999999999999999999999999999999999999)
> +    ok 306 - decimal_len(99999999999999999999999999999999999999) == len(decimal_pack(99999999999999999999999999999999999999)
> +    ok 307 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999))
> +    ok 308 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) len
> +    ok 309 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) value
> +    ok 310 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) scale
> +    ok 311 - decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) precision
> +    ok 312 - str(decimal_unpack(decimal_pack(99999999999999999999999999999999999999)) == 99999999999999999999999999999999999999
> +    ok 313 - mp_sizeof_decimal(99999999999999999999999999999999999999)
> +    ok 314 - mp_sizeof_decimal(99999999999999999999999999999999999999) == len(mp_encode_decimal(99999999999999999999999999999999999999))
> +    ok 315 - mp_next(mp_encode(99999999999999999999999999999999999999))
> +    ok 316 - mp_decode(mp_encode(99999999999999999999999999999999999999) len
> +    ok 317 - mp_decode(mp_encode(99999999999999999999999999999999999999)) value
> +    ok 318 - mp_decode(mp_encode(99999999999999999999999999999999999999)) scale
> +    ok 319 - str(mp_decode(mp_encode(99999999999999999999999999999999999999))) == 99999999999999999999999999999999999999
> +    ok 320 - mp_ext_type is MP_DECIMAL
> +    ok 321 - decimal_unpack() after mp_decode_extl()
> +    ok 322 - decimal_unpack() after mp_decode_extl() value
> +    ok 323 - decimal_unpack() after mp_decode_extl() len
> +    ok 324 - decimal_len(-99999999999999999999999999999999999999)
> +    ok 325 - decimal_len(-99999999999999999999999999999999999999) == len(decimal_pack(-99999999999999999999999999999999999999)
> +    ok 326 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999))
> +    ok 327 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) len
> +    ok 328 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) value
> +    ok 329 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) scale
> +    ok 330 - decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) precision
> +    ok 331 - str(decimal_unpack(decimal_pack(-99999999999999999999999999999999999999)) == -99999999999999999999999999999999999999
> +    ok 332 - mp_sizeof_decimal(-99999999999999999999999999999999999999)
> +    ok 333 - mp_sizeof_decimal(-99999999999999999999999999999999999999) == len(mp_encode_decimal(-99999999999999999999999999999999999999))
> +    ok 334 - mp_next(mp_encode(-99999999999999999999999999999999999999))
> +    ok 335 - mp_decode(mp_encode(-99999999999999999999999999999999999999) len
> +    ok 336 - mp_decode(mp_encode(-99999999999999999999999999999999999999)) value
> +    ok 337 - mp_decode(mp_encode(-99999999999999999999999999999999999999)) scale
> +    ok 338 - str(mp_decode(mp_encode(-99999999999999999999999999999999999999))) == -99999999999999999999999999999999999999
> +    ok 339 - mp_ext_type is MP_DECIMAL
> +    ok 340 - decimal_unpack() after mp_decode_extl()
> +    ok 341 - decimal_unpack() after mp_decode_extl() value
> +    ok 342 - decimal_unpack() after mp_decode_extl() len
> +    ok 343 - unpack malformed decimal fails
> +    ok 344 - decode malformed decimal preserves buffer position
>  ok 258 - subtests

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-24  8:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21  9:02 [PATCH 0/3] decimal. Add internal methods to encode/decode decimals to msgpack Serge Petrenko
2019-06-21  9:02 ` [PATCH 1/3] lib: update msgpuck library Serge Petrenko
2019-06-21 16:00   ` Vladimir Davydov
2019-06-21  9:02 ` [PATCH 2/3] decimal: add const qualifiers for decimal_pack() and decimal_len() Serge Petrenko
2019-06-21 16:00   ` Vladimir Davydov
2019-06-21  9:02 ` [PATCH 3/3] decimal: allow to encode/decode decimals as MsgPack Serge Petrenko
2019-06-24  8:35   ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox