(byte[] rawData)
| 140 | |
| 141 | // 解码响应包(带解密) |
| 142 | public static Response decode(byte[] rawData) { |
| 143 | if (!validate(rawData)) { |
| 144 | return null; |
| 145 | } |
| 146 | ByteBuffer buffer = ByteBuffer.wrap(rawData); |
| 147 | buffer.position(MAGIC_PREFIX.length); |
| 148 | byte type = buffer.get(); |
| 149 | int length = buffer.getInt(); |
| 150 | byte status = buffer.get(); |
| 151 | |
| 152 | // 读取并解密数据 |
| 153 | byte[] encryptedData = null; |
| 154 | if (length > 1) { // length包含status的1字节 |
| 155 | encryptedData = new byte[length - 1]; |
| 156 | buffer.get(encryptedData); |
| 157 | encryptedData = xorProcess(encryptedData); |
| 158 | } |
| 159 | |
| 160 | return new Response(type, status, encryptedData); |
| 161 | } |
| 162 | |
| 163 | // 获取原始数据 |
| 164 | public byte[] getData() { |
no test coverage detected