Example usage for io.netty.buffer ByteBuf getUnsignedShort

List of usage examples for io.netty.buffer ByteBuf getUnsignedShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf getUnsignedShort.

Prototype

public abstract int getUnsignedShort(int index);

Source Link

Document

Gets an unsigned 16-bit short integer at the specified absolute index in this buffer.

Usage

From source file:org.dcache.xrootd.protocol.messages.OpenRequest.java

License:Open Source License

public OpenRequest(ByteBuf buffer) {
    super(buffer, kXR_open);

    mode = buffer.getUnsignedShort(4);
    options = buffer.getUnsignedShort(6);
}

From source file:org.dcache.xrootd.protocol.messages.PrepareRequest.java

License:Open Source License

public PrepareRequest(ByteBuf buffer) {
    super(buffer, kXR_prepare);

    options = buffer.getUnsignedShort(4);
    priority = buffer.getUnsignedShort(5);

    int plen = buffer.getInt(20);
    int end = 24 + plen;

    plist = buffer.toString(24, end - 24, US_ASCII).split("\n");
}

From source file:org.dcache.xrootd.protocol.messages.QueryRequest.java

License:Open Source License

public QueryRequest(ByteBuf buffer) {
    super(buffer, kXR_query);
    reqcode = buffer.getUnsignedShort(4);
    fhandle = buffer.getInt(8);//from   w  w  w.  j  a  v  a  2s.  co  m
    int alen = buffer.getInt(20);

    /* The protocol spec doesn't state anything about trailing zeros in args,
     * however the xrdfs client sends zero terminated paths.
     */
    args = NULL_CHARACTER.trimTrailingFrom(buffer.toString(24, alen, US_ASCII));
}

From source file:org.dcache.xrootd.tpc.core.XrootdClientDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    ChannelId id = ctx.channel().id();//from   w  w  w .j  av a  2  s.c o  m
    int readable = in.readableBytes();

    if (readable < SERVER_RESPONSE_LEN) {
        return;
    }

    int pos = in.readerIndex();
    int headerFrameLength = in.getInt(pos + 4);

    if (headerFrameLength < 0) {
        LOGGER.error("Decoder {}, channel {}: received illegal " + "frame length in " + "xrootd header: {}."
                + " Closing channel.", sourceUrn, id, headerFrameLength);
        ctx.channel().close();
        return;
    }

    int length = SERVER_RESPONSE_LEN + headerFrameLength;

    if (readable < length) {
        return;
    }

    ByteBuf frame = in.readSlice(length);
    int requestId = client.getExpectedResponse();

    try {
        switch (frame.getUnsignedShort(2)) {
        case kXR_error:
            LOGGER.trace("Decoder {}, channel {}: adding error response.", sourceUrn, id);
            out.add(new InboundErrorResponse(frame));
            return;
        case kXR_wait:
            LOGGER.trace("Decoder {}, channel {}: adding wait response.", sourceUrn, id);
            out.add(new InboundWaitResponse(frame, requestId));
            return;
        case kXR_waitresp:
            LOGGER.trace("Decoder {}, channel {}: adding waitresp response.", sourceUrn, id);
            out.add(new InboundWaitRespResponse(frame, requestId));
            return;
        case kXR_redirect:
            LOGGER.trace("Decoder {}, channel {}: adding redirect response.", sourceUrn, id);
            out.add(new InboundRedirectResponse(frame, requestId));
            return;
        case kXR_attn:
            LOGGER.trace("Decoder {}, channel {}: adding attn response.", sourceUrn, id);
            out.add(new InboundAttnResponse(frame, requestId));
            return;
        }

        switch (requestId) {
        case kXR_handshake:
            LOGGER.trace("Decoder {}, channel {}: adding handshake response.", sourceUrn, id);
            out.add(new InboundHandshakeResponse(frame));
            break;
        case kXR_protocol:
            LOGGER.trace("Decoder {}, channel {}: adding protocol response.", sourceUrn, id);
            out.add(new InboundProtocolResponse(frame));
            break;
        case kXR_login:
            LOGGER.trace("Decoder {}, channel {}: adding login response.", sourceUrn, id);
            out.add(new InboundLoginResponse(frame));
            break;
        case kXR_auth:
            LOGGER.trace("Decoder {}, channel {}: adding authentication response.", sourceUrn, id);
            out.add(new InboundAuthenticationResponse(frame));
            break;
        case kXR_open:
            LOGGER.trace("Decoder {}, channel {}: adding open response.", sourceUrn, id);
            out.add(new InboundOpenReadOnlyResponse(frame));
            break;
        case kXR_read:
            LOGGER.trace("Decoder {}, channel {}: adding read response.", sourceUrn, id);
            out.add(new InboundReadResponse(frame));
            break;
        case kXR_query:
            LOGGER.trace("Decoder {}, channel {}: adding query response.", sourceUrn, id);
            out.add(new InboundChecksumResponse(frame));
            break;
        case kXR_close:
            LOGGER.trace("Decoder {}, channel {}: adding close response.", sourceUrn, id);
            out.add(new InboundCloseResponse(frame));
            break;
        case kXR_endsess:
            LOGGER.trace("Decoder {}, channel {}: adding endsess response.", sourceUrn, id);
            out.add(new InboundEndSessionResponse(frame));
            break;
        default:
            LOGGER.trace("Decoder {}, channel {}, received incorrect " + "response of request type {}.",
                    sourceUrn, id, requestId);
            throw new XrootdException(kXR_error, "received incorrect response type.");
        }
    } catch (ParseException | XrootdException e) {
        LOGGER.error("Decoder {}, channel {}: error for request type {}: {}. " + "Closing channel.", requestId,
                id, e.getMessage());
        client.setError(e);
        try {
            client.shutDown(ctx);
        } catch (InterruptedException e1) {
            LOGGER.warn("client shutdown interrupted.");
        }
    }
}

