List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnExperienceOrb.java
License:Apache License
@Override public void encode(ByteBuf buf) { Codec.writeVarInt32(buf, this.entityId); buf.writeInt((int) this.location.x() * 32); buf.writeInt((int) this.location.y() * 32); buf.writeInt((int) this.location.z() * 32); buf.writeShort((int) this.count); }
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnMob.java
License:Apache License
@Override public void encode(ByteBuf buf) { Position loc = this.entity.position(); Vector velocity = this.entity.velocity(); Codec.writeVarInt32(buf, this.entityId); buf.writeByte((int) (byte) this.entity.type().ordinal()); // TODO: use the real type id buf.writeInt((int) loc.x() * 32); buf.writeInt((int) loc.y() * 32); buf.writeInt((int) loc.z() * 42); buf.writeByte((int) (byte) loc.yaw()); buf.writeByte((int) (byte) loc.pitch()); buf.writeByte((int) (byte) loc.pitch()); // -shrugs- buf.writeShort((int) velocity.x()); buf.writeShort((int) velocity.y()); buf.writeShort((int) velocity.z()); metadata.write(buf);/*from w w w .j a va 2s.c om*/ }
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnObject.java
License:Apache License
@Override public void encode(ByteBuf buf) { Position l = this.entity.position(); Vector v = this.entity.velocity(); Codec.writeVarInt32(buf, this.entityId); buf.writeByte(this.type.ordinal()); // TODO: Get the correct id type buf.writeInt((int) l.x() * 32); buf.writeInt((int) l.y() * 32); buf.writeInt((int) l.z() * 32); buf.writeByte((int) (byte) l.yaw()); buf.writeByte((int) (byte) l.pitch()); buf.writeByte((int) (byte) l.pitch()); // -shrugs- buf.writeShort((int) v.x()); buf.writeShort((int) v.y()); buf.writeShort((int) v.z()); }
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnPlayer.java
License:Apache License
@Override public void encode(ByteBuf buf) { Position loc = this.player.position(); UUID id = this.player.uniqueId(); Codec.writeVarInt32(buf, this.entityId); buf.writeLong(id.getMostSignificantBits()); buf.writeLong(id.getLeastSignificantBits()); buf.writeInt((int) loc.x() * 32); buf.writeInt((int) loc.y() * 32); buf.writeInt((int) loc.z() * 32); buf.writeByte((int) (byte) loc.yaw()); buf.writeByte((int) (byte) loc.pitch()); buf.writeShort(player.heldItem().id()); metadata.write(buf);//w w w .j a v a2 s .com }
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutWindowItems.java
License:Apache License
@Override public void encode(ByteBuf buf) { buf.writeByte(this.windowId); buf.writeShort(this.slots.length); for (Slot s : this.slots) { if (s == null) { EMPTY.write(buf);//from w w w .jav a 2 s. c o m continue; } s.write(buf); } }
From source file:nettyClient4.clientImpl.java
License:Apache License
private ByteBuf getWriteBuffer(int arg1, int arg2, ByteBuf buffer, Object... paras) { if (buffer == null) { buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(10); }/* w w w. j a va2s. c o m*/ buffer.writeShort(Short.MIN_VALUE);//?2 buffer.writeByte(arg1); if (arg2 != 0) buffer.writeByte(arg2); for (Object para : paras) { if (para instanceof Byte) { buffer.writeByte((Byte) para); // ?1 } else if ((para instanceof String)) { buffer.writeBytes(((String) para).getBytes()); } else if (para instanceof Integer) { buffer.writeInt((Integer) para); //?4 } else if (para instanceof Short) { buffer.writeShort((Short) para); //?2 } } /**?2setShort*/ buffer.setShort(0, buffer.writerIndex() - 0x2); return buffer; }
From source file:org.aotorrent.common.protocol.tracker.HTTPTrackerResponse.java
License:Apache License
public ByteBuf toTransmit() throws IOException, InvalidBEncodingException { Map<String, BEncodeValue> responseMap = Maps.newHashMap(); responseMap.put("interval", new BEncodeValue(interval)); responseMap.put("min_interval", new BEncodeValue(interval)); responseMap.put("tracker id", new BEncodeValue(trackerId)); responseMap.put("complete", new BEncodeValue(complete)); responseMap.put("incomplete", new BEncodeValue(incomplete)); ByteBuf peersEncoded = Unpooled.buffer(peers.size() * 6); for (InetSocketAddress peer : peers) { peersEncoded.writeBytes(peer.getAddress().getAddress()); peersEncoded.writeShort(peer.getPort()); }//from w w w.j a va 2 s . c o m responseMap.put("peers", new BEncodeValue( new String(peersEncoded.array(), Charset.forName(Torrent.DEFAULT_TORRENT_ENCODING)))); return BEncodeWriter.writeOut(responseMap); }
From source file:org.aotorrent.common.protocol.tracker.UDPAnnounceRequest.java
License:Apache License
@Override public ByteBuf toTransmit() { final ByteBuf buf = Unpooled.buffer(98, 98); buf.writeLong(connectionId);//from ww w.j a va2s .c o m buf.writeInt(action); buf.writeInt(transactionId); buf.writeBytes(infoHash); buf.writeBytes(peerId); buf.writeLong(downloaded); buf.writeLong(left); buf.writeLong(uploaded); buf.writeInt(event); buf.writeInt(0); buf.writeInt(0); // key buf.writeInt(-1); buf.writeShort(port); return buf; }
From source file:org.apache.activemq.artemis.utils.UTF8Util.java
License:Apache License
private static void writeAsShorts(final ByteBuf buffer, final String val) { for (int i = 0; i < val.length(); i++) { buffer.writeShort((short) val.charAt(i)); }//from w ww . j a va2 s . c o m }
From source file:org.apache.activemq.artemis.utils.UTF8Util.java
License:Apache License
public static void saveUTF(final ByteBuf out, final String str) { if (str.length() > 0xffff) { throw ActiveMQUtilBundle.BUNDLE.stringTooLong(str.length()); }/*from www .ja v a2 s . c o m*/ final int len = UTF8Util.calculateUTFSize(str); if (len > 0xffff) { throw ActiveMQUtilBundle.BUNDLE.stringTooLong(len); } out.writeShort((short) len); final int stringLength = str.length(); if (UTF8Util.isTrace) { // This message is too verbose for debug, that's why we are using trace here ActiveMQUtilLogger.LOGGER.trace("Saving string with utfSize=" + len + " stringSize=" + stringLength); } if (out.hasArray()) { out.ensureWritable(len); final byte[] bytes = out.array(); final int writerIndex = out.writerIndex(); final int index = out.arrayOffset() + writerIndex; if (PlatformDependent.hasUnsafe()) { unsafeOnHeapWriteUTF(str, bytes, index, stringLength); } else { writeUTF(str, bytes, index, stringLength); } out.writerIndex(writerIndex + len); } else { if (PlatformDependent.hasUnsafe() && out.hasMemoryAddress()) { out.ensureWritable(len); final long addressBytes = out.memoryAddress(); final int writerIndex = out.writerIndex(); unsafeOffHeapWriteUTF(str, addressBytes, writerIndex, stringLength); out.writerIndex(writerIndex + len); } else { final StringUtilBuffer buffer = UTF8Util.getThreadLocalBuffer(); final byte[] bytes = buffer.borrowByteBuffer(len); writeUTF(str, bytes, 0, stringLength); out.writeBytes(bytes, 0, len); } } }