Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding of arrays fields (issue #30) #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions fixtures/nested-complex-4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports.schema = [{
arr1: ['uint8'],
arr2: ['uint8']
}]

module.exports.items = [
[{
arr1: [9, 9, 9, 9, 9, 9, 9],
arr2: [8, 8, 8]
}],
[{
arr1: [9, 9, 9, 9, 9, 9, 9],
arr2: []
}]
]
123 changes: 123 additions & 0 deletions fixtures/nested-complex-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
module.exports.schema = {
arr1: [{
arr1: ['uint8'],
val1: 'uint8',
arr2: [['uint8']],
arr3: ['uint8'],
arr4: [
{
arr1: ['uint8'],
arr2: ['uint8']
},
'uint8',
[{
arr1: ['uint8'],
arr2: [[{ arr1: ['uint8'], arr2: ['string'] }]]
}]
]
}]
}

module.exports.items = [
{
arr1: [
{
arr1: [3, 3, 3, 3, 3, 3, 3],
val1: 9,
arr2: [[2, 2], [4, 4, 4]],
arr3: [8],
arr4: [
{
arr1: [1, 2, 3],
arr2: [3, 2, 1]
},
55,
[{
arr1: [4, 5],
arr2: [[{ arr1: [6, 7, 8], arr2: ['999'] }], [{ arr1: [9, 10, 11], arr2: ['888'] }, { arr1: [12], arr2: ['777'] }]]
}]
]
}
]
},
{
arr1: [
{
arr1: [3, 3, 3, 3, 3, 3, 3],
val1: 9,
arr2: [[2, 2], [4, 4, 4]],
arr3: [8],
arr4: [
{
arr1: [1, 2, 3],
arr2: [3, 2, 1]
},
55,
[{
arr1: [4, 5],
arr2: [[{ arr1: [6, 7, 8], arr2: ['999'] }], [{ arr1: [9, 10, 11], arr2: ['888'] }, { arr1: [12], arr2: ['777'] }]]
}]
]
},
{
arr1: [3, 3, 3, 3, 3, 3, 3],
val1: 9,
arr2: [[2, 2], [4, 4, 4]],
arr3: [8],
arr4: [
{
arr1: [1, 2, 3],
arr2: [3, 2, 1]
},
55,
[{
arr1: [4, 5],
arr2: [[{ arr1: [6, 7, 8], arr2: ['999'] }], [{ arr1: [9, 10, 11], arr2: ['888'] }, { arr1: [12], arr2: ['777'] }]]
}]
]
}
]
},
{
arr1: [
{
arr1: [3, 3, 3, 3, 3, 3, 3],
val1: 9,
arr2: [[2, 2], [4, 4, 4]],
arr3: [],
arr4: [
{
arr1: [1, 2, 3],
arr2: []
},
55,
[{
arr1: [4, 5],
arr2: [[{ arr1: [6, 7, 8], arr2: [] }], [{ arr1: [9, 10, 11], arr2: [] }, { arr1: [12], arr2: [] }]]
}]
]
}
]
},
{
arr1: [
{
arr1: [],
val1: 0,
arr2: [[]],
arr3: [],
arr4: [
{
arr1: [],
arr2: []
},
0,
[{
arr1: [],
arr2: [[{ arr1: [], arr2: [] }]]
}]
]
}
]
}
]
117 changes: 117 additions & 0 deletions fixtures/nested-complex-6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
module.exports.schema = {
id: "int32",
x: "int32",
y: "int32",
placables: [{
item: "string",
ownerId: "string",
id: "string",
claimable: "boolean",
claimed: "boolean",
coord: { x: "int32", y: "int32" },
expiration: "string",
spriteMap: "string",
spriteMapKey: "string",
rotation: "int32"
}],
dimensions: "int32",
areaDimensions: "int32",
areas: [{
id: "int32",
x: "int32",
y: "int32",
biome: "int32",
weight: "float32",
isAccessible: "boolean",
resources: [{
id: "string",
position: { x: "int32", y: "int32" },
active: "boolean",
classification: "string",
interactive: "boolean",
abstract: "string",
availability: "int32",
state: { i: "int32", w: "string", a: "string", l: "string", r: "string", sha: "string", shi: "string" }
}],
boundries: {
vertices: [{ x: "float32", y: "float32" }],
min: { x: "int32", y: "int32" },
max: { x: "int32", y: "int32" },
size: { x: "int32", y: "int32" }
}
}],
boundries: ["int32"]
}

