org.red5.io.object.Output Java Examples

The following examples show how to use org.red5.io.object.Output. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusObject.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
public void serialize(Output output) {
    output.putString("level");
    output.writeString(getLevel());
    output.putString("code");
    output.writeString(getCode());
    output.putString("description");
    output.writeString(getDescription());
    if (application != null) {
        output.putString("application");
        Serializer.serialize(output, application);
    }
    if (additional != null) {
        // Add additional parameters
        for (Map.Entry<String, Object> entry : additional.entrySet()) {
            output.putString(entry.getKey());
            Serializer.serialize(output, entry.getValue());
        }
    }
}
 
Example #2
Source File: Status.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
public void serialize(Output output) {
    output.putString("level");
    output.writeString(getLevel());
    output.putString("code");
    output.writeString(getCode());
    output.putString("description");
    output.writeString(getDescription());
    output.putString("details");
    if (getDetails() != null) {
        output.writeString(getDetails());
    } else {
        output.writeNull();
    }
    output.putString("clientid");
    output.writeNumber(getClientid());
}
 
Example #3
Source File: SharedObject.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void serialize(Output output) throws IOException {
    log.debug("serialize - name: {}", name);
    Serializer.serialize(output, getName());
    Map<String, Object> map = getAttributes();
    if (log.isTraceEnabled()) {
        log.trace("Attributes: {}", map);
    }
    Serializer.serialize(output, map);
}
 
Example #4
Source File: RTMPProtocolEncoder.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Encode command event and fill given byte buffer.
 *
 * @param out
 *            Buffer to fill
 * @param command
 *            Command event
 */
protected void encodeCommand(IoBuffer out, ICommand command) {
    // TODO: tidy up here
    Output output = new org.red5.io.amf.Output(out);
    final IServiceCall call = command.getCall();
    final boolean isPending = (call.getStatus() == Call.STATUS_PENDING);
    log.debug("Call: {} pending: {}", call, isPending);
    if (!isPending) {
        log.debug("Call has been executed, send result");
        Serializer.serialize(output, call.isSuccess() ? "_result" : "_error");
    } else {
        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 (command instanceof Invoke) {
        Serializer.serialize(output, Integer.valueOf(command.getTransactionId()));
        Serializer.serialize(output, command.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 (Red5.getConnectionLocal().getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        } else {
            output = new org.red5.io.amf.Output(out);
        }
    }
    if (!isPending && (command instanceof Invoke)) {
        IPendingServiceCall pendingCall = (IPendingServiceCall) call;
        if (!call.isSuccess() && (call.getException() != null || pendingCall.getResult() == null)) {
            log.debug("Call was not successful");
            StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
            pendingCall.setResult(status);
        }
        Object res = pendingCall.getResult();
        log.debug("Writing result: {}", res);
        Serializer.serialize(output, res);
    } else {
        log.debug("Writing params");
        final Object[] args = call.getArguments();
        if (args != null) {
            for (Object element : args) {
                if (element instanceof ByteBuffer) {
                    // a byte buffer indicates that serialization is already complete, send raw
                    final ByteBuffer buf = (ByteBuffer) element;
                    buf.mark();
                    try {
                        out.put(buf);
                    } finally {
                        buf.reset();
                    }
                } else {
                    // standard serialize
                    Serializer.serialize(output, element);
                }
            }
        }
    }
    if (command.getData() != null) {
        out.setAutoExpand(true);
        out.put(command.getData());
    }
}
 
Example #5
Source File: RTMPClientProtocolEncoder.java    From red5-client with Apache License 2.0 4 votes vote down vote up
/**
 * Encode notification event and fill given byte buffer.
 *
 * @param out
 *            Byte buffer to fill
 * @param command
 *            Notification event
 */
@Override
protected void encodeCommand(IoBuffer out, ICommand command) {
    log.debug("encodeCommand - command: {}", command);
    RTMPConnection conn = (RTMPConnection) Red5.getConnectionLocal();
    Output output = new org.red5.io.amf.Output(out);
    final IServiceCall call = command.getCall();
    final boolean isPending = (call.getStatus() == Call.STATUS_PENDING);
    log.debug("Call: {} pending: {}", call, isPending);
    if (!isPending) {
        log.debug("Call has been executed, send result");
        Serializer.serialize(output, call.isSuccess() ? "_result" : "_error");
    } else {
        log.debug("This is a pending call, send request");
        // for request we need to use AMF3 for client mode if the connection is AMF3
        if (conn.getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        }
        final String action = (call.getServiceName() == null) ? call.getServiceMethodName() : call.getServiceName() + '.' + call.getServiceMethodName();
        Serializer.serialize(output, action);
    }
    if (command instanceof Invoke) {
        Serializer.serialize(output, Integer.valueOf(command.getTransactionId()));
        Serializer.serialize(output, command.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 (conn.getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        } else {
            output = new org.red5.io.amf.Output(out);
        }
    }
    if (!isPending && (command instanceof Invoke)) {
        IPendingServiceCall pendingCall = (IPendingServiceCall) call;
        if (!call.isSuccess()) {
            log.debug("Call was not successful");
            StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
            pendingCall.setResult(status);
        }
        Object res = pendingCall.getResult();
        log.debug("Writing result: {}", res);
        Serializer.serialize(output, res);
    } else {
        log.debug("Writing params");
        final Object[] args = call.getArguments();
        if (args != null) {
            for (Object element : args) {
                Serializer.serialize(output, element);
            }
        }
    }
    if (command.getData() != null) {
        out.setAutoExpand(true);
        out.put(command.getData());
    }
}
 
Example #6
Source File: IPersistable.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Write the object to the passed output stream.
 * 
 * @param output
 *            Output stream to write to
 * @throws java.io.IOException
 *             Any I/O exception
 */
void serialize(Output output) throws IOException;