Add method to extract LB policy name from service config JSON.

pull/8617/head
Mark D. Roth 8 years ago
parent 4112499c28
commit f2e8a6a138
  1. 16
      src/core/lib/transport/method_config.c
  2. 6
      src/core/lib/transport/method_config.h

@ -181,6 +181,22 @@ void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table,
return value;
}
const char* grpc_service_config_get_lb_policy_name(
grpc_json_tree* service_config) {
grpc_json* json = service_config->root;
if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL;
const char* lb_policy_name = NULL;
for (grpc_json* field = json->child; field != NULL; field = field->next) {
if (field->key == NULL) return NULL;
if (strcmp(field->key, "lb_policy_name") == 0) {
if (lb_policy_name != NULL) return NULL; // Duplicate.
if (field->type != GRPC_JSON_STRING) return NULL;
lb_policy_name = field->value;
}
}
return lb_policy_name;
}
static void* copy_json_tree(void* t) { return grpc_json_tree_ref(t); }
static void destroy_json_tree(void* t) { grpc_json_tree_unref(t); }

@ -54,6 +54,12 @@ grpc_mdstr_hash_table* grpc_method_config_table_create_from_json(
void* grpc_method_config_table_get(const grpc_mdstr_hash_table* table,
const grpc_mdstr* path);
/// Gets the LB policy name from \a service_config.
/// Returns NULL if no LB policy name was specified.
/// Caller does NOT take ownership.
const char* grpc_service_config_get_lb_policy_name(
grpc_json_tree* service_config);
/// Creates a channel arg containing \a service_config.
grpc_arg grpc_service_config_create_channel_arg(grpc_json_tree* service_config);

Loading…
Cancel
Save