List of usage examples for io.netty.buffer ByteBuf getInt
public abstract int getInt(int index);
From source file:com.hazelcast.simulator.protocol.core.ResponseCodec.java
License:Open Source License
public static int getDestinationAddressLevel(ByteBuf in) { return in.getInt(OFFSET_DST_ADDRESS); }
From source file:com.hazelcast.simulator.protocol.core.ResponseCodec.java
License:Open Source License
public static int getChildAddressIndex(ByteBuf in, int addressLevelValue) { return in.getInt(OFFSET_DST_ADDRESS + ((addressLevelValue + 1) * INT_SIZE)); }
From source file:com.hazelcast.simulator.protocol.core.SimulatorMessageCodec.java
License:Open Source License
public static boolean isSimulatorMessage(ByteBuf in) { return (in.getInt(OFFSET_MAGIC_BYTES) == MAGIC_BYTES); }
From source file:com.heliosapm.streams.tracing.writers.NetWriter.java
License:Apache License
/** * {@inheritDoc}//ww w. ja v a2 s. c o m * @see com.heliosapm.streams.tracing.AbstractMetricWriter#onMetrics(io.netty.buffer.ByteBuf) */ @Override public void onMetrics(final ByteBuf metrics) { if (metrics == null || metrics.readableBytes() < 5) return; final int size = metrics.getInt(1); if (!connectionsAvailable.get()) { // FIXME: drop counter return; } boolean complete = false; for (Channel ch : channels) { final ChannelFuture cf = ch.writeAndFlush(metrics).syncUninterruptibly(); if (cf.isSuccess()) { complete = true; break; } } if (!complete) { this.failedMetrics.add(size); } }
From source file:com.necla.simba.server.gateway.server.backend.BackendFrameDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { // length not received yet, return without producing // an output return;/* ww w .j a v a2s . c o m*/ } // get calls on ByteBuf don't change the stream // so we leave 'ByteBuf in' unchanged after reading // the length int readerIndex = in.readerIndex(); int length = in.getInt(readerIndex); LOG.debug("got message len=" + length + " readablebytes=" + in.readableBytes()); if (in.readableBytes() < length + 4) return; ByteBuf frame = extractMessage(ctx, in, 4 + readerIndex, length); out.add(frame); in.readerIndex(readerIndex + 4 + length); return; }
From source file:com.necla.simba.server.gateway.server.frontend.FrontendFrameDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { // length not received yet, return without producing // an output return;/*from w w w. j a v a2s . co m*/ } // get calls on ByteBuf don't change the stream // so we leave 'ByteBuf in' unchanged after reading // the length int readerIndex = in.readerIndex(); int length = in.getInt(readerIndex); int realLength = length & ~(1 << 30); boolean isCompressed = (length >> 30) > 0; LOG.debug("got message len=" + realLength + " isCompressed=" + isCompressed + " readablebytes=" + in.readableBytes()); if (in.readableBytes() < realLength + 4) return; if (!isCompressed) { ByteBuf frame = extractMessage(ctx, in, 4 + readerIndex, realLength); out.add(frame); } else { ByteBuf frame = in.slice(4 + readerIndex, realLength); LOG.debug("going into decompress"); ByteBuf ret = decompress(ctx, frame); LOG.debug("ret readablebytes=" + ret.readableBytes()); out.add(decompress(ctx, frame)); } in.readerIndex(readerIndex + 4 + realLength); Stats.received(readerIndex + 4 + realLength); return; }
From source file:com.neoba.MessageInterpreter.java
MessageInterpreter(ChannelHandlerContext ctx, ByteBuf buff) { VERSION = buff.getByte(0);//from w ww. j a v a2s . c o m type = buff.getByte(1); size = buff.getInt(2); if (type != Constants.PINGPONG && type != Constants.USER_CREATE && type != Constants.USER_LOGIN && type != Constants.FACEBOOK_USER_CREATE && type != Constants.FACEBOOK_USER_LOGIN) { sessid = new UUID(buff.getLong(14), buff.getLong(6)); if (isloggedin()) { logger.info("Authenticated message from user " + Dsyncserver.usersessions.get(sessid) + " with session " + sessid); } } else { sessid = null; } this.buff = buff; this.ctx = ctx; }
From source file:com.quavo.util.buf.ByteBufUtils.java
License:Open Source License
/** * Deciphers the specified {@link ByteBuf} with the given key. * //from w w w .java2 s .c om * @param buffer The {@link ByteBuf}. * @param key The key. * @throws IllegalArgumentException if the key is not exactly 4 elements long. */ private static void decipherXTEA(ByteBuf buffer, int start, int end, int[] key) { if (key.length != 4) { throw new IllegalArgumentException(); } int numQuads = (end - start) / 8; for (int i = 0; i < numQuads; i++) { int sum = 0x9E3779B9 * 32; int v0 = buffer.getInt(start + i * 8); int v1 = buffer.getInt(start + i * 8 + 4); for (int j = 0; j < 32; j++) { v1 -= (((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + key[(sum >>> 11) & 3]); sum -= 0x9E3779B9; v0 -= (((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + key[sum & 3]); } buffer.setInt(start + i * 8, v0); buffer.setInt(start + i * 8 + 4, v1); } }
From source file:com.talent.mysql.packet.request.AuthPacket.java
License:Open Source License
public void decodeBody(ByteBuf _byteBuf) { byte[] bs = new byte[] { -117, -93, 2, 0, 0, 0, 0, 64, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 111, 111, 116, 0, 20, -19, -111, -3, 39, -46, -116, -128, -44, -112, -26, -48, 42, 70, -85, 8, 83, 83, 100, 103, 68, 116, 97, 108, 101, 110, 116, 95, 98, 97, 115, 101, 119, 101, 98, 50, 48, 49, 0 };/*from w ww. j a v a 2 s.c o m*/ ByteBuf byteBuf = Unpooled.buffer(bs.length); byteBuf = byteBuf.order(ByteOrder.LITTLE_ENDIAN); byteBuf.setBytes(0, bs, 0, bs.length); int _index = byteBuf.readerIndex(); int index = _index; clientFlags = byteBuf.getInt(index); //172939 index += 4; maxPacketSize = byteBuf.getInt(index); //1073741824 index += 4; charsetIndex = byteBuf.getByte(index); //33 index += 1; index += extra.length; int len = 0; while (byteBuf.getByte(index + len) != 0) { len++; } user = new byte[len]; byteBuf.getBytes(index, user, 0, len); index += len; index++; passwordLen = byteBuf.getByte(index); index += 1; password = new byte[passwordLen]; byteBuf.getBytes(index, password, 0, passwordLen); len = 0; while (byteBuf.getByte(index + len) != 0) { len++; } database = new byte[len]; byteBuf.getBytes(index, database, 0, len); index += len; index++; }
From source file:com.talent.mysql.packet.response.HandshakePacket.java
License:Open Source License
@Override public HandshakePacket decodeBody(ByteBuf byteBuf, MysqlHeader mysqlHeader) throws DecodeException { this.setMysqlHeader(mysqlHeader); int _index = byteBuf.readerIndex(); int index = _index; protocolVersion = byteBuf.getByte(index++); int len = 0;// ww w . j a v a 2 s .c o m while (byteBuf.getByte(index + len) != 0) { len++; } versionInfo = new byte[len]; byteBuf.getBytes(index, versionInfo, 0, len); index += len; index++; threadId = byteBuf.getInt(index); index += 4; encrypt1 = new byte[8]; byteBuf.getBytes(index, encrypt1, 0, 8); index += 8; fix1 = byteBuf.getByte(index++); serverProp1 = new byte[2]; byteBuf.getBytes(index, serverProp1, 0, 2); index += 2; charset = byteBuf.getByte(index++); serverStatus = new byte[2]; byteBuf.getBytes(index, serverStatus, 0, 2); index += 2; serverProp2 = new byte[2]; byteBuf.getBytes(index, serverProp2, 0, 2); index += 2; fix2 = byteBuf.getByte(index++); // byte10 = new byte[10]; // byteBuf.getBytes(index, byte10, 0, 10); index += 10; len = 0; while (byteBuf.getByte(index + len) != 0) { len++; } encrypt2 = new byte[len]; byteBuf.getBytes(index, encrypt2, 0, len); index += len; index++; len = 0; while (byteBuf.getByte(index + len) != 0) { len++; } authPluginName = new byte[len]; byteBuf.getBytes(index, authPluginName, 0, len); index += len; index++; byteBuf.readerIndex(index); return this; }