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:

obj (bytes) – Datetime to decode.

Returns:

Decoded datetime.

Return type:

tarantool.Datetime

Raise:

MsgpackError, tarantool.Datetime exceptions

tarantool.msgpack_ext.datetime.encode(obj, _)

Encode a datetime object.

Parameters:

obj – Datetime to encode.

Type:
obj:

tarantool.Datetime

Returns:

Encoded datetime.

Return type:

bytes

Raise:

tarantool.Datetime.msgpack_encode exceptions

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, 0x0f stand for plus,

  • 0x0b and 0x0d stand for minus.

tarantool.msgpack_ext.decimal.EXT_ID = 1

decimal type id.

tarantool.msgpack_ext.decimal.decode(data, _)

Decode a decimal object.

Parameters:

obj (bytes) – Decimal to decode.

Returns:

Decoded decimal.

Return type:

decimal.Decimal

Raise:

MsgpackError

tarantool.msgpack_ext.decimal.encode(obj, _)

Encode a decimal object.

Parameters:

obj (decimal.Decimal) – Decimal to encode.

Returns:

Encoded decimal.

Return type:

bytes

Raise:

MsgpackError

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:
Returns:

Decoded interval.

Return type:

tarantool.Interval

Raise:

MsgpackError

tarantool.msgpack_ext.interval.encode(obj, _)

Encode an interval object.

Parameters:

obj – Interval to encode.

Type:
obj:

tarantool.Interval

Returns:

Encoded interval.

Return type:

bytes

module tarantool.msgpack_ext.packer

Tarantool extension types encoding support.

tarantool.msgpack_ext.packer.default(obj, packer=None)

msgpack.Packer encoder.

Parameters:
Returns:

Encoded value.

Return type:

msgpack.ExtType

Raise:

TypeError

module tarantool.msgpack_ext.unpacker

Tarantool extension types decoding support.

tarantool.msgpack_ext.unpacker.ext_hook(code, data, unpacker=None)

msgpack.Unpacker decoder.

Parameters:
  • code (int) – MessagePack extension type code.

  • data (bytes) – MessagePack extension type data.

  • unpacker (msgpack.Unpacker, optional) – msgpack unpacker to work with common types (like dictionary in extended error payload)

Returns:

Decoded value.

Return type:

decimal.Decimal or uuid.UUID or or tarantool.BoxError or tarantool.Datetime or tarantool.Interval

Raise:

NotImplementedError

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.EXT_ID = 2

uuid type id.

tarantool.msgpack_ext.uuid.decode(data, _)

Decode an UUID object.

Parameters:

data (bytes) – UUID to decode.

Returns:

Decoded UUID.

Return type:

uuid.UUID

tarantool.msgpack_ext.uuid.encode(obj, _)

Encode an UUID object.

Parameters:

obj (uuid.UUID) – UUID to encode.

Returns:

Encoded UUID.

Return type:

bytes