orogen_transports::TypelibMarshallerBase* orogen_transports::getMarshallerFor(std::string const& type)
{
    RTT::types::TypeInfoRepository::shared_ptr type_registry =
        RTT::types::TypeInfoRepository::Instance();
    RTT::types::TypeInfo* ti = type_registry->type(type);
    if (!ti)
    {
	// Try harder. Some base types don't have a
	// typelib-normalized name, so we should look
	// for the type without the leading slash
	ti = type_registry->type(type.substr(1));
	if (!ti)
	    throw std::runtime_error("type " + type + " is not registered in the RTT type system");
    }

    if (!ti->hasProtocol(orogen_transports::TYPELIB_MARSHALLER_ID))
        throw std::runtime_error("type " + type + " is registered in the RTT type system, but does not have a typelib transport");

    orogen_transports::TypelibMarshallerBase* typelib_marshaller =
        dynamic_cast<orogen_transports::TypelibMarshallerBase*>(ti->getProtocol(orogen_transports::TYPELIB_MARSHALLER_ID));
    if (!typelib_marshaller)
        throw std::runtime_error("the transport object registered as typelib transport for type " + type + " is not a TypelibMarshallerBase");

    return typelib_marshaller;
}