msgpack-lite 0.1.27 → 0.2.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpack-lite",
3
3
  "description": "Fast Pure JavaScript MessagePack Encoder and Decoder",
4
- "version": "0.1.27",
4
+ "version": "0.2.1",
5
5
  "author": "@kawanet",
6
6
  "bin": {
7
7
  "msgpack": "./bin/msgpack"
@@ -18,23 +18,35 @@
18
18
  "Joshua Mouch <josh@mouch.name>",
19
19
  "Joshua Wise <josh@joshuawise.ninja>",
20
20
  "Maciej Hirsz <maciej.hirsz@gmail.com>",
21
- "Rafał Michalski <royaltm75@gmail.com>"
21
+ "Rafał Michalski <royaltm75@gmail.com>",
22
+ "Yarchik <spoko.dev@gmail.com>"
22
23
  ],
23
24
  "dependencies": {
24
- "event-lite": "^0.1.1",
25
- "ieee754": "^1.1.8",
26
- "int64-buffer": "^0.1.9",
27
- "isarray": "^1.0.0"
25
+ "event-lite": "^1.0.0",
26
+ "ieee754": "^1.2.1",
27
+ "int64-buffer": "^1.1.1",
28
+ "isarray": "^2.0.5"
28
29
  },
29
30
  "devDependencies": {
30
- "async": "^2.1.1",
31
- "browserify": "^13.1.0",
32
- "concat-stream": "^1.5.2",
33
- "jshint": "^2.9.3",
34
- "mocha": "^3.1.2",
35
- "msgpack.codec": "git+https://github.com/kawanet/msgpack-javascript.git#msgpack.codec",
36
- "uglify-js": "^2.7.3"
31
+ "@msgpack/msgpack": "^3.1.3",
32
+ "browserify": "^17.0.1",
33
+ "concat-stream": "^2.0.0",
34
+ "jshint": "^2.13.6",
35
+ "mocha": "^11.8.0",
36
+ "msgpack5": "^6.0.2",
37
+ "msgpackr": "^2.0.6",
38
+ "notepack.io": "^3.0.1",
39
+ "uglify-js": "^3.19.3"
37
40
  },
41
+ "files": [
42
+ "LICENSE",
43
+ "README.md",
44
+ "bin/msgpack",
45
+ "dist/msgpack.min.js",
46
+ "global.js",
47
+ "index.js",
48
+ "lib/*.js"
49
+ ],
38
50
  "homepage": "https://github.com/kawanet/msgpack-lite",
39
51
  "jshintConfig": {
40
52
  "es3": true,
@@ -61,14 +73,14 @@
61
73
  ],
62
74
  "license": "MIT",
63
75
  "main": "index.js",
76
+ "overrides": {
77
+ "buffer": "4.9.2"
78
+ },
64
79
  "repository": {
65
80
  "type": "git",
66
81
  "url": "https://github.com/kawanet/msgpack-lite.git"
67
82
  },
