Skip to content

Commit 347e303

Browse files
authored
Remove protodef varint types (#552)
Remove protodef types which are now natively in ProtoDef
1 parent f48b508 commit 347e303

File tree

3 files changed

+4
-140
lines changed

3 files changed

+4
-140
lines changed

src/datatypes/compiler-minecraft.js

+1-69
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
const UUID = require('uuid-1345')
33
const minecraft = require('./minecraft')
4-
const { Read, Write, SizeOf } = require('./varlong')
4+
const [Read, Write, SizeOf] = [{}, {}, {}]
55

66
/**
77
* UUIDs
@@ -116,74 +116,6 @@ Read.lnbt = ['native', minecraft.lnbt[0]]
116116
Write.lnbt = ['native', minecraft.lnbt[1]]
117117
SizeOf.lnbt = ['native', minecraft.lnbt[2]]
118118

119-
/**
120-
* Bits
121-
*/
122-
123-
Read.bitflags = ['parametrizable', (compiler, { type, flags, shift, big }) => {
124-
let fstr = JSON.stringify(flags)
125-
if (Array.isArray(flags)) {
126-
fstr = '{'
127-
flags.map((v, k) => fstr += `"${v}": ${big ? 1n << BigInt(k) : 1 << k}` + (big ? 'n,' : ','))
128-
fstr += '}'
129-
} else if (shift) {
130-
fstr = '{'
131-
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},`;
132-
fstr += '}'
133-
}
134-
return compiler.wrapCode(`
135-
const { value: _value, size } = ${compiler.callType(type, 'offset')}
136-
const value = { _value }
137-
const flags = ${fstr}
138-
for (const key in flags) {
139-
value[key] = (_value & flags[key]) == flags[key]
140-
}
141-
return { value, size }
142-
`.trim())
143-
}]
144-
145-
Write.bitflags = ['parametrizable', (compiler, { type, flags, shift, big }) => {
146-
let fstr = JSON.stringify(flags)
147-
if (Array.isArray(flags)) {
148-
fstr = '{'
149-
flags.map((v, k) => fstr += `"${v}": ${big ? 1n << BigInt(k) : 1 << k}` + (big ? 'n,' : ','))
150-
fstr += '}'
151-
} else if (shift) {
152-
fstr = '{'
153-
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},`;
154-
fstr += '}'
155-
}
156-
return compiler.wrapCode(`
157-
const flags = ${fstr}
158-
let val = value._value ${big ? '|| 0n' : ''}
159-
for (const key in flags) {
160-
if (value[key]) val |= flags[key]
161-
}
162-
return (ctx.${type})(val, buffer, offset)
163-
`.trim())
164-
}]
165-
166-
SizeOf.bitflags = ['parametrizable', (compiler, { type, flags, shift, big }) => {
167-
let fstr = JSON.stringify(flags)
168-
if (Array.isArray(flags)) {
169-
fstr = '{'
170-
flags.map((v, k) => fstr += `"${v}": ${big ? 1n << BigInt(k) : 1 << k}` + (big ? 'n,' : ','))
171-
fstr += '}'
172-
} else if (shift) {
173-
fstr = '{'
174-
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},`;
175-
fstr += '}'
176-
}
177-
return compiler.wrapCode(`
178-
const flags = ${fstr}
179-
let val = value._value ${big ? '|| 0n' : ''}
180-
for (const key in flags) {
181-
if (value[key]) val |= flags[key]
182-
}
183-
return (ctx.${type})(val)
184-
`.trim())
185-
}]
186-
187119
/**
188120
* Command Packet
189121
* - used for determining the size of the following enum

src/datatypes/minecraft.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
/* eslint-disable */
21
const nbt = require('prismarine-nbt')
32
const UUID = require('uuid-1345')
43

54
const protoLE = nbt.protos.little
65
const protoLEV = nbt.protos.littleVarint
7-
// TODO: deal with this:
8-
const zigzag = require('prismarine-nbt/zigzag')
96

107
function readUUID (buffer, offset) {
11-
if (offset + 16 > buffer.length) { throw new PartialReadError() }
8+
if (offset + 16 > buffer.length) { throw new Error('Reached end of buffer') }
129
return {
1310
value: UUID.stringify(buffer.slice(offset, 16 + offset)),
1411
size: 16
@@ -65,7 +62,7 @@ function readEntityMetadata (buffer, offset, _ref) {
6562
const metadata = []
6663
let item
6764
while (true) {
68-
if (offset + 1 > buffer.length) throw new PartialReadError()
65+
if (offset + 1 > buffer.length) throw new Error('Reached end of buffer')
6966
item = buffer.readUInt8(cursor)
7067
if (item === endVal) {
7168
return {
@@ -159,7 +156,5 @@ module.exports = {
159156
lnbt: [readNbtLE, writeNbtLE, sizeOfNbtLE],
160157
entityMetadataLoop: [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata],
161158
ipAddress: [readIpAddress, writeIpAddress, 4],
162-
endOfArray: [readEndOfArray, writeEndOfArray, sizeOfEndOfArray],
163-
zigzag32: zigzag.interpret.zigzag32,
164-
zigzag64: zigzag.interpret.zigzag64
159+
endOfArray: [readEndOfArray, writeEndOfArray, sizeOfEndOfArray]
165160
}

src/datatypes/varlong.js

-63
This file was deleted.

0 commit comments

Comments
 (0)