Ejemplo n.º 1
0
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(xCoord);
   buf.writeInt(yCoord);
   buf.writeInt(zCoord);
   ByteBufUtils.writeTag(buf, tag);
 }
 @Override
 public void toBytes(ByteBuf buffer) {
   buffer.writeInt(this.owner.length());
   buffer.writeBytes(this.owner.getBytes());
   buffer.writeInt(this.notifier.length());
   buffer.writeBytes(this.notifier.getBytes());
 }
Ejemplo n.º 3
0
  @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);
    }
  }
Ejemplo n.º 4
0
 /*
  * ID 0: client changed xcoord in interface
  * ID 1: client changed ycoord in interface
  * ID 2: sync whether the machine is running
  * ID 3: sync Mode
  * ID 4: jam reset
  */
 @Override
 public void writeDataToNetwork(ByteBuf out, byte id) {
   if (id == 0) out.writeInt(this.laserX);
   else if (id == 1) out.writeInt(this.laserZ);
   else if (id == 2) out.writeBoolean(isRunning);
   else if (id == 3) out.writeInt(mode.ordinal());
 }
Ejemplo n.º 5
0
 private static void writeBlockArrayToBuf(ByteBuf buf, BlockMeta[] array) {
   buf.writeInt(array.length);
   for (BlockMeta block : array) {
     buf.writeInt(Block.blockRegistry.getIDForObject(block.getBlock()));
     buf.writeInt(block.getMeta());
   }
 }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
 public static void serialiseView(View view, ByteBuf buf) {
   buf.writeInt(view.id);
   buf.writeInt(view.members.size());
   for (Address addr : view.members) {
     AddressSerializer.INSTANCE.toBinary(addr, buf);
   }
 }
 @Override
 public void writeBytes(ChannelHandlerContext ctx, ByteBuf bytes) {
   bytes.writeInt(ropeEntID);
   bytes.writeInt(x);
   bytes.writeInt(y);
   bytes.writeInt(z);
 }
    @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);
    }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(x);
   buf.writeInt(y);
   buf.writeInt(z);
   buf.writeInt(data);
 }
Ejemplo n.º 11
0
 @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!");
 }
Ejemplo n.º 12
0
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(x);
   buf.writeInt(y);
   buf.writeInt(z);
   buf.writeFloat(storedEnergy);
 }
 @Override
 public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) throws IOException {
   buffer.writeInt(data.length);
   buffer.writeInt(signature.length);
   buffer.writeBytes(data);
   buffer.writeBytes(signature);
 }
Ejemplo n.º 14
0
  @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);
      }
    }
  }
Ejemplo n.º 15
0
 private ByteBuf encodeResponse(ResponseSocketBlock resMsg) {
   ByteBuf bodyBuf = ByteBufAllocator.DEFAULT.heapBuffer();
   //
   // * --------------------------------------------------------bytes =8
   // * byte[2]  status                               响应状态
   bodyBuf.writeShort(resMsg.getStatus());
   // * byte[2]  serializeType-(attr-index)           序列化策略
   bodyBuf.writeShort(resMsg.getSerializeType());
   // * byte[2]  returnType-(attr-index)              返回类型
   bodyBuf.writeShort(resMsg.getReturnType());
   // * byte[2]  returnData-(attr-index)              返回数据
   bodyBuf.writeShort(resMsg.getReturnData());
   // * --------------------------------------------------------bytes =1 ~ 1021
   // * byte[1]  optionCount                          选项参数总数
   int[] optionMapping = resMsg.getOptions();
   bodyBuf.writeByte(optionMapping.length);
   for (int i = 0; i < optionMapping.length; i++) {
     // * byte[4]  ptype-0-(attr-index,attr-index)  选项参数1
     // * byte[4]  ptype-1-(attr-index,attr-index)  选项参数2
     bodyBuf.writeInt(optionMapping[i]);
   }
   // * --------------------------------------------------------bytes =6 ~ 8192
   // * byte[2]  attrPool-size (Max = 2047)           池大小 0x07FF
   int[] poolData = resMsg.getPoolData();
   bodyBuf.writeShort(poolData.length);
   for (int i = 0; i < poolData.length; i++) {
     // * byte[4]  ptype-0-(attr-index,attr-index)  属性1大小
     // * byte[4]  ptype-1-(attr-index,attr-index)  属性2大小
     bodyBuf.writeInt(poolData[i]);
   }
   // * --------------------------------------------------------bytes =n
   // * dataBody                                      数据内容
   resMsg.fillTo(bodyBuf);
   return bodyBuf;
 }
