*/
protected void encodeNotifyOrInvoke(ByteBuffer out, Notify invoke, RTMP rtmp) {
// TODO: tidy up here
// log.debug("Encode invoke");
Output output = new org.red5.io.amf.Output(out);
final IServiceCall call = invoke.getCall();
final boolean isPending = (call.getStatus() == Call.STATUS_PENDING);
if (!isPending) {
if (log.isDebugEnabled()) {
log.debug("Call has been executed, send result");
}
serializer.serialize(output, call.isSuccess() ? "_result" : "_error"); // seems right
} else {
if (log.isDebugEnabled()) {
log.debug("This is a pending call, send request");
}
final String action = (call.getServiceName() == null) ? call
.getServiceMethodName() : call.getServiceName() + '.'
+ call.getServiceMethodName();
serializer.serialize(output, action); // seems right
}
if (invoke instanceof Invoke) {
serializer.serialize(output, Integer.valueOf(invoke.getInvokeId()));
serializer.serialize(output, invoke.getConnectionParams());
}
if (call.getServiceName() == null && "connect".equals(call.getServiceMethodName())) {
// Response to initial connect, always use AMF0
output = new org.red5.io.amf.Output(out);
} else {
if (rtmp.getEncoding() == Encoding.AMF3) {
output = new org.red5.io.amf3.Output(out);
} else {
output = new org.red5.io.amf.Output(out);
}
}
if (!isPending && (invoke instanceof Invoke)) {
IPendingServiceCall pendingCall = (IPendingServiceCall) call;
if (!call.isSuccess()) {
StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
pendingCall.setResult(status);
}
if (log.isDebugEnabled()) {
log.debug("Writing result: " + pendingCall.getResult());
}