Skip to main content

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')
        self.declareAttribute('inner', 'object')

    def marshall(self, byteOutput, offset=0):
        offset = self.marshallFloat64(self.radius, 0, byteOutput, offset)
        offset = self.marshallBool(self.test, 1, byteOutput, offset)
        offset = self.marshallObject(self.inner, 2, 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)
        self.inner, offset = self.unmarshallObject(2, byteInput, offset)
        return self, offset

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

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

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.

Metadata

Release files for colf 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colf 0.6.2
File Size Uploaded
colf-0.6.2.tar.gz 9.0 kB Details

Release files / colf-0.6.2.tar.gz

Download URL colf-0.6.2.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7b391b2fb906f8a38ae36100fcc693caa455b5a816312e5c079ea320e3871e47
BLAKE2b-256 checksum
How to use checksums
a8c4f05aca77782323aad583f656dab8d51544b5de9933073e3aa73ce2c48dbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.6.2 This release

1 release file

0.5.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page