Comparing version 1.0.0 to 1.0.1
@@ -31,3 +31,3 @@ exports.Packr = require('./pack').Packr | ||
if (typeof window == 'undefined') | ||
console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message.split('\n')[0]) | ||
console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message) | ||
else | ||
@@ -34,0 +34,0 @@ console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]) |
35
pack.js
@@ -52,3 +52,3 @@ "use strict" | ||
this.pack = function(value) { | ||
this.pack = this.encode = function(value) { | ||
if (!target) { | ||
@@ -529,5 +529,2 @@ target = new ByteArrayAllocate(8192) | ||
} | ||
encode(value) { | ||
return this.pack(value) | ||
} | ||
useBuffer(buffer) { | ||
@@ -617,3 +614,3 @@ // this means we are finished using our own buffer and we can write over it safely | ||
if (constructor !== ByteArray && this.structuredClone) | ||
writeExtBuffer(typedArray.buffer, typedArrays.indexOf(constructor.name), allocateForWrite) | ||
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite) | ||
else | ||
@@ -629,23 +626,27 @@ writeBuffer(typedArray, allocateForWrite) | ||
function writeExtBuffer(buffer, type, allocateForWrite) { | ||
let length = buffer.byteLength | ||
let { target, position, targetView } = allocateForWrite(7 + length) | ||
/*if (length < 0x100) { | ||
function writeExtBuffer(typedArray, type, allocateForWrite, encode) { | ||
let length = typedArray.byteLength | ||
let offset = typedArray.byteOffset || 0 | ||
let buffer = typedArray.buffer || typedArray | ||
if (length + 1 < 0x100) { | ||
var { target, position } = allocateForWrite(4 + length) | ||
target[position++] = 0xc7 | ||
target[position++] = length | ||
} else if (length < 0x10000) { | ||
target[position++] = length + 1 | ||
} else if (length + 1 < 0x10000) { | ||
var { target, position } = allocateForWrite(5 + length) | ||
target[position++] = 0xc8 | ||
target[position++] = length >> 8 | ||
target[position++] = length & 0xff | ||
} else {*/ | ||
target[position++] = (length + 1) >> 8 | ||
target[position++] = (length + 1) & 0xff | ||
} else { | ||
var { target, position, targetView } = allocateForWrite(7 + length) | ||
target[position++] = 0xc9 | ||
targetView.setUint32(position, length + 1) // plus one for the type byte | ||
position += 4 | ||
//} | ||
} | ||
target[position++] = 0x74 // "t" for typed array | ||
target[position++] = type | ||
if (hasNodeBuffer) | ||
Buffer.from(buffer).copy(target, position) | ||
Buffer.from(buffer, offset, length).copy(target, position) | ||
else | ||
copyBinary(new Uint8Array(buffer), target, position, 0, length) | ||
copyBinary(new Uint8Array(buffer, offset, length), target, position, 0, length) | ||
} | ||
@@ -652,0 +653,0 @@ function writeBuffer(buffer, allocateForWrite) { |
{ | ||
"name": "msgpackr", | ||
"author": "Kris Zyp", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -35,3 +35,3 @@ # msgpackr | ||
import { PackrStream } from 'msgpackr'; | ||
let stream = PackrStream(); | ||
let stream = new PackrStream(); | ||
stream.write(myData); | ||
@@ -43,4 +43,4 @@ | ||
import { PackrStream } from 'msgpackr'; | ||
let sendingStream = PackrStream(); | ||
let receivingStream = UnpackrStream(); | ||
let sendingStream = new PackrStream(); | ||
let receivingStream = new UnpackrStream(); | ||
// we are just piping to our own stream, but normally you would send and | ||
@@ -92,3 +92,3 @@ // receive over some type of inter-process or network connection. | ||
import { Packr } from 'msgpackr'; | ||
let packr = Packr(); | ||
let packr = new Packr(); | ||
packr.pack(bigDataWithLotsOfObjects); | ||
@@ -106,3 +106,3 @@ | ||
import { Packr } from 'msgpackr'; | ||
let packr = Packr({ | ||
let packr = new Packr({ | ||
structures: [... structures that were last generated ...] | ||
@@ -114,3 +114,3 @@ }); | ||
import { Packr } from 'msgpackr'; | ||
let packr = Packr({ | ||
let packr = new Packr({ | ||
getStructures() { | ||
@@ -248,2 +248,7 @@ // storing our data in file (but we could also store in a db or key-value store) | ||
## Alternate Encoding/Package | ||
The high-performance serialization and deserialization algorithms in the msgpackr package are also available in the [cbor-x](https://github.com/kriszyp/cbor-x) for the CBOR format. A quick summary of the pros and cons of using MessagePack vs CBOR are: | ||
* MessagePack has wider adoption, and, at least with this implementation is slightly more efficient. | ||
* CBOR has an official IETF standardization track, and the record extensions is conceptually/philosophically a better fit for CBOR tags. | ||
## License | ||
@@ -250,0 +255,0 @@ |
@@ -182,2 +182,6 @@ //var inspector = require('inspector') | ||
test('structured cloning: types', function() { | ||
let b = Buffer.alloc(20) | ||
let fa = new Float32Array(b.buffer, 8, 2) | ||
fa[0] = 2.25 | ||
fa[1] = 6 | ||
let object = { | ||
@@ -187,3 +191,3 @@ error: new Error('test'), | ||
regexp: /test/gi, | ||
float32Array: new Float32Array([2.25,6]), | ||
float32Array: fa, | ||
uint16Array: new Uint16Array([3,4]) | ||
@@ -190,0 +194,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
236867
2946
258