Ejemplo n.º 16
0
 @Override
 public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
   buffer.writeInt(tile.xCoord);
   buffer.writeInt(tile.yCoord);
   buffer.writeInt(tile.zCoord);
   tile.packetGuiFill(buffer);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(elementName.length());
   buf.writeBytes(elementName.getBytes());
   buf.writeInt(elementText.length());
   buf.writeBytes(elementText.getBytes());
 }
 @Override
 public void write(ByteBuf bb) {
   writeString(bb, uuidString);
   bb.writeInt(time);
   bb.writeInt(action);
   writeString(bb, teleportString);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(pos.getX());
   buf.writeInt(pos.getY());
   buf.writeInt(pos.getZ());
   ByteBufUtils.writeItemStack(buf, activeItem);
   MagicAmounts.writeAmounts(buf, remaining);
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(entityID);
   buf.writeInt(componentID);
   buf.writeBoolean(ident != null);
   if (ident != null) ident.serializeBuf(buf);
   buf.writeFloat(progress);
 }
Ejemplo n.º 21
0
 @Override
 public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
   buffer.writeInt(playerNames.length);
   for (int i = 0; i < playerNames.length; i++) {
     ByteBufUtils.writeUTF8String(buffer, playerNames[i]);
     buffer.writeInt(races[i]);
   }
 }
  @Override
  public void toBytes(ByteBuf buf) {
    buf.writeInt(this.x);
    buf.writeInt(this.y);
    buf.writeInt(this.z);

    ByteBufUtils.writeUTF8String(buf, this.player);
  }
Ejemplo n.º 23
0
 @Override
 public void writeTo(ByteBuf buffer, Side side) {
   ByteBufUtils.writeUTF8String(buffer, host);
   buffer.writeInt(x);
   buffer.writeInt(y);
   buffer.writeInt(z);
   ByteBufUtils.writeUTF8String(buffer, ident);
 }
Ejemplo n.º 24
0
 public ByteBuf encode(ByteBuf buf, BlockChangeMessage message) throws IOException {
   buf.writeInt(message.getX());
   buf.writeByte(message.getY());
   buf.writeInt(message.getZ());
   ByteBufUtils.writeVarInt(buf, message.getType());
   buf.writeByte(message.getMetadata());
   return buf;
 }
 @Override
 public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
   buffer.writeInt(dim);
   buffer.writeInt(x);
   buffer.writeInt(y);
   buffer.writeInt(z);
   buffer.writeDouble(rotation);
   buffer.writeDouble(scale);
 }
  // api
  public PacketSwapSlots(int slotA, int slotB) {
    ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeInt(this.slotA = slotA);
    data.writeInt(this.slotB = slotB);

    this.configureWrite(data);
  }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(x);
   buf.writeInt(y);
   buf.writeInt(z);
   buf.writeInt(_freq);
   buf.writeBoolean(_isPublic);
   buf.writeByte(_state);
 }
Ejemplo n.º 28
0
    @Override
    public void toBytes(ByteBuf dataStream) {
      dataStream.writeInt(coord4D.xCoord);
      dataStream.writeInt(coord4D.yCoord);
      dataStream.writeInt(coord4D.zCoord);
      dataStream.writeInt(coord4D.dimensionId);

      dataStream.writeInt(mouseButton);
      dataStream.writeInt(tankId);
    }
Ejemplo n.º 29
0
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(color);
   for (int i = 0; i < 16; i++) {
     for (int i2 = 1; i2 < 5; i++) {
       int i2U = i2 == 0 ? 1 : i2 * 4;
       buf.writeInt(Integer.getInteger(this.screen[i].substring(i2U, i2U + 4)));
     }
   }
 }
  @Override
  public void encode(ByteBuf buf) {
    Codec.writeVarInt32(buf, this.entityId);

    buf.writeInt((int) this.location.getX() * 32);
    buf.writeInt((int) this.location.getY() * 32);
    buf.writeInt((int) this.location.getZ() * 32);

    buf.writeShort((int) this.count);
  }