68
83
  "scripts": {
69
- "benchmark": "./lib/benchmark.js",
70
- "benchmark-lite": "./lib/benchmark.js msgpack-lite",
71
- "benchmark-stream": "./lib/benchmark-stream.js",
72
84
  "fixpack": "fixpack",
73
85
  "make": "make",
74
86
  "size": "make clean dist/msgpack.min.js && gzip -9fkv dist/msgpack.min.js && ls -l dist",
@@ -1,23 +0,0 @@
1
- name: Node.js CI
2
-
3
- on: [ push, pull_request ]
4
-
5
- permissions:
6
- contents: read
7
-
8
- jobs:
9
- test:
10
- runs-on: ubuntu-latest
11
- strategy:
12
- matrix:
13
- node-version: [ "18", "20", "22", "24", "26" ]
14
- steps:
15
- - uses: actions/checkout@v7
16
-
17
- - uses: actions/setup-node@v7
18
- with:
19
- node-version: ${{ matrix.node-version }}
20
-
21
- - run: npm install
22
- - run: npm run build --if-present
23
- - run: npm test
@@ -1,64 +0,0 @@
1
- name: Publish
2
-
3
- # Releases are cut by pushing a version tag, so ordinary pushes never reach
4
- # npm. The staged publish below still leaves the version invisible until a
5
- # maintainer approves it with 2FA.
6
- on:
7
- push:
8
- tags: [ "0.*.*" ]
9
-
10
- # Deny by default; each job opts in to the minimum it needs.
11
- permissions: { }
12
-
13
- jobs:
14
- build:
15
- runs-on: ubuntu-latest
16
- permissions:
17
- contents: read
18
- steps:
19
- - uses: actions/checkout@v7
20
- with:
21
- # merge-base below needs the history of main, not just the tag.
22
- fetch-depth: 0
23
- persist-credentials: false
24
-
25
- # A tag created on a side branch must never reach npm.
26
- - name: Verify tag is on main
27
- run: git merge-base --is-ancestor "$GITHUB_SHA" origin/main
28
-
29
- - uses: actions/setup-node@v7
30
- with:
31
- node-version: "24"
32
- package-manager-cache: false
33
-
34
- - name: Verify tag matches package.json
35
- run: |
36
- version=$(npm pkg get version | tr -d '"')
37
- test "$version" = "$GITHUB_REF_NAME"
38
-
39
- - run: npm install --ignore-scripts
40
- - run: npm run build --if-present
41
- - run: npm test
42
-
43
- stage:
44
- needs: build
45
- runs-on: ubuntu-latest
46
- environment: npm-stage
47
- permissions:
48
- contents: read
49
- id-token: write
50
- steps:
51
- # dist/ is committed, so the tag alone carries everything npm needs.
52
- - uses: actions/checkout@v7
53
- with:
54
- persist-credentials: false
55
-
56
- - uses: actions/setup-node@v7
57
- with:
58
- node-version: "24"
59
- package-manager-cache: false
60
-
61
- # Nothing third party is installed in this job, so no foreign code runs
62
- # while the OIDC token is reachable. This only queues the tarball: a
63
- # maintainer releases it with 'npm stage approve'.
64
- - run: npm stage publish --ignore-scripts
package/Makefile DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bash -c make
2
-
3
- SRC=./lib/browser.js
4
- LIB=./index.js ./lib/*.js
5
- TESTS=./test/*.js
6
- HINTS=$(LIB) $(TESTS) ./*.json ./test/*.json
7
- CLASS=msgpack
8
- DIST=./dist
9
- JSTEMP=./dist/msgpack.browserify.js
10
- JSDEST=./dist/msgpack.min.js
11
-
12
- all: test $(JSDEST)
13
-
14
- clean:
15
- rm -fr $(JSDEST) $(JSTEMP)
16
-
17
- $(DIST):
18
- mkdir -p $(DIST)
19
-
20
- $(JSTEMP): $(LIB) $(DIST)
21
- ./node_modules/.bin/browserify -s $(CLASS) $(SRC) -o $(JSTEMP) --debug
22
-
23
- $(JSDEST): $(JSTEMP)
24
- ./node_modules/.bin/uglifyjs $(JSTEMP) -c -m -r Buffer -o $(JSDEST)
25
- ls -l $(JSDEST)
26
-
27
- test: jshint mocha test-dep
28
-
29
- mocha:
30
- ./node_modules/.bin/mocha -R spec $(TESTS)
31
-
32
- jshint:
33
- ./node_modules/.bin/jshint $(HINTS)
34
-
35
- # Requiring the library must stay silent. Deprecation warnings only
36
- # surface under --pending-deprecation, so ask for them explicitly.
37
- test-dep:
38
- ! node --pending-deprecation --trace-deprecation ./index.js 2>&1 | grep .
39
-
40
- bench:
41
- node lib/benchmark.js 1
42
-
43
- .PHONY: all clean test jshint mocha test-dep bench
@@ -1,247 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var PassThrough = require("stream").PassThrough;
4
- var async = require("async");
5
-
6
- var msgpack = require("../");
7
- var Encoder = require("./encoder").Encoder;
8
- var Decoder = require("./decoder").Decoder;
9
- var notepack = require("notepack");
10
-
11
- var pkg = require("../package.json");
12
-
13
- // a sample fluentd message
14
- var data = ["tag", [[1440949922, {"message": "hi there"}]]];
15
- var packed = msgpack.encode(data); // 30 bytes per message
16
- var packsize = packed.length;
17
- var opcount = 1000000;
18
- var joincount = 100;
19
- var packjoin = repeatbuf(packed, joincount); // 3KB per chunk
20
- var limit = 2;
21
-
22
- var argv = Array.prototype.slice.call(process.argv, 2);
23
-
24
- if (argv[0] === "-v") {
25
- console.warn(pkg.name + " " + pkg.version);
26
- process.exit(0);
27
- }
28
-
29
- if (argv[0] - 0) limit = argv.shift() - 0;
30
-
31
- var list = [
32
- ['stream.write(msgpack.encode(obj));', encode1],
33
- ['stream.write(notepack.encode(obj));', encode4],
34
- ['msgpack.Encoder().on("data",ondata).encode(obj);', encode2],
35
- ['msgpack.createEncodeStream().write(obj);', encode3],
36
- ['stream.write(msgpack.decode(buf));', decode1],
37
- ['stream.write(notepack.decode(buf));', decode4],
38
- ['msgpack.Decoder().on("data",ondata).decode(buf);', decode2],
39
- ['msgpack.createDecodeStream().write(buf);', decode3]
40
- ];
41
-
42
- function encode1(callback) {
43
- var stream = new PassThrough();
44
- var cnt = counter(callback);
45
- stream.on("data", cnt.buf);
46
- stream.on("end", cnt.end);
47
- for (var j = 0; j < opcount; j++) {
48
- stream.write(msgpack.encode(data));
49
- }
50
- stream.end();
51
- }
52
-
53
- function encode2(callback) {
54
- var stream = new PassThrough();
55
- var cnt = counter(callback);
56
- stream.on("data", cnt.buf);
57
- stream.on("end", cnt.end);
58
- var encoder = Encoder();
59
- encoder.on("data", function(chunk) {
60
- stream.write(chunk);
61
- });
62
- encoder.on("end", function() {
63
- stream.end();
64
- });
65
- for (var j = 0; j < opcount; j++) {
66
- encoder.encode(data);
67
- }
68
- encoder.end();
69
- }
70
-
71
- function encode3(callback) {
72
- var stream = msgpack.createEncodeStream();
73
- var cnt = counter(callback);
74
- stream.on("data", cnt.buf);
75
- stream.on("end", cnt.end);
76
- for (var j = 0; j < opcount; j++) {
77
- stream.write(data);
78
- }
79
- stream.end();
80
- }
81
-
82
- function encode4(callback) {
83
- var stream = new PassThrough();
84
- var cnt = counter(callback);
85
- stream.on("data", cnt.buf);
86
- stream.on("end", cnt.end);
87
- for (var j = 0; j < opcount; j++) {
88
- stream.write(notepack.encode(data));
89
- }
90
- stream.end();
91
- }
92
-
93
- function decode1(callback) {
94
- var stream = new PassThrough({objectMode: true});
95
- var cnt = counter(callback);
96
- stream.on("data", cnt.inc);
97
- stream.on("end", cnt.end);
98
- for (var j = 0; j < opcount; j++) {
99
- stream.write(msgpack.decode(packed));
100
- }
101
- stream.end();
102
- }
103
-
104
- function decode2(callback) {
105
- var stream = new PassThrough({objectMode: true});
106
- var cnt = counter(callback);
107
- stream.on("data", cnt.inc);
108
- stream.on("end", cnt.end);
109
- var decoder = Decoder();
110
- decoder.on("data", function(chunk) {
111
- stream.write(chunk);
112
- });
113
- decoder.on("end", function() {
114
- stream.end();
115
- });
116
- for (var j = 0; j < opcount / joincount; j++) {
117
- decoder.decode(packjoin);
118
- }
119
- decoder.end();
120
- }
121
-
122
- function decode3(callback) {
123
- var stream = msgpack.createDecodeStream();
124
- var cnt = counter(callback);
125
- stream.on("data", cnt.inc);
126
- stream.on("end", cnt.end);
127
- for (var j = 0; j < opcount / joincount; j++) {
128
- stream.write(packjoin);
129
- }
130
- stream.end();
131
- }
132
-
133
- function decode4(callback) {
134
- var stream = new PassThrough({objectMode: true});
135
- var cnt = counter(callback);
136
- stream.on("data", cnt.inc);
137
- stream.on("end", cnt.end);
138
- for (var j = 0; j < opcount; j++) {
139
- stream.write(notepack.decode(packed));
140
- }
141
- stream.end();
142
- }
143
-
144
- function rpad(str, len, chr) {
145
- if (!chr) chr = " ";
146
- str += "";
147
- while (str.length < len) str += chr;
148
- return str;
149
- }
150
-
151
- function lpad(str, len, chr) {
152
- if (!chr) chr = " ";
153
- str += "";
154
- while (str.length < len) str = chr + str;
155
- return str;
156
- }
157
-
158
- function repeatbuf(buf, cnt) {
159
- var array = [];
160
- for (var i = 0; i < cnt; i++) {
161
- array.push(buf);
162
- }
163
- return Buffer.concat(array);
164
- }
165
-
166
- function counter(callback) {
167
- var cnt = 0;
168
- return {buf: b, inc: i, end: e};
169
-
170
- function b(buf) {
171
- cnt += buf.length / packsize;
172
- }
173
-
174
- function i() {
175
- cnt++;
176
- }
177
-
178
- function e() {
179
- cnt = Math.round(cnt);
180
- callback(null, cnt);
181
- }
182
- }
183
-
184
- function run() {
185
- // task filter
186
- if (argv.length) {
187
- list = list.filter(function(pair) {
188
- var name = pair[0];
189
- var match = argv.filter(function(grep) {
190
- return (name.indexOf(grep) > -1);
191
- });
192
- return match.length;
193
- });
194
- }
195
-
196
- // run tasks repeatedly
197
- var tasks = [];
198
- for (var i = 0; i < limit; i++) {
199
- tasks.push(oneset);
200
- }
201
- async.series(tasks, end);
202
-
203
- // run a series of tasks
204
- function oneset(callback) {
205
- async.eachSeries(list, bench, callback);
206
- }
207
-
208
- // run a single benchmark
209
- function bench(pair, callback) {
210
- process.stdout.write(".");
211
- var func = pair[1];
212
- var start = new Date() - 0;
213
- func(function(err, cnt) {
214
- var end = new Date() - 0;
215
- var array = pair[2] || (pair[2] = []);
216
- array.push(end - start);
217
- pair[3] = cnt;
218
- setTimeout(callback, 100);
219
- });
220
- }
221
-
222
- // show result
223
- function end() {
224
- var title = "operation (" + opcount + " x " + limit + ")";
225
- process.stdout.write("\n");
226
-
227
- // table header
228
- var COL1 = 48;
229
- console.log(rpad(title, COL1), "|", " op ", "|", " ms ", "|", " op/s ");
230
- console.log(rpad("", COL1, "-"), "|", "------:", "|", "----:", "|", "-----:");
231
-
232
- // table body
233
- list.forEach(function(pair) {
234
- var name = pair[0];
235
- var op = pair[3];
236
- var array = pair[2];
237
- array = array.sort(function(a, b) {
238
- return a > b;
239
- });
240
- var fastest = array[0];
241
- var score = Math.floor(opcount / fastest * 1000);
242
- console.log(rpad(name, COL1), "|", lpad(op, 7), "|", lpad(fastest, 5), "|", lpad(score, 6));
243
- });
244
- }
245
- }
246
-
247
- run();
package/lib/benchmark.js DELETED
@@ -1,157 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var msgpack_node = try_require("msgpack");
4
- var msgpack_lite = try_require("../index");
5
- var msgpack_js = try_require("msgpack-js");
6
- var msgpack_js_v5 = try_require("msgpack-js-v5");
7
- var msgpack5 = try_require("msgpack5");
8
- var msgpack_unpack = try_require("msgpack-unpack");
9
- var msgpack_codec = try_require("msgpack.codec");
10
- var notepack = try_require("notepack");
11
-
12
- msgpack5 = msgpack5 && msgpack5();
13
- msgpack_codec = msgpack_codec && msgpack_codec.msgpack;
14
-
15
- var pkg = require("../package.json");
16
- var data = require("../test/example");
17
- var packed = msgpack_lite.encode(data);
18
- var expected = JSON.stringify(data);
19
-
20
- var argv = Array.prototype.slice.call(process.argv, 2);
21
-
22
- if (argv[0] === "-v") {
23
- console.warn(pkg.name + " " + pkg.version);
24
- process.exit(0);
25
- }
26
-
27
- var limit = 5;
28
- if (argv[0] - 0) limit = argv.shift() - 0;
29
- limit *= 1000;
30
-
31
- var COL1 = 57;
32
- var COL2 = 6;
33
- var COL3 = 5;
34
- var COL4 = 6;
35
-
36
- console.log(rpad("operation", COL1), "|", " op ", "|", " ms ", "|", " op/s ");
37
- console.log(rpad("", COL1, "-"), "|", lpad(":", COL2, "-"), "|", lpad(":", COL3, "-"), "|", lpad(":", COL4, "-"));
38
-
39
- var buf, obj;
40
-
41
- if (JSON) {
42
- buf = bench('buf = Buffer(JSON.stringify(obj));', JSON_stringify, data);
43
- obj = bench('obj = JSON.parse(buf);', JSON.parse, buf);
44
- test(obj);
45
- }
46
-
47
- if (msgpack_lite) {
48
- buf = bench('buf = require("msgpack-lite").encode(obj);', msgpack_lite.encode, data);
49
- obj = bench('obj = require("msgpack-lite").decode(buf);', msgpack_lite.decode, packed);
50
- test(obj);
51
- }
52
-
53
- if (msgpack_node) {
54
- buf = bench('buf = require("msgpack").pack(obj);', msgpack_node.pack, data);
55
- obj = bench('obj = require("msgpack").unpack(buf);', msgpack_node.unpack, buf);
56
- test(obj);
57
- }
58
-
59
- if (msgpack_codec) {
60
- buf = bench('buf = Buffer(require("msgpack.codec").msgpack.pack(obj));', msgpack_codec_pack, data);
61
- obj = bench('obj = require("msgpack.codec").msgpack.unpack(buf);', msgpack_codec.unpack, buf);
62
- test(obj);
63
- }
64
-
65
- if (msgpack_js_v5) {
66
- buf = bench('buf = require("msgpack-js-v5").encode(obj);', msgpack_js_v5.encode, data);
67
- obj = bench('obj = require("msgpack-js-v5").decode(buf);', msgpack_js_v5.decode, buf);
68
- test(obj);
69
- }
70
-
71
- if (msgpack_js) {
72
- buf = bench('buf = require("msgpack-js").encode(obj);', msgpack_js.encode, data);
73
- obj = bench('obj = require("msgpack-js").decode(buf);', msgpack_js.decode, buf);
74
- test(obj);
75
- }
76
-
77
- if (msgpack5) {
78
- buf = bench('buf = require("msgpack5")().encode(obj);', msgpack5.encode, data);
79
- obj = bench('obj = require("msgpack5")().decode(buf);', msgpack5.decode, buf);
80
- test(obj);
81
- }
82
-
83
- if (notepack) {
84
- buf = bench('buf = require("notepack").encode(obj);', notepack.encode, data);
85
- obj = bench('obj = require("notepack").decode(buf);', notepack.decode, buf);
86
- test(obj);
87
- }
88
-
89
- if (msgpack_unpack) {
90
- obj = bench('obj = require("msgpack-unpack").decode(buf);', msgpack_unpack, packed);
91
- test(obj);
92
- }
93
-
94
- function JSON_stringify(src) {
95
- return Buffer(JSON.stringify(src));
96
- }
97
-
98
- function msgpack_codec_pack(data) {
99
- return Buffer(msgpack_codec.pack(data));
100
- }
101
-
102
- function bench(name, func, src) {
103
- if (argv.length) {
104
- var match = argv.filter(function(grep) {
105
- return (name.indexOf(grep) > -1);
106
- });
107
- if (!match.length) return SKIP;
108
- }
109
- var ret, duration;
110
- var start = new Date() - 0;
111
- var count = 0;
112
- while (1) {
113
- var end = new Date() - 0;
114
- duration = end - start;
115
- if (duration >= limit) break;
116
- while ((++count) % 100) ret = func(src);
117
- }
118
- name = rpad(name, COL1);
119
- var score = Math.floor(count / duration * 1000);
120
- count = lpad(count, COL2);
121
- duration = lpad(duration, COL3);
122
- score = lpad(score, COL4);
123
- console.log(name, "|", count, "|", duration, "|", score);
124
- return ret;
125
- }
126
-
127
- function rpad(str, len, chr) {
128
- if (!chr) chr = " ";
129
- while (str.length < len) str += chr;
130
- return str;
131
- }
132
-
133
- function lpad(str, len, chr) {
134
- if (!chr) chr = " ";
135
- str += "";
136
- while (str.length < len) str = chr + str;
137
- return str;
138
- }
139
-
140
- function test(actual) {
141
- if (actual === SKIP) return;
142
- actual = JSON.stringify(actual);
143
- if (actual === expected) return;
144
- console.warn("expected: " + expected);
145
- console.warn("actual: " + actual);
146
- }
147
-
148
- function SKIP() {
149
- }
150
-
151
- function try_require(name) {
152
- try {
153
- return require(name);
154
- } catch (e) {
155
- // ignore
156
- }
157
- }