⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lbpmessageadapter.java

📁 中国移动定位引擎的客户端
💻 JAVA
字号:
package ffcs.lbp.common;

import java.nio.ByteBuffer;

import ffcs.lbp.ProtocolException;
import ffcs.lbp.LbpMessage;
import ffcs.logging.Log;
import ffcs.logging.LogFactory;
import net.gleamynode.netty2.Message;
import net.gleamynode.netty2.MessageParseException;

/*
* <p>Title: 协议适配器</p>
* <p>Description: netty协议消息与Le内部协议消息适配</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: 福富软件</p>
* @author chenxin
* @version 1.0
*/
public class LbpMessageAdapter implements Message{
	/**
	 * 协议消息
	 */
	private LbpMessage lbpMessage = null;
	
	private static Log log = LogFactory.getLog(LbpMessageAdapter.class);
	
	/**
	 * 
	 * @param sm
	 */
	public LbpMessageAdapter(LbpMessage lm){
		lbpMessage =lm;
	}
	/**
	 * 读消息
	 */
	public boolean read(ByteBuffer buf) throws MessageParseException {
		if(lbpMessage==null){
			throw new MessageParseException("lbpMessage消息实体为空");
		}
		
		boolean b;
		try {
			//打印日志用
			if(log!=null && log.isDebugEnabled()){
				 b = lbpMessage.readMsg(buf);
				 int position = buf.position();
				 int limit = buf.limit();
				 buf.flip();
				 ByteBuffer slice = buf.slice();
				 log.debug("收到消息:"/* + b + " "  + slice+ */+LbpMessage.byte2hexString(slice));
				 buf.position(position);
				 buf.limit(limit);
				 return b;
			}
			b = lbpMessage.readMsg(buf);
		} catch (ProtocolException spe) {
			throw new MessageParseException(spe);
		}
		return b;
	}
	/**
	 * 写消息
	 */
	public boolean write(ByteBuffer buf) {
		if(lbpMessage==null){
			return false;
		}
		
		//打印日志用
		if(log!=null && log.isDebugEnabled()){
			 boolean b=lbpMessage.writeMsg(buf);
			 int position = buf.position();
			 int limit = buf.limit();
			 buf.flip();
//			 ByteBuffer slice = buf.slice();
			 log.debug("发送消息:"/* + b + " "  + slice+ */+LbpMessage.byte2hexString(buf));
			 buf.position(position);
			 buf.limit(limit);
			 return b;
		}
		return lbpMessage.writeMsg(buf);
	}
	public LbpMessage getLbpMessage() {
		return lbpMessage;
	}
	public void setLbpMessage(LbpMessage lbpMessage) {
		this.lbpMessage = lbpMessage;
	}
	public String toString(){
		if(lbpMessage!=null){
		   return lbpMessage.toString();
		}
		return super.toString();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -