#
luxiaotao1123
2020-08-04 6abc20e29568c129f4ca71eccec9310534a8c779
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package com.zy.common.HslCommunication.Core.Transfer;
 
import com.zy.common.HslCommunication.Utilities;
 
/**
 * 反转的字节变换类
 */
public class ReverseBytesTransform extends ByteTransformBase
{
 
    /**
     * 从缓存中提取short结果
     * @param buffer 缓存数据
     * @param index 索引位置
     * @return short对象
     */
    @Override
    public short TransInt16( byte[] buffer, int index ) {
        byte[] tmp = new byte[2];
        tmp[0] = buffer[1 + index];
        tmp[1] = buffer[0 + index];
        return Utilities.getShort(tmp, 0);
    }
 
 
    /**
     * 从缓存中提取int结果
     * @param buffer 缓存数据
     * @param index 索引位置
     * @return int对象
     */
    @Override
    public int TransInt32( byte[] buffer, int index ) {
        byte[] tmp = new byte[4];
        tmp[0] = buffer[3 + index];
        tmp[1] = buffer[2 + index];
        tmp[2] = buffer[1 + index];
        tmp[3] = buffer[0 + index];
        return Utilities.getInt(ByteTransDataFormat4(tmp),0);
    }
 
 
 
 
    /**
     * 从缓存中提取long结果
     * @param buffer 缓存数据
     * @param index 索引位置
     * @return long对象
     */
    @Override
    public long TransInt64( byte[] buffer, int index ) {
        byte[] tmp = new byte[8];
        tmp[0] = buffer[7 + index];
        tmp[1] = buffer[6 + index];
        tmp[2] = buffer[5 + index];
        tmp[3] = buffer[4 + index];
        tmp[4] = buffer[3 + index];
        tmp[5] = buffer[2 + index];
        tmp[6] = buffer[1 + index];
        tmp[7] = buffer[0 + index];
        return Utilities.getLong(ByteTransDataFormat8(tmp), 0);
    }
 
 
 
    /**
     * 从缓存中提取float结果
     * @param buffer 缓存对象
     * @param index 索引位置
     * @return float对象
     */
    @Override
    public float TransSingle( byte[] buffer, int index ) {
        byte[] tmp = new byte[4];
        tmp[0] = buffer[3 + index];
        tmp[1] = buffer[2 + index];
        tmp[2] = buffer[1 + index];
        tmp[3] = buffer[0 + index];
        return Utilities.getFloat(ByteTransDataFormat4(tmp), 0);
    }
 
 
    /**
     * 从缓存中提取double结果
     * @param buffer 缓存对象
     * @param index 索引位置
     * @return double对象
     */
    @Override
    public double TransDouble( byte[] buffer, int index ) {
        byte[] tmp = new byte[8];
        tmp[0] = buffer[7 + index];
        tmp[1] = buffer[6 + index];
        tmp[2] = buffer[5 + index];
        tmp[3] = buffer[4 + index];
        tmp[4] = buffer[3 + index];
        tmp[5] = buffer[2 + index];
        tmp[6] = buffer[1 + index];
        tmp[7] = buffer[0 + index];
        return Utilities.getDouble(ByteTransDataFormat8(tmp), 0);
    }
 
 
 
 
 
 
    /**
     * short数组变量转化缓存数据
     * @param values 等待转化的数组
     * @return buffer数据
     */
    @Override
    public byte[] TransByte( short[] values ) {
        if (values == null) return null;
 
        byte[] buffer = new byte[values.length * 2];
        for (int i = 0; i < values.length; i++) {
            byte[] tmp = Utilities.getBytes(values[i]);
            Utilities.bytesReverse(tmp);
            System.arraycopy(tmp, 0, buffer, 2 * i, tmp.length);
        }
 
        return buffer;
    }
 
 
 
    /**
     * int数组变量转化缓存数据
     * @param values 等待转化的数组
     * @return buffer数据
     */
    @Override
    public byte[] TransByte( int[] values ) {
        if (values == null) return null;
 
        byte[] buffer = new byte[values.length * 4];
        for (int i = 0; i < values.length; i++) {
            byte[] tmp = Utilities.getBytes(values[i]);
            Utilities.bytesReverse(tmp);
            System.arraycopy(ByteTransDataFormat4(tmp), 0, buffer, 4 * i, tmp.length);
        }
 
        return buffer;
    }
 
 
    /**
     * long数组变量转化缓存数据
     * @param values 等待转化的数组
     * @return buffer数据
     */
    @Override
    public byte[] TransByte( long[] values ) {
        if (values == null) return null;
 
        byte[] buffer = new byte[values.length * 8];
        for (int i = 0; i < values.length; i++) {
            byte[] tmp = Utilities.getBytes(values[i]);
            Utilities.bytesReverse(tmp);
            System.arraycopy(ByteTransDataFormat8(tmp), 0, buffer, 8 * i, tmp.length);
        }
 
        return buffer;
    }
 
 
 
    /**
     * float数组变量转化缓存数据
     * @param values 等待转化的数组
     * @return buffer数据
     */
    @Override
    public byte[] TransByte( float[] values ) {
        if (values == null) return null;
 
        byte[] buffer = new byte[values.length * 4];
        for (int i = 0; i < values.length; i++) {
            byte[] tmp = Utilities.getBytes(values[i]);
            Utilities.bytesReverse(tmp);
            System.arraycopy(ByteTransDataFormat4(tmp), 0, buffer, 4 * i, tmp.length);
        }
 
        return buffer;
    }
 
 
 
    /**
     * double数组变量转化缓存数据
     * @param values 等待转化的数组
     * @return buffer数据
     */
    @Override
    public byte[] TransByte( double[] values ) {
        if (values == null) return null;
 
        byte[] buffer = new byte[values.length * 8];
        for (int i = 0; i < values.length; i++) {
            byte[] tmp = Utilities.getBytes(values[i]);
            Utilities.bytesReverse(tmp);
            System.arraycopy(ByteTransDataFormat8(tmp), 0, buffer, 8 * i, tmp.length);
        }
 
        return buffer;
    }
 
 
}