mirror of
				https://github.com/msgpack/msgpack-python.git
				synced 2025-10-31 17:40:54 +00:00 
			
		
		
		
	packb supports use_single_float option.
This commit is contained in:
		
							parent
							
								
									397d772e11
								
							
						
					
					
						commit
						51335bbee4
					
				
					 3 changed files with 16 additions and 3 deletions
				
			
		|  | @ -1,6 +1,11 @@ | ||||||
| 0.2.2 | 0.2.2 | ||||||
| ======= | ======= | ||||||
| :release date: NOT RELEASED YET | :release date: 2012-09-21 | ||||||
|  | 
 | ||||||
|  | Changes | ||||||
|  | ------- | ||||||
|  | * Add ``use_single_float`` option to ``Packer``. When it is true, packs float | ||||||
|  |   object in single precision format. | ||||||
| 
 | 
 | ||||||
| Bugs fixed | Bugs fixed | ||||||
| ----------- | ----------- | ||||||
|  | @ -8,6 +13,8 @@ Bugs fixed | ||||||
|   ``unpack()`` doesn't control gc now instead of restoring gc state collectly. |   ``unpack()`` doesn't control gc now instead of restoring gc state collectly. | ||||||
|   User can control gc state when gc cause performance issue. |   User can control gc state when gc cause performance issue. | ||||||
| 
 | 
 | ||||||
|  | * ``Unpacker``'s ``read_size`` option didn't used. | ||||||
|  | 
 | ||||||
| 0.2.1 | 0.2.1 | ||||||
| ======= | ======= | ||||||
| :release date: 2012-08-20 | :release date: 2012-08-20 | ||||||
|  |  | ||||||
|  | @ -177,10 +177,11 @@ def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors | ||||||
|     packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) |     packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) | ||||||
|     stream.write(packer.pack(o)) |     stream.write(packer.pack(o)) | ||||||
| 
 | 
 | ||||||
| def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): | def packb(object o, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False): | ||||||
|     """ |     """ | ||||||
|     pack o and return packed bytes.""" |     pack o and return packed bytes.""" | ||||||
|     packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) |     packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors, | ||||||
|  |                     use_single_float=use_single_float) | ||||||
|     return packer.pack(o) |     return packer.pack(o) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| # coding: utf-8 | # coding: utf-8 | ||||||
| 
 | 
 | ||||||
| import six | import six | ||||||
|  | import struct | ||||||
| from nose import main | from nose import main | ||||||
| from nose.tools import * | from nose.tools import * | ||||||
| from nose.plugins.skip import SkipTest | from nose.plugins.skip import SkipTest | ||||||
|  | @ -86,5 +87,9 @@ def testDecodeBinary(): | ||||||
|     re = unpackb(packb("abc"), encoding=None) |     re = unpackb(packb("abc"), encoding=None) | ||||||
|     assert_equal(re, b"abc") |     assert_equal(re, b"abc") | ||||||
| 
 | 
 | ||||||
|  | def testPackFloat(): | ||||||
|  |     assert_equal(packb(1.0, use_single_float=True),  b'\xca' + struct.pack('>f', 1.0)) | ||||||
|  |     assert_equal(packb(1.0, use_single_float=False), b'\xcb' + struct.pack('>d', 1.0)) | ||||||
|  | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     main() |     main() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 INADA Naoki
						INADA Naoki