nelHandlerContext;12 import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;13 import org.slf4j.Logger;14 import org.slf4j.LoggerFactory;15 import flex.messaging.io.SerializationContext;16 import flex.messaging.io.amf.Amf3Input;17 /**18 * amf3协议解码类19 * 20 * @author sunwei21 * @version 2010-7-2122 * @since JDK1.523 */24 public class AMF3Decoder extends LengthFieldBasedFrameDecoder25 {26 public static final Logger logger = LoggerFactory27 .getLogger(AMF3Decoder.class);28 /**29 * 30 * @param maxFrameLength31 * 包的最大大小32 * @param lengthFieldOffset33 * 包头信息,长度的偏移位34 * @param lengthFieldLength35 * 包头信息,长度位数36 */37 public AMF3Decoder(int maxFrameLength, int lengthFieldOffset,38 int lengthFieldLength)39 {40 super(maxFrameLength, lengthFieldOffset, lengthFieldLength);41 }42 /**43 * 44 * @param maxFrameLength45 */46 public AMF3Decoder(int maxFrameLength)47 {48 super(maxFrameLength, 4, 4, 0, 0);49 }50 /**51 * 52 */53 @Override54 protected Object decode(ChannelHandlerContext ctx, Channel channel,55 ChannelBuffer buffer) throws Exception56 {57 ChannelBuffer frame = (ChannelBuffer) super58 .decode(ctx, channel, buffer);59 if (frame == null)60 {61 return null;62 }63 //64 int magicNum = frame.readInt();65 int dataLength = frame.readInt();66 logger.info("magic num={},data length={}", magicNum, dataLength);67 // 读AMF3字节流的内容68 byte[] content = new byte[frame.readableBytes()];69 frame.readBytes(content);70 SerializationContext serializationContext = new SerializationContext();71 Amf3Input amf3Input = new Amf3Input(serializationContext);72 amf3Input.setInputStream(new ByteArrayInputStream(content));73 Object