-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add addTypesToCompiler and addTypesToInterperter method for ProtoDef (#…
…81) * add addTypesToCompiler and addTypesToInterperter method for ProtoDef * add nbtTagName alias to shortString for interperter * add to types * add optionalNbt type from node-minecraft-protocol * fix naming * add anonOptionalNbt and optionalNbt types from nmp protocol.json, remove broken tagType defaults * fix optional compiler code * run benchmark script on test to test addTypesToCompiler/addTypesToInterpreter * Update zigzag.js * Update zigzag.js lint * update nbt.json
- Loading branch information
1 parent
3d02c78
commit e218297
Showing
8 changed files
with
163 additions
and
35 deletions.
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
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,54 @@ | ||
function readOptionalNbt (buffer, offset, { tagType }, rootNode) { | ||
if (offset + 1 > buffer.length) { throw new Error('Read out of bounds') } | ||
if (buffer.readInt8(offset) === 0) return { size: 1 } | ||
return this.read(buffer, offset, tagType, rootNode) | ||
} | ||
|
||
function writeOptionalNbt (value, buffer, offset, { tagType }, rootNode) { | ||
if (value === undefined) { | ||
buffer.writeInt8(0, offset) | ||
return offset + 1 | ||
} | ||
return this.write(value, buffer, offset, tagType, rootNode) | ||
} | ||
|
||
function sizeOfOptionalNbt (value, { tagType }, rootNode) { | ||
if (value === undefined) { return 1 } | ||
return this.sizeOf(value, tagType, tagType, rootNode) | ||
} | ||
|
||
const compiler = { | ||
Read: { | ||
optionalNbtType: ['parametrizable', (compiler, { tagType }) => { | ||
return compiler.wrapCode(` | ||
if (offset + 1 > buffer.length) { throw new PartialReadError() } | ||
if (buffer.readInt8(offset) === 0) return { size: 1 } | ||
return ${compiler.callType(tagType)} | ||
`) | ||
}] | ||
}, | ||
Write: { | ||
optionalNbtType: ['parametrizable', (compiler, { tagType }) => { | ||
return compiler.wrapCode(` | ||
if (value === undefined) { | ||
buffer.writeInt8(0, offset) | ||
return offset + 1 | ||
} | ||
return ${compiler.callType('value', tagType)} | ||
`) | ||
}] | ||
}, | ||
SizeOf: { | ||
optionalNbtType: ['parametrizable', (compiler, { tagType }) => { | ||
return compiler.wrapCode(` | ||
if (value === undefined) { return 1 } | ||
return ${compiler.callType('value', tagType)} | ||
`) | ||
}] | ||
} | ||
} | ||
|
||
module.exports = { | ||
compiler, | ||
interpret: { optionalNbtType: [readOptionalNbt, writeOptionalNbt, sizeOfOptionalNbt] } | ||
} |
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,7 @@ | ||
/* eslint-env mocha */ | ||
const bench = require('../bench/compiled_nbt') | ||
describe('protodef', function () { | ||
it('benchmark', () => { | ||
bench(1000) | ||
}) | ||
}) |
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