This commit is contained in:
lyr90329 2014-08-10 11:42:50 +08:00
parent 2c8ceb2e95
commit 9fa31a189e
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package server;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import server.MDecoder;
import server.MEncoder;
import server.MServerHandler;
public class MServerPipelineFactory implements ChannelPipelineFactory
{
public ChannelPipeline getPipeline() throws Exception
{
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new MDecoder());
pipeline.addLast("encoder", new MEncoder());
pipeline.addLast("handler", new MServerHandler());
return pipeline;
}
}

View File

@ -0,0 +1,53 @@
package server;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.MessageLite;
import server.NetMsg;
import common.EMSGID;
import common.MessageManager;
public class NetMsg
{
EMSGID msgID;
MessageLite messageLite;
private NetMsg(){};
public static NetMsg newMessage()
{
return new NetMsg();
}
NetMsg(byte[] decoded, int id) throws Exception
{
messageLite = MessageManager.getMessage(id, decoded);
}
public byte[] getBytes()
{
return messageLite.toByteArray();
}
public EMSGID getMsgID()
{
return msgID;
}
public void setMsgID(EMSGID id) {
this.msgID = id;
}
@SuppressWarnings("unchecked")
public <T extends MessageLite> T getMessageLite()
{
return (T)messageLite;
}
//Ḭ̈߳²È«µÄ
@SuppressWarnings("rawtypes")
public void setMessageLite(GeneratedMessage.Builder builder)
{
this.messageLite = builder.build();
}
}