}
break;
}
case EVENT: {
ByteBufInputStream in = new ByteBufInputStream(buffer);
Event event = jsonSupport.readValue(in, Event.class);
packet.setName(event.getName());
if (event.getArgs() != null) {
packet.setArgs(event.getArgs());
}
break;
}
case JSON: {
ByteBufInputStream in = new ByteBufInputStream(buffer);
JsonObject obj = jsonSupport.readValue(in, JsonObject.class);
if (obj != null) {
packet.setData(obj.getObject());
} else {
in.reset();
Object object = jsonSupport.readValue(in, Object.class);
packet.setData(object);
}
break;
}
case CONNECT: {
if (buffer.isReadable()) {
packet.setQs(buffer.toString(CharsetUtil.UTF_8));
}
break;
}
case ACK: {
if (!buffer.isReadable()) {
break;
}
boolean validFormat = true;
int plusIndex = -1;
for (int i = buffer.readerIndex(); i < buffer.readerIndex() + buffer.readableBytes(); i++) {
byte dataChar = buffer.getByte(i);
if (!Character.isDigit(dataChar)) {
if (dataChar == '+') {
plusIndex = i;
break;
} else {
validFormat = false;
break;
}
}
}
if (!validFormat) {
break;
}
if (plusIndex == -1) {
packet.setAckId(parseLong(buffer));
break;
} else {
packet.setAckId(parseLong(buffer, plusIndex));
buffer.readerIndex(plusIndex+1);
ByteBufInputStream in = new ByteBufInputStream(buffer);
AckCallback<?> callback = ackManager.getCallback(uuid, packet.getAckId());
AckArgs args = jsonSupport.readAckArgs(in, callback);
packet.setArgs(args.getArgs());
}
break;