JML

net.sf.jqql.packets
Class PacketHelper

java.lang.Object
  extended by net.sf.jqql.packets.PacketHelper

public final class PacketHelper
extends Object

Author:
notXX, luma

Constructor Summary
PacketHelper(int supportedFamily)
           
 
Method Summary
 boolean isDuplicated(InPacket packet)
          checkout packet is whether duplicated received 检查包是否重复收到
 boolean isReplied(OutPacket packet, boolean add)
          this method checkout packet whether is received, remarkable is that checkout is for hash value of this packet, not for packet object, account of hash value is completing in hashCode in packet.
 InPacket parseIn(int supportedFamily, ByteBuffer buf, QQUser user, boolean debug)
          parse content of ByteBuffer to a InPacket subclass, from current position of buf to limit either success or not, should set position of buf after length 把ByteBuffer中的内容解析成一个InPacket子类,从buf的当前位置开始解析,直到limit为止 不论解析成功或者失败,要把bufçš„position置于length后
 OutPacket parseOut(int supportedFamily, ByteBuffer buf, QQUser user)
          parse content of ByteBuffer to a InPacket subclass, from current position of buf to limit either success or not, should set position of buf after length 把ByteBuffer中的内容解析成一个InPacket子类,从buf的当前位置开始解析,直到limit为止 不论解析成功或者失败,要把bufçš„position置于length后
 void putSent(OutPacket out)
          save sent packet 缓存输出包
 boolean relocate(int relocateFamily, ByteBuffer buf)
          set position after initial position of next packet.
 OutPacket retrieveSent(InPacket in)
          get request packet from reply packet 通过回复包获得请求包
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketHelper

public PacketHelper(int supportedFamily)
Method Detail

retrieveSent

public OutPacket retrieveSent(InPacket in)
get request packet from reply packet 通过回复包获得请求包

Parameters:
in - reply packet 回复包
Returns:
OutPacket object, if haven't, return null OutPacket对象,如果没有找到,返回null

putSent

public void putSent(OutPacket out)
save sent packet 缓存输出包

Parameters:
out -

isReplied

public boolean isReplied(OutPacket packet,
                         boolean add)
this method checkout packet whether is received, remarkable is that checkout is for hash value of this packet, not for packet object, account of hash value is completing in hashCode in packet. if two packets, sequence number or command is different, hash value is different. 这个方法检查包是否已收到,要注意的是检查是针对这个包的hash值进行的, 并不是对packet这个对象,hash值的计算是在packet的hashCode中完成的, 如果两个packet的序号或者命令有不同,则hash值肯定不同。

Parameters:
packet - packet to be checkout 要检查的包
add - if is true, then while this packet is null, add hash of this packet, or don't add 如果为true,则当这个包不存在时,添加这个包的hash,否则不添加
Returns:
if this packet is received return true, or teturn false true如果这个包已经收到,否则false
See Also:
Packet.hashCode(), Packet.equals(Object);

isDuplicated

public boolean isDuplicated(InPacket packet)
checkout packet is whether duplicated received 检查包是否重复收到

Parameters:
packet - InPacket subclass InPacket子类
Returns:
true means duplicated true表示重复

parseIn

public InPacket parseIn(int supportedFamily,
                        ByteBuffer buf,
                        QQUser user,
                        boolean debug)
                 throws PacketParseException
parse content of ByteBuffer to a InPacket subclass, from current position of buf to limit either success or not, should set position of buf after length 把ByteBuffer中的内容解析成一个InPacket子类,从buf的当前位置开始解析,直到limit为止 不论解析成功或者失败,要把buf的position置于length后

Parameters:
supportedFamily - supported protocol family 支持的协议族
buf - ByteBuffer objcet ByteBuffer对象
debug - true means debug mode, debug mode will overlook reduplicated packet true表示调试模式,调试模式下会忽略重复包
Returns:
InPacket if parse fail, or content of buffer can't be a packet, return null 如果解析失败,或者缓冲区中的内容构不成一个包,返回null
Throws:
PacketParseException - if packet format wrong 如果包格式不对

parseOut

public OutPacket parseOut(int supportedFamily,
                          ByteBuffer buf,
                          QQUser user)
                   throws PacketParseException
parse content of ByteBuffer to a InPacket subclass, from current position of buf to limit either success or not, should set position of buf after length 把ByteBuffer中的内容解析成一个InPacket子类,从buf的当前位置开始解析,直到limit为止 不论解析成功或者失败,要把buf的position置于length后

Parameters:
buf -
type -
Returns:
Throws:
PacketParseException

relocate

public boolean relocate(int relocateFamily,
                        ByteBuffer buf)
set position after initial position of next packet. commonly while some data fields haven't parser if can, use this method jump over this data field 把position设置到下一个包的起始位置处。一般当某段数据没有parser 可以时,调用此方法跳过这段数据

Parameters:
relocateFamily - relocate use protocol family 重定位使用的协议族
buf - buffer 缓冲区
Returns:
true means relocate success, false means fail or put off true表示重定位成功,false表示失败或者推迟重定位

JML