Java Code Examples for org.jboss.netty.buffer.ChannelBuffer.getShort()

The following are Jave code examples for showing how to use getShort() of the org.jboss.netty.buffer.ChannelBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: athena   File: IsisMessageReader.java   Source Code and License Vote up 4 votes
/**
 * Reads from ISIS packet from buffer.
 *
 * @param channelBuffer buffer
 * @return ISIS message
 * @throws Exception exception
 */
public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception {

    int dataLength = channelBuffer.readableBytes();
    log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength);
    if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) {
        log.debug("Packet should have minimum length...");
        throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH);
    }
    IsisHeader isisHeader = getIsisHeader(channelBuffer);
    int totalLength = 0;
    IsisMessage isisMessage = null;
    switch (isisHeader.isisPduType()) {
        case L1HELLOPDU:
        case L2HELLOPDU:
            isisMessage = new L1L2HelloPdu(isisHeader);
            totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
            break;
        case P2PHELLOPDU:
            isisMessage = new P2PHelloPdu(isisHeader);
            totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION);
            break;
        case L1LSPDU:
        case L2LSPDU:
            isisMessage = new LsPdu(isisHeader);
            totalLength = channelBuffer.getShort(8);
            break;
        case L1CSNP:
        case L2CSNP:
            isisMessage = new Csnp(isisHeader);
            totalLength = channelBuffer.getShort(8);
            break;
        case L1PSNP:
        case L2PSNP:
            isisMessage = new Psnp(isisHeader);
            totalLength = channelBuffer.getShort(8);
            break;
        default:
            log.debug("Message Reader[Decoder] - Unknown PDU type..!!!");
            break;
    }

    if (isisMessage != null) {
        try {
            int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH;
            isisMessage.readFrom(channelBuffer.readBytes(bodyLength));

        } catch (Exception e) {
            throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR,
                                         IsisErrorType.BAD_MESSAGE);
        }

    }

    return isisMessage;
}