library/src/javascript/JSON/BP-JSON.cc
// re-entrant create-output routine (called directly from BP_JSONCreateOutput*)
re-entrant create-output routine (called directly from BP_JSONCreateOutput*)
re - entrant create - output routine ( called directly from BP_JSONCreateOutput * )
BP_ERROR_T BP_JSONCreateOutput_r
(
		P_BP_JSON                   json,
		P_BP_HASH_TABLE_KEYED_ENTRY table_r,
		size_t                      tab_depth,
		P_BP_LINKL           	    out_json_tq,
		BP_BOOL                     base64_encode_bin_data,
		BP_BOOL                     skip_outermost_table_iter
)
{
	if(!json)
		return ERR_FAILURE;
	if(!table_r)
		return ERR_FAILURE;
	if(!out_json_tq)
		return ERR_FAILURE;
	P_BP_JSON_PARSE_TOKEN_ELEMENT element_parse_metadata = (P_BP_JSON_PARSE_TOKEN_ELEMENT) table_r->external_entry_metadata;
	if(!skip_outermost_table_iter)
	{
		BP_HASH_ITER_OPEN((P_BP_HTKE) table_r, table_r_item_iter)
		{
			if(table_r_item_iter->type == BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
			{
				BP_JSONCreateOutput_AddKeyVal(json->json_out_prepare_tq, tab_depth, table_r_item_iter, base64_encode_bin_data);
				BP_JSONCreateOutput_AddTableOpen(json->json_out_prepare_tq, tab_depth);
				BP_JSONCreateOutput_r
				(
					json,
					(P_BP_HTKE) table_r_item_iter->data,
					tab_depth+1,
					out_json_tq,
					base64_encode_bin_data
				);
				BP_JSONCreateOutput_AddTableClose(json->json_out_prepare_tq, tab_depth);
				if(table_r_item_iter->hh.next)
					tq_strdup(json->json_out_prepare_tq, ",", BPLN);
			}
			else
			{
				BP_JSONCreateOutput_AddKeyVal(json->json_out_prepare_tq, tab_depth, table_r_item_iter, base64_encode_bin_data);
				if(table_r_item_iter->hh.next)
					tq_strdup(json->json_out_prepare_tq, ",", BPLN);
			}
		}
		BP_HASH_ITER_CLOSE;
	}
	else
	{
		if(table_r->type == BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
		{
			BP_JSONCreateOutput_AddKeyVal(json->json_out_prepare_tq, tab_depth, table_r, base64_encode_bin_data);
			BP_JSONCreateOutput_AddTableOpen(json->json_out_prepare_tq, tab_depth);
			BP_JSONCreateOutput_r
			(
				json,
				(P_BP_HTKE) table_r->data,
				tab_depth+1,
				out_json_tq,
				base64_encode_bin_data
			);
			BP_JSONCreateOutput_AddTableClose(json->json_out_prepare_tq, tab_depth);
		}
		else
		{
			BP_JSONCreateOutput_AddKeyVal(json->json_out_prepare_tq, tab_depth, table_r, base64_encode_bin_data);
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONCreateOutput_r ( P_BP_JSON json , P_BP_HASH_TABLE_KEYED_ENTRY table_r , size_t tab_depth , P_BP_LINKL out_json_tq , BP_BOOL base64_encode_bin_data , BP_BOOL skip_outermost_table_iter ) { if ( ! json ) return ERR_FAILURE ; if ( ! table_r ) return ERR_FAILURE ; if ( ! out_json_tq ) return ERR_FAILURE ; P_BP_JSON_PARSE_TOKEN_ELEMENT element_parse_metadata = ( P_BP_JSON_PARSE_TOKEN_ELEMENT ) table_r -> external_entry_metadata ; if ( ! skip_outermost_table_iter ) { BP_HASH_ITER_OPEN ( ( P_BP_HTKE ) table_r , table_r_item_iter ) { if ( table_r_item_iter -> type == BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { BP_JSONCreateOutput_AddKeyVal ( json -> json_out_prepare_tq , tab_depth , table_r_item_iter , base64_encode_bin_data ) ; BP_JSONCreateOutput_AddTableOpen ( json -> json_out_prepare_tq , tab_depth ) ; BP_JSONCreateOutput_r ( json , ( P_BP_HTKE ) table_r_item_iter -> data , tab_depth + 1 , out_json_tq , base64_encode_bin_data ) ; BP_JSONCreateOutput_AddTableClose ( json -> json_out_prepare_tq , tab_depth ) ; if ( table_r_item_iter -> hh . next ) tq_strdup ( json -> json_out_prepare_tq , " " , BPLN ) ; } else { BP_JSONCreateOutput_AddKeyVal ( json -> json_out_prepare_tq , tab_depth , table_r_item_iter , base64_encode_bin_data ) ; if ( table_r_item_iter -> hh . next ) tq_strdup ( json -> json_out_prepare_tq , " " , BPLN ) ; } } BP_HASH_ITER_CLOSE ; } else { if ( table_r -> type == BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { BP_JSONCreateOutput_AddKeyVal ( json -> json_out_prepare_tq , tab_depth , table_r , base64_encode_bin_data ) ; BP_JSONCreateOutput_AddTableOpen ( json -> json_out_prepare_tq , tab_depth ) ; BP_JSONCreateOutput_r ( json , ( P_BP_HTKE ) table_r -> data , tab_depth + 1 , out_json_tq , base64_encode_bin_data ) ; BP_JSONCreateOutput_AddTableClose ( json -> json_out_prepare_tq , tab_depth ) ; } else { BP_JSONCreateOutput_AddKeyVal ( json -> json_out_prepare_tq , tab_depth , table_r , base64_encode_bin_data ) ; } } return ERR_SUCCESS ; }
re-entrant create-output routine (called directly from BP_JSONCreateOutput*)
re - entrant create - output routine ( called directly from BP_JSONCreateOutput * )
// run basic null checks // set parse metadata here if it's available (it will be null in all cases except when available) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Process Table Entries (don't skip outermost) %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // if we are not skipping the outermost table // start iteration on the table // if the type is a table, recurse, if not, simply display entry // add key val // open the table // recurse if we have a hash table type // close the table // add comma only if we have a next element // attempt to add key value here // add comma only if we have a next element // if the type is a table, recurse, if not, simply display entry // add key val // open the table // recurse if we have a hash table type // close the table // attempt to add key value here // return indicating success