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


Java ByteBuf.readByte方法代碼示例

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


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

示例1: readVarInt

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int readVarInt(ByteBuf buf, int maxSize) {
	Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize);
	int i = 0;
	int j = 0;
	byte b0;

	do {
		b0 = buf.readByte();
		i |= (b0 & 127) << j++ * 7;

		if (j > maxSize) {
			throw new RuntimeException("VarInt too big");
		}
	}
	while ((b0 & 128) == 128);

	return i;
}
 
開發者ID:NickAcPT,項目名稱:Lithium-Forge,代碼行數:19,代碼來源:NativeUtils.java

示例2: decodeHeaders

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private static Map<String, String> decodeHeaders(int expectedHeadersType, ByteBuf messageHeader)
{
    if (messageHeader.readableBytes() == 0) {
        return ImmutableMap.of();
    }

    byte headersType = messageHeader.readByte();
    if (headersType != expectedHeadersType) {
        return ImmutableMap.of();
    }

    ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
    int headerCount = readVarint(messageHeader);
    for (int i = 0; i < headerCount; i++) {
        String key = readString(messageHeader);
        String value = readString(messageHeader);
        headers.put(key, value);
    }
    return headers.build();
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:21,代碼來源:HeaderMessageEncoding.java

示例3: readVarInt

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private static int readVarInt(ByteBuf buf, int maxSize) {
	Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize);
	int i = 0;
	int j = 0;
	byte b0;

	do {
		b0 = buf.readByte();
		i |= (b0 & 127) << j++ * 7;

		if (j > maxSize) {
			throw new RuntimeException("VarInt too big");
		}
	}
	while ((b0 & 128) == 128);

	return i;
}
 
開發者ID:NickAcPT,項目名稱:Lithium-Spigot,代碼行數:19,代碼來源:LithiumUtils.java

示例4: channelRead0

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
    while (true) {
        if (byteBuf.readableBytes() < FrameSetting.FRAME_HEAD_LENGTH) {
            return;
        }
        if (byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_1
                || byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_2) {
            return;
        }
        int groupId = byteBuf.readByte() & 0xFF;
        int msgId = byteBuf.readByte() & 0xFF;
        int deviceId = byteBuf.readByte() & 0xFF;
        int backupMsg = byteBuf.readByte() & 0xFF;
        int dataLength = byteBuf.readShort() & 0xFF;
        FrameMajorHeader headMsg = new FrameMajorHeader(msgId, groupId, deviceId, dataLength, backupMsg);
        ByteBuf subBuf = ctx.alloc().buffer(dataLength);
        byteBuf.readBytes(subBuf, dataLength);
        ctx.fireChannelRead(new FrameMajor(headMsg, subBuf));
    }
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:22,代碼來源:FrameRecognitionInBoundHandler.java

