msgpackr 1.8.3 → 1.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/test.js CHANGED
@@ -1140,7 +1140,7 @@
1140
1140
  let safeEnd;
1141
1141
  let bundledStrings = null;
1142
1142
  let writeStructSlots;
1143
- const MAX_BUNDLE_SIZE = 0xf000;
1143
+ const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1144
1144
  const hasNonLatin = /[\u0080-\uFFFF]/;
1145
1145
  const RECORD_SYMBOL = Symbol('record-id');
1146
1146
  let Packr$1 = class Packr extends Unpackr$1 {
@@ -2470,11 +2470,11 @@
2470
2470
  case 3:
2471
2471
  if (recordId >= 0x10000) return 0;
2472
2472
  target[start] = 0x39;
2473
- target.setUint16(start + 1, recordId, true);
2473
+ targetView.setUint16(start + 1, recordId, true);
2474
2474
  break;
2475
2475
  case 4:
2476
2476
  if (recordId >= 0x1000000) return 0;
2477
- target.setUint32(start, (recordId << 8) + 0x3a, true);
2477
+ targetView.setUint32(start, (recordId << 8) + 0x3a, true);
2478
2478
  break;
2479
2479
  }
2480
2480
 
@@ -3047,7 +3047,7 @@
3047
3047
  console.log('getStructures');
3048
3048
  }
3049
3049
  });
3050
- for (let i = 0; i < 20; i++) {
3050
+ for (let i = 0; i < 2000; i++) {
3051
3051
  let data = {};
3052
3052
  let props = ['foo', 'bar', 'a', 'b', 'c', 'name', 'age', 'd'];
3053
3053
 
@@ -3129,6 +3129,29 @@
3129
3129
  var deserialized = packr.unpack(serialized);
3130
3130
  assert.deepEqual(deserialized, data);
3131
3131
  });
3132
+ test('pack/unpack large amount of chinese characters', function() {
3133
+ const MSGPACK_OPTIONS = {bundleStrings: true};
3134
+
3135
+ const item = {
3136
+ message: '你好你好你好你好你好你好你好你好你好', // some Chinese characters
3137
+ };
3138
+
3139
+ testSize(100);
3140
+ testSize(1000);
3141
+ testSize(10000);
3142
+ function testSize(size) {
3143
+ const list = [];
3144
+ for (let i = 0; i < size; i++) {
3145
+ list.push({...item});
3146
+ }
3147
+
3148
+ const packer = new Packr(MSGPACK_OPTIONS);
3149
+ const unpacker = new Unpackr(MSGPACK_OPTIONS);
3150
+ const encoded = packer.pack(list);
3151
+ const decoded = unpacker.unpack(encoded);
3152
+ assert.deepEqual(list, decoded);
3153
+ }
3154
+ });
3132
3155
  test('pack/unpack sequential data', function () {
3133
3156
  var data = {foo: 1, bar: 2};
3134
3157
  let packr = new Packr({sequential: true});
@@ -3794,6 +3817,10 @@
3794
3817
  var deserialized = packr.unpack(serialized);
3795
3818
  assert.deepEqual(deserialized.a, '325283295382932843');
3796
3819
  });
3820
+ test('fixint should be one byte', function(){
3821
+ let encoded = pack(123);
3822
+ assert.equal(encoded.length, 1);
3823
+ });
3797
3824
  test('numbers', function(){
3798
3825
  var data = {
3799
3826
  bigEncodable: 48978578104322,