src/mimik_edge_services.c
int mimik_json_parse_service_records(mk_edge_service_record * mk_ser_rec)
{
   char *databuff = NULL;
   service_records *sr = NULL;
   cJSON *jroot = NULL;
   cJSON *jdata = NULL;
   char *name = NULL;
   int rc = 0;

   if (!mk_ser_rec) {
      return -1;
   }

   if (mk_ser_rec->jroot != NULL) {
      MK_LOG(LOG_ERR,"%s() mk_ser_rec->jroot=%p is not empty, may have been parsed already \n",__func__,mk_ser_rec->jroot);
      MK_LOG(LOG_ERR,"%s() call mimik_free_service_records( ) to free old jroot values \n",__func__);
      return -1;
   }

   databuff = mk_ser_rec->ser_rsp_buff;
   sr = &mk_ser_rec->srd;

   jroot = cJSON_Parse(databuff);
   if (!jroot) {
      return -1;
   }
   mk_ser_rec->jroot = jroot;

   MK_LOG(LOG_INFO,"%s() sizeof(service_records)=%d \n",__func__,(int)sizeof(service_records));

   //"type"
    name = "type";
    rc = mk_json_get_string_item_value(jroot,name,&sr->type);
    if (rc == 0) {
        MK_LOG(LOG_DEBUG,"%s() name(%s) => (addr=%p):value(%s) \n ",__func__,name,sr->type,sr->type);
    }

    //"type": "data" //array of data items.
    sr->data_array_count = 0;
    name = "data";
    jdata = cJSON_GetObjectItemCaseSensitive(jroot, name);

    if (jdata && cJSON_IsArray(jdata)) {
       int i = 0;
       int asz = cJSON_GetArraySize(jdata);
       if (asz > MAX_DATA_ARRAY_COUNT) {
	  MK_LOG(LOG_NOTICE,"%s() GetArraySize(%s) = %d > maxsz=%d \n",__func__,name,asz,MAX_DATA_ARRAY_COUNT);
	  asz = MAX_DATA_ARRAY_COUNT;
       }

       for (i = 0; (i < asz); i++) {
	  rc = mk_json_parse_data_array_service_records(&sr->data[sr->data_array_count], jdata, i);
	  if (rc == 0) {
	      sr->data_array_count++;
	      MK_LOG(LOG_DEBUG,"%s() %s array parsing success: i=%d array_count=%d asz=%d\n",
				__func__,name,i,sr->data_array_count,asz);
	  }
       } //end of for data array processing
    }

   return 0;
}
//mimik_json_parse_service_records() parses the content of the string databuff contnet as
//JSON object to equivalent c struct and places the result in service_records
//structure members.
//returns 0 on success and -1 on failure
mimik_json_parse_service_records() parses the content of the string databuff contnet as
JSON object to equivalent c struct and places the result in service_records
structure members.
returns 0 on success and -1 on failure
mimik_json_parse_service_records () parses the content of the string databuff contnet as JSON object to equivalent c struct and places the result in service_records structure members . returns 0 on success and - 1 on failure
int mimik_json_parse_service_records(mk_edge_service_record * mk_ser_rec)
{
   char *databuff = NULL;
   service_records *sr = NULL;
   cJSON *jroot = NULL;
   cJSON *jdata = NULL;
   char *name = NULL;
   int rc = 0;
   if (!mk_ser_rec) {
      return -1;
   }
   if (mk_ser_rec->jroot != NULL) {
      MK_LOG(LOG_ERR,"%s() mk_ser_rec->jroot=%p is not empty, may have been parsed already \n",__func__,mk_ser_rec->jroot);
      MK_LOG(LOG_ERR,"%s() call mimik_free_service_records( ) to free old jroot values \n",__func__);
      return -1;
   }
   databuff = mk_ser_rec->ser_rsp_buff;
   sr = &mk_ser_rec->srd;
   jroot = cJSON_Parse(databuff);
   if (!jroot) {
      return -1;
   }
   mk_ser_rec->jroot = jroot;
   MK_LOG(LOG_INFO,"%s() sizeof(service_records)=%d \n",__func__,(int)sizeof(service_records));
    name = "type";
    rc = mk_json_get_string_item_value(jroot,name,&sr->type);
    if (rc == 0) {
        MK_LOG(LOG_DEBUG,"%s() name(%s) => (addr=%p):value(%s) \n ",__func__,name,sr->type,sr->type);
    }
    : "data" //array of data items.
    sr->data_array_count = 0;
    name = "data";
    jdata = cJSON_GetObjectItemCaseSensitive(jroot, name);
    if (jdata && cJSON_IsArray(jdata)) {
       int i = 0;
       int asz = cJSON_GetArraySize(jdata);
       if (asz > MAX_DATA_ARRAY_COUNT) {
	  MK_LOG(LOG_NOTICE,"%s() GetArraySize(%s) = %d > maxsz=%d \n",__func__,name,asz,MAX_DATA_ARRAY_COUNT);
	  asz = MAX_DATA_ARRAY_COUNT;
       }
       for (i = 0; (i < asz); i++) {
	  rc = mk_json_parse_data_array_service_records(&sr->data[sr->data_array_count], jdata, i);
	  if (rc == 0) {
	      sr->data_array_count++;
	      MK_LOG(LOG_DEBUG,"%s() %s array parsing success: i=%d array_count=%d asz=%d\n",
				__func__,name,i,sr->data_array_count,asz);
	  }
       } 
    }
   return 0;
}
int mimik_json_parse_service_records ( mk_edge_service_record * mk_ser_rec ) { char * databuff = NULL ; service_records * sr = NULL ; cJSON * jroot = NULL ; cJSON * jdata = NULL ; char * name = NULL ; int rc = 0 ; if ( ! mk_ser_rec ) { return -1 ; } if ( mk_ser_rec -> jroot != NULL ) { MK_LOG ( LOG_ERR , " \n " , __func__ , mk_ser_rec -> jroot ) ; MK_LOG ( LOG_ERR , " \n " , __func__ ) ; return -1 ; } databuff = mk_ser_rec -> ser_rsp_buff ; sr = & mk_ser_rec -> srd ; jroot = cJSON_Parse ( databuff ) ; if ( ! jroot ) { return -1 ; } mk_ser_rec -> jroot = jroot ; MK_LOG ( LOG_INFO , " \n " , __func__ , ( int ) sizeof ( service_records ) ) ; name = " " ; rc = mk_json_get_string_item_value ( jroot , name , & sr -> type ) ; if ( rc == 0 ) { MK_LOG ( LOG_DEBUG , " \n " , __func__ , name , sr -> type , sr -> type ) ; } sr -> data_array_count = 0 ; name = " " ; jdata = cJSON_GetObjectItemCaseSensitive ( jroot , name ) ; if ( jdata && cJSON_IsArray ( jdata ) ) { int i = 0 ; int asz = cJSON_GetArraySize ( jdata ) ; if ( asz > MAX_DATA_ARRAY_COUNT ) { MK_LOG ( LOG_NOTICE , " \n " , __func__ , name , asz , MAX_DATA_ARRAY_COUNT ) ; asz = MAX_DATA_ARRAY_COUNT ; } for ( i = 0 ; ( i < asz ) ; i ++ ) { rc = mk_json_parse_data_array_service_records ( & sr -> data [ sr -> data_array_count ] , jdata , i ) ; if ( rc == 0 ) { sr -> data_array_count ++ ; MK_LOG ( LOG_DEBUG , " \n " , __func__ , name , i , sr -> data_array_count , asz ) ; } } } return 0 ; }
mimik_json_parse_service_records() parses the content of the string databuff contnet as
JSON object to equivalent c struct and places the result in service_records
structure members.
mimik_json_parse_service_records () parses the content of the string databuff contnet as JSON object to equivalent c struct and places the result in service_records structure members .
//"type" //"type": "data" //array of data items. //end of for data array processing