}
}
/** {@inheritDoc} */
public Invoke decodeInvoke(Encoding encoding, IoBuffer in) {
Invoke invoke = new Invoke();
int start = in.position();
Input input;
// for response, the action string and invokeId is always encoded as AMF0 we use the first byte to decide which encoding to use.
byte tmp = in.get();
in.position(start);
if (encoding == Encoding.AMF3 && tmp == AMF.TYPE_AMF3_OBJECT) {
input = new org.red5.io.amf3.Input(in);
((org.red5.io.amf3.Input) input).enforceAMF3();
} else {
input = new org.red5.io.amf.Input(in);
}
// get the action
String action = Deserializer.deserialize(input, String.class);
if (log.isTraceEnabled()) {
log.trace("Action " + action);
}
//throw a runtime exception if there is no action
if (action != null) {
invoke.setTransactionId(Deserializer.<Number> deserialize(input, Number.class).intValue());
// now go back to the actual encoding to decode parameters
if (encoding == Encoding.AMF3) {
input = new org.red5.io.amf3.Input(in);
((org.red5.io.amf3.Input) input).enforceAMF3();
} else {
input = new org.red5.io.amf.Input(in);
}
// get / set the parameters if there any
Object[] params = handleParameters(in, invoke, input);
// determine service information
final int dotIndex = action.lastIndexOf('.');
String serviceName = (dotIndex == -1) ? null : action.substring(0, dotIndex);
// pull off the prefixes since java doesnt allow this on a method name
if (serviceName != null && (serviceName.startsWith("@") || serviceName.startsWith("|"))) {
serviceName = serviceName.substring(1);
}
String serviceMethod = (dotIndex == -1) ? action : action.substring(dotIndex + 1, action.length());
// pull off the prefixes since java doesn't allow this on a method name
if (serviceMethod.startsWith("@") || serviceMethod.startsWith("|")) {
serviceMethod = serviceMethod.substring(1);
}
PendingCall call = new PendingCall(serviceName, serviceMethod, params);
invoke.setCall(call);
return invoke;
} else {
//TODO replace this with something better as time permits
throw new RuntimeException("Action was null");
}