JML

net.sf.jqql.packets
Class OutPacket

java.lang.Object
  extended by net.sf.jqql.packets.Packet
      extended by net.sf.jqql.packets.OutPacket
Direct Known Subclasses:
_03OutPacket, _05OutPacket, BasicOutPacket, DiskOutPacket

public abstract class OutPacket
extends Packet

所有输出包基类,这个基类定义了输出包的基本框架

Author:
luma

Field Summary
protected  boolean ack
          æ˜¯å¦éœ€è¦å›žåº”
protected  byte[] key
          åР坆/解密密钥,只有有些包可能需要一个特定的密钥,如果为null,使用缺省的
protected  int resendCountDown
          é‡å‘计数器
protected  int sendCount
          å‘送次数,只在包是不需要ack时有效,比如logout包是发4次,但是其他可能只发一次
protected static char seq
          åŒ…起始序列号
protected  long timeout
          è¶…时截止时间,单位ms
 
Fields inherited from class net.sf.jqql.packets.Packet
bodyBuf, bodyDecrypted, command, crypter, ds, duplicated, header, log, sequence, source, user
 
Constructor Summary
protected OutPacket(ByteBuffer buf, int length, QQUser user)
          create a outPacket from buf, use to debug.
protected OutPacket(ByteBuffer buf, QQUser user)
          create a outPacket from buf, use to debug.
  OutPacket(byte header, char command, boolean ack, QQUser user)
          create a basic output packet 创建一个基本输出包
 
Method Summary
 byte[] dump()
          export all content of packet to a byte array, mostly use to debug 导出包的全部内容到一个字节数组中,主要用于调试
 void fill(ByteBuffer buf)
          change whole packet to byte stream, and write into appointed ByteBuffer object.
 byte[] getKey()
           
protected static char getNextSeq()
           
 String getPacketName()
           
 int getSendCount()
           
 long getTimeout()
           
 boolean needAck()
           
 boolean needResend()
          whether need resend.
protected  void parseBody(ByteBuffer buf)
          parse packet body, from begin position of buf 解析包体,从buf的开头位置解析起
protected abstract  void postFill(ByteBuffer buf, int startPos)
          backfill, some field must fill whole packet to make sure its content, for example length field, then this method will be used after tail filling.
 void setKey(byte[] key)
           
 void setSendCount(int sendCount)
           
 void setTimeout(long timeout)
           
 
Methods inherited from class net.sf.jqql.packets.Packet
decryptBody, encryptBody, equals, getBodyBytes, getCommand, getCryptographStart, getFamily, getHeader, getHeadLength, getLength, getSequence, getSource, getTailLength, hash, hashCode, isDuplicated, parseHeader, parseTail, putBody, putHead, putTail, setDuplicated, setHeader, setSequence, validateHeader
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

seq

protected static char seq
包起始序列号


ack

protected boolean ack
是否需要回应


resendCountDown

protected int resendCountDown
重发计数器


timeout

protected long timeout
超时截止时间,单位ms


sendCount

protected int sendCount
发送次数,只在包是不需要ack时有效,比如logout包是发4次,但是其他可能只发一次


key

protected byte[] key
加密/解密密钥,只有有些包可能需要一个特定的密钥,如果为null,使用缺省的

Constructor Detail

OutPacket

public OutPacket(byte header,
                 char command,
                 boolean ack,
                 QQUser user)
create a basic output packet 创建一个基本输出包

Parameters:
command - packet command 包命令
ack - whether packet needs reply 包是否需要回复
user - QQ user object QQ用户对象

OutPacket

protected OutPacket(ByteBuffer buf,
                    QQUser user)
             throws PacketParseException
create a outPacket from buf, use to debug. this buf maybe contain data which catched by catching packet software 从buf中构造一个OutPacket,用于调试。这个buf里面可能包含了抓包软件抓来的数据

Parameters:
buf - ByteBuffer
Throws:
PacketParseException - parse error 解析出错

OutPacket

protected OutPacket(ByteBuffer buf,
                    int length,
                    QQUser user)
             throws PacketParseException
create a outPacket from buf, use to debug. this buf maybe contain data which catched by catching packet software 从buf中构造一个OutPacket,用于调试。这个buf里面可能包含了抓包软件抓来的数据

Parameters:
buf - ByteBuffer
length - parsing content length 要解析的内容长度
Throws:
PacketParseException - if parse error 如果解析出错
Method Detail

parseBody

protected void parseBody(ByteBuffer buf)
                  throws PacketParseException
Description copied from class: Packet
parse packet body, from begin position of buf 解析包体,从buf的开头位置解析起

Specified by:
parseBody in class Packet
Parameters:
buf - ByteBuffer
Throws:
PacketParseException - if parse error 如果解析出错

postFill

protected abstract void postFill(ByteBuffer buf,
                                 int startPos)
backfill, some field must fill whole packet to make sure its content, for example length field, then this method will be used after tail filling. 回填,有些字段必须填完整个包才能确定其内容,比如长度字段,那么这个方法将在 尾部填充之后调用

Parameters:
buf - ByteBuffer
startPos - packet initial position 包起始位置

fill

public void fill(ByteBuffer buf)
change whole packet to byte stream, and write into appointed ByteBuffer object. generally speaking, front and back respectively need to write into packet header and tail. 将整个包转化为字节流, 并写入指定的ByteBuffer对象. 一般而言, 前后分别需要写入包头部和包尾部.

Parameters:
buf - ByteBuffer object whicn packet need to write into 将包写入的ByteBuffer对象.

dump

public byte[] dump()
Description copied from class: Packet
export all content of packet to a byte array, mostly use to debug 导出包的全部内容到一个字节数组中,主要用于调试

Overrides:
dump in class Packet
Returns:
byte array for packet 包的字节数组

getNextSeq

protected static char getNextSeq()
Returns:
next usble sequence number 下一个可用的序列号

getPacketName

public String getPacketName()
Overrides:
getPacketName in class Packet
Returns:
descriptive name of packet 包的描述性名称

needResend

public final boolean needResend()
whether need resend. 是否需要重发.

Returns:
需要重发返回true, 否则返回false. //need resnend return ture, or return false.

needAck

public final boolean needAck()
Returns:
true表示包需要回复 // true means packet needs reply

getTimeout

public final long getTimeout()
Returns:
Returns the timeout.

setTimeout

public final void setTimeout(long timeout)
Parameters:
timeout - The timeout to set.

setSendCount

public final void setSendCount(int sendCount)
Parameters:
sendCount - The sendCount to set.

getSendCount

public final int getSendCount()
Returns:
Returns the sendCount.

getKey

public byte[] getKey()
Returns:
Returns the key.

setKey

public void setKey(byte[] key)
Parameters:
key - The key to set.

JML