Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kriszyp/msgpackr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.8
Choose a base ref
...
head repository: kriszyp/msgpackr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.9.9
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 8, 2023

  1. Copy the full SHA
    4b01143 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6b010f5 View commit details
Showing with 23 additions and 22 deletions.
  1. +2 −2 pack.js
  2. +1 −1 package.json
  3. +20 −19 struct.js
4 changes: 2 additions & 2 deletions pack.js
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ export class Packr extends Unpackr {
let newSharedData = prepareStructures(structures, packr);
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
// get updated structures and try again if the update failed
return packr.pack(value)
return packr.pack(value, encodeOptions)
}
packr.lastNamedStructuresLength = sharedLength
return returnBuffer
@@ -775,7 +775,7 @@ export class Packr extends Unpackr {
}
}
const writeStruct = (object, safePrototype) => {
let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
if (notifySharedUpdate)
return hasSharedUpdate = true;
position = newPosition;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "msgpackr",
"author": "Kris Zyp",
"version": "1.9.8",
"version": "1.9.9",
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
"license": "MIT",
"types": "./index.d.ts",
39 changes: 20 additions & 19 deletions struct.js
Original file line number Diff line number Diff line change
@@ -69,20 +69,20 @@ const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
const TYPE = Symbol('type');
const PARENT = Symbol('parent');
setWriteStructSlots(writeStruct, prepareStructures);
function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
let typedStructs = packr.typedStructs || (packr.typedStructs = []);
// note that we rely on pack.js to load stored structures before we get to this point
let targetView = target.dataView;
let refsStartPosition = (typedStructs.lastStringStart || 100) + position;
let safeEnd = target.length - 10;
let start = position;
if (position > safeEnd) {
let lastStart = start;
target = makeRoom(position);
targetView = target.dataView;
position -= lastStart;
refsStartPosition -= lastStart;
start = 0;
position -= encodingStart;
start -= encodingStart;
refsStartPosition -= encodingStart;
encodingStart = 0;
safeEnd = target.length - 10;
}

@@ -120,13 +120,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
};
}
if (position > safeEnd) {
let lastStart = start;
target = makeRoom(position);
targetView = target.dataView;
position -= lastStart;
refsStartPosition -= lastStart;
refPosition -= lastStart;
start = 0;
position -= encodingStart;
start -= encodingStart;
refsStartPosition -= encodingStart;
refPosition -= encodingStart;
encodingStart = 0;
safeEnd = target.length - 10
}
switch (typeof value) {
@@ -165,13 +165,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
let strLength = value.length;
refOffset = refPosition - refsStartPosition;
if ((strLength << 2) + refPosition > safeEnd) {
let lastStart = start;
target = makeRoom((strLength << 2) + refPosition);
targetView = target.dataView;
position -= lastStart;
refsStartPosition -= lastStart;
refPosition -= lastStart;
start = 0;
position -= encodingStart;
start -= encodingStart;
refsStartPosition -= encodingStart;
refPosition -= encodingStart;
encodingStart = 0;
safeEnd = target.length - 10
}
if (strLength > ((0xff00 + refOffset) >> 2)) {
@@ -330,9 +330,10 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
refPosition = newPosition.position;
targetView = newPosition.targetView;
target = newPosition.target;
refsStartPosition -= start;
position -= start;
start = 0;
refsStartPosition -= encodingStart;
position -= encodingStart;
start -= encodingStart;
encodingStart = 0;
} else
refPosition = newPosition;
if (size === 2) {
@@ -406,7 +407,7 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
if (refsStartPosition === refPosition)
return position; // no refs
typedStructs.lastStringStart = position - start;
return writeStruct(object, target, start, structures, makeRoom, pack, packr);
return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
}
return refPosition;
}