Skip to content

Commit

Permalink
README.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Mar 29, 2016
1 parent 8e7056b commit 87e2609
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ A basic example of packing/unpacking four integers:
>>> from bitstruct import *
>>> pack('u1u3u4s16', 1, 2, 3, -4)
bytearray(b'\xa3\xff\xfc')
>>> unpack('u1u3u4s16', bytearray(b'\xa3\xff\xfc'))
b'\xa3\xff\xfc'
>>> unpack('u1u3u4s16', b'\xa3\xff\xfc')
(1, 2, 3, -4)
>>> calcsize('u1u3u4s16')
24
Expand All @@ -43,23 +43,23 @@ wrapping the result in a named tuple:
>>> from bitstruct import *
>>> from collections import namedtuple
>>> MyName = namedtuple('myname', [ 'a', 'b', 'c', 'd' ])
>>> unpacked = unpack('u1u3u4s16', bytearray(b'\xa3\xff\xfc'))
>>> unpacked = unpack('u1u3u4s16', b'\xa3\xff\xfc')
>>> myname = MyName(*unpacked)
>>> myname
myname(a=1, b=2, c=3, d=-4)
>>> myname.c
3
An example of packing/unpacking a unsinged integer, a signed integer,
a float, a boolean and a bytearray:
a float, a boolean and a byte string:

.. code-block:: python
>>> from bitstruct import *
>>> pack('u5s5f32b1r13', 1, -1, 3.75, True, bytearray(b'\xff\xff'))
bytearray(b'\x0f\xd0\x1c\x00\x00?\xff')
>>> unpack('u5s5f32b1r13', bytearray(b'\x0f\xd0\x1c\x00\x00?\xff'))
(1, -1, 3.75, True, bytearray(b'\xff\xf8'))
>>> pack('u5s5f32b1r13', 1, -1, 3.75, True, b'\xff\xff')
b'\x0f\xd0\x1c\x00\x00?\xff'
>>> unpack('u5s5f32b1r13', b'\x0f\xd0\x1c\x00\x00?\xff')
(1, -1, 3.75, True, b'\xff\xf8')
>>> calcsize('u5s5f32b1r13')
56
Expand All @@ -70,10 +70,10 @@ Significant Bit) first:
.. code-block:: python
>>> from bitstruct import *
>>> pack('<u5s5f32b1r13', 1, -1, 3.75, True, bytearray(b'\xff\xff'))
bytearray(b'\x87\xc0\x00\x03\x80\xbf\xff')
>>> unpack('<u5s5f32b1r13', bytearray(b'\x87\xc0\x00\x03\x80\xbf\xff'))
(1, -1, 3.75, True, bytearray(b'\xff\xf8'))
>>> pack('<u5s5f32b1r13', 1, -1, 3.75, True, b'\xff\xff')
b'\x87\xc0\x00\x03\x80\xbf\xff'
>>> unpack('<u5s5f32b1r13', b'\x87\xc0\x00\x03\x80\xbf\xff')
(1, -1, 3.75, True, b'\xff\xf8')
>>> calcsize('<u5s5f32b1r13')
56
Expand All @@ -82,13 +82,13 @@ An example of unpacking values from a hexstring and a binary file:
.. code-block:: python
>>> from bitstruct import *
>>> unpack('s17s13r24', bytearray('0123456789abcdef'.decode('hex')))
(582, -3751, bytearray(b'\xe2j\xf3'))
>>> unpack('s17s13r24', '0123456789abcdef'.decode('hex'))
(582, -3751, b'\xe2j\xf3')
>>> with open("test.bin", "rb") as fin:
... unpack('s17s13r24', bytearray(fin.read(8)))
... unpack('s17s13r24', fin.read(8))
...
...
(582, -3751, bytearray(b'\xe2j\xf3'))
(582, -3751, b'\xe2j\xf3')
Change endianness of the data with byteswap(), and then unpack the
values:
Expand Down
2 changes: 1 addition & 1 deletion bitstruct.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import struct

__version__ = "3.0.0"
__version__ = "3.1.0"


def _parse_format(fmt):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
version=bitstruct.__version__,
description=('This module performs conversions between Python values '
'and C bit field structs represented as Python '
'bytearrays.'),
'byte strings.'),
long_description=open('README.rst', 'r').read(),
author='Erik Moqvist, Ilya Petukhov',
author_email='erik.moqvist@gmail.com',
Expand Down

0 comments on commit 87e2609

Please sign in to comment.