-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,2 @@ | ||
const packModule = require('./pack') | ||
exports.Packr = packModule.Packr | ||
exports.addExtension = require('./pack').addExtension | ||
exports.Encoder = exports.Packr | ||
const unpackModule = require('./unpack') | ||
const extractor = tryRequire('msgpackr-extract') | ||
if (extractor) | ||
unpackModule.setExtractor(extractor.extractStrings) | ||
exports.Unpackr = unpackModule.Unpackr | ||
exports.Decoder = exports.Unpackr | ||
exports.C1 = unpackModule.C1 | ||
exports.PackrStream = require('./stream').PackrStream | ||
exports.UnpackrStream = require('./stream').UnpackrStream | ||
exports.EncoderStream = exports.PackrStream | ||
exports.DecoderStream = exports.UnpackrStream | ||
const packr = new exports.Packr({ useRecords: false }) | ||
exports.unpack = unpackModule.unpack | ||
exports.unpackMultiple = unpackModule.unpackMultiple | ||
exports.pack = packModule.pack | ||
exports.decode = unpackModule.unpack | ||
exports.encode = packModule.pack | ||
exports.useRecords = false | ||
exports.mapsAsObjects = true | ||
exports.FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS | ||
Object.assign(exports, unpackModule.FLOAT32_OPTIONS) | ||
|
||
function tryRequire(moduleId) { | ||
try { | ||
return require(moduleId) | ||
} catch (error) { | ||
if (typeof window == 'undefined') | ||
console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message) | ||
else | ||
console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]) | ||
} | ||
} | ||
export { Packr, Encoder, addExtension, pack, encode } from './pack.js' | ||
export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS } from './unpack.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } from './pack.js' | ||
export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS } from './unpack.js' | ||
export { PackrStream, UnpackrStream, PackrStream as EncoderStream, UnpackrStream as DecoderStream } from './stream.js' | ||
import { setExtractor } from './unpack.js' | ||
import { createRequire } from 'module' | ||
|
||
const extractor = tryRequire('msgpackr-extract') | ||
if (extractor) | ||
setExtractor(extractor.extractStrings) | ||
/* | ||
Object.assign(exports, unpackModule.FLOAT32_OPTIONS) | ||
*/ | ||
function tryRequire(moduleId) { | ||
try { | ||
let require = createRequire(import.meta.url) | ||
return require(moduleId) | ||
} catch (error) { | ||
if (typeof window == 'undefined') | ||
console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message.split('\n')[0]) | ||
else | ||
console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import minify from "rollup-plugin-babel-minify"; | ||
import json from "@rollup/plugin-json"; | ||
|
||
export default [ | ||
{ | ||
input: "node.js", | ||
output: [ | ||
{ | ||
file: "dist/node.cjs", | ||
format: "cjs" | ||
} | ||
] | ||
}, | ||
{ | ||
input: "index.js", | ||
output: { | ||
file: "dist/index.js", | ||
format: "umd", | ||
name: "msgpackr" | ||
} | ||
}, | ||
{ | ||
input: "index.js", | ||
plugins: [minify({ | ||
})], | ||
output: { | ||
file: "dist/index.min.js", | ||
format: "umd", | ||
name: "msgpackr" | ||
} | ||
}, | ||
{ | ||
input: "tests/test.js", | ||
plugins: [json()], | ||
external: ['chai', '../index.js'], | ||
output: { | ||
file: "dist/test.js", | ||
format: "iife", | ||
globals: { | ||
chai: 'chai', | ||
'./index.js': 'msgpackr', | ||
}, | ||
} | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PackrStream, UnpackrStream } from '../node.js' | ||
import stream from 'stream' | ||
|
||
suite('msgpackr node stream tests', function(){ | ||
test('serialize/parse stream', () => { | ||
const serializeStream = new PackrStream({ | ||
}) | ||
const parseStream = new UnpackrStream() | ||
serializeStream.pipe(parseStream) | ||
const received = [] | ||
parseStream.on('data', data => { | ||
received.push(data) | ||
}) | ||
const messages = [{ | ||
name: 'first' | ||
}, { | ||
name: 'second' | ||
}, { | ||
name: 'third' | ||
}, { | ||
name: 'third', | ||
extra: [1, 3, { foo: 'hi'}, 'bye'] | ||
}] | ||
for (const message of messages) | ||
serializeStream.write(message) | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
assert.deepEqual(received, messages) | ||
resolve() | ||
}, 10) | ||
}) | ||
}) | ||
test('stream from buffer', () => new Promise(async resolve => { | ||
const parseStream = new UnpackrStream() | ||
let values = [] | ||
parseStream.on('data', (value) => { | ||
values.push(value) | ||
}) | ||
parseStream.on('end', () => { | ||
assert.deepEqual(values, [1, 2]) | ||
resolve() | ||
}) | ||
let bufferStream = new stream.Duplex() | ||
bufferStream.pipe(parseStream) | ||
bufferStream.push(new Uint8Array([1, 2])) | ||
bufferStream.push(null) | ||
})) | ||
}) |
Oops, something went wrong.