nc. All rights reserved. 5 * QISI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 */ 7 package com.qidea.pushserver.codec; 8 import java.io.ByteArrayOutputStream; 9 import org.jboss.netty.buffer.ChannelBuffer;10 import org.jboss.netty.buffer.ChannelBuffers;11 import org.jboss.netty.channel.Channel;12 import org.jboss.netty.channel.ChannelHandlerContext;13 import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;14 import com.qidea.pushserver.Constants;15 import com.qidea.pushserver.message.CommandMessage;16 import com.qidea.pushserver.message.PushMessage;17 import flex.messaging.io.SerializationContext;18 import flex.messaging.io.amf.Amf3Output;19 /**20 * 21 * @author sunwei22 * @version 2010-7-2123 * @since JDK1.524 */25 public class AMF3Encoder extends OneToOneEncoder26 {27 /**28 * 29 */30 @Override31 protected Object encode(ChannelHandlerContext arg0, Channel arg1,32 Object arg2) throws Exception33 {34 ByteArrayOutputStream stream = new ByteArrayOutputStream();35 SerializationContext serializationContext = new SerializationContext();36 Amf3Output amf3Output = new Amf3Output(serializationContext);37 amf3Output.setOutputStream(stream);38 amf3Output.writeObject(arg2);39 byte[] objSe = stream.toByteArray();40 if (objSe != null && objSe.length > 0)41 {42 ChannelBuffer buffer = ChannelBuffers.buffer(objSe.length + 8);43 if (arg2 instanceof PushMessage)44 buffer.writeInt(Constants.MAGIC_NUM_PUSH_MSG);45 else if (arg2 instanceof CommandMessage)46 buffer.writeInt(Constants.MAGIC_NUM_COMMAND_MSG);47 buffer.writeInt(objSe.length);48 buffer.writeBytes(objSe);49 return buffer;50 }51 return null;52 }53 }AMF3Decoder 1 /* 2 * @(#)AMF3Decoder.java 0.1 05/11/17 3 * 4 * Copyright 2010 QISI, Inc. All rights reserved. 5 * QISI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 */ 7 package com.qidea.pushserver.codec; 8 import java.io.ByteArrayInputStream; 9 import org.jboss.netty.buffer.ChannelBuffer;10 import org.jboss.netty.channel.Channel;11 import org.jboss.netty.channel.Chan