From source file:org.dcache.xrootd.tpc.protocol.messages.AbstractXrootdInboundResponse.java

License:Open Source License

protected AbstractXrootdInboundResponse(ByteBuf buffer) {
    this(buffer.getUnsignedShort(0), buffer.getUnsignedShort(2));
}

From source file:org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse.java

License:Open Source License

private void parseParameters(ByteBuf buffer, int len) {
    switch (actnum) {
    case kXR_asyncab:
    case kXR_asyncms:
        message = buffer.toString(12, len, US_ASCII);
        break;// w  w  w  . j a v  a  2 s.  c  o m
    case kXR_asyncdi:
        wsec = buffer.getInt(12);
        msec = buffer.getInt(16);
        break;
    case kXR_asyncrd:
        port = buffer.getInt(12);
        redirectData = buffer.toString(16, len - 4, US_ASCII);
        break;
    case kXR_asynresp:
        rStreamId = buffer.getUnsignedShort(16);
        rStat = buffer.getUnsignedShort(18);
        int dlen = buffer.getInt(20);
        if (dlen > 0) {
            rData = new byte[dlen];
            buffer.getBytes(24, rData);
        }
        break;
    case kXR_asyncwt:
        wsec = buffer.getInt(12);
        break;
    default:
        break;
    }
}

From source file:org.graylog.plugins.netflow.flows.NetFlowParser.java

License:Apache License

public static NetFlowPacket parse(RawMessage rawMessage) throws FlowException {
    final InetSocketAddress sender = rawMessage.getRemoteAddress() != null
            ? rawMessage.getRemoteAddress().getInetSocketAddress()
            : null;/*from w w  w  .  j a va  2 s  .com*/
    final ByteBuf buf = Unpooled.wrappedBuffer(rawMessage.getPayload());

    switch (buf.getUnsignedShort(0)) {
    case 5:
        return NetFlowV5Packet.parse(sender, buf);
    default:
        final RawMessage.SourceNode sourceNode = rawMessage.getSourceNodes()
                .get(rawMessage.getSourceNodes().size() - 1);
        final String inputId = sourceNode == null ? "<unknown>" : sourceNode.inputId;
        LOG.warn("Unsupported NetFlow version {} on input {} (source: {})", buf.getUnsignedShort(0), inputId,
                rawMessage.getRemoteAddress().getInetSocketAddress());
        return null;
    }
}

From source file:org.graylog.plugins.netflow.utils.ByteBufUtils.java

License:Apache License

public static long getUnsignedInteger(final ByteBuf buf, final int offset, final int length) {
    switch (length) {
    case 1://  ww w. j ava  2 s  .c  om
        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;
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.clients.SimpleClientFramer.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
    if (bb.readableBytes() < LENGTH_OF_HEADER) {
        LOGGER.debug("skipping bb - too few data for header: " + bb.readableBytes());
        return;//from   w w w .java  2 s.co  m
    }

    int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER);
    if (bb.readableBytes() < length) {
        LOGGER.debug("skipping bb - too few data for msg: " + bb.readableBytes() + " < " + length);
        return;
    }
    LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(1));

    ByteBuf messageBuffer = bb.slice(bb.readerIndex(), length);
    list.add(messageBuffer);
    messageBuffer.retain();
    bb.skipBytes(length);
}

From source file:org.opendaylight.openflowjava.protocol.impl.clients.SimpleClientHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf bb = (ByteBuf) msg;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb));
    }// www . j a v a  2  s. c  o m
    int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER);
    LOGGER.trace("SimpleClientHandler - start of read");
    byte[] message = new byte[length];
    bb.readBytes(message);
    scenarioHandler.addOfMsg(message);
    LOGGER.trace("end of read");
}