Serialize text size on 4 bytes
This will allow to send text having a size greater than 65535 bytes.
This commit is contained in:
@@ -16,7 +16,7 @@ public class ControlMessageReader {
|
||||
|
||||
private static final int MESSAGE_MAX_SIZE = 4096;
|
||||
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = MESSAGE_MAX_SIZE - 4; // type: 1 byte; paste flag: 1 byte; length: 2 bytes
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = MESSAGE_MAX_SIZE - 6; // type: 1 byte; paste flag: 1 byte; length: 4 bytes
|
||||
public static final int INJECT_TEXT_MAX_LENGTH = 300;
|
||||
|
||||
private final byte[] rawBuffer = new byte[MESSAGE_MAX_SIZE];
|
||||
@@ -103,10 +103,10 @@ public class ControlMessageReader {
|
||||
}
|
||||
|
||||
private String parseString() {
|
||||
if (buffer.remaining() < 2) {
|
||||
if (buffer.remaining() < 4) {
|
||||
return null;
|
||||
}
|
||||
int len = toUnsigned(buffer.getShort());
|
||||
int len = buffer.getInt();
|
||||
if (buffer.remaining() < len) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets;
|
||||
public class DeviceMessageWriter {
|
||||
|
||||
private static final int MESSAGE_MAX_SIZE = 4096;
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = MESSAGE_MAX_SIZE - 3; // type: 1 byte; length: 2 bytes
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = MESSAGE_MAX_SIZE - 5; // type: 1 byte; length: 4 bytes
|
||||
|
||||
private final byte[] rawBuffer = new byte[MESSAGE_MAX_SIZE];
|
||||
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
|
||||
@@ -21,7 +21,7 @@ public class DeviceMessageWriter {
|
||||
String text = msg.getText();
|
||||
byte[] raw = text.getBytes(StandardCharsets.UTF_8);
|
||||
int len = StringUtils.getUtf8TruncationIndex(raw, CLIPBOARD_TEXT_MAX_LENGTH);
|
||||
buffer.putShort((short) len);
|
||||
buffer.putInt(len);
|
||||
buffer.put(raw, 0, len);
|
||||
output.write(rawBuffer, 0, buffer.position());
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user