Skip to content

Commit

Permalink
Merge pull request #83 from fredthomsen/MemoryViewInDataFrame
Browse files Browse the repository at this point in the history
Handle memory view serialization in data frame
  • Loading branch information
Lukasa committed Apr 12, 2017
2 parents 7009f50 + 37100a5 commit 008e266
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ In chronological order:

- Performance improvements to serialization and parsing.

- Fred Thomsen (@fredthomsen)

- Support for memoryview in DataFrames.

4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Release History
6.0.0dev0
---------

**API Changes (Backward-compatible)**

- Added support for ``DataFrame.data`` being a ``memoryview`` object.

5.0.0 (2017-03-07)
------------------

Expand Down
2 changes: 2 additions & 0 deletions hyperframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def __init__(self, stream_id, data=b'', **kwargs):
def serialize_body(self):
padding_data = self.serialize_padding_data()
padding = b'\0' * self.total_padding
if isinstance(self.data, memoryview):
self.data = self.data.tobytes()
return b''.join([padding_data, self.data, padding])

def parse_body(self, data):
Expand Down
8 changes: 6 additions & 2 deletions test/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ def test_data_frame_has_correct_flags(self):
'END_STREAM', 'PADDED'
])

def test_data_frame_serializes_properly(self):
@pytest.mark.parametrize('data', [
b'testdata',
memoryview(b'testdata')
])
def test_data_frame_serializes_properly(self, data):
f = DataFrame(1)
f.flags = set(['END_STREAM'])
f.data = b'testdata'
f.data = data

s = f.serialize()
assert s == self.payload
Expand Down

0 comments on commit 008e266

Please sign in to comment.