superjoe30/node-minecraft-protocol — pull request #74 by roblabla (2014-01-12 21:15:06+00:00)
Title: [WIP] Array and Container type, general protocol.js cleanup

WIP, still have to fix the test cases, and I don't like how some things currently are.

### The Issue:

We have a plethora of array types (byteArray16, byteArray8, slotArray) and container types (intVector, byteVector, mapChunkBulk), with only more getting added after each update, that make the protocol.js harder to read, understand and maintain.

### Justification for this PR:

This creates three simple, convenient types (array, buffer, container) that replaces the current array and container types thanks to a simple, extensible system.

### PR Breakdown

* Array : arrays have a "count" field, a string that points to another field in the packet. This field represents the array's length. They also have a "arrayType" field, which tells us what type the array's contents are. arrayType must be a valid type from the "types" object. Example :

```javascript
"toClient/0x30": [
{ name: "windowId", type: "ubyte" },
{ name: "count", type: "short" },
{ name: "items", type: "array", arrayType: "slot", count: "count" }
]
```

* Buffer : buffers acts exactly like array, except they don't have an "arrayType". They read/write nodejs buffers. Example :

```javascript
"serverBound/0x01": [
{ name: "countSharedSecret", type: "short" },
{ name: "sharedSecret", type: "buffer", count: "countSharedSecret" },
{ name: "countVerifyToken", type: "short" },
{ name: "verifyToken", type: "buffer", count: "countVerifyToken" }
]
```

* Container : Container have a "contents" field, representing the contents of the container in the same format as a packet.

```javascript
0x20: [
{ name: "entityId", type: "int" },
{ name: "count", type: "int" },
{ name: "properties", type: "array", arrayType: "container", count: "count", contents: [
{ name: "key", type: "string" },
{ name: "value", type: "double" },
{ name: "listLength", type: "short" },
{ name: "modifiers", type: "array", arrayType: "container", count: "listLength", contents: [
{ name: "uuid", type: "UUID" },
{ name: "amount", type: "double" },
{ name: "operation", type: "byte" },
]}
]}
],
```

### Caveats:
Right now, count field has to be a variable within the same "container" as the array it represents.

### Notes :
Having a nodejs script that'd generate a documentation of the packets out of the protocol.js would be cool. Right now I think the biggest caveat with node-minecraft-protocol is having to check the protocol.js to find out the fields name for the packet. Having a single html page, following more-or-less the same "layout" as http://wiki.vg/Protocol , but without own field names, would speed up looking up those fields.