* @param buf The buffer.
* @param entries The metadata.
*/
public static void writeMetadata(ByteBuf buf, List<MetadataMap.Entry> entries) throws IOException {
for (MetadataMap.Entry entry : entries) {
MetadataIndex index = entry.index;
Object value = entry.value;
if (value == null) continue;
int type = index.getType().getId();
int id = index.getIndex();
buf.writeByte((type << 5) | id);
switch (index.getType()) {
case BYTE:
buf.writeByte((Byte) value);
break;
case SHORT:
buf.writeShort((Short) value);