List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.quavo.osrs.network.protocol.codec.connection.ConnectionEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ConnectionResponse msg, ByteBuf out) throws Exception { ChannelPipeline pipeline = ctx.pipeline(); switch (msg.getType()) { case HANDSHAKE_CONNECTION: pipeline.addAfter("decoder", "handshake.encoder", new HandshakeEncoder()); pipeline.replace("decoder", "handshake.decoder", new HandshakeDecoder()); break;/* w w w. j a v a 2s. c om*/ case LOGIN_CONNECTION: out.writeByte(ClientMessage.SUCCESSFUL_CONNECTION.getId()); pipeline.addAfter("decoder", "login.encoder", new LoginEncoder()); pipeline.replace("decoder", "login.decoder", new LoginDecoder()); break; } pipeline.remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.game.GamePacketEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, GamePacketResponse msg, ByteBuf out) throws Exception { PacketEncoder<PacketContext> packet = msg.getPacket(); PacketType type = packet.getPacket().getType(); ByteBuf buffer = packet.getBuilder().getBuffer(); out.writeByte(packet.getPacket().getId()/* + encoder.nextInt() */); if (type == PacketType.VARIABLE_BYTE) { out.writeByte(buffer.writerIndex()); } else if (type == PacketType.VARIABLE_SHORT) { out.writeShort(buffer.writerIndex()); }//from w ww . j ava 2s. c o m out.writeBytes(buffer); }
From source file:com.quavo.osrs.network.protocol.codec.handshake.HandshakeEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, HandshakeResponse msg, ByteBuf out) throws Exception { ChannelPipeline pipeline = ctx.pipeline(); ClientMessage message = msg.getMessage(); out.writeByte(message.getId()); if (message == ClientMessage.SUCCESSFUL_CONNECTION) { pipeline.addAfter("handshake.decoder", "xor.encrypt", new XOREncryptionEncoder()); pipeline.addAfter("xor.encrypt", "update.encoder", new UpdateEncoder()); pipeline.replace("handshake.decoder", "update.decoder", new UpdateDecoder()); }//from w ww .ja v a 2 s .c o m pipeline.remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.login.LoginEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, LoginResponse msg, ByteBuf out) throws Exception { ClientMessage message = msg.getMessage(); ChannelPipeline pipeline = ctx.pipeline(); if (message != ClientMessage.SUCCESSFUL) { // dont write the id for successful. out.writeByte(message.getId()); } else {// w w w .j a v a 2 s. co m pipeline.addAfter("login.decoder", "world.encoder", new WorldLoginEncoder()); pipeline.replace("login.decoder", "world.decoder", new WorldLoginDecoder(msg.getType())); } pipeline.remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.login.world.WorldLoginEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, WorldLoginResponse msg, ByteBuf out) throws Exception { ClientMessage message = msg.getMessage(); out.writeByte(message.getId()); if (message == ClientMessage.SUCCESSFUL) { out.writeByte(0);// ww w. j a v a2 s.c om out.writeByte(0); out.writeByte(0); out.writeByte(0); out.writeByte(0); out.writeByte(2);// rights out.writeByte(0); out.writeShort(1);// index out.writeByte(1); } ctx.pipeline().remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.update.UpdateEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, UpdateResponse msg, ByteBuf out) throws Exception { int type = msg.getType(); int id = msg.getId(); ByteBuf container = msg.getContainer(); int compression = container.readUnsignedByte(); int length = container.readInt(); out.writeByte(type); out.writeShort(id);/*from w ww. j a v a 2s . c o m*/ out.writeByte(compression); out.writeInt(length); int bytes = container.readableBytes(); if (bytes > 504) { bytes = 504; } out.writeBytes(container.readBytes(bytes)); while ((bytes = container.readableBytes()) != 0) { if (bytes == 0) { break; } else if (bytes > 511) { bytes = 511; } out.writeByte(0xff); out.writeBytes(container.readBytes(bytes)); } }
From source file:com.quavo.util.buf.ByteBufUtils.java
License:Open Source License
/** * Writes a jag string into the buffer.//from w w w . j a v a2s .c o m * * @param out The buffer. * @param str The string. */ public static void writeJagString(ByteBuf out, String str) { out.writeByte(0); out.writeBytes(str.getBytes()); out.writeByte(ByteBufUtils.STRING_TERMINATOR); }
From source file:com.rs3e.network.protocol.codec.js5.UpdateEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, FileResponse response, ByteBuf buf) throws Exception { ByteBuf container = response.getContainer(); int type = response.getType(); int file = response.getFile(); int compression = container.readUnsignedByte(); int size = ((container.readByte() & 0xff) << 24) + ((container.readByte() & 0xff) << 16) + ((container.readByte() & 0xff) << 8) + (container.readByte() & 0xff); if (!response.isPriority()) { file |= 0x80000000;/*from w w w.j a v a 2s. c o m*/ } buf.writeByte(type); buf.writeInt(file); buf.writeByte(compression); buf.writeInt(size); int bytes = container.readableBytes(); if (bytes > 502) { bytes = 502; } buf.writeBytes(container.readBytes(bytes)); for (;;) { bytes = container.readableBytes(); if (bytes == 0) { break; } else if (bytes > 507) { bytes = 507; } buf.writeByte(type); buf.writeInt(file); buf.writeBytes(container.readBytes(bytes)); } }
From source file:com.rs3e.network.protocol.codec.js5.UpdateStatusEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, UpdateStatusMessage msg, ByteBuf out) throws Exception { for (int i = 0; i < UPDATE_DATA.length; i++) out.writeInt(UPDATE_DATA[i]);/*w w w . ja v a 2s .co m*/ out.writeByte(msg.getStatus()); }
From source file:com.rs3e.network.protocol.codec.js5.XorEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) { while (in.readable()) { out.writeByte(in.readUnsignedByte() ^ key); }/*from w ww.ja v a 2s.c o m*/ }