byte[] encode(Version version, Routable obj) {
        int type = obj.getType();
        RoutableFactory factory = getFactory(version, type);
        if (factory == null) {
            log.log(Level.SEVERE,"No routable factory found for routable type " + type + " (version " + version + ").");
            return new byte[0];
        }
        if (version.getMajor() < 5) {
            log.log(Level.SEVERE,"Can not encode routable type " + type + " (version " + version + "). Only major version 5 and up supported.");
            return new byte[0];
        }
        byte[] ret = factory.encode(type, obj);
        if (ret == null) {
            log.log(Level.SEVERE, "Routable factory " + factory.getClass().getName() + " failed to serialize " +
                                    "routable of type " + type + " (version " + version + ").");
            return new byte[0];
        }
        return ret;
    }
Encodes a {@link Routable} into a byte array. This dispatches the encode request to the appropriate {@link
RoutableFactory} that was previously registered.

If a routable can not be encoded, this method returns an empty byte array.

@param version The version to encode the routable as.
@param obj     The routable to encode.
@return The byte array containing the encoded routable.
documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableRepository.java