示例5: readBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public ByteBuf readBytes(ByteBuf is) throws IOException {
    long l = readLong(is);
    if (l > Integer.MAX_VALUE) {
        throw new IllegalArgumentException(
                "Java only supports arrays up to " + Integer.MAX_VALUE + " in size");
    }
    int size = (int) l;
    if (size == -1) {
        return null;
    }
    ByteBuf buffer = is.readSlice(size);
    int cr = is.readByte();
    int lf = is.readByte();
    if (cr != CR || lf != LF) {
        throw new IOException("Improper line ending: " + cr + ", " + lf);
    }
    return buffer;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:19,代碼來源:CommandDecoder.java

示例6: onRawPacketSending

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void onRawPacketSending(RawPacketEvent event) {
	super.onRawPacketSending(event);

	ByteBuf data = event.getData();
	int packetId = VarNumberSerializer.readVarInt(data);

	if (packetId != PEPacketIDs.SPAWN_PLAYER)
		return;

	data.readByte();
	data.readByte();

	MiscSerializer.readUUID(data);
	String name = StringSerializer.readString(data, con.getVersion());
	long entityId = VarNumberSerializer.readSVarLong(data);

	cachedUsers.put(name, (int) entityId);
}
 
開發者ID:ProtocolSupport,項目名稱:ProtocolSupportPocketStuff,代碼行數:20,代碼來源:TeamsPacketListener.java

示例7: encodeCallingParameter

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Test
@Tag("fast")
public void encodeCallingParameter() throws Exception {
    ChannelHandlerContext ctx = new MockChannelHandlerContext();
    ByteBuf buf = Unpooled.buffer();
    ArrayList<Parameter> parmameters = new ArrayList<>();
    CallingTsapParameter callingParameter = new CallingTsapParameter(DeviceGroup.PG_OR_PC, (byte) 0x7, (byte) 0xe1); // slot number too big and overflows into rack
    parmameters.add(callingParameter);
    ErrorTpdu tpdu = new ErrorTpdu((short)0x1, RejectCause.REASON_NOT_SPECIFIED, parmameters, buf);
    ArrayList<Object> out = new ArrayList<>();

    isoTPProtocol.encode(ctx, tpdu, out);

    assertTrue(out.size() == 1, "Message not decoded");

    ByteBuf userData = ((IsoOnTcpMessage)out.get(0)).getUserData();

    assertTrue(userData.writerIndex() == 9, "Incorrect message length");
    assertTrue(userData.readByte() == (byte)0x8, "Incorrect header length");
    assertTrue(userData.readByte() == TpduCode.TPDU_ERROR.getCode(), "Incorrect Tpdu code");
    assertTrue(userData.readShort() == (short)0x1, "Incorrect destination reference code");
    assertTrue(userData.readByte() == RejectCause.REASON_NOT_SPECIFIED.getCode(), "Incorrect reject cause code");
    assertTrue(userData.readByte() == ParameterCode.CALLING_TSAP.getCode(), "Incorrect parameter code");
    assertTrue(userData.readByte() == (byte)0x2, "Incorrect parameter length");
    assertTrue(userData.readByte() == DeviceGroup.PG_OR_PC.getCode(), "Incorrect device group code");
    byte rackAndSlot = userData.readByte();
    assertTrue((rackAndSlot & 0xf0) >> 4 == 0x7, "Incorrect rack number");
    assertTrue((rackAndSlot & 0x0f) == (0xe1 & 0x0f), "Incorrect slot number");
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:30,代碼來源:IsoTPProtocolTest.java

示例8: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Decodes the machine information of the user during the {@link WorldLoginDecoder}.
 * 
 * @param buffer The {@link ByteBuf}.
 * @return The created machine information.
 */
public static MachineInformation decode(ByteBuf buffer) {
	buffer.readByte();
	int osArch = buffer.readByte();
	boolean is64Bit = buffer.readByte() == 1;
	int osBuild = buffer.readByte();
	int vendor = buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readByte();
	buffer.readShort();
	buffer.readByte();
	buffer.readMedium();
	buffer.readShort();
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	buffer.readByte();
	buffer.readShort();
	ByteBufUtils.readJagString(buffer);
	ByteBufUtils.readJagString(buffer);
	buffer.readByte();
	buffer.readByte();
	return new MachineInformation(osArch, is64Bit, osBuild, vendor);
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:33,代碼來源:MachineInformation.java

示例9: fromBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void fromBytes(ByteBuf buf)
{
    player = buf.readInt();
    where = ContainingInventory.VALUES[buf.readByte()];
    slot = buf.readByte();
    stack = ByteBufUtils.readItemStack(buf);
}
 
開發者ID:gigaherz,項目名稱:ToolBelt,代碼行數:9,代碼來源:BeltContentsChange.java

示例10: fromBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void fromBytes(ByteBuf buf) {
    selectedBlock = BlockPos.fromLong(buf.readLong());
    selectedSide = EnumFacing.VALUES[buf.readByte()];
    destination = new TeleportDestination(NetworkTools.readStringUTF8(buf), buf.readInt(), BlockPos.fromLong(buf.readLong()),
            EnumFacing.VALUES[buf.readByte()]);
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:8,代碼來源:PacketMakePortals.java

示例11: readLine

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private String readLine(ByteBuf in) {
    while (in.isReadable()) {
        byte b = in.readByte();
        byteBuf.writeByte(b);
        lineBuf.append((char) b);
        int len = lineBuf.length();
        if (len >= 2 && lineBuf.substring(len - 2).equals("\r\n")) {
            String line = lineBuf.substring(0, len - 2);
            lineBuf.delete(0, len);
            return line;
        }
    }
    return null;
}
 
開發者ID:shuaicj,項目名稱:http-proxy-netty,代碼行數:15,代碼來源:HttpProxyClientHeader.java

示例12: readFromBuf

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static AnimaStack readFromBuf(ByteBuf from)
{
	int count = from.readByte();
	int id = from.readShort();
	if (count < 0)
	{
		return AnimaStack.EMPTY;
	} else
	{

		AnimaStack stack = new AnimaStack(Anima.getAnimaByID(id), count);

		return stack;
	}
}
 
開發者ID:raphydaphy,項目名稱:ArcaneMagic,代碼行數:16,代碼來源:AnimaStack.java

示例13: readField

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static Object readField(ByteBuf buf, int type) {
    switch (type) {
        case 0:
            return buf.readInt();
        case 1:
            return buf.readFloat();
        case 2:
            return buf.readDouble();
        case 3:
            return buf.readBoolean();
        case 4:
            return ByteBufUtils.readUTF8String(buf);
        case 5:
            return buf.readByte();
        case 6:
            return ByteBufUtils.readItemStack(buf);
        case 7:
            if (!buf.readBoolean()) return null;
            return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
        case 8:
            try {
                PacketBuffer packetBuffer = new PacketBuffer(buf);
                NBTTagCompound tag = packetBuffer.readCompoundTag();
                if (tag == null) return EmptyHandler.INSTANCE;
                ItemStackHandler handler = new ItemStackHandler();
                handler.deserializeNBT(tag);
                return handler;
            } catch (IOException e) {
                return EmptyHandler.INSTANCE;
            }
    }
    throw new IllegalArgumentException("Invalid sync type! " + type);
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:34,代碼來源:PacketUpdateGui.java

示例14: parseBooleanValue

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Parse Single-point information with quality descriptor
 *
 * @param withTimestamp
 *            <code>true</code> if the time should be parsed as well,
 *            <code>false</code> otherwise
 */
public static Value<Boolean> parseBooleanValue ( final ProtocolOptions options, final ByteBuf data, final boolean withTimestamp )
{
    final byte siq = data.readByte ();

    final Boolean value = ( siq & 0x01 ) > 0 ? Boolean.TRUE : Boolean.FALSE; // we need to use a boolean object due to the following generic object
    final QualityInformation qualityInformation = QualityInformation.parse ( siq );

    final long timestamp = withTimestamp ? parseTimestamp ( options, data ) : System.currentTimeMillis ();

    return new Value<Boolean> ( value, timestamp, qualityInformation );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:TypeHelper.java

示例15: readString

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * Converts data from a {@link ByteBuf} into a readable string.
 *
 * @param buffer The {@link ByteBuf}.
 * @return The string.
 */
public static String readString(ByteBuf buffer) {
	StringBuilder bldr = new StringBuilder();
	byte b;
	while (buffer.isReadable() && (b = buffer.readByte()) != STRING_TERMINATOR) {
		bldr.append((char) b);
	}
	return bldr.toString();
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:15,代碼來源:ByteBufUtils.java


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