package com.dd.model.protocol;
public class Field implements IProtocolBase
{
TTL ttl;
Value value;
public Field()
{
}
public Field(TTL ttl, Value value)
{
super();
this.ttl = ttl;
this.value = value;
ttl.setLen((short)value.getTotalLen());
}
@Override
public int getTotalLen()
{
if((ttl == null) || (value == null))return 0;
else return (ttl.getTotalLen() + value.getTotalLen());
}
@Override
public int getSerialTotalLen()
{
if((ttl == null) || (value == null))return 0;
else return (ttl.getSerialTotalLen() + value.getSerialTotalLen());
}
@Override
public byte[] serial()
{
byte ttlByte[] = ttl.serial();
byte valueByte[] = value.serial();
int totalLen = getTotalLen();
byte result[] = new byte[totalLen];
int i;
for (i = 0; i < ttlByte.length; i++)
{
byte b = ttlByte[i];
result[i] = b;
}
int j;
for (j = 0; j < valueByte.length; j++)
{
byte b = valueByte[j];
result[i+j] = b;
}
return result;
}
@Override
public String toString()
{
return "Field [ttl=" + ttl + ", value=" + value + "]";
}
public TTL getTtl()
{
return ttl;
}
public void setTtl(TTL ttl)
{
this.ttl = ttl;
}
public Value getValue()
{
return value;
}
public void setValue(Value value)
{
this.value = value;
}
}
阅读(785) | 评论(0) | 转发(0) |