remote proxy bugfix: the magic of signed bytes
This commit is contained in:
parent
09c5d28f7f
commit
2cbcbe5697
|
@ -65,4 +65,8 @@ public class IoHelper {
|
|||
public static boolean checkResponseCode(byte[] response, byte code) {
|
||||
return response != null && response.length > 0 && response[0] == code;
|
||||
}
|
||||
|
||||
public static int getInt(byte firstByte, byte secondByte) {
|
||||
return firstByte * 256 + (secondByte & 0xFF);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.rusefi.Listener;
|
|||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
|
@ -80,7 +81,7 @@ public class BinaryProtocolProxy {
|
|||
@NotNull
|
||||
private static BinaryProtocolServer.Packet readClientRequest(IncomingDataBuffer in, byte firstByte) throws IOException {
|
||||
byte secondByte = in.readByte();
|
||||
int length = firstByte * 256 + secondByte;
|
||||
int length = IoHelper.getInt(firstByte, secondByte);
|
||||
|
||||
return BinaryProtocolServer.readPromisedBytes(in, length);
|
||||
}
|
||||
|
|
|
@ -367,7 +367,8 @@ public class BinaryProtocolServer {
|
|||
protocolCommandHandler.handle();
|
||||
return 0;
|
||||
}
|
||||
return first * 256 + in.readByte(ioTimeout);
|
||||
byte secondByte = in.readByte(ioTimeout);
|
||||
return IoHelper.getInt(first, secondByte);
|
||||
}
|
||||
|
||||
public static Packet readPromisedBytes(DataInputStream in, int length) throws IOException {
|
||||
|
|
|
@ -10,6 +10,11 @@ import java.io.IOException;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IoHelperTest {
|
||||
@Test
|
||||
public void test255() {
|
||||
assertEquals(255, IoHelper.getInt((byte) 0, (byte) -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwap16() throws IOException {
|
||||
byte packet[] = {-12, 0};
|
||||
|
|
Loading…
Reference in New Issue