com.aspire.nm.component.cmppserver.filter.coder.packet
类 Packet

java.lang.Object
  继承者 com.aspire.nm.component.cmppserver.filter.coder.packet.Packet
直接已知子类:
CmppPacket

public class Packet
extends Object

用于存放与协议相关的一个完整封包

JNSF并不强制要求使用此类, 但某些情况下使用此类可以减少很多工作。
Packet底层有一个ByteBuffer来存放从网络读到字节序列, 或者经过编码后即将发送到网络的字节序列, 当向网络发送封包时, ByteBuffer的数据由具体实现类的对象内部直接填充或者在编码器中填充, 也就是说底层数据由具体实现类的对象或具体编码器实现类的对象提供. 当从网络读时, ByteBuffer由解码器负责填充, 也就是说底层数据由具体的解码器实现提供.
基于ByteBuffer请参见java.nio.ByteBuffer

从以下版本开始:
2.0.0 LAST MODIFIED: 2008-12-29
作者:
zhangkai

构造方法摘要
Packet()
          构造Packet对象
Packet(byte[] bytes)
          用指定的字节数组构造Packet对象
Packet(ByteBuffer buffer)
          用指定的ByteBuffer构造Packet对象
 
方法摘要
protected  ByteBuffer allocate(int capacity)
          为Packet申请底层存储空间。
protected  byte get()
          取得一个byte(相对)
protected  ByteBuffer get(byte[] desc)
          取得byte[]
protected  ByteBuffer get(byte[] dst, int offset, int length)
          取得byte[]
protected  byte get(int index)
          取得byte(绝对)
 ByteBuffer getByteBuffer()
          获得底层用于存放数据的ByteBuffer, 返回的ByteBuffer是只读的
 byte[] getBytes()
          返回底层字节数组
protected  char getChar()
          取得char(相对)
protected  char getChar(int index)
          取得char(绝对)
protected  double getDouble()
          取得double(相对)
protected  double getDouble(int index)
          取得double(绝对)
protected  float getFloat()
          取得float(相对)
protected  float getFloat(int index)
          取得float(绝对)
protected  int getInt()
          取得int(相对)
protected  int getInt(int index)
          取得int(绝对)
protected  long getLong()
          取得long(相对)
protected  long getLong(int index)
          取得long(绝对)
protected  short getShort()
          取得short(相对)
protected  short getShort(int index)
          取得short(绝对)
protected  String getString(int length)
          取得指定长度的字符串
protected  ByteBuffer put(byte b)
          写入byte
protected  ByteBuffer put(byte[] src)
          写入byte[]
protected  ByteBuffer put(byte[] src, int offset, int length)
          写入byte[]
protected  ByteBuffer put(ByteBuffer src)
          写入ByteBuffer
protected  ByteBuffer put(int index, byte b)
          写入byte到ByteBuffer指定位置
protected  ByteBuffer putChar(char value)
          写入char
protected  ByteBuffer putChar(int index, char value)
          写入char到ByteBuffer指定位置
protected  ByteBuffer putDouble(double value)
          写入double
protected  ByteBuffer putDouble(int index, double value)
          写入double到ByteBuffer指定位置
protected  ByteBuffer putFloat(float value)
          写入float
protected  ByteBuffer putFloat(int index, float value)
          写入float到ByteBuffer指定位置
protected  ByteBuffer putInt(int value)
          写入int
protected  ByteBuffer putInt(int index, int value)
          写入int到ByteBuffer指定位置
protected  ByteBuffer putLong(int index, long value)
          写入long到ByteBuffer指定位置
protected  ByteBuffer putLong(long value)
          写入long
protected  ByteBuffer putShort(int index, short value)
          写入short到ByteBuffer指定位置
protected  ByteBuffer putShort(short value)
          写入short
protected  ByteBuffer putString(String value)
          写入指定字串
protected  ByteBuffer putString(String value, int beginIndex, int endIndex)
          写入指定字串
protected  ByteBuffer putStringLeftPad(String value, int len)
          写入指定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则左补\0
protected  ByteBuffer putStringRightPad(String value, int len)
          写入制定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则右补\0
protected  void setByteBuffer(ByteBuffer bytes)
          填充底层ByteBuffer, 之前已有数据将被清除, 并且通过参数ByteBuffer的其他引用对对象的更改将影响底层数据。
protected  void setBytes(byte[] bytes)
          填充底层ByteBuffer, 之前已有数据将被清除
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

Packet

public Packet()
构造Packet对象


Packet

public Packet(byte[] bytes)
用指定的字节数组构造Packet对象

参数:
bytes - 代表封包数据的字节数组

Packet

public Packet(ByteBuffer buffer)
用指定的ByteBuffer构造Packet对象

参数:
buffer - ByteBuffer
方法详细信息

getBytes

public byte[] getBytes()
返回底层字节数组

返回:
底层字节数组

getByteBuffer

public ByteBuffer getByteBuffer()
获得底层用于存放数据的ByteBuffer, 返回的ByteBuffer是只读的

返回:
底层ByteBuffer的只读副本

allocate

protected ByteBuffer allocate(int capacity)
为Packet申请底层存储空间。之前已存在的数据将被清除。

参数:
capacity - 存储空间大小

setBytes

protected void setBytes(byte[] bytes)
填充底层ByteBuffer, 之前已有数据将被清除

