Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: TLV-JSON-TLV converter #27279

Closed
wants to merge 1 commit into from
Closed

Draft: TLV-JSON-TLV converter #27279

wants to merge 1 commit into from

Conversation

chrisdecenzo
Copy link
Contributor

(for message serialization between android tv-app platform and content apps)

TODO:

  • Add readme describing JSON schema
  • Add call from android casting app
  • Add translation to/from android intent to android tv-app

@@ -139,6 +139,7 @@ CHIP_ERROR CastingServer::OpenBasicCommissioningWindow(std::function<void(CHIP_E
mOnConnectionSuccessClientCallback = onConnectionSuccess;
mOnConnectionFailureClientCallback = onConnectionFailure;
mOnNewOrUpdatedEndpoint = onNewOrUpdatedEndpoint;
ChipLogError(AppServer, "-----------------------CastingServer PrepareForCommissioning");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove

@github-actions
Copy link

github-actions bot commented Jun 15, 2023

PR #27279: Size comparison from eef9529 to 09dc61b

Increases (10 builds for bl602, cc32xx, cyw30739, esp32, nrfconnect, telink)
platform target config section eef9529 09dc61b change % change
bl602 lighting-app bl602+rpc .text 1081356 1081360 4 0.0
cc32xx lock CC3235SF_LAUNCHXL .debug_info 19931503 19931504 1 0.0
cyw30739 switch cyw930739m2evb_01 (read/write) 531967 531975 8 0.0
.app_xip_area 422953 422961 8 0.0
esp32 all-clusters-app m5stack (read/write) 494246 494250 4 0.0
.flash.rodata 244024 244028 4 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 text 839312 839316 4 0.0
telink all-clusters-app tlsr9518adk80d (read/write) 1034532 1034540 8 0.0
text 708210 708214 4 0.0
lock-app tlsr9518adk80d text 614336 614338 2 0.0
ota-requestor-app tlsr9518adk80d text 607480 607484 4 0.0
pump-app tlsr9518adk80d text 591428 591430 2 0.0
temperature-measurement-app tlsr9518adk80d text 577442 577444 2 0.0
Decreases (8 builds for bl702, psoc6, telink)
platform target config section eef9529 09dc61b change % change
bl702 lighting-app bl702 (read/write) 1173707 1173703 -4 -0.0
.debug_info 4160151 41601511 -1 -0.0
.text 945034 945032 -2 -0.0
psoc6 all-clusters-minimal cy8ckit_062s2_43012 .debug_info 28317196 28317195 -1 -0.0
telink bridge-app tlsr9518adk80d (read/write) 929408 929400 -8 -0.0
text 642506 642504 -2 -0.0
contact-sensor-app tlsr9518adk80d text 585710 585708 -2 -0.0
lighting-app-rpc tlsr9518adk80d text 724220 724218 -2 -0.0
lighting-app-shell tlsr9518adk80d (read/write) 1066504 1066496 -8 -0.0
text 744366 744364 -2 -0.0
thermostat tlsr9518adk80d (read/write) 895660 895652 -8 -0.0
text 616692 616688 -4 -0.0
window-covering tlsr9518adk80d text 611612 611610 -2 -0.0
Full report (46 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
platform target config section eef9529 09dc61b change % change
bl602 lighting-app bl602 (read/write) 1368922 1368922 0 0.0
.bss 88182 88182 0 0.0
.data 9584 9584 0 0.0
.text 1049218 1049218 0 0.0
bl602+rpc (read/write) 1416590 1416590 0 0.0
.bss 96230 96230 0 0.0
.data 9976 9976 0 0.0
.text 1081356 1081360 4 0.0
bl702 lighting-app bl702 (read only) 3358 3358 0 0.0
(read/write) 1173707 1173703 -4 -0.0
.bleromro 6342 6342 0 0.0
.bleromrw 124 124 0 0.0
.boot2 328 328 0 0.0
.bss 77773 77773 0 0.0
.bss_psram 24656 24656 0 0.0
.comment 48 48 0 0.0
.data 3576 3576 0 0.0
.debug_abbrev 1543146 1543146 0 0.0
.debug_aranges 149952 149952 0 0.0
.debug_frame 552112 552112 0 0.0
.debug_info 4160151 41601511 -1 -0.0
.debug_line 5582445 5582445 0 0.0
.debug_loc 3800671 3800671 0 0.0
.debug_ranges 395144 395144 0 0.0
.debug_str 4352645 4352645 0 0.0
.hbn 536 536 0 0.0
.hbn_noinit 260 260 0 0.0
.init 342 342 0 0.0
.init_array 140 140 0 0.0
.psram 0 0 0 0.0
.riscv.attributes 47 47 0 0.0
.rodata 104972 104972 0 0.0
.rsvd 4 4 0 0.0
.sha_ocram 72 72 0 0.0
.shstrtab 304 304 0 0.0
.stack 2048 2048 0 0.0
.strtab 581710 581710 0 0.0
.symtab 173904 173904 0 0.0
.tcm_data 28 28 0 0.0
.tcmcode 3358 3358 0 0.0
.text 0 0 0 0.0
945034 945032 -2 -0.0
bl702+rpc (read only) 3358 3358 0 0.0
(read/write) 1271651 1271651 0 0.0
.bleromro 6342 6342 0 0.0
.bleromrw 124 124 0 0.0
.boot2 328 328 0 0.0
.bss 85821 85821 0 0.0
.bss_psram 25072 25072 0 0.0
.comment 48 48 0 0.0
.data 4136 4136 0 0.0
.debug_abbrev 1708311 1708311 0 0.0
.debug_aranges 158432 158432 0 0.0
.debug_frame 580744 580744 0 0.0
.debug_info 46783064 46783064 0 0.0
.debug_line 6008194 6008194 0 0.0
.debug_loc 4005907 4005907 0 0.0
.debug_ranges 420824 420824 0 0.0
.debug_str 4781319 4781319 0 0.0
.hbn 536 536 0 0.0
.hbn_noinit 260 260 0 0.0
.init 342 342 0 0.0
.init_array 156 156 0 0.0
.psram 0 0 0 0.0
.riscv.attributes 47 47 0 0.0
.rodata 119568 119568 0 0.0
.rsvd 4 4 0 0.0
.sha_ocram 72 72 0 0.0
.shstrtab 304 304 0 0.0
.stack 2048 2048 0 0.0
.strtab 644310 644310 0 0.0
.symtab 192704 192704 0 0.0
.tcm_data 28 28 0 0.0
.tcmcode 3358 3358 0 0.0
.text 0 0 0 0.0
1018784 1018784 0 0.0
cc32xx lock CC3235SF_LAUNCHXL (blank) 0 0 0 0.0
(read only) 606858 606858 0 0.0
(read/write) 204164 204164 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197576 197576 0 0.0
.comment 206 206 0 0.0
.data 1468 1468 0 0.0
.debug_abbrev 946006 946006 0 0.0
.debug_aranges 119144 119144 0 0.0
.debug_frame 407092 407092 0 0.0
.debug_info 19931503 19931504 1 0.0
.debug_line 2876094 2876094 0 0.0
.debug_line_str 513 513 0 0.0
.debug_loc 33340 33340 0 0.0
.debug_loclists 1730657 1730657 0 0.0
.debug_ranges 4984 4984 0 0.0
.debug_rnglists 107730 107730 0 0.0
.debug_str 3793841 3793841 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 104546 104546 0 0.0
.shstrtab 265 265 0 0.0
.stack 2048 2048 0 0.0
.strtab 485272 485272 0 0.0
.symtab 287968 287968 0 0.0
.text 500188 500188 0 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 543127 543127 0 0.0
.app_xip_area 435745 435745 0 0.0
.bss 62360 62360 0 0.0
.data 712 712 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 530135 530135 0 0.0
.app_xip_area 417625 417625 0 0.0
.bss 67480 67480 0 0.0
.data 720 720 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor cyw930739m2evb_01 (read/write) 567551 567551 0 0.0
.app_xip_area 461105 461105 0 0.0
.bss 61472 61472 0 0.0
.data 668 668 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
switch cyw930739m2evb_01 (read/write) 531967 531975 8 0.0
.app_xip_area 422953 422961 8 0.0
.bss 63960 63960 0 0.0
.data 744 744 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A+rs9116 (read/write) 994868 994868 0 0.0
.bss 181848 181848 0 0.0
.data 2144 2144 0 0.0
.text 810856 810856 0 0.0
BRD4187C (read/write) 1027096 1027096 0 0.0
.bss 161572 161572 0 0.0
.data 2788 2788 0 0.0
.text 862716 862716 0 0.0
lock-app BRD4161A+wf200 (read/write) 1075824 1075824 0 0.0
.bss 176136 176136 0 0.0
.data 2152 2152 0 0.0
.text 897516 897516 0 0.0
window-app BRD4187C (read/write) 1097152 1097152 0 0.0
.bss 144548 144548 0 0.0
.data 2680 2680 0 0.0
.text 949904 949904 0 0.0
esp32 all-clusters-app c3devkit (read only) 1075412 1075412 0 0.0
(read/write) 1583792 1583792 0 0.0
.dram0.bss 75280 75280 0 0.0
.dram0.data 13940 13940 0 0.0
.flash.rodata 215432 215432 0 0.0
.flash.text 1075412 1075412 0 0.0
.iram0.text 76740 76740 0 0.0
m5stack (read only) 1123411 1123411 0 0.0
(read/write) 494246 494250 4 0.0
.dram0.bss 80768 80768 0 0.0
.dram0.data 34304 34304 0 0.0
.flash.rodata 244024 244028 4 0.0
.flash.text 1118027 1118027 0 0.0
.iram0.text 126055 126055 0 0.0
k32w contact k32w0+release (read only) 585732 585732 0 0.0
(read/write) 90096 90096 0 0.0
.bss 66100 66100 0 0.0
.data 2168 2168 0 0.0
.text 585196 585196 0 0.0
light k32w0+release (read only) 584356 584356 0 0.0
(read/write) 89744 89744 0 0.0
.bss 65764 65764 0 0.0
.data 2156 2156 0 0.0
.text 583820 583820 0 0.0
lock k32w0+release (read only) 557012 557012 0 0.0
(read/write) 87568 87568 0 0.0
.bss 63636 63636 0 0.0
.data 2100 2100 0 0.0
.text 556476 556476 0 0.0
linux chip-tool-ipv6only arm64 (read only) 15225576 15225576 0 0.0
(read/write) 788312 788312 0 0.0
.bss 34376 34376 0 0.0
.data 3008 3008 0 0.0
.data.rel.ro 728632 728632 0 0.0
.dynamic 560 560 0 0.0
.got 17024 17024 0 0.0
.init 24 24 0 0.0
.init_array 240 240 0 0.0
.rodata 636624 636624 0 0.0
.text 12724212 12724212 0 0.0
thermostat-no-ble arm64 (read only) 2612460 2612460 0 0.0
(read/write) 143000 143000 0 0.0
.bss 52360 52360 0 0.0
.data 1736 1736 0 0.0
.data.rel.ro 79264 79264 0 0.0
.dynamic 560 560 0 0.0
.got 5520 5520 0 0.0
.init 24 24 0 0.0
.init_array 424 424 0 0.0
.rodata 129536 129536 0 0.0
.text 2217444 2217444 0 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2498528 2498528 0 0.0
.bss 216304 216304 0 0.0
.data 5144 5144 0 0.0
.text 1461212 1461212 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read only) 4 4 0 0.0
(read/write) 1210496 1210496 0 0.0
bss 154745 154745 0 0.0
rodata 137380 137380 0 0.0
text 839312 839316 4 0.0
nrf7002dk_nrf5340_cpuapp (read only) 4 4 0 0.0
(read/write) 1313364 1313364 0 0.0
bss 138075 138075 0 0.0
rodata 132816 132816 0 0.0
text 751760 751760 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read only) 4 4 0 0.0
(read/write) 1148852 1148852 0 0.0
bss 153377 153377 0 0.0
rodata 111096 111096 0 0.0
text 805312 805312 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 (read only) 841992 841992 0 0.0
(read/write) 1728884 1728884 0 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 188788 188788 0 0.0
.comment 212 212 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2560 2560 0 0.0
.debug_abbrev 1290678 1290678 0 0.0
.debug_aranges 148952 148952 0 0.0
.debug_frame 498968 498968 0 0.0
.debug_info 28857366 28857366 0 0.0
.debug_line 4029791 4029791 0 0.0
.debug_line_str 957 957 0 0.0
.debug_loclists 2307480 2307480 0 0.0
.debug_rnglists 144432 144432 0 0.0
.debug_str 4361228 4361228 0 0.0
.heap 841992 841992 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 296 296 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 751738 751738 0 0.0
.symtab 479040 479040 0 0.0
.text 1529148 1529148 0 0.0
.zero.table 8 8 0 0.0
text 0 0 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 (read only) 843320 843320 0 0.0
(read/write) 1661348 1661348 0 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 187460 187460 0 0.0
.comment 212 212 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2560 2560 0 0.0
.debug_abbrev 1278458 1278458 0 0.0
.debug_aranges 147704 147704 0 0.0
.debug_frame 499912 499912 0 0.0
.debug_info 28317196 28317195 -1 -0.0
.debug_line 4034761 4034761 0 0.0
.debug_line_str 981 981 0 0.0
.debug_loclists 2292312 2292312 0 0.0
.debug_rnglists 142878 142878 0 0.0
.debug_str 4344158 4344158 0 0.0
.heap 843320 843320 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 296 296 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 700619 700619 0 0.0
.symtab 460160 460160 0 0.0
.text 1462940 1462940 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
light cy8ckit_062s2_43012 (read only) 849568 849568 0 0.0
(read/write) 1593948 1593948 0 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 181380 181380 0 0.0
.comment 212 212 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2392 2392 0 0.0
.debug_abbrev 1116033 1116033 0 0.0
.debug_aranges 138040 138040 0 0.0
.debug_frame 463820 463820 0 0.0
.debug_info 23102733 23102733 0 0.0
.debug_line 3606463 3606463 0 0.0
.debug_line_str 942 942 0 0.0
.debug_loclists 2133180 2133180 0 0.0
.debug_rnglists 132870 132870 0 0.0
.debug_str 4158223 4158223 0 0.0
.heap 849568 849568 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 296 296 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 624203 624203 0 0.0
.symtab 425584 425584 0 0.0
.text 1401788 1401788 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
lock cy8ckit_062s2_43012 (read only) 821968 821968 0 0.0
(read/write) 1626972 1626972 0 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 208980 208980 0 0.0
.comment 212 212 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2392 2392 0 0.0
.debug_abbrev 1098620 1098620 0 0.0
.debug_aranges 136336 136336 0 0.0
.debug_frame 457788 457788 0 0.0
.debug_info 22813295 22813295 0 0.0
.debug_line 3544308 3544308 0 0.0
.debug_line_str 933 933 0 0.0
.debug_loclists 2104403 2104403 0 0.0
.debug_rnglists 130581 130581 0 0.0
.debug_str 4114875 4114875 0 0.0
.heap 821968 821968 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 296 296 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 597173 597173 0 0.0
.symtab 417184 417184 0 0.0
.text 1407212 1407212 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
qpg lighting-app qpg6105+debug (read/write) 1171808 1171808 0 0.0
.bss 99960 99960 0 0.0
.data 788 788 0 0.0
.text 618648 618648 0 0.0
lock-app qpg6105+debug (read/write) 1129512 1129512 0 0.0
.bss 94816 94816 0 0.0
.data 792 792 0 0.0
.text 576356 576356 0 0.0
telink all-clusters-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 1034532 1034540 8 0.0
bss 97660 97660 0 0.0
text 708210 708214 4 0.0
all-clusters-minimal-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 961680 961680 0 0.0
bss 96176 96176 0 0.0
text 665468 665468 0 0.0
bridge-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 929408 929400 -8 -0.0
bss 100308 100308 0 0.0
text 642506 642504 -2 -0.0
contact-sensor-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 861140 861140 0 0.0
bss 89968 89968 0 0.0
text 585710 585708 -2 -0.0
light-switch-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 877464 877464 0 0.0
bss 90136 90136 0 0.0
text 600334 600334 0 0.0
lighting-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 965648 965648 0 0.0
bss 98500 98500 0 0.0
text 679326 679326 0 0.0
lighting-app-factory-data tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 977028 977028 0 0.0
bss 102748 102748 0 0.0
text 686846 686846 0 0.0
lighting-app-rpc tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 1035148 1035148 0 0.0
bss 100064 100064 0 0.0
text 724220 724218 -2 -0.0
lighting-app-shell tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 1066504 1066496 -8 -0.0
bss 111140 111140 0 0.0
text 744366 744364 -2 -0.0
lock-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 916212 916212 0 0.0
bss 90632 90632 0 0.0
text 614336 614338 2 0.0
ota-requestor-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 883668 883668 0 0.0
bss 91244 91244 0 0.0
text 607480 607484 4 0.0
pump-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 866700 866700 0 0.0
bss 90100 90100 0 0.0
text 591428 591430 2 0.0
pump-controller-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 853760 853760 0 0.0
bss 89900 89900 0 0.0
text 581812 581812 0 0.0
temperature-measurement-app tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 849916 849916 0 0.0
bss 89808 89808 0 0.0
text 577442 577444 2 0.0
thermostat tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 895660 895652 -8 -0.0
bss 90344 90344 0 0.0
text 616692 616688 -4 -0.0
window-covering tlsr9518adk80d (read only) 4 4 0 0.0
(read/write) 891032 891032 0 0.0
bss 90636 90636 0 0.0
text 611612 611610 -2 -0.0

Copy link
Contributor

@andy31415 andy31415 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: please add unit tests for such large code changes that are quite stand-alone (parsing and creating a JSON seems like it would be unit testable ... and unit tests would also explain how the JSON looks like)

return CHIP_NO_ERROR;
}

class JsonParser2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the 2 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in some namespace of chip?

* @namespace chip::TLV::Json
*
* @brief
* This namespace includes types and interfaces for json conversion of CHIP TLV.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these comments do not seem to help too much ... namespace re-states the namespace name and it seems obvious that chip::TLV::Json describes a json interface for TLV

Can we add more useful commets (e.g. explaining what the json format is with examples and explaining what a context is and such)

void * mContext;
};

extern CHIP_ERROR WriteJSON(const TLVReader & aReader, Encoding::BufferWriter & bWriter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably do not need "extern"

* buffer. On failure, the value of *octetCount is undefined.
*/
template <typename F>
CHIP_ERROR ConvertHexToBytes(chip::CharSpan hex, F bufferAllocator, size_t * octetCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not seem TLV-specific so should probably not be in JSONTlv.h

We have some lib/support/BytesToHex ... maybe we want HexToBytes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have HexToBytes too, inside the BytesToHex header.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.... that is confusing ... maybe we can find a better name or split headers.

class JsonTLVParser
{
public:
static CHIP_ERROR Put(chip::TLV::TLVWriter * writer, chip::TLV::Tag tag, Json::Value & value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like complex code in a header. Should probably be in a C++ file.

Also please add unit tests.

chip::TLV::TLVWriter writer;
chip::TLV::TLVReader reader;

uint8_t buf[74];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to explain the sizes here ...74 seems a very particular constant.

return CHIP_NO_ERROR;
}

CHIP_ERROR RunJsonTests()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be unit tests run during test execution, not a shell command (we can include it in the casting app as well, but a variant of unit tests that are stand alone should exist).

CHIP_ERROR RunJsonTests()
{
char json[] = "{"
"\"0x0\" : { \"tlvType\":\"0x00\", \"value\": 7 },"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may want some NULL tests as well.

@andy31415 andy31415 marked this pull request as draft June 15, 2023 19:06
@andy31415
Copy link
Contributor

@chrisdecenzo I moved your PR to draft since the title said so.


if (TLVTypeIsContainer(type))
{
if (tagControl == TLVTagControl::ContextSpecific)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about profile tags in TLV lists?

}
else
{
if (tagControl == TLVTagControl::ContextSpecific)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this does not seem to handle profile tags right. But also, shouldn't that "tag" : prefix just be written out independently of whether the tag is a container or not?

case kTLVType_ByteString:
err = temp.GetDataPtr(strbuf);
VerifyOrExit(err == CHIP_NO_ERROR, FormattedWrite(aWriter, "Error in kTLVType_ByteString"));
FormattedWrite(aWriter, "hex:");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this produces valid JSON, unless I am missing something.....

uint64_t uVal;
err = temp.Get(uVal);
VerifyOrExit(err == CHIP_NO_ERROR, FormattedWrite(aWriter, "Error in kTLVType_UnsignedInteger"));
FormattedWrite(aWriter, "%" PRIu64, uVal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're OK with the data corruptions for values > 2^53?

* buffer. On failure, the value of *octetCount is undefined.
*/
template <typename F>
CHIP_ERROR ConvertHexToBytes(chip::CharSpan hex, F bufferAllocator, size_t * octetCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have HexToBytes too, inside the BytesToHex header.

{
public:
// Returns whether the parse succeeded.
static bool ParseComplexArgument(const char * label, const char * json, Json::Value & value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be duplicating the chip-tool complex argument parser, right? Is it different from that code? If so, maybe it should not be called ParseComplexArgument... If it's not different, why is it separate?

constexpr const char kHexNumPrefix[] = "0x";
constexpr size_t kHexNumPrefixLen = ArraySize(kHexNumPrefix) - 1;

Json::Value objTlvType = value.get("tlvType", "0x0c");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document why the defaulting to 0x0c.

@yunhanw-google
Copy link
Contributor

@chrisdecenzo we are preparing one pull request that provide the generic TLV-JSON-TLV converter using C++ along with documentation, similar to the kotlin one we provided in #26527
@emargolis is working on this c++ version, which should be ready within 1 or 2 weeks, you can consider to leverage that version

@stale
Copy link

stale bot commented Sep 17, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale Stale issue or PR label Sep 17, 2023
@woody-apple woody-apple added this to the No Target Milestone milestone Nov 27, 2023
Copy link

stale bot commented Mar 13, 2024

This stale pull request has been automatically closed. Thank you for your contributions.

@andy31415
Copy link
Contributor

This seems in draft for over 1 year. @chrisdecenzo can we close it?

@andy31415
Copy link
Contributor

Closing very old PR in draft form.

@andy31415 andy31415 closed this Oct 10, 2024
@andy31415 andy31415 deleted the json-tlv2 branch October 10, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants