Skip to main content

Domain Specific Language(DSL) for parsing and mapping binary data to python objects

Project description

# Binmapper

Python package for mapping objects to binary data.
It works with Python 2.7+

## Installation

Binmapper is available from https://pypi.python.org/pypi/binmapper and can be installed using pip

```sh
pip install binmapper
```

## Example usage

```python

import binmapper
import textwrap

definition = u"""\
bintype BinX:
field: uint8
bintype Bin:
fieldX: BinX
"""
definition = textwrap.dedent(definition)
binmap = binmapper.compile(definition)
bin = binmap.Bin()
input = io.BytesIO("\x01")
bin.parse(input)
print(bin.fieldX.field)
```

## Data types

Type | Byte Size | Description
--------|-----------|--------------
uint8 | 1 | Unsigned byte
uint16 | 2 | Unsigned short
uint32 | 4 | Unsigned short
sint8 | 1 | Signed byte
sint16 | 2 | Signed short
sint32 | 4 | Signed word
float | 4 | Floating point with single-precision
string | n | String
array | n | Array

## Common class template

```python

bintype CLASS_NAME:
FIELD_NAME : FIELD_TYPE &FIELD_ATTRIBUTE
...
&CLASS_ATTRIBUTE = CLASS_ATTRIBUTE_VALUE
...
&LET_FIELD_NAME = EXPRESSION
...
```

## Fields

## Byteorder

Value | Description
------------|------------
littlendian | Increasing numeric significance with increasing memory addresses
bigendian | Decreasing numeric significance with increasing memory addresses

Byteorder can be specified 3-way

- Field attribute

`field: uint8 &byteorder=littlendian`

Apply only to field

- BinType attribute

:::python
field: uint8
&byteorder=littlendian

Apply to all fields in BinType, except having attribute byteorder

- Parse argument

:::python
bin.parse(input, byteorder='littlendian')

Apply to all parsed data, except having attribute byteorder or BinType byteorder

Byteorder apply order:

`field byteorder > class byteorder > parse byteorder`

## Class Usage

## Array Usage

## String Usage

## Let Field Usage

## Change elements in runtime

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

binmapper-0.1a2.zip (50.1 kB view details)

Uploaded Source

File details

Details for the file binmapper-0.1a2.zip.

File metadata

  • Download URL: binmapper-0.1a2.zip
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for binmapper-0.1a2.zip
Algorithm Hash digest
SHA256 f9a8fb7c03a61fd92f035a21ddadc4652897782148fffd2af59fc5b7bf94c8ac
MD5 cbfa8d78c837fee5d6f7e4a18c31b0ba
BLAKE2b-256 5449da2c97d069e6909b10ccec55faa1298b400ec284d7ad3d946e88e34e0ef4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page