This commit is contained in:
parent
2c8ceb2e95
commit
9fa31a189e
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue