@@ -694,70 +694,79 @@ static int bin_deserialize_value(struct thingset_context *ts,
694
694
bin_deserialize_simple_value (ts , object -> data , object -> type , object -> detail , check_only );
695
695
696
696
if (err == - THINGSET_ERR_UNSUPPORTED_FORMAT ) {
697
- if (object -> type == THINGSET_TYPE_ARRAY ) {
698
- struct thingset_array * array = object -> data .array ;
699
- bool success ;
697
+ bool success ;
700
698
701
- success = zcbor_list_start_decode (ts -> decoder );
702
- if (!success ) {
703
- return - THINGSET_ERR_UNSUPPORTED_FORMAT ;
704
- }
705
-
706
- size_t type_size = thingset_type_size (array -> element_type );
707
- int index = 0 ;
708
- do {
709
- /* using uint8_t pointer for byte-wise pointer arithmetics */
710
- union thingset_data_pointer data = { .u8 = array -> elements .u8 + index * type_size };
699
+ switch (object -> type ) {
700
+ case THINGSET_TYPE_ARRAY :
701
+ struct thingset_array * array = object -> data .array ;
711
702
712
- err = bin_deserialize_simple_value (ts , data , array -> element_type , array -> decimals ,
713
- check_only );
714
- if ( err != 0 ) {
703
+ success = zcbor_list_start_decode (ts -> decoder );
704
+ if (! success ) {
705
+ err = - THINGSET_ERR_UNSUPPORTED_FORMAT ;
715
706
break ;
716
707
}
717
- index ++ ;
718
- } while (index < array -> max_elements );
719
708
720
- if (!check_only ) {
721
- array -> num_elements = index ;
722
- }
709
+ size_t type_size = thingset_type_size (array -> element_type );
710
+ int index = 0 ;
711
+ do {
712
+ /* using uint8_t pointer for byte-wise pointer arithmetics */
713
+ union thingset_data_pointer data = { .u8 = array -> elements .u8 + index * type_size };
723
714
724
- success = zcbor_list_end_decode (ts -> decoder );
725
- if (success ) {
726
- err = 0 ;
727
- }
728
- }
729
- else if (object -> type == THINGSET_TYPE_RECORDS ) {
730
- struct thingset_records * records = object -> data .records ;
731
- uint32_t id ;
732
- bool success ;
733
-
734
- success = zcbor_list_start_decode (ts -> decoder );
735
- for (unsigned int i = 0 ; i < records -> num_records ; i ++ ) {
736
- success = zcbor_map_start_decode (ts -> decoder );
737
- if (!success ) {
738
- return - THINGSET_ERR_UNSUPPORTED_FORMAT ;
715
+ err = bin_deserialize_simple_value (ts , data , array -> element_type , array -> decimals ,
716
+ check_only );
717
+ if (err != 0 ) {
718
+ break ;
719
+ }
720
+ index ++ ;
721
+ } while (index < array -> max_elements );
722
+
723
+ if (!check_only ) {
724
+ array -> num_elements = index ;
739
725
}
740
726
741
- while (zcbor_uint32_decode (ts -> decoder , & id ) && id < UINT16_MAX ) {
742
- struct thingset_data_object * element = thingset_get_object_by_id (ts , id );
743
- if (element == NULL ) {
744
- zcbor_any_skip (ts -> decoder , NULL );
745
- continue ;
727
+ success = zcbor_list_end_decode (ts -> decoder );
728
+ if (success ) {
729
+ err = 0 ;
730
+ }
731
+ break ;
732
+
733
+ case THINGSET_TYPE_RECORDS :
734
+ struct thingset_records * records = object -> data .records ;
735
+ uint32_t id ;
736
+
737
+ success = zcbor_list_start_decode (ts -> decoder );
738
+ for (unsigned int i = 0 ; i < records -> num_records ; i ++ ) {
739
+ success = zcbor_map_start_decode (ts -> decoder );
740
+ if (!success ) {
741
+ err = - THINGSET_ERR_UNSUPPORTED_FORMAT ;
742
+ break ;
743
+ }
744
+
745
+ while (zcbor_uint32_decode (ts -> decoder , & id ) && id < UINT16_MAX ) {
746
+ struct thingset_data_object * element = thingset_get_object_by_id (ts , id );
747
+ if (element == NULL ) {
748
+ zcbor_any_skip (ts -> decoder , NULL );
749
+ continue ;
750
+ }
751
+ union thingset_data_pointer data = { .u8 = ((uint8_t * )records -> records )
752
+ + (i * records -> record_size )
753
+ + element -> data .offset };
754
+ err = bin_deserialize_simple_value (ts , data , element -> type , element -> detail ,
755
+ check_only );
746
756
}
747
- union thingset_data_pointer data = { .u8 = ((uint8_t * )records -> records )
748
- + (i * records -> record_size )
749
- + element -> data .offset };
750
- err = bin_deserialize_simple_value (ts , data , element -> type , element -> detail ,
751
- check_only );
757
+
758
+ success = zcbor_map_end_decode (ts -> decoder );
752
759
}
753
760
754
- success = zcbor_map_end_decode (ts -> decoder );
755
- }
761
+ success = zcbor_list_end_decode (ts -> decoder );
762
+ if (success ) {
763
+ err = 0 ;
764
+ }
765
+ break ;
756
766
757
- success = zcbor_list_end_decode (ts -> decoder );
758
- if (success ) {
759
- err = 0 ;
760
- }
767
+ default :
768
+ err = - THINGSET_ERR_UNSUPPORTED_FORMAT ;
769
+ break ;
761
770
}
762
771
}
763
772
0 commit comments