Skip to main content

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

pycerializer-0.5.3.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

pycerializer-0.5.3-py2.py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 2 Python 3

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