compatible with engine.io-parser 1.0.7

This commit is contained in:
Naoyuki Kanezawa
2014-06-29 13:29:50 +09:00
parent 18cb59c446
commit f42e993234
2 changed files with 15 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ import java.util.Map;
public class Parser { public class Parser {
private static final int MAX_INT_CHAR_LENGTH = String.valueOf(Integer.MAX_VALUE).length();
public static final int protocol = 3; public static final int protocol = 3;
private static final Map<String, Integer> packets = new HashMap<String, Integer>() {{ private static final Map<String, Integer> packets = new HashMap<String, Integer>() {{
@@ -189,11 +191,23 @@ public class Parser {
while (bufferTail.capacity() > 0) { while (bufferTail.capacity() > 0) {
StringBuilder strLen = new StringBuilder(); StringBuilder strLen = new StringBuilder();
boolean isString = (bufferTail.get(0) & 0xFF) == 0; boolean isString = (bufferTail.get(0) & 0xFF) == 0;
boolean numberTooLong = false;
for (int i = 1; ; i++) { for (int i = 1; ; i++) {
int b = bufferTail.get(i) & 0xFF; int b = bufferTail.get(i) & 0xFF;
if (b == 255) break; if (b == 255) break;
// supports only integer
if (strLen.length() > MAX_INT_CHAR_LENGTH) {
numberTooLong = true;
break;
}
strLen.append(b); strLen.append(b);
} }
if (numberTooLong) {
@SuppressWarnings("unchecked")
DecodePayloadCallback<String> _callback = callback;
_callback.call(err, 0, 1);
return;
}
bufferTail.position(strLen.length() + 1); bufferTail.position(strLen.length() + 1);
bufferTail = bufferTail.slice(); bufferTail = bufferTail.slice();

View File

@@ -3,6 +3,6 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"engine.io": "1.2.2" "engine.io": "1.3.1"
} }
} }