module.exports.items = [
{
"id": 2111339991,
"placables": [],
"x": 3,
"y": 2,
"dimensions": 16,
"areaDimensions": 128,
"areas": [
{
"id": 2114289141,
"x": 48,
"y": 32,
"boundries": {
"vertices": [
{ "x": -35.052616119384766, "y": -45.469512939453125 },
{ "x": -14.295523643493652, "y": 4.885631084442139 },
{ "x": 30.104928970336914, "y": 24.392292022705078 }
],
"min": { "x": -35, "y": -100 },
"max": { "x": 109, "y": 24 },
"size": { "x": 144, "y": 124 }
},
"biome": 0,
"weight": 0.06912259757518768,
"isAccessible": true,
"resources": []
},
{
"id": 2114289146,
"x": 48,
"y": 37,
"boundries": {
"vertices": [
{ "x": -63.573089599609375, "y": -62.38645553588867 },
{ "x": -29.82942771911621, "y": 20.665653228759766 },
{ "x": -23.759756088256836, "y": 28.030988693237305 }
],
"min": { "x": -63, "y": -105 },
"max": { "x": 124, "y": 93 },
"size": { "x": 188, "y": 199 }
},
"biome": 0,
"weight": 0.21172510087490082,
"isAccessible": true,
"resources": [
{
"active": true,
"abstract": "Proc",
"classification": "Wheat",
"availability": 1000,
"interactive": true,
"position": { "x": 69, "y": -84 },
"state": { "i": 4, "w": "0", "r": "-", "a": "-", "l": "-", "sha": "-", "shi": "-" },
"id": "2114289146_2_4"
},
{
"active": true,
"abstract": "Proc",
"classification": "Wheat",
"availability": 1000,
"interactive": true,
"position": { "x": 48, "y": -78 },
"state": { "i": 4, "w": "0", "r": "-", "a": "-", "l": "-", "sha": "-", "shi": "-" },
"id": "2114289146_3_4"
}
]
}
],
"boundries": [0, 0, 2, 2]
}
]
19 changes: 10 additions & 9 deletions schemapack.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ function getCompiledSchema(schema, validate) {
var repEncArrStack = [""];
var repDecArrStack = [""];
var repByteCountStack = [""];
var tmpRepEncArr = "";
var tmpRepDecArr = "";
var tmpRepByteCount = "";

schema = { 'a': schema };

Expand Down Expand Up @@ -324,14 +321,18 @@ function getCompiledSchema(schema, validate) {

compileSchema(val, true);

tmpRepEncArr = encArrayLength + processArrayEnd(val, newID, repEncArrStack.pop() + tmpRepEncArr, repEncArrStack.length);
tmpRepDecArr = decArrayLength + processArrayEnd(val, newID, repDecArrStack.pop() + tmpRepDecArr, repEncArrStack.length, arrLenStr);
tmpRepByteCount = byteArrayLength + processArrayEnd(val, newID, repByteCountStack.pop() + tmpRepByteCount, repEncArrStack.length);
var repEncArr = encArrayLength + processArrayEnd(val, newID, repEncArrStack.pop(), repEncArrStack.length);
var repDecArr = decArrayLength + processArrayEnd(val, newID, repDecArrStack.pop(), repEncArrStack.length, arrLenStr);
var repByteCount = byteArrayLength + processArrayEnd(val, newID, repByteCountStack.pop(), repEncArrStack.length);

if (repEncArrStack.length === 1) {
strEncodeFunction += tmpRepEncArr; tmpRepEncArr = "";
strDecodeFunction += tmpRepDecArr; tmpRepDecArr = "";
strByteCount += tmpRepByteCount; tmpRepByteCount = "";
strEncodeFunction += repEncArr;
strDecodeFunction += repDecArr;
strByteCount += repByteCount;
} else {
repEncArrStack[repEncArrStack.length - 1] += repEncArr
repDecArrStack[repDecArrStack.length - 1] += repDecArr
repByteCountStack[repByteCountStack.length - 1] += repByteCount
}
} else if (typeof val === 'object') {
var newID = incID + 1;
Expand Down