A python library to compress a dict into a bytearray.
Project description
proJSON
A python library to compress a dict into a bytearray.
Install
pip install proJSON
The Crafter
Types
# Format
"name" : {
"type": type, # Types specified below with arguments
...
}
"intExample" : {
"type": "int", # Set int type
"byte": 1 # Set max int size to 1 byte (int8)
}
"stringExample" : {
"type": "string", # Set string type
"maxlen": 1 # Set max size of string ( the max size of the string is calculated by (2^(8*n)-1). if n is 1 then the max size is 255) (optional defaults to 2)
}
"bytesExample" : {
"type": "bytes", # Set bytes type
"maxlen": 1 # Set max size of string ( the max size of the string is calculated by (2^(8*n)-1). if n is 1 then the max size is 255) (optional defaults to 2)
}
"dirExample" : {
"type": "dir", # Set dir type
"subdirs": {} # A dictionary of int, string and byte types in the format above.
}
Don't put a dir in another dir. It won't work
Init
from proJSON import Crafter
template = {
# See the [types section](###Types) for how to make this.
"intExample" : {
"type": "int",
"byte": 1
},
"stringExample" : {
"type": "string",
"maxlen": 1
},
"bytesExample" : {
"type": "bytes",
"maxlen": 1
},
"dirExample" : {
"type": "dir",
"subdirs": {
"intExample2" : {
"type": "int",
"byte": 1
},
"stringExample2" : {
"type": "string",
"maxlen": 1
},
}
}
}
crafter = Crafter(template)
Encoding data
exampledata = {
"intExample" : 7,
"stringExample" : "Hello World!",
"bytesExample": b"This is bytes",
"dirExample" : {
"intExample2" : 200,
"stringExample2": "Hello Again!"
}
}
encoded = crafter.encode(exampledata)
print(encoded) # b'\x07\x0cHello World!\x00\rThis is bytes\xc8\x0cHello Again!' (43 bytes)
Decoding data
data = b'\x07\x0cHello World!\x00\rThis is bytes\xc8\x0cHello Again!'
decoded = crafter.decode(data)
print(decoded) # {'intExample': 7, 'stringExample': 'Hello World!', 'bytesExample': b'This is bytes', 'dirExample': {'intExample2': 200, 'stringExample2': 'Hello Again!'}} (154 bytes)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
proJSON-1.1.3.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file proJSON-1.1.3.tar.gz
.
File metadata
- Download URL: proJSON-1.1.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba26f359009fc4e7d680025eb35406fdc04fce43f2140c0e6bbed2f4ddc52a1 |
|
MD5 | b1968ef959876aee869a6c2a3353b530 |
|
BLAKE2b-256 | 509921d4cb2b0804106c17fff825545ddcf693df5b2f1b15fd089b5db55c9006 |
File details
Details for the file proJSON-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: proJSON-1.1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af18bfa0bbc3b044225f3dfe50b63719c07054c2860d6891cf460478d5253384 |
|
MD5 | 2964ca8749e607992d3acade3a88994c |
|
BLAKE2b-256 | dae4363f043ca93e4903d87ef4bcd3d1c3bd2979073e66f12be7a8cea80739a3 |