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

The following are Jave code examples for showing how to use readMedium() 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: cr-private-server   File: PacketDecoder.java   Source Code and License Vote up 6 votes
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!hasHeader) {
		if (in.readableBytes() >= 7) {
			short id = in.readShort();
			int payloadLength = in.readMedium();
			short version = in.readShort();

			hasHeader = true;
			header.id = id;
			header.payload = new byte[payloadLength];
		}
	} else {
		if (in.readableBytes() >= header.payload.length) {
			in.readBytes(header.payload);
			hasHeader = false;

			crypto.decryptPacket(header);

			ClientMessage message = processPacket();
			if (message != null) {
				out.add(message);
			}
		}
	}
}
 
Example 2
Project: Quavo   File: MachineInformation.java   Source Code and License Vote up 5 votes
/**
 * Decodes the machine information of the user during the {@link WorldLoginDecoder}.
 * 
 * @param buffer The {@link ByteBuf}.
 * @return The created machine information.
 */
public static MachineInformation decode(ByteBuf buffer) {
	buffer.readByte();
	int osArch = buffer.readByte();
	boolean is64Bit = buffer.readByte() == 1;
	int osBuild = buffer.readByte();
	int vendor = buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readShort();
	buffer.readByte();
	buffer.readMedium();
	buffer.readShort();
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	buffer.readByte();
	buffer.readShort();
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	buffer.readByte();
	buffer.readByte();
	return new MachineInformation(osArch, is64Bit, osBuild, vendor);
}