andrewrk/node-minecraft-protocol — pull request #79 by roblabla (2014-04-04 10:01:33+00:00)
Title: Container and array data types

PR Breakdown
============

Issue
-------
There are currently is 14 different "array" data types in the types version. Every time a minecraft updates adds a new "type" of/ array, we are forced to create a three new functions, one new type, etc...
This has led to the packet definition being unclear (What is a mapChunkBulk ? What is a statistic array ?) and the source of protocol.js to be ridiculously big.

Proposed Fix
------------------
We should replace the different data types with a simple and flexible system.

Every types can have access to "typeArgs", which can define some options that are only given for that data type.

The following four data types :
- container, pretty much defines a javascript object. Takes a "fields" array in it's typeArgs.
- count, a hack that uses an array/buffer as its value instead of the given one. Takes a "type" and a "countFor" string in its typeArgs
- array, represents a length-prefixed array. Takes a "type" and a "count" string in its typeArgs.
- buffer, a specialized array for "bytes" that return a nodejs Buffer, instead of a js array. Takes a "count" string in its typeArgs

All of those can be nested, which allows for nearly every complex data types to be broken down into simpler ones.

Examples :

```javascript
map_chunk_bulk: {id: 0x26, fields: [
{ name: "chunkColumnCount", type: "count", typeArgs: { type: "short", countFor: "meta" } },
{ name: "dataLength", type: "count", typeArgs: { type: "int", countFor: "compressedChunkData" } },
{ name: "skyLightSent", type: "bool" },
{ name: "compressedChunkData", type: "buffer", typeArgs: { count: "dataLength" } },
{ name: "meta", type: "array", typeArgs: { count: "chunkColumnCount",
type: "container", typeArgs: { fields: [
{ name: "x", type: "int" },
{ name: "z", type: "int" },
{ name: "bitMap", type: "ushort" },
{ name: "addBitMap", type: "ushort" }
] } } }
]},
```