Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1480906
  • 博文数量: 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:42:10

package com.dd.model.protocol;






public class FieldDecoder
{
Field field;
private String serialData;
private byte serialByte[];
public FieldDecoder(byte serialByte[])
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < serialByte.length; i++)
{
sb.append(String.format("%02x", serialByte[i]));
}
this.serialData = sb.toString();
this.serialByte = serialByte;
}
public Field doDecoder()
{
TTLDecoder ttlDecoder = new TTLDecoder(getTTLbyteSerial());
TTL ttl = ttlDecoder.doDecoder();

ValueDecoder valueDecoder = new ValueDecoder(ttl.getType(),getValueByteSerial());

Value value = valueDecoder.doDecoder();
Field field = new  Field( ttl,  value);
return field;
}
private byte []getTTLbyteSerial()
{
byte [] result = new byte[6];//2+2+2
for (int i = 0; i < result.length; i++)
{
result[i] = serialByte[i];

}
return result;
}
private byte []getValueByteSerial()
{
int ttlByteLen = 6;//2+2+2
byte [] result = new byte[serialByte.length - ttlByteLen];
for (int i = 0; i < result.length; i++)
{
result[i] = serialByte[i+ttlByteLen];

}
return result;
}
}

阅读(781) | 评论(0) | 转发(0) |
0

上一篇:Field.java

下一篇:IProtocolBase

给主人留下些什么吧!~~