msgpackr 1.7.0-alpha1 → 1.7.0-alpha2

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/struct.js CHANGED
@@ -170,7 +170,6 @@ var sourceSymbol = Symbol('source')
170
170
  function readStruct(src, position, srcEnd, structure, unpackr) {
171
171
  var stringLength = (src[position++] << 8) | src[position++];
172
172
  var construct = structure.construct;
173
- var srcString;
174
173
  if (!construct) {
175
174
  construct = structure.construct = function() {
176
175
  }
@@ -206,16 +205,16 @@ function readStruct(src, position, srcEnd, structure, unpackr) {
206
205
  start = (value & 0xffff) + position;
207
206
  return src.toString('utf8', start, start + ((value >> 16) & 0x7ff));
208
207
  } else {
209
- if (!srcString) {
208
+ if (!source.srcString) {
210
209
  start = source.position + (l << 2);
211
- srcString = src.toString('latin1', start, start + stringLength);
210
+ source.srcString = src.toString('latin1', start, start + source.stringLength);
212
211
  }
213
212
  start = value & 0xffff;
214
- return srcString.slice(start, start + ((value >> 16) & 0x7ff));
213
+ return source.srcString.slice(start, start + ((value >> 16) & 0x7ff));
215
214
  }
216
215
  case 4:
217
216
  start = (0x1fffffff & value) + position;
218
- let end = srcEnd;
217
+ let end = source.srcEnd;
219
218
  for (let next = i + 1; next < l; next++) {
220
219
  position = source.position + (next << 2);
221
220
  let nextValue = dataView.getUint32(position, true);;
@@ -239,8 +238,8 @@ function readStruct(src, position, srcEnd, structure, unpackr) {
239
238
  case 8: return dataView.getFloat64(position + (value & 0x3ffffff), true);
240
239
  case 0x18: return '';
241
240
  case 0x19: return String.fromCharCode((value >> 16) & 0xff);
242
- case 0x20: return String.fromCharCode((value >> 16) & 0xff, (value >> 8) & 0xff);
243
- case 0x21: return String.fromCharCode((value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff);
241
+ case 0x1a: return String.fromCharCode((value >> 16) & 0xff, (value >> 8) & 0xff);
242
+ case 0x1b: return String.fromCharCode((value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff);
244
243
  default: throw new Error('Unknown constant');
245
244
  }
246
245
  }
@@ -254,6 +253,9 @@ function readStruct(src, position, srcEnd, structure, unpackr) {
254
253
  src,
255
254
  uint32: src.uint32,
256
255
  position,
256
+ srcString: '',
257
+ srcEnd,
258
+ stringLength
257
259
  }
258
260
  return instance;
259
261
  }