File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ class Packer {
171
171
this . _ch . writeBytes ( bytes ) ;
172
172
} else if ( size < 0x100000000 ) {
173
173
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 ) ;
175
175
this . _ch . writeUInt8 ( ( size / 65536 >> 0 ) % 256 ) ;
176
176
this . _ch . writeUInt8 ( ( size / 256 >> 0 ) % 256 ) ;
177
177
this . _ch . writeUInt8 ( size % 256 ) ;
@@ -188,7 +188,9 @@ class Packer {
188
188
this . _ch . writeUInt8 ( LIST_8 )
189
189
this . _ch . writeUInt8 ( size ) ;
190
190
} 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 ) ;
192
194
} else if ( size < 0x100000000 ) {
193
195
this . _ch . writeUInt8 ( LIST_32 ) ;
194
196
this . _ch . writeUInt8 ( ( size / 16777216 >> 0 ) % 256 ) ;
Original file line number Diff line number Diff line change @@ -44,10 +44,22 @@ describe('packstream', function() {
44
44
expect ( roundtripped [ 0 ] ) . toBe ( list [ 0 ] ) ;
45
45
expect ( roundtripped [ 1 ] ) . toBe ( list [ 1 ] ) ;
46
46
} ) ;
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
+ } ) ;
47
58
} ) ;
48
59
49
- function packAndUnpack ( val ) {
50
- var buffer = alloc ( 128 ) ;
60
+ function packAndUnpack ( val , bufferSize ) {
61
+ bufferSize = bufferSize || 128 ;
62
+ var buffer = alloc ( bufferSize ) ;
51
63
new Packer ( buffer ) . pack ( val ) ;
52
64
buffer . reset ( ) ;
53
65
return new Unpacker ( ) . unpack ( buffer ) ;
You can’t perform that action at this time.
0 commit comments