This module performs conversions between Python values (numbers and dictionaries) and C structs represented as Python bytes objects.
Project description
PyCerializer
PyCerializer is a lightweight module for Python serialization. The aim of PyCerializer is to produce serialized data that can be easily read in other programming languages such as C/C++ and others.
Requirements
There are no external dependencies.
The package is based on standard python module struct
that is available in all supported python versions, but
the PyCerializer use also typing
module that was introduced
in Python 3.5.
Supported types:
- [u]int64_t
- [u]int32_t
- [u]int16_t
- [u]int8_t
- string
- structures
Endianess:
- little
- big
Installation
pip install pycerializer
A simple example
Pack and save to file python list:
original = (1, 123, 4321)
packed = pack_list_num(original, 'int16', 'little')
with open('file.bin', 'wb') as f:
f.write(packed)
Unpack this list using python:
with open('file.bin', 'rb') as f:
packed = f.read()
unpacked = unpack_list_num(*packed, 'int16', 'little')
Unpack this list using C/C++:
FILE *f = fopen("file.bin", "rb");
const int n = 3;
int16_t buff[n];
fread(buff, sizeof(int16_t), n, f);
for (int i = 0; i < n; i++) printf("%d ", buff[i] );
Limitation
The structure packing supports only Python dictionaries with numeric fields and strings.
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
Built Distribution
File details
Details for the file pycerializer-0.5.3.tar.gz
.
File metadata
- Download URL: pycerializer-0.5.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af2fcc3dd814162ed9c90b3a3f59a8cc053997883c8f96a0501a04abb7ad2ca |
|
MD5 | 044dadd530cb3c564d0c94fb1c27f544 |
|
BLAKE2b-256 | 2cf86d137bb2c02da08b0582b876e905f18f4548b663dc28d49570837f8c5f75 |
File details
Details for the file pycerializer-0.5.3-py2.py3-none-any.whl
.
File metadata
- Download URL: pycerializer-0.5.3-py2.py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14f3d650a78b73133698ae247a22b929eb3bcd90470a469e4b536a5630d47f79 |
|
MD5 | 30996b68c16d5f6d31119a2de0845189 |
|
BLAKE2b-256 | 1868ac47afd6223f63361a2c73176624a81d38973ce930969c1710a18bb642c8 |