JML

net.sf.jqql.packets
Class BasicInPacket

java.lang.Object
  extended by net.sf.jqql.packets.Packet
      extended by net.sf.jqql.packets.InPacket
          extended by net.sf.jqql.packets.BasicInPacket
Direct Known Subclasses:
AddFriendAuthResponseReplyPacket, AddFriendExReplyPacket, AddFriendReplyPacket, AdvancedSearchUserReplyPacket, AuthorizeReplyPacket, ChangeStatusReplyPacket, ClusterCommandReplyPacket, DeleteFriendReplyPacket, DownloadGroupFriendReplyPacket, ErrorPacket, FriendChangeStatusPacket, FriendDataOpReplyPacket, FriendLevelOpReplyPacket, GetFriendListReplyPacket, GetOnlineOpReplyPacket, GetTempClusterOnlineMemberReplyPacket, GetUserInfoReplyPacket, GroupDataOpReplyPacket, KeepAliveReplyPacket, LoginReplyPacket, ModifyInfoReplyPacket, PrivacyDataOpReplyPacket, ReceiveIMPacket, RemoveSelfReplyPacket, RequestKeyReplyPacket, RequestLoginTokenReplyPacket, SearchUserReplyPacket, SendIMReplyPacket, SendSMSReplyPacket, SignatureOpReplyPacket, SystemNotificationPacket, TempSessionOpReplyPacket, UnknownInPacket, UploadGroupFriendReplyPacket, UserPropertyOpReplyPacket, WeatherOpReplyPacket

public abstract class BasicInPacket
extends InPacket

 input packet base class of basic protocol family
 1. packet header sign, 1 byte, 0x02
 2. server version code, 2 byte
 3. command, 2 byte
 4. packet sequence number, 2 byte
 5. packet body
 6. packet tail sign, 1 byte, 0x03

 基本协议族的输入包基类:
 1. 包头标志,1字节,0x02
 2. 服务器端版本代码, 2字节
 3. 命令,2字节
 4. 包序号,2字节
 5. 包体
 6. 包尾标志,1字节,0x03
 

Author:
notxx, luma

Field Summary
 
Fields inherited from class net.sf.jqql.packets.Packet
bodyBuf, bodyDecrypted, command, crypter, ds, duplicated, header, log, sequence, source, user
 
Constructor Summary
BasicInPacket(ByteBuffer buf, int length, QQUser user)
          create a InPacket, parse length count byte from current position of buf 构造一个InPacket,从buf的当前位置解析length个字节
BasicInPacket(ByteBuffer buf, QQUser user)
          create a Specify Parameters packet.
BasicInPacket(char command, QQUser user)
           
 
Method Summary
protected  byte[] decryptBody(byte[] buf, int offset, int len)
          decrypt packet body 解密包体
protected  byte[] encryptBody(byte[] b, int offset, int length)
          encrypt packet body 加密包体
protected  byte[] getBodyBytes(ByteBuffer buf, int length)
          get byte array of packet body 得到包体的字节数组
protected  int getCryptographStart()
           
 int getFamily()
           
protected  int getHeadLength()
           
protected  int getLength(int bodyLength)
          get total length of UDP form packet, rule out TCP form 得到UDP形式包的总长度,不考虑TCP形式
 String getPacketName()
           
protected  int getTailLength()
           
protected  void parseHeader(ByteBuffer buf)
          parse packet header from current position of buf 从buf的当前位置解析包头
protected  void parseTail(ByteBuffer buf)
          parse packet tail from current position of buf 从buf的当前未知解析包尾
protected  void putBody(ByteBuffer buf)
          initialize packet body 初始化包体
protected  void putHead(ByteBuffer buf)
          change packet header to byte stream, and write into appointed ByteBuffer object.
protected  void putTail(ByteBuffer buf)
          change packet tail to byte stream, and write into appointed ByteBuffer object.
 String toString()
           
 
Methods inherited from class net.sf.jqql.packets.InPacket
validateHeader
 
Methods inherited from class net.sf.jqql.packets.Packet
dump, equals, getCommand, getHeader, getSequence, getSource, hash, hashCode, isDuplicated, parseBody, setDuplicated, setHeader, setSequence
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicInPacket

public BasicInPacket(char command,
                     QQUser user)
Parameters:
command -
user -

BasicInPacket

public BasicInPacket(ByteBuffer buf,
                     QQUser user)
              throws PacketParseException
