Skip to content

Commit

Permalink
Remove push/pop index from incremental serializer.
Browse files Browse the repository at this point in the history
Closes #434.
  • Loading branch information
flatheadmill committed Apr 30, 2020
1 parent a3e9ae4 commit 9ea3bcb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
2 changes: 0 additions & 2 deletions parse.inc.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ function generate (packet) {
`)
}

// TODO Vivify through a funciton so that `object = vivify()`.
// TOOO Write directly to object, I think, get rid of `$_`?
const object = `parsers.inc.${packet.name}`
return $(`
${object} = function (${signature.join(', ')}) {
Expand Down
9 changes: 2 additions & 7 deletions serialize.inc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ function generate (packet) {
// TODO I don't need to push and pop $i.
function lengthEncoded (path, packet) {
variables.i = true
variables.I = true
const i = `$i[${$i}]`
const I = `$I[${$i}]`
const again = $step
const source = $(`
`, dispatch(`${path}[${i}]`, packet.element), `
Expand All @@ -75,8 +73,6 @@ function generate (packet) {
$step = ${again}
continue
}
$i.pop()
`)
$i--
return source
Expand All @@ -86,7 +82,7 @@ function generate (packet) {
$i++
return $(`
`, integer(path + '.length', packet), `
$i.push(0)
$i[${$i}] = 0
`)

}
Expand Down Expand Up @@ -225,8 +221,7 @@ function generate (packet) {
const signatories = {
packet: `${packet.name}`,
step: '$step = 0',
i: '$i = []',
I: '$I = []'
i: '$i = []'
}
const signature = Object.keys(signatories)
.filter(key => variables[key])
Expand Down
6 changes: 2 additions & 4 deletions test/generated/length-encoded-fixed.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (serializers) {
serializers.inc.object = function (object, $step = 0, $i = [], $I = []) {
serializers.inc.object = function (object, $step = 0, $i = []) {
let $bite, $stop, $_

return function serialize ($buffer, $start, $end) {
Expand All @@ -21,7 +21,7 @@ module.exports = function (serializers) {
$bite--
}

$i.push(0)
$i[0] = 0

case 2:

Expand Down Expand Up @@ -62,8 +62,6 @@ module.exports = function (serializers) {
continue
}

$i.pop()

$step = 6

case 6:
Expand Down
10 changes: 3 additions & 7 deletions test/generated/length-encoded-variable.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (serializers) {
serializers.inc.object = function (object, $step = 0, $i = [], $I = []) {
serializers.inc.object = function (object, $step = 0, $i = []) {
let $bite, $stop, $_

return function serialize ($buffer, $start, $end) {
Expand All @@ -21,7 +21,7 @@ module.exports = function (serializers) {
$bite--
}

$i.push(0)
$i[0] = 0

case 2:

Expand All @@ -39,7 +39,7 @@ module.exports = function (serializers) {
$bite--
}

$i.push(0)
$i[1] = 0

case 4:

Expand All @@ -63,15 +63,11 @@ module.exports = function (serializers) {
continue
}

$i.pop()

if (++$i[0] != object.array.length) {
$step = 2
continue
}

$i.pop()

$step = 6

case 6:
Expand Down
6 changes: 2 additions & 4 deletions test/generated/length-encoded-words.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (serializers) {
serializers.inc.object = function (object, $step = 0, $i = [], $I = []) {
serializers.inc.object = function (object, $step = 0, $i = []) {
let $bite, $stop, $_

return function serialize ($buffer, $start, $end) {
Expand All @@ -21,7 +21,7 @@ module.exports = function (serializers) {
$bite--
}

$i.push(0)
$i[0] = 0

case 2:

Expand All @@ -45,8 +45,6 @@ module.exports = function (serializers) {
continue
}

$i.pop()

$step = 4

case 4:
Expand Down

0 comments on commit 9ea3bcb

Please sign in to comment.