org.red5.io.amf3.Input.RefStorage refStorage = new org.red5.io.amf3.Input.RefStorage();
Input input = new org.red5.io.amf.Input(in);
String action = Deserializer.deserialize(input, String.class);
int transactionId = Deserializer.<Number> deserialize(input, Number.class).intValue();
FlexMessage msg = new FlexMessage();
msg.setTransactionId(transactionId);
Object[] params = new Object[] {};
if (in.hasRemaining()) {
ArrayList<Object> paramList = new ArrayList<Object>();
final Object obj = Deserializer.deserialize(input, Object.class);
if (obj != null) {
paramList.add(obj);
}
while (in.hasRemaining()) {
// Check for AMF3 encoding of parameters
byte objectEncodingType = in.get();
in.position(in.position() - 1);
log.debug("Object encoding: {}", objectEncodingType);
switch (objectEncodingType) {
case AMF.TYPE_AMF3_OBJECT:
case AMF3.TYPE_VECTOR_NUMBER:
case AMF3.TYPE_VECTOR_OBJECT:
// The next parameter is encoded using AMF3
input = new org.red5.io.amf3.Input(in, refStorage);
// Vectors with number and object have to have AMF3 forced
((org.red5.io.amf3.Input) input).enforceAMF3();
break;
case AMF3.TYPE_VECTOR_INT:
case AMF3.TYPE_VECTOR_UINT:
// The next parameter is encoded using AMF3
input = new org.red5.io.amf3.Input(in, refStorage);
break;
default:
// The next parameter is encoded using AMF0
input = new org.red5.io.amf.Input(in);
}
paramList.add(Deserializer.deserialize(input, Object.class));
}
params = paramList.toArray();
if (log.isTraceEnabled()) {
log.trace("Parameter count: {}", paramList.size());
for (int i = 0; i < params.length; i++) {
log.trace(" > {}: {}", i, params[i]);
}
}
}
final int dotIndex = action.lastIndexOf('.');
String serviceName = (dotIndex == -1) ? null : action.substring(0, dotIndex);
String serviceMethod = (dotIndex == -1) ? action : action.substring(dotIndex + 1, action.length());
log.debug("Service name: {} method: {}", serviceName, serviceMethod);
PendingCall call = new PendingCall(serviceName, serviceMethod, params);
msg.setCall(call);
return msg;
}