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


Java ByteBuf.setByte方法代碼示例

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


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

示例1: openWrittenBook

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Open the given written book
 *
 * @param book Written book
 * @param player Player
 */
public static void openWrittenBook(ItemStack book, Player player)
{
    if (book.getType() != Material.WRITTEN_BOOK)
        return;

    ItemStack previous = player.getInventory().getItemInHand();
    player.getInventory().setItemInHand(book);

    ByteBuf buffer = Unpooled.buffer(256);
    buffer.setByte(0, (byte) 1);
    buffer.writerIndex(1);

    Reflection.sendPacket(player, new PacketPlayOutCustomPayload("MC|BOpen", new PacketDataSerializer(buffer)));

    player.getInventory().setItemInHand(previous);
}
 
開發者ID:SamaGames,項目名稱:SamaGamesAPI,代碼行數:23,代碼來源:ItemUtils.java

示例2: parseBinaryString

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * In-place parsing of a hex encoded binary string.
 *
 * This function does not modify  the {@code readerIndex} and {@code writerIndex}
 * of the byte buffer.
 *
 * @return Index in the byte buffer just after the last written byte.
 */
public static int parseBinaryString(ByteBuf str, int strStart, int strEnd) {
  int length = (strEnd - strStart);
  int dstEnd = strStart;
  for (int i = strStart; i < length ; i++) {
    byte b = str.getByte(i);
    if (b == '\\'
        && length > i+3
        && (str.getByte(i+1) == 'x' || str.getByte(i+1) == 'X')) {
      // ok, take next 2 hex digits.
      byte hd1 = str.getByte(i+2);
      byte hd2 = str.getByte(i+3);
      if (isHexDigit(hd1) && isHexDigit(hd2)) { // [a-fA-F0-9]
        // turn hex ASCII digit -> number
        b = (byte) ((toBinaryFromHex(hd1) << 4) + toBinaryFromHex(hd2));
        i += 3; // skip 3
      }
    }
    str.setByte(dstEnd++, b);
  }
  return dstEnd;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:30,代碼來源:DrillStringUtils.java

示例3: encrypt

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void encrypt(ByteBuf buf)
{
	if (!_isEnabled)
	{
		_isEnabled = true;
		onPacketSent(buf);
		return;
	}
	
	onPacketSent(buf);
	
	int a = 0;
	while (buf.isReadable())
	{
		final int b = buf.readByte() & 0xFF;
		a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
		buf.setByte(buf.readerIndex() - 1, a);
	}
	
	shiftKey(_outKey, buf.writerIndex());
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:23,代碼來源:Crypt.java

示例4: decrypt

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void decrypt(ByteBuf buf)
{
	if (!_isEnabled)
	{
		onPacketReceive(buf);
		return;
	}
	
	int a = 0;
	while (buf.isReadable())
	{
		final int b = buf.readByte() & 0xFF;
		buf.setByte(buf.readerIndex() - 1, b ^ _inKey[(buf.readerIndex() - 1) & 15] ^ a);
		a = b;
	}
	
	shiftKey(_inKey, buf.writerIndex());
	
	onPacketReceive(buf);
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:22,代碼來源:Crypt.java

示例5: parseBinaryString

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Parses a hex encoded binary string and write to an output buffer.
 *
 * This function does not modify  the {@code readerIndex} and {@code writerIndex}
 * of the byte buffer.
 *
 * @return Index in the byte buffer just after the last written byte.
 */
public static int parseBinaryString(ByteBuf str, int strStart, int strEnd, ByteBuf out) {
  int dstEnd = 0;
  for (int i = strStart; i < strEnd; i++) {
    byte b = str.getByte(i);
    if (b == '\\'
        && strEnd > i+3
        && (str.getByte(i+1) == 'x' || str.getByte(i+1) == 'X')) {
      // ok, take next 2 hex digits.
      byte hd1 = str.getByte(i+2);
      byte hd2 = str.getByte(i+3);
      if (isHexDigit(hd1) && isHexDigit(hd2)) { // [a-fA-F0-9]
        // turn hex ASCII digit -> number
        b = (byte) ((toBinaryFromHex(hd1) << 4) + toBinaryFromHex(hd2));
        i += 3; // skip 3
      }
    }
    out.setByte(dstEnd++, b);
  }
  return dstEnd;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:29,代碼來源:DremioStringUtils.java

示例6: parseBinaryStringNoFormat

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int parseBinaryStringNoFormat(ByteBuf str, int strStart, int strEnd, ByteBuf out) {
  int dstEnd = 0;

  if(((strStart - strEnd) % 2) != 0){
    throw UserException.functionError().message("Failure parsing hex string, length was not a multiple of two.").build(logger);
  }
  for (int i = strStart; i < strEnd; i+=2) {
    byte b1 = str.getByte(i);
    byte b2 = str.getByte(i+1);
    if(isHexDigit(b1) && isHexDigit(b2)){
      byte finalByte = (byte) ((toBinaryFromHex(b1) << 4) + toBinaryFromHex(b2));
      out.setByte(dstEnd++, finalByte);
    }else{
      throw UserException.functionError().message("Failure parsing hex string, one or more bytes was not a valid hex value.").build(logger);
    }
  }
  return dstEnd;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:19,代碼來源:DremioStringUtils.java

示例7: encodeText

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void encodeText(Buffer value, ByteBuf buff) {
  int index = buff.writerIndex();
  buff.setByte(index + 4, '\\');
  buff.setByte(index + 5, 'x');
  // todo : optimize - no need to create an intermediate string here
  int len = buff.setCharSequence(index + 6, printHexBinary(value.getBytes()), StandardCharsets.UTF_8);
  buff.writeInt(2 + len);
  buff.writerIndex(index + 2 + len);
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:11,代碼來源:DataType.java

示例8: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, XOREncryptionResponse msg, ByteBuf out) throws Exception {
	if (msg.getKey() != 0) {
		for (int i = 0; i < out.writerIndex(); i++) {
			out.setByte(i, out.getByte(i) ^ msg.getKey());
		}
	}

	ctx.pipeline().remove(this);
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:11,代碼來源:XOREncryptionEncoder.java


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