Skip to content

Commit 51335bb

Browse files
committed
packb supports use_single_float option.
1 parent 397d772 commit 51335bb

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

ChangeLog.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
0.2.2
22
=======
3-
:release date: NOT RELEASED YET
3+
:release date: 2012-09-21
4+
5+
Changes
6+
-------
7+
* Add ``use_single_float`` option to ``Packer``. When it is true, packs float
8+
object in single precision format.
49

510
Bugs fixed
611
-----------
712
* ``unpack()`` didn't restores gc state when it called with gc disabled.
813
``unpack()`` doesn't control gc now instead of restoring gc state collectly.
914
User can control gc state when gc cause performance issue.
1015

16+
* ``Unpacker``'s ``read_size`` option didn't used.
17+
1118
0.2.1
1219
=======
1320
:release date: 2012-08-20

msgpack/_msgpack.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors
177177
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
178178
stream.write(packer.pack(o))
179179

180-
def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'):
180+
def packb(object o, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False):
181181
"""
182182
pack o and return packed bytes."""
183-
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
183+
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors,
184+
use_single_float=use_single_float)
184185
return packer.pack(o)
185186

186187

test/test_pack.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding: utf-8
33

44
import six
5+
import struct
56
from nose import main
67
from nose.tools import *
78
from nose.plugins.skip import SkipTest
@@ -86,5 +87,9 @@ def testDecodeBinary():
8687
re = unpackb(packb("abc"), encoding=None)
8788
assert_equal(re, b"abc")
8889

90+
def testPackFloat():
91+
assert_equal(packb(1.0, use_single_float=True), b'\xca' + struct.pack('>f', 1.0))
92+
assert_equal(packb(1.0, use_single_float=False), b'\xcb' + struct.pack('>d', 1.0))
93+
8994
if __name__ == '__main__':
9095
main()

0 commit comments

Comments
 (0)