Java Code Examples for io.netty.buffer.ByteBuf#setShortLE()
The following examples show how to use
io.netty.buffer.ByteBuf#setShortLE() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FecEncode.java From java-Kcp with Apache License 2.0 | 5 votes |
public void markParity(ByteBuf byteBuf, int offset){ byteBuf.setIntLE(offset, (int) this.next); byteBuf.setShortLE(offset+4,Fec.typeParity); //if(next==this.paws){ // next=0; //}else{ // next++; //} this.next = (this.next + 1) % this.paws; //if(next+1>=this.paws) { // this.next++; // //this.next = (this.next + 1) % this.paws; //} }
Example 2
Source File: FecEncode.java From java-Kcp with Apache License 2.0 | 4 votes |
public void markData(ByteBuf byteBuf,int offset){ byteBuf.setIntLE(offset, (int) this.next); byteBuf.setShortLE(offset+4, Fec.typeData); this.next++; }
Example 3
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static void writeItemData(ByteBuf buffer, ItemData item) { Preconditions.checkNotNull(buffer, "buffer"); Preconditions.checkNotNull(item, "item"); // Write id int id = item.getId(); if (id == 0) { // We don't need to write anything extra. buffer.writeByte(0); return; } VarInts.writeInt(buffer, id); // Write damage and count short damage = item.getDamage(); if (damage == -1) damage = Short.MAX_VALUE; VarInts.writeInt(buffer, (damage << 8) | (item.getCount() & 0xff)); // Remember this position, since we'll be writing the true NBT size here later: int sizeIndex = buffer.writerIndex(); buffer.writeShortLE(0); if (item.getTag() != null) { int afterSizeIndex = buffer.writerIndex(); try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianByteBufOutputStream(buffer))) { stream.write(item.getTag()); } catch (IOException e) { // This shouldn't happen (as this is backed by a Netty ByteBuf), but okay... throw new IllegalStateException("Unable to save NBT data", e); } // Set to the written NBT size buffer.setShortLE(sizeIndex, buffer.writerIndex() - afterSizeIndex); } String[] canPlace = item.getCanPlace(); VarInts.writeInt(buffer, canPlace.length); for (String aCanPlace : canPlace) { BedrockUtils.writeString(buffer, aCanPlace); } String[] canBreak = item.getCanBreak(); VarInts.writeInt(buffer, canBreak.length); for (String aCanBreak : canBreak) { BedrockUtils.writeString(buffer, aCanBreak); } }
Example 4
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static void writeItemData(ByteBuf buffer, ItemData item) { Preconditions.checkNotNull(buffer, "buffer"); Preconditions.checkNotNull(item, "item"); // Write id int id = item.getId(); if (id == 0) { // We don't need to write anything extra. buffer.writeByte(0); return; } VarInts.writeInt(buffer, id); // Write damage and count short damage = item.getDamage(); if (damage == -1) damage = Short.MAX_VALUE; VarInts.writeInt(buffer, (damage << 8) | (item.getCount() & 0xff)); // Remember this position, since we'll be writing the true NBT size here later: int sizeIndex = buffer.writerIndex(); buffer.writeShortLE(0); if (item.getTag() != null) { int afterSizeIndex = buffer.writerIndex(); try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianByteBufOutputStream(buffer))) { stream.write(item.getTag()); } catch (IOException e) { // This shouldn't happen (as this is backed by a Netty ByteBuf), but okay... throw new IllegalStateException("Unable to save NBT data", e); } // Set to the written NBT size buffer.setShortLE(sizeIndex, buffer.writerIndex() - afterSizeIndex); } String[] canPlace = item.getCanPlace(); VarInts.writeInt(buffer, canPlace.length); for (String aCanPlace : canPlace) { BedrockUtils.writeString(buffer, aCanPlace); } String[] canBreak = item.getCanBreak(); VarInts.writeInt(buffer, canBreak.length); for (String aCanBreak : canBreak) { BedrockUtils.writeString(buffer, aCanBreak); } }