protected int processAMQPFrames(final QpidByteBuffer buf) throws AMQFrameDecodingException { final int required = decodable(buf); if (required == 0) { processInput(buf); } return required; }
protected void processInput(final QpidByteBuffer in) throws AMQFrameDecodingException, AMQProtocolVersionException { final byte type = in.get(); final int channel = in.getUnsignedShort(); final long bodySize = in.getUnsignedInt(); // bodySize can be zero if ((channel < 0) || (bodySize < 0)) { throw new AMQFrameDecodingException( "Undecodable frame: type = " + type + " channel = " + channel + " bodySize = " + bodySize); } processFrame(channel, type, bodySize, in); byte marker = in.get(); if ((marker & 0xFF) != 0xCE) { throw new AMQFrameDecodingException( "End of frame marker not found. Read " + marker + " length=" + bodySize + " type=" + type); } }
protected void processFrame(final int channel, final byte type, final long bodySize, final QpidByteBuffer in) throws AMQFrameDecodingException { switch (type) { case 1: processMethod(channel, in); break; case 2: ContentHeaderBody.process(in, _methodProcessor.getChannelMethodProcessor(channel), bodySize); break; case 3: ContentBody.process(in, _methodProcessor.getChannelMethodProcessor(channel), bodySize); break; case 8: HeartbeatBody.process(channel, in, _methodProcessor, bodySize); break; default: throw new AMQFrameDecodingException("Unsupported frame type: " + type); } }
protected final int decode(final QpidByteBuffer buf) throws AMQFrameDecodingException { // If this is the first read then we may be getting a protocol initiation back if we tried to negotiate // an unsupported version if(_firstRead && buf.hasRemaining()) { _firstRead = false; if(!_expectProtocolInitiation && (((int)buf.get(buf.position())) &0xff) > 8) { _expectProtocolInitiation = true; } } int required = 0; while (required == 0) { if(!_expectProtocolInitiation) { required = processAMQPFrames(buf); } else { required = _piDecoder.decodable(buf); if (required == 0) { _methodProcessor.receiveProtocolHeader(new ProtocolInitiation(buf)); } } } return buf.hasRemaining() ? required : 0; }