@@ -6,9 +6,9 @@ void fill_tag(char* new_tag, char* old_tag, size_t tag_len) {
66 sprintf (new_tag , "%s%*.*s" , old_tag , pad_len , pad_len , nines );
77}
88
9- status_t ta_hash243_stack_to_json_array (hash243_stack_t stack ,
10- cJSON * const json_root ,
11- char const * const obj_name ) {
9+ static status_t ta_hash243_stack_to_json_array (hash243_stack_t stack ,
10+ cJSON * const json_root ,
11+ char const * const obj_name ) {
1212 size_t array_count = 0 ;
1313 cJSON * array_obj = NULL ;
1414 hash243_stack_entry_t * s_iter = NULL ;
@@ -41,9 +41,9 @@ status_t ta_hash243_stack_to_json_array(hash243_stack_t stack,
4141 return SC_OK ;
4242}
4343
44- status_t ta_hash243_queue_to_json_array (hash243_queue_t queue ,
45- cJSON * const json_root ,
46- char const * const obj_name ) {
44+ static status_t ta_hash243_queue_to_json_array (hash243_queue_t queue ,
45+ cJSON * const json_root ,
46+ char const * const obj_name ) {
4747 size_t array_count ;
4848 cJSON * array_obj = NULL ;
4949 hash243_queue_entry_t * q_iter = NULL ;
@@ -75,6 +75,25 @@ status_t ta_hash243_queue_to_json_array(hash243_queue_t queue,
7575 return SC_OK ;
7676}
7777
78+ static status_t ta_json_get_string (cJSON const * const json_obj ,
79+ char const * const obj_name ,
80+ char * const text ) {
81+ retcode_t ret = SC_OK ;
82+
83+ cJSON * json_value = cJSON_GetObjectItemCaseSensitive (json_obj , obj_name );
84+ if (json_value == NULL ) {
85+ return RC_CCLIENT_JSON_KEY ;
86+ }
87+
88+ if (cJSON_IsString (json_value ) && (json_value -> valuestring != NULL )) {
89+ strcpy (text , json_value -> valuestring );
90+ } else {
91+ return RC_CCLIENT_JSON_PARSE ;
92+ }
93+
94+ return ret ;
95+ }
96+
7897status_t iota_transaction_to_json_object (iota_transaction_t const * const txn ,
7998 cJSON * * txn_json ) {
8099 if (txn == NULL ) {
@@ -431,6 +450,37 @@ status_t send_mam_res_serialize(char** obj, const send_mam_res_t* const res) {
431450 return ret ;
432451}
433452
453+ status_t send_mam_res_deserialize (const char * const obj ,
454+ send_mam_res_t * const res ) {
455+ if (obj == NULL ) {
456+ return SC_SERIALIZER_NULL ;
457+ }
458+ cJSON * json_obj = cJSON_Parse (obj );
459+ status_t ret = SC_OK ;
460+ tryte_t addr [NUM_TRYTES_ADDRESS + 1 ];
461+
462+ if (json_obj == NULL ) {
463+ ret = SC_SERIALIZER_JSON_PARSE ;
464+ goto done ;
465+ }
466+
467+ if (ta_json_get_string (json_obj , "channel" , (char * )addr ) != SC_OK ) {
468+ ret = SC_SERIALIZER_NULL ;
469+ goto done ;
470+ }
471+ send_mam_res_set_channel_id (res , addr );
472+
473+ if (ta_json_get_string (json_obj , "bundle_hash" , (char * )addr ) != SC_OK ) {
474+ ret = SC_SERIALIZER_NULL ;
475+ goto done ;
476+ }
477+ send_mam_res_set_bundle_hash (res , addr );
478+
479+ done :
480+ cJSON_Delete (json_obj );
481+ return ret ;
482+ }
483+
434484status_t send_mam_req_deserialize (const char * const obj , send_mam_req_t * req ) {
435485 if (obj == NULL ) {
436486 return SC_SERIALIZER_NULL ;
0 commit comments