Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1502951
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: Java

2016-01-18 00:40:06

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();
}
}

阅读(944) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~