当前位置: 首页>>代码示例>>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;未经允许,请勿转载。