// Remove the read packet
packets.remove(channel);
// Decode result
final TypedObject result;
if (p.getType() == 0x14) // Connect
result = adc.decodeConnect(p.getData());
else if (p.getType() == 0x11) // Invoke
result = adc.decodeInvoke(p.getData());
else if (p.getType() == 0x06) // Set peer bandwidth
{
byte[] data = p.getData();
int windowSize = 0;
for (int i = 0; i < 4; i++)
windowSize = windowSize * 256 + (data[i] & 0xFF);
int type = data[4];
continue;
}
else if (p.getType() == 0x03) // Ack
{
byte[] data = p.getData();
int ackSize = 0;
for (int i = 0; i < 4; i++)
ackSize = ackSize * 256 + (data[i] & 0xFF);
continue;
}
else
// Skip most messages
{
System.out.println("Unrecognized message type");
System.out.print(String.format("%02X ", p.getType()));
for (byte b : p.getData())
System.out.print(String.format("%02X", b & 0xff));
System.out.println();
continue;
}
// Store result
Integer id = result.getInt("invokeId");
// Receive handler
if (id == null || id == 0) {
if (receiveCallback != null)
receiveCallback.callback(result);