Java Code Examples for io.netty.buffer.ByteBuf.writeIntLE()

The following are Jave code examples for showing how to use writeIntLE() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RakNetty   File: LoginPacket.java   Source Code and License Vote up 7 votes
@Override
public void write(RakNetByteBuf out) {
    super.write(out);
    out.writeInt(protocolVersion);
    out.writeByte(edition);

    ByteBuf buf = Unpooled.buffer();
    buf.writeIntLE(chainData.length());
    buf.writeCharSequence(chainData, Charsets.UTF_8);
    buf.writeIntLE(skinData.length());
    buf.writeCharSequence(skinData, Charsets.UTF_8);

    out.writeUnsignedVarInt(buf.writerIndex());
    out.writeBytes(buf);
    buf.release();
}
 
Example 2
Project: JungleTree   File: LoginCodec.java   Source Code and License Vote up 6 votes
@Override
public void encode(Packet msg, ByteBuf buf) {
    LoginPacket message = (LoginPacket) msg;

    // TODO: Encoding
    buf.writeInt(message.getClientNetworkVersion());

    ConnectionInfo info = message.getConnectionInfo();
    byte[] chainBytes = GSON.toJson(info.getTokenChain()).getBytes(StandardCharsets.UTF_8);
    byte[] clientDataTokenBytes = info.getClientDataToken().getBytes(StandardCharsets.UTF_8);

    // Write body size
    ByteBufUtils.writeUnsignedVarInt(buf, chainBytes.length + clientDataTokenBytes.length + (LE_INT_SIZE_BYTES * 2));

    buf.writeIntLE(chainBytes.length);
    buf.writeBytes(chainBytes);

    buf.writeIntLE(clientDataTokenBytes.length);
    buf.writeBytes(clientDataTokenBytes);
}
 
Example 3
Project: nearenough   File: RtWire.java   Source Code and License Vote up 5 votes
private static void writeOffsets(RtMessage msg, ByteBuf buf) {
  if (msg.numTags() < 2) {
    return;
  }

  Iterator<byte[]> iter = msg.mapping().values().iterator();
  int offsetSum = iter.next().length;

  while (iter.hasNext()) {
    buf.writeIntLE(offsetSum);
    offsetSum += iter.next().length;
  }

  checkState(offsetSum >= 0);
}
 
Example 4
Project: kcp-netty   File: Kcp.java   Source Code and License Vote up 5 votes
private static int encodeSeg(ByteBuf buf, Segment seg) {
    int offset = buf.writerIndex();

    buf.writeIntLE(seg.conv);
    buf.writeByte(seg.cmd);
    buf.writeByte(seg.frg);
    buf.writeShortLE(seg.wnd);
    buf.writeIntLE((int) seg.ts);
    buf.writeIntLE((int) seg.sn);
    buf.writeIntLE((int) seg.una);
    buf.writeIntLE(seg.data.readableBytes());

    return buf.writerIndex() - offset;
}
 
Example 5
Project: ProtocolSupportPocketStuff   File: ResourcePackChunkDataPacket.java   Source Code and License Vote up 5 votes
@Override
public void toData(Connection connection, ByteBuf serializer) {
	StringSerializer.writeString(serializer, ProtocolVersion.MINECRAFT_PE, packId);
	serializer.writeIntLE(chunkIdx);
	serializer.writeLongLE(StuffUtils.CHUNK_SIZE * chunkIdx);
	serializer.writeIntLE(packChunk.length);
	serializer.writeBytes(packChunk);
}
 
Example 6
Project: ProtocolSupportPocketStuff   File: ResourcePackDataInfoPacket.java   Source Code and License Vote up 5 votes
@Override
public void toData(Connection connection, ByteBuf serializer) {
	StringSerializer.writeString(serializer, ProtocolVersion.MINECRAFT_PE, pack.getPackId());
	serializer.writeIntLE(StuffUtils.CHUNK_SIZE); // max chunk size 1MB
	serializer.writeIntLE(pack.getPackSize() / StuffUtils.CHUNK_SIZE); // chunk count
	serializer.writeLongLE(pack.getPackSize()); // res pack size

	byte[] hash = pack.getSha256();

	VarNumberSerializer.writeVarInt(serializer, hash.length);
	for (byte b : hash) {
		serializer.writeByte(b);
	}
}
 
Example 7
Project: JungleTree   File: ByteBufUtils.java   Source Code and License Vote up 4 votes
public static void writeFloatLE(ByteBuf buf, float value) {
    buf.writeIntLE(Float.floatToRawIntBits(value));
}
 
Example 8
Project: nearenough   File: RtWire.java   Source Code and License Vote up 4 votes
private static void writeNumTags(RtMessage msg, ByteBuf buf) {
  buf.writeIntLE(msg.numTags());
}