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


Java ByteBuf.readUnsignedByte方法代码示例

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


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

示例1: decodeFixedHeader

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Decodes the fixed header. It's one byte for the flags and then variable bytes for the remaining length.
 *
 * @param buffer the buffer to decode from
 * @return the fixed header
 */
private static MqttFixedHeader decodeFixedHeader(ByteBuf buffer) {
    short b1 = buffer.readUnsignedByte();

    MqttMessageType messageType = MqttMessageType.valueOf(b1 >> 4);
    boolean dupFlag = (b1 & 0x08) == 0x08;
    int qosLevel = (b1 & 0x06) >> 1;
    boolean retain = (b1 & 0x01) != 0;

    int remainingLength = 0;
    int multiplier = 1;
    short digit;
    int loops = 0;
    do {
        digit = buffer.readUnsignedByte();
        remainingLength += (digit & 127) * multiplier;
        multiplier *= 128;
        loops++;
    } while ((digit & 128) != 0 && loops < 4);

    // MQTT protocol limits Remaining Length to 4 bytes
    if (loops == 4 && (digit & 128) != 0) {
        throw new DecoderException("remaining length exceeds 4 digits (" + messageType + ')');
    }
    return new MqttFixedHeader(messageType, dupFlag, MqttQoS.valueOf(qosLevel), retain, remainingLength);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:32,代码来源:MqttDecoder.java

示例2: startBodyParse

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Timed
void startBodyParse(ByteBuf in) throws UnknownFetchItemTypeException, IOException {
  skipControlCharacters(in);

  char c = ((char) in.readUnsignedByte());

  //String bodySection = ""; At some point we will need to actually store the body section that is being parsed below
  if (c != '[') {
    // This is effectively BODYSTRUCTURE which is not yet supported
    lineParser.parse(in);
    checkpoint(State.RESET);
    throw new UnknownFetchItemTypeException("BODYSTRUCTURE");
  } else {
    c = ((char) in.readUnsignedByte());
    while (c != ']') { // Skip characters within "[]"
      c = ((char) in.readUnsignedByte());
    }
  }

  checkpoint(State.FETCH_BODY);
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:22,代码来源:ResponseDecoder.java

示例3: parse

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static InterrogationCommand parse ( final ProtocolOptions options, final byte length, final ASDUHeader header, final ByteBuf data )
{
    final InformationObjectAddress informationObjectAddress = InformationObjectAddress.parse ( options, data );
    final short qualifierOfInterrogation = data.readUnsignedByte ();
    final InterrogationCommand result = new InterrogationCommand ( header, informationObjectAddress, qualifierOfInterrogation );
    return result;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:InterrogationCommand.java

示例4: reset

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Reset checks to see if we are at the end of this response line. If not it fast forwards the buffer to the end of this line to prepare for the next response.
 *
 * @param in
 */
private void reset(ByteBuf in) {
  char c = (char) in.readUnsignedByte();
  if (c == UNTAGGED_PREFIX || c == CONTINUATION_PREFIX || c == TAGGED_PREFIX) { // We are already at the end of the line
    in.readerIndex(in.readerIndex() - 1);
  } else if (!(c == HttpConstants.CR || c == HttpConstants.LF)) {
    lineParser.parse(in);
  }

  discardSomeReadBytes();
  responseBuilder = new TaggedResponse.Builder();
  checkpoint(State.START_RESPONSE);
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:18,代码来源:ResponseDecoder.java

示例5: decodeSubscribePayload

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Result<MqttSubscribePayload> decodeSubscribePayload(
        ByteBuf buffer,
        int bytesRemainingInVariablePart) {
    final List<MqttTopicSubscription> subscribeTopics = new ArrayList<>();
    int numberOfBytesConsumed = 0;
    while (numberOfBytesConsumed < bytesRemainingInVariablePart) {
        final Result<String> decodedTopic = decodeString(buffer);
        numberOfBytesConsumed += decodedTopic.numberOfBytesConsumed;
        int qos = buffer.readUnsignedByte() & 0x03;
        numberOfBytesConsumed++;
        subscribeTopics.add(new MqttTopicSubscription(decodedTopic.value, MqttQoS.valueOf(qos)));
    }
    return new Result<>(new MqttSubscribePayload(subscribeTopics), numberOfBytesConsumed);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:15,代码来源:MqttDecoder.java

示例6: decodeSubAckPayload

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Result<MqttSubAckPayload> decodeSubAckPayload(
        ByteBuf buffer,
        int bytesRemainingInVariablePart) {
    final List<MqttGrantedQoS> grantedQos = new ArrayList<>();
    int numberOfBytesConsumed = 0;
    while (numberOfBytesConsumed < bytesRemainingInVariablePart) {
        int qos = buffer.readUnsignedByte() & 0x03;
        numberOfBytesConsumed++;
        grantedQos.add(MqttGrantedQoS.valueOf(qos));
    }
    return new Result<>(new MqttSubAckPayload(grantedQos), numberOfBytesConsumed);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:13,代码来源:MqttDecoder.java

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

示例8: decodeFixedHeader

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Decodes the fixed header. It's one byte for the flags and then variable bytes for the remaining length.
 *
 * @param buffer the buffer to decode from
 * @return the fixed header
 */
private static MqttFixedHeader decodeFixedHeader(ByteBuf buffer) {
    short b1 = buffer.readUnsignedByte();

    MqttMessageType messageType = MqttMessageType.valueOf(b1 >> 4);
    boolean dupFlag = (b1 & 0x08) == 0x08;
    int qosLevel = (b1 & 0x06) >> 1;
    boolean retain = (b1 & 0x01) != 0;

    int remainingLength = 0;
    int multiplier = 1;
    short digit;
    int loops = 0;
    do {
        digit = buffer.readUnsignedByte();
        remainingLength += (digit & 127) * multiplier;
        multiplier *= 128;
        loops++;
    } while ((digit & 128) != 0 && loops < 4);

    // MQTT protocol limits Remaining Length to 4 bytes
    if (loops == 4 && (digit & 128) != 0) {
        throw new DecoderException("remaining length exceeds 4 digits (" + messageType + ')');
    }
    MqttFixedHeader decodedFixedHeader =
            new MqttFixedHeader(messageType, dupFlag, MqttQoS.valueOf(qosLevel), retain, remainingLength);
    return validateFixedHeader(resetUnusedFields(decodedFixedHeader));
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:34,代码来源:MqttDecoder.java

示例9: decodeSubscribePayload

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Result<MqttSubscribePayload> decodeSubscribePayload(
        ByteBuf buffer,
        int bytesRemainingInVariablePart) {
    final List<MqttTopicSubscription> subscribeTopics = new ArrayList<MqttTopicSubscription>();
    int numberOfBytesConsumed = 0;
    while (numberOfBytesConsumed < bytesRemainingInVariablePart) {
        final Result<String> decodedTopicName = decodeString(buffer);
        numberOfBytesConsumed += decodedTopicName.numberOfBytesConsumed;
        int qos = buffer.readUnsignedByte() & 0x03;
        numberOfBytesConsumed++;
        subscribeTopics.add(new MqttTopicSubscription(decodedTopicName.value, MqttQoS.valueOf(qos)));
    }
    return new Result<MqttSubscribePayload>(new MqttSubscribePayload(subscribeTopics), numberOfBytesConsumed);
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:15,代码来源:MqttDecoder.java

示例10: decodeSubackPayload

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Result<MqttSubAckPayload> decodeSubackPayload(
        ByteBuf buffer,
        int bytesRemainingInVariablePart) {
    final List<Integer> grantedQos = new ArrayList<Integer>();
    int numberOfBytesConsumed = 0;
    while (numberOfBytesConsumed < bytesRemainingInVariablePart) {
        int qos = buffer.readUnsignedByte() & 0x03;
        numberOfBytesConsumed++;
        grantedQos.add(qos);
    }
    return new Result<MqttSubAckPayload>(new MqttSubAckPayload(grantedQos), numberOfBytesConsumed);
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:13,代码来源:MqttDecoder.java

示例11: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, UpdateResponse msg, ByteBuf out) throws Exception {
	int type = msg.getType();
	int id = msg.getId();
	ByteBuf container = msg.getContainer();

	int compression = container.readUnsignedByte();
	int length = container.readInt();

	out.writeByte(type);
	out.writeShort(id);
	out.writeByte(compression);
	out.writeInt(length);

	int bytes = container.readableBytes();
	if (bytes > 504) {
		bytes = 504;
	}
	out.writeBytes(container.readBytes(bytes));
	while ((bytes = container.readableBytes()) != 0) {
		if (bytes == 0) {
			break;
		} else if (bytes > 511) {
			bytes = 511;
		}
		out.writeByte(0xff);
		out.writeBytes(container.readBytes(bytes));
	}
}
 
开发者ID:jordanabrahambaws,项目名称:Quavo,代码行数:30,代码来源:UpdateEncoder.java

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

示例13: readResponse

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public Object readResponse(ByteBuf buffer, int sequenceId, MethodMetadata method)
        throws Exception
{
    short magic = buffer.readShort();
    verify(magic == HEADER_MAGIC, "Unexpected response header magic");
    short flags = buffer.readShort();
    verify(flags == 1, "Unexpected response header flags");

    int frameSequenceId = buffer.readInt();
    if (frameSequenceId != sequenceId) {
        throw new TApplicationException(BAD_SEQUENCE_ID, method.getName() + " failed: out of sequence response");
    }
    int headerSize = buffer.readShort() << 2;

    ByteBuf messageHeader = buffer.readBytes(headerSize);
    int protocolId = messageHeader.readUnsignedByte();
    verify(protocolId == this.protocolId, "response protocol is different than request protocol");

    int numberOfTransforms = messageHeader.readUnsignedByte();
    verify(numberOfTransforms < 128, "Too many transforms for response");

    boolean gzipCompressed = false;
    for (int i = 0; i < numberOfTransforms; i++) {
        int transform = messageHeader.readUnsignedByte();
        verify(transform == 0x01, "Unsupported response transform");
        gzipCompressed = true;
    }

    // Currently we ignore response headers from the server because there is no API to fetch the headers
    Map<String, String> normalHeaders = decodeHeaders(NORMAL_HEADERS, messageHeader);
    Map<String, String> persistentHeaders = decodeHeaders(PERSISTENT_HEADERS, messageHeader);

    ByteBuf message = buffer.readBytes(buffer.readableBytes());
    if (gzipCompressed) {
        // todo decompress
        throw new TTransportException("gzip compression not implemented");
    }

    return MessageEncoding.decodeResponse(protocolFactory, message, sequenceId, method);
}
 
开发者ID:airlift,项目名称:drift,代码行数:43,代码来源:HeaderMessageEncoding.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: parseFetch

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Timed
private void parseFetch(ByteBuf in) throws UnknownFetchItemTypeException, IOException, ResponseParseException {
  skipControlCharacters(in);

  char next = ((char) in.readUnsignedByte());
  if (next != LPAREN && next != RPAREN) {
    in.readerIndex(in.readerIndex() - 1);
  } else if (next == RPAREN) { // Check to see if this is the end of this fetch response
    char second = ((char) in.readUnsignedByte());
    if (second == HttpConstants.CR || second == HttpConstants.LF) {
      // At the end of the fetch, add the current message to the untagged responses and reset
      messageComplete();
      return;
    } else {
      in.readerIndex(in.readerIndex() - 2);
    }
  }

  String fetchItemString = fetchResponseTypeParser.parse(in);
  if (StringUtils.isBlank(fetchItemString)) {
    checkpoint(State.FETCH);
    return;
  }

  FetchDataItemType fetchType = FetchDataItemType.getFetchType(fetchItemString);
  switch (fetchType) {
    case FLAGS:
      List<String> flags = nestedArrayParserRecycler.get().parse(in).stream()
          .map(o -> ((String) o))
          .collect(Collectors.toList());
      currentMessage.setFlagStrings(flags);
      break;
    case INTERNALDATE:
      String internalDate = atomOrStringParser.parse(in);
      currentMessage.setInternalDate(internalDate);
      break;
    case RFC822_SIZE:
      currentMessage.setSize(Ints.checkedCast(numberParser.parse(in)));
      break;
    case UID:
      currentMessage.setUid(numberParser.parse(in));
      break;
    case ENVELOPE:
      currentMessage.setEnvelope(parseEnvelope(in));
      break;
    case BODY:
      startBodyParse(in);
      return;
    case X_GM_MSGID:
      currentMessage.setGmailMessageId(numberParser.parse(in));
      break;
    case X_GM_THRID:
      currentMessage.setGmailThreadId(numberParser.parse(in));
      break;
    case X_GM_LABELS:
      currentMessage.setGMailLabels(
          nestedArrayParserRecycler.get().parse(in).stream()
              .filter(o -> !(o instanceof NilMarker))
              .map(o -> ((String) o))
              .map(GMailLabel::get)
              .collect(Collectors.toSet())
      );
      break;
    case INVALID:
    default:
      throw new UnknownFetchItemTypeException(fetchItemString);
  }

  checkpoint(State.FETCH);
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:71,代码来源:ResponseDecoder.java


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