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

add addTypesToCompiler and addTypesToInterperter method for ProtoDef #81

Merged
merged 11 commits into from
Dec 27, 2023

Conversation

extremeheat
Copy link
Member

No description provided.

README.md Outdated
### addTypesToCompiler (type, compiler)
Adds prismarine-nbt types to an ProtoDef compiler instance

### addTypesToInterperter (type, interperter)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interpret

@@ -0,0 +1,57 @@
function readOptionalNbt (buffer, offset, { tagType } = { tagType: 'nbt' }, rootNode) {
Copy link
Member

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

@rom1504
Copy link
Member

rom1504 commented Dec 25, 2023

nice, would be good to add a simple test using this .addTypesToCompiler and using 'nbt' in a custom protodef proto
so we don't have to rely on nmp tests to make sure this code works

@rom1504
Copy link
Member

rom1504 commented Dec 25, 2023

But also let's try to integrate this in nmp PR and see if that works well

Comment on lines +147 to 158
"anonOptionalNbt": [
"optionalNbtType",
{
"tagType": "anonymousNbt"
}
],
"optionalNbt": [
"optionalNbtType",
{
"tagType": "nbt"
}
]
Copy link
Member Author

@extremeheat extremeheat Dec 26, 2023

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

Copy link
Member

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

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
Copy link
Member Author

@extremeheat extremeheat Dec 26, 2023

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

Copy link
Member

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?

Copy link
Member Author

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

@rom1504 rom1504 merged commit e218297 into PrismarineJS:master Dec 27, 2023
3 checks passed
@rom1504
Copy link
Member

rom1504 commented Dec 27, 2023

thanks

@rom1504
Copy link
Member

rom1504 commented Dec 27, 2023

/makerelease

@rom1504bot rom1504bot mentioned this pull request Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants