package com.dd.model.protocol;
import java.util.ArrayList;
public class CmdLogin implements IProtocolBase
{
Field version;
Field cmd;
Field handle;
Field userName;
Field password;
Field crc;
ArrayList
fieldList = new ArrayList();
public CmdLogin(Field version, Field cmd, Field handle, Field userName, Field password)
{
super();
this.version = version;
this.cmd = cmd;
this.handle = handle;
this.userName = userName;
this.password = password;
fieldList.add(version);
fieldList.add(cmd);
fieldList.add(handle);
fieldList.add(userName);
fieldList.add(password);
}
@Override
public int getTotalLen()
{
int result = 0;
for (Field field : fieldList)
{
result +=field.getTotalLen();
}
return result;
}
@Override
public int getSerialTotalLen()
{
int result = 0;
for (Field field : fieldList)
{
result +=field.getSerialTotalLen();
}
return result;
}
@Override
public byte[] serial()
{
int len = getTotalLen();
byte result[] = new byte[len];
int offset = 0;
for (Field field : fieldList)
{
byte array[] = field.serial();
for (int i = 0; i < array.length; i++)
{
result[offset + i] = array[i];
}
offset += array.length;
}
return result;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
for (Field field : fieldList)
{
sb.append(field.toString());
}
return sb.toString();
}
}
阅读(951) | 评论(0) | 转发(0) |