msgpackr 1.4.6 → 1.5.2

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/unpack.js CHANGED
@@ -15,6 +15,7 @@ var currentStructures
15
15
  var srcString
16
16
  var srcStringStart = 0
17
17
  var srcStringEnd = 0
18
+ var bundledStrings
18
19
  var referenceMap
19
20
  var currentExtensions = []
20
21
  var dataView
@@ -55,12 +56,21 @@ export class Unpackr {
55
56
  srcStringEnd = 0
56
57
  srcString = null
57
58
  strings = EMPTY_ARRAY
59
+ bundledStrings = null
58
60
  src = source
59
61
  // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
60
62
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
61
63
  // new ones
62
- dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength))
63
- if (this) {
64
+ try {
65
+ dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength))
66
+ } catch(error) {
67
+ // if it doesn't have a buffer, maybe it is the wrong type of object
68
+ src = null
69
+ if (source instanceof Uint8Array)
70
+ throw error
71
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
72
+ }
73
+ if (this instanceof Unpackr) {
64
74
  currentUnpackr = this
65
75
  if (this.structures) {
66
76
  currentStructures = this.structures
@@ -240,7 +250,15 @@ export function read() {
240
250
  let value
241
251
  switch (token) {
242
252
  case 0xc0: return null
243
- case 0xc1: return C1; // "never-used", return special object to denote that
253
+ case 0xc1:
254
+ if (bundledStrings) {
255
+ value = read() // followed by the length of the string in characters (not bytes!)
256
+ if (value > 0)
257
+ return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
258
+ else
259
+ return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
260
+ }
261
+ return C1; // "never-used", return special object to denote that
244
262
  case 0xc2: return false
245
263
  case 0xc3: return true
246
264
  case 0xc4:
@@ -295,10 +313,11 @@ export function read() {
295
313
  position += 4
296
314
  return value
297
315
  case 0xcf:
298
- if (currentUnpackr.uint64AsNumber)
299
- return src[position++] * 0x100000000000000 + src[position++] * 0x1000000000000 + src[position++] * 0x10000000000 + src[position++] * 0x100000000 +
300
- src[position++] * 0x1000000 + (src[position++] << 16) + (src[position++] << 8) + src[position++]
301
- value = dataView.getBigUint64(position)
316
+ if (currentUnpackr.int64AsNumber) {
317
+ value = dataView.getUint32(position) * 0x100000000
318
+ value += dataView.getUint32(position + 4)
319
+ } else
320
+ value = dataView.getBigUint64(position)
302
321
  position += 8
303
322
  return value
304
323
 
@@ -314,7 +333,11 @@ export function read() {
314
333
  position += 4
315
334
  return value
316
335
  case 0xd3:
317
- value = dataView.getBigInt64(position)
336
+ if (currentUnpackr.int64AsNumber) {
337
+ value = dataView.getInt32(position) * 0x100000000
338
+ value += dataView.getUint32(position + 4)
339
+ } else
340
+ value = dataView.getBigInt64(position)
318
341
  position += 8
319
342
  return value
320
343
 
@@ -463,8 +486,10 @@ var readFixedString = readStringJS
463
486
  var readString8 = readStringJS
464
487
  var readString16 = readStringJS
465
488
  var readString32 = readStringJS
489
+ export let isNativeAccelerationEnabled = false
466
490
 
467
491
  export function setExtractor(extractStrings) {
492
+ isNativeAccelerationEnabled = true
468
493
  readFixedString = readString(1)
469
494
  readString8 = readString(2)
470
495
  readString16 = readString(3)
@@ -883,6 +908,22 @@ currentExtensions[0x78] = () => {
883
908
  return new RegExp(data[0], data[1])
884
909
  }
885
910
 
911
+ currentExtensions[0x62] = (data) => {
912
+ let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]
913
+ let dataPosition = position
914
+ position += dataSize - 4
915
+ bundledStrings = [read(), read()]
916
+ bundledStrings.position0 = 0
917
+ bundledStrings.position1 = 0
918
+ let postBundlePosition = position
919
+ position = dataPosition
920
+ try {
921
+ return read()
922
+ } finally {
923
+ position = postBundlePosition
924
+ }
925
+ }
926
+
886
927
  currentExtensions[0xff] = (data) => {
887
928
  // 32-bit date extension
888
929
  if (data.length == 4)
@@ -896,7 +937,7 @@ currentExtensions[0xff] = (data) => {
896
937
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
897
938
  (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
898
939
  else
899
- throw new Error('Invalid timestamp length')
940
+ return new Date('invalid')
900
941
  } // notepack defines extension 0 to mean undefined, so use that as the default here
901
942
  // registration of bulk record definition?
902
943
  // currentExtensions[0x52] = () =>
@@ -910,6 +951,7 @@ function saveState(callback) {
910
951
  let savedSrcString = srcString
911
952
  let savedStrings = strings
912
953
  let savedReferenceMap = referenceMap
954
+ let savedBundledStrings = bundledStrings
913
955
 
914
956
  // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
915
957
  let savedSrc = new Uint8Array(src.slice(0, srcEnd)) // we copy the data in case it changes while external data is processed
@@ -926,6 +968,7 @@ function saveState(callback) {
926
968
  srcString = savedSrcString
927
969
  strings = savedStrings
928
970
  referenceMap = savedReferenceMap
971
+ bundledStrings = savedBundledStrings
929
972
  src = savedSrc
930
973
  sequentialMode = savedSequentialMode
931
974
  currentStructures = savedStructures
@@ -951,8 +994,6 @@ export const mult10 = new Array(147) // this is a table matching binary exponent
951
994
  for (let i = 0; i < 256; i++) {
952
995
  mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103))
953
996
  }
954
- export const useRecords = false
955
- export const mapsAsObjects = true
956
997
  export const Decoder = Unpackr
957
998
  var defaultUnpackr = new Unpackr({ useRecords: false })
958
999
  export const unpack = defaultUnpackr.unpack
@@ -1,23 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "pwa-node",
9
- "request": "launch",
10
- "name": "Run msgpackr tests",
11
- "runtimeArgs": [
12
- "test"
13
- ],
14
- "runtimeExecutable": "npm",
15
- "skipFiles": [
16
- "<node_internals>/**"
17
- ],
18
- "type": "pwa-node",
19
- "console": "internalConsole",
20
- "outputCapture": "std"
21
- }
22
- ]
23
- }
@@ -1,282 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var PassThrough = require("stream").PassThrough;
4
- var async = require("async");
5
-
6
- let { PackrStream, UnpackrStream } = require("..");
7
- var msgpack = require("msgpack-lite");
8
- var Encoder = require("msgpack-lite/lib/encoder").Encoder;
9
- var Decoder = require("msgpack-lite/lib/decoder").Decoder;
10
- var notepack = require("notepack");
11
-
12
- var pkg = require("../package.json");
13
-
14
- // a sample fluentd message
15
- var data = ["tag", [[1440949922, {"message": "hi there"}]]];
16
- var packed = msgpack.encode(data); // 30 bytes per message
17
- var packsize = packed.length;
18
- var opcount = 1000000;
19
- var joincount = 100;
20
- var packjoin = repeatbuf(packed, joincount); // 3KB per chunk
21
- var limit = 2;
22
-
23
- var blocksToJoin = []
24
- var streamForJoin = new PackrStream();
25
- streamForJoin.on("data", data => blocksToJoin.push(data));
26
- for (var j = 0; j < joincount; j++) {
27
- streamForJoin.write(data);
28
- }
29
- var packjoinWithRecords = Buffer.concat(blocksToJoin)
30
-
31
- var argv = Array.prototype.slice.call(process.argv, 2);
32
-
33
- if (argv[0] === "-v") {
34
- console.warn(pkg.name + " " + pkg.version);
35
- process.exit(0);
36
- }
37
-
38
- if (argv[0] - 0) limit = argv.shift() - 0;
39
-
40
- var list = [
41
- ['new PackrStream().write(obj);', encode5],
42
- ['new UnpackrStream().write(buf);', decode5],
43
- ['stream.write(msgpack.encode(obj));', encode1],
44
- ['stream.write(msgpack.decode(buf));', decode1],
45
- ['stream.write(notepack.encode(obj));', encode4],
46
- ['stream.write(notepack.decode(buf));', decode4],
47
- ['msgpack.Encoder().on("data",ondata).encode(obj);', encode2],
48
- ['msgpack.createDecodeStream().write(buf);', decode3],
49
- ['msgpack.createEncodeStream().write(obj);', encode3],
50
- ['msgpack.Decoder().on("data",ondata).decode(buf);', decode2],
51
- // ['stream.write(Buffer.from(JSON.stringify(obj)));', stringify],
52
- // ['stream.write(JSON.parse(buf));', parse]
53
- ];
54
-
55
- function encode5(callback) {
56
- var stream = new PackrStream();
57
- var cnt = counter(callback);
58
- stream.on("data", cnt.inc);
59
- stream.on("end", cnt.end);
60
- for (var j = 0; j < opcount; j++) {
61
- stream.write(data);
62
- }
63
- stream.end();
64
- }
65
-
66
- function encode1(callback) {
67
- var stream = new PassThrough();
68
- var cnt = counter(callback);
69
- stream.on("data", cnt.buf);
70
- stream.on("end", cnt.end);
71
- for (var j = 0; j < opcount; j++) {
72
- stream.write(msgpack.encode(data));
73
- }
74
- stream.end();
75
- }
76
-
77
- function encode2(callback) {
78
- var stream = new PassThrough();
79
- var cnt = counter(callback);
80
- stream.on("data", cnt.buf);
81
- stream.on("end", cnt.end);
82
- var encoder = Encoder();
83
- encoder.on("data", function(chunk) {
84
- stream.write(chunk);
85
- });
86
- encoder.on("end", function() {
87
- stream.end();
88
- });
89
- for (var j = 0; j < opcount; j++) {
90
- encoder.encode(data);
91
- }
92
- encoder.end();
93
- }
94
-
95
- function encode3(callback) {
96
- var stream = msgpack.createEncodeStream();
97
- var cnt = counter(callback);
98
- stream.on("data", cnt.buf);
99
- stream.on("end", cnt.end);
100
- for (var j = 0; j < opcount; j++) {
101
- stream.write(data);
102
- }
103
- stream.end();
104
- }
105
-
106
- function encode4(callback) {
107
- var stream = new PassThrough();
108
- var cnt = counter(callback);
109
- stream.on("data", cnt.buf);
110
- stream.on("end", cnt.end);
111
- for (var j = 0; j < opcount; j++) {
112
- stream.write(notepack.encode(data));
113
- }
114
- stream.end();
115
- }
116
-
117
- function decode5(callback) {
118
- var stream = new UnpackrStream();
119
- var cnt = counter(callback);
120
- stream.on("data", cnt.inc);
121
- stream.on("end", cnt.end);
122
- for (var j = 0; j < opcount / joincount; j++) {
123
- stream.write(packjoinWithRecords);
124
- }
125
- stream.end();
126
- }
127
-
128
- function decode1(callback) {
129
- var stream = new PassThrough({objectMode: true});
130
- var cnt = counter(callback);
131
- stream.on("data", cnt.inc);
132
- stream.on("end", cnt.end);
133
- for (var j = 0; j < opcount; j++) {
134
- stream.write(msgpack.decode(packed));
135
- }
136
- stream.end();
137
- }
138
-
139
- function decode2(callback) {
140
- var stream = new PassThrough({objectMode: true});
141
- var cnt = counter(callback);
142
- stream.on("data", cnt.inc);
143
- stream.on("end", cnt.end);
144
- var decoder = Decoder();
145
- decoder.on("data", function(chunk) {
146
- stream.write(chunk);
147
- });
148
- decoder.on("end", function() {
149
- stream.end();
150
- });
151
- for (var j = 0; j < opcount / joincount; j++) {
152
- decoder.decode(packjoin);
153
- }
154
- decoder.end();
155
- }
156
-
157
- function decode3(callback) {
158
- var stream = msgpack.createDecodeStream();
159
- var cnt = counter(callback);
160
- stream.on("data", cnt.inc);
161
- stream.on("end", cnt.end);
162
- for (var j = 0; j < opcount / joincount; j++) {
163
- stream.write(packjoin);
164
- }
165
- stream.end();
166
- }
167
-
168
- function decode4(callback) {
169
- var stream = new PassThrough({objectMode: true});
170
- var cnt = counter(callback);
171
- stream.on("data", cnt.inc);
172
- stream.on("end", cnt.end);
173
- for (var j = 0; j < opcount; j++) {
174
- stream.write(notepack.decode(packed));
175
- }
176
- stream.end();
177
- }
178
-
179
- function rpad(str, len, chr) {
180
- if (!chr) chr = " ";
181
- str += "";
182
- while (str.length < len) str += chr;
183
- return str;
184
- }
185
-
186
- function lpad(str, len, chr) {
187
- if (!chr) chr = " ";
188
- str += "";
189
- while (str.length < len) str = chr + str;
190
- return str;
191
- }
192
-
193
- function repeatbuf(buf, cnt) {
194
- var array = [];
195
- for (var i = 0; i < cnt; i++) {
196
- array.push(buf);
197
- }
198
- return Buffer.concat(array);
199
- }
200
-
201
- function counter(callback) {
202
- var cnt = 0;
203
- return {buf: b, inc: i, end: e};
204
-
205
- function b(buf) {
206
- cnt += buf.length / packsize;
207
- }
208
-
209
- function i() {
210
- cnt++;
211
- }
212
-
213
- function e() {
214
- cnt = Math.round(cnt);
215
- callback(null, cnt);
216
- }
217
- }
218
-
219
- function run() {
220
- // task filter
221
- if (argv.length) {
222
- list = list.filter(function(pair) {
223
- var name = pair[0];
224
- var match = argv.filter(function(grep) {
225
- return (name.indexOf(grep) > -1);
226
- });
227
- return match.length;
228
- });
229
- }
230
-
231
- // run tasks repeatedly
232
- var tasks = [];
233
- for (var i = 0; i < limit; i++) {
234
- tasks.push(oneset);
235
- }
236
- async.series(tasks, end);
237
-
238
- // run a series of tasks
239
- function oneset(callback) {
240
- async.eachSeries(list, bench, callback);
241
- }
242
-
243
- // run a single benchmark
244
- function bench(pair, callback) {
245
- process.stdout.write(".");
246
- var func = pair[1];
247
- var start = new Date() - 0;
248
- func(function(err, cnt) {
249
- var end = new Date() - 0;
250
- var array = pair[2] || (pair[2] = []);
251
- array.push(end - start);
252
- pair[3] = cnt;
253
- setTimeout(callback, 100);
254
- });
255
- }
256
-
257
- // show result
258
- function end() {
259
- var title = "operation (" + opcount + " x " + limit + ")";
260
- process.stdout.write("\n");
261
-
262
- // table header
263
- var COL1 = 48;
264
- console.log(rpad(title, COL1), "|", " op ", "|", " ms ", "|", " op/s ");
265
- console.log(rpad("", COL1, "-"), "|", "------:", "|", "----:", "|", "-----:");
266
-
267
- // table body
268
- list.forEach(function(pair) {
269
- var name = pair[0];
270
- var op = pair[3];
271
- var array = pair[2];
272
- array = array.sort(function(a, b) {
273
- return a > b;
274
- });
275
- var fastest = array[0];
276
- var score = Math.floor(opcount / fastest * 1000);
277
- console.log(rpad(name, COL1), "|", lpad(op, 7), "|", lpad(fastest, 5), "|", lpad(score, 6));
278
- });
279
- }
280
- }
281
-
282
- run();
@@ -1,199 +0,0 @@
1
- var msgpackr = tryRequire("../dist/node.cjs");
2
- var msgpack_node = tryRequire("msgpack");
3
- var msgpack_msgpack = tryRequire("@msgpack/msgpack");
4
- var msgpack_lite = tryRequire("msgpack-lite");
5
- var msgpack_js = tryRequire("msgpack-js");
6
- var msgpack_js_v5 = tryRequire("msgpack-js-v5");
7
- var msgpack5 = tryRequire("msgpack5");
8
- var msgpack_unpack = tryRequire("msgpack-unpack");
9
- var msgpack_codec = tryRequire("msgpack.codec");
10
- var notepack = tryRequire("notepack");
11
- var what_the_pack = tryRequire("what-the-pack");
12
- var avro = tryRequire('avsc')
13
- var cbor = tryRequire('cbor')
14
-
15
- msgpack5 = msgpack5 && msgpack5();
16
- msgpack_codec = msgpack_codec && msgpack_codec.msgpack;
17
- what_the_pack = what_the_pack && what_the_pack.initialize(2**20);
18
-
19
- var pkg = require("../package.json");
20
- var data = require("./example4.json");
21
- var packed = msgpack_lite && msgpack_lite.encode(data);
22
- var expected = JSON.stringify(data);
23
-
24
- var argv = Array.prototype.slice.call(process.argv, 2);
25
-
26
- if (argv[0] === "-v") {
27
- console.warn(pkg.name + " " + pkg.version);
28
- process.exit(0);
29
- }
30
-
31
- var limit = 5;
32
- if (argv[0] - 0) limit = argv.shift() - 0;
33
- limit *= 1000;
34
-
35
- var COL1 = 58;
36
- var COL2 = 7;
37
- var COL3 = 5;
38
- var COL4 = 6;
39
-
40
- console.log(rpad("operation", COL1), "|", " op ", "|", " ms ", "|", " op/s ");
41
- console.log(rpad("", COL1, "-"), "|", lpad(":", COL2, "-"), "|", lpad(":", COL3, "-"), "|", lpad(":", COL4, "-"));
42
-
43
- var buf, obj;
44
-
45
- if (msgpackr) {
46
- let packr = new msgpackr.Packr({ useRecords: false })
47
- buf = bench('require("msgpackr").pack(obj);', msgpackr.pack, data);
48
- //buf = bench('require("msgpackr").pack(obj);', data => {let result = packr.pack(data); packr.resetMemory(); return result;}, data);
49
-
50
- obj = bench('require("msgpackr").unpack(buf);', msgpackr.unpack, buf);
51
- test(obj);
52
-
53
- packr = new msgpackr.Packr({ structures: [] })
54
- buf = bench('msgpackr w/ shared structures: packr.pack(obj);', packr.pack.bind(packr), data);
55
- //buf = bench('msgpackr w/ shared structures: packr.pack(obj);', data => {let result = packr.pack(data); packr.resetMemory(); return result;}, data);
56
-
57
- obj = bench('msgpackr w/ shared structures: packr.unpack(buf);', packr.unpack.bind(packr), buf);
58
- test(obj);
59
- }
60
-
61
- if (JSON) {
62
- buf = bench('buf = Buffer(JSON.stringify(obj));', JSON_stringify, data);
63
- obj = bench('obj = JSON.parse(buf);', JSON.parse, buf);
64
- test(obj);
65
- }
66
-
67
- if (msgpack_lite) {
68
- buf = bench('buf = require("msgpack-lite").encode(obj);', msgpack_lite.encode, data);
69
- obj = bench('obj = require("msgpack-lite").decode(buf);', msgpack_lite.decode, packed);
70
- test(obj);
71
- }
72
-
73
- if (msgpack_msgpack) {
74
- buf = bench('buf = require("@msgpack/msgpack").encode(obj);', msgpack_msgpack.encode, data);
75
- obj = bench('obj = require("@msgpack/msgpack").decode(buf);', msgpack_msgpack.decode, buf);
76
- test(obj);
77
- }
78
-
79
- if (msgpack_node) {
80
- buf = bench('buf = require("msgpack").pack(obj);', msgpack_node.pack, data);
81
- obj = bench('obj = require("msgpack").unpack(buf);', msgpack_node.unpack, buf);
82
- test(obj);
83
- }
84
-
85
- if (msgpack_codec) {
86
- buf = bench('buf = Buffer(require("msgpack.codec").msgpack.pack(obj));', msgpack_codec_pack, data);
87
- obj = bench('obj = require("msgpack.codec").msgpack.unpack(buf);', msgpack_codec.unpack, buf);
88
- test(obj);
89
- }
90
-
91
- if (msgpack_js_v5) {
92
- buf = bench('buf = require("msgpack-js-v5").encode(obj);', msgpack_js_v5.encode, data);
93
- obj = bench('obj = require("msgpack-js-v5").decode(buf);', msgpack_js_v5.decode, buf);
94
- test(obj);
95
- }
96
-
97
- if (msgpack_js) {
98
- buf = bench('buf = require("msgpack-js").encode(obj);', msgpack_js.encode, data);
99
- obj = bench('obj = require("msgpack-js").decode(buf);', msgpack_js.decode, buf);
100
- test(obj);
101
- }
102
-
103
- if (msgpack5) {
104
- buf = bench('buf = require("msgpack5")().encode(obj);', msgpack5.encode, data);
105
- obj = bench('obj = require("msgpack5")().decode(buf);', msgpack5.decode, buf);
106
- test(obj);
107
- }
108
-
109
- if (notepack) {
110
- buf = bench('buf = require("notepack").encode(obj);', notepack.encode, data);
111
- obj = bench('obj = require("notepack").decode(buf);', notepack.decode, buf);
112
- test(obj);
113
- }
114
- if (what_the_pack) {
115
- buf = bench('require("what-the-pack")... encoder.encode(obj);', what_the_pack.encode, data);
116
- obj = bench('require("what-the-pack")... encoder.decode(buf);', what_the_pack.decode, buf);
117
- test(obj);
118
- }
119
-
120
- if (msgpack_unpack) {
121
- obj = bench('obj = require("msgpack-unpack").decode(buf);', msgpack_unpack, packed);
122
- test(obj);
123
- }
124
-
125
- if (avro) {
126
- const type = avro.Type.forValue(data);
127
- buf = bench('require("avsc")...make schema/type...type.toBuffer(obj);', type.toBuffer.bind(type), data);
128
- obj = bench('require("avsc")...make schema/type...type.fromBuffer(obj);', type.fromBuffer.bind(type), buf);
129
- }
130
- if (cbor) {
131
- buf = bench('buf = require("cbor").encode(obj);', cbor.encode, data);
132
- obj = bench('obj = require("cbor").decode(buf);', cbor.decode, buf);
133
- test(obj);
134
- }
135
-
136
- function JSON_stringify(src) {
137
- return Buffer(JSON.stringify(src));
138
- }
139
-
140
- function msgpack_codec_pack(data) {
141
- return Buffer(msgpack_codec.pack(data));
142
- }
143
-
144
- function bench(name, func, src) {
145
- if (argv.length) {
146
- var match = argv.filter(function(grep) {
147
- return (name.indexOf(grep) > -1);
148
- });
149
- if (!match.length) return SKIP;
150
- }
151
- var ret, duration;
152
- var start = new Date() - 0;
153
- var count = 0;
154
- while (1) {
155
- var end = new Date() - 0;
156
- duration = end - start;
157
- if (duration >= limit) break;
158
- while ((++count) % 100) ret = func(src);
159
- }
160
- name = rpad(name, COL1);
161
- var score = Math.floor(count / duration * 1000);
162
- count = lpad(count, COL2);
163
- duration = lpad(duration, COL3);
164
- score = lpad(score, COL4);
165
- console.log(name, "|", count, "|", duration, "|", score);
166
- return ret;
167
- }
168
-
169
- function rpad(str, len, chr) {
170
- if (!chr) chr = " ";
171
- while (str.length < len) str += chr;
172
- return str;
173
- }
174
-
175
- function lpad(str, len, chr) {
176
- if (!chr) chr = " ";
177
- str += "";
178
- while (str.length < len) str = chr + str;
179
- return str;
180
- }
181
-
182
- function test(actual) {
183
- if (actual === SKIP) return;
184
- actual = JSON.stringify(actual);
185
- if (actual === expected) return;
186
- console.warn("expected: " + expected);
187
- console.warn("actual: " + actual);
188
- }
189
-
190
- function SKIP() {
191
- }
192
-
193
- function tryRequire(name) {
194
- try {
195
- return require(name);
196
- } catch (e) {
197
- // ignore
198
- }
199
- }
@@ -1,52 +0,0 @@
1
- {
2
- "int0": 0,
3
- "int1": 1,
4
- "int1-": -1,
5
- "int8": 255,
6
- "int8-": -255,
7
- "int16": 256,
8
- "int16-": -256,
9
- "int32": 65536,
10
- "int32-": -65536,
11
- "nil": null,
12
- "true": true,
13
- "false": false,
14
- "float": 0.5,
15
- "float-": -0.5,
16
- "string0": "",
17
- "string1": "A",
18
- "string4": "foobarbaz",
19
- "string8": "Omnes viae Romam ducunt.",
20
- "string16": "L’homme n’est qu’un roseau, le plus faible de la nature ; mais c’est un roseau pensant. Il ne faut pas que l’univers entier s’arme pour l’écraser : une vapeur, une goutte d’eau, suffit pour le tuer. Mais, quand l’univers l’écraserait, l’homme serait encore plus noble que ce qui le tue, puisqu’il sait qu’il meurt, et l’avantage que l’univers a sur lui, l’univers n’en sait rien. Toute notre dignité consiste donc en la pensée. C’est de là qu’il faut nous relever et non de l’espace et de la durée, que nous ne saurions remplir. Travaillons donc à bien penser : voilà le principe de la morale.",
21
- "array0": [],
22
- "array1": [
23
- "foo"
24
- ],
25
- "array8": [
26
- 1,
27
- 2,
28
- 4,
29
- 8,
30
- 16,
31
- 32,
32
- 64,
33
- 128,
34
- 256,
35
- 512,
36
- 1024,
37
- 2048,
38
- 4096,
39
- 8192,
40
- 16384,
41
- 32768,
42
- 65536,
43
- 131072,
44
- 262144,
45
- 524288,
46
- 1048576
47
- ],
48
- "map0": {},
49
- "map1": {
50
- "foo": "bar"
51
- }
52
- }