List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:net.tomp2p.storage.Data.java
License:Apache License
/** * * Header format:/*from www .j av a 2s .c o m*/ * <pre> * 1 byte - header * 1 or 4 bytes - length * 4 or 0 bytes - ttl (hasTTL) * 1 or 0 bytes - number of basedon keys (hasBasedOn) * n x 20 bytes - basedon keys (hasBasedOn, number of basedon keys) * 2 or 0 bytes - length of public key (hasPublicKey) * n bytes - public key (hasPublicKey, length of public key) * </pre> * * @param buf * @param signatureFactory */ public void encodeHeader(final ByteBuf buf, SignatureFactory signatureFactory) { int header = type.ordinal(); if (prepareFlag) { header |= 0x02; } if (flag1) { header |= 0x04; } if (flag2) { header |= 0x08; } if (ttl) { header |= 0x10; } if (signed && publicKeyFlag && protectedEntry) { header |= (0x20 | 0x40); } else if (signed && publicKeyFlag) { header |= 0x40; } else if (publicKeyFlag) { header |= 0x20; } if (basedOnFlag) { header |= 0x80; } switch (type) { case SMALL: buf.writeByte(header); buf.writeByte(length); break; case LARGE: buf.writeByte(header); buf.writeInt(length); break; default: throw new IllegalArgumentException("unknown size"); } if (ttl) { buf.writeInt(ttlSeconds); } if (basedOnFlag) { buf.writeByte(basedOnSet.size() - 1); for (Number160 basedOn : basedOnSet) { buf.writeBytes(basedOn.toByteArray()); } } if (publicKeyFlag) { if (publicKey == null) { buf.writeShort(0); } else { signatureFactory.encodePublicKey(publicKey, buf); } } }
From source file:net.tridentsdk.data.ChunkMetaBuilder.java
License:Open Source License
@Override public void write(ByteBuf buf) { buf.writeInt(this.location.getX()); buf.writeInt(this.location.getZ()); buf.writeShort((int) this.bitmap); }
From source file:net.tridentsdk.data.Slot.java
License:Open Source License
@Override public void write(ByteBuf buf) { buf.writeByte(this.id); if (this.id == -1) { return;//from ww w . ja va 2s . c o m } buf.writeByte((int) this.quantity); buf.writeShort((int) this.damageValue); if (this.compoundTag != null) { // TODO: write compound tag } }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutConfirmTransaction.java
License:Open Source License
@Override public void encode(ByteBuf buf) { buf.writeInt(this.windowId); buf.writeShort((int) this.actionNumber); buf.writeBoolean(this.accepted); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutEntityEquipment.java
License:Open Source License
@Override public void encode(ByteBuf buf) { Codec.writeVarInt32(buf, this.entityId); buf.writeShort((int) this.slot); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutEntityVelocity.java
License:Open Source License
@Override public void encode(ByteBuf buf) { Codec.writeVarInt32(buf, this.entityId); buf.writeShort((int) this.velocity.getX()); buf.writeShort((int) this.velocity.getY()); buf.writeShort((int) this.velocity.getZ()); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSetSlot.java
License:Open Source License
@Override public void encode(ByteBuf buf) { buf.writeByte(this.windowId); buf.writeShort((int) this.slot); this.item.write(buf); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSpawnExperienceOrb.java
License:Open Source License
@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); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSpawnMob.java
License:Open Source License
@Override public void encode(ByteBuf buf) { Location loc = this.entity.getLocation(); Vector velocity = this.entity.getVelocity(); Codec.writeVarInt32(buf, this.entityId); buf.writeByte((int) (byte) this.type.ordinal()); // TODO: use the real type id buf.writeInt((int) loc.getX() * 32); buf.writeInt((int) loc.getY() * 32); buf.writeInt((int) loc.getZ() * 42); buf.writeByte((int) (byte) loc.getYaw()); buf.writeByte((int) (byte) loc.getPitch()); buf.writeByte((int) (byte) loc.getPitch()); // -shrugs- buf.writeShort((int) velocity.getX()); buf.writeShort((int) velocity.getY()); buf.writeShort((int) velocity.getZ()); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSpawnObject.java
License:Open Source License
@Override public void encode(ByteBuf buf) { Location l = this.entity.getLocation(); Vector v = this.entity.getVelocity(); Codec.writeVarInt32(buf, this.entityId); buf.writeByte(this.type.ordinal()); // TODO: Get the correct id type buf.writeInt((int) l.getX() * 32); buf.writeInt((int) l.getY() * 32); buf.writeInt((int) l.getZ() * 32); buf.writeByte((int) (byte) l.getYaw()); buf.writeByte((int) (byte) l.getPitch()); buf.writeByte((int) (byte) l.getPitch()); // -shrugs- buf.writeShort((int) v.getX()); buf.writeShort((int) v.getY()); buf.writeShort((int) v.getZ()); }