List of usage examples for io.netty.buffer ByteBuf readerIndex
public abstract ByteBuf readerIndex(int readerIndex);
From source file:com.outbrain.pajamasproxy.memcached.adapter.LocalCacheElement.java
License:Apache License
@Override public void setData(final ByteBuf data) { data.readerIndex(0); this.data = data; }
From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java
License:Open Source License
/** * Reads the data from a {@link ByteBuf} for a login clearance. * //www .ja v a2 s . c o m * @param buffer The {@link ByteBuf}. */ public void readNoReturn(ByteBuf buffer) { switch (this) { case NORMAL: buffer.readerIndex(buffer.readerIndex() + 8); break; case TRUSTED_COMPUTER: buffer.readInt(); buffer.readerIndex(buffer.readerIndex() + 4); break; case AUTHENTICATOR: case TRUSTED_AUTHENTICATOR: buffer.readMedium(); buffer.readerIndex(buffer.readerIndex() + 5); break; } }
From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java
License:Open Source License
/** * Reads the data from a {@link ByteBuf} for a login clearance. * /*from www . jav a2s. c om*/ * @param buffer The {@link ByteBuf}. * @return The created login clearance type. */ public LoginClearance read(ByteBuf buffer) { switch (this) { case NORMAL: buffer.readerIndex(buffer.readerIndex() + 8); break; case TRUSTED_COMPUTER: buffer.readInt(); buffer.readerIndex(buffer.readerIndex() + 4); break; case AUTHENTICATOR: case TRUSTED_AUTHENTICATOR: buffer.readMedium(); buffer.readerIndex(buffer.readerIndex() + 5); break; } return this; }
From source file:com.rs3e.network.protocol.codec.js5.UpdateDecoder.java
License:Open Source License
@Override public Object decode(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { if (buf.readableBytes() < 6) return null; if (updateStage == UpdateStage.READ_VERSION) { updateStage = UpdateStage.READ_REQUEST; int length = buf.readUnsignedByte(); if (buf.readableBytes() >= length) { int version = buf.readInt(); int subVersion = buf.readInt(); String key = ByteBufUtils.readString(buf); return new UpdateVersionMessage(version, subVersion, key); }/*from www .ja v a 2s . c om*/ } else { int opcode = buf.readUnsignedByte(); if (opcode == 0 || opcode == 1) { int type = buf.readUnsignedByte(); int file = buf.readInt(); return new FileRequest(opcode == 1, type, file); } else if (opcode == 4) { int key = buf.readUnsignedByte(); buf.readerIndex(buf.readerIndex() + 2); return new UpdateEncryptionMessage(key); } else { buf.readerIndex(buf.readerIndex() + 5); return null; } } return null; }
From source file:com.rs3e.utility.ByteBufUtils.java
License:Open Source License
public static String readString(ByteBuf buffer) { buffer.markReaderIndex();/* w ww . j a v a 2 s.c om*/ int len = 0; while (buffer.readUnsignedByte() != 0) len++; buffer.resetReaderIndex(); byte[] bytes = new byte[len]; buffer.readBytes(bytes); buffer.readerIndex(buffer.readerIndex() + 1); return new String(bytes, Charsets.ASCII_LATIN1_CHARSET); }
From source file:com.streamsets.pipeline.lib.parser.net.BaseNetworkMessageDataParser.java
License:Apache License
private void decodeMessages() throws IOException, DataParserException { byte[] bytes; if (inputStream != null) { bytes = IOUtils.toByteArray(inputStream); } else if (reader != null) { bytes = IOUtils.toByteArray(reader, charset); } else {/*from ww w.j a va2 s. c om*/ throw new IllegalStateException( "Both inputStream and reader were null in BaseNetworkMessageDataParser#decodeMessages"); } ByteBuf buffer = Unpooled.copiedBuffer(bytes); if (maxObjectLen > 0) { buffer.capacity(maxObjectLen); } if (readerOffset != null && readerOffset > 0) { buffer.readerIndex(readerOffset.intValue()); } try { performDecode(buffer); decodedMessagesIter = decodedMessages.listIterator(); decoded = true; } catch (OnRecordErrorException e) { throw new DataParserException(Errors.SYSLOG_20, e.getMessage(), e); } }
From source file:com.talent.balance.backend.decode.BackendResponseDecoder.java
License:Open Source License
@Override public PacketWithMeta<Packet> decode(ByteBuf buffer, ChannelContext channelContext) throws DecodeException { BalancePacket backendResponsePacket = new BalancePacket(); if (MysqlExt.getHandshakePacket(channelContext) == null && BackendExt.PROTOCOL_MYSQL.equals(channelContext.getProtocol())) { HandshakePacket handshakePacket = new HandshakePacket(); PacketWithMeta<Packet> pwm = handshakePacket.decode(buffer); return pwm; }/*from w w w . ja va 2 s. c o m*/ backendResponsePacket.setBuffer(Unpooled.copiedBuffer(buffer)); List<Packet> packets = new ArrayList<Packet>(); packets.add(backendResponsePacket); PacketWithMeta<Packet> packetWithMeta = new PacketWithMeta<Packet>(); buffer.readerIndex(buffer.capacity()); packetWithMeta.setPacketLenght(buffer.capacity()); packetWithMeta.setPackets(packets); return packetWithMeta; }
From source file:com.talent.balance.frontend.decode.FrontendRequestDecoder.java
License:Open Source License
@Override public PacketWithMeta decode(ByteBuf buffer, ChannelContext channelContext) throws DecodeException { BalancePacket frontendRequestPacket = new BalancePacket(); frontendRequestPacket.setBuffer(Unpooled.copiedBuffer(buffer)); List<Packet> ret = new ArrayList<Packet>(); ret.add(frontendRequestPacket);/* w ww. ja va 2 s . c o m*/ PacketWithMeta packetWithMeta = new PacketWithMeta(); buffer.readerIndex(buffer.capacity()); packetWithMeta.setPacketLenght(buffer.capacity()); packetWithMeta.setPackets(ret); return packetWithMeta; }
From source file:com.talent.mysql.packet.factory.MysqlHeaderFactory.java
License:Open Source License
/** * @param args/* w w w . j av a 2s . c o m*/ */ public static void main(String[] args) { int bodyLength = 9; byte serialNum = 2; MysqlHeader mysqlHeader = new MysqlHeader(bodyLength, serialNum); ByteBuf byteBuf = mysqlHeader.encode(); byteBuf.readerIndex(0); mysqlHeader.decode(byteBuf); }
From source file:com.talent.mysql.packet.MysqlRequestPacket.java
License:Open Source License
public ByteBuf encode() { ByteBuf byteBuf = createHeader().encode(); encodeBody(byteBuf); byteBuf.readerIndex(0); return byteBuf; }