Example usage for io.netty.buffer ByteBuf writeShort

List of usage examples for io.netty.buffer ByteBuf writeShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeShort.

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:net.killermapper.roadstuff.common.network.PacketSignType.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeShort(this.signType);
    buf.writeByte(this.signShape);
    buf.writeInt(this.tileX);
    buf.writeInt(this.tileY);
    buf.writeInt(this.tileZ);
}

From source file:net.mechanicalcat.pycode.net.InvokeWandMessage.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeDouble(this.traceResult.hitVec.xCoord);
    buf.writeDouble(this.traceResult.hitVec.yCoord);
    buf.writeDouble(this.traceResult.hitVec.zCoord);
    buf.writeShort(this.traceResult.typeOfHit.ordinal());
    switch (this.traceResult.typeOfHit) {
    case ENTITY://from w ww  .j  a  v a 2 s.c  om
        buf.writeInt(this.traceResult.entityHit.getEntityId());
        break;
    case BLOCK:
        BlockPos blockPos = this.traceResult.getBlockPos();
        buf.writeInt(blockPos.getX());
        buf.writeInt(blockPos.getY());
        buf.writeInt(blockPos.getZ());
        buf.writeShort(this.traceResult.sideHit.ordinal());
    }
}

From source file:net.packet.movement.AbsoluteLifeMovement.java

License:Open Source License

@Override
public void serialize(ByteBuf buf) {
    buf.writeByte(getType());/*www .  ja v a  2s  . com*/
    buf.writeShort(getPosition().x);
    buf.writeShort(getPosition().y);
    buf.writeShort(pixelsPerSecond.x);
    buf.writeShort(pixelsPerSecond.y);
    buf.writeShort(unk);
    buf.writeByte(getNewstate());
    buf.writeShort(getDuration());
}

From source file:net.packet.movement.ChairMovement.java

License:Open Source License

@Override
public void serialize(ByteBuf lew) {
    lew.writeByte(getType());//from  w  w  w  .  ja  v a  2s.c o m
    lew.writeShort(getPosition().x);
    lew.writeShort(getPosition().y);
    lew.writeShort(unk);
    lew.writeByte(getNewstate());
    lew.writeShort(getDuration());
}

From source file:net.packet.movement.JumpDownMovement.java

License:Open Source License

@Override
public void serialize(ByteBuf lew) {
    lew.writeByte(getType());/*from   w  w w . j  a va  2 s  . c  o  m*/
    lew.writeShort(getPosition().x);
    lew.writeShort(getPosition().y);
    lew.writeShort(pixelsPerSecond.x);
    lew.writeShort(pixelsPerSecond.y);
    lew.writeShort(unk);
    lew.writeShort(fh);
    lew.writeByte(getNewstate());
    lew.writeShort(getDuration());
}

From source file:net.packet.movement.RelativeLifeMovement.java

License:Open Source License

@Override
public void serialize(ByteBuf lew) {
    lew.writeByte(getType());//from   w w  w  .j  a  va 2  s.  c  om
    lew.writeShort(getPosition().x);
    lew.writeShort(getPosition().y);
    lew.writeByte(getNewstate());
    lew.writeShort(getDuration());
}

From source file:net.shadowmage.ancientwarfare.core.util.StringTools.java

License:Open Source License

public static final void writeString(ByteBuf out, String string) {
    byte[] nameBytes = string.getBytes();
    out.writeShort(nameBytes.length);
    out.writeBytes(nameBytes);//from   w  ww.  ja  va  2s . co m
}

From source file:net.tomp2p.connection.DefaultSignatureFactory.java

License:Apache License

@Override
public void encodePublicKey(PublicKey publicKey, ByteBuf buf) {
    byte[] data = publicKey.getEncoded();
    buf.writeShort(data.length);
    buf.writeBytes(data);/*from w ww  . ja v a2s .  c  o  m*/
}

From source file:net.tomp2p.message.MessageHeaderCodec.java

License:Apache License

/**
 * Encodes a message object./*ww w  .j  av  a  2s  .  co  m*/
 * 
 * The format looks as follows: 28bit p2p version - 4bit message type - 32bit message id - 8bit message command - 160bit
 * sender id - 16bit sender tcp port - 16bit sender udp port - 160bit recipient id - 32bit content types - 8bit options. It total,
 * the header is of size 58 bytes.
 * 
 * @param buffer
 *            The buffer to encode to
 * @param message
 *            The message with the header that will be encoded
 * @return The buffer passed as an argument
 */
public static void encodeHeader(final ByteBuf buffer, final Message message) {
    final int versionAndType = message.version() << 4 | (message.type().ordinal() & Utils.MASK_0F);
    buffer.writeInt(versionAndType); // 4
    buffer.writeInt(message.messageId()); // 8
    buffer.writeByte(message.command()); // 9
    buffer.writeBytes(message.sender().peerId().toByteArray()); // 29
    buffer.writeShort((short) message.sender().tcpPort()); // 31
    buffer.writeShort((short) message.sender().udpPort()); // 33
    buffer.writeBytes(message.recipient().peerId().toByteArray()); // 53
    buffer.writeInt(encodeContentTypes(message.contentTypes())); // 57
    // three bits for the message options, 5 bits for the sender options
    buffer.writeByte((message.sender().options() << 3) | message.options()); // 58
}

From source file:net.tomp2p.rpc.SimpleBloomFilter.java

License:Apache License

/**
 * Converts data to a byte buffer. The first two bytes contain the size of
 * this simple bloom filter. Thus, the bloom filter can only be of length
 * 65536.//from ww w .  j  av a 2s  .c  o m
 * 
 * @param buf
 *            The byte buffer where the bloom filter will be written.
 */
public void toByteBuf(final ByteBuf buf) {
    buf.writeShort(byteArraySize + SIZE_HEADER_ELEMENTS + SIZE_HEADER_LENGTH);
    buf.writeInt(expectedElements);
    byte[] tmp = RPCUtils.toByteArray(bitSet);
    int currentByteArraySize = tmp.length;
    buf.writeBytes(tmp);
    buf.writeZero(byteArraySize - currentByteArraySize);
}