Skip to main content

colf: Colfer serialization/deserialization for Python

Project description

Python-Colfer

A strong typed version of Colfer serialization/deserialization for Python.

Usage

First install with PyPi

pip install colf

Then use it to construct a Colfer Object and use it:

from colf import Colfer

class TestType(Colfer):

    def __init__(self):
        super(Colfer, self).__init__()
        self.declareAttribute('radius', 'float64')
        self.declareAttribute('test', 'bool')

    def marshall(self, byteOutput, offset=0):
        offset = self.marshallFloat64(self.radius, 0, byteOutput, offset)
        offset = self.marshallBool(self.test, 1, byteOutput, offset)
        return offset

    def unmarshall(self, byteInput, offset=0):
        self.radius, offset = self.unmarshallFloat64(0, byteInput, offset)
        self.test, offset = self.unmarshallBool(1, byteInput, offset)
        return self, offset

# Write to Somewhere
exampleObject = TestType()
exampleObject.radius = 2.5
exampleObject.test = True
byteOutput = bytearray(24)
length = exampleObject.marshall(byteOutput)
print(byteOutput[:length])

# Read from Somewhere
deserializedObject, _ = TestType().unmarshall(byteOutput[:length])
print(deserializedObject)

Running Unit Tests

pip install tox
tox

Call for Testing Volunteers

The code was tested on Python 2.7, 3.6, 3.7, 3.8.

This code has been tested on Little-Endian machines only. It requires to be tested on other architectures such as PowerPC, or those with unique floating point formats.

Also, there may be chances this code may not work on some Python version due to nuances not previously uncovered.

Please volunteer to test it on as many exotic computers, OSes and send in your patches (or) bug reports.

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

colf-0.5.1.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file colf-0.5.1.tar.gz.

File metadata

  • Download URL: colf-0.5.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for colf-0.5.1.tar.gz
Algorithm Hash digest
SHA256 4f47cb7ae14e1fb40456152050f963f8bc8841988d15af872d6308291e6510cc
MD5 dd03704b79b6407802118b6dec0683e8
BLAKE2b-256 696b8c89bbe3ff97f28695e6a4e6301c18073c27a6adebe5b70370ef05979626

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