File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ class Packer {
171171 this . _ch . writeBytes ( bytes ) ;
172172 } else if ( size < 0x100000000 ) {
173173 this . _ch . writeUInt8 ( STRING_32 ) ;
174- this . _ch . writeUInt8 ( ( size / 16777216 >> 0 ) % 256 ) ; // TODO: Why is it shifting by 0 here?
174+ this . _ch . writeUInt8 ( ( size / 16777216 >> 0 ) % 256 ) ;
175175 this . _ch . writeUInt8 ( ( size / 65536 >> 0 ) % 256 ) ;
176176 this . _ch . writeUInt8 ( ( size / 256 >> 0 ) % 256 ) ;
177177 this . _ch . writeUInt8 ( size % 256 ) ;
@@ -188,7 +188,9 @@ class Packer {
188188 this . _ch . writeUInt8 ( LIST_8 )
189189 this . _ch . writeUInt8 ( size ) ;
190190 } else if ( size < 0x10000 ) {
191- this . _ch . writeUInt8 ( LIST_16 , size / 256 >> 0 , size % 256 ) ;
191+ this . _ch . writeUInt8 ( LIST_16 ) ;
192+ this . _ch . writeUInt8 ( ( size / 256 >> 0 ) % 256 ) ;
193+ this . _ch . writeUInt8 ( size % 256 ) ;
192194 } else if ( size < 0x100000000 ) {
193195 this . _ch . writeUInt8 ( LIST_32 ) ;
194196 this . _ch . writeUInt8 ( ( size / 16777216 >> 0 ) % 256 ) ;
Original file line number Diff line number Diff line change @@ -44,10 +44,22 @@ describe('packstream', function() {
4444 expect ( roundtripped [ 0 ] ) . toBe ( list [ 0 ] ) ;
4545 expect ( roundtripped [ 1 ] ) . toBe ( list [ 1 ] ) ;
4646 } ) ;
47+
48+ it ( 'should pack long lists' , function ( ) {
49+ var listLength = 256 ;
50+ var list = [ ] ;
51+ for ( var i = 0 ; i < listLength ; i ++ ) {
52+ list . push ( null )
53+ }
54+ var roundtripped = packAndUnpack ( list , 1400 ) ;
55+ expect ( roundtripped [ 0 ] ) . toBe ( list [ 0 ] ) ;
56+ expect ( roundtripped [ 1 ] ) . toBe ( list [ 1 ] ) ;
57+ } ) ;
4758} ) ;
4859
49- function packAndUnpack ( val ) {
50- var buffer = alloc ( 128 ) ;
60+ function packAndUnpack ( val , bufferSize ) {
61+ bufferSize = bufferSize || 128 ;
62+ var buffer = alloc ( bufferSize ) ;
5163 new Packer ( buffer ) . pack ( val ) ;
5264 buffer . reset ( ) ;
5365 return new Unpacker ( ) . unpack ( buffer ) ;
You can’t perform that action at this time.
0 commit comments