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


Java ByteBuf.readUnsignedShort方法代码示例

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


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

示例1: decodeRowDescription

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private Column[]  decodeRowDescription(ByteBuf in) {
  Column[] columns = new Column[in.readUnsignedShort()];
  for (int c = 0; c < columns.length; ++c) {
    String fieldName = Util.readCStringUTF8(in);
    int tableOID = in.readInt();
    short columnAttributeNumber = in.readShort();
    int typeOID = in.readInt();
    short typeSize = in.readShort();
    int typeModifier = in.readInt();
    int textOrBinary = in.readUnsignedShort(); // Useless for now
    Column column = new Column(
      fieldName,
      tableOID,
      columnAttributeNumber,
      DataType.valueOf(typeOID),
      typeSize,
      typeModifier,
      DataFormat.valueOf(textOrBinary)
    );
    columns[c] = column;
  }
  return columns;
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:24,代码来源:MessageDecoder.java

示例2: readString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String readString(ByteBuf cb)
{
    try
    {
        int length = cb.readUnsignedShort();
        return readString(cb, length);
    }
    catch (IndexOutOfBoundsException e)
    {
        throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by its 2 bytes length");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:13,代码来源:CBUtil.java

示例3: readBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static byte[] readBytes(ByteBuf cb)
{
    try
    {
        int length = cb.readUnsignedShort();
        byte[] bytes = new byte[length];
        cb.readBytes(bytes);
        return bytes;
    }
    catch (IndexOutOfBoundsException e)
    {
        throw new ProtocolException("Not enough bytes to read a byte array preceded by its 2 bytes length");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:15,代码来源:CBUtil.java

示例4: readBytesMap

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static Map<String, ByteBuffer> readBytesMap(ByteBuf cb)
{
    int length = cb.readUnsignedShort();
    Map<String, ByteBuffer> m = new HashMap<>(length);
    for (int i = 0; i < length; i++)
    {
        String k = readString(cb);
        ByteBuffer v = readValue(cb);
        m.put(k, v);
    }
    return m;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:13,代码来源:CBUtil.java

示例5: readStringList

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static List<String> readStringList(ByteBuf cb)
{
    int length = cb.readUnsignedShort();
    List<String> l = new ArrayList<String>(length);
    for (int i = 0; i < length; i++)
        l.add(readString(cb));
    return l;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:9,代码来源:CBUtil.java

示例6: readVarShort

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * An extended length short. Used by custom payload packets to extend size.
 *
 * @param buf
 * @return
 */
public static int readVarShort(ByteBuf buf)
{
    int low = buf.readUnsignedShort();
    int high = 0;
    if ((low & 0x8000) != 0)
    {
        low = low & 0x7FFF;
        high = buf.readUnsignedByte();
    }
    return ((high & 0xFF) << 15) | low;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:18,代码来源:ByteBufUtils.java

示例7: readValueList

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static List<ByteBuffer> readValueList(ByteBuf cb, ProtocolVersion protocolVersion)
{
    int size = cb.readUnsignedShort();
    if (size == 0)
        return Collections.<ByteBuffer>emptyList();

    List<ByteBuffer> l = new ArrayList<ByteBuffer>(size);
    for (int i = 0; i < size; i++)
        l.add(readBoundValue(cb, protocolVersion));
    return l;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:12,代码来源:CBUtil.java

示例8: readNameAndValueList

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static Pair<List<String>, List<ByteBuffer>> readNameAndValueList(ByteBuf cb, ProtocolVersion protocolVersion)
{
    int size = cb.readUnsignedShort();
    if (size == 0)
        return Pair.create(Collections.<String>emptyList(), Collections.<ByteBuffer>emptyList());

    List<String> s = new ArrayList<>(size);
    List<ByteBuffer> l = new ArrayList<>(size);
    for (int i = 0; i < size; i++)
    {
        s.add(readString(cb));
        l.add(readBoundValue(cb, protocolVersion));
    }
    return Pair.create(s, l);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:16,代码来源:CBUtil.java

示例9: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!in.isReadable() || !player.getChannel().isRegistered()) {
		return;
	}
	int opcode = in.readUnsignedByte();
	Optional<PacketDecoderIdentifier> data = PacketDecoderIdentifier.getPacket(opcode);
	if (data.isPresent()) {
		PacketDecoderIdentifier packet = data.get();

		int size = packet.getSize();
		if (packet.getType() == PacketType.VARIABLE_BYTE) {
			if (in.readableBytes() < 1) {
				return;
			}
			size = in.readUnsignedByte();
		} else if (packet.getType() == PacketType.VARIABLE_SHORT) {
			if (in.readableBytes() < 2) {
				return;
			}
			size = in.readUnsignedShort();
		}

		if (in.readableBytes() >= size) {
			if (size < 0) {
				return;
			}

			byte[] bytes = new byte[size];
			in.readBytes(bytes, 0, size);
			out.add(new GamePacketRequest(this, player, packet.getId(), new GamePacketReader(Unpooled.wrappedBuffer(bytes))));
		}

	} else {
		System.out.println("No data present for incoming packet: " + opcode + ".");
		in.readBytes(new byte[in.readableBytes()]);
	}
}
 
开发者ID:jordanabrahambaws,项目名称:Quavo,代码行数:39,代码来源:GamePacketDecoder.java

示例10: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!in.isReadable() || in.readableBytes() < 4) {
		return;
	}

	Optional<UpdateType> request = UpdateType.getType(in.readUnsignedByte());
	if (request.isPresent()) {
		UpdateType updateType = request.get();
		switch (updateType) {
		case LOW_PRIORITY_UPDATE:
		case HIGH_PRIORITY_UPDATE:
			int uid = in.readUnsignedMedium();
			int type = (uid >> 16);
			int id = (uid & 0xffff);

			out.add(new UpdateRequest(this, type, id, updateType == UpdateType.HIGH_PRIORITY_UPDATE));
			break;
		case XOR_ENCRYPTION_UPDATE:
			int key = in.readUnsignedByte();
			in.readUnsignedShort();
			out.add(new XOREncryptionRequest(this, key));
			break;
		}
	} else {
		in.readUnsignedMedium();
	}
}
 
开发者ID:jordanabrahambaws,项目名称:Quavo,代码行数:29,代码来源:UpdateDecoder.java

示例11: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    LOGGER.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;
                case 1:

                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;
                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:81,代码来源:LegacyPingHandler.java

示例12: readUnsignedShort

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public int readUnsignedShort(ByteBuf source) {
  return source.readUnsignedShort();
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:5,代码来源:ByteBufCodec.java

示例13: parse

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static HeaderFrame parse(ByteBuf buf, int channel) throws Exception {
    int classId = buf.readUnsignedShort();
    // ignore weight
    buf.skipBytes(2);
    long bodySize = buf.readLong();
    HeaderFrame headerFrame = new HeaderFrame(channel, classId, bodySize);

    int propertyFlags = buf.readUnsignedShort();

    // Skip other property flags if exists
    boolean hasMoreProperties = (propertyFlags & LAST_BIT_MASK) != 0;
    while (hasMoreProperties) {
        int otherPropertyFlags = buf.readUnsignedShort();
        hasMoreProperties = (otherPropertyFlags & LAST_BIT_MASK) != 0;
    }

    // read known properties
    if ((propertyFlags & CONTENT_TYPE_MASK) != 0) {
        headerFrame.setContentType(ShortString.parse(buf));
    }

    if ((propertyFlags & ENCODING_MASK) != 0) {
        headerFrame.setContentEncoding(ShortString.parse(buf));
    }

    if ((propertyFlags & HEADERS_MASK) != 0) {
        headerFrame.setHeaders(FieldTable.parse(buf));
    }

    if ((propertyFlags & DELIVERY_MODE_MASK) != 0) {
        headerFrame.setDeliveryMode(buf.readUnsignedByte());
    }

    if ((propertyFlags & PRIORITY_MASK) != 0) {
        headerFrame.setPriority(buf.readUnsignedByte());
    }

    if ((propertyFlags & CORRELATION_ID_MASK) != 0) {
        headerFrame.setCorrelationId(ShortString.parse(buf));
    }

    if ((propertyFlags & REPLY_TO_MASK) != 0) {
        headerFrame.setReplyTo(ShortString.parse(buf));
    }

    if ((propertyFlags & EXPIRATION_MASK) != 0) {
        headerFrame.setExpiration(ShortString.parse(buf));
    }

    if ((propertyFlags & MESSAGE_ID_MASK) != 0) {
        headerFrame.setMessageId(ShortString.parse(buf));
    }

    if ((propertyFlags & TIMESTAMP_MASK) != 0) {
        headerFrame.setTimestamp(buf.readLong());
    }

    if ((propertyFlags & TYPE_MASK) != 0) {
        headerFrame.setType(ShortString.parse(buf));
    }

    if ((propertyFlags & USER_ID_MASK) != 0) {
        headerFrame.setUserId(ShortString.parse(buf));
    }

    if ((propertyFlags & APPLICATION_ID_MASK) != 0) {
        headerFrame.setAppId(ShortString.parse(buf));
    }

    headerFrame.properties.add(PROPERTY_FLAGS, FieldValue.parseLongInt(propertyFlags));
    return headerFrame;
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:73,代码来源:HeaderFrame.java

示例14: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    logger.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:82,代码来源:PingResponseHandler.java

示例15: decodeMessageV0

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
protected void decodeMessageV0(ClusterMessage hdr, ByteBuf in) {
    in.skipBytes(2);
    hdr.type = in.readUnsignedShort();
    hdr.count = in.readUnsignedShort();
    hdr.currentEpoch = in.readLong();
    hdr.configEpoch = in.readLong();
    hdr.offset = in.readLong();
    hdr.name = truncate(in, CLUSTER_NODE_NULL_NAME);
    in.readBytes(hdr.slots);
    hdr.master = truncate(in, CLUSTER_NODE_NULL_NAME);
    in.skipBytes(32);
    hdr.ip = null;
    hdr.port = in.readUnsignedShort();
    hdr.busPort = hdr.port + CLUSTER_PORT_INCR;
    hdr.flags = in.readUnsignedShort();
    hdr.state = valueOf(in.readByte());
    in.readBytes(hdr.messageFlags);
    switch (hdr.type) {
        case CLUSTERMSG_TYPE_PING:
        case CLUSTERMSG_TYPE_PONG:
        case CLUSTERMSG_TYPE_MEET:
            for (int i = 0; i < hdr.count; i++) {
                ClusterMessageDataGossip gossip = new ClusterMessageDataGossip();
                gossip.name = truncate(in, CLUSTER_NODE_NULL_NAME);
                gossip.pingTime = in.readInt() * 1000L;
                gossip.pongTime = in.readInt() * 1000L;
                gossip.ip = truncate(in, CLUSTER_NODE_NULL_IP);
                gossip.port = in.readUnsignedShort();
                gossip.busPort = gossip.port + CLUSTER_PORT_INCR;
                gossip.flags = in.readUnsignedShort();
                in.skipBytes(2);
                in.skipBytes(4);
                hdr.data.gossips.add(gossip);
            }
            break;
        case CLUSTERMSG_TYPE_FAIL:
            hdr.data.fail.name = truncate(in, CLUSTER_NODE_NULL_NAME);
            break;
        case CLUSTERMSG_TYPE_PUBLISH:
            hdr.data.publish.channelLength = in.readInt();
            hdr.data.publish.messageLength = in.readInt();
            in.readBytes(hdr.data.publish.bulkData);
            break;
        case CLUSTERMSG_TYPE_UPDATE:
            hdr.data.config.configEpoch = in.readLong();
            hdr.data.config.name = truncate(in, CLUSTER_NODE_NULL_NAME);
            in.readBytes(hdr.data.config.slots);
            break;
        default:
            break;
    }
}
 
开发者ID:leonchen83,项目名称:redis-cluster-watchdog,代码行数:53,代码来源:ClusterMessageDecoder.java


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