mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-27 17:55:45 -05:00
Add compiler example (#841)
* Initial commit * require minecraft-data * use buffer.compare instead of === * use .equals * Fix flipped serializer
This commit is contained in:
parent
bfb1472e7e
commit
294e20b54a
2 changed files with 30 additions and 0 deletions
20
examples/compiler_parse_buffer/index.js
Normal file
20
examples/compiler_parse_buffer/index.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const { createSerializer, createDeserializer, states } = require('minecraft-protocol')
|
||||
const mcPackets = require('minecraft-packets')
|
||||
|
||||
const serializer = createSerializer({ state: states.PLAY, version: '1.16.5', isServer: true })
|
||||
const deserializer = createDeserializer({ state: states.PLAY, version: '1.16.5' })
|
||||
|
||||
function convertBufferToObject (buffer) {
|
||||
return deserializer.parsePacketBuffer(buffer)
|
||||
}
|
||||
|
||||
function convertObjectToBuffer (object) {
|
||||
return serializer.createPacketBuffer(object)
|
||||
}
|
||||
|
||||
const buffer = mcPackets.pc['1.16.5']['from-server'].abilities[0].raw
|
||||
const parsed = convertBufferToObject(buffer).data
|
||||
const parsedBuffer = convertObjectToBuffer(parsed)
|
||||
console.log(buffer)
|
||||
console.log(parsedBuffer)
|
||||
console.log(buffer.equals(parsedBuffer))
|
10
examples/compiler_parse_buffer/package.json
Normal file
10
examples/compiler_parse_buffer/package.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "node-minecraft-protocol-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"minecraft-packets": "^1.1.5"
|
||||
},
|
||||
"description": "A node-minecraft-protocol example"
|
||||
}
|
||||
|
Loading…
Reference in a new issue