package com.safeluck.aykj.decoder;
|
|
import com.safeluck.aykj.annotation.Int16;
|
import com.safeluck.aykj.utils.BytesUtils;
|
|
/**
|
* Created by zhouwei on 2016/12/1.
|
*/
|
public class Int16Coder extends BaseDecoder<Integer> {
|
|
public static Int16Coder instance = new Int16Coder();
|
|
@Override
|
public Integer decode(String str) {
|
if(str==null||"".equals(str))
|
return 0;
|
return Integer.valueOf(str, 16);
|
}
|
|
@Override
|
public String encode(Integer i) {
|
if(i==null)
|
i=0;
|
byte[] b = new byte[2];
|
b[1]= (byte)(i&0xff);
|
b[0]= (byte)(i >> 8);
|
return BytesUtils.bytesToHexString(b);
|
}
|
}
|