Java Code Examples for io.netty.buffer.ByteBuf#getUnsignedMedium()

The following examples show how to use io.netty.buffer.ByteBuf#getUnsignedMedium() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LengthFieldBasedFrameDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes the specified region of the buffer into an unadjusted frame length.  The default implementation is
 * capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer.  Override this method to
 * decode the length field encoded differently.  Note that this method must not modify the state of the specified
 * buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.)
 *
 * @throws DecoderException if failed to decode the specified region
 * 将缓冲区的指定区域解码为未调整的帧长度。默认实现可以将指定的区域解码为无符号的8/16/24/32/64位整数。重写此方法,以不同的方式解码长度字段。注意,此方法不能修改指定缓冲区的状态(例如readerIndex、writerIndex和缓冲区的内容)。
 */
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
    buf = buf.order(order);
    long frameLength;
    switch (length) {
    case 1:
        frameLength = buf.getUnsignedByte(offset);
        break;
    case 2:
        frameLength = buf.getUnsignedShort(offset);
        break;
    case 3:
        frameLength = buf.getUnsignedMedium(offset);
        break;
    case 4:
        frameLength = buf.getUnsignedInt(offset);
        break;
    case 8:
        frameLength = buf.getLong(offset);
        break;
    default:
        throw new DecoderException(
                "unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
    }
    return frameLength;
}
 
Example 2
Source File: HermesLengthFieldBasedFrameDecoder.java    From hermes with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes the specified region of the buffer into an unadjusted frame length. The default implementation is capable of decoding
 * the specified region into an unsigned 8/16/24/32/64 bit integer. Override this method to decode the length field encoded
 * differently. Note that this method must not modify the state of the specified buffer (e.g. {@code readerIndex},
 * {@code writerIndex}, and the content of the buffer.)
 *
 * @throws DecoderException
 *            if failed to decode the specified region
 */
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
	buf = buf.order(order);
	long frameLength;
	switch (length) {
	case 1:
		frameLength = buf.getUnsignedByte(offset);
		break;
	case 2:
		frameLength = buf.getUnsignedShort(offset);
		break;
	case 3:
		frameLength = buf.getUnsignedMedium(offset);
		break;
	case 4:
		frameLength = buf.getUnsignedInt(offset);
		break;
	case 8:
		frameLength = buf.getLong(offset);
		break;
	default:
		throw new DecoderException("unsupported lengthFieldLength: " + lengthFieldLength
		      + " (expected: 1, 2, 3, 4, or 8)");
	}
	return frameLength;
}
 
Example 3
Source File: ByteBufUtils.java    From graylog-plugin-netflow with Apache License 2.0 6 votes vote down vote up
public static long getUnsignedInteger(final ByteBuf buf, final int offset, final int length) {
    switch (length) {
        case 1:
            return buf.getUnsignedByte(offset);
        case 2:
            return buf.getUnsignedShort(offset);
        case 3:
            return buf.getUnsignedMedium(offset);
        case 4:
            return buf.getUnsignedInt(offset);
        case 8:
            return buf.getLong(offset) & 0x00000000ffffffffL;
        default:
            return 0L;
    }
}
 
Example 4
Source File: LengthFieldBasedFrameDecoder.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes the specified region of the buffer into an unadjusted frame length.  The default implementation is
 * capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer.  Override this method to
 * decode the length field encoded differently.  Note that this method must not modify the state of the specified
 * buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.)
 *
 * @throws DecoderException if failed to decode the specified region
 */
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
    buf = buf.order(order);
    long frameLength;
    switch (length) {
    case 1:
        frameLength = buf.getUnsignedByte(offset);
        break;
    case 2:
        frameLength = buf.getUnsignedShort(offset);
        break;
    case 3:
        frameLength = buf.getUnsignedMedium(offset);
        break;
    case 4:
        frameLength = buf.getUnsignedInt(offset);
        break;
    case 8:
        frameLength = buf.getLong(offset);
        break;
    default:
        throw new DecoderException(
                "unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
    }
    return frameLength;
}
 
Example 5
Source File: HttpResponseDecoder.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private static int nettyBufferToStatusCode(final ByteBuf buffer, final int start, final int length) {
    if (length != 3) {
        splitInitialLineError();
    }

    final int medium = buffer.getUnsignedMedium(start);
    return toDecimal((medium & 0xff0000) >> 16) * 100 +
            toDecimal((medium & 0xff00) >> 8) * 10 +
            toDecimal(medium & 0xff);
}
 
Example 6
Source File: MplsLabelUtil.java    From bgpcep with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Gets Bottom Bit.
 *
 * @param slice with 20 leftmost bits as label
 * @return value of bottom bit
 */
public static boolean getBottomBit(final ByteBuf slice) {
    return (slice.getUnsignedMedium(slice.readerIndex()) & BOTTOM_LABEL_BIT) == 1;
}