Skip to main content

MessageToBytes(msg2bytes) is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller.

Project description

msg2bytes

MessageToBytes(msg2bytes) is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller.

Install

pip install msg2bytes

Usage

In [1]: import datetime
   ...: import msg2bytes
   ...: 

In [2]: data1 = {
   ...:     "id": 12,
   ...:     "username": "ceshi",
   ...:     "name": "测试",
   ...:     "mobiles": ["12345678901", "12345678902"],
   ...:     "add_time": datetime.datetime(2023, 4, 25, 18, 12, 32),
   ...:     "mod_time": datetime.datetime.now(),
   ...: }

In [3]: print(data1)
{'id': 12, 'username': 'ceshi', 'name': '测试', 'mobiles': ['12345678901', '12345678902'], 'add_time': datetime.datetime(2023, 4, 25, 18, 12, 32), 'mod_time': datetime.datetime(2023, 4, 26, 13, 2, 5, 293796)}

In [4]: data2 = msg2bytes.dumps(data1)

In [5]: print(data2)
b'\x04\x06\x0b\x02id\x15\x0c\x0b\x08username\x0b\x05ceshi\x0b\x04name\x0b\x06\xe6\xb5\x8b\xe8\xaf\x95\x0b\x07mobiles\x01\x02\x0b\x0b12345678901\x0b\x0b12345678902\x0b\x08add_time\r\x132023-04-25T18:12:32\x0b\x08mod_time\r\x1a2023-04-26T13:02:05.293796'

In [6]: data3 = msg2bytes.loads(data2)

In [7]: print(data3)
{'id': 12, 'username': 'ceshi', 'name': '测试', 'mobiles': ['12345678901', '12345678902'], 'add_time': datetime.datetime(2023, 4, 25, 18, 12, 32), 'mod_time': datetime.datetime(2023, 4, 26, 13, 2, 5, 293796)}

Releases

v0.1.2

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msg2bytes-0.1.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

msg2bytes-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file msg2bytes-0.1.2.tar.gz.

File metadata

  • Download URL: msg2bytes-0.1.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for msg2bytes-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3a0ec5957338b8306f94c6140d67c90c8b41850fffccbd4ec1c399769b4e99ac
MD5 a4a191c7a67fc84f2eb76793b7b85e3e
BLAKE2b-256 2b62420da438fc81d909d39f76ee10b838ff2ba97399545a02d523d99b9e30dd

See more details on using hashes here.

File details

Details for the file msg2bytes-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: msg2bytes-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for msg2bytes-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 389c2e562e0ff3e0e2b1079e43d85c1498612281fcc6089dbebd5677314014d1
MD5 a0f0cce05ccc9b87715b7c0574daf145
BLAKE2b-256 021ee78e893c2744244516c71354cc83f7a4fc3a3364a6f08cb94b6ce326051a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page