8000 [WIP] Newspec stage 2. by methane · Pull Request #79 · msgpack/msgpack-python · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Newspec stage 2. #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 20, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d610975
add support for extended types: you can now pack/unpack custom python…
antocuni Oct 15, 2013
5529dfe
kill some duplicate code from unpack/unpackb and move the logic to Un…
antocuni Oct 18, 2013
522c4bf
slightly change to API
antocuni Oct 18, 2013
c727440
automatically find the best format to encode extended types
antocuni Oct 18, 2013
afa28fb
add support to unpack all ext formats
antocuni Oct 18, 2013
5467515
implement Packer.pack_extended_type also in the cython version of the…
antocuni Oct 18, 2013
a7485ec
add the hook for unknown types also to the cython Packer
antocuni Oct 18, 2013
ff85838
implement unpack_one also for the cython version, and add a test for it
antocuni Oct 18, 2013
985d4c1
add a test for unpacking extended types
antocuni Oct 19, 2013
56dd165
implement unpacking for all the fixtext formats
antocuni Oct 19, 2013
c9b97f0
implement unpacking of ext 8,16,32
antocuni Oct 19, 2013
6386481
add a note in the README
antocuni Oct 19, 2013
27f0cba
Merge branch 'master' of https://github.com/antocuni/msgpack-python i…
methane Oct 20, 2013
aa68c9b
fallback: Support pack_ext_type.
methane Oct 20, 2013
96bcd76
Packing ExtType and some cleanup
methane Oct 20, 2013
822cce8
Support unpacking new types.
methane Oct 20, 2013
0d5c58b
cleanup
methane Oct 20, 2013
84dc99c
Add ext_type example to README.
methane Oct 20, 2013
cb78959
Update README.
methane Oct 20, 2013
37c2ad6
Add tests and bugfix.
methane Oct 20, 2013
e3fee4d
fallback: support packing ExtType
methane Oct 20, 2013
d84a403
fix bugs.
methane Oct 20, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests and bugfix.
  • Loading branch information
methane committed Oct 20, 2013
commit 37c2ad63af8a6e5cb6944f80d931fedbc6b49e7d
3 changes: 2 additions & 1 deletion msgpack/pack_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ static inline int msgpack_pack_bin(msgpack_packer *x, size_t l)

static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
if (l > 0) msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
return 0;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions msgpack/unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static inline int unpack_callback_array_item(unpack_user* u, unsigned int curren
static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
{
if (u->list_hook) {
PyObject *new_c = PyObject_CallFunction(u->list_hook, "(O)", *c);
PyObject *new_c = PyObject_CallFunctionObjArgs(u->list_hook, *c, NULL);
if (!new_c)
return -1;
Py_DECREF(*c);
Expand Down Expand Up @@ -203,7 +203,7 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
{
if (u->object_hook) {
PyObject *new_c = PyObject_CallFunction(u->object_hook, "(O)", *c);
PyObject *new_c = PyObject_CallFunctionObjArgs(u->object_hook, *c, NULL);
if (!new_c)
return -1;

Expand Down
23 changes: 21 additions & 2 deletions test/test_newspec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

from msgpack import packb, unpackb
from msgpack import packb, unpackb, ExtType


def test_str8():
Expand Down Expand Up @@ -66,4 +66,23 @@ def test_bin32():
assert b[5:] == data
assert unpackb(b) == data


def test_ext():
def check(ext, packed):
assert packb(ext) == packed
assert unpackb(packed) == ext
check(ExtType(0x42, b'Z'), b'\xd4\x42Z') # fixext 1
check(ExtType(0x42, b'ZZ'), b'\xd5\x42ZZ') # fixext 2
check(ExtType(0x42, b'Z'*4), b'\xd6\x42' + b'Z'*4) # fixext 4
check(ExtType(0x42, b'Z'*8), b'\xd7\x42' + b'Z'*8) # fixext 8
check(ExtType(0x42, b'Z'*16), b'\xd8\x42' + b'Z'*16) # fixext 16
# ext 8
check(ExtType(0x42, b''), b'\xc7\x00\x42')
check(ExtType(0x42, b'Z'*255), b'\xc7\xff\x42' + b'Z'*255)
# ext 16
check(ExtType(0x42, b'Z'*256), b'\xc8\x01\x00\x42' + b'Z'*256)
check(ExtType(0x42, b'Z'*0xffff), b'\xc8\xff\xff\x42' + b'Z'*0xffff)
# ext 32
check(ExtType(0x42, b'Z'*0x10000), b'\xc9\x00\x01\x00\x00\x42' + b'Z'*0x10000)
# needs large memory
#check(ExtType(0x42, b'Z'*0xffffffff),
# b'\xc9\xff\xff\xff\xff\x42' + b'Z'*0xffffffff)
0