當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf.getInt方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf.getInt方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.getInt方法的具體用法?Java ByteBuf.getInt怎麽用?Java ByteBuf.getInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.getInt方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUpdate

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Test
public void testUpdate() throws Exception {
  serverDenseIntRow = new ServerDenseIntRow(rowId, startCol, endCol);
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeInt(-1);
  int newValue0 = buf.getInt(0) + serverDenseIntRow.getData().get(0);
  int newValue1 = buf.getInt(4) + serverDenseIntRow.getData().get(1);
  serverDenseIntRow.update(RowType.T_INT_DENSE, buf, 3);
  assertEquals(serverDenseIntRow.getData().get(0), newValue0, 0.000);
  assertEquals(serverDenseIntRow.getData().get(1), newValue1, 0.000);
  assertEquals(serverDenseIntRow.getData().get(2), -1, 0.000);

  serverDenseIntRow = new ServerDenseIntRow(rowId, startCol, endCol);
  buf = Unpooled.buffer(0);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeInt(2);
  buf.writeInt(-2);
  serverDenseIntRow.update(RowType.T_INT_SPARSE, buf, 2);
  assertEquals(serverDenseIntRow.getData().get(0), 1, 0.000);
  assertEquals(serverDenseIntRow.getData().get(1), 0, 0.000);
  assertEquals(serverDenseIntRow.getData().get(2), -2, 0.000);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:26,代碼來源:ServerDenseIntRowTest.java

示例2: channelRead

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Transports.assertTransportThread();
    if (!(msg instanceof ByteBuf)) {
        ctx.fireChannelRead(msg);
        return;
    }
    final ByteBuf buffer = (ByteBuf) msg;
    final int remainingMessageSize = buffer.getInt(buffer.readerIndex() - TcpHeader.MESSAGE_LENGTH_SIZE);
    final int expectedReaderIndex = buffer.readerIndex() + remainingMessageSize;
    try {
        InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
        // netty always copies a buffer, either in NioWorker in its read handler, where it copies to a fresh
        // buffer, or in the cumulative buffer, which is cleaned each time so it could be bigger than the actual size
        BytesReference reference = Netty4Utils.toBytesReference(buffer, remainingMessageSize);
        transport.messageReceived(reference, ctx.channel(), profileName, remoteAddress, remainingMessageSize);
    } finally {
        // Set the expected position of the buffer, no matter what happened
        buffer.readerIndex(expectedReaderIndex);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:Netty4MessageChannelHandler.java

示例3: decipherXTEA

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Deciphers the specified {@link ByteBuf} with the given key.
 * 
 * @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);
	}
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:26,代碼來源:ByteBufUtils.java

示例4: metadata

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static ByteBuf metadata(ByteBuf byteBuf) {
  int offset = VERSION_SIZE + NAMESPACE_ID_SIZE + SERVICE_ID_SIZE + METHOD_ID_SIZE;
  int length = byteBuf.getInt(offset);
  offset += METADATA_LENGTH_SIZE;

  return byteBuf.slice(offset, length);
}
 
開發者ID:netifi,項目名稱:proteus-java,代碼行數:8,代碼來源:ProteusMetadata.java

示例5: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // Check if we have enough bytes in the buffer.
    if (in.readableBytes() < HEADER_LENGTH) {
        // Retry once we have more data.
        return;
    }

    int startIndex = in.readerIndex();

    // Peek length header (note that we are not updating the buffer's read index).
    int length = in.getInt(startIndex);

    // Magic length value:
    //   negative - for internal messages
    //   positive - for user messages
    boolean internalMsg = length < 0;

    // Make sure that length is always positive.
    if (internalMsg) {
        length = -length;
    }

    // Check if we have enough bytes to decode.
    if (in.readableBytes() < length) {
        // Retry once we have more data.
        return;
    }

    // Skip the length header (we already have it).
    in.skipBytes(HEADER_LENGTH);

    // Decode message.
    int msgOffset = startIndex + HEADER_LENGTH;
    int msgLength = length - HEADER_LENGTH;

    Object msg;

    if (internalMsg) {
        // Decode internal message.
        msg = decodeInternal(in, msgOffset, msgLength);
    } else {
        // Decode user-defined message.
        msg = decodeUser(in, msgOffset, msgLength);
    }

    // Advance buffer's read position.
    in.readerIndex(startIndex + length);

    if (msg != null) {
        out.add(msg);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:54,代碼來源:NetworkProtocolCodec.java

示例6: namespaceId

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int namespaceId(ByteBuf byteBuf) {
  int offset = VERSION_SIZE;
  return byteBuf.getInt(offset);
}
 
開發者ID:netifi,項目名稱:proteus-java,代碼行數:5,代碼來源:ProteusMetadata.java

示例7: serviceId

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int serviceId(ByteBuf byteBuf) {
  int offset = VERSION_SIZE + NAMESPACE_ID_SIZE;
  return byteBuf.getInt(offset);
}
 
開發者ID:netifi,項目名稱:proteus-java,代碼行數:5,代碼來源:ProteusMetadata.java

示例8: methodId

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int methodId(ByteBuf byteBuf) {
  int offset = VERSION_SIZE + NAMESPACE_ID_SIZE + SERVICE_ID_SIZE;
  return byteBuf.getInt(offset);
}
 
開發者ID:netifi,項目名稱:proteus-java,代碼行數:5,代碼來源:ProteusMetadata.java

示例9: fromBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Convert from the supplied buffer into your specific message type
 *
 * @param buf
 */
@Override
public void fromBytes(ByteBuf buf) {
    int lengh = buf.getInt(0);
    key = buf.getCharSequence(1, lengh, StandardCharsets.UTF_8).toString();
}
 
開發者ID:MinecraftPangu,項目名稱:Pangu,代碼行數:11,代碼來源:KeyMessage.java

示例10: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  while (true) {
    if (in.readableBytes() < 5) {
      break;
    }
    int beginIdx = in.readerIndex();
    byte id = in.getByte(beginIdx);
    int length = in.getInt(beginIdx + 1);
    int endIdx = beginIdx + length + 1;
    final int writerIndex = in.writerIndex();
    if (writerIndex < endIdx) {
      break;
    }
    try {
      in.setIndex(beginIdx + 5, endIdx);
      switch (id) {
        case READY_FOR_QUERY: {
          decodeReadyForQuery(in, out);
          break;
        }
        case DATA_ROW: {
          decodeDataRow(in);
          break;
        }
        case COMMAND_COMPLETE: {
          decodeCommandComplete(in, out);
          break;
        }
        case BIND_COMPLETE: {
          decodeBindComplete(out);
          break;
        }
        default: {
          decodeMessage(id, in ,out);
        }
      }
    } finally {
      in.setIndex(endIdx, writerIndex);
    }
  }
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:43,代碼來源:MessageDecoder.java


注:本文中的io.netty.buffer.ByteBuf.getInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。