pg_query 1.3.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (480) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +237 -117
  3. data/README.md +84 -65
  4. data/Rakefile +71 -5
  5. data/ext/pg_query/extconf.rb +4 -38
  6. data/ext/pg_query/guc-file.c +0 -0
  7. data/ext/pg_query/include/access/amapi.h +246 -0
  8. data/ext/pg_query/include/access/attmap.h +52 -0
  9. data/ext/pg_query/include/access/attnum.h +64 -0
  10. data/ext/pg_query/include/access/clog.h +61 -0
  11. data/ext/pg_query/include/access/commit_ts.h +77 -0
  12. data/ext/pg_query/include/access/detoast.h +92 -0
  13. data/ext/pg_query/include/access/genam.h +228 -0
  14. data/ext/pg_query/include/access/gin.h +78 -0
  15. data/ext/pg_query/include/access/htup.h +89 -0
  16. data/ext/pg_query/include/access/htup_details.h +819 -0
  17. data/ext/pg_query/include/access/itup.h +161 -0
  18. data/ext/pg_query/include/access/parallel.h +82 -0
  19. data/ext/pg_query/include/access/printtup.h +35 -0
  20. data/ext/pg_query/include/access/relation.h +28 -0
  21. data/ext/pg_query/include/access/relscan.h +176 -0
  22. data/ext/pg_query/include/access/rmgr.h +35 -0
  23. data/ext/pg_query/include/access/rmgrlist.h +49 -0
  24. data/ext/pg_query/include/access/sdir.h +58 -0
  25. data/ext/pg_query/include/access/skey.h +151 -0
  26. data/ext/pg_query/include/access/stratnum.h +83 -0
  27. data/ext/pg_query/include/access/sysattr.h +29 -0
  28. data/ext/pg_query/include/access/table.h +27 -0
  29. data/ext/pg_query/include/access/tableam.h +1825 -0
  30. data/ext/pg_query/include/access/transam.h +265 -0
  31. data/ext/pg_query/include/access/tupconvert.h +51 -0
  32. data/ext/pg_query/include/access/tupdesc.h +154 -0
  33. data/ext/pg_query/include/access/tupmacs.h +247 -0
  34. data/ext/pg_query/include/access/twophase.h +61 -0
  35. data/ext/pg_query/include/access/xact.h +463 -0
  36. data/ext/pg_query/include/access/xlog.h +398 -0
  37. data/ext/pg_query/include/access/xlog_internal.h +330 -0
  38. data/ext/pg_query/include/access/xlogdefs.h +109 -0
  39. data/ext/pg_query/include/access/xloginsert.h +64 -0
  40. data/ext/pg_query/include/access/xlogreader.h +327 -0
  41. data/ext/pg_query/include/access/xlogrecord.h +227 -0
  42. data/ext/pg_query/include/bootstrap/bootstrap.h +62 -0
  43. data/ext/pg_query/include/c.h +1334 -0
  44. data/ext/pg_query/include/catalog/catalog.h +42 -0
  45. data/ext/pg_query/include/catalog/catversion.h +58 -0
  46. data/ext/pg_query/include/catalog/dependency.h +275 -0
  47. data/ext/pg_query/include/catalog/genbki.h +64 -0
  48. data/ext/pg_query/include/catalog/index.h +199 -0
  49. data/ext/pg_query/include/catalog/indexing.h +366 -0
  50. data/ext/pg_query/include/catalog/namespace.h +188 -0
  51. data/ext/pg_query/include/catalog/objectaccess.h +197 -0
  52. data/ext/pg_query/include/catalog/objectaddress.h +84 -0
  53. data/ext/pg_query/include/catalog/pg_aggregate.h +176 -0
  54. data/ext/pg_query/include/catalog/pg_aggregate_d.h +77 -0
  55. data/ext/pg_query/include/catalog/pg_am.h +60 -0
  56. data/ext/pg_query/include/catalog/pg_am_d.h +45 -0
  57. data/ext/pg_query/include/catalog/pg_attribute.h +204 -0
  58. data/ext/pg_query/include/catalog/pg_attribute_d.h +59 -0
  59. data/ext/pg_query/include/catalog/pg_authid.h +58 -0
  60. data/ext/pg_query/include/catalog/pg_authid_d.h +49 -0
  61. data/ext/pg_query/include/catalog/pg_class.h +200 -0
  62. data/ext/pg_query/include/catalog/pg_class_d.h +103 -0
  63. data/ext/pg_query/include/catalog/pg_collation.h +73 -0
  64. data/ext/pg_query/include/catalog/pg_collation_d.h +45 -0
  65. data/ext/pg_query/include/catalog/pg_constraint.h +247 -0
  66. data/ext/pg_query/include/catalog/pg_constraint_d.h +67 -0
  67. data/ext/pg_query/include/catalog/pg_control.h +250 -0
  68. data/ext/pg_query/include/catalog/pg_conversion.h +72 -0
  69. data/ext/pg_query/include/catalog/pg_conversion_d.h +35 -0
  70. data/ext/pg_query/include/catalog/pg_depend.h +73 -0
  71. data/ext/pg_query/include/catalog/pg_depend_d.h +34 -0
  72. data/ext/pg_query/include/catalog/pg_event_trigger.h +51 -0
  73. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +34 -0
  74. data/ext/pg_query/include/catalog/pg_index.h +80 -0
  75. data/ext/pg_query/include/catalog/pg_index_d.h +56 -0
  76. data/ext/pg_query/include/catalog/pg_language.h +67 -0
  77. data/ext/pg_query/include/catalog/pg_language_d.h +39 -0
  78. data/ext/pg_query/include/catalog/pg_namespace.h +59 -0
  79. data/ext/pg_query/include/catalog/pg_namespace_d.h +34 -0
  80. data/ext/pg_query/include/catalog/pg_opclass.h +85 -0
  81. data/ext/pg_query/include/catalog/pg_opclass_d.h +49 -0
  82. data/ext/pg_query/include/catalog/pg_operator.h +102 -0
  83. data/ext/pg_query/include/catalog/pg_operator_d.h +106 -0
  84. data/ext/pg_query/include/catalog/pg_opfamily.h +60 -0
  85. data/ext/pg_query/include/catalog/pg_opfamily_d.h +47 -0
  86. data/ext/pg_query/include/catalog/pg_partitioned_table.h +63 -0
  87. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +35 -0
  88. data/ext/pg_query/include/catalog/pg_proc.h +211 -0
  89. data/ext/pg_query/include/catalog/pg_proc_d.h +99 -0
  90. data/ext/pg_query/include/catalog/pg_publication.h +115 -0
  91. data/ext/pg_query/include/catalog/pg_publication_d.h +36 -0
  92. data/ext/pg_query/include/catalog/pg_replication_origin.h +57 -0
  93. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +29 -0
  94. data/ext/pg_query/include/catalog/pg_statistic.h +275 -0
  95. data/ext/pg_query/include/catalog/pg_statistic_d.h +194 -0
  96. data/ext/pg_query/include/catalog/pg_statistic_ext.h +74 -0
  97. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +40 -0
  98. data/ext/pg_query/include/catalog/pg_transform.h +45 -0
  99. data/ext/pg_query/include/catalog/pg_transform_d.h +32 -0
  100. data/ext/pg_query/include/catalog/pg_trigger.h +137 -0
  101. data/ext/pg_query/include/catalog/pg_trigger_d.h +106 -0
  102. data/ext/pg_query/include/catalog/pg_ts_config.h +50 -0
  103. data/ext/pg_query/include/catalog/pg_ts_config_d.h +32 -0
  104. data/ext/pg_query/include/catalog/pg_ts_dict.h +54 -0
  105. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +33 -0
  106. data/ext/pg_query/include/catalog/pg_ts_parser.h +57 -0
  107. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +35 -0
  108. data/ext/pg_query/include/catalog/pg_ts_template.h +48 -0
  109. data/ext/pg_query/include/catalog/pg_ts_template_d.h +32 -0
  110. data/ext/pg_query/include/catalog/pg_type.h +372 -0
  111. data/ext/pg_query/include/catalog/pg_type_d.h +285 -0
  112. data/ext/pg_query/include/catalog/storage.h +48 -0
  113. data/ext/pg_query/include/commands/async.h +54 -0
  114. data/ext/pg_query/include/commands/dbcommands.h +35 -0
  115. data/ext/pg_query/include/commands/defrem.h +173 -0
  116. data/ext/pg_query/include/commands/event_trigger.h +88 -0
  117. data/ext/pg_query/include/commands/explain.h +127 -0
  118. data/ext/pg_query/include/commands/prepare.h +61 -0
  119. data/ext/pg_query/include/commands/tablespace.h +67 -0
  120. data/ext/pg_query/include/commands/trigger.h +277 -0
  121. data/ext/pg_query/include/commands/user.h +37 -0
  122. data/ext/pg_query/include/commands/vacuum.h +293 -0
  123. data/ext/pg_query/include/commands/variable.h +38 -0
  124. data/ext/pg_query/include/common/file_perm.h +56 -0
  125. data/ext/pg_query/include/common/hashfn.h +104 -0
  126. data/ext/pg_query/include/common/ip.h +37 -0
  127. data/ext/pg_query/include/common/keywords.h +33 -0
  128. data/ext/pg_query/include/common/kwlookup.h +44 -0
  129. data/ext/pg_query/include/common/relpath.h +90 -0
  130. data/ext/pg_query/include/common/string.h +19 -0
  131. data/ext/pg_query/include/common/unicode_combining_table.h +196 -0
  132. data/ext/pg_query/include/datatype/timestamp.h +197 -0
  133. data/ext/pg_query/include/executor/execdesc.h +70 -0
  134. data/ext/pg_query/include/executor/executor.h +620 -0
  135. data/ext/pg_query/include/executor/functions.h +41 -0
  136. data/ext/pg_query/include/executor/instrument.h +101 -0
  137. data/ext/pg_query/include/executor/spi.h +175 -0
  138. data/ext/pg_query/include/executor/tablefunc.h +67 -0
  139. data/ext/pg_query/include/executor/tuptable.h +487 -0
  140. data/ext/pg_query/include/fmgr.h +775 -0
  141. data/ext/pg_query/include/funcapi.h +348 -0
  142. data/ext/pg_query/include/getaddrinfo.h +162 -0
  143. data/ext/pg_query/include/jit/jit.h +105 -0
  144. data/ext/pg_query/include/kwlist_d.h +1072 -0
  145. data/ext/pg_query/include/lib/ilist.h +727 -0
  146. data/ext/pg_query/include/lib/pairingheap.h +102 -0
  147. data/ext/pg_query/include/lib/simplehash.h +1059 -0
  148. data/ext/pg_query/include/lib/stringinfo.h +161 -0
  149. data/ext/pg_query/include/libpq/auth.h +29 -0
  150. data/ext/pg_query/include/libpq/crypt.h +46 -0
  151. data/ext/pg_query/include/libpq/hba.h +140 -0
  152. data/ext/pg_query/include/libpq/libpq-be.h +326 -0
  153. data/ext/pg_query/include/libpq/libpq.h +133 -0
  154. data/ext/pg_query/include/libpq/pqcomm.h +208 -0
  155. data/ext/pg_query/include/libpq/pqformat.h +210 -0
  156. data/ext/pg_query/include/libpq/pqsignal.h +42 -0
  157. data/ext/pg_query/include/mb/pg_wchar.h +672 -0
  158. data/ext/pg_query/include/mb/stringinfo_mb.h +24 -0
  159. data/ext/pg_query/include/miscadmin.h +476 -0
  160. data/ext/pg_query/include/nodes/bitmapset.h +122 -0
  161. data/ext/pg_query/include/nodes/execnodes.h +2523 -0
  162. data/ext/pg_query/include/nodes/extensible.h +160 -0
  163. data/ext/pg_query/include/nodes/lockoptions.h +61 -0
  164. data/ext/pg_query/include/nodes/makefuncs.h +108 -0
  165. data/ext/pg_query/include/nodes/memnodes.h +108 -0
  166. data/ext/pg_query/include/nodes/nodeFuncs.h +162 -0
  167. data/ext/pg_query/include/nodes/nodes.h +842 -0
  168. data/ext/pg_query/include/nodes/params.h +170 -0
  169. data/ext/pg_query/include/nodes/parsenodes.h +3579 -0
  170. data/ext/pg_query/include/nodes/pathnodes.h +2556 -0
  171. data/ext/pg_query/include/nodes/pg_list.h +605 -0
  172. data/ext/pg_query/include/nodes/plannodes.h +1251 -0
  173. data/ext/pg_query/include/nodes/primnodes.h +1541 -0
  174. data/ext/pg_query/include/nodes/print.h +34 -0
  175. data/ext/pg_query/include/nodes/tidbitmap.h +75 -0
  176. data/ext/pg_query/include/nodes/value.h +61 -0
  177. data/ext/pg_query/include/optimizer/cost.h +206 -0
  178. data/ext/pg_query/include/optimizer/geqo.h +88 -0
  179. data/ext/pg_query/include/optimizer/geqo_gene.h +45 -0
  180. data/ext/pg_query/include/optimizer/optimizer.h +199 -0
  181. data/ext/pg_query/include/optimizer/paths.h +257 -0
  182. data/ext/pg_query/include/optimizer/planmain.h +119 -0
  183. data/ext/pg_query/include/parser/analyze.h +49 -0
  184. data/ext/pg_query/include/parser/gram.h +1067 -0
  185. data/ext/pg_query/include/parser/gramparse.h +75 -0
  186. data/ext/pg_query/include/parser/kwlist.h +477 -0
  187. data/ext/pg_query/include/parser/parse_agg.h +68 -0
  188. data/ext/pg_query/include/parser/parse_clause.h +54 -0
  189. data/ext/pg_query/include/parser/parse_coerce.h +97 -0
  190. data/ext/pg_query/include/parser/parse_collate.h +27 -0
  191. data/ext/pg_query/include/parser/parse_expr.h +26 -0
  192. data/ext/pg_query/include/parser/parse_func.h +73 -0
  193. data/ext/pg_query/include/parser/parse_node.h +327 -0
  194. data/ext/pg_query/include/parser/parse_oper.h +67 -0
  195. data/ext/pg_query/include/parser/parse_relation.h +123 -0
  196. data/ext/pg_query/include/parser/parse_target.h +46 -0
  197. data/ext/pg_query/include/parser/parse_type.h +60 -0
  198. data/ext/pg_query/include/parser/parser.h +41 -0
  199. data/ext/pg_query/include/parser/parsetree.h +61 -0
  200. data/ext/pg_query/include/parser/scanner.h +152 -0
  201. data/ext/pg_query/include/parser/scansup.h +30 -0
  202. data/ext/pg_query/include/partitioning/partdefs.h +26 -0
  203. data/ext/pg_query/include/pg_config.h +989 -0
  204. data/ext/pg_query/include/pg_config_ext.h +8 -0
  205. data/ext/pg_query/include/pg_config_manual.h +357 -0
  206. data/ext/pg_query/include/pg_config_os.h +8 -0
  207. data/ext/pg_query/include/pg_getopt.h +56 -0
  208. data/ext/pg_query/include/pg_query.h +121 -0
  209. data/ext/pg_query/include/pg_query_enum_defs.c +2454 -0
  210. data/ext/pg_query/include/pg_query_fingerprint_conds.c +875 -0
  211. data/ext/pg_query/include/pg_query_fingerprint_defs.c +12413 -0
  212. data/ext/pg_query/include/pg_query_json_helper.c +61 -0
  213. data/ext/pg_query/include/pg_query_outfuncs_conds.c +686 -0
  214. data/ext/pg_query/include/pg_query_outfuncs_defs.c +2438 -0
  215. data/ext/pg_query/include/pg_query_readfuncs_conds.c +222 -0
  216. data/ext/pg_query/include/pg_query_readfuncs_defs.c +2879 -0
  217. data/ext/pg_query/include/pg_trace.h +17 -0
  218. data/ext/pg_query/include/pgstat.h +1487 -0
  219. data/ext/pg_query/include/pgtime.h +84 -0
  220. data/ext/pg_query/include/pl_gram.h +385 -0
  221. data/ext/pg_query/include/pl_reserved_kwlist.h +52 -0
  222. data/ext/pg_query/include/pl_reserved_kwlist_d.h +114 -0
  223. data/ext/pg_query/include/pl_unreserved_kwlist.h +112 -0
  224. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +246 -0
  225. data/ext/pg_query/include/plerrcodes.h +990 -0
  226. data/ext/pg_query/include/plpgsql.h +1347 -0
  227. data/ext/pg_query/include/port.h +524 -0
  228. data/ext/pg_query/include/port/atomics.h +524 -0
  229. data/ext/pg_query/include/port/atomics/arch-arm.h +26 -0
  230. data/ext/pg_query/include/port/atomics/arch-ppc.h +254 -0
  231. data/ext/pg_query/include/port/atomics/arch-x86.h +252 -0
  232. data/ext/pg_query/include/port/atomics/fallback.h +170 -0
  233. data/ext/pg_query/include/port/atomics/generic-gcc.h +286 -0
  234. data/ext/pg_query/include/port/atomics/generic.h +401 -0
  235. data/ext/pg_query/include/port/pg_bitutils.h +226 -0
  236. data/ext/pg_query/include/port/pg_bswap.h +161 -0
  237. data/ext/pg_query/include/port/pg_crc32c.h +101 -0
  238. data/ext/pg_query/include/portability/instr_time.h +256 -0
  239. data/ext/pg_query/include/postgres.h +764 -0
  240. data/ext/pg_query/include/postgres_ext.h +74 -0
  241. data/ext/pg_query/include/postmaster/autovacuum.h +83 -0
  242. data/ext/pg_query/include/postmaster/bgworker.h +161 -0
  243. data/ext/pg_query/include/postmaster/bgworker_internals.h +64 -0
  244. data/ext/pg_query/include/postmaster/bgwriter.h +45 -0
  245. data/ext/pg_query/include/postmaster/fork_process.h +17 -0
  246. data/ext/pg_query/include/postmaster/interrupt.h +32 -0
  247. data/ext/pg_query/include/postmaster/pgarch.h +39 -0
  248. data/ext/pg_query/include/postmaster/postmaster.h +77 -0
  249. data/ext/pg_query/include/postmaster/syslogger.h +98 -0
  250. data/ext/pg_query/include/postmaster/walwriter.h +21 -0
  251. data/ext/pg_query/include/protobuf-c.h +1110 -0
  252. data/ext/pg_query/include/protobuf-c/protobuf-c.h +1110 -0
  253. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +10851 -0
  254. data/ext/pg_query/include/protobuf/pg_query.pb.h +124718 -0
  255. data/ext/pg_query/include/regex/regex.h +184 -0
  256. data/ext/pg_query/include/replication/logicallauncher.h +31 -0
  257. data/ext/pg_query/include/replication/logicalproto.h +110 -0
  258. data/ext/pg_query/include/replication/logicalworker.h +19 -0
  259. data/ext/pg_query/include/replication/origin.h +73 -0
  260. data/ext/pg_query/include/replication/reorderbuffer.h +467 -0
  261. data/ext/pg_query/include/replication/slot.h +219 -0
  262. data/ext/pg_query/include/replication/syncrep.h +115 -0
  263. data/ext/pg_query/include/replication/walreceiver.h +340 -0
  264. data/ext/pg_query/include/replication/walsender.h +74 -0
  265. data/ext/pg_query/include/rewrite/prs2lock.h +46 -0
  266. data/ext/pg_query/include/rewrite/rewriteHandler.h +40 -0
  267. data/ext/pg_query/include/rewrite/rewriteManip.h +87 -0
  268. data/ext/pg_query/include/rewrite/rewriteSupport.h +26 -0
  269. data/ext/pg_query/include/storage/backendid.h +37 -0
  270. data/ext/pg_query/include/storage/block.h +121 -0
  271. data/ext/pg_query/include/storage/buf.h +46 -0
  272. data/ext/pg_query/include/storage/bufmgr.h +292 -0
  273. data/ext/pg_query/include/storage/bufpage.h +459 -0
  274. data/ext/pg_query/include/storage/condition_variable.h +62 -0
  275. data/ext/pg_query/include/storage/dsm.h +61 -0
  276. data/ext/pg_query/include/storage/dsm_impl.h +75 -0
  277. data/ext/pg_query/include/storage/fd.h +168 -0
  278. data/ext/pg_query/include/storage/ipc.h +81 -0
  279. data/ext/pg_query/include/storage/item.h +19 -0
  280. data/ext/pg_query/include/storage/itemid.h +184 -0
  281. data/ext/pg_query/include/storage/itemptr.h +206 -0
  282. data/ext/pg_query/include/storage/large_object.h +100 -0
  283. data/ext/pg_query/include/storage/latch.h +190 -0
  284. data/ext/pg_query/include/storage/lmgr.h +114 -0
  285. data/ext/pg_query/include/storage/lock.h +612 -0
  286. data/ext/pg_query/include/storage/lockdefs.h +59 -0
  287. data/ext/pg_query/include/storage/lwlock.h +232 -0
  288. data/ext/pg_query/include/storage/lwlocknames.h +51 -0
  289. data/ext/pg_query/include/storage/off.h +57 -0
  290. data/ext/pg_query/include/storage/pg_sema.h +61 -0
  291. data/ext/pg_query/include/storage/pg_shmem.h +90 -0
  292. data/ext/pg_query/include/storage/pmsignal.h +94 -0
  293. data/ext/pg_query/include/storage/predicate.h +87 -0
  294. data/ext/pg_query/include/storage/proc.h +333 -0
  295. data/ext/pg_query/include/storage/proclist_types.h +51 -0
  296. data/ext/pg_query/include/storage/procsignal.h +75 -0
  297. data/ext/pg_query/include/storage/relfilenode.h +99 -0
  298. data/ext/pg_query/include/storage/s_lock.h +1047 -0
  299. data/ext/pg_query/include/storage/sharedfileset.h +45 -0
  300. data/ext/pg_query/include/storage/shm_mq.h +85 -0
  301. data/ext/pg_query/include/storage/shm_toc.h +58 -0
  302. data/ext/pg_query/include/storage/shmem.h +81 -0
  303. data/ext/pg_query/include/storage/sinval.h +153 -0
  304. data/ext/pg_query/include/storage/sinvaladt.h +43 -0
  305. data/ext/pg_query/include/storage/smgr.h +109 -0
  306. data/ext/pg_query/include/storage/spin.h +77 -0
  307. data/ext/pg_query/include/storage/standby.h +91 -0
  308. data/ext/pg_query/include/storage/standbydefs.h +74 -0
  309. data/ext/pg_query/include/storage/sync.h +62 -0
  310. data/ext/pg_query/include/tcop/cmdtag.h +58 -0
  311. data/ext/pg_query/include/tcop/cmdtaglist.h +217 -0
  312. data/ext/pg_query/include/tcop/deparse_utility.h +108 -0
  313. data/ext/pg_query/include/tcop/dest.h +149 -0
  314. data/ext/pg_query/include/tcop/fastpath.h +21 -0
  315. data/ext/pg_query/include/tcop/pquery.h +45 -0
  316. data/ext/pg_query/include/tcop/tcopprot.h +89 -0
  317. data/ext/pg_query/include/tcop/utility.h +108 -0
  318. data/ext/pg_query/include/tsearch/ts_cache.h +98 -0
  319. data/ext/pg_query/include/utils/acl.h +312 -0
  320. data/ext/pg_query/include/utils/aclchk_internal.h +45 -0
  321. data/ext/pg_query/include/utils/array.h +459 -0
  322. data/ext/pg_query/include/utils/builtins.h +127 -0
  323. data/ext/pg_query/include/utils/bytea.h +27 -0
  324. data/ext/pg_query/include/utils/catcache.h +231 -0
  325. data/ext/pg_query/include/utils/date.h +90 -0
  326. data/ext/pg_query/include/utils/datetime.h +343 -0
  327. data/ext/pg_query/include/utils/datum.h +68 -0
  328. data/ext/pg_query/include/utils/dsa.h +123 -0
  329. data/ext/pg_query/include/utils/dynahash.h +19 -0
  330. data/ext/pg_query/include/utils/elog.h +439 -0
  331. data/ext/pg_query/include/utils/errcodes.h +352 -0
  332. data/ext/pg_query/include/utils/expandeddatum.h +159 -0
  333. data/ext/pg_query/include/utils/expandedrecord.h +231 -0
  334. data/ext/pg_query/include/utils/float.h +356 -0
  335. data/ext/pg_query/include/utils/fmgroids.h +2657 -0
  336. data/ext/pg_query/include/utils/fmgrprotos.h +2646 -0
  337. data/ext/pg_query/include/utils/fmgrtab.h +48 -0
  338. data/ext/pg_query/include/utils/guc.h +443 -0
  339. data/ext/pg_query/include/utils/guc_tables.h +272 -0
  340. data/ext/pg_query/include/utils/hsearch.h +149 -0
  341. data/ext/pg_query/include/utils/inval.h +64 -0
  342. data/ext/pg_query/include/utils/lsyscache.h +198 -0
  343. data/ext/pg_query/include/utils/memdebug.h +82 -0
  344. data/ext/pg_query/include/utils/memutils.h +225 -0
  345. data/ext/pg_query/include/utils/numeric.h +76 -0
  346. data/ext/pg_query/include/utils/palloc.h +136 -0
  347. data/ext/pg_query/include/utils/partcache.h +102 -0
  348. data/ext/pg_query/include/utils/pg_locale.h +119 -0
  349. data/ext/pg_query/include/utils/pg_lsn.h +29 -0
  350. data/ext/pg_query/include/utils/pidfile.h +56 -0
  351. data/ext/pg_query/include/utils/plancache.h +235 -0
  352. data/ext/pg_query/include/utils/portal.h +241 -0
  353. data/ext/pg_query/include/utils/probes.h +114 -0
  354. data/ext/pg_query/include/utils/ps_status.h +25 -0
  355. data/ext/pg_query/include/utils/queryenvironment.h +74 -0
  356. data/ext/pg_query/include/utils/regproc.h +28 -0
  357. data/ext/pg_query/include/utils/rel.h +644 -0
  358. data/ext/pg_query/include/utils/relcache.h +151 -0
  359. data/ext/pg_query/include/utils/reltrigger.h +81 -0
  360. data/ext/pg_query/include/utils/resowner.h +86 -0
  361. data/ext/pg_query/include/utils/rls.h +50 -0
  362. data/ext/pg_query/include/utils/ruleutils.h +44 -0
  363. data/ext/pg_query/include/utils/sharedtuplestore.h +61 -0
  364. data/ext/pg_query/include/utils/snapmgr.h +158 -0
  365. data/ext/pg_query/include/utils/snapshot.h +206 -0
  366. data/ext/pg_query/include/utils/sortsupport.h +276 -0
  367. data/ext/pg_query/include/utils/syscache.h +219 -0
  368. data/ext/pg_query/include/utils/timeout.h +88 -0
  369. data/ext/pg_query/include/utils/timestamp.h +116 -0
  370. data/ext/pg_query/include/utils/tuplesort.h +277 -0
  371. data/ext/pg_query/include/utils/tuplestore.h +91 -0
  372. data/ext/pg_query/include/utils/typcache.h +202 -0
  373. data/ext/pg_query/include/utils/tzparser.h +39 -0
  374. data/ext/pg_query/include/utils/varlena.h +39 -0
  375. data/ext/pg_query/include/utils/xml.h +84 -0
  376. data/ext/pg_query/include/xxhash.h +5445 -0
  377. data/ext/pg_query/include/xxhash/xxhash.h +5445 -0
  378. data/ext/pg_query/pg_query.c +104 -0
  379. data/ext/pg_query/pg_query.pb-c.c +37643 -0
  380. data/ext/pg_query/pg_query_deparse.c +9965 -0
  381. data/ext/pg_query/pg_query_fingerprint.c +367 -0
  382. data/ext/pg_query/pg_query_fingerprint.h +8 -0
  383. data/ext/pg_query/pg_query_internal.h +24 -0
  384. data/ext/pg_query/pg_query_json_plpgsql.c +738 -0
  385. data/ext/pg_query/pg_query_json_plpgsql.h +9 -0
  386. data/ext/pg_query/pg_query_normalize.c +491 -0
  387. data/ext/pg_query/pg_query_outfuncs.h +10 -0
  388. data/ext/pg_query/pg_query_outfuncs_json.c +297 -0
  389. data/ext/pg_query/pg_query_outfuncs_protobuf.c +237 -0
  390. data/ext/pg_query/pg_query_parse.c +148 -0
  391. data/ext/pg_query/pg_query_parse_plpgsql.c +460 -0
  392. data/ext/pg_query/pg_query_readfuncs.h +11 -0
  393. data/ext/pg_query/pg_query_readfuncs_protobuf.c +142 -0
  394. data/ext/pg_query/pg_query_ruby.c +108 -12
  395. data/ext/pg_query/pg_query_scan.c +173 -0
  396. data/ext/pg_query/pg_query_split.c +221 -0
  397. data/ext/pg_query/protobuf-c.c +3667 -0
  398. data/ext/pg_query/src_backend_catalog_namespace.c +1051 -0
  399. data/ext/pg_query/src_backend_catalog_pg_proc.c +142 -0
  400. data/ext/pg_query/src_backend_commands_define.c +117 -0
  401. data/ext/pg_query/src_backend_libpq_pqcomm.c +651 -0
  402. data/ext/pg_query/src_backend_nodes_bitmapset.c +513 -0
  403. data/ext/pg_query/src_backend_nodes_copyfuncs.c +6013 -0
  404. data/ext/pg_query/src_backend_nodes_equalfuncs.c +4003 -0
  405. data/ext/pg_query/src_backend_nodes_extensible.c +99 -0
  406. data/ext/pg_query/src_backend_nodes_list.c +922 -0
  407. data/ext/pg_query/src_backend_nodes_makefuncs.c +417 -0
  408. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +1363 -0
  409. data/ext/pg_query/src_backend_nodes_value.c +84 -0
  410. data/ext/pg_query/src_backend_parser_gram.c +47456 -0
  411. data/ext/pg_query/src_backend_parser_parse_expr.c +313 -0
  412. data/ext/pg_query/src_backend_parser_parser.c +497 -0
  413. data/ext/pg_query/src_backend_parser_scan.c +7091 -0
  414. data/ext/pg_query/src_backend_parser_scansup.c +160 -0
  415. data/ext/pg_query/src_backend_postmaster_postmaster.c +2230 -0
  416. data/ext/pg_query/src_backend_storage_ipc_ipc.c +192 -0
  417. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +370 -0
  418. data/ext/pg_query/src_backend_tcop_postgres.c +776 -0
  419. data/ext/pg_query/src_backend_utils_adt_datum.c +326 -0
  420. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +98 -0
  421. data/ext/pg_query/src_backend_utils_adt_format_type.c +136 -0
  422. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +1683 -0
  423. data/ext/pg_query/src_backend_utils_error_assert.c +74 -0
  424. data/ext/pg_query/src_backend_utils_error_elog.c +1748 -0
  425. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +570 -0
  426. data/ext/pg_query/src_backend_utils_hash_dynahash.c +1086 -0
  427. data/ext/pg_query/src_backend_utils_init_globals.c +168 -0
  428. data/ext/pg_query/src_backend_utils_mb_mbutils.c +839 -0
  429. data/ext/pg_query/src_backend_utils_misc_guc.c +1831 -0
  430. data/ext/pg_query/src_backend_utils_mmgr_aset.c +1560 -0
  431. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +1042 -0
  432. data/ext/pg_query/src_common_encnames.c +158 -0
  433. data/ext/pg_query/src_common_hashfn.c +420 -0
  434. data/ext/pg_query/src_common_keywords.c +39 -0
  435. data/ext/pg_query/src_common_kwlist_d.h +1081 -0
  436. data/ext/pg_query/src_common_kwlookup.c +91 -0
  437. data/ext/pg_query/src_common_psprintf.c +158 -0
  438. data/ext/pg_query/src_common_string.c +86 -0
  439. data/ext/pg_query/src_common_stringinfo.c +336 -0
  440. data/ext/pg_query/src_common_wchar.c +1651 -0
  441. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1133 -0
  442. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +877 -0
  443. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +6533 -0
  444. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +107 -0
  445. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +123 -0
  446. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +671 -0
  447. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +255 -0
  448. data/ext/pg_query/src_port_erand48.c +127 -0
  449. data/ext/pg_query/src_port_pg_bitutils.c +246 -0
  450. data/ext/pg_query/src_port_pgsleep.c +69 -0
  451. data/ext/pg_query/src_port_pgstrcasecmp.c +83 -0
  452. data/ext/pg_query/src_port_qsort.c +240 -0
  453. data/ext/pg_query/src_port_random.c +31 -0
  454. data/ext/pg_query/src_port_snprintf.c +1449 -0
  455. data/ext/pg_query/src_port_strerror.c +324 -0
  456. data/ext/pg_query/src_port_strnlen.c +39 -0
  457. data/ext/pg_query/xxhash.c +43 -0
  458. data/lib/pg_query.rb +6 -4
  459. data/lib/pg_query/constants.rb +21 -0
  460. data/lib/pg_query/deparse.rb +15 -1673
  461. data/lib/pg_query/filter_columns.rb +88 -85
  462. data/lib/pg_query/fingerprint.rb +120 -87
  463. data/lib/pg_query/node.rb +31 -0
  464. data/lib/pg_query/param_refs.rb +42 -37
  465. data/lib/pg_query/parse.rb +274 -202
  466. data/lib/pg_query/parse_error.rb +1 -1
  467. data/lib/pg_query/pg_query_pb.rb +3213 -0
  468. data/lib/pg_query/scan.rb +23 -0
  469. data/lib/pg_query/treewalker.rb +24 -40
  470. data/lib/pg_query/truncate.rb +71 -42
  471. data/lib/pg_query/version.rb +2 -2
  472. metadata +472 -11
  473. data/ext/pg_query/pg_query_ruby.h +0 -10
  474. data/lib/pg_query/deep_dup.rb +0 -16
  475. data/lib/pg_query/deparse/alter_table.rb +0 -42
  476. data/lib/pg_query/deparse/interval.rb +0 -105
  477. data/lib/pg_query/deparse/keywords.rb +0 -159
  478. data/lib/pg_query/deparse/rename.rb +0 -41
  479. data/lib/pg_query/legacy_parsetree.rb +0 -109
  480. data/lib/pg_query/node_types.rb +0 -297
