jsongen.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. #!/usr/bin/env python3
  2. #
  3. # This file is Copyright 2010 by the GPSD project
  4. # SPDX-License-Identifier: BSD-2-clause
  5. #
  6. # This code runs compatibly under Python 2 and 3.x for x >= 2.
  7. # Preserve this property!
  8. """Never hand-hack what you can generate...
  9. This code generates template declarations for AIS-JSON parsing from a
  10. declarative specification of a JSON structure.
  11. """
  12. from __future__ import absolute_import, print_function, division
  13. import getopt
  14. import sys
  15. #
  16. # Here is the information that makes it all work - attribute, type, and
  17. # default information for all fields. We generate a JSON
  18. # parser template spec. Doing it this way guarantees consistency.
  19. #
  20. # Notes on the fields:
  21. # initname: becomes the name of the generated structure initializer
  22. # header: common header to include in front of the structure template
  23. # structname: gets prepended to all fieldnames in the generated C
  24. # fieldmap: each member fills an initializer slot
  25. # stringbuffered: list strings that should be buffered rather than copied
  26. # directly into the structure.
  27. ais_specs = (
  28. {
  29. "initname": "json_ais1",
  30. "headers": ("AIS_HEADER",),
  31. "structname": "ais->type1",
  32. "fieldmap": (
  33. # fieldname type default
  34. ('status', 'uinteger', '0'),
  35. ('status_text', 'ignore', None),
  36. ('turn', 'integer', 'AIS_TURN_NOT_AVAILABLE'),
  37. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  38. ('accuracy', 'boolean', 'false'),
  39. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  40. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  41. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  42. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  43. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  44. ('maneuver', 'uinteger', 'AIS_SEC_INOPERATIVE'),
  45. ('raim', 'boolean', 'false'),
  46. ('radio', 'uinteger', '0'),
  47. ),
  48. },
  49. # Message types 2 and 3 duplicate 1
  50. {
  51. "initname": "json_ais4",
  52. "headers": ("AIS_HEADER",),
  53. "structname": "ais->type4",
  54. "fieldmap": (
  55. # fieldname type default
  56. ('timestamp', 'string', None),
  57. ('accuracy', 'boolean', "true"),
  58. ('lon', 'integer', "AIS_LON_NOT_AVAILABLE"),
  59. ('lat', 'integer', "AIS_LAT_NOT_AVAILABLE"),
  60. ('epfd', 'uinteger', "0"),
  61. ('epfd_text', 'ignore', None),
  62. ('raim', 'boolean', "false"),
  63. ('radio', 'uinteger', "0"),
  64. ),
  65. "stringbuffered": ("timestamp",),
  66. },
  67. {
  68. "initname": "json_ais5",
  69. "headers": ("AIS_HEADER",),
  70. "structname": "ais->type5",
  71. "fieldmap": (
  72. # fieldname type default
  73. ('imo', 'uinteger', '0'),
  74. ('ais_version', 'uinteger', '0'),
  75. ('callsign', 'string', None),
  76. ('shipname', 'string', None),
  77. ('shiptype', 'uinteger', '0'),
  78. ('shiptype_text', 'ignore', None),
  79. ('to_bow', 'uinteger', '0'),
  80. ('to_stern', 'uinteger', '0'),
  81. ('to_port', 'uinteger', '0'),
  82. ('to_starboard', 'uinteger', '0'),
  83. ('epfd', 'uinteger', '0'),
  84. ('epfd_text', 'ignore', None),
  85. ('eta', 'string', None),
  86. ('draught', 'uinteger', '0'),
  87. ('destination', 'string', None),
  88. ('dte', 'uinteger', '1'),
  89. ),
  90. "stringbuffered": ("eta",),
  91. },
  92. {
  93. "initname": "json_ais6",
  94. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  95. "structname": "ais->type6",
  96. "fieldmap": (
  97. # fieldname type default
  98. ('data', 'string', None),
  99. ),
  100. "stringbuffered": ("data",),
  101. },
  102. {
  103. "initname": "json_ais6_fid10",
  104. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  105. "structname": "ais->type6.dac235fid10",
  106. "fieldmap": (
  107. # fieldname type default
  108. ('ana_int', 'uinteger', '0'),
  109. ('ana_ext1', 'uinteger', '0'),
  110. ('ana_ext2', 'uinteger', '0'),
  111. ('racon', 'uinteger', '0'),
  112. ('racon_text', 'ignore', None),
  113. ('light', 'uinteger', '0'),
  114. ('light_text', 'ignore', None),
  115. ('alarm', 'boolean', 'false'),
  116. ('stat_ext', 'uinteger', '0'),
  117. ('off_pos', 'boolean', 'false'),
  118. ),
  119. },
  120. {
  121. "initname": "json_ais6_fid12",
  122. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  123. "structname": "ais->type6.dac1fid12",
  124. "fieldmap": (
  125. # fieldname type default
  126. ('lastport', 'string', None),
  127. ('departure', 'string', None),
  128. ('nextport', 'string', None),
  129. ('eta', 'string', None),
  130. ('dangerous', 'string', None),
  131. ('imdcat', 'string', None),
  132. ('unid', 'uinteger', '0'),
  133. ('amount', 'uinteger', '0'),
  134. ('unit', 'uinteger', '0'),
  135. ),
  136. "stringbuffered": ("departure", "eta",),
  137. },
  138. {
  139. "initname": "json_ais6_fid15",
  140. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  141. "structname": "ais->type6.dac1fid15",
  142. "fieldmap": (
  143. # fieldname type default
  144. ('airdraught', 'uinteger', '0'),
  145. ),
  146. },
  147. {
  148. "initname": "json_ais6_fid16",
  149. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  150. "structname": "ais->type6.dac1fid16",
  151. "fieldmap": (
  152. # fieldname type default
  153. ('persons', 'uinteger', '0'),
  154. ),
  155. },
  156. {
  157. "initname": "json_ais6_fid18",
  158. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  159. "structname": "ais->type6.dac1fid18",
  160. "fieldmap": (
  161. # fieldname type default
  162. ('linkage', 'uinteger', '0'),
  163. ('arrival', 'string', None),
  164. ('portname', 'string', None),
  165. ('destination', 'string', None),
  166. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  167. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  168. ),
  169. 'stringbuffered': ('arrival',),
  170. },
  171. {
  172. "initname": "json_ais6_fid20",
  173. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  174. "structname": "ais->type6.dac1fid20",
  175. "fieldmap": (
  176. # fieldname type default
  177. ('linkage', 'uinteger', '0'),
  178. ('berth_length', 'uinteger', '0'),
  179. ('berth_depth', 'uinteger', '0'),
  180. ('position', 'uinteger', '0'),
  181. ('position_text', 'ignore', None),
  182. ('arrival', 'string', None),
  183. ('availability', 'uinteger', '0'),
  184. ('agent', 'uinteger', '0'),
  185. ('fuel', 'uinteger', '0'),
  186. ('chandler', 'uinteger', '0'),
  187. ('stevedore', 'uinteger', '0'),
  188. ('electrical', 'uinteger', '0'),
  189. ('water', 'uinteger', '0'),
  190. ('customs', 'uinteger', '0'),
  191. ('cartage', 'uinteger', '0'),
  192. ('crane', 'uinteger', '0'),
  193. ('lift', 'uinteger', '0'),
  194. ('medical', 'uinteger', '0'),
  195. ('navrepair', 'uinteger', '0'),
  196. ('provisions', 'uinteger', '0'),
  197. ('shiprepair', 'uinteger', '0'),
  198. ('surveyor', 'uinteger', '0'),
  199. ('steam', 'uinteger', '0'),
  200. ('tugs', 'uinteger', '0'),
  201. ('solidwaste', 'uinteger', '0'),
  202. ('liquidwaste', 'uinteger', '0'),
  203. ('hazardouswaste', 'uinteger', '0'),
  204. ('ballast', 'uinteger', '0'),
  205. ('additional', 'uinteger', '0'),
  206. ('regional1', 'uinteger', '0'),
  207. ('regional2', 'uinteger', '0'),
  208. ('future1', 'uinteger', '0'),
  209. ('future2', 'uinteger', '0'),
  210. ('berth_name', 'string', None),
  211. ('berth_lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  212. ('berth_lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  213. ),
  214. 'stringbuffered': ('arrival', 'berth_name',),
  215. },
  216. {
  217. "initname": "json_ais6_fid21",
  218. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  219. "structname": "ais->type6.dac200fid21",
  220. "fieldmap": (
  221. # fieldname type default
  222. ('country', 'string', None),
  223. ('locode', 'string', None),
  224. ('section', 'string', None),
  225. ('terminal', 'string', None),
  226. ('hectometre', 'string', None),
  227. ('eta', 'string', None),
  228. ('tugs', 'uinteger', '0'),
  229. ('airdraught', 'uinteger', '0'),
  230. ),
  231. "stringbuffered": ("eta",),
  232. },
  233. {
  234. "initname": "json_ais6_fid22",
  235. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  236. "structname": "ais->type6.dac200fid22",
  237. "fieldmap": (
  238. # fieldname type default
  239. ('country', 'string', None),
  240. ('locode', 'string', None),
  241. ('section', 'string', None),
  242. ('terminal', 'string', None),
  243. ('hectometre', 'string', None),
  244. ('rta', 'string', None),
  245. ('status', 'uinteger', 'DAC200FID22_STATUS_NOT_AVAILABLE'),
  246. ),
  247. "stringbuffered": ("rta",),
  248. },
  249. {
  250. "initname": "json_ais6_fid25",
  251. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  252. "structname": "ais->type6.dac1fid25",
  253. "fieldmap": (
  254. # fieldname type default
  255. ('unit', 'uinteger', '0'),
  256. ('amount', 'uinteger', '0'),
  257. ('cargos', 'array', (
  258. ('cargo_t', 'ncargos', (
  259. ('code', 'uinteger', '0'),
  260. ('subtype', 'uinteger', '0'),
  261. )))),
  262. ),
  263. },
  264. {
  265. "initname": "json_ais6_fid28",
  266. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  267. "structname": "ais->type6.dac1fid28",
  268. "fieldmap": (
  269. # fieldname type default
  270. ('linkage', 'uinteger', '0'),
  271. ('sender', 'uinteger', '0'),
  272. ('rtype', 'uinteger', '0'),
  273. ('rtype_text', 'ignore', None),
  274. ('start', 'string', None),
  275. ('duration', 'uinteger', '0'),
  276. ('waypoints', 'array', (
  277. ('waypoint_t', 'waycount', (
  278. ('lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  279. ('lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  280. )))),
  281. ),
  282. 'stringbuffered': ('start',),
  283. },
  284. {
  285. "initname": "json_ais6_fid30",
  286. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  287. "structname": "ais->type6.dac1fid30",
  288. "fieldmap": (
  289. # fieldname type default
  290. ('linkage', 'uinteger', '0'),
  291. ('text', 'string', '0'),
  292. ),
  293. },
  294. {
  295. "initname": "json_ais6_fid32",
  296. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  297. "structname": "ais->type6.dac1fid32",
  298. "fieldmap": (
  299. # fieldname type default
  300. ('month', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  301. ('day', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  302. ('tidals', 'array', (
  303. ('tidal_t', 'ntidals', (
  304. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  305. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  306. ('from_hour', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  307. ('from_min', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  308. ('to_hour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  309. ('to_min', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  310. ('cdir', 'uinteger', 'DAC1FID32_CDIR_NOT_AVAILABLE'),
  311. ('cspeed', 'uinteger', 'DAC1FID32_CSPEED_NOT_AVAILABLE'),
  312. )))),
  313. ),
  314. },
  315. {
  316. "initname": "json_ais6_fid55",
  317. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  318. "structname": "ais->type6.dac200fid55",
  319. "fieldmap": (
  320. # fieldname type default
  321. ('crew', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  322. ('passengers', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  323. ('personnel', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  324. ),
  325. },
  326. {
  327. "initname": "json_ais7",
  328. "headers": ("AIS_HEADER",),
  329. "structname": "ais->type7",
  330. "fieldmap": (
  331. # fieldname type default
  332. ('mmsi1', 'uinteger', '0'),
  333. ('mmsi2', 'uinteger', '0'),
  334. ('mmsi3', 'uinteger', '0'),
  335. ('mmsi4', 'uinteger', '0'),
  336. ('seqno1', 'uinteger', '0'),
  337. ('seqno2', 'uinteger', '0'),
  338. ('seqno3', 'uinteger', '0'),
  339. ('seqno4', 'uinteger', '0'),
  340. ),
  341. },
  342. {
  343. "initname": "json_ais8",
  344. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  345. "structname": "ais->type8",
  346. "fieldmap": (
  347. # fieldname type default
  348. ('data', 'string', None),
  349. ),
  350. "stringbuffered": ("data",),
  351. },
  352. {
  353. "initname": "json_ais8_fid10",
  354. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  355. "structname": "ais->type8.dac200fid10",
  356. "fieldmap": (
  357. # fieldname type default
  358. ('vin', 'string', None),
  359. ('length', 'uinteger', '0'),
  360. ('beam', 'uinteger', '0'),
  361. ('shiptype', 'uinteger', '0'),
  362. ('shiptype_text', 'ignore', None),
  363. ('hazard', 'uinteger', '0'),
  364. ('hazard_text', 'ignore', None),
  365. ('draught', 'uinteger', '0'),
  366. ('loaded', 'uinteger', '0'),
  367. ('loaded_text', 'ignore', None),
  368. ('speed_q', 'boolean', 'false'),
  369. ('course_q', 'boolean', 'false'),
  370. ('heading_q', 'boolean', 'false'),
  371. ),
  372. },
  373. {
  374. "initname": "json_ais8_fid11",
  375. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  376. "structname": "ais->type8.dac1fid11",
  377. "fieldmap": (
  378. # fieldname type default
  379. ('lat', 'integer', 'DAC1FID11_LAT_NOT_AVAILABLE'),
  380. ('lon', 'integer', 'DAC1FID11_LON_NOT_AVAILABLE'),
  381. ('timestamp', 'string', None),
  382. ('wspeed', 'uinteger', 'DAC1FID11_WSPEED_NOT_AVAILABLE'),
  383. ('wgust', 'uinteger', 'DAC1FID11_WSPEED_NOT_AVAILABLE'),
  384. ('wdir', 'uinteger', 'DAC1FID11_WDIR_NOT_AVAILABLE'),
  385. ('wgustdir', 'uinteger', 'DAC1FID11_WDIR_NOT_AVAILABLE'),
  386. ('airtemp', 'uinteger', 'DAC1FID11_AIRTEMP_NOT_AVAILABLE'),
  387. ('humidity', 'uinteger', 'DAC1FID11_HUMIDITY_NOT_AVAILABLE'),
  388. ('dewpoint', 'uinteger', 'DAC1FID11_DEWPOINT_NOT_AVAILABLE'),
  389. ('pressure', 'uinteger', 'DAC1FID11_PRESSURE_NOT_AVAILABLE'),
  390. ('pressuretend', 'uinteger',
  391. 'DAC1FID11_PRESSURETREND_NOT_AVAILABLE'),
  392. ('visibility', 'uinteger', 'DAC1FID11_VISIBILITY_NOT_AVAILABLE'),
  393. ('waterlevel', 'integer', 'DAC1FID11_WATERLEVEL_NOT_AVAILABLE'),
  394. ('leveltrend', 'uinteger',
  395. 'DAC1FID11_WATERLEVELTREND_NOT_AVAILABLE'),
  396. ('cspeed', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  397. ('cdir', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  398. ('cspeed2', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  399. ('cdir2', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  400. ('cdepth2', 'uinteger', 'DAC1FID11_CDEPTH_NOT_AVAILABLE'),
  401. ('cspeed3', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  402. ('cdir3', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  403. ('cdepth3', 'uinteger', 'DAC1FID11_CDEPTH_NOT_AVAILABLE'),
  404. ('waveheight', 'uinteger', 'DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE'),
  405. ('waveperiod', 'uinteger', 'DAC1FID11_WAVEPERIOD_NOT_AVAILABLE'),
  406. ('wavedir', 'uinteger', 'DAC1FID11_WAVEDIR_NOT_AVAILABLE'),
  407. ('swellheight', 'uinteger', 'DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE'),
  408. ('swellperiod', 'uinteger', 'DAC1FID11_WAVEPERIOD_NOT_AVAILABLE'),
  409. ('swelldir', 'uinteger', 'DAC1FID11_WAVEDIR_NOT_AVAILABLE'),
  410. ('seastate', 'uinteger', 'DAC1FID11_SEASTATE_NOT_AVAILABLE'),
  411. ('watertemp', 'uinteger', 'DAC1FID11_WATERTEMP_NOT_AVAILABLE'),
  412. ('preciptype', 'uinteger', 'DAC1FID11_PRECIPTYPE_NOT_AVAILABLE'),
  413. ('preciptype_text', 'ignore', None),
  414. ('salinity', 'uinteger', 'DAC1FID11_SALINITY_NOT_AVAILABLE'),
  415. ('ice', 'uinteger', 'DAC1FID11_ICE_NOT_AVAILABLE'),
  416. ('ice_text', 'ignore', None),
  417. ),
  418. "stringbuffered": ("timestamp",),
  419. },
  420. {
  421. "initname": "json_ais8_fid13",
  422. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  423. "structname": "ais->type8.dac1fid13",
  424. "fieldmap": (
  425. # fieldname type default
  426. ('reason', 'string', None),
  427. ('closefrom', 'string', None),
  428. ('closeto', 'string', None),
  429. ('radius', 'uinteger', 'AIS_DAC1FID13_RADIUS_NOT_AVAILABLE'),
  430. ('extunit', 'uinteger', 'AIS_DAC1FID13_EXTUNIT_NOT_AVAILABLE'),
  431. ('fday', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  432. ('fmonth', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  433. ('fhour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  434. ('fminute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  435. ('tday', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  436. ('tmonth', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  437. ('thour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  438. ('tminute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  439. ),
  440. 'stringbuffered': ('closefrom', 'closeto'),
  441. },
  442. {
  443. "initname": "json_ais8_fid15",
  444. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  445. "structname": "ais->type8.dac1fid15",
  446. "fieldmap": (
  447. # fieldname type default
  448. ('airdraught', 'uinteger', '0'),
  449. ),
  450. },
  451. {
  452. "initname": "json_ais8_fid16",
  453. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  454. "structname": "ais->type8.dac1fid16",
  455. "fieldmap": (
  456. # fieldname type default
  457. ('persons', 'uinteger', '0'),
  458. ),
  459. },
  460. {
  461. "initname": "json_ais8_fid17",
  462. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  463. "structname": "ais->type8.dac1fid17",
  464. "fieldmap": (
  465. # fieldname type default
  466. ('targets', 'array', (
  467. ('target_t', 'ntargets', (
  468. ('idtype', 'uinteger', 'DAC1FID17_IDTYPE_OTHER'),
  469. ("id.mmsi", 'uinteger', '0'),
  470. ("id.imo", 'uinteger', '0'),
  471. ("id.callsign", 'string', 'DAC1FID17_ID_LENGTH'),
  472. ("id.other", 'string', 'DAC1FID17_ID_LENGTH'),
  473. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  474. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  475. ('course', 'uinteger', 'DAC1FID17_COURSE_NOT_AVAILABLE'),
  476. ('second', 'uinteger', 'AIS_SECOND_NOT_AVAILABLE'),
  477. ('speed', 'uinteger', 'DAC1FID17_SPEED_NOT_AVAILABLE'),
  478. )))),
  479. ),
  480. },
  481. {
  482. "initname": "json_ais8_fid19",
  483. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  484. "structname": "ais->type8.dac1fid19",
  485. "fieldmap": (
  486. # fieldname type default
  487. ('linkage', 'uinteger', '0'),
  488. ('station', 'string', None),
  489. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  490. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  491. ('status', 'uinteger', '0'),
  492. ('signal', 'uinteger', '0'),
  493. ('signal_text', 'ignore', None),
  494. ('hour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  495. ('minute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  496. ('nextsignal', 'uinteger', '0'),
  497. ('nextsignal_type', 'ignore', None),
  498. ),
  499. },
  500. {
  501. "initname": "json_ais8_fid23",
  502. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  503. "structname": "ais->type8.dac200fid23",
  504. "fieldmap": (
  505. # fieldname type default
  506. ('start', 'string', None),
  507. ('end', 'string', None),
  508. ('start_lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  509. ('start_lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  510. ('end_lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  511. ('end_lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  512. ('type', 'uinteger', 'DAC200FID23_TYPE_UNKNOWN'),
  513. ('type_text', 'ignore', None),
  514. ('min', 'integer', 'DAC200FID23_MIN_UNKNOWN'),
  515. ('max', 'integer', 'DAC200FID23_MAX_UNKNOWN'),
  516. ('intensity', 'uinteger', 'DAC200FID23_CLASS_UNKNOWN'),
  517. ('intensity_text', 'ignore', None),
  518. ('wind', 'uinteger', 'DAC200FID23_WIND_UNKNOWN'),
  519. ('wind_text', 'ignore', None),
  520. ),
  521. 'stringbuffered': ('start', 'end'),
  522. },
  523. {
  524. "initname": "json_ais8_fid24",
  525. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  526. "structname": "ais->type8.dac200fid24",
  527. "fieldmap": (
  528. # fieldname type default
  529. ('country', 'string', None),
  530. ('gauges', 'array', (
  531. ('gauge_t', 'ngauges', (
  532. ('id', 'uinteger', 'DAC200FID24_GAUGE_ID_UNKNOWN'),
  533. ('level', 'integer', 'DAC200FID24_GAUGE_LEVEL_UNKNOWN'),
  534. )))),
  535. ),
  536. },
  537. {
  538. "initname": "json_ais8_fid27",
  539. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  540. "structname": "ais->type8.dac1fid27",
  541. "fieldmap": (
  542. # fieldname type default
  543. ('linkage', 'uinteger', '0'),
  544. ('sender', 'uinteger', '0'),
  545. ('rtype', 'uinteger', '0'),
  546. ('rtype_text', 'ignore', None),
  547. ('start', 'string', None),
  548. ('duration', 'uinteger', '0'),
  549. ('waypoints', 'array', (
  550. ('waypoint_t', 'waycount', (
  551. ('lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  552. ('lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  553. )))),
  554. ),
  555. 'stringbuffered': ('start',),
  556. },
  557. {
  558. "initname": "json_ais8_fid29",
  559. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  560. "structname": "ais->type8.dac1fid29",
  561. "fieldmap": (
  562. # fieldname type default
  563. ('linkage', 'uinteger', '0'),
  564. ('text', 'string', '0'),
  565. ),
  566. },
  567. {
  568. "initname": "json_ais8_fid31",
  569. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  570. "structname": "ais->type8.dac1fid31",
  571. "fieldmap": (
  572. # fieldname type default
  573. ('lon', 'integer', 'DAC1FID31_LON_NOT_AVAILABLE'),
  574. ('lat', 'integer', 'DAC1FID31_LAT_NOT_AVAILABLE'),
  575. ('accuracy', 'boolean', 'false'),
  576. ('timestamp', 'string', None),
  577. ('wspeed', 'uinteger', 'DAC1FID31_WIND_NOT_AVAILABLE'),
  578. ('wgust', 'uinteger', 'DAC1FID31_WIND_NOT_AVAILABLE'),
  579. ('wdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  580. ('wgustdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  581. ('airtemp', 'integer', 'DAC1FID31_AIRTEMP_NOT_AVAILABLE'),
  582. ('humidity', 'uinteger', 'DAC1FID31_HUMIDITY_NOT_AVAILABLE'),
  583. ('dewpoint', 'integer', 'DAC1FID31_DEWPOINT_NOT_AVAILABLE'),
  584. ('pressure', 'uinteger', 'DAC1FID31_PRESSURE_NOT_AVAILABLE'),
  585. ('pressuretend', 'uinteger',
  586. 'DAC1FID31_PRESSURETEND_NOT_AVAILABLE'),
  587. ('visgreater', 'boolean', 'false'),
  588. ('visibility', 'uinteger', 'DAC1FID31_VISIBILITY_NOT_AVAILABLE'),
  589. ('waterlevel', 'integer', 'DAC1FID31_WATERLEVEL_NOT_AVAILABLE'),
  590. ('leveltrend', 'uinteger',
  591. 'DAC1FID31_WATERLEVELTREND_NOT_AVAILABLE'),
  592. ('cspeed', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  593. ('cdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  594. ('cspeed2', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  595. ('cdir2', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  596. ('cdepth2', 'uinteger', 'DAC1FID31_CDEPTH_NOT_AVAILABLE'),
  597. ('cspeed3', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  598. ('cdir3', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  599. ('cdepth3', 'uinteger', 'DAC1FID31_CDEPTH_NOT_AVAILABLE'),
  600. ('waveheight', 'uinteger', 'DAC1FID31_HEIGHT_NOT_AVAILABLE'),
  601. ('waveperiod', 'uinteger', 'DAC1FID31_PERIOD_NOT_AVAILABLE'),
  602. ('wavedir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  603. ('swellheight', 'uinteger', 'DAC1FID31_HEIGHT_NOT_AVAILABLE'),
  604. ('swellperiod', 'uinteger', 'DAC1FID31_PERIOD_NOT_AVAILABLE'),
  605. ('swelldir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  606. ('seastate', 'uinteger', 'DAC1FID31_SEASTATE_NOT_AVAILABLE'),
  607. ('watertemp', 'integer', 'DAC1FID31_WATERTEMP_NOT_AVAILABLE'),
  608. ('preciptype', 'uinteger', 'DAC1FID31_PRECIPTYPE_NOT_AVAILABLE'),
  609. ('preciptype_text', 'ignore', None),
  610. ('salinity', 'uinteger', 'DAC1FID31_SALINITY_NOT_AVAILABLE'),
  611. ('ice', 'uinteger', 'DAC1FID31_ICE_NOT_AVAILABLE'),
  612. ),
  613. "stringbuffered": ("timestamp",),
  614. },
  615. {
  616. "initname": "json_ais8_fid40",
  617. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  618. "structname": "ais->type8.dac200fid40",
  619. "fieldmap": (
  620. # fieldname type default
  621. ('form', 'uinteger', 'DAC200FID40_FORM_UNKNOWN'),
  622. ('facing', 'uinteger', 'DAC200FID40_FACING_UNKNOWN'),
  623. ('direction', 'uinteger', 'DAC200FID40_DIRECTION_UNKNOWN'),
  624. ('direction_text', 'ignore', None),
  625. ('status', 'uinteger', 'DAC200FID40_STATUS_UNKNOWN'),
  626. ('status_text', 'ignore', None),
  627. ),
  628. },
  629. {
  630. "initname": "json_ais9",
  631. "headers": ("AIS_HEADER",),
  632. "structname": "ais->type9",
  633. "fieldmap": (
  634. # fieldname type default
  635. ('alt', 'uinteger', 'AIS_ALT_NOT_AVAILABLE'),
  636. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  637. ('accuracy', 'boolean', 'false'),
  638. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  639. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  640. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  641. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  642. ('regional', 'uinteger', '0'),
  643. ('dte', 'uinteger', '1'),
  644. ('raim', 'boolean', 'false'),
  645. ('radio', 'uinteger', '0'),
  646. ),
  647. },
  648. {
  649. "initname": "json_ais10",
  650. "headers": ("AIS_HEADER",),
  651. "structname": "ais->type10",
  652. "fieldmap": (
  653. # fieldname type default
  654. ('dest_mmsi', 'uinteger', '0'),
  655. ),
  656. },
  657. # Message type 11 duplicates 4
  658. {
  659. "initname": "json_ais12",
  660. "headers": ("AIS_HEADER",),
  661. "structname": "ais->type12",
  662. "fieldmap": (
  663. # fieldname type default
  664. ('seqno', 'uinteger', '0'),
  665. ('dest_mmsi', 'uinteger', '0'),
  666. ('retransmit', 'boolean', '0'),
  667. ('text', 'string', None),
  668. ),
  669. },
  670. # Message type 13 duplicates 7
  671. {
  672. "initname": "json_ais14",
  673. "headers": ("AIS_HEADER",),
  674. "structname": "ais->type14",
  675. "fieldmap": (
  676. # fieldname type default
  677. ('text', 'string', None),
  678. ),
  679. },
  680. {
  681. "initname": "json_ais15",
  682. "headers": ("AIS_HEADER",),
  683. "structname": "ais->type15",
  684. "fieldmap": (
  685. # fieldname type default
  686. ('mmsi1', 'uinteger', '0'),
  687. ('type1_1', 'uinteger', '0'),
  688. ('offset1_1', 'uinteger', '0'),
  689. ('type1_2', 'uinteger', '0'),
  690. ('offset1_2', 'uinteger', '0'),
  691. ('mmsi2', 'uinteger', '0'),
  692. ('type2_1', 'uinteger', '0'),
  693. ('offset2_1', 'uinteger', '0'),
  694. ),
  695. },
  696. {
  697. "initname": "json_ais16",
  698. "headers": ("AIS_HEADER",),
  699. "structname": "ais->type16",
  700. "fieldmap": (
  701. # fieldname type default
  702. ('mmsi1', 'uinteger', '0'),
  703. ('offset1', 'uinteger', '0'),
  704. ('increment1', 'uinteger', '0'),
  705. ('mmsi2', 'uinteger', '0'),
  706. ('offset2', 'uinteger', '0'),
  707. ('increment2', 'uinteger', '0'),
  708. ),
  709. },
  710. {
  711. "initname": "json_ais17",
  712. "headers": ("AIS_HEADER",),
  713. "structname": "ais->type17",
  714. "fieldmap": (
  715. # fieldname type default
  716. ('lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  717. ('lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  718. ('data', 'string', None),
  719. ),
  720. "stringbuffered": ("data",),
  721. },
  722. {
  723. "initname": "json_ais18",
  724. "headers": ("AIS_HEADER",),
  725. "structname": "ais->type18",
  726. "fieldmap": (
  727. # fieldname type default
  728. ('reserved', 'uinteger', '0'),
  729. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  730. ('accuracy', 'boolean', 'false'),
  731. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  732. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  733. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  734. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  735. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  736. ('regional', 'uinteger', '0'),
  737. ('cs', 'boolean', 'false'),
  738. ('display', 'boolean', 'false'),
  739. ('dsc', 'boolean', 'false'),
  740. ('band', 'boolean', 'false'),
  741. ('msg22', 'boolean', 'false'),
  742. ('raim', 'boolean', 'false'),
  743. ('radio', 'uinteger', '0'),
  744. ),
  745. },
  746. {
  747. "initname": "json_ais19",
  748. "headers": ("AIS_HEADER",),
  749. "structname": "ais->type19",
  750. "fieldmap": (
  751. # fieldname type default
  752. ('reserved', 'uinteger', '0'),
  753. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  754. ('accuracy', 'boolean', 'false'),
  755. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  756. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  757. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  758. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  759. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  760. ('regional', 'uinteger', '0'),
  761. ('shipname', 'string', None),
  762. ('shiptype', 'uinteger', '0'),
  763. ('shiptype_text', 'ignore', None),
  764. ('to_bow', 'uinteger', '0'),
  765. ('to_stern', 'uinteger', '0'),
  766. ('to_port', 'uinteger', '0'),
  767. ('to_starboard', 'uinteger', '0'),
  768. ('epfd', 'uinteger', '0'),
  769. ('epfd_text', 'ignore', None),
  770. ('raim', 'boolean', 'false'),
  771. ('dte', 'uinteger', '1'),
  772. ('assigned', 'boolean', 'false'),
  773. ),
  774. },
  775. {
  776. "initname": "json_ais20",
  777. "headers": ("AIS_HEADER",),
  778. "structname": "ais->type20",
  779. "fieldmap": (
  780. # fieldname type default
  781. ('offset1', 'uinteger', '0'),
  782. ('number1', 'uinteger', '0'),
  783. ('timeout1', 'uinteger', '0'),
  784. ('increment1', 'uinteger', '0'),
  785. ('offset2', 'uinteger', '0'),
  786. ('number2', 'uinteger', '0'),
  787. ('timeout2', 'uinteger', '0'),
  788. ('increment2', 'uinteger', '0'),
  789. ('offset3', 'uinteger', '0'),
  790. ('number3', 'uinteger', '0'),
  791. ('timeout3', 'uinteger', '0'),
  792. ('increment3', 'uinteger', '0'),
  793. ('offset4', 'uinteger', '0'),
  794. ('number4', 'uinteger', '0'),
  795. ('timeout4', 'uinteger', '0'),
  796. ('increment4', 'uinteger', '0'),
  797. ),
  798. },
  799. {
  800. "initname": "json_ais21",
  801. "headers": ("AIS_HEADER",),
  802. "structname": "ais->type21",
  803. "fieldmap": (
  804. # fieldname type default
  805. ('aid_type', 'uinteger', '0'),
  806. ('aid_type_text', 'ignore', None),
  807. ('name', 'string', None),
  808. ('accuracy', 'boolean', 'false'),
  809. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  810. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  811. ('to_bow', 'uinteger', '0'),
  812. ('to_stern', 'uinteger', '0'),
  813. ('to_port', 'uinteger', '0'),
  814. ('to_starboard', 'uinteger', '0'),
  815. ('epfd', 'uinteger', '0'),
  816. ('epfd_text', 'ignore', None),
  817. ('second', 'uinteger', '0'),
  818. ('regional', 'uinteger', '0'),
  819. ('off_position', 'boolean', 'false'),
  820. ('raim', 'boolean', 'false'),
  821. ('virtual_aid', 'boolean', 'false'),
  822. ),
  823. },
  824. {
  825. "initname": "json_ais22",
  826. "headers": ("AIS_HEADER",),
  827. "structname": "ais->type22",
  828. "fieldmap": (
  829. # fieldname type default
  830. ('channel_a', 'uinteger', '0'),
  831. ('channel_b', 'uinteger', '0'),
  832. ('txrx', 'uinteger', '0'),
  833. ('power', 'boolean', 'false'),
  834. ('area.ne_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  835. ('area.ne_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  836. ('area.sw_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  837. ('area.sw_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  838. ('mmsi.dest1', 'uinteger', '0'),
  839. ('mmsi.dest2', 'uinteger', '0'),
  840. ('addressed', 'boolean', 'false'),
  841. ('band_a', 'boolean', 'false'),
  842. ('band_b', 'boolean', 'false'),
  843. ('zonesize', 'uinteger', '0'),
  844. ),
  845. },
  846. {
  847. "initname": "json_ais23",
  848. "headers": ("AIS_HEADER",),
  849. "structname": "ais->type23",
  850. "fieldmap": (
  851. # fieldname type default
  852. ('ne_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  853. ('ne_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  854. ('sw_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  855. ('sw_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  856. ('stationtype', 'uinteger', '0'),
  857. ('stationtype_text', 'ignore', None),
  858. ('shiptype', 'uinteger', '0'),
  859. ('shiptype_text', 'ignore', None),
  860. ('txrx', 'uinteger', '0'),
  861. ('interval', 'uinteger', '0'),
  862. ('quiet', 'uinteger', '0'),
  863. ),
  864. },
  865. {
  866. "initname": "json_ais24",
  867. "headers": ("AIS_HEADER",),
  868. "structname": "ais->type24",
  869. "fieldmap": (
  870. # fieldname type default
  871. ('shipname', 'string', None), # Part A
  872. ('shiptype', 'uinteger', '0'), # Part B
  873. ('shiptype_text', 'ignore', None),
  874. ('vendorid', 'string', None), # Part B
  875. ('model', 'uinteger', '0'), # Part B
  876. ('serial', 'uinteger', '0'), # Part B
  877. ('callsign', 'string', None), # Part B
  878. ('mothership_mmsi', 'uinteger', '0'), # Part B
  879. ('dim.to_bow', 'uinteger', '0'), # Part B
  880. ('dim.to_stern', 'uinteger', '0'), # Part B
  881. ('dim.to_port', 'uinteger', '0'), # Part B
  882. ('dim.to_starboard', 'uinteger', '0'), # Part B
  883. ),
  884. },
  885. {
  886. "initname": "json_ais25",
  887. "headers": ("AIS_HEADER",),
  888. "structname": "ais->type25",
  889. "fieldmap": (
  890. # fieldname type default
  891. ('addressed', 'boolean', 'false'),
  892. ('structured', 'boolean', 'false'),
  893. ('dest_mmsi', 'uinteger', '0'),
  894. ('app_id', 'uinteger', '0'),
  895. ('data', 'string', None),
  896. ),
  897. "stringbuffered": ("data",),
  898. },
  899. {
  900. "initname": "json_ais26",
  901. "headers": ("AIS_HEADER",),
  902. "structname": "ais->type26",
  903. "fieldmap": (
  904. # fieldname type default
  905. ('addressed', 'boolean', 'false'),
  906. ('structured', 'boolean', 'false'),
  907. ('dest_mmsi', 'uinteger', '0'),
  908. ('app_id', 'uinteger', '0'),
  909. ('data', 'string', None),
  910. ('radio', 'uinteger', '0'),
  911. ),
  912. "stringbuffered": ("data",),
  913. },
  914. {
  915. "initname": "json_ais27",
  916. "headers": ("AIS_HEADER",),
  917. "structname": "ais->type27",
  918. "fieldmap": (
  919. # fieldname type default
  920. ('status', 'uinteger', '0'),
  921. ('speed', 'uinteger', 'AIS_LONGRANGE_SPEED_NOT_AVAILABLE'),
  922. ('accuracy', 'boolean', 'false'),
  923. ('lon', 'integer', 'AIS_LONGRANGE_LON_NOT_AVAILABLE'),
  924. ('lat', 'integer', 'AIS_LONGRANGE_LAT_NOT_AVAILABLE'),
  925. ('course', 'uinteger', 'AIS_LONGRANGE_COURSE_NOT_AVAILABLE'),
  926. ('raim', 'boolean', 'false'),
  927. ('gnss', 'boolean', 'true'),
  928. ),
  929. },
  930. )
  931. # You should not need to modify anything below this line.
  932. def generate(spec):
  933. """Generate it."""
  934. report = ""
  935. leader = " " * 39
  936. initname = spec["initname"]
  937. # Utter storage declarations for any fields that are declared to be
  938. # stringbuffered. These will need to be postprocessed in json_ais_read().
  939. attributes = [t[0] for t in spec["fieldmap"]]
  940. for attr in spec.get("stringbuffered", []):
  941. if attr not in attributes:
  942. sys.stderr.write("buffered %s is not in base attributes of %s\n"
  943. % (attr, initname))
  944. raise SystemExit(1)
  945. if attr not in outboard:
  946. report += " char %s[JSON_VAL_MAX+1];\n" % attr
  947. outboard.append(attr)
  948. structname = spec["structname"]
  949. # If there are structarrays describing array subobjects, we need
  950. # to make a separate parse control initializer for each one. The
  951. # attribute name is the name of the array; substructure and length
  952. # fieldnames must be given in the defaults part.
  953. for (attr, itype, arrayparts) in spec["fieldmap"]:
  954. if itype == 'array':
  955. (innerstruct, lengthfield, elements) = arrayparts
  956. report += (" const struct json_attr_t %s_%s_subtype[] = {\n"
  957. % (initname, attr))
  958. for (subattr, subitype, default) in elements:
  959. report += ('\t{"%s",%st_%s,%sSTRUCTOBJECT(struct %s, %s),\n'
  960. % (subattr, " " * (14 - len(subattr)), subitype,
  961. " " * (8 - len(subitype)), innerstruct, subattr))
  962. if subitype != "string":
  963. report += (leader + ".dflt.%s = %s},\n"
  964. % (subitype, default))
  965. elif default:
  966. report += leader + ".len = %s},\n" % (default,)
  967. else:
  968. sys.stderr.write(
  969. "explicit length specification required\n")
  970. raise SystemExit(1)
  971. report += """\
  972. {NULL}
  973. };
  974. """
  975. # Generate the main structure definition describing this parse.
  976. # It may have object subarrays.
  977. report += " const struct json_attr_t %s[] = {\n" % initname
  978. if "headers" in spec:
  979. for header in spec["headers"]:
  980. report += '\t' + header + "\n"
  981. for (attr, itype, default) in spec["fieldmap"]:
  982. if itype == 'array':
  983. (innerstruct, lengthfield, elements) = default
  984. report += ('\t{"%s",%st_array, '
  985. 'STRUCTARRAY(%s.%s, %s_%s_subtype, &%s.%s)},\n'
  986. % (attr, " " * (14 - len(attr)), structname, attr,
  987. initname, attr, structname, lengthfield))
  988. else:
  989. if itype == "string":
  990. deref = ""
  991. else:
  992. deref = "&"
  993. if attr in spec.get("stringbuffered", []):
  994. target = attr
  995. else:
  996. target = structname + "." + attr
  997. if "." in attr:
  998. attr = attr[attr.rfind(".") + 1:]
  999. if itype == 'ignore':
  1000. report += '\t{"%s", t_ignore},\n' % attr
  1001. continue
  1002. report += '\t{"%s",%st_%s,%s.addr.%s = %s%s,\n' % \
  1003. (attr, " " * (14 - len(attr)), itype, " " * (10 - len(itype)),
  1004. itype, deref, target)
  1005. if itype == "string":
  1006. report += leader + ".len = sizeof(%s)},\n" % target
  1007. else:
  1008. report += leader + ".dflt.%s = %s},\n" % (itype, default)
  1009. report += """\
  1010. {NULL}
  1011. };
  1012. """
  1013. print(report)
  1014. if __name__ == '__main__':
  1015. try:
  1016. # The --ais and --target= options are (required) placeholders.
  1017. # In the future, this script will generate more different kinds
  1018. # of code.
  1019. (options, arguments) = getopt.getopt(sys.argv[1:], "",
  1020. ["ais", "target="])
  1021. except getopt.GetoptError as msg:
  1022. print("jsongen.py: " + str(msg))
  1023. raise SystemExit(1)
  1024. spec = None
  1025. target = None
  1026. for (switch, val) in options:
  1027. if switch == '--ais':
  1028. spec = ais_specs
  1029. elif switch == '--target':
  1030. target = val
  1031. if not target or not spec:
  1032. print("jsongen.py: must specify type and target.")
  1033. raise SystemExit(1)
  1034. if target == 'parser':
  1035. print("""/*
  1036. * This is code generated by jsongen.py. Do not hand-hack it!
  1037. */
  1038. #define NITEMS(x) (int)(sizeof(x)/sizeof(x[0]))
  1039. """)
  1040. outboard = []
  1041. for description in spec:
  1042. generate(description)
  1043. print("""
  1044. /* Generated code ends. */
  1045. """)
  1046. # The following sets edit modes for GNU EMACS
  1047. # Local Variables:
  1048. # mode:python
  1049. # End:
  1050. # vim: set expandtab shiftwidth=4