@@ -137,7 +137,6 @@ int sldm_telemetry_structure_parse(const struct telemetry_log *tl,
137137 struct json_object * obj_arraySizeArray = NULL ;
138138 struct json_object * obj = NULL ;
139139 struct json_object * obj_memberList ;
140- struct json_object * major_dimension = NULL ;
141140 struct json_object * sub_output ;
142141 struct json_object * obj_arraySizeIndicator = NULL ;
143142 bool force_array = false;
@@ -218,7 +217,6 @@ int sldm_telemetry_structure_parse(const struct telemetry_log *tl,
218217 struct json_object * dimension = json_object_array_get_idx (obj_arraySizeArray , i );
219218
220219 array_size_dimension [i ] = json_object_get_int (dimension );
221- major_dimension = dimension ;
222220 }
223221
224222 // Check for arraySizeIndicator property to support dynamic array sizes
@@ -241,25 +239,42 @@ int sldm_telemetry_structure_parse(const struct telemetry_log *tl,
241239 }
242240
243241 if (array_rank > 1 ) {
244- uint32_t linear_pos_per_index = array_size_dimension [ 0 ] ;
242+ uint32_t linear_pos_per_index = 1 ;
245243 uint32_t prev_index_offset_bit = 0 ;
246244 struct json_object * dimension_output ;
245+ struct json_object * inner_dim_array ;
247246
248- for (unsigned int i = 1 ; i < (array_rank - 1 ); i ++ )
247+ /* Stride = product of all inner dimensions (1..rank-1) */
248+ for (unsigned int i = 1 ; i < array_rank ; i ++ )
249249 linear_pos_per_index *= array_size_dimension [i ];
250250
251- dimension_output = json_create_array ();
252- if (json_object_get_type (output ) == json_type_array )
253- json_object_array_add (output , dimension_output );
254- else
251+ /*
252+ * When output is already an array (recursive call from
253+ * outer dimension), fill it directly to avoid extra wrap.
254+ */
255+ if (json_object_get_type (output ) == json_type_array ) {
256+ dimension_output = output ;
257+ } else {
258+ dimension_output = json_create_array ();
255259 json_object_add_value_array (output , name , dimension_output );
260+ }
256261
257262 /*
258- * Make sure major_dimension object will not be
259- * deleted from memory when deleted from array
263+ * Build a copy of arraySize without the first dimension
264+ * so recursive calls see only the inner dimensions.
260265 */
261- json_object_get (major_dimension );
262- json_object_array_del_idx (obj_arraySizeArray , array_rank - 1 , 1 );
266+ inner_dim_array = json_create_array ();
267+ for (size_t i = 1 ; i < array_rank ; i ++ ) {
268+ struct json_object * dim =
269+ json_object_array_get_idx (
270+ obj_arraySizeArray , i );
271+
272+ json_object_get (dim );
273+ json_object_array_add (inner_dim_array , dim );
274+ }
275+ json_object_get (obj_arraySizeArray );
276+ json_object_object_add (struct_def , "arraySize" ,
277+ inner_dim_array );
263278
264279 for (unsigned int i = 0 ; i < array_size_dimension [0 ]; i ++ ) {
265280 struct json_object * sub_array = json_create_array ();
@@ -273,8 +288,8 @@ int sldm_telemetry_structure_parse(const struct telemetry_log *tl,
273288 prev_index_offset_bit += linear_pos_per_index * size_bit ;
274289 }
275290
276- json_object_array_put_idx ( obj_arraySizeArray , array_rank - 1 ,
277- major_dimension );
291+ json_object_object_add ( struct_def , "arraySize" ,
292+ obj_arraySizeArray );
278293
279294 return 0 ;
280295 }
@@ -300,11 +315,16 @@ int sldm_telemetry_structure_parse(const struct telemetry_log *tl,
300315 json_object_put (str_obj );
301316 }
302317
303- sub_output = json_create_array ();
304- if (json_object_is_type (output , json_type_array ))
305- json_object_array_add (output , sub_output );
306- else
318+ /*
319+ * When output is already an array (from an outer
320+ * multi-dim call), fill it directly to avoid extra wrap.
321+ */
322+ if (json_object_is_type (output , json_type_array )) {
323+ sub_output = output ;
324+ } else {
325+ sub_output = json_create_array ();
307326 json_object_add_value_array (output , name , sub_output );
327+ }
308328 }
309329
310330 for (uint32_t j = 0 ; j < array_size_dimension [0 ]; j ++ ) {
0 commit comments