本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}