web::http::uri generate_queue_uri(const web::http::uri& base_uri, const utility::string_t& prefix, bool get_metadata, int max_results, const continuation_token& token)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);

        if (!prefix.empty())
        {
            builder.append_query(core::make_query_parameter(uri_query_prefix, prefix));
        }

        if (get_metadata)
        {
            builder.append_query(core::make_query_parameter(uri_query_include, component_metadata, /* do_encoding */ false));
        }

        if (max_results > 0)
        {
            builder.append_query(core::make_query_parameter(uri_query_max_results, max_results, /* do_encoding */ false));
        }

        if (!token.empty())
        {
            builder.append_query(token.next_marker());
        }

        return builder.to_uri();
    }
    web::http::uri generate_queue_uri(const web::http::uri& base_uri, const utility::string_t& prefix, bool get_metadata, int max_results, const continuation_token& continuation_token)
    {
        if (base_uri.is_empty())
        {
            return web::http::uri();
        }

        web::http::uri_builder builder(base_uri);

        if (!prefix.empty())
        {
            builder.append_query(U("prefix"), prefix);
        }

        if (get_metadata)
        {
            builder.append_query(U("include"), U("metadata"));
        }

        if (max_results >= 0)
        {
            builder.append_query(U("maxresults"), max_results);
        }

        if (!continuation_token.empty())
        {
            builder.append_query(continuation_token.next_marker());
        }

        return builder.to_uri();
    }
    pplx::task<table_query_segment> cloud_table::execute_query_segmented_async(const table_query& query, const continuation_token& token, const table_request_options& options, operation_context context) const
    {
        table_request_options modified_options = get_modified_options(options);
        storage_uri uri = protocol::generate_table_uri(service_client(), *this, query, token);

        std::shared_ptr<core::storage_command<table_query_segment>> command = std::make_shared<core::storage_command<table_query_segment>>(uri);
        command->set_build_request(std::bind(protocol::execute_query, options.payload_format(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
        command->set_authentication_handler(service_client().authentication_handler());
        command->set_location_mode(core::command_location_mode::primary_or_secondary, token.target_location());
        command->set_preprocess_response(std::bind(protocol::preprocess_response<table_query_segment>, table_query_segment(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
        command->set_postprocess_response([] (const web::http::http_response& response, const request_result& result, const core::ostream_descriptor&, operation_context context) -> pplx::task<table_query_segment>
        {
            UNREFERENCED_PARAMETER(context);
            continuation_token next_token = protocol::table_response_parsers::parse_continuation_token(response, result);

            return response.extract_json().then([next_token] (const web::json::value& obj) -> table_query_segment
            {
                table_query_segment query_segment(protocol::table_response_parsers::parse_query_results(obj), std::move(next_token));
                return query_segment;
            });
        });
        return core::executor<table_query_segment>::execute_async(command, modified_options, context);
    }