* @param in
* @param header
* @return decoded notify result
*/
public Notify decodeNotify(Encoding encoding, IoBuffer in, Header header) {
Notify notify = new Notify();
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) {
//TODO Handle NetStream.send? Where and how?
if (header != null && header.getStreamId() != 0 && !isStreamCommand(action)) {
// don't decode "NetStream.send" requests
in.position(start);
notify.setData(in.asReadOnlyBuffer());
return notify;
}
if (header == null || header.getStreamId() == 0) {
int invokeId = Deserializer.<Number> deserialize(input, Number.class).intValue();
if (invokeId != 0) {
throw new RuntimeException("Notify invoke / transaction id was non-zero");
}
}
// 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, notify, input);
// determine service information
final int dotIndex = action.lastIndexOf('.');
String serviceName = (dotIndex == -1) ? null : action.substring(0, dotIndex);
// pull off the prefixes since java doesn't 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 doesnt allow this on a method name
if (serviceMethod.startsWith("@") || serviceMethod.startsWith("|")) {
serviceMethod = serviceMethod.substring(1);
}
Call call = new Call(serviceName, serviceMethod, params);
notify.setCall(call);
return notify;
} else {
//TODO replace this with something better as time permits
throw new RuntimeException("Action was null");
}