@@ -0,0 +1,1110 @@
1
+ /*
2
+ * Copyright (c) 2008-2018, Dave Benson and the protobuf-c authors.
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are
7
+ * met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ *
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ /*! \file
31
+ * \mainpage Introduction
32
+ *
33
+ * This is [protobuf-c], a C implementation of [Protocol Buffers].
34
+ *
35
+ * This file defines the public API for the `libprotobuf-c` support library.
36
+ * This API includes interfaces that can be used directly by client code as well
37
+ * as the interfaces used by the code generated by the `protoc-c` compiler.
38
+ *
39
+ * The `libprotobuf-c` support library performs the actual serialization and
40
+ * deserialization of Protocol Buffers messages. It interacts with structures,
41
+ * definitions, and metadata generated by the `protoc-c` compiler from .proto
42
+ * files.
43
+ *
44
+ * \authors Dave Benson and the `protobuf-c` authors.
45
+ *
46
+ * \copyright 2008-2014. Licensed under the terms of the [BSD-2-Clause] license.
47
+ *
48
+ * [protobuf-c]: https://github.com/protobuf-c/protobuf-c
49
+ * [Protocol Buffers]: https://developers.google.com/protocol-buffers/
50
+ * [BSD-2-Clause]: http://opensource.org/licenses/BSD-2-Clause
51
+ *
52
+ * \page gencode Generated Code
53
+ *
54
+ * For each enum, we generate a C enum. For each message, we generate a C
55
+ * structure which can be cast to a `ProtobufCMessage`.
56
+ *
57
+ * For each enum and message, we generate a descriptor object that allows us to
58
+ * implement a kind of reflection on the structures.
59
+ *
60
+ * First, some naming conventions:
61
+ *
62
+ * - The name of the type for enums and messages and services is camel case
63
+ * (meaning WordsAreCrammedTogether) except that double underscores are used
64
+ * to delimit scopes. For example, the following `.proto` file:
65
+ *
66
+ ~~~{.proto}
67
+ package foo.bar;
68
+ message BazBah {
69
+ optional int32 val = 1;
70
+ }
71
+ ~~~
72
+ *
73
+ * would generate a C type `Foo__Bar__BazBah`.
74
+ *
75
+ * - Identifiers for functions and globals are all lowercase, with camel case
76
+ * words separated by single underscores. For example, one of the function
77
+ * prototypes generated by `protoc-c` for the above example:
78
+ *
79
+ ~~~{.c}
80
+ Foo__Bar__BazBah *
81
+ foo__bar__baz_bah__unpack
82
+ (ProtobufCAllocator *allocator,
83
+ size_t len,
84
+ const uint8_t *data);
85
+ ~~~
86
+ *
87
+ * - Identifiers for enum values contain an uppercase prefix which embeds the
88
+ * package name and the enum type name.
89
+ *
90
+ * - A double underscore is used to separate further components of identifier
91
+ * names.
92
+ *
93
+ * For example, in the name of the unpack function above, the package name
94
+ * `foo.bar` has become `foo__bar`, the message name BazBah has become
95
+ * `baz_bah`, and the method name is `unpack`. These are all joined with double
96
+ * underscores to form the C identifier `foo__bar__baz_bah__unpack`.
97
+ *
98
+ * We also generate descriptor objects for messages and enums. These are
99
+ * declared in the `.pb-c.h` files:
100
+ *
101
+ ~~~{.c}
102
+ extern const ProtobufCMessageDescriptor foo__bar__baz_bah__descriptor;
103
+ ~~~
104
+ *
105
+ * The message structures all begin with `ProtobufCMessageDescriptor *` which is
106
+ * sufficient to allow them to be cast to `ProtobufCMessage`.
107
+ *
108
+ * For each message defined in a `.proto` file, we generate a number of
109
+ * functions and macros. Each function name contains a prefix based on the
110
+ * package name and message name in order to make it a unique C identifier.
111
+ *
112
+ * - `INIT`. Statically initializes a message object, initializing its
113
+ * descriptor and setting its fields to default values. Uninitialized
114
+ * messages cannot be processed by the protobuf-c library.
115
+ *
116
+ ~~~{.c}
117
+ #define FOO__BAR__BAZ_BAH__INIT \
118
+ { PROTOBUF_C_MESSAGE_INIT (&foo__bar__baz_bah__descriptor), 0 }
119
+ ~~~
120
+ * - `init()`. Initializes a message object, initializing its descriptor and
121
+ * setting its fields to default values. Uninitialized messages cannot be
122
+ * processed by the protobuf-c library.
123
+ *
124
+ ~~~{.c}
125
+ void foo__bar__baz_bah__init
126
+ (Foo__Bar__BazBah *message);
127
+ ~~~
128
+ * - `unpack()`. Unpacks data for a particular message format. Note that the
129
+ * `allocator` parameter is usually `NULL` to indicate that the system's
130
+ * `malloc()` and `free()` functions should be used for dynamically allocating
131
+ * memory.
132
+ *
133
+ ~~~{.c}
134
+ Foo__Bar__BazBah *
135
+ foo__bar__baz_bah__unpack
136
+ (ProtobufCAllocator *allocator,
137
+ size_t len,
138
+ const uint8_t *data);
139
+ ~~~
140
+ *
141
+ * - `free_unpacked()`. Frees a message object obtained with the `unpack()`
142
+ * method. Freeing `NULL` is allowed (the same as with `free()`).
143
+ *
144
+ ~~~{.c}
145
+ void foo__bar__baz_bah__free_unpacked
146
+ (Foo__Bar__BazBah *message,
147
+ ProtobufCAllocator *allocator);
148
+ ~~~
149
+ *
150
+ * - `get_packed_size()`. Calculates the length in bytes of the serialized
151
+ * representation of the message object.
152
+ *
153
+ ~~~{.c}
154
+ size_t foo__bar__baz_bah__get_packed_size
155
+ (const Foo__Bar__BazBah *message);
156
+ ~~~
157
+ *
158
+ * - `pack()`. Pack a message object into a preallocated buffer. Assumes that
159
+ * the buffer is large enough. (Use `get_packed_size()` first.)
160
+ *
161
+ ~~~{.c}
162
+ size_t foo__bar__baz_bah__pack
163
+ (const Foo__Bar__BazBah *message,
164
+ uint8_t *out);
165
+ ~~~
166
+ *
167
+ * - `pack_to_buffer()`. Packs a message into a "virtual buffer". This is an
168
+ * object which defines an "append bytes" callback to consume data as it is
169
+ * serialized.
170
+ *
171
+ ~~~{.c}
172
+ size_t foo__bar__baz_bah__pack_to_buffer
173
+ (const Foo__Bar__BazBah *message,
174
+ ProtobufCBuffer *buffer);
175
+ ~~~
176
+ *
177
+ * \page pack Packing and unpacking messages
178
+ *
179
+ * To pack a message, first compute the packed size of the message with
180
+ * protobuf_c_message_get_packed_size(), then allocate a buffer of at least
181
+ * that size, then call protobuf_c_message_pack().
182
+ *
183
+ * Alternatively, a message can be serialized without calculating the final size
184
+ * first. Use the protobuf_c_message_pack_to_buffer() function and provide a
185
+ * ProtobufCBuffer object which implements an "append" method that consumes
186
+ * data.
187
+ *
188
+ * To unpack a message, call the protobuf_c_message_unpack() function. The
189
+ * result can be cast to an object of the type that matches the descriptor for
190
+ * the message.
191
+ *
192
+ * The result of unpacking a message should be freed with
193
+ * protobuf_c_message_free_unpacked().
194
+ */
195
+
196
+ #ifndef PROTOBUF_C_H
197
+ #define PROTOBUF_C_H
198
+
199
+ #include <assert.h>
200
+ #include <limits.h>
201
+ #include <stddef.h>
202
+ #include <stdint.h>
203
+
204
+ #ifdef __cplusplus
205
+ # define PROTOBUF_C__BEGIN_DECLS extern "C" {
206
+ # define PROTOBUF_C__END_DECLS }
207
+ #else
208
+ # define PROTOBUF_C__BEGIN_DECLS
209
+ # define PROTOBUF_C__END_DECLS
210
+ #endif
211
+
212
+ PROTOBUF_C__BEGIN_DECLS
213
+
214
+ #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
215
+ # ifdef PROTOBUF_C_EXPORT
216
+ # define PROTOBUF_C__API __declspec(dllexport)
217
+ # else
218
+ # define PROTOBUF_C__API __declspec(dllimport)
219
+ # endif
220
+ #else
221
+ # define PROTOBUF_C__API
222
+ #endif
223
+
224
+ #if !defined(PROTOBUF_C__NO_DEPRECATED) && \
225
+ ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
226
+ # define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__))
227
+ #else
228
+ # define PROTOBUF_C__DEPRECATED
229
+ #endif
230
+
231
+ #ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
232
+ #define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \
233
+ , _##enum_name##_IS_INT_SIZE = INT_MAX
234
+ #endif
235
+
236
+ #define PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC 0x14159bc3
237
+ #define PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9
238
+ #define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af
239
+
240
+ /* Empty string used for initializers */
241
+ #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
242
+ static const char protobuf_c_empty_string[] = "";
243
+ #else
244
+ extern const char protobuf_c_empty_string[];
245
+ #endif
246
+
247
+ /**
248
+ * \defgroup api Public API
249
+ *
250
+ * This is the public API for `libprotobuf-c`. These interfaces are stable and
251
+ * subject to Semantic Versioning guarantees.
252
+ *
253
+ * @{
254
+ */
255
+
256
+ /**
257
+ * Values for the `flags` word in `ProtobufCFieldDescriptor`.
258
+ */
259
+ typedef enum {
260
+ /** Set if the field is repeated and marked with the `packed` option. */
261
+ PROTOBUF_C_FIELD_FLAG_PACKED = (1 << 0),
262
+
263
+ /** Set if the field is marked with the `deprecated` option. */
264
+ PROTOBUF_C_FIELD_FLAG_DEPRECATED = (1 << 1),
265
+
266
+ /** Set if the field is a member of a oneof (union). */
267
+ PROTOBUF_C_FIELD_FLAG_ONEOF = (1 << 2),
268
+ } ProtobufCFieldFlag;
269
+
270
+ /**
271
+ * Message field rules.
272
+ *
273
+ * \see [Defining A Message Type] in the Protocol Buffers documentation.
274
+ *
275
+ * [Defining A Message Type]:
276
+ * https://developers.google.com/protocol-buffers/docs/proto#simple
277
+ */
278
+ typedef enum {
279
+ /** A well-formed message must have exactly one of this field. */
280
+ PROTOBUF_C_LABEL_REQUIRED,
281
+
282
+ /**
283
+ * A well-formed message can have zero or one of this field (but not
284
+ * more than one).
285
+ */
286
+ PROTOBUF_C_LABEL_OPTIONAL,
287
+
288
+ /**
289
+ * This field can be repeated any number of times (including zero) in a
290
+ * well-formed message. The order of the repeated values will be
291
+ * preserved.
292
+ */
293
+ PROTOBUF_C_LABEL_REPEATED,
294
+
295
+ /**
296
+ * This field has no label. This is valid only in proto3 and is
297
+ * equivalent to OPTIONAL but no "has" quantifier will be consulted.
298
+ */
299
+ PROTOBUF_C_LABEL_NONE,
300
+ } ProtobufCLabel;
301
+
302
+ /**
303
+ * Field value types.
304
+ *
305
+ * \see [Scalar Value Types] in the Protocol Buffers documentation.
306
+ *
307
+ * [Scalar Value Types]:
308
+ * https://developers.google.com/protocol-buffers/docs/proto#scalar
309
+ */
310
+ typedef enum {
311
+ PROTOBUF_C_TYPE_INT32, /**< int32 */
312
+ PROTOBUF_C_TYPE_SINT32, /**< signed int32 */
313
+ PROTOBUF_C_TYPE_SFIXED32, /**< signed int32 (4 bytes) */
314
+ PROTOBUF_C_TYPE_INT64, /**< int64 */
315
+ PROTOBUF_C_TYPE_SINT64, /**< signed int64 */
316
+ PROTOBUF_C_TYPE_SFIXED64, /**< signed int64 (8 bytes) */
317
+ PROTOBUF_C_TYPE_UINT32, /**< unsigned int32 */
318
+ PROTOBUF_C_TYPE_FIXED32, /**< unsigned int32 (4 bytes) */
319
+ PROTOBUF_C_TYPE_UINT64, /**< unsigned int64 */
320
+ PROTOBUF_C_TYPE_FIXED64, /**< unsigned int64 (8 bytes) */
321
+ PROTOBUF_C_TYPE_FLOAT, /**< float */
322
+ PROTOBUF_C_TYPE_DOUBLE, /**< double */
323
+ PROTOBUF_C_TYPE_BOOL, /**< boolean */
324
+ PROTOBUF_C_TYPE_ENUM, /**< enumerated type */
325
+ PROTOBUF_C_TYPE_STRING, /**< UTF-8 or ASCII string */
326
+ PROTOBUF_C_TYPE_BYTES, /**< arbitrary byte sequence */
327
+ PROTOBUF_C_TYPE_MESSAGE, /**< nested message */
328
+ } ProtobufCType;
329
+
330
+ /**
331
+ * Field wire types.
332
+ *
333
+ * \see [Message Structure] in the Protocol Buffers documentation.
334
+ *
335
+ * [Message Structure]:
336
+ * https://developers.google.com/protocol-buffers/docs/encoding#structure
337
+ */
338
+ typedef enum {
339
+ PROTOBUF_C_WIRE_TYPE_VARINT = 0,
340
+ PROTOBUF_C_WIRE_TYPE_64BIT = 1,
341
+ PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED = 2,
342
+ /* "Start group" and "end group" wire types are unsupported. */
343
+ PROTOBUF_C_WIRE_TYPE_32BIT = 5,
344
+ } ProtobufCWireType;
345
+
346
+ struct ProtobufCAllocator;
347
+ struct ProtobufCBinaryData;
348
+ struct ProtobufCBuffer;
349
+ struct ProtobufCBufferSimple;
350
+ struct ProtobufCEnumDescriptor;
351
+ struct ProtobufCEnumValue;
352
+ struct ProtobufCEnumValueIndex;
353
+ struct ProtobufCFieldDescriptor;
354
+ struct ProtobufCIntRange;
355
+ struct ProtobufCMessage;
356
+ struct ProtobufCMessageDescriptor;
357
+ struct ProtobufCMessageUnknownField;
358
+ struct ProtobufCMethodDescriptor;
359
+ struct ProtobufCService;
360
+ struct ProtobufCServiceDescriptor;
361
+
362
+ typedef struct ProtobufCAllocator ProtobufCAllocator;
363
+ typedef struct ProtobufCBinaryData ProtobufCBinaryData;
364
+ typedef struct ProtobufCBuffer ProtobufCBuffer;
365
+ typedef struct ProtobufCBufferSimple ProtobufCBufferSimple;
366
+ typedef struct ProtobufCEnumDescriptor ProtobufCEnumDescriptor;
367
+ typedef struct ProtobufCEnumValue ProtobufCEnumValue;
368
+ typedef struct ProtobufCEnumValueIndex ProtobufCEnumValueIndex;
369
+ typedef struct ProtobufCFieldDescriptor ProtobufCFieldDescriptor;
370
+ typedef struct ProtobufCIntRange ProtobufCIntRange;
371
+ typedef struct ProtobufCMessage ProtobufCMessage;
372
+ typedef struct ProtobufCMessageDescriptor ProtobufCMessageDescriptor;
373
+ typedef struct ProtobufCMessageUnknownField ProtobufCMessageUnknownField;
374
+ typedef struct ProtobufCMethodDescriptor ProtobufCMethodDescriptor;
375
+ typedef struct ProtobufCService ProtobufCService;
376
+ typedef struct ProtobufCServiceDescriptor ProtobufCServiceDescriptor;
377
+
378
+ /** Boolean type. */
379
+ typedef int protobuf_c_boolean;
380
+
381
+ typedef void (*ProtobufCClosure)(const ProtobufCMessage *, void *closure_data);
382
+ typedef void (*ProtobufCMessageInit)(ProtobufCMessage *);
383
+ typedef void (*ProtobufCServiceDestroy)(ProtobufCService *);
384
+
385
+ /**
386
+ * Structure for defining a custom memory allocator.
387
+ */
388
+ struct ProtobufCAllocator {
389
+ /** Function to allocate memory. */
390
+ void *(*alloc)(void *allocator_data, size_t size);
391
+
392
+ /** Function to free memory. */
393
+ void (*free)(void *allocator_data, void *pointer);
394
+
395
+ /** Opaque pointer passed to `alloc` and `free` functions. */
396
+ void *allocator_data;
397
+ };
398
+
399
+ /**
400
+ * Structure for the protobuf `bytes` scalar type.
401
+ *
402
+ * The data contained in a `ProtobufCBinaryData` is an arbitrary sequence of
403
+ * bytes. It may contain embedded `NUL` characters and is not required to be
404
+ * `NUL`-terminated.
405
+ */
406
+ struct ProtobufCBinaryData {
407
+ size_t len; /**< Number of bytes in the `data` field. */
408
+ uint8_t *data; /**< Data bytes. */
409
+ };
410
+
411
+ /**
412
+ * Structure for defining a virtual append-only buffer. Used by
413
+ * protobuf_c_message_pack_to_buffer() to abstract the consumption of serialized
414
+ * bytes.
415
+ *
416
+ * `ProtobufCBuffer` "subclasses" may be defined on the stack. For example, to
417
+ * write to a `FILE` object:
418
+ *
419
+ ~~~{.c}
420
+ typedef struct {
421
+ ProtobufCBuffer base;
422
+ FILE *fp;
423
+ } BufferAppendToFile;
424
+
425
+ static void
426
+ my_buffer_file_append(ProtobufCBuffer *buffer,
427
+ size_t len,
428
+ const uint8_t *data)
429
+ {
430
+ BufferAppendToFile *file_buf = (BufferAppendToFile *) buffer;
431
+ fwrite(data, len, 1, file_buf->fp); // XXX: No error handling!
432
+ }
433
+ ~~~
434
+ *
435
+ * To use this new type of ProtobufCBuffer, it could be called as follows:
436
+ *
437
+ ~~~{.c}
438
+ ...
439
+ BufferAppendToFile tmp = {0};
440
+ tmp.base.append = my_buffer_file_append;
441
+ tmp.fp = fp;
442
+ protobuf_c_message_pack_to_buffer(&message, &tmp);
443
+ ...
444
+ ~~~
445
+ */
446
+ struct ProtobufCBuffer {
447
+ /** Append function. Consumes the `len` bytes stored at `data`. */
448
+ void (*append)(ProtobufCBuffer *buffer,
449
+ size_t len,
450
+ const uint8_t *data);
451
+ };
452
+
453
+ /**
454
+ * Simple buffer "subclass" of `ProtobufCBuffer`.
455
+ *
456
+ * A `ProtobufCBufferSimple` object is declared on the stack and uses a
457
+ * scratch buffer provided by the user for the initial allocation. It performs
458
+ * exponential resizing, using dynamically allocated memory. A
459
+ * `ProtobufCBufferSimple` object can be created and used as follows:
460
+ *
461
+ ~~~{.c}
462
+ uint8_t pad[128];
463
+ ProtobufCBufferSimple simple = PROTOBUF_C_BUFFER_SIMPLE_INIT(pad);
464
+ ProtobufCBuffer *buffer = (ProtobufCBuffer *) &simple;
465
+ ~~~
466
+ *
467
+ * `buffer` can now be used with `protobuf_c_message_pack_to_buffer()`. Once a
468
+ * message has been serialized to a `ProtobufCBufferSimple` object, the
469
+ * serialized data bytes can be accessed from the `.data` field.
470
+ *
471
+ * To free the memory allocated by a `ProtobufCBufferSimple` object, if any,
472
+ * call PROTOBUF_C_BUFFER_SIMPLE_CLEAR() on the object, for example:
473
+ *
474
+ ~~~{.c}
475
+ PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple);
476
+ ~~~
477
+ *
478
+ * \see PROTOBUF_C_BUFFER_SIMPLE_INIT
479
+ * \see PROTOBUF_C_BUFFER_SIMPLE_CLEAR
480
+ */
481
+ struct ProtobufCBufferSimple {
482
+ /** "Base class". */
483
+ ProtobufCBuffer base;
484
+ /** Number of bytes allocated in `data`. */
485
+ size_t alloced;
486
+ /** Number of bytes currently stored in `data`. */
487
+ size_t len;
488
+ /** Data bytes. */
489
+ uint8_t *data;
490
+ /** Whether `data` must be freed. */
491
+ protobuf_c_boolean must_free_data;
492
+ /** Allocator to use. May be NULL to indicate the system allocator. */
493
+ ProtobufCAllocator *allocator;
494
+ };
495
+
496
+ /**
497
+ * Describes an enumeration as a whole, with all of its values.
498
+ */
499
+ struct ProtobufCEnumDescriptor {
500
+ /** Magic value checked to ensure that the API is used correctly. */
501
+ uint32_t magic;
502
+
503
+ /** The qualified name (e.g., "namespace.Type"). */
504
+ const char *name;
505
+ /** The unqualified name as given in the .proto file (e.g., "Type"). */
506
+ const char *short_name;
507
+ /** Identifier used in generated C code. */
508
+ const char *c_name;
509
+ /** The dot-separated namespace. */
510
+ const char *package_name;
511
+
512
+ /** Number elements in `values`. */
513
+ unsigned n_values;
514
+ /** Array of distinct values, sorted by numeric value. */
515
+ const ProtobufCEnumValue *values;
516
+
517
+ /** Number of elements in `values_by_name`. */
518
+ unsigned n_value_names;
519
+ /** Array of named values, including aliases, sorted by name. */
520
+ const ProtobufCEnumValueIndex *values_by_name;
521
+
522
+ /** Number of elements in `value_ranges`. */
523
+ unsigned n_value_ranges;
524
+ /** Value ranges, for faster lookups by numeric value. */
525
+ const ProtobufCIntRange *value_ranges;
526
+
527
+ /** Reserved for future use. */
528
+ void *reserved1;
529
+ /** Reserved for future use. */
530
+ void *reserved2;
531
+ /** Reserved for future use. */
532
+ void *reserved3;
533
+ /** Reserved for future use. */
534
+ void *reserved4;
535
+ };
536
+
537
+ /**
538
+ * Represents a single value of an enumeration.
539
+ */
540
+ struct ProtobufCEnumValue {
541
+ /** The string identifying this value in the .proto file. */
542
+ const char *name;
543
+
544
+ /** The string identifying this value in generated C code. */
545
+ const char *c_name;
546
+
547
+ /** The numeric value assigned in the .proto file. */
548
+ int value;
549
+ };
550
+
551
+ /**
552
+ * Used by `ProtobufCEnumDescriptor` to look up enum values.
553
+ */
554
+ struct ProtobufCEnumValueIndex {
555
+ /** Name of the enum value. */
556
+ const char *name;
557
+ /** Index into values[] array. */
558
+ unsigned index;
559
+ };
560
+
561
+ /**
562
+ * Describes a single field in a message.
563
+ */
564
+ struct ProtobufCFieldDescriptor {
565
+ /** Name of the field as given in the .proto file. */
566
+ const char *name;
567
+
568
+ /** Tag value of the field as given in the .proto file. */
569
+ uint32_t id;
570
+
571
+ /** Whether the field is `REQUIRED`, `OPTIONAL`, or `REPEATED`. */
572
+ ProtobufCLabel label;
573
+
574
+ /** The type of the field. */
575
+ ProtobufCType type;
576
+
577
+ /**
578
+ * The offset in bytes of the message's C structure's quantifier field
579
+ * (the `has_MEMBER` field for optional members or the `n_MEMBER` field
580
+ * for repeated members or the case enum for oneofs).
581
+ */
582
+ unsigned quantifier_offset;
583
+
584
+ /**
585
+ * The offset in bytes into the message's C structure for the member
586
+ * itself.
587
+ */
588
+ unsigned offset;
589
+
590
+ /**
591
+ * A type-specific descriptor.
592
+ *
593
+ * If `type` is `PROTOBUF_C_TYPE_ENUM`, then `descriptor` points to the
594
+ * corresponding `ProtobufCEnumDescriptor`.
595
+ *
596
+ * If `type` is `PROTOBUF_C_TYPE_MESSAGE`, then `descriptor` points to
597
+ * the corresponding `ProtobufCMessageDescriptor`.
598
+ *
599
+ * Otherwise this field is NULL.
600
+ */
601
+ const void *descriptor; /* for MESSAGE and ENUM types */
602
+
603
+ /** The default value for this field, if defined. May be NULL. */
604
+ const void *default_value;
605
+
606
+ /**
607
+ * A flag word. Zero or more of the bits defined in the
608
+ * `ProtobufCFieldFlag` enum may be set.
609
+ */
610
+ uint32_t flags;
611
+
612
+ /** Reserved for future use. */
613
+ unsigned reserved_flags;
614
+ /** Reserved for future use. */
615
+ void *reserved2;
616
+ /** Reserved for future use. */
617
+ void *reserved3;
618
+ };
619
+
620
+ /**
621
+ * Helper structure for optimizing int => index lookups in the case
622
+ * where the keys are mostly consecutive values, as they presumably are for
623
+ * enums and fields.
624
+ *
625
+ * The data structures requires that the values in the original array are
626
+ * sorted.
627
+ */
628
+ struct ProtobufCIntRange {
629
+ int start_value;
630
+ unsigned orig_index;
631
+ /*
632
+ * NOTE: the number of values in the range can be inferred by looking
633
+ * at the next element's orig_index. A dummy element is added to make
634
+ * this simple.
635
+ */
636
+ };
637
+
638
+ /**
639
+ * An instance of a message.
640
+ *
641
+ * `ProtobufCMessage` is a light-weight "base class" for all messages.
642
+ *
643
+ * In particular, `ProtobufCMessage` doesn't have any allocation policy
644
+ * associated with it. That's because it's common to create `ProtobufCMessage`
645
+ * objects on the stack. In fact, that's what we recommend for sending messages.
646
+ * If the object is allocated from the stack, you can't really have a memory
647
+ * leak.
648
+ *
649
+ * This means that calls to functions like protobuf_c_message_unpack() which
650
+ * return a `ProtobufCMessage` must be paired with a call to a free function,
651
+ * like protobuf_c_message_free_unpacked().
652
+ */
653
+ struct ProtobufCMessage {
654
+ /** The descriptor for this message type. */
655
+ const ProtobufCMessageDescriptor *descriptor;
656
+ /** The number of elements in `unknown_fields`. */
657
+ unsigned n_unknown_fields;
658
+ /** The fields that weren't recognized by the parser. */
659
+ ProtobufCMessageUnknownField *unknown_fields;
660
+ };
661
+
662
+ /**
663
+ * Describes a message.
664
+ */
665
+ struct ProtobufCMessageDescriptor {
666
+ /** Magic value checked to ensure that the API is used correctly. */
667
+ uint32_t magic;
668
+
669
+ /** The qualified name (e.g., "namespace.Type"). */
670
+ const char *name;
671
+ /** The unqualified name as given in the .proto file (e.g., "Type"). */
672
+ const char *short_name;
673
+ /** Identifier used in generated C code. */
674
+ const char *c_name;
675
+ /** The dot-separated namespace. */
676
+ const char *package_name;
677
+
678
+ /**
679
+ * Size in bytes of the C structure representing an instance of this
680
+ * type of message.
681
+ */
682
+ size_t sizeof_message;
683
+
684
+ /** Number of elements in `fields`. */
685
+ unsigned n_fields;
686
+ /** Field descriptors, sorted by tag number. */
687
+ const ProtobufCFieldDescriptor *fields;
688
+ /** Used for looking up fields by name. */
689
+ const unsigned *fields_sorted_by_name;
690
+
691
+ /** Number of elements in `field_ranges`. */
692
+ unsigned n_field_ranges;
693
+ /** Used for looking up fields by id. */
694
+ const ProtobufCIntRange *field_ranges;
695
+
696
+ /** Message initialisation function. */
697
+ ProtobufCMessageInit message_init;
698
+
699
+ /** Reserved for future use. */
700
+ void *reserved1;
701
+ /** Reserved for future use. */
702
+ void *reserved2;
703
+ /** Reserved for future use. */
704
+ void *reserved3;
705
+ };
706
+
707
+ /**
708
+ * An unknown message field.
709
+ */
710
+ struct ProtobufCMessageUnknownField {
711
+ /** The tag number. */
712
+ uint32_t tag;
713
+ /** The wire type of the field. */
714
+ ProtobufCWireType wire_type;
715
+ /** Number of bytes in `data`. */
716
+ size_t len;
717
+ /** Field data. */
718
+ uint8_t *data;
719
+ };
720
+
721
+ /**
722
+ * Method descriptor.
723
+ */
724
+ struct ProtobufCMethodDescriptor {
725
+ /** Method name. */
726
+ const char *name;
727
+ /** Input message descriptor. */
728
+ const ProtobufCMessageDescriptor *input;
729
+ /** Output message descriptor. */
730
+ const ProtobufCMessageDescriptor *output;
731
+ };
732
+
733
+ /**
734
+ * Service.
735
+ */
736
+ struct ProtobufCService {
737
+ /** Service descriptor. */
738
+ const ProtobufCServiceDescriptor *descriptor;
739
+ /** Function to invoke the service. */
740
+ void (*invoke)(ProtobufCService *service,
741
+ unsigned method_index,
742
+ const ProtobufCMessage *input,
743
+ ProtobufCClosure closure,
744
+ void *closure_data);
745
+ /** Function to destroy the service. */
746
+ void (*destroy)(ProtobufCService *service);
747
+ };
748
+
749
+ /**
750
+ * Service descriptor.
751
+ */
752
+ struct ProtobufCServiceDescriptor {
753
+ /** Magic value checked to ensure that the API is used correctly. */
754
+ uint32_t magic;
755
+
756
+ /** Service name. */
757
+ const char *name;
758
+ /** Short version of service name. */
759
+ const char *short_name;
760
+ /** C identifier for the service name. */
761
+ const char *c_name;
762
+ /** Package name. */
763
+ const char *package;
764
+ /** Number of elements in `methods`. */
765
+ unsigned n_methods;
766
+ /** Method descriptors, in the order defined in the .proto file. */
767
+ const ProtobufCMethodDescriptor *methods;
768
+ /** Sort index of methods. */
769
+ const unsigned *method_indices_by_name;
770
+ };
771
+
772
+ /**
773
+ * Get the version of the protobuf-c library. Note that this is the version of
774
+ * the library linked against, not the version of the headers compiled against.
775
+ *
776
+ * \return A string containing the version number of protobuf-c.
777
+ */
778
+ PROTOBUF_C__API
779
+ const char *
780
+ protobuf_c_version(void);
781
+
782
+ /**
783
+ * Get the version of the protobuf-c library. Note that this is the version of
784
+ * the library linked against, not the version of the headers compiled against.
785
+ *
786
+ * \return A 32 bit unsigned integer containing the version number of
787
+ * protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH.
788
+ */
789
+ PROTOBUF_C__API
790
+ uint32_t
791
+ protobuf_c_version_number(void);
792
+
793
+ /**
794
+ * The version of the protobuf-c headers, represented as a string using the same
795
+ * format as protobuf_c_version().
796
+ */
797
+ #define PROTOBUF_C_VERSION "1.4.0"
798
+
799
+ /**
800
+ * The version of the protobuf-c headers, represented as an integer using the
801
+ * same format as protobuf_c_version_number().
802
+ */
803
+ #define PROTOBUF_C_VERSION_NUMBER 1004000
804
+
805
+ /**
806
+ * The minimum protoc-c version which works with the current version of the
807
+ * protobuf-c headers.
808
+ */
809
+ #define PROTOBUF_C_MIN_COMPILER_VERSION 1000000
810
+
811
+ /**
812
+ * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by name.
813
+ *
814
+ * \param desc
815
+ * The `ProtobufCEnumDescriptor` object.
816
+ * \param name
817
+ * The `name` field from the corresponding `ProtobufCEnumValue` object to
818
+ * match.
819
+ * \return
820
+ * A `ProtobufCEnumValue` object.
821
+ * \retval NULL
822
+ * If not found or if the optimize_for = CODE_SIZE option was set.
823
+ */
824
+ PROTOBUF_C__API
825
+ const ProtobufCEnumValue *
826
+ protobuf_c_enum_descriptor_get_value_by_name(
827
+ const ProtobufCEnumDescriptor *desc,
828
+ const char *name);
829
+
830
+ /**
831
+ * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric
832
+ * value.
833
+ *
834
+ * \param desc
835
+ * The `ProtobufCEnumDescriptor` object.
836
+ * \param value
837
+ * The `value` field from the corresponding `ProtobufCEnumValue` object to
838
+ * match.
839
+ *
840
+ * \return
841
+ * A `ProtobufCEnumValue` object.
842
+ * \retval NULL
843
+ * If not found.
844
+ */
845
+ PROTOBUF_C__API
846
+ const ProtobufCEnumValue *
847
+ protobuf_c_enum_descriptor_get_value(
848
+ const ProtobufCEnumDescriptor *desc,
849
+ int value);
850
+
851
+ /**
852
+ * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
853
+ * the name of the field.
854
+ *
855
+ * \param desc
856
+ * The `ProtobufCMessageDescriptor` object.
857
+ * \param name
858
+ * The name of the field.
859
+ * \return
860
+ * A `ProtobufCFieldDescriptor` object.
861
+ * \retval NULL
862
+ * If not found or if the optimize_for = CODE_SIZE option was set.
863
+ */
864
+ PROTOBUF_C__API
865
+ const ProtobufCFieldDescriptor *
866
+ protobuf_c_message_descriptor_get_field_by_name(
867
+ const ProtobufCMessageDescriptor *desc,
868
+ const char *name);
869
+
870
+ /**
871
+ * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
872
+ * the tag value of the field.
873
+ *
874
+ * \param desc
875
+ * The `ProtobufCMessageDescriptor` object.
876
+ * \param value
877
+ * The tag value of the field.
878
+ * \return
879
+ * A `ProtobufCFieldDescriptor` object.
880
+ * \retval NULL
881
+ * If not found.
882
+ */
883
+ PROTOBUF_C__API
884
+ const ProtobufCFieldDescriptor *
885
+ protobuf_c_message_descriptor_get_field(
886
+ const ProtobufCMessageDescriptor *desc,
887
+ unsigned value);
888
+
889
+ /**
890
+ * Determine the number of bytes required to store the serialised message.
891
+ *
892
+ * \param message
893
+ * The message object to serialise.
894
+ * \return
895
+ * Number of bytes.
896
+ */
897
+ PROTOBUF_C__API
898
+ size_t
899
+ protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
900
+
901
+ /**
902
+ * Serialise a message from its in-memory representation.
903
+ *
904
+ * This function stores the serialised bytes of the message in a pre-allocated
905
+ * buffer.
906
+ *
907
+ * \param message
908
+ * The message object to serialise.
909
+ * \param[out] out
910
+ * Buffer to store the bytes of the serialised message. This buffer must
911
+ * have enough space to store the packed message. Use
912
+ * protobuf_c_message_get_packed_size() to determine the number of bytes
913
+ * required.
914
+ * \return
915
+ * Number of bytes stored in `out`.
916
+ */
917
+ PROTOBUF_C__API
918
+ size_t
919
+ protobuf_c_message_pack(const ProtobufCMessage *message, uint8_t *out);
920
+
921
+ /**
922
+ * Serialise a message from its in-memory representation to a virtual buffer.
923
+ *
924
+ * This function calls the `append` method of a `ProtobufCBuffer` object to
925
+ * consume the bytes generated by the serialiser.
926
+ *
927
+ * \param message
928
+ * The message object to serialise.
929
+ * \param buffer
930
+ * The virtual buffer object.
931
+ * \return
932
+ * Number of bytes passed to the virtual buffer.
933
+ */
934
+ PROTOBUF_C__API
935
+ size_t
936
+ protobuf_c_message_pack_to_buffer(
937
+ const ProtobufCMessage *message,
938
+ ProtobufCBuffer *buffer);
939
+
940
+ /**
941
+ * Unpack a serialised message into an in-memory representation.
942
+ *
943
+ * \param descriptor
944
+ * The message descriptor.
945
+ * \param allocator
946
+ * `ProtobufCAllocator` to use for memory allocation. May be NULL to
947
+ * specify the default allocator.
948
+ * \param len
949
+ * Length in bytes of the serialised message.
950
+ * \param data
951
+ * Pointer to the serialised message.
952
+ * \return
953
+ * An unpacked message object.
954
+ * \retval NULL
955
+ * If an error occurred during unpacking.
956
+ */
957
+ PROTOBUF_C__API
958
+ ProtobufCMessage *
959
+ protobuf_c_message_unpack(
960
+ const ProtobufCMessageDescriptor *descriptor,
961
+ ProtobufCAllocator *allocator,
962
+ size_t len,
963
+ const uint8_t *data);
964
+
965
+ /**
966
+ * Free an unpacked message object.
967
+ *
968
+ * This function should be used to deallocate the memory used by a call to
969
+ * protobuf_c_message_unpack().
970
+ *
971
+ * \param message
972
+ * The message object to free. May be NULL.
973
+ * \param allocator
974
+ * `ProtobufCAllocator` to use for memory deallocation. May be NULL to
975
+ * specify the default allocator.
976
+ */
977
+ PROTOBUF_C__API
978
+ void
979
+ protobuf_c_message_free_unpacked(
980
+ ProtobufCMessage *message,
981
+ ProtobufCAllocator *allocator);
982
+
983
+ /**
984
+ * Check the validity of a message object.
985
+ *
986
+ * Makes sure all required fields (`PROTOBUF_C_LABEL_REQUIRED`) are present.
987
+ * Recursively checks nested messages.
988
+ *
989
+ * \retval TRUE
990
+ * Message is valid.
991
+ * \retval FALSE
992
+ * Message is invalid.
993
+ */
994
+ PROTOBUF_C__API
995
+ protobuf_c_boolean
996
+ protobuf_c_message_check(const ProtobufCMessage *);
997
+
998
+ /** Message initialiser. */
999
+ #define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL }
1000
+
1001
+ /**
1002
+ * Initialise a message object from a message descriptor.
1003
+ *
1004
+ * \param descriptor
1005
+ * Message descriptor.
1006
+ * \param message
1007
+ * Allocated block of memory of size `descriptor->sizeof_message`.
1008
+ */
1009
+ PROTOBUF_C__API
1010
+ void
1011
+ protobuf_c_message_init(
1012
+ const ProtobufCMessageDescriptor *descriptor,
1013
+ void *message);
1014
+
1015
+ /**
1016
+ * Free a service.
1017
+ *
1018
+ * \param service
1019
+ * The service object to free.
1020
+ */
1021
+ PROTOBUF_C__API
1022
+ void
1023
+ protobuf_c_service_destroy(ProtobufCService *service);
1024
+
1025
+ /**
1026
+ * Look up a `ProtobufCMethodDescriptor` by name.
1027
+ *
1028
+ * \param desc
1029
+ * Service descriptor.
1030
+ * \param name
1031
+ * Name of the method.
1032
+ *
1033
+ * \return
1034
+ * A `ProtobufCMethodDescriptor` object.
1035
+ * \retval NULL
1036
+ * If not found or if the optimize_for = CODE_SIZE option was set.
1037
+ */
1038
+ PROTOBUF_C__API
1039
+ const ProtobufCMethodDescriptor *
1040
+ protobuf_c_service_descriptor_get_method_by_name(
1041
+ const ProtobufCServiceDescriptor *desc,
1042
+ const char *name);
1043
+
1044
+ /**
1045
+ * Initialise a `ProtobufCBufferSimple` object.
1046
+ */
1047
+ #define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \
1048
+ { \
1049
+ { protobuf_c_buffer_simple_append }, \
1050
+ sizeof(array_of_bytes), \
1051
+ 0, \
1052
+ (array_of_bytes), \
1053
+ 0, \
1054
+ NULL \
1055
+ }
1056
+
1057
+ /**
1058
+ * Clear a `ProtobufCBufferSimple` object, freeing any allocated memory.
1059
+ */
1060
+ #define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \
1061
+ do { \
1062
+ if ((simp_buf)->must_free_data) { \
1063
+ if ((simp_buf)->allocator != NULL) \
1064
+ (simp_buf)->allocator->free( \
1065
+ (simp_buf)->allocator, \
1066
+ (simp_buf)->data); \
1067
+ else \
1068
+ free((simp_buf)->data); \
1069
+ } \
1070
+ } while (0)
1071
+
1072
+ /**
1073
+ * The `append` method for `ProtobufCBufferSimple`.
1074
+ *
1075
+ * \param buffer
1076
+ * The buffer object to append to. Must actually be a
1077
+ * `ProtobufCBufferSimple` object.
1078
+ * \param len
1079
+ * Number of bytes in `data`.
1080
+ * \param data
1081
+ * Data to append.
1082
+ */
1083
+ PROTOBUF_C__API
1084
+ void
1085
+ protobuf_c_buffer_simple_append(
1086
+ ProtobufCBuffer *buffer,
1087
+ size_t len,
1088
+ const unsigned char *data);
1089
+
1090
+ PROTOBUF_C__API
1091
+ void
1092
+ protobuf_c_service_generated_init(
1093
+ ProtobufCService *service,
1094
+ const ProtobufCServiceDescriptor *descriptor,
1095
+ ProtobufCServiceDestroy destroy);
1096
+
1097
+ PROTOBUF_C__API
1098
+ void
1099
+ protobuf_c_service_invoke_internal(
1100
+ ProtobufCService *service,
1101
+ unsigned method_index,
1102
+ const ProtobufCMessage *input,
1103
+ ProtobufCClosure closure,
1104
+ void *closure_data);
1105
+
1106
+ /**@}*/
1107
+
1108
+ PROTOBUF_C__END_DECLS
1109
+
1110
+ #endif /* PROTOBUF_C_H */