📄 query.java
字号:
package cmpp.v2_0;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
public class Query extends CMPP
{
private final int commandId = CMPP.ID_CMPP_QUERY;
private final int commandLength = 27;
private String Time = null;
private int QueryType = 0;
private String QueryCode = null;
private String Reserve = null;
public Query() {
super(CMPP.ID_CMPP_QUERY);
}
public Query(CMPP cmpp) {
super(cmpp);
}
public int getCommandId() {
return commandId;
}
public int getCommandLength() {
return commandLength;
}
// getter
public String getQueryCode() {
return QueryCode;
}
public void setQueryCode(String queryCode) {
QueryCode = queryCode;
}
public int getQueryType() {
return QueryType;
}
public void setQueryType(int queryType) {
QueryType = queryType;
}
public String getReserve() {
return Reserve;
}
public void setReserve(String reserve) {
Reserve = reserve;
}
public String getTime() {
return Time;
}
public void setTime(String time) {
Time = time;
}
/**
*
*/
protected int parseBody() {
if( super.bodyLength < commandLength ) { //length too short.
return -1;
}
byte[] abyte0 = new byte[21];
int off = 0;
Arrays.fill(abyte0,(byte)0);
CMPP.BytesCopy(super.bodybytes, abyte0, off, off+7, 0);
Time = new String(abyte0, 0, 8);
off += 8;
Arrays.fill(abyte0,(byte)0);
CMPP.BytesCopy(super.bodybytes, abyte0, off, off, 0);
QueryType = CMPP.ByteToInt(abyte0[0]);
off += 1;
Arrays.fill(abyte0,(byte)0);
CMPP.BytesCopy(super.bodybytes, abyte0, off, off+9, 0);
QueryCode = new String(abyte0, 0, 10);
off += 10;
Arrays.fill(abyte0,(byte)0);
CMPP.BytesCopy(super.bodybytes, abyte0, off, off+7, 0);
Reserve = new String(abyte0, 0, 8);
off += 8;
return 0;
}
/**
*
*/
protected int makeBody() {
// make bodybytes
super.bodyLength = commandLength;
super.bodybytes = new byte[super.bodyLength];
Arrays.fill(super.bodybytes,(byte)0);
// make parameter
if( Time == null ) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int timestamp = calendar.get(Calendar.YEAR) * 10000
+ (calendar.get(Calendar.MONTH) + 1) * 100
+ calendar.get(Calendar.DAY_OF_MONTH);
Time = String.valueOf(timestamp);
}
if( QueryCode == null ) {
QueryCode = "";
}
if( Reserve == null ) {
Reserve = "";
}
// make body
int off = 0;
CMPP.BytesCopy(Time.getBytes(), super.bodybytes, 0, 7, off );
off += 8;
super.bodybytes[off] = CMPP.IntToByte(QueryType);
off += 1;
CMPP.BytesCopy(QueryCode.getBytes(), super.bodybytes, 0, 9, off );
off += 10;
CMPP.BytesCopy(Reserve.getBytes(), super.bodybytes, 0, 7, off );
off += 8;
return 0;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Time=" + Time + "\n");
sb.append("QueryType=" + QueryType + "\n");
sb.append("QueryCode=" + QueryCode + "\n");
sb.append("Reserve=" + Reserve + "\n");
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -