yy1717
2021-02-03 026e1750503ec74bbe181bce3ece9931c244e367
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.safeluck.aykj.decoder;
 
import com.safeluck.aykj.annotation.Int16;
import com.safeluck.aykj.utils.BytesUtils;
 
 
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);
    }
}