参数:
bytes - 字节数组

setByteBuffer

protected void setByteBuffer(ByteBuffer bytes)
填充底层ByteBuffer, 之前已有数据将被清除, 并且通过参数ByteBuffer的其他引用对对象的更改将影响底层数据。

参数:
bytes - ByteBuffer

put

protected ByteBuffer put(byte b)
写入byte

参数:
b - byte
返回:
ByteBuffer

put

protected ByteBuffer put(byte[] src)
写入byte[]

参数:
src - byte[]
返回:
ByteBuffer

put

protected ByteBuffer put(byte[] src,
                         int offset,
                         int length)
写入byte[]

参数:
src - byte[]
offset - byte[]的起始位置
length - 写入长度
返回:
ByteBuffer

put

protected ByteBuffer put(ByteBuffer src)
写入ByteBuffer

参数:
src - ByteBuffer
返回:
ByteBuffer

put

protected ByteBuffer put(int index,
                         byte b)
写入byte到ByteBuffer指定位置

参数:
index - ByteBuffer中指定位置
b - byte
返回:
ByteBuffer

putChar

protected ByteBuffer putChar(char value)
写入char

参数:
value - char
返回:
ByteBuffer

putChar

protected ByteBuffer putChar(int index,
                             char value)
写入char到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - char
返回:
ByteBuffer

putDouble

protected ByteBuffer putDouble(double value)
写入double

参数:
value - double
返回:
ByteBuffer

putDouble

protected ByteBuffer putDouble(int index,
                               double value)
写入double到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - double
返回:
ByteBuffer

putFloat

protected ByteBuffer putFloat(float value)
写入float

参数:
value - float
返回:
ByteBuffer

putFloat

protected ByteBuffer putFloat(int index,
                              float value)
写入float到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - float
返回:
ByteBuffer

putInt

protected ByteBuffer putInt(int value)
写入int

参数:
value - int
返回:
ByteBuffer

putInt

protected ByteBuffer putInt(int index,
                            int value)
写入int到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - int
返回:
ByteBuffer

putLong

protected ByteBuffer putLong(long value)
写入long

参数:
value - long
返回:
ByteBuffer

putLong

protected ByteBuffer putLong(int index,
                             long value)
写入long到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - long
返回:
ByteBuffer

putShort

protected ByteBuffer putShort(short value)
写入short

参数:
value - short
返回:
ByteBuffer

putShort

protected ByteBuffer putShort(int index,
                              short value)
写入short到ByteBuffer指定位置

参数:
index - ByteBuffer指定位置
value - short
返回:
ByteBuffer

putString

protected ByteBuffer putString(String value)
写入指定字串

参数:
value - 字符串
返回:
底层缓冲区ByteBuffer

putString

protected ByteBuffer putString(String value,
                               int beginIndex,
                               int endIndex)
写入指定字串

参数:
value - 准备写入的字串
beginIndex - 字串起始字符位置
endIndex - 字串终止字符位置
返回:
底层缓冲区ByteBuffer

putStringLeftPad

protected ByteBuffer putStringLeftPad(String value,
                                      int len)
写入指定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则左补\0

参数:
value - 字符串
len - 写入长度
返回:
底层缓冲区ByteBuffer

putStringRightPad

protected ByteBuffer putStringRightPad(String value,
                                       int len)
写入制定字串的特定长度到缓冲区, 如果字串为null或者字串长度不足, 则右补\0

参数:
value - 字符串
len - 写入长度
返回:
底层缓冲区ByteBuffer

get

protected byte get()
取得一个byte(相对)

返回:
byte

get

protected ByteBuffer get(byte[] desc)
取得byte[]

参数:
desc - 目的byte[]
返回:
底层ByteBuffer

get

protected ByteBuffer get(byte[] dst,
                         int offset,
                         int length)
取得byte[]

参数:
dst - 目的byte[]
offset - dst起始位置
length - 读取长度
返回:
底层ByteBuffer

get

protected byte get(int index)
取得byte(绝对)

参数:
index - ByteBuffer绝对位置
返回:
int

getChar

protected char getChar()
取得char(相对)

返回:
char

getChar

protected char getChar(int index)
取得char(绝对)

参数:
index - ByteBuffer绝对位置
返回:
char

getDouble

protected double getDouble()
取得double(相对)

返回:
double

getDouble

protected double getDouble(int index)
取得double(绝对)

参数:
index - ByteBuffer绝对位置
返回:
double

getFloat

protected float getFloat()
取得float(相对)

返回:
float

getFloat

protected float getFloat(int index)
取得float(绝对)

参数:
index - ByteBuffer绝对位置
返回:
float

getInt

protected int getInt()
取得int(相对)

返回:
int

getInt

protected int getInt(int index)
取得int(绝对)

参数:
index - ByteBuffer绝对位置
返回:
int

getLong

protected long getLong()
取得long(相对)

返回:
long

getLong

protected long getLong(int index)
取得long(绝对)

参数:
index - ByteBuffer绝对位置
返回:
long

getShort

protected short getShort()
取得short(相对)

返回:
short

getShort

protected short getShort(int index)
取得short(绝对)

参数:
index - ByteBuffer绝对位置
返回:
short

getString

protected String getString(int length)
取得指定长度的字符串

参数:
length - 长度
返回:
字符串


Copyright © 2016. All rights reserved.