
org.wso2.broker.amqp.codec.AmqpDecoder Maven / Gradle / Ivy
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.broker.amqp.codec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.broker.amqp.codec.frames.AmqMethodBodyFactory;
import org.wso2.broker.amqp.codec.frames.AmqMethodRegistry;
import org.wso2.broker.amqp.codec.frames.AmqpBadMessage;
import org.wso2.broker.amqp.codec.frames.ContentFrame;
import org.wso2.broker.amqp.codec.frames.GeneralFrame;
import org.wso2.broker.amqp.codec.frames.HeaderFrame;
import org.wso2.broker.amqp.codec.frames.ProtocolInitFrame;
import java.util.List;
/**
* Netty based AMQP frame decoder.
*/
public class AmqpDecoder extends ByteToMessageDecoder {
private static final Logger LOGGER = LoggerFactory.getLogger(AmqpDecoder.class);
/**
* Used to lookup AMQP method frames depending on their class ID and method ID. We keep this as a static variable
* since it is read only
*/
private static final AmqMethodRegistry methodRegistry = new AmqMethodRegistry();
private static final int FRAME_SIZE_WITHOUT_PAYLOAD = 8;
private static final CharSequence AMQP_PROTOCOL_IDENTIFIER = "AMQP";
/**
* class-id(short) + weight(short) + body-size(long long) + property-flags(short)
*/
private static final int MIN_HEADER_FRAME_SIZE = 14;
/**
* The internal state of {@link AmqpDecoder}.
*/
private enum State {
PROTOCOL_INITIALIZATION,
READ_FRAME,
BAD_MESSAGE
}
private State currentState = State.PROTOCOL_INITIALIZATION;
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy