当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.readShort方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.readShort方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.readShort方法的具体用法?Java ByteBuf.readShort怎么用?Java ByteBuf.readShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.readShort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: fromBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
	short len = buf.readShort();
	byte[] compressedBody = new byte[len];

	for (short i = 0; i < len; i++) {
		compressedBody[i] = buf.readByte();
	}

	try {
		ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
		values = (Map<String, Object>) obj.readObject();
		obj.close();
	}
	catch (Exception e) {
		Throwables.propagate(e);
	}
}
 
开发者ID:p455w0rd,项目名称:ToughExpansion,代码行数:20,代码来源:PacketConfigSync.java

示例3: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!hasHeader) {
		if (in.readableBytes() >= 7) {
			short id = in.readShort();
			int payloadLength = in.readMedium();
			short version = in.readShort();

			hasHeader = true;
			header.id = id;
			header.payload = new byte[payloadLength];
		}
	} else {
		if (in.readableBytes() >= header.payload.length) {
			in.readBytes(header.payload);
			hasHeader = false;

			crypto.decryptPacket(header);

			ClientMessage message = processPacket();
			if (message != null) {
				out.add(message);
			}
		}
	}
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:27,代码来源:PacketDecoder.java

示例4: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	try {
		//LibraLog.info("decode is bytebuf in is :" + JsonUtil.ObjectToJsonString(in.array()));
		// 空的buf
		if (in instanceof EmptyByteBuf || in.readableBytes() < 0) {
			return;
		}
		short length = in.readShort();
		if (length != in.readableBytes()) {
			return;
		}
		// 反序列化
		LibraMessage message = LibraMessage.decode(in);
		if (message == null) {
			return;
		}
		out.add(message);
	} catch (Exception e) {
		e.printStackTrace();
		return;
	}
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:24,代码来源:LibraDecoder.java

示例5: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    ByteBuf buf = (ByteBuf) msg;
    int curCount = buf.readShort();

    if (curCount == -1) {
        scheduleSrv.schedule(new Runnable() {
            @Override
            public void run() {
                ctx.close();
            }
        }, 3, TimeUnit.SECONDS);
    } else {
        int idx = curCount - 1;
        long time = buf.readInt();
        if (rtts[idx] != -1) {
            log.error("???");
        }
        //log.info("rcv count {} {}", curCount, System.currentTimeMillis());
        rtts[idx] = (int) (System.currentTimeMillis() - startTime - time);

        log.info("rtt {}: {}", curCount, rtts[idx]);
    }

    buf.release();
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:27,代码来源:KcpRttClientHandler.java

示例6: fromBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
	short len = buf.readShort();
	byte[] compressedBody = new byte[len];

	for (short i = 0; i < len; i++) {
		compressedBody[i] = buf.readByte();
	}

	try {
		ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
		registry = (Map<Integer, UUID>) obj.readObject();
		obj.close();
	}
	catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:p455w0rd,项目名称:EndermanEvolution,代码行数:20,代码来源:PacketFriendermanRegistrySync.java

示例7: 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

示例8: read

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
    entityId = readVarInt( buf );
    deltaX = buf.readShort();
    deltaY = buf.readShort();
    deltaZ = buf.readShort();
    yaw = buf.readFloat();
    pitch = buf.readFloat();
    onGround = buf.readBoolean();
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:11,代码来源:MessageS27EntityRelMoveLook.java

示例9: parseFrame

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void parseFrame(ByteBuf buffer, List<Object> out) throws Exception {
    buffer.markReaderIndex();
    if (buffer.readableBytes() > FRAME_SIZE_WITHOUT_PAYLOAD) {
        byte type = buffer.readByte();
        int channel = buffer.readShort();
        long payloadSize = buffer.readInt();

        long estimatedRemainingSize = payloadSize + 1;
        if (buffer.readableBytes() < estimatedRemainingSize) {
            buffer.resetReaderIndex();
            return;
        }

        GeneralFrame frame = null;
        switch (type) {
            case 1: // Method
                short amqpClass = buffer.readShort();
                short amqpMethod = buffer.readShort();
                AmqMethodBodyFactory factory = methodRegistry.getFactory(amqpClass, amqpMethod);

                frame = factory.newInstance(buffer, channel, payloadSize);
                break;
            case 2: // Header
                frame = HeaderFrame.parse(buffer, channel);
                break;
            case 3: // Body
                frame = ContentFrame.parse(buffer, channel, payloadSize);
                break;
            case 4: // Heartbeat
                throw new Exception("Method Not implemented");
        }

        byte frameEnd = buffer.readByte();
        if (frameEnd != (byte) GeneralFrame.FRAME_END) {
            throw new Exception("Invalid AMQP frame");
        }

        out.add(frame);
    }
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:41,代码来源:AmqpDecoder.java

示例10: fromBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void fromBytes(ByteBuf buf) {

	type = EnumParticleTypes.values()[buf.readShort()];
	x = buf.readDouble();
	y = buf.readDouble();
	z = buf.readDouble();
	loopSize = buf.readInt();
}
 
开发者ID:bafomdad,项目名称:uniquecrops,代码行数:10,代码来源:PacketUCEffect.java

示例11: fromBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
void fromBytes(ByteBuf bytes)
{
    dimensionId = bytes.readInt();
    byte[] data = new byte[bytes.readShort()];
    bytes.readBytes(data);
    providerId = new String(data, Charsets.UTF_8);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:9,代码来源:ForgeMessage.java

示例12: channelRead0

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FrameMajor msg) throws Exception {
    FrameMajorHeader head = msg.getHead();
    ByteBuf byteBuf = msg.getData();
    while (byteBuf.readableBytes() >= FrameSetting.SUB_FRAME_HEAD_LENGTH) {
        int subMsgId = byteBuf.readByte() & 0xFF;
        byte[] data = new byte[byteBuf.readShort()];
        byteBuf.readBytes(data);
        server.decodeAndHuntMessage(head, subMsgId, data, ctx.channel());
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:12,代码来源:ParsedMessageInBoundHandler.java

示例13: read

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
    protocolVersion = readVarInt( buf );
    serverAddress = readString( buf );
    port = buf.readShort();
    nextState = readVarInt( buf );
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:8,代码来源:MessageC00HandHake.java

示例14: decodeError

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private Tpdu decodeError(ByteBuf userData, List<Parameter> parameters) {
    Tpdu tpdu;
    short destinationReference = userData.readShort();
    RejectCause rejectCause = RejectCause.valueOf(userData.readByte());
    tpdu = new ErrorTpdu(destinationReference, rejectCause, parameters, userData);
    return tpdu;
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:8,代码来源:IsoTPProtocol.java

示例15: read

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void read( ByteBuf buf ) throws IOException {
    entityId = readVarInt( buf );
    deltaX = buf.readShort();
    deltaY = buf.readShort();
    deltaZ = buf.readShort();
    onGround = buf.readBoolean();
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:9,代码来源:MessageS26EntityRelMove.java


注:本文中的io.netty.buffer.ByteBuf.readShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。