-
Notifications
You must be signed in to change notification settings - Fork 56
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
5 changed files
with
75 additions
and
1 deletion.
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
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,37 @@ | ||
import packModule from './pack.js' | ||
import unpackModule from './unpack.js' | ||
|
||
export const Packr = packModule.Packr | ||
export const addExtension = packModule.addExtension | ||
export const Encoder = packModule.Packr | ||
let extractor = tryRequire('msgpackr-extract') | ||
if (extractor) | ||
unpackModule.setExtractor(extractor.extractStrings) | ||
export const Unpackr = unpackModule.Unpackr | ||
export const Decoder = unpackModule.Unpackr | ||
import stream from './stream.js' | ||
export const PackrStream = stream.PackrStream | ||
export const UnpackrStream = stream.UnpackrStream | ||
export const EncoderStream = stream.PackrStream | ||
export const DecoderStream = stream.UnpackrStream | ||
let packr = new packModule.Packr({ useRecords: false }) | ||
export const unpack = packr.unpack | ||
export const pack = packr.pack | ||
export const decode = packr.unpack | ||
export const encode = packr.pack | ||
export const ALWAYS = 1 | ||
export const DECIMAL_ROUND = 3 | ||
export const DECIMAL_FIT = 4 | ||
|
||
|
||
function tryRequire(moduleId) { | ||
try { | ||
let require = module.createRequire() | ||
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,31 @@ | ||
import { pack, unpack } from '../index.mjs' | ||
var ITERATIONS = 10000 | ||
|
||
suite('msgpackr basic tests from module', function(){ | ||
test('pack/unpack data', function(){ | ||
var data = { | ||
data: [ | ||
{ a: 1, name: 'one', type: 'odd', isOdd: true }, | ||
{ a: 2, name: 'two', type: 'even'}, | ||
{ a: 3, name: 'three', type: 'odd', isOdd: true }, | ||
{ a: 4, name: 'four', type: 'even'}, | ||
{ a: 5, name: 'five', type: 'odd', isOdd: true }, | ||
{ a: 6, name: 'six', type: 'even', isOdd: null } | ||
], | ||
description: 'some names', | ||
types: ['odd', 'even'], | ||
convertEnumToNum: [ | ||
{ prop: 'test' }, | ||
{ prop: 'test' }, | ||
{ prop: 'test' }, | ||
{ prop: 1 }, | ||
{ prop: 2 }, | ||
{ prop: [undefined] }, | ||
{ prop: null } | ||
] | ||
} | ||
var serialized = pack(data) | ||
var deserialized = unpack(serialized) | ||
assert.deepEqual(deserialized, data) | ||
}) | ||
}) |
2 comments
on commit 5e4d2e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chase-moskal noticed on kawanet/msgpack-lite#113 you might be looking for msgpack implementation with ESM support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kriszyp i'm happy to see that you're bringing msgpack into the future! awesome work, i hope you keep it up!
might be worth including the unofficial package.json field
"module": "./index.mjs",
which some community tooling like pika might respond to