package com.safeluck.aykj.decoder;
|
|
import com.safeluck.aykj.annotation.Int32;
|
import com.safeluck.aykj.utils.BytesUtils;
|
|
/**
|
* Created by zhouwei on 2016/12/1.
|
*/
|
public class Int32Coder extends BaseDecoder<Integer> {
|
|
public static Int32Coder instance = new Int32Coder();
|
|
@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;
|
//高位在前 32位整数
|
int num = i.intValue();
|
byte[] b = new byte[4];
|
b[3]= (byte)(num&0xff);
|
b[2]= (byte)(num >> 8);
|
b[1]= (byte)(num >> 16);
|
b[0]= (byte)(num >> 24);
|
return BytesUtils.bytesToHexString(b);
|
}
|
}
|