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 |
|
1 |
|
|
1 |
|
|
1 |
|
|
2 |
|
|
2 |
|
|
4 |
|
|
4 |
|
|
4 |
|
|
4 |
|
|
8 |
|
|
8 |
|
|
4 |
|
|
8 |
|
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)