API

Functions

pyparcel.load(*objs: Any, encoding: str = 'utf-8') → bytes[source]

Converts objs into a byte string format in order.

Parameters
  • encoding – encoding for strings to be encoded in

  • objs – Objects to be converted to byte string

Returns

Byte string of objs

pyparcel.unload(data: bytes, *objs: Any, encoding: str = 'utf-8') → Tuple[Any][source]

Converts data into python objects, in the order and format of objs

Parameters
  • encoding – encoding that strings are encoded in

  • data – data to be converted

  • objs – order and objects that data conforms to

Returns

One object if objs contains one element, or tuple of objects if objs contains more than 1 element

Strict Types

Strict types are used to explicity define how certain variables are to be packed.

Note: By default int’s are packed as Int, and float’s are packed as Float.

Types

# Bytes

Format Specifier

Char

1

"c"

UnsignedChar

1

"B"

SignedChar

1

"b"

Short

2

"h"

UnsignedShort

2

"H"

Int

4

"i"

UnsignedInt

4

"I"

Long

4

"l"

UnsignedLong

4

"L"

LongLong

8

"q"

UnsignedLongLong

8

"Q"

Float

4

"f"

Double

8

"d"

Example

from pyparcel import Long, UnsignedLongLong, Double


class Foo:
    def __init__(self, a: int, b: int, c: int, d: long):
        self.a = a
        self.b = Long(b)
        self.c = UnsignedLongLong(c)
        self.d = Double(d)

Classes

class pyparcel.Char(c: str = '\x00')[source]

Represents the strict type for a char.

class pyparcel.UnsignedChar(c: int = 0)[source]

Represents the strict type for an unsigned char.

class pyparcel.SignedChar(c: int = 0)[source]

Represents the strict type for a signed char.

class pyparcel.Short(n: int = 0)[source]

Represents the strict type for a short.

class pyparcel.UnsignedShort(n: int = 0)[source]

Represents the strict type for an unsigned short.

class pyparcel.Int(n: int = 0)[source]

Represents the strict type for an integer.

class pyparcel.UnsignedInt(n: int = 0)[source]

Represents the strict type for an unsigned integer.

class pyparcel.Long(n: int = 0)[source]

Represents the strict type for an long.

class pyparcel.UnsignedLong(n: int = 0)[source]

Represents the strict type for an unsigned long.

class pyparcel.LongLong(n: int = 0)[source]

Represents the strict type for a long long.

class pyparcel.UnsignedLongLong(n: int = 0)[source]

Represents the strict type for an unsigned long long.

class pyparcel.Float(n: int = 0)[source]

Represents the strict type for a float.

class pyparcel.Double(n: int = 0)[source]

Represents the strict type for a double.