create a Specify Parameters packet. parse from current position of buf to limit 构造一个指定参数的包.从buf的当前位置开始解析直到limit

Parameters:
buf - ByteBuffer对象 //ByteBuffer object
Throws:
PacketParseException - content parse error 内容解析出错.

BasicInPacket

public BasicInPacket(ByteBuffer buf,
                     int length,
                     QQUser user)
              throws PacketParseException
create a InPacket, parse length count byte from current position of buf 构造一个InPacket,从buf的当前位置解析length个字节

Parameters:
buf - ByteBuffer对象 //ByteBuffer object
length - 字节数 //byte count
Throws:
PacketParseException - content parse error 内容解析出错
Method Detail

parseHeader

protected void parseHeader(ByteBuffer buf)
                    throws PacketParseException
Description copied from class: Packet
parse packet header from current position of buf 从buf的当前位置解析包头

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

parseTail

protected void parseTail(ByteBuffer buf)
Description copied from class: Packet
parse packet tail from current position of buf 从buf的当前未知解析包尾

Specified by:
parseTail in class Packet
Parameters:
buf - ByteBuffer

putHead

protected void putHead(ByteBuffer buf)
Description copied from class: Packet
change packet header to byte stream, and write into appointed ByteBuffer object. 将包头部转化为字节流, 写入指定的ByteBuffer对象.

Specified by:
putHead in class Packet
Parameters:
buf - ByteBuffer object whicn packet need to write into 写入的ByteBuffer对象.

putBody

protected void putBody(ByteBuffer buf)
Description copied from class: Packet
initialize packet body 初始化包体

Specified by:
putBody in class Packet
Parameters:
buf - ByteBuffer

putTail

protected void putTail(ByteBuffer buf)
Description copied from class: Packet
change packet tail to byte stream, and write into appointed ByteBuffer object. 将包尾部转化为字节流, 写入指定的ByteBuffer对象.

Specified by:
putTail in class Packet
Parameters:
buf - ByteBuffer object whicn packet need to write into 写入的ByteBuffer对象.

getPacketName

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

decryptBody

protected byte[] decryptBody(byte[] buf,
                             int offset,
                             int len)
Description copied from class: Packet
decrypt packet body 解密包体

Specified by:
decryptBody in class Packet
Parameters:
buf - byte array of packet body 包体字节数组
offset - offset of packet body begin 包体开始偏移
len - packet length 包体长度
Returns:
解密的包体字节数组 // byte array of decrypted packet body

encryptBody

protected byte[] encryptBody(byte[] b,
                             int offset,
                             int length)
Description copied from class: Packet
encrypt packet body 加密包体

Specified by:
encryptBody in class Packet
Parameters:
b - unencrypt byte array 未加密的字节数组
offset - offset of packet body begin 包体开始的偏移
length - packet body length 包体长度
Returns:
encrypted packet body 加密的包体

getBodyBytes

protected byte[] getBodyBytes(ByteBuffer buf,
                              int length)
Description copied from class: Packet
get byte array of packet body 得到包体的字节数组

Specified by:
getBodyBytes in class Packet
Parameters:
buf - ByteBuffer
length - packet total length 包总长度
Returns:
byte array of packet body 包体字节数组

getLength

protected int getLength(int bodyLength)
Description copied from class: Packet
get total length of UDP form packet, rule out TCP form 得到UDP形式包的总长度,不考虑TCP形式

Specified by:
getLength in class Packet
Parameters:
bodyLength - packet body length 包体长度
Returns:
packet length 包长度

getHeadLength

protected int getHeadLength()
Specified by:
getHeadLength in class Packet
Returns:
packet header length 包头长度

getTailLength

protected int getTailLength()
Specified by:
getTailLength in class Packet
Returns:
packet tail length 包尾长度

toString

public String toString()
Overrides:
toString in class Object

getCryptographStart

protected int getCryptographStart()
Specified by:
getCryptographStart in class Packet
Returns:
start position of cryptograph, relative to the first byte of packet body. if this packet is unknown packet, return -1, this method only available to some protocol family. 密文的起始位置,这个位置是相对于包体的第一个字节来说的,如果这个包是未知包, 返回-1,这个方法只对某些协议族有意义

getFamily

public int getFamily()
Specified by:
getFamily in class Packet
Returns:
sign this packet belong which protocol family 标识这个包属于哪个协议族

JML