/**
  * Serialize an object into a given byte buffer.
  *
  * @param o The object to serialize.
  * @param b The bytebuf to serialize it into.
  */
 @Override
 public void serialize(Object o, ByteBuf b) {
   String className = o == null ? "null" : o.getClass().getName();
   if (className.contains("$ByteBuddy$")) {
     String SMRClass = className.split("\\$")[0];
     className = "CorfuObject";
     byte[] classNameBytes = className.getBytes();
     b.writeShort(classNameBytes.length);
     b.writeBytes(classNameBytes);
     byte[] SMRClassNameBytes = SMRClass.getBytes();
     b.writeShort(SMRClassNameBytes.length);
     b.writeBytes(SMRClassNameBytes);
     UUID id = ((ICorfuObject) o).getStreamID();
     log.trace("Serializing a CorfuObject of type {} as a stream pointer to {}", SMRClass, id);
     b.writeLong(id.getMostSignificantBits());
     b.writeLong(id.getLeastSignificantBits());
   } else {
     byte[] classNameBytes = className.getBytes();
     b.writeShort(classNameBytes.length);
     b.writeBytes(classNameBytes);
     if (o == null) {
       return;
     }
     try (ByteBufOutputStream bbos = new ByteBufOutputStream(b)) {
       try (OutputStreamWriter osw = new OutputStreamWriter(bbos)) {
         gson.toJson(o, o.getClass(), osw);
       }
     } catch (IOException ie) {
       log.error("Exception during serialization!", ie);
     }
   }
 }
    @Override
    public void write(ByteBuf bb, OFFlowStatsEntryVer10 message) {
      int startIndex = bb.writerIndex();
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      message.tableId.writeByte(bb);
      // pad: 1 bytes
      bb.writeZero(1);
      message.match.writeTo(bb);
      bb.writeInt(U32.t(message.durationSec));
      bb.writeInt(U32.t(message.durationNsec));
      bb.writeShort(U16.t(message.priority));
      bb.writeShort(U16.t(message.idleTimeout));
      bb.writeShort(U16.t(message.hardTimeout));
      // pad: 6 bytes
      bb.writeZero(6);
      bb.writeLong(message.cookie.getValue());
      bb.writeLong(message.packetCount.getValue());
      bb.writeLong(message.byteCount.getValue());
      ChannelUtils.writeList(bb, message.actions);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
    public void write(ByteBuf buf) {
      buf.writeLong(this.id.getMostSignificantBits());
      buf.writeLong(this.id.getLeastSignificantBits());

      // rip in organize
      for (Object o : this.values) {
        switch (o.getClass().getSimpleName()) {
          case "String":
            Codec.writeString(buf, (String) o);
            break;

          case "Integer":
            Codec.writeVarInt32(buf, (Integer) o);
            break;

          case "Boolean":
            buf.writeBoolean((Boolean) o);
            break;

          default:
            // ignore bad developers
            break;
        }
      }
    }
 @Override
 public void encodeInto(ByteBuf buffer) {
   buffer.writeLong(this.playerUUID.getMostSignificantBits());
   buffer.writeLong(this.playerUUID.getLeastSignificantBits());
   buffer.writeInt(this.dim);
   ByteBufUtils.writeTag(buffer, this.tag);
 }
  @Override
  public void writeSpawnData(ByteBuf buffer) {
    buffer.writeInt(spiderType.getId());

    if (owner != null) {
      buffer.writeLong(owner.getMostSignificantBits());
      buffer.writeLong(owner.getLeastSignificantBits());
    }
  }
  @Override
  public void toBytes(ByteBuf buf) {
    buf.writeInt(posX);
    buf.writeInt(posY);
    buf.writeInt(posZ);
    buf.writeInt(data.size());

    for (int i = 0; i < data.size(); i++) {
      Object obj = data.get(i);
      if (obj instanceof Character) {
        buf.writeByte(0x00);
        buf.writeChar((Character) obj);
      } else if (obj instanceof String) {
        buf.writeByte(0x01);
        writeString(buf, (String) obj);
      } else if (obj instanceof Float) {
        buf.writeByte(0x02);
        buf.writeFloat((Float) obj);
      } else if (obj instanceof Double) {
        buf.writeByte(0x03);
        buf.writeDouble((Double) obj);
      } else if (obj instanceof Byte) {
        buf.writeByte(0x04);
        buf.writeByte((Byte) obj);
      } else if (obj instanceof Long) {
        buf.writeByte(0x05);
        buf.writeLong((Long) obj);
      } else {
        buf.writeByte(0x0F);
        buf.writeInt((Integer) obj);
      }
    }
  }
Beispiel #7
0
  public ByteBuf encode(NettyMessage msg) throws Exception {
    ByteBuf sendBuf = Unpooled.buffer();
    sendBuf.writeInt((msg.getHeader().getCrcCode()));
    sendBuf.writeInt((msg.getHeader().getLength()));
    sendBuf.writeLong((msg.getHeader().getSessionID()));
    sendBuf.writeByte((msg.getHeader().getType()));
    sendBuf.writeByte((msg.getHeader().getPriority()));
    sendBuf.writeInt((msg.getHeader().getAttachment().size()));
    String key = null;
    byte[] keyArray = null;
    Object value = null;

    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
      key = param.getKey();
      keyArray = key.getBytes("UTF-8");
      sendBuf.writeInt(keyArray.length);
      sendBuf.writeBytes(keyArray);
      value = param.getValue();
      marshallingEncoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    if (msg.getBody() != null) {
      marshallingEncoder.encode(msg.getBody(), sendBuf);
    } else sendBuf.writeInt(0);
    sendBuf.setInt(4, sendBuf.readableBytes());
    return sendBuf;
  }
  @Override
  protected void encode(ChannelHandlerContext ctx, TransportFrame frame, ByteBuf out)
      throws Exception {
    out.writeByte('E');
    out.writeByte('Q');
    out.writeInt(frame.version().id);
    out.writeLong(frame.request());

    if (frame instanceof StreamableTransportFrame) {
      // message request
      // skip size header
      int sizePos = out.writerIndex();
      out.writerIndex(out.writerIndex() + 4);
      try (StreamOutput output = streamService.output(out)) {
        Streamable message = ((StreamableTransportFrame) frame).message();
        output.writeClass(message.getClass());
        output.writeStreamable(message);
      }
      int size = out.writerIndex() - sizePos - 4;
      out.setInt(sizePos, size);
    } else {
      // ping request
      out.writeInt(0);
    }
  }
 /**
  * Writes 64-bit long <code>value</code> if not null, otherwise writes zeros to the <code>output
  * </code> ByteBuf. ByteBuf's writerIndex is increased by 8.
  *
  * @param value Long value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeLong(final Long value, final ByteBuf output) {
   if (value != null) {
     output.writeLong(value);
   } else {
     output.writeZero(LONG_BYTES_LENGTH);
   }
 }
 /**
  * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise writes zeros to the
  * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 8.
  *
  * @param value BigInteger value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) {
   if (value != null) {
     output.writeLong(value.longValue());
   } else {
     output.writeZero(LONG_BYTES_LENGTH);
   }
 }
 @Test
 public void testDecode() {
   ByteBuf buffer = Unpooled.buffer();
   // header
   buffer.writeByte(0);
   buffer.writeShort(1);
   buffer.writeByte(Integer.valueOf(240).byteValue());
   buffer.writeInt(44);
   buffer.writeLong(1);
   buffer.writeLong(2);
   // attributes
   buffer.writeShort(4);
   buffer.writeInt(4);
   buffer.writeBytes("luo!".getBytes());
   buffer.writeShort(5);
   buffer.writeInt(4);
   buffer.writeBytes("luo!".getBytes());
   MockRelayMessage message =
       (MockRelayMessage) MessageFactory.getInstance().createMessage(buffer);
   Assert.assertEquals(message.version(), GenericMessage.VERSION);
   Assert.assertEquals(message.length(), Unsigned32.get(44L));
   Assert.assertEquals(message.flag().get().isGroup(), true);
   Assert.assertEquals(message.flag().get().isRequest(), true);
   Assert.assertEquals(message.flag().get().isProxiable(), true);
   Assert.assertEquals(message.flag().get().isError(), true);
   assertEquals(message.code(), Unsigned16.get(1));
   assertEquals(message.hopByHop(), Integer64.get(1L));
   assertEquals(message.endToEnd(), Integer64.get(2L));
   Assert.assertEquals(message.attribute(Unsigned16.get(4)).length(), Unsigned32.get(4L));
   assertEquals(message.attribute(Unsigned16.get(4)).data().get(), "luo!");
   Assert.assertEquals(message.attribute(Unsigned16.get(5)).length(), Unsigned32.get(4L));
   assertEquals(message.attribute(Unsigned16.get(5)).data().get(), "luo!");
 }
 @Override
 public void eval() {
   buffer.clear();
   buffer.writeLong(in.value);
   out.buffer = buffer;
   out.start = 0;
   out.end = 8;
 }
 @Override
 public void write(ByteBuf bb, OFBsnTlvMissPacketsVer13 message) {
   // fixed value property type = 0xd
   bb.writeShort((short) 0xd);
   // fixed value property length = 12
   bb.writeShort((short) 0xc);
   bb.writeLong(message.value.getValue());
 }
 @Override
 public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
   writeString(cursor, buf);
   if (protocolVersion >= ProtocolConstants.MINECRAFT_1_8) {
     buf.writeBoolean(hasPositon);
     if (hasPositon) {
       buf.writeLong(position);
     }
   }
 }
 @Override
 public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) {
   ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
   outBuffer.writeLong(message.getCookie().longValue());
   outBuffer.writeShort(message.getPriority());
   outBuffer.writeByte(message.getReason().getIntValue());
   outBuffer.writeByte(message.getTableId().getValue().byteValue());
   outBuffer.writeInt(message.getDurationSec().intValue());
   outBuffer.writeInt(message.getDurationNsec().intValue());
   outBuffer.writeShort(message.getIdleTimeout());
   outBuffer.writeShort(message.getHardTimeout());
   outBuffer.writeLong(message.getPacketCount().longValue());
   outBuffer.writeLong(message.getByteCount().longValue());
   OFSerializer<Match> matchSerializer =
       registry.<Match, OFSerializer<Match>>getSerializer(
           new MessageTypeKey<>(message.getVersion(), Match.class));
   matchSerializer.serialize(message.getMatch(), outBuffer);
   ByteBufUtils.updateOFHeaderLength(outBuffer);
 }
 /** encode Message to byte & write to network framework */
 public void encode(ResponseSocketBlock resMsg, ByteBuf buf) throws IOException {
   //
   // * --------------------------------------------------------bytes =13
   // * byte[1]  version                              RSF版本(0x81)
   buf.writeByte(resMsg.getVersion());
   // * byte[8]  requestID                            请求ID
   buf.writeLong(resMsg.getRequestID());
   // * byte[1]  keepData                             保留区
   buf.writeByte(0);
   // * byte[3]  contentLength                        内容大小(max = 16MB)
   ByteBuf responseBody = this.encodeResponse(resMsg);
   int bodyLength = responseBody.readableBytes();
   bodyLength = (bodyLength << 8) >>> 8; // 左移8未,在无符号右移8位。形成最大16777215字节的限制。
   buf.writeMedium(bodyLength);
   //
   buf.writeBytes(responseBody);
   //
 }
 @Override
 public void write(ByteBuf bb, OFBsnSetPktinSuppressionRequestVer12 message) {
   // fixed value property version = 3
   bb.writeByte((byte) 0x3);
   // fixed value property type = 4
   bb.writeByte((byte) 0x4);
   // fixed value property length = 32
   bb.writeShort((short) 0x20);
   bb.writeInt(U32.t(message.xid));
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0xbL
   bb.writeInt(0xb);
   bb.writeByte(message.enabled ? 1 : 0);
   // pad: 1 bytes
   bb.writeZero(1);
   bb.writeShort(U16.t(message.idleTimeout));
   bb.writeShort(U16.t(message.hardTimeout));
   bb.writeShort(U16.t(message.priority));
   bb.writeLong(message.cookie.getValue());
 }
  @Override
  protected void encode(ChannelHandlerContext ctx, RPCMessage in, List<Object> out)
      throws Exception {
    RPCRequest.Type type = in.getType();

    long bodyBytes = 0;
    DataBuffer payload = null;

    if (in.hasPayload()) {
      payload = in.getPayloadDataBuffer();
      bodyBytes = payload.getLength();
    }

    int lengthBytes = Longs.BYTES;
    int typeBytes = type.getEncodedLength();
    int messageBytes = in.getEncodedLength();

    int headerBytes = lengthBytes + typeBytes + messageBytes;
    long frameBytes = headerBytes + bodyBytes;

    // Write the header info into a buffer.
    // The format is: [frame length][message type][message][(optional) data]
    ByteBuf buffer = ctx.alloc().buffer();
    buffer.writeLong(frameBytes);
    type.encode(buffer);
    in.encode(buffer);

    // Output the header buffer.
    out.add(buffer);

    if (payload != null && bodyBytes > 0) {
      Object output = payload.getNettyOutput();
      Preconditions.checkArgument(
          output instanceof ByteBuf || output instanceof FileRegion,
          "The payload must be a ByteBuf or a FileRegion.");
      out.add(output);
    }
  }
 @Override
 public void write(ByteBuf buf) throws Exception {
   buf.writeByte(actionId);
   buf.writeLong(targetEntityId);
 }
 @Override
 public void encode(ByteBuf out) {
   out.writeLong(mTempUfsFileId);
   out.writeLong(mOffset);
   out.writeLong(mLength);
 }
Beispiel #21
0
 private void init() {
   ByteBuf buf = channel.alloc().buffer(8);
   buf.writeLong(serverSessionKey);
   channel.write(new LoginResponse(LoginResponse.STATUS_EXCHANGE_KEYS, buf));
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeLong(pos.toLong());
 }
Beispiel #23
0
  public void toBytes(ByteBuf buf) {
    NetworkTools.writeEnum(buf, terrainType, TerrainType.TERRAIN_VOID);
    NetworkTools.writeEnumCollection(buf, featureTypes);
    NetworkTools.writeEnumCollection(buf, structureTypes);
    NetworkTools.writeEnumCollection(buf, effectTypes);

    buf.writeInt(biomes.size());
    for (BiomeGenBase entry : biomes) {
      if (entry != null) {
        buf.writeInt(entry.biomeID);
      } else {
        buf.writeInt(BiomeGenBase.plains.biomeID);
      }
    }
    NetworkTools.writeEnum(buf, controllerType, ControllerType.CONTROLLER_DEFAULT);

    NetworkTools.writeString(buf, digitString);
    buf.writeLong(forcedDimensionSeed);
    buf.writeLong(baseSeed);
    buf.writeInt(worldVersion);

    buf.writeInt(Block.blockRegistry.getIDForObject(baseBlockForTerrain.getBlock()));
    buf.writeInt(baseBlockForTerrain.getMeta());
    buf.writeInt(Block.blockRegistry.getIDForObject(tendrilBlock.getBlock()));
    buf.writeInt(tendrilBlock.getMeta());

    writeBlockArrayToBuf(buf, pyramidBlocks);
    writeBlockArrayToBuf(buf, sphereBlocks);
    writeBlockArrayToBuf(buf, hugeSphereBlocks);
    writeBlockArrayToBuf(buf, liquidSphereBlocks);
    writeFluidArrayToBuf(buf, liquidSphereFluids);
    writeBlockArrayToBuf(buf, hugeLiquidSphereBlocks);
    writeFluidArrayToBuf(buf, hugeLiquidSphereFluids);

    buf.writeInt(Block.blockRegistry.getIDForObject(canyonBlock.getBlock()));
    buf.writeInt(canyonBlock.getMeta());
    buf.writeInt(Block.blockRegistry.getIDForObject(fluidForTerrain));

    writeBlockArrayToBuf(buf, extraOregen);

    writeFluidArrayToBuf(buf, fluidsForLakes);

    buf.writeBoolean(peaceful);
    buf.writeBoolean(noanimals);
    buf.writeBoolean(shelter);
    buf.writeBoolean(respawnHere);
    NetworkTools.writeFloat(buf, celestialAngle);
    NetworkTools.writeFloat(buf, timeSpeed);

    buf.writeInt(probeCounter);
    buf.writeInt(actualRfCost);

    skyDescriptor.toBytes(buf);
    weatherDescriptor.toBytes(buf);

    buf.writeLong(patreon1);

    buf.writeInt(extraMobs.size());
    for (MobDescriptor mob : extraMobs) {
      if (mob != null) {
        if (mob.getEntityClass() != null) {
          NetworkTools.writeString(buf, mob.getEntityClass().getName());
          buf.writeInt(mob.getSpawnChance());
          buf.writeInt(mob.getMinGroup());
          buf.writeInt(mob.getMaxGroup());
          buf.writeInt(mob.getMaxLoaded());
        }
      }
    }

    buf.writeInt(dimensionTypes.length);
    for (String type : dimensionTypes) {
      NetworkTools.writeString(buf, type);
    }
  }
Beispiel #24
0
 public static void writeUUID(UUID value, ByteBuf output) {
   output.writeLong(value.getMostSignificantBits());
   output.writeLong(value.getLeastSignificantBits());
 }
Beispiel #25
0
  @Override
  public void encode(ByteBuf buf) {
    // For testing purposes using default dummy entity :)
    /*boolean dummy = false;
    if (name.contains("dummy")) dummy = true;*/

    buf.writeLong(id); // Ulong but whatever
    buf.writeBytes(bitSet.toByteArray());
    buf.writeBytes(
        new byte
            [8 - bitSet.toByteArray().length]); // BitSet/BitArray are the stupidest classes ever :(
    if (bitSet.get(0)) {
      writeLongVector3(buf, position);
    }
    if (bitSet.get(1)) {
      writeOrientation(buf, orientation);
    }
    if (bitSet.get(2)) {
      writeFloatVector3(buf, velocity);
    }
    if (bitSet.get(3)) {
      writeFloatVector3(buf, accel);
    }
    if (bitSet.get(4)) {
      writeFloatVector3(buf, extraVel);
    }
    if (bitSet.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitSet.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitSet.get(7)) {
      buf.writeByte(hostileType);
    }
    if (bitSet.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitSet.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitSet.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitSet.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitSet.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitSet.get(13)) {
      app.encode(buf);
    }
    if (bitSet.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitSet.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitSet.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitSet.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitSet.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitSet.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitSet.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitSet.get(21)) {
      buf.writeByte(classType);
    }
    if (bitSet.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitSet.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitSet.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitSet.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitSet.get(26)) {
      writeFloatVector3(buf, rayHit);
    }
    if (bitSet.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitSet.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitSet.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitSet.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitSet.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitSet.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitSet.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitSet.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitSet.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitSet.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitSet.get(37)) {
      buf.writeByte(na3);
    }
    if (bitSet.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitSet.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitSet.get(40)) {
      writeLongVector3(buf, spawnPosition);
    }
    if (bitSet.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitSet.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitSet.get(43)) {
      itemData.encode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitSet.get(45)) {
      byte[] ascii = name.getBytes(Charsets.US_ASCII);
      buf.writeBytes(ascii);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitSet.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      Glydar.getServer().getLogger().warning("Data read during encode.");
    }
  }
Beispiel #26
0
 @Override
 public void toBytes(ByteBuf buffer) {
   buffer.writeInt(islandX);
   buffer.writeInt(islandZ);
   buffer.writeLong(seed);
 }
 @Override
 public MessageBuffer<ByteBuf> writeLong(long value) {
   buffer.writeLong(value);
   return this;
 }
 @Override
 public ByteBuf writeLong(long value) {
   return buf.writeLong(value);
 }
Beispiel #29
0
 /**
  * Appends the specified {@code long} to the end of the Buffer. The buffer will expand as
  * necessary to accommodate any bytes written.
  *
  * <p>Returns a reference to {@code this} so multiple operations can be appended together.
  */
 public Buffer appendLong(long l) {
   buffer.writeLong(l);
   return this;
 }
Beispiel #30
0
  @SuppressWarnings("restriction")
  @Override
  public void encode(ByteBuf buf) {
    buf.writeLong(id); // Ulong but whatever
    // TODO: Not sure exactly how to approach writing unsigned ints!
    BitArray bitArray = new BitArray(8 * bitmask.length, bitmask); // Size in bits, byte[]
    buf.writeBytes(bitmask);

    if (bitArray.get(0)) {
      buf.writeLong(posX);
      buf.writeLong(posY);
      buf.writeLong(posZ);
    }
    if (bitArray.get(1)) {
      buf.writeFloat(pitch);
      buf.writeFloat(roll);
      buf.writeFloat(yaw);
    }
    if (bitArray.get(2)) {
      velocity.encode(buf);
    }
    if (bitArray.get(3)) {
      accel.encode(buf);
    }
    if (bitArray.get(4)) {
      extraVel.encode(buf);
    }
    if (bitArray.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitArray.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitArray.get(7)) {
      buf.writeByte(speedFlags);
    }
    if (bitArray.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitArray.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitArray.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitArray.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitArray.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitArray.get(13)) {
      app.encode(buf);
    }
    if (bitArray.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitArray.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitArray.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitArray.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitArray.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitArray.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitArray.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitArray.get(21)) {
      buf.writeByte(classType);
    }
    if (bitArray.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitArray.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitArray.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitArray.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitArray.get(26)) {
      rayHit.encode(buf);
    }
    if (bitArray.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitArray.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitArray.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitArray.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitArray.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitArray.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitArray.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitArray.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitArray.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitArray.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitArray.get(37)) {
      buf.writeByte(na3);
    }
    if (bitArray.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitArray.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitArray.get(40)) {
      buf.writeInt((int) nu13);
      buf.writeInt((int) nu14);
      buf.writeInt((int) nu15);
      buf.writeInt((int) nu16);
      buf.writeInt((int) nu17);
      buf.writeInt((int) nu18);
    }
    if (bitArray.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitArray.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitArray.get(43)) {
      itemData.encode(buf);
    }
    if (bitArray.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitArray.get(45)) {
      byte[] utf8 = name.getBytes(Charsets.UTF_8);
      buf.writeBytes(new byte[4]); // TODO But why?
      buf.writeBytes(utf8);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitArray.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitArray.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      System.out.println("I read something during an encode?!");
    }
  }