module tarantool.msgpack_ext¶
module tarantool.msgpack_ext.datetime¶
Tarantool `datetime`_ extension type support module.
The datetime MessagePack representation looks like this:
+---------+----------------+==========+-----------------+
| MP_EXT | MP_DATETIME | seconds | nsec; tzoffset; |
| = d7/d8 | = 4 | | tzindex; |
+---------+----------------+==========+-----------------+
MessagePack data contains:
Seconds (8 bytes) as an unencoded 64-bit signed integer stored in the little-endian order.
The optional fields (8 bytes), if any of them have a non-zero value. The fields include nsec (4 bytes), tzoffset (2 bytes), and tzindex (2 bytes) packed in the little-endian order.
seconds is seconds since Epoch, where the epoch is the point where
the time starts, and is platform dependent. For Unix, the epoch is
January 1, 1970, 00:00:00 (UTC). Tarantool uses a double type, see a
structure definition in src/lib/core/datetime.h and reasons in
datetime RFC.
nsec is nanoseconds, fractional part of seconds. Tarantool uses
int32_t, see a definition in src/lib/core/datetime.h.
tzoffset is timezone offset in minutes from UTC. Tarantool uses
int16_t type, see a structure definition in src/lib/core/datetime.h.
tzindex is Olson timezone id. Tarantool uses int16_t type, see
a structure definition in src/lib/core/datetime.h. If both
tzoffset and tzindex are specified, tzindex has the
preference and the tzoffset value is ignored.
- tarantool.msgpack_ext.datetime.EXT_ID = 4¶
`datetime`_ type id.
- tarantool.msgpack_ext.datetime.decode(data, _)¶
Decode a datetime object.
- Parameters:
- Returns:
Decoded datetime.
- Return type:
- Raise:
MsgpackError,tarantool.Datetimeexceptions
module tarantool.msgpack_ext.decimal¶
Tarantool decimal extension type support module.
The decimal MessagePack representation looks like this:
+--------+-------------------+------------+===============+
| MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
+--------+-------------------+------------+===============+
PackedDecimal has the following structure:
<--- length bytes -->
+-------+=============+
| scale | BCD |
+-------+=============+
Here the scale is either mp_int or mp_uint. Scale is the number of digits after the decimal point
BCD is a sequence of bytes representing decimal digits of the encoded
number (each byte has two decimal digits each encoded using 4-bit
nibbles), so byte >> 4 is the first digit and byte & 0x0f is
the second digit. The leftmost digit in the array is the most
significant. The rightmost digit in the array is the least significant.
The first byte of the BCD array contains the first digit of the number,
represented as follows:
| 4 bits | 4 bits |
= 0x = the 1st digit
(The first nibble contains 0 if the decimal number has an even
number of digits.) The last byte of the BCD array contains the last
digit of the number and the final nibble, represented as follows:
| 4 bits | 4 bits |
= the last digit = nibble
The final nibble represents the number’s sign:
0x0a,0x0c,0x0e,0x0fstand for plus,0x0band0x0dstand for minus.
- tarantool.msgpack_ext.decimal.decode(data, _)¶
Decode a decimal object.
- Parameters:
- Returns:
Decoded decimal.
- Return type:
- Raise:
- tarantool.msgpack_ext.decimal.encode(obj, _)¶
Encode a decimal object.
- Parameters:
obj¶ (
decimal.Decimal) – Decimal to encode.- Returns:
Encoded decimal.
- Return type:
- Raise:
module tarantool.msgpack_ext.interval¶
Tarantool datetime.interval extension type support module.
The interval MessagePack representation looks like this:
+--------+-------------------------+-------------+----------------+
| MP_EXT | Size of packed interval | MP_INTERVAL | PackedInterval |
+--------+-------------------------+-------------+----------------+
Packed interval consists of:
Packed number of non-zero fields.
Packed non-null fields.
Each packed field has the following structure:
+----------+=====================+
| field ID | field value |
+----------+=====================+
The number of defined (non-null) fields can be zero. In this case, the packed interval will be encoded as integer 0.
List of the field IDs:
0 – year
1 – month
2 – week
3 – day
4 – hour
5 – minute
6 – second
7 – nanosecond
8 – adjust
- tarantool.msgpack_ext.interval.EXT_ID = 6¶
datetime.interval type id.
- tarantool.msgpack_ext.interval.decode(data, unpacker)¶
Decode an interval object.
- Parameters:
unpacker¶ (
msgpack.Unpacker) – msgpack unpacker to decode fields.
- Returns:
Decoded interval.
- Return type:
- Raise:
MsgpackError
module tarantool.msgpack_ext.packer¶
Tarantool extension types encoding support.
- tarantool.msgpack_ext.packer.default(obj, packer=None)¶
msgpack.Packerencoder.- Parameters:
obj¶ (
decimal.Decimaloruuid.UUIDor ortarantool.BoxErrorortarantool.Datetimeortarantool.Interval) – Object to encode.packer¶ (
msgpack.Packer, optional) – msgpack packer to work with common types (like dictionary in extended error payload)
- Returns:
Encoded value.
- Return type:
- Raise:
module tarantool.msgpack_ext.unpacker¶
Tarantool extension types decoding support.
- tarantool.msgpack_ext.unpacker.ext_hook(code, data, unpacker=None)¶
msgpack.Unpackerdecoder.- Parameters:
- Returns:
Decoded value.
- Return type:
decimal.Decimaloruuid.UUIDor ortarantool.BoxErrorortarantool.Datetimeortarantool.Interval- Raise:
module tarantool.msgpack_ext.uuid¶
Tarantool uuid extension type support module.
The UUID MessagePack representation looks like this:
+--------+------------+-----------------+
| MP_EXT | MP_UUID | UuidValue |
| = d8 | = 2 | = 16-byte value |
+--------+------------+-----------------+
- tarantool.msgpack_ext.uuid.decode(data, _)¶
Decode an UUID object.