link.thingscloud.freeswitch.esl.transport.message.EslFrameDecoder Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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 link.thingscloud.freeswitch.esl.transport.message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.ReferenceCountUtil;
import link.thingscloud.freeswitch.esl.exception.EslDecoderException;
import link.thingscloud.freeswitch.esl.transport.util.ByteBuilder;
import link.thingscloud.freeswitch.esl.transport.util.HeaderParser;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* EslFrameDecoder class.
*
* @author : zhouhailin
* @version 1.0.0
*/
@Slf4j
public class EslFrameDecoder extends ReplayingDecoder {
/**
* Line feed character
*/
private static final byte LF = 10;
private final int maxHeaderSize;
private EslMessage currentMessage;
private boolean treatUnknownHeadersAsBody = false;
/**
* Constructor for EslFrameDecoder.
*
* @param maxHeaderSize a int.
*/
public EslFrameDecoder(int maxHeaderSize) {
super(State.READ_HEADER);
if (maxHeaderSize <= 0) {
throw new IllegalArgumentException(
"maxHeaderSize must be a positive integer: " +
maxHeaderSize);
}
this.maxHeaderSize = maxHeaderSize;
}
/**
* Constructor for EslFrameDecoder.
*
* @param maxHeaderSize a int.
* @param treatUnknownHeadersAsBody a boolean.
*/
public EslFrameDecoder(int maxHeaderSize, boolean treatUnknownHeadersAsBody) {
this(maxHeaderSize);
this.treatUnknownHeadersAsBody = treatUnknownHeadersAsBody;
}
/**
* {@inheritDoc}
*/
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy