Skip to content

Commit

Permalink
add bytes primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Knio committed Sep 3, 2015
1 parent 779a383 commit 7e108b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions structpack/structpack.py
Expand Up @@ -36,6 +36,9 @@ class Float(PrimitiveType):
class Str(PrimitiveType):
native = str

class Bytes(PrimitiveType):
native = bytes


class List(PackType):
def __init__(self, cls):
Expand Down Expand Up @@ -149,6 +152,10 @@ def float(self):
def str(self):
return Str()

@property
def bytes(self):
return Bytes()

@property
def bool(self):
return Bool()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_structpack.py
Expand Up @@ -196,12 +196,16 @@ def test_types():
class Foo(structpack.msg):
a_int = structpack.int
a_float = structpack.float
a_str = structpack.str
a_bytes = structpack.bytes

f = Foo()
f.a_int = 3.14
f.a_float = 2
f.a_str = 'Hello'
f.a_bytes = b'World'
data = f.pack()
assert data == (3, 2.0)
assert data == (3, 2.0, 'Hello', b'World')


'''
Expand Down

0 comments on commit 7e108b1

Please sign in to comment.