-
Notifications
You must be signed in to change notification settings - Fork 29
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
add addTypesToCompiler and addTypesToInterperter method for ProtoDef #81
Conversation
README.md
Outdated
### addTypesToCompiler (type, compiler) | ||
Adds prismarine-nbt types to an ProtoDef compiler instance | ||
|
||
### addTypesToInterperter (type, interperter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
nbt.js
Outdated
compiler.addTypes(require('./compiler-optional').interpert) | ||
let proto = beNbtJson | ||
if (type === 'littleVarint') { | ||
compiler.addTypes(require('./compiler-zigzag').interpert) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interpret
compiler-optional.js
Outdated
@@ -0,0 +1,57 @@ | |||
function readOptionalNbt (buffer, offset, { tagType } = { tagType: 'nbt' }, rootNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove compiler from the name since it provides both version / and let's do the same for other files
nice, would be good to add a simple test using this .addTypesToCompiler and using 'nbt' in a custom protodef proto |
But also let's try to integrate this in nmp PR and see if that works well |
…ove broken tagType defaults
"anonOptionalNbt": [ | ||
"optionalNbtType", | ||
{ | ||
"tagType": "anonymousNbt" | ||
} | ||
], | ||
"optionalNbt": [ | ||
"optionalNbtType", | ||
{ | ||
"tagType": "nbt" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These (anonOptionalNbt and optionalNbt) don't have to be here, but can be put into all of the the protocol.json's if needed. optionalNbtType
is the base type that can take a custom tagType
to read from the stream. I kept optionalNbt
naming here to refer to the default nbt
tag just for compatibility with current protocol.json's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to have them here
bench/compiled_nbt.js
Outdated
proto.addTypes(require('../nbt.json')) | ||
function main (nbTests = 10000) { | ||
const buffer = fs.readFileSync(__dirname + '/../sample/bigtest.nbt') // eslint-disable-line n/no-path-concat | ||
const validate = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the compiled_nbt benchmark script inside the test workflow now, so it should test the 2 new methods
This fails with validation on with protodef-validator
{
"keyword": "enum",
"dataPath": "",
"schemaPath": "#/oneOf/0/enum",
"params": {
"allowedValues": [
"native"
]
},
"message": "should be equal to one of the allowed values",
"schema": [
"native"
],
"parentSchema": {
"enum": [
"native"
]
},
"data": [
"container",
[
{
"name": "type",
"type": "nbtMapper"
},
{
"name": "name",
"type": "nbtTagName"
},
{
"name": "value",
"type": [
"nbtSwitch",
{
"type": "type"
}
]
}
]
]
}
The tests run ok disabling the validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is some type not added as native? how come it fails validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah looks like missing native was the cause, should be fixed now
thanks |
/makerelease |
No description provided.