From 89e15a397a2d3b1080756ce77587bc3ccf5318f1 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:25:38 -0500 Subject: [PATCH 01/11] docs: add OTEL_REWRITE_DESIGN.md for the C exporter rewrite Captures the design driving the C++->C exporter rewrite: the memory-aware OTLP/HTTP + nanoarrow architecture, the preallocated zero-allocation memory model, the OTLP/Arrow wire contracts, the failure semantics (peek/commit two-phase dequeue, backoff, poison-batch valve), the memory_limit GUC consolidation, and the SIGABRT backstop. Motivated by a production SIGABRT where a gRPC allocation aborted under strict overcommit and forced database-wide crash recovery. --- OTEL_REWRITE_DESIGN.md | 216 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 OTEL_REWRITE_DESIGN.md diff --git a/OTEL_REWRITE_DESIGN.md b/OTEL_REWRITE_DESIGN.md new file mode 100644 index 0000000..2c34c0d --- /dev/null +++ b/OTEL_REWRITE_DESIGN.md @@ -0,0 +1,216 @@ +# Design: memory-aware OTel exporter, C conversion, and GUC consolidation + +**Branch:** `otel-rewrite` · **Date:** 2026-06-10 · **Status:** approved direction, pre-implementation +**Trigger:** production SIGABRT 2026-06-10 (gRPC `gpr_malloc` → `abort()` on NULL malloc under +`vm.overcommit_memory=2`; shmem-attached bgworker death → 49 s database-wide crash recovery). +Problem statement: `pg_stat_ch-sigabrt-problem-statement.md` (Downloads). + +## 1. Goals and non-goals + +**Goal:** no code path inside the postgres process may call `abort()` under memory pressure; +telemetry failure costs at most a bgworker restart (`proc_exit(1)`, `bgw_restart_time=10s`), +never database-wide crash recovery. Steady-state export performs **zero heap allocation**. + +**Non-goals:** changing the wire contract (collector pipeline and `datagres_otel.query_logs_arrow` +ingestion must keep working unchanged); out-of-process export; keeping gRPC. + +**Decisions (user-approved):** +1. In-process rewrite, no gRPC — single-threaded, hand-rolled OTLP client on the bgworker main thread +2. OTLP/HTTP (`POST /v1/logs`, `application/x-protobuf`), identical payload +3. Preallocated fixed memory budget; hot path cannot allocate +4. nanoarrow (vendored amalgamation) + custom IPC emit layer (see §4) +5. Entire project converts C++ → C (only 4 `.cc` files exist, all in `src/export/`) +6. Memory GUCs consolidate around `pg_stat_ch.memory_limit` (see §6) + +## 2. What discovery established (oracles for the rewrite) + +- **Wire payload (Arrow path):** Arrow IPC *streaming* format, V5, little-endian: schema message, + 13 dictionary batches (ids 0–12 in field order, `isDelta=false`, fresh per flush), 1 record + batch, 8-byte EOS. 56 fields, exact names/types/order in `/tmp/wf1-code-arrow-batch.md` + (traps: `shared_blks_written` BEFORE `dirtied`; `jit_deform_time_us` last among jit; `pid`/`query_id` + are decimal strings; `severity`/`body`/`trace_id`/`span_id` constant `""`; `null_count=0` everywhere). + Every body buffer ZSTD-framed: `BodyCompression{ZSTD, BUFFER}`, int64-LE uncompressed-length + prefix + ZSTD frame (Arrow C++ never emits the `-1` raw escape). `ts = (ts_start + 946684800000000) * 1000` ns. +- **OTLP envelope:** resource attrs `service.name=pg_stat_ch`, `service.version`, `host.name` + (GUC > `$HOSTNAME` > `gethostname()`), `pg_stat_ch.block_format=arrow_ipc`; scope + `pg_stat_ch`/version; one LogRecord, body = `bytes_value(IPC)`, attrs `pg_stat_ch.block_format` + + `pg_stat_ch.block_rows`. Per-record path: attributes-only records, no body, zero-valued int attrs + skipped, duration dual-encoded (`db.client.operation.duration` seconds double + `duration_us` int). +- **OTLP/HTTP:** pin opentelemetry-proto **v1.9.0** field surface (never emit `strindex`, + `EntityRef`, LogRecord field 4, ResourceLogs field 1000). Identity encoding legal. Retry only + 429/502/503/504 + connection-drop, honor `Retry-After` delta-seconds. 200-with-`partial_success` + = do not retry, log rejects. otelcol HTTP body cap 20 MiB default — applies to **decompressed** body. +- **nanoarrow 0.8.0:** IPC writer exists but supports neither write-side compression nor dictionary + batches → custom IPC emit layer (§4). Built with `NDEBUG` + `FLATCC_NO_ASSERT`: zero `abort()` + paths, all OOM → `ENOMEM`. Vendor via `bundle.py --with-ipc --with-flatcc --symbol-namespace=PgStatCh`. +- **Today's biggest memory bug:** `DequeueEvents` reserves `batch_max × sizeof(PschEvent)` = + 200000 × 4600 B ≈ **877 MiB transient heap per export cycle** (`stats_exporter.cc:99-106`) — + a larger overcommit hazard than the gRPC allocation that aborted. The rewrite deletes it. +- **Failure-semantics holes:** destructive dequeue before export (post-dequeue failure silently + drops up to batch_max events, uncounted); backoff counter only increments on wire-send failure + (bad_alloc/connect/build failures retry at 500 ms → the 2/sec log flood). +- **Verified sizes:** `sizeof(PschRingEntry)` = 520 B (not 512!), `sizeof(PschEvent)` ≈ 4600 B, + intern HTAB sized at `queue_capacity` entries ≈ 592 B/slot amortized (ring+intern). + +## 3. Architecture (all C) + +``` +hooks (C, unchanged) → shmem ring (C, + peek/commit) → bgworker (C) + ├─ stats_exporter.c driver: chunked peek → dispatch → commit/requeue + ├─ exporter.h PschExporterOps fn-pointer table + PschExportStatus + ├─ clickhouse_exporter.c (port; clickhouse-c, already C underneath) + ├─ otel_exporter.c NEW: OTLP/HTTP client (sockets + optional OpenSSL) + ├─ otlp_encode.c NEW: protobuf wire encoder (v1.9.0 surface) + ├─ arrow_batch.c NEW: nanoarrow arrays + custom IPC emitter + └─ third_party/nanoarrow/ vendored amalgamation (+ flatcc) +``` + +**Interface** (`src/export/exporter.h`, replaces `exporter_interface.h`): `PschExporterOps` +function-pointer table — `connect`, `is_connected`, `export_events(self, const PschEvent*, int n, int* exported)`, +`send_arrow(self, const uint8*, size_t, int rows)` (NULL = unsupported), `consecutive_failures`, +`reset_failures`, `destroy`. Backends consume `PschEvent` directly — the Column/factory +abstraction and all per-row `std::string` temporaries are deleted, not ported. Status enum: +`OK / EMPTY / ERR_NOMEM / ERR_CONN / ERR_SEND / ERR_INTERNAL`. + +**Threading:** strictly single-threaded; reuse proven CH-path patterns (`ConnectWithTimeout` +EINTR loop, `SO_RCVTIMEO/SNDTIMEO` + monotonic deadlines, `ProcDiePending` cancel callback). +No library may spawn threads in the bgworker. + +## 4. Arrow batch builder (`arrow_batch.c`) + +nanoarrow for schema/array building and buffer management; custom IPC message emitter because +nanoarrow's encoder can't write dictionary batches or compressed buffers: + +- All `ArrowBuffer`s caller-owned, allocators installed via `ArrowBufferSetAllocator`, pre-reserved + at worker start to high-water sizes; flatcc builder pages warm-up-allocated then reused + (`flatcc_builder_reset` keeps capacity). Steady state: zero alloc. +- IPC emitter uses the flatbuffer builders already in the bundled `flatcc_generated.h` + (`BodyCompression_create`, `RecordBatch_compression_add`, DictionaryBatch) to emit: + schema msg → 13 dictionary batches → record batch → EOS, each message framed + `0xFFFFFFFF | int32 LE len | flatbuffer (8-aligned) | body`. +- ZSTD per-buffer: preallocated `ZSTD_CCtx` (static alloc via `ZSTD_initStaticCCtx`, with + `ZSTD_estimateCCtxSize` verify-at-start + windowLog degrade-and-LOG), output via + `ZSTD_compressBound`-sized region, compress directly into the network/encode buffer. + Match Arrow C++ behavior: compress every buffer unconditionally, level 1, never emit `-1` escape. +- Dictionary columns: fixed-capacity open-addressing memo table sized for full-chunk cardinality + (worst case = rows per chunk), preallocated. +- Value transforms preserved exactly (clamps 63/63/45/2048/2048, `strnlen(sqlstate,5)`, + negative→0 with 1/sec rate-limited WARNING, `PschCmdTypeToString`, extra_attributes parsing, + first-wins dup keys). +- Oracle: capture fixture payloads from the **old** implementation via `debug_arrow_dump_dir` + before deletion; `t/026_arrow_dump.pl` (pyarrow) must pass unchanged; add a decoded-equality + comparison old-vs-new on identical synthetic events. + +## 5. OTLP/HTTP exporter (`otel_exporter.c` + `otlp_encode.c`) + +- Single-pass protobuf encoding into a preallocated buffer (length-delimited submessages via + reserved fixed-width varint slots or leaf-first assembly — decided at implementation, both + zero-alloc). Never emit post-v1.9.0 fields. +- HTTP/1.1 keep-alive POST `/v1/logs`, `Content-Type: application/x-protobuf`, no + `Content-Encoding`. Parse status line + headers from a fixed response buffer; decode + `partial_success` (log, don't retry) and `google.rpc.Status` (diagnostics). +- Retry/backoff: 429/502/503/504 and connection-drop → failure + requeue (§5a) + consecutive-failure + backoff (existing 1 s × 2^n cap 60 s curve), honoring `Retry-After` (delta-seconds only). + All other 4xx/5xx → permanent failure for that batch (consume + count as export-drop). +- `otel_endpooint` → URL semantics: scheme decides TLS (`http://localhost:4318` default); new GUC + for static headers (auth parity with `OTEL_EXPORTER_OTLP_HEADERS`); CA-file GUC for TLS. + OpenSSL only on the TLS path (allocation failures return NULL — checked). +- Request deadline: `export_timeout` (renamed from `otel_log_delay_ms`), default **1000 ms** + (100 ms was gRPC-tuned; cannot absorb TLS reconnect), SIGHUP. +- Quiesce-on-OOM: `ERR_NOMEM` enters backoff like any failure; no allocation is attempted during + backoff (buffers are static — the abort window is structurally gone). + +### 5a. Failure semantics (changed deliberately, fixes both holes) + +- `shmem.c` gains two-phase consume: `PschPeekEvents(buf, max)` / `PschConsumeEvents(n)` — + safe, bgworker is the ring's sole consumer. +- Connection check still precedes peek. `ERR_CONN`/`ERR_SEND` → do NOT consume (events survive + collector outages — upgrade over today's silent drop); `ERR_NOMEM`/`ERR_INTERNAL`, or send + failure with `consecutive_failures ≥ 10` → consume anyway (poison-batch valve) + count in a + new `export_dropped` stat (distinct from enqueue-overflow `dropped`). +- **Every** failure mode increments the backoff counter (kills the 2/sec flood). +- `PschExportBatch` returns 0 on any failure (drain-loop contract, `bgworker.c:133`); drain loop + gets an explicit per-cycle iteration bound to preserve flush cadence and barrier processing. +- Staging: fixed chunk array (4096 events ≈ 18 MiB) preallocated at init — replaces the 877 MiB reserve. +- SIGABRT handler installed in `PschBgworkerMain` before `BackgroundWorkerUnblockSignals`: + async-signal-safe `write(2, msg)` + `_exit(1)` only. Covers residual aborts (libc heap + corruption paths keep SIGSEGV/SIGBUS full-crash semantics — only SIGABRT is trapped). + Ring-sanity check on worker start compensates for skipped shmem-corruption reinit. +- `ereport(FATAL)` allowed only at init (exporter creation/preallocation failure → clean worker restart). +- Mid-batch longjmp recovery: backends reset batch state on entry; an `in_flight` flag forces + reconnect instead of resuming a poisoned CH connection. + +## 6. GUC consolidation (panel synthesis, critique-adjusted) + +Surface: **8 memory knobs → 1 operator knob + 3 expert overrides.** + +| GUC | Type/context | Default | Semantics | +|---|---|---|---| +| `memory_limit` | int MB, POSTMASTER | **160** | Total budget: ring + intern HTAB + DSA strings + worker export arena. 160 MB is the *verified* equivalence point of today's defaults (131072×520 B ring + intern + 64 MB DSA + ~19 MiB arena). `-1` = opt-in auto `clamp(shared_buffers/16, 48MB, 256MB)` — documented as changing sizes, never the boot default. | +| `queue_capacity` | int, POSTMASTER | -1 = auto | Auto: largest pow2 with full per-slot cost (520 B ring + ~72 B intern) ≤ ~50% of budget. Explicit values: check hook **rounds** to pow2 (no more startup error). | +| `string_area_size` | int MB, POSTMASTER | -1 = auto | Auto: DSA absorbs the budget remainder after ring+intern+arena (rounding loss becomes string capacity). | +| `export_buffer_size` | int MB, POSTMASTER | -1 = auto | Worker arena: staging chunk + arrow scratch + encode buffer + ZSTD cctx + network buffer. Encode ceiling 16 MiB **uncompressed** (otelcol 20 MiB decompressed cap). Replaces `otel_max_block_bytes`, `otel_log_max_bytes`, `otel_log_batch_size`, `batch_max`. | + +Policy details (each traces to a critique finding): +- **Overrides auto-raise the budget with WARNING — never FATAL, never sibling-starvation.** + Old fleet templates (`queue_capacity=131072` + `string_area_size=64`) must boot byte-identically. +- **Write-back** resolved values via `SetConfigOption(PGC_S_DYNAMIC_DEFAULT)` so `SHOW` reports + effective sizes (wal_buffers idiom) — keeps auto-raise honest. +- **Intern HTAB is charged** per-slot inside the budget (it's sized by queue_capacity). +- Migration: dead shims (`otel_log_queue_size`, `otel_metric_interval_ms`) deleted now; live-folded + GUCs get a one-release Citus-style bridge (hidden, honored iff successor = -1, deprecation + WARNING on explicit set). Release notes must flag: prefix is reserved, so post-deletion + `SET`/`ALTER SYSTEM` of old names **errors** — fleet template + `postgresql.auto.conf` scrub required. +- `otel_log_delay_ms` → `export_timeout` (SIGHUP, 1000 ms), bridged. +- `normalize_cache_max` unchanged this release (per-backend ≠ shared budget; documented exclusion + with ×max_connections worst case; named AllocSet for `pg_backend_memory_contexts` visibility). + Bytes-denominated rename is follow-up work. +- Observability ships in the same release: `pg_stat_ch_memory()` view (per-component + budget/used/high-water/source: auto|override|derived), reason-split drop counters + (`dropped_queue_full` / `dropped_string_oom` / `export_dropped`), startup LOG printing the full + resolved derivation, overflow errhint rewritten to name `memory_limit` (restart) and + `sample_rate`/`min_duration_us` (no restart). View = SQL surface → `.control` bump 0.3 → 0.4 + migration script. + +## 7. Build / tooling + +- Staged: ports land file-by-file under the existing dual glob; flip `project(LANGUAGES C)` + + inverted stray-C++ FATAL check + delete `cxx_std_17`, `-include libintl.h`, `-Wglobal-constructors` + block in one final commit. `C_STANDARD 17` + `C_EXTENSIONS ON` codified in CMake (replaces env CFLAGS). +- **Keep vcpkg for now** (3 deps: openssl, lz4, zstd) — release tarballs stay static/pinned; + dropping vcpkg for system libs is a flagged follow-up decision (OpenSSL 1.1-era distro risk). + Delete `opentelemetry-cpp` + `arrow` manifest entries (gRPC/protobuf/abseil go transitively). +- nanoarrow vendored as checked-in amalgamation under `third_party/nanoarrow/` (not a submodule) + + `VERSION` pin; SYSTEM include; compiled as dedicated TUs (clickhouse-c pattern). +- `.clang-format`: keep Google-ish (`Language: Cpp` formats C); `.clang-tidy`: drop + `modernize-*`/`google-*`, add `bugprone-*`; mise/CI format globs gain `-e c` — **one-time reformat + of existing .c files as an isolated commit** (they were never format-enforced). +- CI: drop g++/CXX launcher/triplet CXX bits; keep clang as second compiler; verify with `nm` + that no `__cxa_*`/`_ZSt` symbols remain in `pg_stat_ch.so`. +- Docs/skills: CLAUDE.md language/deps rewrite, README compiler line, retire cpp-* skills. + +## 8. Sequencing + +1. **Prep:** vendor nanoarrow; formatting-glob fix + bulk reformat (isolated commit); capture + Arrow fixture payloads from old implementation. +2. **New C modules:** `otlp_encode.c` → `arrow_batch.c` (+IPC emitter) → `otel_exporter.c`. +3. **Ports:** `exporter.h`, `clickhouse_exporter.c`, `stats_exporter.c`, shmem peek/commit, + SIGABRT handler. Old `.cc` files deleted in the same series (terminate handler lives until the + last `.cc` dies; mangled bridge symbols force the interface flip to be atomic with the ports). +4. **Build flip:** LANGUAGES C, dep pruning, CI updates. +5. **GUC consolidation** + `pg_stat_ch_memory` view (+ control bump 0.3→0.4, migration script, + `guc.out` update). +6. **Verification:** PG 16/17/18 builds (gcc+clang), regress/isolation/TAP (incl. tap-enabled + local PG), byte-compat fixtures, OOM-injection (NULL-malloc shim), failure/backoff TAP test, + valgrind batch loop, adversarial multi-agent review with an explicit abort-surface audit + (`nm` + grep for abort/assert in linked objects). + +## 9. Risk register (top) + +| Risk | Mitigation | +|---|---| +| IPC byte-compat drift (dicts, ZSTD framing, padding) | old-impl fixtures + pyarrow decoded-equality + t/026 unchanged | +| Requeue introduces poison-batch wedge | consume-after-N-failures valve + `export_dropped` counter + TAP test | +| Per-request 100 ms deadline regression under TLS | `export_timeout` default 1000 ms | +| Old fleet templates vs new budget | auto-raise + WARNING + write-back; never FATAL | +| flatcc/nanoarrow hidden allocs on hot path | warm-up at init + `FLATCC_ALLOC` override option; verify with alloc-counting shim in tests | +| Drain-loop livelock without batch_max | explicit per-cycle iteration/time bound | From cd9373f55c71c8da808580a6e62215aa5eaf400f Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:25:41 -0500 Subject: [PATCH 02/11] build: vendor nanoarrow 0.8.0 amalgamation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checked-in amalgamation (not a submodule) generated with bundle.py --with-ipc --with-flatcc --symbol-namespace PgStatCh, pinned in third_party/nanoarrow/VERSION. Provides Arrow array building plus the flatcc runtime for hand-built IPC messages. Built with NDEBUG + FLATCC_NO_ASSERT so every failure path returns an error code instead of abort()/assert() — the property the exporter rewrite depends on. --- third_party/nanoarrow/VERSION | 5 + .../include/flatcc/flatcc_accessors.h | 106 + .../nanoarrow/include/flatcc/flatcc_alloc.h | 128 + .../nanoarrow/include/flatcc/flatcc_assert.h | 45 + .../nanoarrow/include/flatcc/flatcc_builder.h | 1911 + .../nanoarrow/include/flatcc/flatcc_emitter.h | 215 + .../nanoarrow/include/flatcc/flatcc_endian.h | 125 + .../include/flatcc/flatcc_epilogue.h | 7 + .../include/flatcc/flatcc_flatbuffers.h | 57 + .../include/flatcc/flatcc_identifier.h | 148 + .../nanoarrow/include/flatcc/flatcc_iov.h | 31 + .../include/flatcc/flatcc_portable.h | 14 + .../include/flatcc/flatcc_prologue.h | 8 + .../nanoarrow/include/flatcc/flatcc_refmap.h | 144 + .../include/flatcc/flatcc_rtconfig.h | 171 + .../nanoarrow/include/flatcc/flatcc_types.h | 97 + .../include/flatcc/flatcc_verifier.h | 267 + .../include/flatcc/portable/paligned_alloc.h | 213 + .../include/flatcc/portable/pattributes.h | 84 + .../include/flatcc/portable/pdiagnostic.h | 84 + .../include/flatcc/portable/pdiagnostic_pop.h | 20 + .../flatcc/portable/pdiagnostic_push.h | 51 + .../include/flatcc/portable/pendian.h | 206 + .../include/flatcc/portable/pendian_detect.h | 118 + .../include/flatcc/portable/pinline.h | 19 + .../include/flatcc/portable/pinttypes.h | 52 + .../include/flatcc/portable/pmemaccess.h | 232 + .../include/flatcc/portable/portable.h | 2 + .../include/flatcc/portable/portable_basic.h | 27 + .../include/flatcc/portable/prestrict.h | 39 + .../include/flatcc/portable/pstatic_assert.h | 67 + .../include/flatcc/portable/pstdalign.h | 170 + .../include/flatcc/portable/pstdint.h | 898 + .../include/flatcc/portable/punaligned.h | 190 + .../include/flatcc/portable/pversion.h | 6 + .../include/flatcc/portable/pwarnings.h | 52 + .../nanoarrow/include/nanoarrow/nanoarrow.h | 4482 +++ .../include/nanoarrow/nanoarrow_ipc.h | 779 + third_party/nanoarrow/src/flatcc.c | 3247 ++ third_party/nanoarrow/src/nanoarrow.c | 4117 +++ third_party/nanoarrow/src/nanoarrow_ipc.c | 29562 ++++++++++++++++ 41 files changed, 48196 insertions(+) create mode 100644 third_party/nanoarrow/VERSION create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_accessors.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_alloc.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_assert.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_builder.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_emitter.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_endian.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_epilogue.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_flatbuffers.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_identifier.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_iov.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_portable.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_prologue.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_refmap.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_rtconfig.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_types.h create mode 100644 third_party/nanoarrow/include/flatcc/flatcc_verifier.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/paligned_alloc.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pattributes.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pdiagnostic.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pdiagnostic_pop.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pdiagnostic_push.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pendian.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pendian_detect.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pinline.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pinttypes.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pmemaccess.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/portable.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/portable_basic.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/prestrict.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pstatic_assert.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pstdalign.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pstdint.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/punaligned.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pversion.h create mode 100644 third_party/nanoarrow/include/flatcc/portable/pwarnings.h create mode 100644 third_party/nanoarrow/include/nanoarrow/nanoarrow.h create mode 100644 third_party/nanoarrow/include/nanoarrow/nanoarrow_ipc.h create mode 100644 third_party/nanoarrow/src/flatcc.c create mode 100644 third_party/nanoarrow/src/nanoarrow.c create mode 100644 third_party/nanoarrow/src/nanoarrow_ipc.c diff --git a/third_party/nanoarrow/VERSION b/third_party/nanoarrow/VERSION new file mode 100644 index 0000000..f914642 --- /dev/null +++ b/third_party/nanoarrow/VERSION @@ -0,0 +1,5 @@ +apache/arrow-nanoarrow 0.8.0 (tag apache-arrow-nanoarrow-0.8.0, commit a579fbf5d192e85b6249935e117de7d02a6dc4e9) +Generated with: python3 ci/scripts/bundle.py --output-dir --with-ipc --with-flatcc --symbol-namespace PgStatCh +License: Apache-2.0 (see upstream LICENSE.txt) +Local modifications: none yet (write-side ZSTD buffer compression and dictionary-batch +emission live in src/export/arrow_ipc_emit.c, NOT as patches to these files) diff --git a/third_party/nanoarrow/include/flatcc/flatcc_accessors.h b/third_party/nanoarrow/include/flatcc/flatcc_accessors.h new file mode 100644 index 0000000..51f6e34 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_accessors.h @@ -0,0 +1,106 @@ +#ifndef FLATCC_ACCESSORS +#define FLATCC_ACCESSORS + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef UINT8_MAX +#include +#endif + + +#define __flatcc_basic_scalar_accessors_impl(N, T, W, E) \ +static inline size_t N ## __size(void) \ +{ return sizeof(T); } \ +static inline T *N ## __ptr_add(T *p, size_t i) \ +{ return p + i; } \ +static inline const T *N ## __const_ptr_add(const T *p, size_t i) \ +{ return p + i; } \ +static inline T N ## _read_from_pe(const void *p) \ +{ return N ## _cast_from_pe(N ## _read(p)); } \ +static inline T N ## _read_to_pe(const void *p) \ +{ return N ## _cast_to_pe(N ## _read(p)); } \ +static inline void N ## _write_from_pe(void *p, T v) \ +{ N ## _write(p, N ## _cast_from_pe(v)); } \ +static inline void N ## _write_to_pe(void *p, T v) \ +{ N ## _write(p, N ## _cast_to_pe(v)); } \ +static inline T N ## _read_from_le(const void *p) \ +{ return N ## _cast_from_le(N ## _read(p)); } \ +typedef struct { int is_null; T value; } N ## _option_t; + +#define __flatcc_define_integer_accessors_impl(N, T, W, E) \ +static inline T N ## _read(const void *p) \ +{ return (T) mem_read_ ## W(p); } \ +static inline void N ## _write(void *p, T v) \ +{ mem_write_ ## W(p, v); } \ +static inline T N ## _cast_from_pe(T v) \ +{ return (T) E ## W ## toh((uint ## W ## _t)v); } \ +static inline T N ## _cast_to_pe(T v) \ +{ return (T) hto ## E ## W((uint ## W ## _t)v); } \ +static inline T N ## _cast_from_le(T v) \ +{ return (T) le ## W ## toh((uint ## W ## _t)v); } \ +static inline T N ## _cast_to_le(T v) \ +{ return (T) htole ## W((uint ## W ## _t)v); } \ +static inline T N ## _cast_from_be(T v) \ +{ return (T) be ## W ## toh((uint ## W ## _t)v); } \ +static inline T N ## _cast_to_be(T v) \ +{ return (T) htobe ## W((uint ## W ## _t)v); } \ +__flatcc_basic_scalar_accessors_impl(N, T, W, E) + +#define __flatcc_define_real_accessors_impl(N, T, W, E) \ +static inline T N ## _read(const void *p) \ +{ return (T) mem_read_float_ ## W(p); } \ +static inline void N ## _write(void *p, T v) \ +{ mem_write_float_ ## W(p, v); } \ +union __ ## N ## _cast { T v; uint ## W ## _t u; }; \ +static inline T N ## _cast_from_pe(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = E ## W ## toh(x.u); return x.v; } \ +static inline T N ## _cast_to_pe(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = hto ## E ## W(x.u); return x.v; } \ +static inline T N ## _cast_from_le(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = le ## W ## toh(x.u); return x.v; } \ +static inline T N ## _cast_to_le(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = htole ## W(x.u); return x.v; } \ +static inline T N ## _cast_from_be(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = be ## W ## toh(x.u); return x.v; } \ +static inline T N ## _cast_to_be(T v) \ +{ union __ ## N ## _cast x; \ + x.v = v; x.u = htobe ## W(x.u); return x.v; } \ +__flatcc_basic_scalar_accessors_impl(N, T, W, E) + +#define __flatcc_define_integer_accessors(N, T, W, E) \ +__flatcc_define_integer_accessors_impl(N, T, W, E) + +#define __flatcc_define_real_accessors(N, T, W, E) \ +__flatcc_define_real_accessors_impl(N, T, W, E) + +#define __flatcc_define_basic_integer_accessors(NS, TN, T, W, E) \ +__flatcc_define_integer_accessors(NS ## TN, T, W, E) + +#define __flatcc_define_basic_real_accessors(NS, TN, T, W, E) \ +__flatcc_define_real_accessors(NS ## TN, T, W, E) + +#define __flatcc_define_basic_scalar_accessors(NS, E) \ +__flatcc_define_basic_integer_accessors(NS, char, char, 8, E) \ +__flatcc_define_basic_integer_accessors(NS, uint8, uint8_t, 8, E) \ +__flatcc_define_basic_integer_accessors(NS, uint16, uint16_t, 16, E) \ +__flatcc_define_basic_integer_accessors(NS, uint32, uint32_t, 32, E) \ +__flatcc_define_basic_integer_accessors(NS, uint64, uint64_t, 64, E) \ +__flatcc_define_basic_integer_accessors(NS, int8, int8_t, 8, E) \ +__flatcc_define_basic_integer_accessors(NS, int16, int16_t, 16, E) \ +__flatcc_define_basic_integer_accessors(NS, int32, int32_t, 32, E) \ +__flatcc_define_basic_integer_accessors(NS, int64, int64_t, 64, E) \ +__flatcc_define_basic_real_accessors(NS, float, float, 32, E) \ +__flatcc_define_basic_real_accessors(NS, double, double, 64, E) + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_ACCESSORS */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_alloc.h b/third_party/nanoarrow/include/flatcc/flatcc_alloc.h new file mode 100644 index 0000000..20fd207 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_alloc.h @@ -0,0 +1,128 @@ +#ifndef FLATCC_ALLOC_H +#define FLATCC_ALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * These allocation abstractions are __only__ for runtime libraries. + * + * The flatcc compiler uses Posix allocation routines regardless + * of how this file is configured. + * + * This header makes it possible to use systems where malloc is not + * valid to use. In this case the portable library will not help + * because it implements Posix / C11 abstractions. + * + * Systems like FreeRTOS do not work with Posix memory calls and here it + * can be helpful to override runtime allocation primitives. + * + * In general, it is better to customize the allocator and emitter via + * flatcc_builder_custom_init and to avoid using the default emitter + * specific high level calls the copy out a buffer that must later be + * deallocated. This provides full control of allocation withou the need + * for this file. + * + * + * IMPORTANT + * + * If you override malloc, free, etc., make sure your applications + * use the same allocation methods. For example, samples/monster.c + * and several test cases are no longer guaranteed to work out of the + * box. + * + * The changes must only affect target runtime compilation including the + * the runtime library libflatccrt. + * + * The host system flatcc compiler and the compiler library libflatcc + * should NOT be compiled with non-Posix allocation since the compiler + * has a dependency on the runtime library and the wrong free operation + * might be callled. The safest way to avoid this problem this is to + * compile flatcc with the CMake script and the runtime files with a + * dedicated build system for the target system. + */ + +#include + +#ifndef FLATCC_ALLOC +#define FLATCC_ALLOC(n) malloc(n) +#endif + +#ifndef FLATCC_FREE +#define FLATCC_FREE(p) free(p) +#endif + +#ifndef FLATCC_REALLOC +#define FLATCC_REALLOC(p, n) realloc(p, n) +#endif + +#ifndef FLATCC_CALLOC +#define FLATCC_CALLOC(nm, n) calloc(nm, n) +#endif + +/* + * Implements `aligned_alloc` and `aligned_free`. + * Even with C11, this implements non-standard aligned_free needed for portable + * aligned_alloc implementations. + */ +#ifndef FLATCC_USE_GENERIC_ALIGNED_ALLOC + +#ifndef FLATCC_NO_PALIGNED_ALLOC +#include "flatcc/portable/paligned_alloc.h" +#else +#if !defined(__aligned_free_is_defined) || !__aligned_free_is_defined +#define aligned_free free +#endif +#endif + +#else /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ + +#ifndef FLATCC_ALIGNED_ALLOC +static inline void *__flatcc_aligned_alloc(size_t alignment, size_t size) +{ + char *raw; + void *buf; + size_t total_size = (size + alignment - 1 + sizeof(void *)); + + if (alignment < sizeof(void *)) { + alignment = sizeof(void *); + } + raw = (char *)(size_t)FLATCC_ALLOC(total_size); + if (!raw) return 0; + buf = raw + alignment - 1 + sizeof(void *); + buf = (void *)(((size_t)buf) & ~(alignment - 1)); + ((void **)buf)[-1] = raw; + return buf; +} +#define FLATCC_ALIGNED_ALLOC(alignment, size) __flatcc_aligned_alloc(alignment, size) +#endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ + +#ifndef FLATCC_ALIGNED_FREE +static inline void __flatcc_aligned_free(void *p) +{ + char *raw; + + if (!p) return; + raw = ((void **)p)[-1]; + + FLATCC_FREE(raw); +} +#define FLATCC_ALIGNED_FREE(p) __flatcc_aligned_free(p) +#endif + +#endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ + +#ifndef FLATCC_ALIGNED_ALLOC +#define FLATCC_ALIGNED_ALLOC(a, n) aligned_alloc(a, n) +#endif + +#ifndef FLATCC_ALIGNED_FREE +#define FLATCC_ALIGNED_FREE(p) aligned_free(p) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_ALLOC_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_assert.h b/third_party/nanoarrow/include/flatcc/flatcc_assert.h new file mode 100644 index 0000000..0a3b8ee --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_assert.h @@ -0,0 +1,45 @@ +#ifndef FLATCC_ASSERT_H +#define FLATCC_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* +* This assert abstraction is only used for the flatcc runtime library. +* The flatcc compiler uses Posix assert routines regardless of how this +* file is configured. +* +* This header makes it possible to use systems where assert is not +* valid to use. Note that `` may remain a dependency for static +* assertions. +* +* `FLATCC_ASSERT` is designed to handle errors which cannot be ignored +* and could lead to crash. The portable library may use assertions that +* are not affected by this macro. +* +* `FLATCC_ASSERT` defaults to POSIX assert but can be overrided by a +* preprocessor definition. +* +* Runtime assertions can be entirely disabled by defining +* `FLATCC_NO_ASSERT`. +*/ + +#ifdef FLATCC_NO_ASSERT +/* NOTE: This will not affect inclusion of for static assertions. */ +#undef FLATCC_ASSERT +#define FLATCC_ASSERT(x) ((void)0) +/* Grisu3 is used for floating point conversion in JSON processing. */ +#define GRISU3_NO_ASSERT +#endif + +#ifndef FLATCC_ASSERT +#include +#define FLATCC_ASSERT assert +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_ASSERT_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_builder.h b/third_party/nanoarrow/include/flatcc/flatcc_builder.h new file mode 100644 index 0000000..2e84d29 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_builder.h @@ -0,0 +1,1911 @@ +#ifndef FLATCC_BUILDER_H +#define FLATCC_BUILDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Library for building untyped FlatBuffers. Intended as a support + * library for generated C code to produce typed builders, but might + * also be useful in runtime environments and as support for scripting + * languages. + * + * The builder has two API layers: a stack based `start/end` approach, + * and a direct `create`, and they may be mixed freely. The direct + * approach may be used as part of more specialized optimizations such + * as rewriting buffers while the stack approach is convenient for state + * machine driven parsers without a stack, or with a very simple stack + * without extra allocations. + * + * The builder emits partial buffer sequences to a user provided emitter + * function and does not require a full buffer reprensenation in memory. + * For this reason it also does not support sorting or other operations + * that requires representing the buffer, but post-processors can easily + * do this, and the generated schema specific code and provide functions + * to handle this. + * + * A custom allocator with a default realloc implementation can place + * restraints on resource consumption and provide initial allocation + * sizes for various buffers and stacks in use. + * + * A buffer under construction uses a virtual address space for the + * completed part of the buffer, starting at 0 and growing in both + * directions, or just down depending on whether vtables should be + * clustered at the end or not. Clustering may help caching and + * preshipping that part of the buffer. + * + * Because an offset cannot be known before its reference location is + * defined, every completed table, vector, etc. returns a reference into + * the virtual address range. If the final buffer keeps the 0 offset, + * these references remain stable an may be used for external references + * into the buffer. + * + * The maximum buffer that can be constructed is in praxis limited to + * half the UOFFSET_MAX size, typically 2^31 bytes, not counting + * clustered vtables that may consume and additional 2^31 bytes + * (positive address range), but in praxis cannot because vtable + * references are signed and thus limited to 2^31 bytes (or equivalent + * depending on the flatbuffer types chosen). + * + * CORRECTION: in various places rules are mentioned about nesting and using + * a reference at most once. In fact, DAG's are also valid flatbuffers. + * This means a reference may be reused as long as each individual use + * obeys the rules and, for example, circular references are not + * constructed (circular types are ok, but objects graphs with cycles + * are not permitted). Be especially aware of the offset vector create + * call which translates the references into offsets - this can be + * reverted by noting the reference in vector and calculate the base + * used for the offset to restore the original references after the + * vector has been emitted. + */ + +#include +#ifndef UINT8_MAX +#include +#endif + +#include "flatcc_flatbuffers.h" +#include "flatcc_emitter.h" +#include "flatcc_refmap.h" + +/* It is possible to enable logging here. */ +#ifndef FLATCC_BUILDER_ASSERT +#define FLATCC_BUILDER_ASSERT(cond, reason) FLATCC_ASSERT(cond) +#endif + +/* + * Eror handling is not convenient and correct use should not cause + * errors beyond possibly memory allocation, but assertions are a + * good way to trace problems. + * + * Note: some internal assertion will remain if disabled. + */ +#ifndef FLATCC_BUILDER_ASSERT_ON_ERROR +#define FLATCC_BUILDER_ASSERT_ON_ERROR 1 +#endif + +/* + * If set, checks user input agains state and returns error, + * otherwise errors are ignored (assuming they won't happen). + * Errors will be asserted if enabled and checks are not skipped. + */ +#ifndef FLATCC_BUILDER_SKIP_CHECKS +#define FLATCC_BUILDER_SKIP_CHECKS 0 +#endif + + +/* + * When adding the same field to a table twice this is either an error + * or the existing field is returned, potentially introducing garbage + * if the type is a vector, table, or string. When implementing parsers + * it may be convenient to not treat this as an error. + */ +#ifndef FLATCC_BUILDER_ALLOW_REPEAT_TABLE_ADD +#define FLATCC_BUILDER_ALLOW_REPEAT_TABLE_ADD 0 +#endif + +/** + * This type must have same size as `flatbuffers_uoffset_t` + * and must be a signed type. + */ +typedef flatbuffers_soffset_t flatcc_builder_ref_t; +typedef flatbuffers_utype_t flatcc_builder_utype_t; + +/** + * This type must be compatible with code generation that + * creates union specific ref types. + */ +typedef struct flatcc_builder_union_ref { + flatcc_builder_utype_t type; + flatcc_builder_ref_t value; +} flatcc_builder_union_ref_t; + +typedef struct flatcc_builder_union_vec_ref { + flatcc_builder_ref_t type; + flatcc_builder_ref_t value; +} flatcc_builder_union_vec_ref_t; + +/** + * Virtual tables are off by one to avoid being mistaken for error at + * position 0, and it makes them detectable as such because no other + * reference is uneven. Vtables are emitted at their actual location + * which is one less than the reference value. + */ +typedef flatbuffers_soffset_t flatcc_builder_vt_ref_t; + +typedef flatbuffers_uoffset_t flatcc_builder_identifier_t; + +/** + * Hints to custom allocators so they can provide initial alloc sizes + * etc. There will be at most one buffer for each allocation type per + * flatcc_builder instance. Buffers containing only structs may avoid + * allocation altogether using a `create` call. The vs stack must hold + * vtable entries for all open tables up to their requested max id, but + * unused max id overlap on the stack. The final vtables only store the + * largest id actually added. The fs stack must hold stack frames for + * the nesting levels expected in the buffer, each about 50-100 bytes. + * The ds stack holds open vectors, table data, and nested buffer state. + * `create` calls bypass the `ds` and `fs` stack and are thus faster. + * The vb buffer holds a copy of all vtables seen and emitted since last + * vtable flush. The patch log holds a uoffset for every table field + * added to currently open tables. The hash table holds a uoffset entry + * for each hash slot where the allocator decides how many to provide + * above a certain minimum. The vd buffer allocates vtable descriptors + * which is a reference to an emitted vtable, an offset to a cached + * vtable, and a link to next descriptor with same hash. Calling `reset` + * after build can either keep the allocation levels for the next + * buffer, or reduce the buffers already allocated by requesting 1 byte + * allocations (meaning provide a default). + * + * The user stack is not automatically allocated, but when entered + * explicitly, the boundary is rembered in the current live + * frame. + */ +enum flatcc_builder_alloc_type { + /* The stack where vtables are build. */ + flatcc_builder_alloc_vs, + /* The stack where data structures are build. */ + flatcc_builder_alloc_ds, + /* The virtual table buffer cache, holds a copy of each vt seen. */ + flatcc_builder_alloc_vb, + /* The patch log, remembers table fields with outstanding offset refs. */ + flatcc_builder_alloc_pl, + /* The stack of frames for nested types. */ + flatcc_builder_alloc_fs, + /* The hash table part of the virtual table cache. */ + flatcc_builder_alloc_ht, + /* The vtable descriptor buffer, i.e. list elements for emitted vtables. */ + flatcc_builder_alloc_vd, + /* User stack frame for custom data. */ + flatcc_builder_alloc_us, + + /* Number of allocation buffers. */ + flatcc_builder_alloc_buffer_count +}; + +/** Must reflect the `flatcc_builder_alloc_type` enum. */ +#define FLATCC_BUILDER_ALLOC_BUFFER_COUNT flatcc_builder_alloc_buffer_count + +#ifndef FLATCC_BUILDER_ALLOC +#define FLATCC_BUILDER_ALLOC(n) FLATCC_ALLOC(n) +#endif + +#ifndef FLATCC_BUILDER_FREE +#define FLATCC_BUILDER_FREE(p) FLATCC_FREE(p) +#endif + +#ifndef FLATCC_BUILDER_REALLOC +#define FLATCC_BUILDER_REALLOC(p, n) FLATCC_REALLOC(p, n) +#endif + +#ifndef FLATCC_BUILDER_ALIGNED_ALLOC +#define FLATCC_BUILDER_ALIGNED_ALLOC(a, n) FLATCC_ALIGNED_ALLOC(a, n) +#endif + +#ifndef FLATCC_BUILDER_ALIGNED_FREE +#define FLATCC_BUILDER_ALIGNED_FREE(p) FLATCC_ALIGNED_FREE(p) +#endif + +/** + * Emits data to a conceptual deque by appending to either front or + * back, starting from offset 0. + * + * Each emit call appends a strictly later or earlier sequence than the + * last emit with same offset sign. Thus a buffer is gradually grown at + * both ends. `len` is the combined length of all iov entries such that + * `offset + len` yields the former offset for negative offsets and + * `offset + len` yields the next offset for non-negative offsets. + * The bulk of the data will be in the negative range, possibly all of + * it. The first emitted emitted range will either start or end at + * offset 0. If offset 0 is emitted, it indicates the start of clustered + * vtables. The last positive (non-zero) offset may be zero padding to + * place the buffer in a full multiple of `block_align`, if set. + * + * No iov entry is empty, 0 < iov_count <= FLATCC_IOV_COUNT_MAX. + * + * The source data are in general ephemeral and should be consumed + * immediately, as opposed to caching iov. + * + * For high performance applications: + * + * The `create` calls may reference longer living data, but header + * fields etc. will still be short lived. If an emitter wants to + * reference data in another buffer rather than copying, it should + * inspect the memory range. The length of an iov entry may also be used + * since headers are never very long (anything starting at 16 bytes can + * safely be assumed to be user provided, or static zero padding). It is + * guaranteed that data pointers in `create` calls receive a unique slot + * separate from temporary headers, in the iov table which may be used + * for range checking or hashing (`create_table` is the only call that + * mutates the data buffer). It is also guaranteed (with the exception + * of `create_table` and `create_cached_vtable`) that data provided to + * create calls are not referenced at all by the builder, and these data + * may therefore de-facto be handles rather than direct pointers when + * the emitter and data provider can agree on such a protocol. This does + * NOT apply to any start/end/add/etc. calls which do copy to stack. + * `flatcc_builder_padding_base` may be used to test if an iov entry is + * zero padding which always begins at that address. + * + * Future: the emit interface could be extended with a type code + * and return an existing object insted of the emitted if, for + * example, they are identical. Outside this api level, generated + * code could provide a table comparison function to help such + * deduplication. It would be optional because two equal objects + * are not necessarily identical. The emitter already receives + * one object at time. + * + * Returns 0 on success and otherwise causes the flatcc_builder + * to fail. + */ +typedef int flatcc_builder_emit_fun(void *emit_context, + const flatcc_iovec_t *iov, int iov_count, flatbuffers_soffset_t offset, size_t len); + +/* + * Returns a pointer to static padding used in emitter calls. May + * sometimes also be used for empty defaults such as identifier. + */ +extern const uint8_t flatcc_builder_padding_base[]; + +/** + * `request` is a minimum size to be returned, but allocation is + * expected to grow exponentially or in reasonable chunks. Notably, + * `alloc_type = flatcc_builder_alloc_ht` will only use highest available + * power of 2. The allocator may shrink if `request` is well below + * current size but should avoid repeated resizing on small changes in + * request sizes. If `zero_fill` is non-zero, allocated data beyond + * the current size must be zeroed. The buffer `b` may be null with 0 + * length initially. `alloc_context` is completely implementation + * dependendent, and not needed when just relying on realloc. The + * resulting buffer may be the same or different with moved data, like + * realloc. Returns -1 with unmodified buffer on failure or 0 on + * success. The `alloc_type` identifies the buffer type. This may be + * used to cache buffers between instances of builders, or to decide a + * default allocation size larger than requested. If `need` is zero the + * buffer should be deallocate if non-zero, and return success (0) + * regardless. + */ +typedef int flatcc_builder_alloc_fun(void *alloc_context, + flatcc_iovec_t *b, size_t request, int zero_fill, int alloc_type); + +/* + * The number of hash slots there will be allocated space for. The + * allocator may provide more. The size returned should be + * `sizeof(flatbuffers_uoffset_t) * count`, where the size is a power of + * 2 (or the rest is wasted). The hash table can store many more entries + * than slots using linear search. The table does not resize. + */ +#ifndef FLATCC_BUILDER_MIN_HASH_COUNT +#define FLATCC_BUILDER_MIN_HASH_COUNT 64 +#endif + +typedef struct __flatcc_builder_buffer_frame __flatcc_builder_buffer_frame_t; +struct __flatcc_builder_buffer_frame { + flatcc_builder_identifier_t identifier; + flatcc_builder_ref_t mark; + flatbuffers_uoffset_t vs_end; + flatbuffers_uoffset_t nest_id; + uint16_t flags; + uint16_t block_align; +}; + +typedef struct __flatcc_builder_vector_frame __flatcc_builder_vector_frame_t; +struct __flatcc_builder_vector_frame { + flatbuffers_uoffset_t elem_size; + flatbuffers_uoffset_t count; + flatbuffers_uoffset_t max_count; +}; + +typedef struct __flatcc_builder_table_frame __flatcc_builder_table_frame_t; +struct __flatcc_builder_table_frame { + flatbuffers_uoffset_t vs_end; + flatbuffers_uoffset_t pl_end; + uint32_t vt_hash; + flatbuffers_voffset_t id_end; +}; + +/* + * Store state for nested structures such as buffers, tables and vectors. + * + * For less busy data and data where access to a previous state is + * irrelevant, the frame may store the current state directly. Otherwise + * the current state is maintained in the flatcc_builder_t structure in a + * possibly derived form (e.g. ds pointer instead of ds_end offset) and + * the frame is used to store the previous state when the frame is + * entered. + * + * Most operations have a start/update/end cycle the decides the + * liftetime of a frame, but these generally also have a direct form + * (create) that does not use a frame at all. These still do some + * state updates notably passing min_align to parent which may also be + * an operation without a frame following the child level operation + * (e.g. create struct, create buffer). Ending a frame results in the + * same kind of updates. + */ +typedef struct __flatcc_builder_frame __flatcc_builder_frame_t; +struct __flatcc_builder_frame { + flatbuffers_uoffset_t ds_first; + flatbuffers_uoffset_t type_limit; + flatbuffers_uoffset_t ds_offset; + uint16_t align; + uint16_t type; + union { + __flatcc_builder_table_frame_t table; + __flatcc_builder_vector_frame_t vector; + __flatcc_builder_buffer_frame_t buffer; + } container; +}; + +/** + * The main flatcc_builder structure. Can be stack allocated and must + * be initialized with `flatcc_builder_init` and cleared with + * `flatcc_builder_clear` to reclaim memory. Between buffer builds, + * `flatcc_builder_reset` may be used. + */ +typedef struct flatcc_builder flatcc_builder_t; + +struct flatcc_builder { + /* Next entry on reserved stack in `alloc_pl` buffer. */ + flatbuffers_voffset_t *pl; + /* Next entry on reserved stack in `alloc_vs` buffer. */ + flatbuffers_voffset_t *vs; + /* One above the highest entry in vs, used to track vt_size. */ + flatbuffers_voffset_t id_end; + /* The evolving vtable hash updated with every new field. */ + uint32_t vt_hash; + + /* Pointer to ds_first. */ + uint8_t *ds; + /* Offset from `ds` on current frame. */ + flatbuffers_uoffset_t ds_offset; + /* ds buffer size relative to ds_first, clamped to max size of current type. */ + flatbuffers_uoffset_t ds_limit; + + /* ds_first, ds_first + ds_offset is current ds stack range. */ + flatbuffers_uoffset_t ds_first; + /* Points to currently open frame in `alloc_fs` buffer. */ + __flatcc_builder_frame_t *frame; + + /* Only significant to emitter function, if at all. */ + void *emit_context; + /* Only significant to allocator function, if at all. */ + void *alloc_context; + /* Customizable write function that both appends and prepends data. */ + flatcc_builder_emit_fun *emit; + /* Customizable allocator that also deallocates. */ + flatcc_builder_alloc_fun *alloc; + /* Buffers indexed by `alloc_type` */ + flatcc_iovec_t buffers[FLATCC_BUILDER_ALLOC_BUFFER_COUNT]; + /* Number of slots in ht given as 1 << ht_width. */ + size_t ht_width; + + /* The location in vb to add next cached vtable. */ + flatbuffers_uoffset_t vb_end; + /* Where to allocate next vtable descriptor for hash table. */ + flatbuffers_uoffset_t vd_end; + /* Ensure final buffer is aligned to at least this. Nested buffers get their own `min_align`. */ + uint16_t min_align; + /* The current active objects alignment isolated from nested activity. */ + uint16_t align; + /* The current buffers block alignment used when emitting buffer. */ + uint16_t block_align; + /* Signed virtual address range used for `flatcc_builder_ref_t` and emitter. */ + flatcc_builder_ref_t emit_start; + flatcc_builder_ref_t emit_end; + /* 0 for top level, and end of buffer ref for nested buffers (can also be 0). */ + flatcc_builder_ref_t buffer_mark; + /* Next nest_id. */ + flatbuffers_uoffset_t nest_count; + /* Unique id to prevent sharing of vtables across buffers. */ + flatbuffers_uoffset_t nest_id; + /* Current nesting level. Helpful to state-machines with explicit stack and to check `max_level`. */ + int level; + /* Aggregate check for allocated frame and max_level. */ + int limit_level; + /* Track size prefixed buffer. */ + uint16_t buffer_flags; + + /* Settings that may happen with no frame allocated. */ + + flatcc_builder_identifier_t identifier; + + /* Settings that survive reset (emitter, alloc, and contexts also survive): */ + + /* If non-zero, vtable cache gets flushed periodically. */ + size_t vb_flush_limit; + /* If non-zero, fails on deep nesting to help drivers with a stack, such as recursive parsers etc. */ + int max_level; + /* If non-zero, do not cluster vtables at end, only emit negative offsets (0 by default). */ + int disable_vt_clustering; + + /* Set if the default emitter is being used. */ + int is_default_emitter; + /* Only used with default emitter. */ + flatcc_emitter_t default_emit_context; + + /* Offset to the last entered user frame on the user frame stack, after frame header, or 0. */ + size_t user_frame_offset; + + /* The offset to the end of the most recent user frame. */ + size_t user_frame_end; + + /* The optional user supplied refmap for cloning DAG's - not shared with nested buffers. */ + flatcc_refmap_t *refmap; +}; + +/** + * Call this before any other API call. + * + * The emitter handles the completed chunks of the buffer that will no + * longer be required by the builder. It is largely a `write` function + * that can append to both positive and negative offsets. + * + * No memory is allocated during init. Buffers will be allocated as + * needed. The `emit_context` is only used by the emitter, if at all. + * + * `flatcc_builder_reset/clear` calls are automtically forwarded to the + * default emitter. + * + * Returns -1 on failure, 0 on success. + */ +int flatcc_builder_init(flatcc_builder_t *B); + +/** + * Use instead of `flatcc_builder_init` when providing a custom allocator + * or emitter. Leave emitter or allocator null to use default. + * Cleanup of emit and alloc context must be handled manually after + * the builder is cleared or reset, except if emitter is null the + * default will be automatically cleared and reset. + * + * Returns -1 on failure, 0 on success. + */ +int flatcc_builder_custom_init(flatcc_builder_t *B, + flatcc_builder_emit_fun *emit, void *emit_context, + flatcc_builder_alloc_fun *alloc, void *alloc_context); + +/* + * Returns (flatcc_emitter_t *) if the default context is used. + * Other emitter might have null contexts. + */ +void *flatcc_builder_get_emit_context(flatcc_builder_t *B); + +/** + * Prepares builder for a new build. The emitter is not told when a + * buffer is finished or when a new begins, and must be told so + * separately. Allocated buffers will be zeroed, but may optionally be + * reduced to their defaults (signalled by reallocating each non-empty + * buffer to a single byte). General settings are cleared optionally, + * such as cache flushing. Buffer specific settings such as buffer + * identifier are always cleared. + * + * Returns -1 if allocator complains during buffer reduction, 0 on + * success. + */ +int flatcc_builder_custom_reset(flatcc_builder_t *B, + int reduce_buffers, int set_defaults); + +/* + * Same as `flatcc_builder_custom_reset` with default arguments + * where buffers are not reduced and default settings are not reset. + */ +int flatcc_builder_reset(flatcc_builder_t *B); + +/** + * Deallocates all memory by calling allocate with a zero size request + * on each buffer, then zeroing the builder structure itself. + */ +void flatcc_builder_clear(flatcc_builder_t *B); + +/** + * Allocates to next higher power of 2 using system realloc and ignores + * `alloc_context`. Only reduces size if a small subsequent increase in + * size would not trigger a reallocation. `alloc_type` is used to + * set minimum sizes. Hash tables are allocated to the exact requested + * size. See also `alloc_fun`. + */ +int flatcc_builder_default_alloc(void *alloc_context, + flatcc_iovec_t *b, size_t request, int zero_fill, int alloc_type); + +/** + * If non-zero, the vtable cache will get flushed whenever it reaches + * the given limit at a point in time where more space is needed. The + * limit is not exact as it is only tested when reallocation is + * required. + */ +void flatcc_builder_set_vtable_cache_limit(flatcc_builder_t *B, size_t size); + +/** + * Manual flushing of vtable for long running tasks. Mostly used + * internally to deal with nested buffers. + */ +void flatcc_builder_flush_vtable_cache(flatcc_builder_t *B); + +/** + * Low-level support function to aid in constructing nested buffers without + * allocation. Not for regular use. + * + * Call where `start_buffer` would have been placed when using + * `create_buffer` in a nested context. Save the return value on a stack + * as argument to `pop_buffer_alignment`. + * + * The call resets the current derived buffer alignment so the nested + * buffer will not be aligned to more than required. + * + * Often it will not be necessary to be so careful with alignment since + * the alignment cannot be invalid by failing to use push and pop, but + * for code generation it will ensure the correct result every time. + */ +uint16_t flatcc_builder_push_buffer_alignment(flatcc_builder_t *B); + +/** + * Low-level call. + * + * Call with the return value from push_buffer_alignment after a nested + * `create_buffer_call`. The alignments merge back up in the buffer + * hierarchy so the top level buffer gets the largest of all aligments. + */ +void flatcc_builder_pop_buffer_alignment(flatcc_builder_t *B, uint16_t buffer_align); + +/** + * This value may be of interest when the buffer has been ended, for + * example when subsequently allocating memory for the buffer to ensure + * that memory is properly aligned. + */ +uint16_t flatcc_builder_get_buffer_alignment(flatcc_builder_t *B); + +/** + * Level 0 means no buffer is started, otherwise it increments with + * start calls and decrements with end calls (approximately for + * optimized operations such as table vectors). + * + * If `max_level` has been set, `get_level` always returns a value <= + * `max_level` provided no start call has failed. + * + * Level continues to increment inside nested buffers. + */ +int flatcc_builder_get_level(flatcc_builder_t *B); + +/** + * Setting the max level triggers a failure on start of new nestings + * when the level is reached. May be used to protect recursive descend + * parsers etc. or later buffer readers. + * + * The builder itself is not sensitive to depth, and the allocator is a + * better way to protect resource abuse. + * + * `max_level` is not reset inside nested buffers. + */ +void flatcc_builder_set_max_level(flatcc_builder_t *B, int level); + +/** + * By default ordinary data such as tables are placed in front of + * earlier produced content and vtables are placed at the very end thus + * clustering vtables together. This can be disabled so all content is + * placed in front. Nested buffers ignores this setting because they can + * only place content in front because they cannot blend with the + * containing buffers content. Clustering could be more cache friendly + * and also enables pre-shipping of the vtables during transmission. + */ +void flatcc_builder_set_vtable_clustering(flatcc_builder_t *B, int enable); + +/** + * Sets a new user supplied refmap which maps source pointers to + * references and returns the old refmap, or null. It is also + * possible to disable an existing refmap by setting a null + * refmap. + * + * A clone or pick operation may use this map when present, + * depending on the data type. If a hit is found, the stored + * reference will be used instead of performing a new clone or + * pick operation. It is also possible to manually populate the + * refmap. Note that the builder does not have a concept of + * clone or pick - these are higher level recursive operations + * to add data from one buffer to another - but such code may + * rely on the builder to provide the current refmap during + * recursive operations. For this reason, the builder makes no + * calls to the refmap interface on its own - it just stores the + * current refmap such that recursive operations can find it. + * + * Refmaps MUST be reset, replaced or disabled if a source + * pointer may be reused for different purposes - for example if + * repeatedly reading FlatBuffers into the same memory buffer + * and performing a clone into a buffer under construction. + * Refmaps may also be replaced if the same object is to be + * cloned several times keeping the internal DAG structure + * intact with every new clone being an independent object. + * + * Refmaps must also be replaced or disabled prior to starting a + * nested buffer and after stopping it, or when cloning a object + * as a nested root. THIS IS VERY EASY TO GET WRONG! The + * builder does a lot of bookkeeping for nested buffers but not + * in this case. Shared references may happen and they WILL fail + * verification and they WILL break when copying out a nested + * buffer to somewhere else. The user_frame stack may be used + * for pushing refmaps, but often user codes recursive stack + * will work just as well. + * + * It is entirely optional to use refmaps when cloning - they + * preserve DAG structure and may speed up operations or slow + * them down, depending on the source material. + * + * Refmaps may consume a lot of space when large offset vectors + * are cloned when these do not have significant shared + * references. They may also be very cheap to use without any + * dynamic allocation when objects are small and have at most a + * few references. + * + * Refmaps only support init, insert, find, reset, clear but not + * delete. There is a standard implementation in the runtime + * source tree but it can easily be replaced compile time and it + * may also be left out if unused. The builder wraps reset, insert, + * and find so the user does not have to check if a refmap is + * present but other operations must be done direcly on the + * refmap. + * + * The builder wrapped refmap operations are valid on a null + * refmap which will find nothing and insert nothing. + * + * The builder will reset the refmap during a builder reset and + * clear the refmap during a builder clear operation. If the + * refmap goes out of scope before that happens it is important + * to call set_refmap with null and manually clear the refmap. + */ +static inline flatcc_refmap_t *flatcc_builder_set_refmap(flatcc_builder_t *B, flatcc_refmap_t *refmap) +{ + flatcc_refmap_t *refmap_old; + + refmap_old = B->refmap; + B->refmap = refmap; + return refmap_old; +} + +/* Retrieves the current refmap, or null. */ +static inline flatcc_refmap_t *flatcc_builder_get_refmap(flatcc_builder_t *B) +{ + return B->refmap; +} + +/* Finds a reference, or a null reference if no refmap is active. * */ +static inline flatcc_builder_ref_t flatcc_builder_refmap_find(flatcc_builder_t *B, const void *src) +{ + return B->refmap ? flatcc_refmap_find(B->refmap, src) : flatcc_refmap_not_found; +} + +/* + * Inserts into the current refmap with the inseted ref upon + * upon success, or not_found on failure (default 0), or just + * returns ref if refmap is absent. + * + * Note that if an existing item exists, the ref is replaced + * and the new, not the old, ref is returned. + */ +static inline flatcc_builder_ref_t flatcc_builder_refmap_insert(flatcc_builder_t *B, const void *src, flatcc_builder_ref_t ref) +{ + return B->refmap ? flatcc_refmap_insert(B->refmap, src, ref) : ref; +} + +static inline void flatcc_builder_refmap_reset(flatcc_builder_t *B) +{ + if (B->refmap) flatcc_refmap_reset(B->refmap); +} + + +typedef uint16_t flatcc_builder_buffer_flags_t; +static const flatcc_builder_buffer_flags_t flatcc_builder_is_nested = 1; +static const flatcc_builder_buffer_flags_t flatcc_builder_with_size = 2; + +/* The flag size in the API needs to match the internal size. */ +static_assert(sizeof(flatcc_builder_buffer_flags_t) == + sizeof(((flatcc_builder_t *)0)->buffer_flags), "flag size mismatch"); + +/** + * An alternative to start buffer, start struct/table ... end buffer. + * + * This call is mostly of interest as a means to quicly create a zero + * allocation top-level buffer header following a call to create_struct, + * or to create_vtable/create_table. For that, it is quite simple to + * use. For general buffer construction without allocation, more care is + * needed, as discussed below. + * + * If the content is created with `start/end_table` calls, or similar, + * it is better to use `start/end_buffer` since stack allocation is used + * anyway. + * + * The buffer alignment must be provided manually as it is not derived + * from constructed content, unlike `start/end_buffer`. Typically + * `align` would be same argument as provided to `create_struct`. + * `get_buffer_alignment` may also used (note: `get_buffer_alignment` + * may return different after the call because it will be updated with + * the `block_align` argument to `create_buffer` but that is ok). + * + * The buffer may be constructed as a nested buffer with the `is_nested + * = 1` flag. As a nested buffer a ubyte vector header is placed before + * the aligned buffer header. A top-level buffer will normally have + * flags set to 0. + * + * A top-level buffer may also be constructed with the `with_size = 2` + * flag for top level buffers. It adds a size prefix similar to + * `is_nested` but the size is part of the aligned buffer. A size + * prefixed top level buffer must be accessed with a size prefix aware + * reader, or the buffer given to a standard reader must point to after + * the size field while keeping the buffer aligned to the size field + * (this will depend on the readers API which may be an arbitrary other + * language). + * + * If the `with_size` is used with the `is_nested` flag, the size is + * added as usual and all fields remain aligned as before, but padding + * is adjusted to ensure the buffer is aligned to the size field so + * that, for example, the nested buffer with size can safely be copied + * to a new memory buffer for consumption. + * + * Generally, references may only be used within the same buffer + * context. With `create_buffer` this becomes less precise. The rule + * here is that anything that would be valid with start/end_buffer + * nestings is also valid when removing the `start_buffer` call and + * replacing `end_buffer` with `create_buffer`. + * + * Note the additional burden of tracking buffer alignment manually - + * To help with this use `push_buffer_alignment` where `start_buffer` + * would have been placed, and `pop_buffer_alignment after the + * `create_buffer` call, and use `get_buffer_alignemnt` as described + * above. + * + * `create_buffer` is not suitable as a container for buffers created + * with `start/end_buffer` as these make assumptions about context that + * create buffer does not provide. Also, there is no point in doing so, + * since the idea of `create_buffer` is to avoid allocation in the first + * place. + */ +flatcc_builder_ref_t flatcc_builder_create_buffer(flatcc_builder_t *B, + const char identifier[FLATBUFFERS_IDENTIFIER_SIZE], + uint16_t block_align, + flatcc_builder_ref_t ref, uint16_t align, flatcc_builder_buffer_flags_t flags); + +/** + * Creates a struct within the current buffer without using any + * allocation. + * + * The struct should be used as a root in the `end_buffer` call or as a + * union value as there are no other ways to use struct while conforming + * to the FlatBuffer format - noting that tables embed structs in their + * own data area except in union fields. + * + * The struct should be in little endian format and follow the usual + * FlatBuffers alignment rules, although this API won't care about what + * is being stored. + * + * May also be used to simply emit a struct through the emitter + * interface without being in a buffer and without being a valid + * FlatBuffer. + */ +flatcc_builder_ref_t flatcc_builder_create_struct(flatcc_builder_t *B, + const void *data, size_t size, uint16_t align); + +/** + * Starts a struct and returns a pointer that should be used immediately + * to fill in the struct in protocol endian format, and when done, + * `end_struct` should be called. The returned reference should be used + * as argument to `end_buffer` or as a union value. See also + * `create_struct`. + */ +void *flatcc_builder_start_struct(flatcc_builder_t *B, + size_t size, uint16_t align); + +/** + * Return a pointer also returned at start struct, e.g. for endian + * conversion. + */ +void *flatcc_builder_struct_edit(flatcc_builder_t *B); + +/** + * Emits the struct started by `start_struct` and returns a reference to + * be used as root in an enclosing `end_buffer` call or as a union + * value. As mentioned in `create_struct`, these can also be used more + * freely, but not while being conformant FlatBuffers. + */ +flatcc_builder_ref_t flatcc_builder_end_struct(flatcc_builder_t *B); + +/** + * The buffer always aligns to at least the offset size (typically 4) + * and the internal alignment requirements of the buffer content which + * is derived as content is added. + * + * In addition, block_align can be specified. This ensures the resulting + * buffer is at least aligned to the block size and that the total size + * is zero padded to fill a block multiple if necessary. Because the + * emitter operates on a virtual address range before the full buffer is + * aligned, it may have to make assumptions based on that: For example, + * it may be processing encryption blocks in the fly, and the resulting + * buffer should be aligned to the encryption block size, even if the + * content is just a byte aligned struct. Block align helps ensure this. + * If the block align as 1 there will be no attempt to zero pad at the + * end, but the content may still warrant padding after the header. End + * padding is only needed with clustered vtables (which is the default). + * + * `block_align` is allowed to be 0 meaning it will inherit from parent if + * present, and otherwise it defaults to 1. + * + * The identifier may be null, and it may optionally be set later with + * `set_identifier` before the `end_buffer` call. + * + * General note: + * + * Only references returned with this buffer as current (i.e. last + * unended buffer) can be stored in other objects (tables, offset + * vectors) also belonging to this buffer, or used as the root argument + * to `end_buffer`. A reference may be stored at most once, and unused + * references will result in buffer garbage. All calls must be balanced + * around the respective start / end operations, but may otherwise nest + * freely, including nested buffers. Nested buffers are supposed to be + * stored in a table offset field to comply with FlatBuffers, but the + * API does not place any restrictions on where references are stored, + * as long as they are indicated as offset fields. + * + * All alignment in all API calls must be between 1 and 256 and must be a + * power of 2. This is not checked. Only if explicitly documented can it + * also be 0 for a default value. + * + * `flags` can be `with_size` but `is_nested` is derived from context + * see also `create_buffer`. + */ +int flatcc_builder_start_buffer(flatcc_builder_t *B, + const char identifier[FLATBUFFERS_IDENTIFIER_SIZE], + uint16_t block_align, flatcc_builder_buffer_flags_t flags); + +/** + * The root object should be a struct or a table to conform to the + * FlatBuffers format, but technically it can also be a vector or a + * string, or even a child buffer (which is also vector as seen by the + * buffer). The object must be created within the current buffer + * context, that is, while the current buffer is the deepest nested + * buffer on the stack. + */ +flatcc_builder_ref_t flatcc_builder_end_buffer(flatcc_builder_t *B, flatcc_builder_ref_t root); + +/** + * The embed buffer is mostly intended to add an existing buffer as a + * nested buffer. The buffer will be wrapped in a ubyte vector such that + * the buffer is aligned at vector start, after the size field. + * + * If `align` is 0 it will default to 8 so that all FlatBuffer numeric + * types will be readable. NOTE: generally do not count on align 0 being + * valid or even checked by the API, but in this case it may be + * difficult to know the internal buffer alignment, and 1 would be the wrong + * choice. + * + * If `block_align` is set (non-zero), the buffer is placed in an isolated + * block multiple. This may cost up to almost 2 block sizes in padding. + * If the `block_align` argument is 0, it inherits from the parent + * buffer block_size, or defaults to 1. + * + * The `align` argument must be set to respect the buffers internal + * alignment requirements, but if the buffer is smaller it will not be + * padded to isolate the buffer. For example a buffer of with + * `align = 64` and `size = 65` may share its last 64 byte block with + * other content, but not if `block_align = 64`. + * + * Because the ubyte size field is not, by default, part of the aligned + * buffer, significant space can be wasted if multiple blocks are added + * in sequence with a large block size. + * + * In most cases the distinction between the two alignments is not + * important, but it allows separate configuration of block internal + * alignment and block size, which can be important for auto-generated + * code that may know the alignment of the buffer, but not the users + * operational requirements. + * + * If the buffer is embedded without a parent buffer, it will simply + * emit the buffer through the emit interface, but may also add padding + * up to block alignment. At top-level there will be no size field + * header. + * + * If `with_size` flag is set, the buffer is aligned to size field and + * the above note about padding space no longer applies. The size field + * is added regardless. The `is_nested` flag has no effect since it is + * impplied. + */ +flatcc_builder_ref_t flatcc_builder_embed_buffer(flatcc_builder_t *B, + uint16_t block_align, + const void *data, size_t size, uint16_t align, flatcc_builder_buffer_flags_t flags); + +/** + * Applies to the innermost open buffer. The identifier may be null or + * contain all zero. Overrides any identifier given to the start buffer + * call. + */ +void flatcc_builder_set_identifier(flatcc_builder_t *B, + const char identifier[FLATBUFFERS_IDENTIFIER_SIZE]); + +enum flatcc_builder_type { + flatcc_builder_empty = 0, + flatcc_builder_buffer, + flatcc_builder_struct, + flatcc_builder_table, + flatcc_builder_vector, + flatcc_builder_offset_vector, + flatcc_builder_string, + flatcc_builder_union_vector +}; + +/** + * Returns the object type currently on the stack, for example if + * needing to decide how to close a buffer. Because a table is + * automatically added when starting a table buffer, + * `flatcc_builder_table_buffer` should not normally be seen and the level + * should be 2 before when closing a top-level table buffer, and 0 + * after. A `flatcc_builder_struct_buffer` will be visible at level 1. + * + */ +enum flatcc_builder_type flatcc_builder_get_type(flatcc_builder_t *B); + +/** + * Similar to `get_type` but for a specific level. `get_type_at(B, 1)` + * will return `flatcc_builder_table_buffer` if this is the root buffer + * type. get_type_at(B, 0) is always `flatcc_builder_empty` and so are any + * level above `get_level`. + */ +enum flatcc_builder_type flatcc_builder_get_type_at(flatcc_builder_t *B, int level); + +/** + * The user stack is available for custom data. It may be used as + * a simple stack by extending or reducing the inner-most frame. + * + * A frame has a size and a location on the user stack. Entering + * a frame ensures the start is aligned to sizeof(size_t) and + * ensures the requested space is available without reallocation. + * When exiting a frame, the previous frame is restored. + * + * A user frame works completely independently of the builders + * frame stack for tracking tables vectors etc. and does not have + * to be completely at exit, but obviously it is not valid to + * exit more often the entered. + * + * The frame is zeroed when entered. + * + * Returns a non-zero handle to the user frame upon success or + * 0 on allocation failure. + */ +size_t flatcc_builder_enter_user_frame(flatcc_builder_t *B, size_t size); + +/** + * Makes the parent user frame current, if any. It is not valid to call + * if there isn't any current frame. Returns handle to parent frame if + * any, or 0. + */ +size_t flatcc_builder_exit_user_frame(flatcc_builder_t *B); + +/** + * Exits the frame represented by the given handle. All more + * recently entered frames will also be exited. Returns the parent + * frame handle if any, or 0. + */ +size_t flatcc_builder_exit_user_frame_at(flatcc_builder_t *B, size_t handle); + +/** + * Returns a non-zero handle to the current inner-most user frame if + * any, or 0. + */ +size_t flatcc_builder_get_current_user_frame(flatcc_builder_t *B); + +/* + * Returns a pointer to the user frame at the given handle. Any active + * frame can be accessed in this manner but the pointer is invalidated + * by user frame enter and exit operations. + */ +void *flatcc_builder_get_user_frame_ptr(flatcc_builder_t *B, size_t handle); + +/** + * Returns the size of the buffer and the logical start and end address + * of with respect to the emitters address range. `end` - `start` also + * yields the size. During construction `size` is the emitted number of + * bytes and after buffer close it is the actual buffer size - by then + * the start is also the return value of close buffer. End marks the end + * of the virtual table cluster block. + * + * NOTE: there is no guarantee that all vtables end up in the cluster + * block if there is placed a limit on the vtable size, or if nested + * buffers are being used. On the other hand, if these conditions are + * met, it is guaranteed that all vtables are present if the vtable + * block is available (this depends on external transmission - the + * vtables are always emitted before tables using them). In all cases + * the vtables will behave as valid vtables in a flatbuffer. + */ +size_t flatcc_builder_get_buffer_size(flatcc_builder_t *B); + +/** + * Returns the reference to the start of the emitter buffer so far, or + * in total after buffer end, in the virtual address range used + * by the emitter. Start is also returned by buffer end. + */ +flatcc_builder_ref_t flatcc_builder_get_buffer_start(flatcc_builder_t *B); + +/** + * Returns the reference to the end of buffer emitted so far. When + * clustering vtables, this is the end of tables, or after buffer end, + * also zero padding if block aligned. If clustering is disabled, this + * method will return 0 as the buffer only grows down then. + */ +flatcc_builder_ref_t flatcc_builder_get_buffer_mark(flatcc_builder_t *B); + +/** + * Creates the vtable in the current buffer context, somewhat similar to + * how create_vector operates. Each call results in a new table even if + * an identical has already been emitted. + * + * Also consider `create_cached_vtable` which will reuse existing + * vtables. + * + * This is low-low-level function intended to support + * `create_cached_vtable` or equivalent, and `create_table`, both of + * which are normally used indirectly via `start_table`, `table_add`, + * `table_add_offset`..., `table_end`. + * + * Creates a vtable as a verbatim copy. This means the vtable must + * include the header fields containing the vtable size and the table + * size in little endian voffset_t encoding followed by the vtable + * entries in same encoding. + * + * The function may be used to copy vtables from other other buffers + * since they are directly transferable. + * + * The returned reference is actually the emitted location + 1. This + * ensures the vtable is not mistaken for error because 0 is a valid + * vtable reference. `create_table` is aware of this and substracts one + * before computing the final offset relative to the table. This also + * means vtable references are uniquely identifiable by having the + * lowest bit set. + * + * vtable references may be reused within the same buffer, not any + * parent or other related buffer (technically this is possible though, + * as long as it is within same builder context, but it will not construct + * valid FlatBuffers because the buffer cannot be extracted in isolation). + */ +flatcc_builder_vt_ref_t flatcc_builder_create_vtable(flatcc_builder_t *B, + const flatbuffers_voffset_t *vt, + flatbuffers_voffset_t vt_size); + +/** + * Support function to `create_vtable`. See also the uncached version + * `create_vtable`. + * + * Looks up the constructed vtable on the vs stack too see if it matches + * a cached entry. If not, it emits a new vtable either at the end if + * top-level and clustering is enabled, or at the front (always for + * nested buffers). + * + * If the same vtable was already emitted in a different buffer, but not + * in the current buffer, the cache entry will be reused, but a new + * table will be emitted the first it happens in the same table. + * + * The returned reference is + 1 relative to the emitted address range + * to identify it as a vtable and to avoid mistaking the valid 0 + * reference for an error (clustered vtables tend to start at the end at + * the virtual address 0, and up). + * + * The hash function can be chosen arbitrarily but may result in + * duplicate emitted vtables if different hash functions are being used + * concurrently, such as mixing the default used by `start/end table` + * with a custom function (this is not incorrect, it only increases the + * buffer size and cache pressure). + * + * If a vtable has a unique ID by other means than hashing the content, + * such as an integer id, and offset into another buffer, or a pointer, + * a good hash may be multiplication by a 32-bit prime number. The hash + * table is not very sensitive to collissions as it uses externally + * chained hashing with move to front semantics. + */ +flatcc_builder_vt_ref_t flatcc_builder_create_cached_vtable(flatcc_builder_t *B, + const flatbuffers_voffset_t *vt, + flatbuffers_voffset_t vt_size, uint32_t vt_hash); + +/* + * Based on Knuth's prime multiplier. + * + * This is an incremental hash that is called with id and size of each + * non-empty field, and finally with the two vtable header fields + * when vtables are constructed via `table_add/table_add_offset`. + * + */ +#ifndef FLATCC_SLOW_MUL +#ifndef FLATCC_BUILDER_INIT_VT_HASH +#define FLATCC_BUILDER_INIT_VT_HASH(hash) { (hash) = (uint32_t)0x2f693b52UL; } +#endif +#ifndef FLATCC_BUILDER_UPDATE_VT_HASH +#define FLATCC_BUILDER_UPDATE_VT_HASH(hash, id, offset) \ + { (hash) = (((((uint32_t)id ^ (hash)) * (uint32_t)2654435761UL)\ + ^ (uint32_t)(offset)) * (uint32_t)2654435761UL); } +#endif +#ifndef FLATCC_BUILDER_BUCKET_VT_HASH +#define FLATCC_BUILDER_BUCKET_VT_HASH(hash, width) (((uint32_t)(hash)) >> (32 - (width))) +#endif +#endif + +/* + * By default we use Bernsteins hash as fallback if multiplication is slow. + * + * This just have to be simple, fast, and work on devices without fast + * multiplication. We are not too sensitive to collisions. Feel free to + * experiment and replace. + */ +#ifndef FLATCC_BUILDER_INIT_VT_HASH +#define FLATCC_BUILDER_INIT_VT_HASH(hash) { (hash) = 5381; } +#endif +#ifndef FLATCC_BUILDER_UPDATE_VT_HASH +#define FLATCC_BUILDER_UPDATE_VT_HASH(hash, id, offset) \ + { (hash) = ((((hash) << 5) ^ (id)) << 5) ^ (offset); } +#endif +#ifndef FLATCC_BUILDER_BUCKET_VT_HASH +#define FLATCC_BUILDER_BUCKET_VT_HASH(hash, width) (((1 << (width)) - 1) & (hash)) +#endif + + + +/** + * Normally use `start_table` instead of this call. + * + * This is a low-level call only intended for high-performance + * applications that repeatedly churn about similar tables of known + * layout, or as a support layer for other builders that maintain their + * own allocation rather than using the stack of this builder. + * + * Creates a table from an already emitted vtable, actual data that is + * properly aligned relative to data start and in little endian + * encoding. Unlike structs, tables can have offset fields. These must + * be stored as flatcc_builder_ref_t types (which have uoffset_t size) as + * returned by the api in native encoding. The `offsets` table contain + * voffsets relative to `data` start (this is different from how vtables + * store offsets because they are relative to a table header). The + * `offsets` table is only used temporarily to translate the stored + * references and is not part of final buffer content. `offsets` may be + * null if `offset_count` is 0. `align` should be the highest aligned + * field in the table, but `size` need not be a multiple of `align`. + * Aside from endian encoding, the vtable must record a table size equal + * to `size + sizeof(flatbuffers_uoffset_t)` because it includes the + * table header field size. The vtable is not accessed by this call (nor + * is it available). Unlike other references, the vtable reference may + * be shared between tables in the same buffer (not with any related + * buffer such as a parent buffer). + * + * The operation will not use any allocation, but will update the + * alignment of the containing buffer if any. + * + * Note: unlike other create calls, except `create_offset_vector`, + * the source data is modified in order to translate references intok + * offsets before emitting the table. + */ +flatcc_builder_ref_t flatcc_builder_create_table(flatcc_builder_t *B, + const void *data, size_t size, uint16_t align, + flatbuffers_voffset_t *offsets, int offset_count, + flatcc_builder_vt_ref_t vt_ref); + +/** + * Starts a table, typically following a start_buffer call as an + * alternative to starting a struct, or to create table fields to be + * stored in a parent table, or in an offset vector. + * A number of `table_add` and table_add_offset` call may be placed + * before the `end_table` call. Struct fields should NOT use `struct` + * related call (because table structs are in-place), rather they should + * use the `table_add` call with the appropriate size and alignment. + * + * A table, like other reference returning calls, may also be started + * outside a buffer if the buffer header and alignment is of no + * interest to the application, for example as part of an externally + * built buffer. + * + * `count` must be larger than the largest id used for this table + * instance. Normally it is set to the number of fields defined in the + * schema, but it may be less if memory is constrained and only few + * fields with low valued id's are in use. The count can extended later + * with `reserve_table` if necessary. `count` may be also be set to a + * large enough value such as FLATBUFFERS_ID_MAX + 1 if memory is not a + * concern (reserves about twice the maximum vtable size to track the + * current vtable and voffsets where references must be translated to + * offsets at table end). `count` may be zero if for example + * `reserve_table` is being used. + * + * Returns -1 on error, 0 on success. + */ +int flatcc_builder_start_table(flatcc_builder_t *B, int count); + +/** + * Call before adding a field with an id that is not below the count set + * at table start. Not needed in most cases. For performance reasons + * the builder does not check all bounds all the the time, but the user + * can do so if memory constraints prevent start_table from using a + * conservative value. See also `table_start`. + * + * Note: this call has absolutely no effect on the table layout, it just + * prevents internal buffer overruns. + * + * Returns -1 on error, 0 on success. + */ +int flatcc_builder_reserve_table(flatcc_builder_t *B, int count); + +/** + * Completes the table constructed on the internal stack including + * emitting a vtable, or finding a matching vtable that has already been + * emitted to the same buffer. (Vtables cannot be shared between + * buffers, but they can between tables of the same buffer). + * + * Note: there is a considerable, but necessary, amount of bookkeeping + * involved in constructing tables. The `create_table` call is much + * faster, but it also expects a lot of work to be done already. + * + * Tables can be created with no fields added. This will result in an + * empty vtable and a table with just a vtable reference. If a table is + * used as a sub-table, such a table might also not be stored at all, + * but we do not return a special reference for that, nor do we provide + * and option to not create the table in this case. This may be + * interpreted as the difference between a null table (not stored in + * parent), and an empty table with a unique offset (and thus identity) + * different from other empty tables. + */ +flatcc_builder_ref_t flatcc_builder_end_table(flatcc_builder_t *B); + +/** + * Optionally this method can be called just before `flatcc_builder_end_table` + * to verify that all required fields have been set. + * Each entry is a table field id. + * + * Union fields should use the type field when checking for presence and + * may also want to check the soundness of the union field overall using + * `check_union_field` with the id one higher than the type field id. + * + * This funcion is typically called by an assertion in generated builder + * interfaces while release builds may want to avoid this performance + * overhead. + * + * Returns 1 if all fields are matched, 0 otherwise. + */ +int flatcc_builder_check_required(flatcc_builder_t *B, const flatbuffers_voffset_t *required, int count); + +/** + * Same as `check_required` when called with a single element. + * + * Typically used when direct calls are more convenient than building an + * array first. Useful when dealing with untrusted intput such as parsed + * text from an external source. + */ +int flatcc_builder_check_required_field(flatcc_builder_t *B, flatbuffers_voffset_t id); + +/** + * Checks that a union field is valid. + * + * The criteria is: + * + * If the type field is not present (at id - 1), or it holds a zero value, + * then the table field (at id) must be present. + * + * Generated builder code may be able to enforce valid unions without + * this check by setting both type and table together, but e.g. parsers + * may receive the type and the table independently and then it makes + * sense to validate the union fields before table completion. + * + * Note that an absent union field is perfectly valid. If a union is + * required, the type field (id - 1), should be checked separately + * while the table field should only be checked here because it can + * (and must) be absent when the type is NONE (= 0). + */ +int flatcc_builder_check_union_field(flatcc_builder_t *B, flatbuffers_voffset_t id); + +/** + * A struct, enum or scalar added should be stored in little endian in + * the return pointer location. The pointer is short lived and will + * not necessarily survive other builder calls. + * + * A union type field can also be set using this call. In fact, this is + * the only way to deal with unions via this API. Consequently, it is + * the users repsonsibility to ensure the appropriate type is added + * at the next higher id. + * + * Null and default values: + * + * FlatBuffers does not officially provide an option for null values + * because it does not distinguish between default values and values + * that are not present. At this api level, we do not deal with defaults + * at all. Callee should test the stored value against the default value + * and only add the field if it does not match the default. This only + * applies to scalar and enum values. Structs cannot have defaults so + * their absence means null, and strings, vectors and subtables do have + * natural null values different from the empty object and empty objects + * with different identity is also possible. + * + * To handle Null for scalars, the following approach is recommended: + * + * Provide a schema-specific `add` operation that only calls this + * low-level add method if the default does not match, and also provide + * another `set` operation that always stores the value, regardless of + * default. For most readers this will be transparent, except for extra + * space used, but for Null aware readers, these can support operations + * to test for Null/default/other value while still supporting the + * normal read operation that returns default when a value is absent + * (i.e. Null). + * + * It is valid to call with a size of 0 - the effect being adding the + * vtable entry. The call may also be dropped in this case to reduce + * the vtable size - the difference will be in null detection. + */ +void *flatcc_builder_table_add(flatcc_builder_t *B, int id, size_t size, uint16_t align); + +/** + * Returns a pointer to the buffer holding the last field added. The + * size argument must match the field size added. May, for example, be + * used to perform endian conversion after initially updating field + * as a native struct. Must be called before the table is ended. + */ +void *flatcc_builder_table_edit(flatcc_builder_t *B, size_t size); + +/** + * Similar to `table_add` but copies source data into the buffer before + * it is returned. Useful when adding a larger struct already encoded in + * little endian. + */ +void *flatcc_builder_table_add_copy(flatcc_builder_t *B, int id, const void *data, size_t size, uint16_t align); + +/** + * Add a string, vector, or sub-table depending on the type if the + * field identifier. The offset ref obtained when the field object was + * closed should be stored as is in the given pointer. The pointer + * is only valid short term, so create the object before calling + * add to table, but the owner table can be started earlier. Never mix + * refs from nested buffers with parent buffers. + * + * Also uses this method to add nested buffers. A nested buffer is + * simple a buffer created while another buffer is open. The buffer + * close operation provides the necessary reference. + * + * When the table closes, all references get converted into offsets. + * Before that point, it is not required that the offset is written + * to. + */ +flatcc_builder_ref_t *flatcc_builder_table_add_offset(flatcc_builder_t *B, int id); + +/* + * Adds a union type and reference in a single operation and returns 0 + * on success. Stores the type field at `id - 1` and the value at + * `id`. The `value` is a reference to a table, to a string, or to a + * standalone `struct` outside the table. + * + * If the type is 0, the value field must also be 0. + * + * Unions can also be added as separate calls to the type and the offset + * separately which can lead to better packing when the type is placed + * together will other small fields. + */ +int flatcc_builder_table_add_union(flatcc_builder_t *B, int id, + flatcc_builder_union_ref_t uref); + +/* + * Adds a union type vector and value vector in a single operations + * and returns 0 on success. + * + * If both the type and value vector is null, nothing is added. + * Otherwise both must be present and have the same length. + * + * Any 0 entry in the type vector must also have a 0 entry in + * the value vector. + */ +int flatcc_builder_table_add_union_vector(flatcc_builder_t *B, int id, + flatcc_builder_union_vec_ref_t uvref); +/** + * Creates a vector in a single operation using an externally supplied + * buffer. This completely bypasses the stack, but the size must be + * known and the content must be little endian. Do not use for strings + * and offset vectors. Other flatbuffer vectors could be used as a + * source, but the length prefix is not required. + * + * Set `max_count` to `FLATBUFFERS_COUNT_MAX(elem_size)` before a call + * to any string or vector operation to the get maximum safe vector + * size, or use (size_t)-1 if overflow is not a concern. + * + * The max count property is a global property that remains until + * explicitly changed. + * + * `max_count` is to prevent malicous or accidental overflow which is + * difficult to detect by multiplication alone, depending on the type + * sizes being used and having `max_count` thus avoids a division for + * every vector created. `max_count` does not guarantee a vector will + * fit in an empty buffer, it just ensures the internal size checks do + * not overflow. A safe, sane limit woud be max_count / 4 because that + * is half the maximum buffer size that can realistically be + * constructed, corresponding to a vector size of `UOFFSET_MAX / 4` + * which can always hold the vector in 1GB excluding the size field when + * sizeof(uoffset_t) = 4. + */ +flatcc_builder_ref_t flatcc_builder_create_vector(flatcc_builder_t *B, + const void *data, size_t count, size_t elem_size, uint16_t align, size_t max_count); + +/** + * Starts a vector on the stack. + * + * Do not use these calls for string or offset vectors, but do store + * scalars, enums and structs, always in little endian encoding. + * + * Use `extend_vector` subsequently to add zero, one or more elements + * at time. + * + * See `create_vector` for `max_count` argument (strings and offset + * vectors have a fixed element size and does not need this argument). + * + * Returns 0 on success. + */ +int flatcc_builder_start_vector(flatcc_builder_t *B, size_t elem_size, + uint16_t align, size_t max_count); + +/** + * Emits the vector constructed on the stack by start_vector. + * + * The vector may be accessed in the emitted stream using the returned + * reference, even if the containing buffer is still under construction. + * This may be useful for sorting. This api does not support sorting + * because offset vectors cannot read their references after emission, + * and while plain vectors could be sorted, it has been chosen that this + * task is better left as a separate processing step. Generated code can + * provide sorting functions that work on final in-memory buffers. + */ +flatcc_builder_ref_t flatcc_builder_end_vector(flatcc_builder_t *B); + +/** Returns the number of elements currently on the stack. */ +size_t flatcc_builder_vector_count(flatcc_builder_t *B); + +/** + * Returns a pointer ot the first vector element on stack, + * accessible up to the number of elements currently on stack. + */ +void *flatcc_builder_vector_edit(flatcc_builder_t *B); + +/** + * Returns a zero initialized buffer to a new region of the vector which + * is extended at the end. The buffer must be consumed before other api + * calls that may affect the stack, including `extend_vector`. + * + * Do not use for strings, offset or union vectors. May be used for nested + * buffers, but these have dedicated calls to provide better alignment. + */ +void *flatcc_builder_extend_vector(flatcc_builder_t *B, size_t count); + +/** + * A specialized `vector_extend` that pushes a single element. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. Note: for structs, care must be taken to ensure + * the source has been zero padded. For this reason it may be better to + * use extend(B, 1) and assign specific fields instead. + */ +void *flatcc_builder_vector_push(flatcc_builder_t *B, const void *data); + +/** + * Pushes multiple elements at a time. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +void *flatcc_builder_append_vector(flatcc_builder_t *B, const void *data, size_t count); + +/** + * Removes elements already added to vector that has not been ended. + * For example, a vector of parsed list may remove the trailing comma, + * or the vector may simply overallocate to get some temporary working + * space. The total vector size must never become negative. + * + * Returns -1 if the count as larger than current count, or 0 on success. + */ +int flatcc_builder_truncate_vector(flatcc_builder_t *B, size_t count); + +/* + * Similar to `create_vector` but with references that get translated + * into offsets. The references must, as usual, belong to the current + * buffer. Strings, scalar and struct vectors can emit directly without + * stack allocation, but offset vectors must translate the offsets + * and therefore need the temporary space. Thus, this function is + * roughly equivalent to to start, append, end offset vector. + * + * See also `flatcc_builder_create_offset_vector_direct`. + */ +flatcc_builder_ref_t flatcc_builder_create_offset_vector(flatcc_builder_t *B, + const flatcc_builder_ref_t *data, size_t count); + +/* + * NOTE: this call takes non-const source array of references + * and destroys the content. + * + * This is a faster version of `create_offset_vector` where the + * source references are destroyed. In return the vector can be + * emitted directly without passing over the stack. + */ +flatcc_builder_ref_t flatcc_builder_create_offset_vector_direct(flatcc_builder_t *B, + flatcc_builder_ref_t *data, size_t count); + + +/** + * Starts a vector holding offsets to tables or strings. Before + * completion it will hold `flatcc_builder_ref_t` references because the + * offset is not known until the vector start location is known, which + * depends to the final size, which for parsers is generally unknown. + */ +int flatcc_builder_start_offset_vector(flatcc_builder_t *B); + +/** + * Similar to `end_vector` but updates all stored references so they + * become offsets to the vector start. + */ +flatcc_builder_ref_t flatcc_builder_end_offset_vector(flatcc_builder_t *B); + +/** + * Same as `flatcc_builder_end_offset_vector` except null references are + * permitted when the corresponding `type` entry is 0 (the 'NONE' type). + * This makes it possible to build union vectors with less overhead when + * the `type` vector is already known. Use standand offset vector calls + * prior to this call. + */ +flatcc_builder_ref_t flatcc_builder_end_offset_vector_for_unions(flatcc_builder_t *B, + const flatcc_builder_utype_t *type); + +/** Returns the number of elements currently on the stack. */ +size_t flatcc_builder_offset_vector_count(flatcc_builder_t *B); + +/** + * Returns a pointer ot the first vector element on stack, + * accessible up to the number of elements currently on stack. + */ +void *flatcc_builder_offset_vector_edit(flatcc_builder_t *B); + +/** + * Similar to `extend_vector` but returns a buffer indexable as + * `flatcc_builder_ref_t` array. All elements must be set to a valid + * unique non-null reference, but truncate and extend may be used to + * perform edits. Unused references will leave garbage in the buffer. + * References should not originate from any other buffer than the + * current, including parents and nested buffers. It is valid to reuse + * references in DAG form when contained in the sammer, excluding any + * nested, sibling or parent buffers. + */ +flatcc_builder_ref_t *flatcc_builder_extend_offset_vector(flatcc_builder_t *B, size_t count); + +/** Similar to truncate_vector. */ +int flatcc_builder_truncate_offset_vector(flatcc_builder_t *B, size_t count); + +/** + * A specialized extend that pushes a single element. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +flatcc_builder_ref_t *flatcc_builder_offset_vector_push(flatcc_builder_t *B, + flatcc_builder_ref_t ref); + +/** + * Takes an array of refs as argument to do a multi push operation. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +flatcc_builder_ref_t *flatcc_builder_append_offset_vector(flatcc_builder_t *B, + const flatcc_builder_ref_t *refs, size_t count); + +/** + * All union vector operations are like offset vector operations, + * except they take a struct with a type and a reference rather than + * just a reference. The finished union vector is returned as a struct + * of two references, one for the type vector and one for the table offset + * vector. Each reference goes to a separate table field where the type + * offset vector id must be one larger than the type vector. + */ + +/** + * Creates a union vector which is in reality two vectors, a type vector + * and an offset vector. Both vectors references are returned. + */ +flatcc_builder_union_vec_ref_t flatcc_builder_create_union_vector(flatcc_builder_t *B, + const flatcc_builder_union_ref_t *urefs, size_t count); + +/* + * NOTE: this call takes non-const source array of references + * and destroys the content. The type array remains intact. + * + * This is a faster version of `create_union_vector` where the source + * references are destroyed and where the types are given in a separate + * array. In return the vector can be emitted directly without passing + * over the stack. + * + * Unlike `create_offset_vector` we do allow null references but only if + * the union type is NONE (0). + */ +flatcc_builder_union_vec_ref_t flatcc_builder_create_union_vector_direct(flatcc_builder_t *B, + const flatcc_builder_utype_t *types, flatcc_builder_ref_t *data, size_t count); + +/* + * Creates just the type vector part of a union vector. This is + * similar to a normal `create_vector` call except that the size + * and alignment are given implicitly. Can be used during + * cloning or similar operations where the types are all given + * but the values must be handled one by one as prescribed by + * the type. The values can be added separately as an offset vector. + */ +flatcc_builder_ref_t flatcc_builder_create_type_vector(flatcc_builder_t *B, + const flatcc_builder_utype_t *types, size_t count); + +/** + * Starts a vector holding types and offsets to tables or strings. Before + * completion it will hold `flatcc_builder_union_ref_t` references because the + * offset is not known until the vector start location is known, which + * depends to the final size, which for parsers is generally unknown, + * and also because the union type must be separated out into a separate + * vector. It would not be practicaly to push on two different vectors + * during construction. + */ +int flatcc_builder_start_union_vector(flatcc_builder_t *B); + +/** + * Similar to `end_vector` but updates all stored references so they + * become offsets to the vector start and splits the union references + * into a type vector and an offset vector. + */ +flatcc_builder_union_vec_ref_t flatcc_builder_end_union_vector(flatcc_builder_t *B); + +/** Returns the number of elements currently on the stack. */ +size_t flatcc_builder_union_vector_count(flatcc_builder_t *B); + +/** + * Returns a pointer ot the first vector element on stack, + * accessible up to the number of elements currently on stack. + */ +void *flatcc_builder_union_vector_edit(flatcc_builder_t *B); + +/** + * Similar to `extend_offset_vector` but returns a buffer indexable as a + * `flatcc_builder_union_ref_t` array. All elements must be set to a valid + * unique non-null reference with a valid union type to match, or it + * must be null with a zero union type. + */ +flatcc_builder_union_ref_t *flatcc_builder_extend_union_vector(flatcc_builder_t *B, size_t count); + +/** Similar to truncate_vector. */ +int flatcc_builder_truncate_union_vector(flatcc_builder_t *B, size_t count); + +/** + * A specialized extend that pushes a single element. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +flatcc_builder_union_ref_t *flatcc_builder_union_vector_push(flatcc_builder_t *B, + flatcc_builder_union_ref_t uref); + +/** + * Takes an array of union_refs as argument to do a multi push operation. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +flatcc_builder_union_ref_t *flatcc_builder_append_union_vector(flatcc_builder_t *B, + const flatcc_builder_union_ref_t *urefs, size_t count); + +/** + * Faster string operation that avoids temporary stack storage. The + * string is not required to be zero-terminated, but is expected + * (unchecked) to be utf-8. Embedded zeroes would be allowed but + * ubyte vectors should be used for that. The resulting string will + * have a zero termination added, not included in length. + */ +flatcc_builder_ref_t flatcc_builder_create_string(flatcc_builder_t *B, + const char *s, size_t len); + +/** `create_string` up to zero termination of source. */ +flatcc_builder_ref_t flatcc_builder_create_string_str(flatcc_builder_t *B, + const char *s); + +/** + * `create_string` up to zero termination or at most max_len of source. + * + * Note that like `strncpy` it will include `max_len` characters if + * the source is longer than `max_len`, but unlike `strncpy` it will + * always add zero termination. + */ +flatcc_builder_ref_t flatcc_builder_create_string_strn(flatcc_builder_t *B, const char *s, size_t max_len); + +/** + * Starts an empty string that can be extended subsequently. + * + * While the string is being created, it is guaranteed that there is + * always a null character after the end of the current string length. + * This also holds after `extend` and `append` operations. It is not + * allowed to modify the null character. + * + * Returns 0 on success. + */ +int flatcc_builder_start_string(flatcc_builder_t *B); + +/** + * Similar to `extend_vector` except for the buffer return type and a + * slight speed advantage. Strings are expected to contain utf-8 content + * but this isn't verified, and null characters would be accepted. The + * length is given in bytes. + * + * Appending too much, then truncating can be used to trim string + * escapes during parsing, or convert between unicode formats etc. + */ +char *flatcc_builder_extend_string(flatcc_builder_t *B, size_t len); + +/** + * Concatenes a length of string. If the string contains zeroes (which + * it formally shouldn't), they will be copied in. + * + * Returns the buffer holding a modifiable copy of the added content, + * or null on error. + */ +char *flatcc_builder_append_string(flatcc_builder_t *B, const char *s, size_t len); + +/** `append_string` up to zero termination of source. */ +char *flatcc_builder_append_string_str(flatcc_builder_t *B, const char *s); + +/** `append_string` up zero termination or at most max_len of source. */ +char *flatcc_builder_append_string_strn(flatcc_builder_t *B, const char *s, size_t max_len); + +/** + * Similar to `truncate_vector` available for consistency and a slight + * speed advantage. Reduces string by `len` bytes - it does not set + * the length. The resulting length must not become negative. Zero + * termination is not counted. + * + * Returns -1 of the length becomes negative, 0 on success. + */ +int flatcc_builder_truncate_string(flatcc_builder_t *B, size_t len); + +/** + * Similar to `end_vector` but adds a trailing zero not included + * in the length. The trailing zero is added regardless of whatever + * zero content may exist in the provided string (although it + * formally should not contain any). + */ +flatcc_builder_ref_t flatcc_builder_end_string(flatcc_builder_t *B); + +/** Returns the length of string currently on the stack. */ +size_t flatcc_builder_string_len(flatcc_builder_t *B); + +/** + * Returns a ponter to the start of the string + * accessible up the length of string currently on the stack. + */ +char *flatcc_builder_string_edit(flatcc_builder_t *B); + + +/* + * Only for use with the default emitter. + * + * Fast acces to small buffers from default emitter. + * + * Only valid for default emitters before `flatcc_builder_clear`. The + * return buffer is not valid after a call to `flatcc_builder_reset` or + * `flatcc_builder_clear`. + * + * Returns null if the buffer size is too large to a have a linear + * memory representation or if the emitter is not the default. A valid + * size is between half and a full emitter page size depending on vtable + * content. + * + * Non-default emitters must be accessed by means specific to the + * particular emitter. + * + * If `size_out` is not null, it is set to the buffer size, or 0 if + * operation failed. + * + * The returned buffer should NOT be deallocated explicitly. + * + * The buffer size is the size reported by `flatcc_builder_get_buffer_size`. + */ +void *flatcc_builder_get_direct_buffer(flatcc_builder_t *B, size_t *size_out); + +/* + * Only for use with the default emitter. + * + * Default finalizer that allocates a buffer from the default emitter. + * + * Returns null if memory could not be allocated or if the emitter is + * not the default. This is just a convenience method - there are many + * other possible ways to extract the result of the emitter depending on + * use case. + * + * If `size_out` is not null, it is set to the buffer size, or 0 if + * operation failed. + * + * The allocated buffer is aligned according to malloc which may not be + * sufficient in advanced cases - for that purpose + * `flatcc_builder_finalize_aligned_buffer` may be used. + * + * It may be worth calling `flatcc_builder_get_direct_buffer` first to see + * if the buffer is small enough to avoid copying. + * + * The returned buffer must be deallocated using `free`. + */ +void *flatcc_builder_finalize_buffer(flatcc_builder_t *B, size_t *size_out); + +/* + * Only for use with the default emitter. + * + * Similar to `flatcc_builder_finalize_buffer` but ensures the returned + * memory is aligned to the overall alignment required for the buffer. + * Often it is not necessary unless special operations rely on larger + * alignments than the stored scalars. + * + * If `size_out` is not null, it is set to the buffer size, or 0 if + * operation failed. + * + * The returned buffer must be deallocated using `aligned_free` which is + * implemented via `flatcc_flatbuffers.h`. `free` will usually work but + * is not portable to platforms without posix_memalign or C11 + * aligned_alloc support. + * + * NOTE: if a library might be compiled with a version of aligned_free + * that differs from the application using it, use + * `flatcc_builder_aligned_free` to make sure the correct deallocation + * function is used. + */ +void *flatcc_builder_finalize_aligned_buffer(flatcc_builder_t *B, size_t *size_out); + +/* + * A stable implementation of `aligned_alloc` that is not sensitive + * to the applications compile time flags. + */ +void *flatcc_builder_aligned_alloc(size_t alignment, size_t size); + +/* + * A stable implementation of `aligned_free` that is not sensitive + * to the applications compile time flags. + */ +void flatcc_builder_aligned_free(void *p); + +/* + * Same allocation as `flatcc_builder_finalize_buffer` returnes. Usually + * same as `malloc` but can redefined via macros. + */ +void *flatcc_builder_alloc(size_t size); + +/* + * A stable implementation of `free` when the default allocation + * methods have been redefined. + * + * Deallocates memory returned from `flatcc_builder_finalize_buffer`. + */ +void flatcc_builder_free(void *p); + +/* + * Only for use with the default emitter. + * + * Convenience method to copy buffer from default emitter. Forwards + * call to default emitter and returns input pointer, or null if + * the emitter is not default or of the given size is smaller than + * the buffer size. + * + * Note: the `size` argument is the target buffers capacity, not the + * flatcc_builders buffer size. + * + * Other emitters have custom interfaces for reaching their content. + */ +void *flatcc_builder_copy_buffer(flatcc_builder_t *B, void *buffer, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_BUILDER_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_emitter.h b/third_party/nanoarrow/include/flatcc/flatcc_emitter.h new file mode 100644 index 0000000..b8c83b9 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_emitter.h @@ -0,0 +1,215 @@ +#ifndef FLATCC_EMITTER_H +#define FLATCC_EMITTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Default implementation of a flatbuilder emitter. + * + * This may be used as a starting point for more advanced emitters, + * for example writing completed pages to disk or network and + * the recycling those pages. + */ + +#include +#include + +#include "flatcc/flatcc_types.h" +#include "flatcc/flatcc_iov.h" +#include "flatcc/flatcc_alloc.h" + +/* + * The buffer steadily grows during emission but the design allows for + * an extension where individual pages can recycled before the buffer + * is complete, for example because they have been transmitted. + * + * When done, the buffer can be cleared to free all memory, or reset to + * maintain an adaptive page pool for next buffer construction. + * + * Unlike an exponentially growing buffer, each buffer page remains + * stable in memory until reset, clear or recycle is called. + * + * Design notes for possible extensions: + * + * The buffer is a ring buffer marked by a front and a back page. The + * front and back may be the same page and may initially be absent. + * Anything outside these pages are unallocated pages for recycling. + * Any page between (but excluding) the front and back pages may be + * recycled by unlinking and relinking outside the front and back pages + * but then copy operations no longer makes sense. Each page stores the + * logical offset within the buffer but isn't otherwise used by the + * implemention - it might be used for network transmission. The buffer + * is not explicitly designed for multithreaded access but any page + * strictly between front and back is not touched unless recycled and in + * this case aligned allocation is useful to prevent cache line sharing. + */ + +/* + * Memory is allocated in fixed length page units - the first page is + * split between front and back so each get half the page size. If the + * size is a multiple of 128 then each page offset will be a multiple of + * 64, which may be useful for sequencing etc. + */ +#ifndef FLATCC_EMITTER_PAGE_SIZE +#define FLATCC_EMITTER_MAX_PAGE_SIZE 3000 +#define FLATCC_EMITTER_PAGE_MULTIPLE 64 +#define FLATCC_EMITTER_PAGE_SIZE ((FLATCC_EMITTER_MAX_PAGE_SIZE) &\ + ~(2 * (FLATCC_EMITTER_PAGE_MULTIPLE) - 1)) +#endif + +#ifndef FLATCC_EMITTER_ALLOC +#ifdef FLATCC_EMITTER_USE_ALIGNED_ALLOC +/* + * does not always provide aligned_alloc, so include whatever + * is required when enabling this feature. + */ +#define FLATCC_EMITTER_ALLOC(n) aligned_alloc(FLATCC_EMITTER_PAGE_MULTIPLE,\ + (((n) + FLATCC_EMITTER_PAGE_MULTIPLE - 1) & ~(FLATCC_EMITTER_PAGE_MULTIPLE - 1))) +#ifndef FLATCC_EMITTER_FREE +#define FLATCC_EMITTER_FREE(p) aligned_free(p) +#endif +#endif +#endif + +#ifndef FLATCC_EMITTER_ALLOC +#define FLATCC_EMITTER_ALLOC(n) FLATCC_ALLOC(n) +#endif +#ifndef FLATCC_EMITTER_FREE +#define FLATCC_EMITTER_FREE(p) FLATCC_FREE(p) +#endif + +typedef struct flatcc_emitter_page flatcc_emitter_page_t; +typedef struct flatcc_emitter flatcc_emitter_t; + +struct flatcc_emitter_page { + uint8_t page[FLATCC_EMITTER_PAGE_SIZE]; + flatcc_emitter_page_t *next; + flatcc_emitter_page_t *prev; + /* + * The offset is relative to page start, but not necessarily + * to any present content if part of front or back page, + * and undefined for unused pages. + */ + flatbuffers_soffset_t page_offset; +}; + +/* + * Must be allocated and zeroed externally, e.g. on the stack + * then provided as emit_context to the flatbuilder along + * with the `flatcc_emitter` function. + */ +struct flatcc_emitter { + flatcc_emitter_page_t *front, *back; + uint8_t *front_cursor; + size_t front_left; + uint8_t *back_cursor; + size_t back_left; + size_t used; + size_t capacity; + size_t used_average; +}; + +/* Optional helper to ensure emitter is zeroed initially. */ +static inline void flatcc_emitter_init(flatcc_emitter_t *E) +{ + memset(E, 0, sizeof(*E)); +} + +/* Deallocates all buffer memory making the emitter ready for next use. */ +void flatcc_emitter_clear(flatcc_emitter_t *E); + +/* + * Similar to `clear_flatcc_emitter` but heuristacally keeps some allocated + * memory between uses while gradually reducing peak allocations. + * For small buffers, a single page will remain available with no + * additional allocations or deallocations after first use. + */ +void flatcc_emitter_reset(flatcc_emitter_t *E); + +/* + * Helper function that allows a page between front and back to be + * recycled while the buffer is still being constructed - most likely as part + * of partial copy or transmission. Attempting to recycle front or back + * pages will result in an error. Recycling pages outside the + * front and back will be valid but pointless. After recycling and copy + * operations are no longer well-defined and should be replaced with + * whatever logic is recycling the pages. The reset operation + * automatically recycles all (remaining) pages when emission is + * complete. After recycling, the `flatcc_emitter_size` function will + * return as if recycle was not called, but will only represent the + * logical size, not the size of the active buffer. Because a recycled + * page is fully utilized, it is fairly easy to compensate for this if + * required. + * + * Returns 0 on success. + */ +int flatcc_emitter_recycle_page(flatcc_emitter_t *E, flatcc_emitter_page_t *p); + +/* + * The amount of data copied with `flatcc_emitter_copy_buffer` and related + * functions. Normally called at end of buffer construction but is + * always valid, as is the copy functions. The size is a direct + * function of the amount emitted data so the flatbuilder itself can + * also provide this information. + */ +static inline size_t flatcc_emitter_get_buffer_size(flatcc_emitter_t *E) +{ + return E->used; +} + +/* + * Returns buffer start iff the buffer fits on a single internal page. + * Only useful for fairly small buffers - about half the page size since + * one half of first page goes to vtables that likely use little space. + * Returns null if request could not be served. + * + * If `size_out` is not null, it is set to the buffer size, or 0 if + * operation failed. + */ +static inline void *flatcc_emitter_get_direct_buffer(flatcc_emitter_t *E, size_t *size_out) +{ + if (E->front == E->back) { + if (size_out) { + *size_out = E->used; + } + return E->front_cursor; + } + if (size_out) { + *size_out = 0; + } + return 0; +} + +/* + * Copies the internal flatcc_emitter representation to an externally + * provided linear buffer that must have size `flatcc_emitter_get_size`. + * + * If pages have been recycled, only the remaining pages will be copied + * and thus less data than what `flatcc_emitter_get_size` would suggest. It + * makes more sense to provide a customized copy operation when + * recycling pages. + * + * If the buffer is too small, nothing is copied, otherwise the + * full buffer is copied and the input buffer is returned. + */ +void *flatcc_emitter_copy_buffer(flatcc_emitter_t *E, void *buf, size_t size); + +/* + * The emitter interface function to the flatbuilder API. + * `emit_context` should be of type `flatcc_emitter_t` for this + * particular implementation. + * + * This function is compatible with the `flatbuilder_emit_fun` + * type defined in "flatbuilder.h". + */ +int flatcc_emitter(void *emit_context, + const flatcc_iovec_t *iov, int iov_count, + flatbuffers_soffset_t offset, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_EMITTER_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_endian.h b/third_party/nanoarrow/include/flatcc/flatcc_endian.h new file mode 100644 index 0000000..0592f31 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_endian.h @@ -0,0 +1,125 @@ +#ifndef FLATCC_ENDIAN_H +#define FLATCC_ENDIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This file provides helper macros to define type-specific macros and + * inline functions that convert between stored data and native data + * indedpently of both native (host) endianness and protocol endianness + * (i.e. the serialized endian format). + * + * To detect endianness correctly ensure one of the following is defined. + * + * __LITTLE_ENDIAN__ + * __BIG_ENDIAN__ + * FLATBUFFERS_LITTLEENDIAN=1 + * FLATBUFFERS_LITTLEENDIAN=0 + * + * Note: the Clang compiler likely already does this, but other + * compilers may have their own way, if at all. + * + * It is also necessary to include or a compatible + * implementation in order to provide: + * + * le16toh, le32to, le64toh, be16toh, be32toh, be64toh, + * htole16, htole32, htole64, htobe16, htobe32, htobe64. + * + * A simple way to ensure all of the above for most platforms is + * to include the portable endian support file: + * + * #include "flatcc/portable/pendian.h" + * + * It is also necessary to include + * + * #include "flatcc/flatcc_types.h" + * + * or an equivalent file. This makes it possible to change the + * endianness of the serialized data and the sizes of flatbuffer + * specific types such as `uoffset_t`. + * + * Note: the mentioned include files are likely already included + * by the file including this file, at least for the default + * configuration. + */ + +#ifndef UINT8_t +#include +#endif + +/* These are needed to simplify accessor macros and are not found in . */ +#ifndef le8toh +#define le8toh(n) (n) +#endif + +#ifndef be8toh +#define be8toh(n) (n) +#endif + +#ifndef htole8 +#define htole8(n) (n) +#endif + +#ifndef htobe8 +#define htobe8(n) (n) +#endif + +#include "flatcc/flatcc_accessors.h" + +/* This is the binary encoding endianness, usually LE for flatbuffers. */ +#if FLATBUFFERS_PROTOCOL_IS_LE +#define flatbuffers_endian le +#elif FLATBUFFERS_PROTOCOL_IS_BE +#define flatbuffers_endian be +#else +#error "flatbuffers has no defined endiannesss" +#endif + + __flatcc_define_basic_scalar_accessors(flatbuffers_, flatbuffers_endian) + + __flatcc_define_integer_accessors(flatbuffers_bool, flatbuffers_bool_t, + FLATBUFFERS_BOOL_WIDTH, flatbuffers_endian) + __flatcc_define_integer_accessors(flatbuffers_union_type, flatbuffers_union_type_t, + FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian) + + __flatcc_define_integer_accessors(__flatbuffers_uoffset, flatbuffers_uoffset_t, + FLATBUFFERS_UOFFSET_WIDTH, flatbuffers_endian) + __flatcc_define_integer_accessors(__flatbuffers_soffset, flatbuffers_soffset_t, + FLATBUFFERS_SOFFSET_WIDTH, flatbuffers_endian) + __flatcc_define_integer_accessors(__flatbuffers_voffset, flatbuffers_voffset_t, + FLATBUFFERS_VOFFSET_WIDTH, flatbuffers_endian) + __flatcc_define_integer_accessors(__flatbuffers_utype, flatbuffers_utype_t, + FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian) + __flatcc_define_integer_accessors(__flatbuffers_thash, flatbuffers_thash_t, + FLATBUFFERS_THASH_WIDTH, flatbuffers_endian) + +/* flatcc/portable/pendian.h sets LITTLE/BIG flags if possible, and always defines le16toh. */ +#ifndef flatbuffers_is_native_pe +#if defined(__LITTLE_ENDIAN__) || FLATBUFFERS_LITTLEENDIAN +#undef FLATBUFFERS_LITTLEENDIAN +#define FLATBUFFERS_LITTLEENDIAN 1 +#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_LE) +#elif defined(__BIG_ENDIAN__) || (defined(FLATBUFFERS_LITTLEENDIAN) && !FLATBUFFERS_LITTLEENDIAN) +#undef FLATBUFFERS_LITTLEENDIAN +#define FLATBUFFERS_LITTLEENDIAN 0 +#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_BE) +#else +#define flatbuffers_is_native_pe() (__FLATBUFFERS_CONCAT(flatbuffers_endian, 16toh)(1) == 1) +#endif +#endif + +#ifndef flatbuffers_is_native_le +#define flatbuffers_is_native_le() flatbuffers_is_native_pe() +#endif + +#ifndef flatbuffers_is_native_be +#define flatbuffers_is_native_be() (!flatbuffers_is_native_pe()) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_ENDIAN_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_epilogue.h b/third_party/nanoarrow/include/flatcc/flatcc_epilogue.h new file mode 100644 index 0000000..e43114d --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_epilogue.h @@ -0,0 +1,7 @@ +/* Include guard intentionally left out. */ + +#ifdef __cplusplus +} +#endif + +#include "flatcc/portable/pdiagnostic_pop.h" diff --git a/third_party/nanoarrow/include/flatcc/flatcc_flatbuffers.h b/third_party/nanoarrow/include/flatcc/flatcc_flatbuffers.h new file mode 100644 index 0000000..6b17583 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_flatbuffers.h @@ -0,0 +1,57 @@ +/* + * Even C11 compilers depend on clib support for `static_assert` which + * isn't always present, so we deal with this here for all compilers. + * + * Outside include guard to handle scope counter. + */ +#include "flatcc/portable/pstatic_assert.h" + +#ifndef FLATCC_FLATBUFFERS_H +#define FLATCC_FLATBUFFERS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef flatcc_flatbuffers_defined +#define flatcc_flatbuffers_defined + +#ifdef FLATCC_PORTABLE +#include "flatcc/flatcc_portable.h" +#endif +#include "flatcc/portable/pwarnings.h" +/* Needed by C99 compilers without FLATCC_PORTABLE. */ +#include "flatcc/portable/pstdalign.h" + +/* Handle fallthrough attribute in switch statements. */ +#include "flatcc/portable/pattributes.h" + +#include "flatcc/flatcc_alloc.h" +#include "flatcc/flatcc_assert.h" + +#define __FLATBUFFERS_PASTE2(a, b) a ## b +#define __FLATBUFFERS_PASTE3(a, b, c) a ## b ## c +#define __FLATBUFFERS_CONCAT(a, b) __FLATBUFFERS_PASTE2(a, b) + +/* + * "flatcc_endian.h" requires the preceeding include files, + * or compatible definitions. + */ +#include "flatcc/portable/pendian.h" +/* Needed by flatcc_accessors.h to handle strict aliasing rules. */ +#include "flatcc/portable/pmemaccess.h" +#include "flatcc/flatcc_types.h" +#include "flatcc/flatcc_endian.h" +#include "flatcc/flatcc_identifier.h" + +#ifndef FLATBUFFERS_WRAP_NAMESPACE +#define FLATBUFFERS_WRAP_NAMESPACE(ns, x) ns ## _ ## x +#endif + +#endif /* flatcc_flatbuffers_defined */ + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_FLATBUFFERS_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_identifier.h b/third_party/nanoarrow/include/flatcc/flatcc_identifier.h new file mode 100644 index 0000000..825f0fd --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_identifier.h @@ -0,0 +1,148 @@ +#ifndef FLATCC_IDENTIFIER_H +#define FLATCC_IDENTIFIER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef FLATCC_FLATBUFFERS_H +#error "include via flatcc/flatcc_flatbuffers.h" +#endif + +#ifndef UINT8_MAX +#include +#endif + +/* + * FlatBuffers identifiers are normally specified by "file_identifer" in + * the schema, but a standard hash of the fully qualified type name can + * also be used. This file implements such a mapping, but the generated + * headers also contain the necessary information for known types. + */ + + +/* + * Returns the type hash of a given name in native endian format. + * Generated code already provides these, but if a name was changed + * in the schema it may be relevant to recompute the hash manually. + * + * The wire-format of this value should always be little endian. + * + * Note: this must be the fully qualified name, e.g. in the namespace + * "MyGame.Example": + * + * flatbuffers_type_hash_from_name("MyGame.Example.Monster"); + * + * or, in the global namespace just: + * + * flatbuffers_type_hash_from_name("MyTable"); + * + * This assumes 32 bit hash type. For other sizes, other FNV-1a + * constants would be required. + * + * Note that we reserve hash value 0 for missing or ignored value. + */ +static inline flatbuffers_thash_t flatbuffers_type_hash_from_name(const char *name) +{ + uint32_t hash = UINT32_C(2166136261); + while (*name) { + hash ^= (unsigned char)*name; + hash = hash * UINT32_C(16777619); + ++name; + } + if (hash == 0) { + hash = UINT32_C(2166136261); + } + return hash; +} + +/* + * Type hash encoded as little endian file identifier string. + * Note: if type hash is 0, the identifier should be null which + * we cannot return in this interface. + */ +static inline void flatbuffers_identifier_from_type_hash(flatbuffers_thash_t type_hash, flatbuffers_fid_t out_identifier) +{ + out_identifier[0] = (char)(type_hash & 0xff); + type_hash >>= 8; + out_identifier[1] = (char)(type_hash & 0xff); + type_hash >>= 8; + out_identifier[2] = (char)(type_hash & 0xff); + type_hash >>= 8; + out_identifier[3] = (char)(type_hash & 0xff); +} + +/* Native integer encoding of file identifier. */ +static inline flatbuffers_thash_t flatbuffers_type_hash_from_identifier(const flatbuffers_fid_t identifier) +{ + uint8_t *p = (uint8_t *)identifier; + + return identifier ? + (uint32_t)p[0] + (((uint32_t)p[1]) << 8) + (((uint32_t)p[2]) << 16) + (((uint32_t)p[3]) << 24) : 0; +} + +/* + * Convert a null terminated string identifier like "MONS" or "X" into a + * native type hash identifier, usually for comparison. This will not + * work with type hash strings because they can contain null bytes. + */ +static inline flatbuffers_thash_t flatbuffers_type_hash_from_string(const char *identifier) +{ + flatbuffers_thash_t h = 0; + const uint8_t *p = (const uint8_t *)identifier; + + if (!p[0]) return h; + h += ((flatbuffers_thash_t)p[0]); + if (!p[1]) return h; + h += ((flatbuffers_thash_t)p[1]) << 8; + if (!p[2]) return h; + h += ((flatbuffers_thash_t)p[2]) << 16; + /* No need to test for termination here. */ + h += ((flatbuffers_thash_t)p[3]) << 24; + return h; +} + +/* + * Computes the little endian wire format of the type hash. It can be + * used as a file identifer argument to various flatcc buffer calls. + * + * `flatbuffers_fid_t` is just `char [4]` for the default flatbuffers + * type system defined in `flatcc/flatcc_types.h`. + */ +static inline void flatbuffers_identifier_from_name(const char *name, flatbuffers_fid_t out_identifier) +{ + flatbuffers_identifier_from_type_hash(flatbuffers_type_hash_from_name(name), out_identifier); +} + +/* + * This is a collision free hash (a permutation) of the type hash to + * provide better distribution for use in hash tables. It is likely not + * necessary in praxis, and for uniqueness of identifiers it provides no + * advantage over just using the FNV-1a type hash, except when truncating + * the identifier to less than 32-bits. + * + * Note: the output should not be used in transmission. It provides no + * additional information and just complicates matters. Furthermore, the + * unmodified type hash has the benefit that it can seed a child namespace. + */ +static inline uint32_t flatbuffers_disperse_type_hash(flatbuffers_thash_t type_hash) +{ + /* http://stackoverflow.com/a/12996028 */ + uint32_t x = type_hash; + + x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); + x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); + x = ((x >> 16) ^ x); + return x; +} + + +/* We have hardcoded assumptions about identifier size. */ +static_assert(sizeof(flatbuffers_fid_t) == 4, "unexpected file identifier size"); +static_assert(sizeof(flatbuffers_thash_t) == 4, "unexpected type hash size"); + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_IDENTIFIER_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_iov.h b/third_party/nanoarrow/include/flatcc/flatcc_iov.h new file mode 100644 index 0000000..a6d27f8 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_iov.h @@ -0,0 +1,31 @@ +#ifndef FLATCC_IOV_H +#define FLATCC_IOV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * The emitter receives one, or a few buffers at a time via + * this type. compatible iovec structure used for + * allocation and emitter interface. + */ +typedef struct flatcc_iovec flatcc_iovec_t; +struct flatcc_iovec { + void *iov_base; + size_t iov_len; +}; + +/* + * The largest iovec vector the builder will issue. It will + * always be a relatively small number. + */ +#define FLATCC_IOV_COUNT_MAX 8 + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_IOV_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_portable.h b/third_party/nanoarrow/include/flatcc/flatcc_portable.h new file mode 100644 index 0000000..9b0eb0c --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_portable.h @@ -0,0 +1,14 @@ +#ifndef FLATCC_PORTABLE_H +#define FLATCC_PORTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "flatcc/portable/portable_basic.h" + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_PORTABLE_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_prologue.h b/third_party/nanoarrow/include/flatcc/flatcc_prologue.h new file mode 100644 index 0000000..3a74ed6 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_prologue.h @@ -0,0 +1,8 @@ +/* Include guard intentionally left out. */ + +#define PDIAGNOSTIC_IGNORE_UNUSED +#include "flatcc/portable/pdiagnostic_push.h" + +#ifdef __cplusplus +extern "C" { +#endif diff --git a/third_party/nanoarrow/include/flatcc/flatcc_refmap.h b/third_party/nanoarrow/include/flatcc/flatcc_refmap.h new file mode 100644 index 0000000..062d94f --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_refmap.h @@ -0,0 +1,144 @@ +/* + * The flatcc builder supports storing a pointer to a refmap + * and wraps some operations to make them work as a dummy + * even if no refmap has been set. This enables optional + * DAG preservation possible during clone operations. + * + * A refmap maps a source address to a builder reference. + * + * This is just a map, but the semantics are important: + * + * The map thus preserves identity of the source. It is not a + * cache because cache eviction would fail to properly track + * identity. + * + * The map is used for memoization during object cloning are and + * may also be used by user logic doing similar operations. + * This ensures that identity is preserved so a source object is + * not duplicated which could lead to either loss of semantic + * information, or an explosion in size, or both. In some, or + * even most, cases this concern may not be important, but when + * it is important, it is important. + * + * The source address must not be reused for different content + * for the lifetime of the map, although the content doest not + * have to be valid or event exist at that location since source + * address is just used as a key. + * + * The lifetime may be a single clone operation which then + * tracks child object references as well, or it may be the + * lifetime of the buffer builder. + * + * The map may be flushed explicitly when the source addresses + * are no longer unique, such as when reusing a memory buffer, + * and when identity preservation is no longer important. + * Flushing a map is esentially the same as ending a lifetime. + * + * Multiple maps may exist concurrently for example if cloning + * an object twice into two new objects that should have + * separate identities. This is especially true and necessary + * when creating a new nested buffer because the nested buffer + * cannot share references with the parent. Cloning and object + * that contains a nested buffer does not require multiple maps + * because the nested buffer is then opaque. + */ + +#ifndef FLATCC_REFMAP_H +#define FLATCC_REFMAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "flatcc/flatcc_types.h" + +#ifndef FLATCC_REFMAP_MIN_BUCKETS +/* 8 buckets gives us 5 useful initial entries with a load factor of 0.7 */ +#define FLATCC_REFMAP_MIN_BUCKETS 8 +#endif + +#define FLATCC_REFMAP_LOAD_FACTOR 0.7f + +typedef struct flatcc_refmap flatcc_refmap_t; +typedef flatbuffers_soffset_t flatcc_refmap_ref_t; + +static const flatcc_refmap_ref_t flatcc_refmap_not_found = 0; + +struct flatcc_refmap_item { + const void *src; + flatcc_refmap_ref_t ref; +}; + +struct flatcc_refmap { + size_t count; + size_t buckets; + struct flatcc_refmap_item *table; + /* Use stack allocation for small maps. */ + struct flatcc_refmap_item min_table[FLATCC_REFMAP_MIN_BUCKETS]; +}; + +/* + * Fast zero initialization - does not allocate any memory. + * May be replaced by memset 0, but `init` avoids clearing the + * stack allocated initial hash table until it is needed. + */ +static inline int flatcc_refmap_init(flatcc_refmap_t *refmap) +{ + refmap->count = 0; + refmap->buckets = 0; + refmap->table = 0; + return 0; +} + +/* + * Removes all items and deallocates memory. + * Not required unless `insert` or `resize` took place. The map can be + * reused subsequently without calling `init`. + */ +void flatcc_refmap_clear(flatcc_refmap_t *refmap); + +/* + * Keeps allocated memory as is, but removes all items. The map + * must intialized first. + */ +void flatcc_refmap_reset(flatcc_refmap_t *refmap); + +/* + * Returns the inserted reference if the `src` pointer was found, + * without inspecting the content of the `src` pointer. + * + * Returns flatcc_refmap_not_found (default 0) if the `src` pointer was + * not found. + */ +flatcc_refmap_ref_t flatcc_refmap_find(flatcc_refmap_t *refmap, const void *src); + +/* + * Inserts a `src` source pointer and its associated `ref` reference + * into the refmap without inspecting the `src` pointer content. The + * `ref` value will be replaced if the the `src` pointer already exists. + * + * Inserting null will just return the ref without updating the map. + * + * There is no delete operation which simplifies an open + * addressing hash table, and it isn't needed for this use case. + * + * Returns the input ref or not_found on allocation error. + */ +flatcc_refmap_ref_t flatcc_refmap_insert(flatcc_refmap_t *refmap, const void *src, flatcc_refmap_ref_t ref); + +/* + * Set the hash table to accommodate at least `count` items while staying + * within the predefined load factor. + * + * Resize is primarily an internal operation, but the user may resize + * ahead of a large anticipated load, or after a large load to shrink + * the table using 0 as the `count` argument. The table never shrinks + * on its own account. + */ +int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_REFMAP_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_rtconfig.h b/third_party/nanoarrow/include/flatcc/flatcc_rtconfig.h new file mode 100644 index 0000000..32b80da --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_rtconfig.h @@ -0,0 +1,171 @@ +#ifndef FLATCC_RTCONFIG_H +#define FLATCC_RTCONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Include portability layer here since all other files depend on it. */ +#ifdef FLATCC_PORTABLE +#include "flatcc/portable/portable.h" +#endif + +/* + * Fast printing and parsing of double. + * + * This requires the grisu3/grisu3_* files to be in the include path, + * otherwise strod and sprintf will be used (these needed anyway + * as fallback for cases not supported by grisu3). + */ +#ifndef FLATCC_USE_GRISU3 +#define FLATCC_USE_GRISU3 1 +#endif + +/* + * This requires compiler that has enabled marc=native or similar so + * __SSE4_2__ flag is defined. Otherwise it will have no effect. + * + * While SSE may be used for different purposes, it has (as of this + * writing) only be used to test the effect on JSON whitespace handling + * which improved, but not by a lot, assuming 64-bit unligned access is + * otherwise available: + * + * With 8 space indentation, the JSON benchmark handles 308K parse ops/sec + * while SSE ups that to 333 parse ops/sec or 336 if \r\n is also + * consumed by SSE. Disabling indentation leaves SSE spacing handling + * ineffective, and performance reaches 450K parse ops/sec and can + * improve further to 500+K parse ops/sec if inexact GRISU3 numbers are + * allowed (they are pretty accurate anyway, just not exact). This + * feature requires hacking a flag direct in the grisu3 double parsing + * lib directly and only mentioned for comparison. + * + * In conclusion SSE doesn't add a lot to JSON space handling at least. + * + * Disabled by default, but can be overriden by build system. + */ +#ifndef FLATCC_USE_SSE4_2 +#define FLATCC_USE_SSE4_2 0 +#endif + +/* + * The verifier only reports yes and no. The following setting + * enables assertions in debug builds. It must be compiled into + * the runtime library and is not normally the desired behavior. + * + * NOTE: enabling this can break test cases so use with build, not test. + */ +#if !defined(FLATCC_DEBUG_VERIFY) && !defined(NDEBUG) +#define FLATCC_DEBUG_VERIFY 0 +#endif + +#if !defined(FLATCC_TRACE_VERIFY) +#define FLATCC_TRACE_VERIFY 0 +#endif + +/* + * Some producers allow empty vectors to be misaligned. + * The following setting will cause the verifier to require the index 0 + * position to be element aligned even if the vector is empty (otherwise that + * position is only required to be aligned to the preceding size field). + */ +#if !defined(FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS) +#define FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS 0 +#endif + +/* + * Limit recursion level for tables. Actual level may be deeper + * when structs are deeply nested - but these are limited by the + * schema compiler. + */ +#ifndef FLATCC_JSON_PRINT_MAX_LEVELS +#define FLATCC_JSON_PRINT_MAX_LEVELS 100 +#endif + +/* Maximum length of names printed exluding _type suffix. */ +#ifndef FLATCC_JSON_PRINT_NAME_LEN_MAX +#define FLATCC_JSON_PRINT_NAME_LEN_MAX 100 +#endif + +/* + * Print float and double values with C99 hexadecimal floating point + * notation. This option is not valid JSON but it avoids precision + * loss, correctly handles NaN, +/-Infinity and is significantly faster + * to parse and print. Some JSON parsers rely on strtod which does + * support hexadecimal floating points when C99 compliant. + */ +#ifndef FLATCC_JSON_PRINT_HEX_FLOAT +#define FLATCC_JSON_PRINT_HEX_FLOAT 0 +#endif + +/* + * Always print multipe enum flags like `color: "Red Green"` + * even when unquote is selected as an option for single + * value like `color: Green`. Otherwise multiple values + * are printed as `color: Red Green`, but this could break + * some flatbuffer json parser. + */ +#ifndef FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS +#define FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS 1 +#endif + +/* + * The general nesting limit may be lower, but for skipping + * JSON we do not need to - we can set this high as it only + * costs a single char per level in a stack array. + */ +#ifndef FLATCC_JSON_PARSE_GENERIC_MAX_NEST +#define FLATCC_JSON_PARSE_GENERIC_MAX_NEST 512 +#endif + +/* Store value even if it is default. */ +#ifndef FLATCC_JSON_PARSE_FORCE_DEFAULTS +#define FLATCC_JSON_PARSE_FORCE_DEFAULTS 0 +#endif + +#ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED +#define FLATCC_JSON_PARSE_ALLOW_UNQUOTED 1 +#endif + +/* + * Multiple enum values are by default not permitted unless + * quoted like `color: "Red Green" as per Googles flatc JSON + * parser while a single value like `color: Red` can be + * unquoted. Enabling this setting will allow `color: Red + * Green`, but only if FLATCC_JSON_PARSE_ALLOW_UNQUOTED is + * also enabled. + */ +#ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST +#define FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST 0 +#endif + +#ifndef FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD +#define FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD 1 +#endif + +#ifndef FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA +#define FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA 1 +#endif + +/* + * Just parse to the closing bracket '}' if set. + * Otherwise parse to end by consuming space and + * fail if anything but space follows. + */ +#ifndef FLATCC_PARSE_IGNORE_TRAILING_DATA +#define FLATCC_PARSE_IGNORE_TRAILING_DATA 0 +#endif + +/* + * Optimize to parse a lot of white space, but + * in most cases it probably slows parsing down. + */ +#ifndef FLATCC_JSON_PARSE_WIDE_SPACE +#define FLATCC_JSON_PARSE_WIDE_SPACE 0 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_RTCONFIG_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_types.h b/third_party/nanoarrow/include/flatcc/flatcc_types.h new file mode 100644 index 0000000..69605d2 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_types.h @@ -0,0 +1,97 @@ +#ifndef FLATCC_TYPES_H +#define FLATCC_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifndef UINT8_MAX +#include +#endif + +/* + * This should match generated type declaratios in + * `flatbuffers_common_reader.h` (might have different name prefix). + * Read only generated code does not depend on library code, + * hence the duplication. + */ +#ifndef flatbuffers_types_defined +#define flatbuffers_types_defined + +/* + * uoffset_t and soffset_t must be same integer type, except for sign. + * They can be (u)int16_t, (u)int32_t, or (u)int64_t. + * The default is (u)int32_t. + * + * voffset_t is expected to be uint16_t, but can experimentally be + * compiled from uint8_t up to uint32_t. + * + * ID_MAX is the largest value that can index a vtable. The table size + * is given as voffset value. Each id represents a voffset value index + * from 0 to max inclusive. Space is required for two header voffset + * fields and the unaddressible highest index (due to the table size + * representation). For 16-bit voffsets this yields a max of 2^15 - 4, + * or (2^16 - 1) / 2 - 3. + */ + +#define flatbuffers_uoffset_t_defined +#define flatbuffers_soffset_t_defined +#define flatbuffers_voffset_t_defined +#define flatbuffers_utype_t_defined +#define flatbuffers_bool_t_defined +#define flatbuffers_thash_t_defined +#define flatbuffers_fid_t_defined + +/* uoffset_t is also used for vector and string headers. */ +#define FLATBUFFERS_UOFFSET_MAX UINT32_MAX +#define FLATBUFFERS_SOFFSET_MAX INT32_MAX +#define FLATBUFFERS_SOFFSET_MIN INT32_MIN +#define FLATBUFFERS_VOFFSET_MAX UINT16_MAX +#define FLATBUFFERS_UTYPE_MAX UINT8_MAX +/* Well - the max of the underlying type. */ +#define FLATBUFFERS_BOOL_MAX UINT8_MAX +#define FLATBUFFERS_THASH_MAX UINT32_MAX + +#define FLATBUFFERS_ID_MAX (FLATBUFFERS_VOFFSET_MAX / sizeof(flatbuffers_voffset_t) - 3) +/* Vectors of empty structs can yield div by zero, so we must guard against this. */ +#define FLATBUFFERS_COUNT_MAX(elem_size) (FLATBUFFERS_UOFFSET_MAX/((elem_size) == 0 ? 1 : (elem_size))) + +#define FLATBUFFERS_UOFFSET_WIDTH 32 +#define FLATBUFFERS_COUNT_WIDTH 32 +#define FLATBUFFERS_SOFFSET_WIDTH 32 +#define FLATBUFFERS_VOFFSET_WIDTH 16 +#define FLATBUFFERS_UTYPE_WIDTH 8 +#define FLATBUFFERS_BOOL_WIDTH 8 +#define FLATBUFFERS_THASH_WIDTH 32 + +#define FLATBUFFERS_TRUE 1 +#define FLATBUFFERS_FALSE 0 + +#define FLATBUFFERS_PROTOCOL_IS_LE 1 +#define FLATBUFFERS_PROTOCOL_IS_BE 0 + +typedef uint32_t flatbuffers_uoffset_t; +typedef int32_t flatbuffers_soffset_t; +typedef uint16_t flatbuffers_voffset_t; +typedef uint8_t flatbuffers_utype_t; +typedef uint8_t flatbuffers_bool_t; +typedef uint32_t flatbuffers_thash_t; +/* Public facing type operations. */ +typedef flatbuffers_utype_t flatbuffers_union_type_t; + +static const flatbuffers_bool_t flatbuffers_true = FLATBUFFERS_TRUE; +static const flatbuffers_bool_t flatbuffers_false = FLATBUFFERS_FALSE; + +#define FLATBUFFERS_IDENTIFIER_SIZE (FLATBUFFERS_THASH_WIDTH / 8) + +typedef char flatbuffers_fid_t[FLATBUFFERS_IDENTIFIER_SIZE]; + +#endif /* flatbuffers_types_defined */ + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_TYPES_H */ diff --git a/third_party/nanoarrow/include/flatcc/flatcc_verifier.h b/third_party/nanoarrow/include/flatcc/flatcc_verifier.h new file mode 100644 index 0000000..eb19b64 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/flatcc_verifier.h @@ -0,0 +1,267 @@ +#ifndef FLATCC_VERIFIER_H +#define FLATCC_VERIFIER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Runtime support for verifying flatbuffers. + * + * Link with the verifier implementation file. + * + * Note: + * + * 1) nested buffers will NOT have their identifier verified. + * The user may do so subsequently. The reason is in part because + * the information is not readily avaible without generated reader code, + * in part because the buffer might use a different, but valid, + * identifier and the user has no chance of specifiying this in the + * verifier code. The root verifier also doesn't assume a specific id + * but accepts a user supplied input which may be null. + * + * 2) All offsets in a buffer are verified for alignment relative to the + * buffer start, but the buffer itself is only assumed to aligned to + * uoffset_t. A reader should therefore ensure buffer alignment separately + * before reading the buffer. Nested buffers are in fact checked for + * alignment, but still only relative to the root buffer. + * + * 3) The max nesting level includes nested buffer nestings, so the + * verifier might fail even if the individual buffers are otherwise ok. + * This is to prevent abuse with lots of nested buffers. + * + * + * IMPORTANT: + * + * Even if verifier passes, the buffer may be invalid to access due to + * lack of alignemnt in memory, but the verifier is safe to call. + * + * NOTE: The buffer is not safe to modify after verification because an + * attacker may craft overlapping data structures such that modification + * of one field updates another in a way that violates the buffer + * constraints. This may also be caused by a clever compression scheme. + * + * It is likely faster to rewrite the table although this is also + * dangerous because an attacker (or even normal user) can draft a DAG + * that explodes when expanded carelesslessly. A safer approach is to + * hash all object references written and reuse those that match. This + * will expand references into other objects while bounding expansion + * and it will be safe to update assuming shared objects are ok to + * update. + * + */ + +#include "flatcc/flatcc_types.h" + +#define FLATCC_VERIFY_ERROR_MAP(XX)\ + XX(ok, "ok")\ + XX(buffer_header_too_small, "buffer header too small")\ + XX(identifier_mismatch, "identifier mismatch")\ + XX(max_nesting_level_reached, "max nesting level reached")\ + XX(required_field_missing, "required field missing")\ + XX(runtime_buffer_header_not_aligned, "runtime: buffer header not aligned")\ + XX(runtime_buffer_size_too_large, "runtime: buffer size too large")\ + XX(string_not_zero_terminated, "string not zero terminated")\ + XX(string_out_of_range, "string out of range")\ + XX(struct_out_of_range, "struct out of range")\ + XX(struct_size_overflow, "struct size overflow")\ + XX(struct_unaligned, "struct unaligned")\ + XX(table_field_not_aligned, "table field not aligned")\ + XX(table_field_out_of_range, "table field out of range")\ + XX(table_field_size_overflow, "table field size overflow")\ + XX(table_header_out_of_range_or_unaligned, "table header out of range or unaligned")\ + XX(vector_header_out_of_range_or_unaligned, "vector header out of range or unaligned")\ + XX(string_header_out_of_range_or_unaligned, "string header out of range or unaligned")\ + XX(offset_out_of_range, "offset out of range")\ + XX(table_offset_out_of_range_or_unaligned, "table offset out of range or unaligned")\ + XX(table_size_out_of_range, "table size out of range")\ + XX(type_field_absent_from_required_union_field, "type field absent from required union field")\ + XX(type_field_absent_from_required_union_vector_field, "type field absent from required union vector field")\ + XX(union_cannot_have_a_table_without_a_type, "union cannot have a table without a type")\ + XX(union_type_NONE_cannot_have_a_value, "union value field present with type NONE")\ + XX(vector_count_exceeds_representable_vector_size, "vector count exceeds representable vector size")\ + XX(vector_out_of_range, "vector out of range")\ + XX(vtable_header_out_of_range, "vtable header out of range")\ + XX(vtable_header_too_small, "vtable header too small")\ + XX(vtable_offset_out_of_range_or_unaligned, "vtable offset out of range or unaligned")\ + XX(vtable_size_out_of_range_or_unaligned, "vtable size out of range or unaligned")\ + XX(vtable_size_overflow, "vtable size overflow")\ + XX(union_element_absent_without_type_NONE, "union element absent without type NONE")\ + XX(union_element_present_with_type_NONE, "union element present with type NONE")\ + XX(union_vector_length_mismatch, "union type and table vectors have different lengths")\ + XX(union_vector_verification_not_supported, "union vector verification not supported")\ + XX(runtime_buffer_size_less_than_size_field, "runtime buffer size less than buffer headers size field")\ + XX(not_supported, "not supported") + + + +enum flatcc_verify_error_no { +#define XX(no, str) flatcc_verify_error_##no, + FLATCC_VERIFY_ERROR_MAP(XX) +#undef XX +}; + +#define flatcc_verify_ok flatcc_verify_error_ok + +const char *flatcc_verify_error_string(int err); + +/* + * Type specific table verifier function that checks each known field + * for existence in the vtable and then calls the appropriate verifier + * function in this library. + * + * The table descriptor values have been verified for bounds, overflow, + * and alignment, but vtable entries after header must be verified + * for all fields the table verifier function understands. + * + * Calls other typespecific verifier functions recursively whenever a + * table field, union or table vector is encountered. + */ +typedef struct flatcc_table_verifier_descriptor flatcc_table_verifier_descriptor_t; +struct flatcc_table_verifier_descriptor { + /* Pointer to buffer. Not assumed to be aligned beyond uoffset_t. */ + const void *buf; + /* Buffer size. */ + flatbuffers_uoffset_t end; + /* Time to live: number nesting levels left before failure. */ + int ttl; + /* Vtable of current table. */ + const void *vtable; + /* Table offset relative to buffer start */ + flatbuffers_uoffset_t table; + /* Table end relative to buffer start as per vtable[1] field. */ + flatbuffers_voffset_t tsize; + /* Size of vtable in bytes. */ + flatbuffers_voffset_t vsize; +}; + +typedef int flatcc_table_verifier_f(flatcc_table_verifier_descriptor_t *td); + +typedef struct flatcc_union_verifier_descriptor flatcc_union_verifier_descriptor_t; + +struct flatcc_union_verifier_descriptor { + /* Pointer to buffer. Not assumed to be aligned beyond uoffset_t. */ + const void *buf; + /* Buffer size. */ + flatbuffers_uoffset_t end; + /* Time to live: number nesting levels left before failure. */ + int ttl; + /* Type of union value to be verified */ + flatbuffers_utype_t type; + /* Offset relative to buffer start to where union value offset is stored. */ + flatbuffers_uoffset_t base; + /* Offset of union value relative to base. */ + flatbuffers_uoffset_t offset; +}; + +typedef int flatcc_union_verifier_f(flatcc_union_verifier_descriptor_t *ud); + +/* + * The `as_root` functions are normally the only functions called + * explicitly in this interface. + * + * If `fid` is null, the identifier is not checked and is allowed to be entirely absent. + * + * The buffer must at least be aligned to uoffset_t on systems that + * require aligned memory addresses. The buffer pointers alignment is + * not significant to internal verification of the buffer. + * + * The `_with_size` variant handles size prefixed buffers which aligns slighly differently + * due to the size prefix, notably for buffers with alignment above the uoffset_t type. + */ +int flatcc_verify_struct_as_root(const void *buf, size_t bufsiz, const char *fid, + size_t size, uint16_t align); + +int flatcc_verify_struct_as_root_with_size(const void *buf, size_t bufsiz, const char *fid, + size_t size, uint16_t align); + +int flatcc_verify_struct_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, + size_t size, uint16_t align); + +int flatcc_verify_struct_as_typed_root_with_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, + size_t size, uint16_t align); + +int flatcc_verify_table_as_root(const void *buf, size_t bufsiz, const char *fid, + flatcc_table_verifier_f *root_tvf); + +int flatcc_verify_table_as_root_with_size(const void *buf, size_t bufsiz, const char *fid, + flatcc_table_verifier_f *root_tvf); + +int flatcc_verify_table_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, + flatcc_table_verifier_f *root_tvf); + +int flatcc_verify_table_as_typed_root_with_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, + flatcc_table_verifier_f *root_tvf); + +/* + * The buffer header is verified by any of the `_as_root` verifiers, but + * this function may be used as a quick sanity check. + */ +int flatcc_verify_buffer_header(const void *buf, size_t bufsiz, const char *fid); + +int flatcc_verify_typed_buffer_header(const void *buf, size_t bufsiz, flatbuffers_thash_t type_hash); + +/* + * Verifies size prefixed buffer headers. The `bufsiz` argument is a pointer that will be updated + * with the size stored in the buffer header iff it is no larger than the input argument, and + * otherwise the verifer fails. The updated size field adds sizeof(flatbuffers_uoffset_t) to the size + * to be compatible with bufsiz since the header size field does not include itself. + */ +int flatcc_verify_buffer_header_with_size(const void *buf, size_t *bufsiz, const char *fid); + +int flatcc_verify_typed_buffer_header_with_size(const void *buf, size_t *bufsiz, flatbuffers_thash_t type_hash); + +/* + * The following functions are typically called by a generated table + * verifier function. + */ + +/* Scalar, enum or struct field. */ +int flatcc_verify_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, size_t size, uint16_t align); +/* Vector of scalars, enums or structs. */ +int flatcc_verify_vector_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, size_t elem_size, uint16_t align, size_t max_count); +int flatcc_verify_string_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required); +int flatcc_verify_string_vector_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required); +int flatcc_verify_table_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, flatcc_table_verifier_f tvf); +int flatcc_verify_table_vector_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, flatcc_table_verifier_f tvf); +/* Table verifiers pass 0 as fid. */ +int flatcc_verify_struct_as_nested_root(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, const char *fid, + size_t size, uint16_t align); +int flatcc_verify_table_as_nested_root(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, const char *fid, + uint16_t align, flatcc_table_verifier_f tvf); + +/* + * A NONE type will not accept a table being present, and a required + * union will not accept a type field being absent, and an absent type + * field will not accept a table field being present. + * + * If the above checks out and the type is not NONE, the uvf callback + * is executed. It must test each known table type and silently accept + * any unknown table type for forward compatibility. A union table + * value is verified without the required flag because an absent table + * encodes a typed NULL value while an absent type field encodes a + * missing union which fails if required. + */ +int flatcc_verify_union_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, flatcc_union_verifier_f uvf); + +int flatcc_verify_union_vector_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, flatcc_union_verifier_f uvf); + +int flatcc_verify_union_table(flatcc_union_verifier_descriptor_t *ud, flatcc_table_verifier_f *tvf); +int flatcc_verify_union_struct(flatcc_union_verifier_descriptor_t *ud, size_t size, uint16_t align); +int flatcc_verify_union_string(flatcc_union_verifier_descriptor_t *ud); + +#ifdef __cplusplus +} +#endif + +#endif /* FLATCC_VERIFIER_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/paligned_alloc.h b/third_party/nanoarrow/include/flatcc/portable/paligned_alloc.h new file mode 100644 index 0000000..419b610 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/paligned_alloc.h @@ -0,0 +1,213 @@ +#ifndef PALIGNED_ALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * NOTE: MSVC in general has no aligned alloc function that is + * compatible with free and it is not trivial to implement a version + * which is. Therefore, to remain portable, end user code needs to + * use `aligned_free` which is not part of C11 but defined in this header. + * + * glibc only provides aligned_alloc when _ISOC11_SOURCE is defined, but + * MingW does not support aligned_alloc despite of this, it uses the + * the _aligned_malloc as MSVC. + * + * The same issue is present on some Unix systems not providing + * posix_memalign. + * + * Note that clang and gcc with -std=c11 or -std=c99 will not define + * _POSIX_C_SOURCE and thus posix_memalign cannot be detected but + * aligned_alloc is not necessarily available either. We assume + * that clang always has posix_memalign although it is not strictly + * correct. For gcc, use -std=gnu99 or -std=gnu11 or don't use -std in + * order to enable posix_memalign, or live with the fallback until using + * a system where glibc has a version that supports aligned_alloc. + * + * For C11 compliant compilers and compilers with posix_memalign, + * it is valid to use free instead of aligned_free with the above + * caveats. + */ + +#include + +/* + * Define this to see which version is used so the fallback is not + * enganged unnecessarily: + * + * #define PORTABLE_DEBUG_ALIGNED_ALLOC + */ + +#if 0 +#define PORTABLE_DEBUG_ALIGNED_ALLOC +#endif + +#if !defined(PORTABLE_C11_ALIGNED_ALLOC) + +/* + * PORTABLE_C11_ALIGNED_ALLOC = 1 + * indicates that the system has builtin aligned_alloc + * If it doesn't, the section after detection provides an implemention. + */ +#if defined (__MINGW32__) +/* MingW does not provide aligned_alloc despite defining _ISOC11_SOURCE */ +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#elif defined (_ISOC11_SOURCE) +/* glibc aligned_alloc detection, but MingW is not truthful */ +#define PORTABLE_C11_ALIGNED_ALLOC 1 +#elif defined (__GLIBC__) +/* aligned_alloc is not available in glibc just because __STDC_VERSION__ >= 201112L. */ +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#elif defined (__clang__) +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#elif defined (__APPLE__) +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#elif defined(__IBMC__) +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#elif (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +#define PORTABLE_C11_ALIGNED_ALLOC 1 +#else +#define PORTABLE_C11_ALIGNED_ALLOC 0 +#endif + +#endif /* PORTABLE_C11_ALIGNED_ALLOC */ + +/* https://linux.die.net/man/3/posix_memalign */ +#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_GNU_SOURCE) +#define PORTABLE_POSIX_MEMALIGN 1 +#endif + +/* https://forum.kde.org/viewtopic.php?p=66274 */ +#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_XOPEN_SOURCE) +#if _XOPEN_SOURCE >= 600 +#define PORTABLE_POSIX_MEMALIGN 1 +#endif +#endif + +#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(_POSIX_C_SOURCE) +#if _POSIX_C_SOURCE >= 200112L +#define PORTABLE_POSIX_MEMALIGN 1 +#endif +#endif + +#if !defined(PORTABLE_POSIX_MEMALIGN) && defined(__clang__) +#define PORTABLE_POSIX_MEMALIGN 1 +#endif + +#if !defined(PORTABLE_POSIX_MEMALIGN) +#define PORTABLE_POSIX_MEMALIGN 0 +#endif + +/* https://forum.kde.org/viewtopic.php?p=66274 */ +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +/* C11 or newer */ +#include +#endif + +/* C11 or newer */ +#if !defined(aligned_alloc) && !defined(__aligned_alloc_is_defined) + +#if PORTABLE_C11_ALIGNED_ALLOC +#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC +#error "DEBUG: C11_ALIGNED_ALLOC configured" +#endif +#elif defined(_MSC_VER) || defined(__MINGW32__) + +#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC +#error "DEBUG: Windows _aligned_malloc configured" +#endif + +/* Aligned _aligned_malloc is not compatible with free. */ +#define aligned_alloc(alignment, size) _aligned_malloc(size, alignment) +#define aligned_free(p) _aligned_free(p) +#define __aligned_alloc_is_defined 1 +#define __aligned_free_is_defined 1 + +#elif PORTABLE_POSIX_MEMALIGN + +#if defined(__GNUC__) +#if !defined(__GNUCC__) +extern int posix_memalign (void **, size_t, size_t); +#elif __GNUCC__ < 5 +extern int posix_memalign (void **, size_t, size_t); +#endif +#endif + +static inline void *__portable_aligned_alloc(size_t alignment, size_t size) +{ + int err; + void *p = 0; + + if (alignment < sizeof(void *)) { + alignment = sizeof(void *); + } + err = posix_memalign(&p, alignment, size); + if (err && p) { + free(p); + p = 0; + } + return p; +} + +#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC +#error "DEBUG: POSIX_MEMALIGN configured" +#endif + +#define aligned_alloc(alignment, size) __portable_aligned_alloc(alignment, size) +#define aligned_free(p) free(p) +#define __aligned_alloc_is_defined 1 +#define __aligned_free_is_defined 1 + +#else + +static inline void *__portable_aligned_alloc(size_t alignment, size_t size) +{ + char *raw; + void *buf; + size_t total_size = (size + alignment - 1 + sizeof(void *)); + + if (alignment < sizeof(void *)) { + alignment = sizeof(void *); + } + raw = (char *)(size_t)malloc(total_size); + if (!raw) return 0; + buf = raw + alignment - 1 + sizeof(void *); + buf = (void *)(((size_t)buf) & ~(alignment - 1)); + ((void **)buf)[-1] = raw; + return buf; +} + +static inline void __portable_aligned_free(void *p) +{ + char *raw; + + if (p) { + raw = (char*)((void **)p)[-1]; + free(raw); + } +} + +#define aligned_alloc(alignment, size) __portable_aligned_alloc(alignment, size) +#define aligned_free(p) __portable_aligned_free(p) +#define __aligned_alloc_is_defined 1 +#define __aligned_free_is_defined 1 + +#ifdef PORTABLE_DEBUG_ALIGNED_ALLOC +#error "DEBUG: aligned_alloc malloc fallback configured" +#endif + +#endif + +#endif /* aligned_alloc */ + +#if !defined(aligned_free) && !defined(__aligned_free_is_defined) +#define aligned_free(p) free(p) +#define __aligned_free_is_defined 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PALIGNED_ALLOC_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pattributes.h b/third_party/nanoarrow/include/flatcc/portable/pattributes.h new file mode 100644 index 0000000..dd4918a --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pattributes.h @@ -0,0 +1,84 @@ + +/* + * C23 introduces an attribute syntax `[[]]`. Prior to that + * other non-standard syntaxes such as `__attribute__(())` + * and `__declspec()` have been supported by some compiler + * versions. + * + * See also: + * https://en.cppreference.com/w/c/language/attributes + * + * There is no portable way to use C23 attributes in older C standards + * so in order to use these portably, some macro name needs to be + * defined for each attribute that either maps to the older supported + * syntax, or ignores the attribute as appropriate. + * + * The Linux kernel defines certain attributes as macros, such as + * `fallthrough`. When adding attributes it seems reasonable to follow + * the Linux conventions in lack of any official standard. However, it + * is not the intention that this file should mirror the Linux + * attributes 1 to 1. + * + * See also: + * https://github.com/torvalds/linux/blob/master/include/linux/compiler_attributes.h + * + * There is a risk that exposed attribute names may lead to name + * conflicts. A conflicting name can be undefined and if necessary used + * using `pattribute()`. All attributes can be hidden by + * defining `PORTABLE_EXPOSE_ATTRIBUTES=0` in which case + * `pattribute()` can still be used and then if a specific + * attribute name still needs to be exposed, it can be defined manually + * like `#define fallthrough pattribute(fallthrough)`. + */ + + +#ifndef PATTRIBUTES_H +#define PATTRIBUTES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PORTABLE_EXPOSE_ATTRIBUTES +#define PORTABLE_EXPOSE_ATTRIBUTES 0 +#endif + +#ifdef __has_c_attribute +# define PORTABLE_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) +#else +# define PORTABLE_HAS_C_ATTRIBUTE(x) 0 +#endif + +#ifdef __has_attribute +# define PORTABLE_HAS_ATTRIBUTE(x) __has_attribute(x) +#else +# define PORTABLE_HAS_ATTRIBUTE(x) 0 +#endif + + +/* https://en.cppreference.com/w/c/language/attributes/fallthrough */ +#if PORTABLE_HAS_C_ATTRIBUTE(__fallthrough__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +# define pattribute_fallthrough [[__fallthrough__]] +#elif PORTABLE_HAS_ATTRIBUTE(__fallthrough__) +# define pattribute_fallthrough __attribute__((__fallthrough__)) +#else +# define pattribute_fallthrough ((void)0) +#endif + + +#define pattribute(x) pattribute_##x + +#if PORTABLE_EXPOSE_ATTRIBUTES + +#ifndef fallthrough +# define fallthrough pattribute(fallthrough) +#endif + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* PATTRIBUTES_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pdiagnostic.h b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic.h new file mode 100644 index 0000000..7e48773 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic.h @@ -0,0 +1,84 @@ + /* There is intentionally no include guard in this file. */ + + +/* + * Usage: optionally disable any of these before including. + * + * #define PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION + * #define PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE + * #define PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER + * #define PDIAGNOSTIC_IGNORE_UNUSED // all of the above + * + * #include "pdiagnostic.h" + * + * Alternatively use #include "pdiagnostic_push/pop.h" + */ + +#ifdef _MSC_VER +#pragma warning(disable: 4668) /* preprocessor name not defined */ +#endif + +#if !defined(PDIAGNOSTIC_AWARE_MSVC) && defined(_MSC_VER) +#define PDIAGNOSTIC_AWARE_MSVC 1 +#elif !defined(PDIAGNOSTIC_AWARE_MSVC) +#define PDIAGNOSTIC_AWARE_MSVC 0 +#endif + +#if !defined(PDIAGNOSTIC_AWARE_CLANG) && defined(__clang__) +#define PDIAGNOSTIC_AWARE_CLANG 1 +#elif !defined(PDIAGNOSTIC_AWARE_CLANG) +#define PDIAGNOSTIC_AWARE_CLANG 0 +#endif + +#if !defined(PDIAGNOSTIC_AWARE_GCC) && defined(__GNUC__) && !defined(__clang__) +/* Can disable some warnings even if push is not available (gcc-4.2 vs gcc-4.7) */ +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) +#define PDIAGNOSTIC_AWARE_GCC 1 +#endif +#endif + +#if !defined(PDIAGNOSTIC_AWARE_GCC) +#define PDIAGNOSTIC_AWARE_GCC 0 +#endif + +#if defined(PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION) || defined(PDIAGNOSTIC_IGNORE_UNUSED) +#if PDIAGNOSTIC_AWARE_CLANG +#pragma clang diagnostic ignored "-Wunused-function" +#elif PDIAGNOSTIC_AWARE_GCC +#pragma GCC diagnostic ignored "-Wunused-function" +#endif +#endif +#undef PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION + +#if defined(PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE) || defined(PDIAGNOSTIC_IGNORE_UNUSED) +#if PDIAGNOSTIC_AWARE_MSVC +#pragma warning(disable: 4101) /* unused local variable */ +#elif PDIAGNOSTIC_AWARE_CLANG +#pragma clang diagnostic ignored "-Wunused-variable" +#elif PDIAGNOSTIC_AWARE_GCC +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif +#endif +#undef PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE + +#if defined(PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER) || defined(PDIAGNOSTIC_IGNORE_UNUSED) +#if PDIAGNOSTIC_AWARE_CLANG +#pragma clang diagnostic ignored "-Wunused-parameter" +#elif PDIAGNOSTIC_AWARE_GCC +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif +#endif +#undef PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER + +#undef PDIAGNOSTIC_IGNORE_UNUSED + +#if defined (__cplusplus) && __cplusplus < 201103L +#if PDIAGNOSTIC_AWARE_CLANG +/* Needed for < C++11 clang C++ static_assert */ +#pragma clang diagnostic ignored "-Wc11-extensions" +/* Needed for empty macro arguments. */ +#pragma clang diagnostic ignored "-Wc99-extensions" +/* Needed for trailing commas. */ +#pragma clang diagnostic ignored "-Wc++11-extensions" +#endif +#endif diff --git a/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_pop.h b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_pop.h new file mode 100644 index 0000000..f5e16b3 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_pop.h @@ -0,0 +1,20 @@ +#if defined(PDIAGNOSTIC_PUSHED_MSVC) +#if PDIAGNOSTIC_PUSHED_MSVC +#pragma warning( pop ) +#endif // PDIAGNOSTIC_PUSHED_MSVC +#undef PDIAGNOSTIC_PUSHED_MSVC +#endif // defined(PDIAGNOSTIC_PUSHED_MSVC) + +#if defined(PDIAGNOSTIC_PUSHED_CLANG) +#if PDIAGNOSTIC_PUSHED_CLANG +#pragma clang diagnostic pop +#endif // PDIAGNOSTIC_PUSHED_CLANG +#undef PDIAGNOSTIC_PUSHED_CLANG +#endif // defined(PDIAGNOSTIC_PUSHED_CLANG) + +#if defined(PDIAGNOSTIC_PUSHED_GCC) +#if PDIAGNOSTIC_PUSHED_GCC +#pragma GCC diagnostic pop +#endif // PDIAGNOSTIC_PUSHED_GCC +#undef PDIAGNOSTIC_PUSHED_GCC +#endif // defined(PDIAGNOSTIC_PUSHED_GCC) diff --git a/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_push.h b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_push.h new file mode 100644 index 0000000..66586d7 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pdiagnostic_push.h @@ -0,0 +1,51 @@ +/* + * See also comment in "pdiagnostic.h" + * + * e.g. + * #define PDIAGNOSTIC_IGNORE_USED_FUNCTION + * #define PDIAGNOSTIC_IGNORE_USED_VARIABLE + * #include "pdiagnostic_push" + * ... + * #include "pdiagnostic_pop.h" + * + * + * or if push pop isn't desired: + * #define PDIAGNOSTIC_IGNORE_USED_FUNCTION + * #define PDIAGNOSTIC_IGNORE_USED_VARIABLE + * #include "pdiagnostic.h" + * ... + * + * + * + * Some if these warnings cannot be ignored + * at the #pragma level, but might in the future. + * Use compiler switches like -Wno-unused-function + * to work around this. + */ + +#if defined(_MSC_VER) +#pragma warning( push ) +#define PDIAGNOSTIC_PUSHED_MSVC 1 +#else +#define PDIAGNOSTIC_PUSHED_MSVC 0 +#endif + +#if defined(__clang__) +#pragma clang diagnostic push +#define PDIAGNOSTIC_PUSHED_CLANG 1 +#else +#define PDIAGNOSTIC_PUSHED_CLANG 0 +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#pragma GCC diagnostic push +#define PDIAGNOSTIC_PUSHED_GCC 1 +#else +#define PDIAGNOSTIC_PUSHED_GCC 0 +#endif // GNUC >= 4.6 +#else +#define PDIAGNOSTIC_PUSHED_GCC 0 +#endif // defined(__GNUC__) && !defined(__clang__) + +#include "pdiagnostic.h" diff --git a/third_party/nanoarrow/include/flatcc/portable/pendian.h b/third_party/nanoarrow/include/flatcc/portable/pendian.h new file mode 100644 index 0000000..122ba8e --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pendian.h @@ -0,0 +1,206 @@ +#ifndef PENDIAN_H +#define PENDIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Defines platform optimized (as per linux + * + * le16toh, le32to, le64toh, be16toh, be32toh, be64toh + * htole16, htole32, htole64, htobe16, htobe32, htobe64 + * + * Falls back to auto-detect endian conversion which is also fast + * if fast byteswap operation was detected. + * + * Also defines platform optimized: + * + * bswap16, bswap32, bswap64, + * + * with fall-back to shift-or implementation. + * + * For convenience also defines: + * + * le8to, be8toh, htole8, htobe8 + * bswap8 + * + * The convience functions makes is simpler to define conversion macros + * based on type size. + * + * NOTE: this implementation expects arguments with no side-effects and + * with appropriately sized unsigned arguments. These are expected to be + * used with typesafe wrappers. + */ + +#ifndef UINT8_MAX +#include "pstdint.h" +#endif + +#if defined(__linux__) +#include +#elif defined(__OpenBSD__) || defined(__FreeBSD__) +#include +#endif + +#include "pendian_detect.h" + +#if defined(_MSC_VER) +#if _MSC_VER >= 1300 +#include +#define bswap16 _byteswap_ushort +#define bswap32 _byteswap_ulong +#define bswap64 _byteswap_uint64 +#endif +#elif defined(__clang__) +#if __has_builtin(__builtin_bswap16) +#ifndef bswap16 +#define bswap16 __builtin_bswap16 +#endif +#endif +#if __has_builtin(__builtin_bswap32) +#ifndef bswap32 +#define bswap32 __builtin_bswap32 +#endif +#endif +#if __has_builtin(__builtin_bswap64) +#ifndef bswap64 +#define bswap64 __builtin_bswap64 +#endif +#endif +#elif defined(__OpenBSD__) || defined(__FreeBSD__) +#ifndef bswap16 +#define bswap16 swap16 +#endif +#ifndef bswap32 +#define bswap32 swap32 +#endif +#ifndef bswap64 +#define bswap64 swap64 +#endif +#elif defined(__GNUC__) /* Supported since at least GCC 4.4 */ +#ifndef bswap32 +#define bswap32 __builtin_bswap32 +#endif +#ifndef bswap64 +#define bswap64 __builtin_bswap64 +#endif +#endif + +#ifndef bswap16 +#define bswap16(v) \ + (((uint16_t)(v) << 8) | ((uint16_t)(v) >> 8)) +#endif + +#ifndef bswap32 +#define bswap32(v) \ + ((((uint32_t)(v) << 24)) \ + | (((uint32_t)(v) << 8) & UINT32_C(0x00FF0000)) \ + | (((uint32_t)(v) >> 8) & UINT32_C(0x0000FF00)) \ + | (((uint32_t)(v) >> 24))) +#endif + +#ifndef bswap64 +#define bswap64(v) \ + ((((uint64_t)(v) << 56)) \ + | (((uint64_t)(v) << 40) & UINT64_C(0x00FF000000000000)) \ + | (((uint64_t)(v) << 24) & UINT64_C(0x0000FF0000000000)) \ + | (((uint64_t)(v) << 8) & UINT64_C(0x000000FF00000000)) \ + | (((uint64_t)(v) >> 8) & UINT64_C(0x00000000FF000000)) \ + | (((uint64_t)(v) >> 24) & UINT64_C(0x0000000000FF0000)) \ + | (((uint64_t)(v) >> 40) & UINT64_C(0x000000000000FF00)) \ + | (((uint64_t)(v) >> 56))) +#endif + +#ifndef bswap8 +#define bswap8(v) ((uint8_t)(v)) +#endif + +#if !defined(le16toh) && defined(letoh16) +#define le16toh letoh16 +#define le32toh letoh32 +#define le64toh letoh64 +#endif + +#if !defined(be16toh) && defined(betoh16) +#define be16toh betoh16 +#define be32toh betoh32 +#define be64toh betoh64 +#endif + +/* Assume it goes for all. */ +#if !defined(le16toh) + +#if defined(__LITTLE_ENDIAN__) + +#define le16toh(v) (v) +#define le32toh(v) (v) +#define le64toh(v) (v) + +#define htole16(v) (v) +#define htole32(v) (v) +#define htole64(v) (v) + +#define be16toh(v) bswap16(v) +#define be32toh(v) bswap32(v) +#define be64toh(v) bswap64(v) + +#define htobe16(v) bswap16(v) +#define htobe32(v) bswap32(v) +#define htobe64(v) bswap64(v) + +#elif defined(__BIG_ENDIAN__) + +#define le16toh(v) bswap16(v) +#define le32toh(v) bswap32(v) +#define le64toh(v) bswap64(v) + +#define htole16(v) bswap16(v) +#define htole32(v) bswap32(v) +#define htole64(v) bswap64(v) + +#define be16toh(v) (v) +#define be32toh(v) (v) +#define be64toh(v) (v) + +#define htobe16(v) (v) +#define htobe32(v) (v) +#define htobe64(v) (v) + +#else + +static const int __pendian_test = 1; + +#define le16toh(v) (*(char *)&__pendian_test ? (v) : bswap16(v)) +#define le32toh(v) (*(char *)&__pendian_test ? (v) : bswap32(v)) +#define le64toh(v) (*(char *)&__pendian_test ? (v) : bswap64(v)) + +#define htole16(v) (*(char *)&__pendian_test ? (v) : bswap16(v)) +#define htole32(v) (*(char *)&__pendian_test ? (v) : bswap32(v)) +#define htole64(v) (*(char *)&__pendian_test ? (v) : bswap64(v)) + +#define be16toh(v) (*(char *)&__pendian_test ? bswap16(v) : (v)) +#define be32toh(v) (*(char *)&__pendian_test ? bswap32(v) : (v)) +#define be64toh(v) (*(char *)&__pendian_test ? bswap64(v) : (v)) + +#define htobe16(v) (*(char *)&__pendian_test ? bswap16(v) : (v)) +#define htobe32(v) (*(char *)&__pendian_test ? bswap32(v) : (v)) +#define htobe64(v) (*(char *)&__pendian_test ? bswap64(v) : (v)) + +#endif + +#endif /* le16toh */ + +/* Helpers not part of Linux */ +#if !defined(le8toh) +#define le8toh(n) (n) +#define htole8(n) (n) +#define be8toh(n) (n) +#define htobe8(n) (n) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PENDIAN_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pendian_detect.h b/third_party/nanoarrow/include/flatcc/portable/pendian_detect.h new file mode 100644 index 0000000..1dd62c0 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pendian_detect.h @@ -0,0 +1,118 @@ +/* + * Uses various known flags to decide endianness and defines: + * + * __LITTLE_ENDIAN__ or __BIG_ENDIAN__ if not already defined + * + * and also defines + * + * __BYTE_ORDER__ to either __ORDER_LITTLE_ENDIAN__ or + * __ORDER_BIG_ENDIAN__ if not already defined + * + * If none of these could be set, __UNKNOWN_ENDIAN__ is defined, + * which is not a known flag. If __BYTE_ORDER__ is defined but + * not big or little endian, __UNKNOWN_ENDIAN__ is also defined. + * + * Note: Some systems define __BYTE_ORDER without __ at the end + * - this will be mapped to to __BYTE_ORDER__. + */ + +#ifndef PENDIAN_DETECT +#define PENDIAN_DETECT + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __ORDER_LITTLE_ENDIAN__ +#define __ORDER_LITTLE_ENDIAN__ 1234 +#endif + +#ifndef __ORDER_BIG_ENDIAN__ +#define __ORDER_BIG_ENDIAN__ 4321 +#endif + +#ifdef __BYTE_ORDER__ + +#if defined(__LITTLE_ENDIAN__) && __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ +#error __LITTLE_ENDIAN__ inconsistent with __BYTE_ORDER__ +#endif + +#if defined(__BIG_ENDIAN__) && __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ +#error __BIG_ENDIAN__ inconsistent with __BYTE_ORDER__ +#endif + +#else /* __BYTE_ORDER__ */ + + +#if \ + defined(__LITTLE_ENDIAN__) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ + defined(__ARMEL__) || defined(__THUMBEL__) || \ + defined(__AARCH64EL__) || \ + (defined(_MSC_VER) && defined(_M_ARM)) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ + defined(_M_X64) || defined(_M_IX86) || defined(_M_I86) || \ + defined(__i386__) || defined(__alpha__) || \ + defined(__ia64) || defined(__ia64__) || \ + defined(_M_IA64) || defined(_M_ALPHA) || \ + defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \ + defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ + defined(__bfin__) + +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ + +#endif + +#if \ + defined (__BIG_ENDIAN__) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ + defined(__ARMEB__) || defined(THUMBEB__) || defined (__AARCH64EB__) || \ + defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \ + defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \ + defined(__hpux) || defined(__hppa) || defined(__s390__) + +#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ + +#endif + +#endif /* __BYTE_ORDER__ */ + +#ifdef __BYTE_ORDER__ + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + +#ifndef __LITTLE_ENDIAN__ +#define __LITTLE_ENDIAN__ 1 +#endif + +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + +#ifndef __BIG_ENDIAN__ +#define __BIG_ENDIAN__ 1 +#endif + +#else + +/* + * Custom extension - we only define __BYTE_ORDER__ if known big or little. + * User code that understands __BYTE_ORDER__ may also assume unkown if + * it is not defined by now - this will allow other endian formats than + * big or little when supported by compiler. + */ +#ifndef __UNKNOWN_ENDIAN__ +#define __UNKNOWN_ENDIAN__ 1 +#endif + +#endif +#endif /* __BYTE_ORDER__ */ + +#if defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__) +#error conflicting definitions of __LITTLE_ENDIAN__ and __BIG_ENDIAN__ +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PENDIAN_DETECT */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pinline.h b/third_party/nanoarrow/include/flatcc/portable/pinline.h new file mode 100644 index 0000000..f4f8f27 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pinline.h @@ -0,0 +1,19 @@ +#ifndef PINLINE_H +#define PINLINE_H + +#ifndef __cplusplus + +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +/* C99 or newer */ +#elif _MSC_VER >= 1500 /* MSVC 9 or newer */ +#undef inline +#define inline __inline +#elif __GNUC__ >= 3 /* GCC 3 or newer */ +#define inline __inline +#else /* Unknown or ancient */ +#define inline +#endif + +#endif /* __cplusplus */ + +#endif /* PINLINE_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pinttypes.h b/third_party/nanoarrow/include/flatcc/portable/pinttypes.h new file mode 100644 index 0000000..a1be9df --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pinttypes.h @@ -0,0 +1,52 @@ +#ifndef PINTTYPES_H +#define PINTTYPES_H + +#ifndef PRId16 + +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +/* C99 or newer */ +#include +#else + +/* + * This is not a complete implementation of , just the most + * useful printf modifiers. + */ + +#include "pstdint.h" + +#ifndef PRINTF_INT64_MODIFIER +#error "please define PRINTF_INT64_MODIFIER" +#endif + +#ifndef PRId64 +#define PRId64 PRINTF_INT64_MODIFIER "d" +#define PRIu64 PRINTF_INT64_MODIFIER "u" +#define PRIx64 PRINTF_INT64_MODIFIER "x" +#endif + +#ifndef PRINTF_INT32_MODIFIER +#define PRINTF_INT32_MODIFIER "l" +#endif + +#ifndef PRId32 +#define PRId32 PRINTF_INT32_MODIFIER "d" +#define PRIu32 PRINTF_INT32_MODIFIER "u" +#define PRIx32 PRINTF_INT32_MODIFIER "x" +#endif + +#ifndef PRINTF_INT16_MODIFIER +#define PRINTF_INT16_MODIFIER "h" +#endif + +#ifndef PRId16 +#define PRId16 PRINTF_INT16_MODIFIER "d" +#define PRIu16 PRINTF_INT16_MODIFIER "u" +#define PRIx16 PRINTF_INT16_MODIFIER "x" +#endif + +# endif /* __STDC__ */ + +#endif /* PRId16 */ + +#endif /* PINTTYPES */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pmemaccess.h b/third_party/nanoarrow/include/flatcc/portable/pmemaccess.h new file mode 100644 index 0000000..0735af5 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pmemaccess.h @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2024 Mikkel Fahnøe Jørgensen, dvide.com + * + * (MIT License) + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + +/* Provide strict aliasing safe portable access to reading and writing integer and + floating point values from memory buffers of size 1, 2, 4, and 8 bytes, and + optionally 16 bytes when C23 uint128_t is available. + Also supports casting between integers and floats at the binary level, e.g. + mem_read_float32(&myuint32), which can be necessary for endian conversions. + + It is often suggested to use memcpy for this purpose, that is not an ideal + solution. See comments below. + + While this is intended to be aligned access, the strict C aliasing rules forces + this to be the same as unaligned access. On x86/64 we can be more relaxed both + with aliasing and alignment, but if at some point a compiler starts to + modify this behaviour, the header can be updated or PORTABLE_MEM_PTR_ACCESS + can be defined to 0 in the build configuration, or this file can be updated. + + The balance is betweem knowing memcpy or __builtin_memcpy is fast, + and knowing that pointer casts do not break. + + Known targets that require PORTABLE_MEM_PTR_ACCESS=0 for at least some version: + + - ARM cross compiler: arm-none-eabi, -O2, -mcpu=cortext-m7, + breaks on PORTABLE_MEM_PTR_ACCESS=0 + slow memcpy, has fast __builtin_memcpy + + - Intel ICC -O3 on x86/64 (that compiler is deprecated by Intel). + breaks on PORTABLE_MEM_PTR_ACCESS=0 + has __builtin_memcpy, performance unknown, memcpy perforamnce unknown. + + */ + + +/* NOTE: for best performance, `__builtin_memcpy` should be detectable, but + the current detection logic is not ideal for older compilers. See below. */ + + +#ifndef PMEMACCESS_H +#define PMEMACCESS_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Set to 1 to see which implementation is chosen on current platform. */ +#ifndef PORTABLE_MEM_ACCESS_DEBUG +#define PORTABLE_MEM_ACCESS_DEBUG 0 +#endif + +/* MEM_PTR_ACCESS (aka pointer casts) (*(T *)p) is not formally valid for strict aliasing. + It works in most cases, but not always. It may be the best option for older + compilers that do not optimize well and which don't care about strict aliazing. + x86/64 platforms appears to work well with this, while it only sometimes work + on other platforms. + + NOTE: this might change as compiler updates their optimization strategies. */ + +#ifndef PORTABLE_MEM_PTR_ACCESS + +#if defined(__INTEL_COMPILER) +# /* Prevents Intel ICC compiler from breaking on -O3 on x86/64 target, + likely due to strict aliasing rules. */ +# define PORTABLE_MEM_PTR_ACCESS 0 +#elif (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) +# define PORTABLE_MEM_PTR_ACCESS 1 +#else +# define PORTABLE_MEM_PTR_ACCESS 0 +#endif + +#endif /* PORTABLE_MEM_PTR_ACCESS */ + + +#ifndef UINT8_MAX +# include +#endif + +/* `mem_copy_word` implements optimized non-overlapping memory copies of + 1, 2, 4, 8, or 16 bytes, noting that C23 introduces uin128_t. + Other sizes are not defined even if some implementation might support them. + `mem_copy_word` of 16 bytes are supported even if uint128_t is not available. + + Ideally call `mem_copy_word` with known constant lengths for best optimization. + + The objective is both to support type punning where a binary representation is + reinterpreted, and to read and write integers and floats safely from memory without + risking undefined behaviour from strict aliasing rules. + + `memcpy` is supposed to handle this efficiently given small constant powers of 2, but + this evidently fails on some platforms since even small constants lengths with -O2 + level optimization can issue a function call. On such platforms, `__builtin_memcpy` + tends to work better, if it can be detected. + + A pointer cast can and will, albeit uncommon, lead to undefined behaviour + such as reading from uninitialized stack memory when strict aliasing is the default + optimization strategy. + + Note: __has_builtin is not necessarily defined on platforms with __builtin_memcpy support, + so detection can be improved. Feel free to contribute. + + Note: `mem_copy_word_` is a macro that may call `mem_copy_word` but it is guaranteed to + be called with a literal length argument, so it could be redefined to forward calls + to e.g. my_mem_copy_word_2 via token pasting. It is used with the `mem_read/write_nn` + functions below. */ + +#ifndef mem_copy_word +# if defined(__has_builtin) +# if __has_builtin(__builtin_memcpy) +# define mem_copy_word(d, s, n) __builtin_memcpy((d), (s), (n)) +# if PORTABLE_MEM_ACCESS_DEBUG +# error mem_copy_word using: __builtin_memcpy +# endif +# endif +# endif +#endif + +#ifndef mem_copy_word + #include "pinline.h" + #include "prestrict.h" + /* Sometimes `memcpy` is a call even when optimized and given small constant length arguments, + so this is more likely to be optimized. `int len` is used to avoid dependency. + Also, by not using `memcpy`, we avoid depending on . + + As an alternative consider PORTABLE_MEM_PTR_ACCESS=1 with `mem_read/write_nn` for some older + platforms that might not care about strict aliasing, and which also might not optimize well. */ + static inline void mem_copy_word(void * restrict dest, const void * restrict src, int len) + { + char *d = (char *)dest; + const char *s = (const char *)src; + while(len--) *d++ = *s++; + } + #if PORTABLE_MEM_ACCESS_DEBUG + # error mem_copy_word using: inline memcpy + #endif +#endif + + +#if PORTABLE_MEM_PTR_ACCESS + +#define mem_read_8(p) (*(uint8_t*)(p)) +#define mem_read_16(p) (*(uint16_t*)(p)) +#define mem_read_32(p) (*(uint32_t*)(p)) +#define mem_read_64(p) (*(uint64_t*)(p)) + +#define mem_write_8(p, v) ((void)(*(uint8_t*)(p) = (uint8_t)(v))) +#define mem_write_16(p, v) ((void)(*(uint16_t*)(p) = (uint16_t)(v))) +#define mem_write_32(p, v) ((void)(*(uint32_t*)(p) = (uint32_t)(v))) +#define mem_write_64(p, v) ((void)(*(uint64_t*)(p) = (uint64_t)(v))) + +#define mem_read_float_32(p) (*(float*)(p)) +#define mem_read_float_64(p) (*(double*)(p)) + +#define mem_write_float_32(p, v) ((void)(*(float*)(p) = (float)(v))) +#define mem_write_float_64(p, v) ((void)(*(double*)(p) = (double)(v))) + +#ifdef UINT128_MAX + +#define mem_read_128(p) (*(uint128_t*)(p)) + +#define mem_write_128(p, v) ((void)(*(uint128_t*)(p) = (uint128_t)(v))) + +#endif + +#if PORTABLE_MEM_ACCESS_DEBUG +# error mem_read/write_nn using: pointer cast +#endif + +#else /* PORTABLE_MEM_PTR_ACCESS */ + +/* mem_copy_word_ is guaranteed to receive literal `n` arguments + so operations can be optimized via token pasting if necessary. */ +#ifndef mem_copy_word_ +#define mem_copy_word_(d, s, n) mem_copy_word(d, s, n) +#endif + +#define mem_read_8(p) (*(uint8_t*)(p)) +#define mem_write_8(p, v) ((void)(*(uint8_t*)(p) = (uint8_t)(v))) + +static inline uint16_t mem_read_16(const void *p) { uint16_t v; mem_copy_word_(&v, p, 2); return v; } +static inline uint32_t mem_read_32(const void *p) { uint32_t v; mem_copy_word_(&v, p, 4); return v; } +static inline uint64_t mem_read_64(const void *p) { uint64_t v; mem_copy_word_(&v, p, 8); return v; } + +#define mem_write_16(p, v) do { const uint16_t x = (uint16_t)(v); mem_copy_word_((p), &x, 2); } while(0) +#define mem_write_32(p, v) do { const uint32_t x = (uint32_t)(v); mem_copy_word_((p), &x, 4); } while(0) +#define mem_write_64(p, v) do { const uint64_t x = (uint64_t)(v); mem_copy_word_((p), &x, 8); } while(0) + +static inline float mem_read_float_32(const void *p) { float v; mem_copy_word_(&v, p, 4); return v; } +static inline double mem_read_float_64(const void *p) { double v; mem_copy_word_(&v, p, 8); return v; } + +#define mem_write_float_32(p, v) do { const float x = (float)(v); mem_copy_word_((p), &x, 4); } while(0) +#define mem_write_float_64(p, v) do { const double x = (double)(v); mem_copy_word_((p), &x, 8); } while(0) + +#ifdef UINT128_MAX + +static inline uint128_t mem_read_128(const void *p) { uint128_t v; mem_copy_word_(&v, p, 16); return v; } + +#define mem_write_128(p, v) do { const uint128_t x = (uint128_t)(v); mem_copy_word_((p), &x, 128); } while(0) + +#endif + +#if PORTABLE_MEM_ACCESS_DEBUG +# error mem_read/write_nn using: mem_copy_word +#endif + +#endif /* PORTABLE_MEM_PTR_ACCESS */ + + +#ifdef __cplusplus +} +#endif + +#endif /* PMEMACCESS_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/portable.h b/third_party/nanoarrow/include/flatcc/portable/portable.h new file mode 100644 index 0000000..7a6a484 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/portable.h @@ -0,0 +1,2 @@ +/* portable.h is widely used, so we redirect to a less conflicting name. */ +#include "portable_basic.h" diff --git a/third_party/nanoarrow/include/flatcc/portable/portable_basic.h b/third_party/nanoarrow/include/flatcc/portable/portable_basic.h new file mode 100644 index 0000000..86cbff4 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/portable_basic.h @@ -0,0 +1,27 @@ +#ifndef PORTABLE_BASIC_H +#define PORTABLE_BASIC_H + +/* + * Basic features need to make compilers support the most common moden C + * features, and endian / unligned read support as well. + * + * It is not assumed that this file is always included. + * Other include files are independent or include what they need. + */ + +#include "pversion.h" +#include "pwarnings.h" + +/* Featutures that ought to be supported by C11, but some aren't. */ +#include "pinttypes.h" +#include "pstdalign.h" +#include "pinline.h" +#include "pstatic_assert.h" + +/* These are not supported by C11 and are general platform abstractions. */ +#include "pendian.h" +#include "punaligned.h" +#include "pmemaccess.h" + + +#endif /* PORTABLE_BASIC_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/prestrict.h b/third_party/nanoarrow/include/flatcc/portable/prestrict.h new file mode 100644 index 0000000..a3c2aa0 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/prestrict.h @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 2024 Mikkel Fahnøe Jørgensen, dvide.com + * + * (MIT License) + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + +#ifndef PRESTRICT_H +#define PRESTRICT_H + + +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +/* C99 or newer */ +#elif defined(__restrict) +/* Some C/C++ compilers use alternative syntax. If these are defines, we can detect them. */ +#define restrict __restrict +#elif defined(__restrict__) +#define restrict __restrict__ +#else +#define restrict +#endif + + +#endif /* PRESTRICT_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pstatic_assert.h b/third_party/nanoarrow/include/flatcc/portable/pstatic_assert.h new file mode 100644 index 0000000..24d5634 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pstatic_assert.h @@ -0,0 +1,67 @@ +#ifndef PSTATIC_ASSERT_H +#define PSTATIC_ASSERT_H + +#include + +/* Handle clang */ +#ifndef __has_feature + #define __has_feature(x) 0 +#endif + +#if defined(static_assert) +#ifndef __static_assert_is_defined +#define __static_assert_is_defined 1 +#endif +#endif + +/* Handle static_assert as a keyword in C++ and compiler specifics. */ +#if !defined(__static_assert_is_defined) + +#if defined(__cplusplus) + +#if __cplusplus >= 201103L +#define __static_assert_is_defined 1 +#elif __has_feature(cxx_static_assert) +#define __static_assert_is_defined 1 +#elif defined(_MSC_VER) && (_MSC_VER >= 1600) +#define __static_assert_is_defined 1 +#endif + +#else + +#if defined(_MSC_VER) && (_MSC_VER >= 1600) +#define __static_assert_is_defined 1 +#elif __has_feature(c_static_assert) +#define static_assert(pred, msg) _Static_assert(pred, msg) +#define __static_assert_is_defined 1 +#elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +/* In case the clib headers are not compliant. */ +#define static_assert(pred, msg) _Static_assert(pred, msg) +#define __static_assert_is_defined 1 +#endif + +#endif /* __cplusplus */ +#endif /* __static_assert_is_defined */ + + +#if !defined(__static_assert_is_defined) + +#define __PSTATIC_ASSERT_CONCAT_(a, b) static_assert_scope_##a##_line_##b +#define __PSTATIC_ASSERT_CONCAT(a, b) __PSTATIC_ASSERT_CONCAT_(a, b) +#ifdef __COUNTER__ +#define static_assert(e, msg) enum { __PSTATIC_ASSERT_CONCAT(__COUNTER__, __LINE__) = 1/(!!(e)) } +#else +#include "pstatic_assert_scope.h" +#define static_assert(e, msg) enum { __PSTATIC_ASSERT_CONCAT(__PSTATIC_ASSERT_COUNTER, __LINE__) = 1/(int)(!!(e)) } +#endif + +#define __static_assert_is_defined 1 + +#endif /* __static_assert_is_defined */ + +#endif /* PSTATIC_ASSERT_H */ + +/* Update scope counter outside of include guard. */ +#ifdef __PSTATIC_ASSERT_COUNTER +#include "pstatic_assert_scope.h" +#endif diff --git a/third_party/nanoarrow/include/flatcc/portable/pstdalign.h b/third_party/nanoarrow/include/flatcc/portable/pstdalign.h new file mode 100644 index 0000000..1737ca0 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pstdalign.h @@ -0,0 +1,170 @@ +#ifndef PSTDALIGN_H +#define PSTDALIGN_H + +/* + * NOTE: aligned_alloc is defined via paligned_alloc.h + * and requires aligned_free to be fully portable although + * free also works on C11 and platforms with posix_memalign. + * + * NOTE: C++11 defines alignas as a keyword but then also defines + * __alignas_is_defined. + * + * C++14 does not define __alignas_is_defined, at least sometimes. + * + * GCC 8.3 reverts on this and makes C++11 behave the same as C++14 + * preventing a simple __cplusplus version check from working. + * + * Clang C++ without std=c++11 or std=c++14 does define alignas + * but does so incorrectly wrt. C11 and C++11 semantics because + * `alignas(4) float x;` is not recognized. + * To fix such issues, either move to a std version, or + * include a working stdalign.h for the given compiler before + * this file. + * + * newlib defines _Alignas and _Alignof in sys/cdefs but rely on + * gcc version for which can lead to conflicts if + * stdalign is not included. + * + * newlibs need for conflicts with broken C++ stdalign + * but this can be fixed be using std=C++11 or newer. + * + * MSVC does not support at least up to MSVC 2015, + * but does appear to support alignas and alignof keywords in + * recent standard C++. + * + * TCC only supports alignas with a numeric argument like + * `alignas(4)`, but not `alignas(float)`. + * + * If stdalign.h is supported but heuristics in this file are + * insufficient to detect this, try including manually + * or define HAVE_STDALIGN_H. + */ + +/* https://github.com/dvidelabs/flatcc/issues/130 */ +#ifndef __alignas_is_defined +#if defined(__cplusplus) +#if __cplusplus == 201103 && !defined(__clang__) && ((__GNUC__ > 8) || (__GNUC__ == 8 && __GNUC_MINOR__ >= 3)) +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 +#include +#endif +#endif +#endif + +/* Allow for alternative solution to be included first. */ +#ifndef __alignas_is_defined + +#ifdef __cplusplus +#if defined(PORTABLE_PATCH_CPLUSPLUS_STDALIGN) +#include +#undef alignas +#define alignas(t) __attribute__((__aligned__(t))) +#endif +#endif + +#if !defined(PORTABLE_HAS_INCLUDE_STDALIGN) +#if defined(__has_include) +#if __has_include() +#define PORTABLE_HAS_INCLUDE_STDALIGN 1 +#else +#define PORTABLE_HAS_INCLUDE_STDALIGN 0 +#endif +#endif +#endif + + /* https://lists.gnu.org/archive/html/bug-gnulib/2015-08/msg00003.html */ +#if defined(__cplusplus) +#if !defined(_MSC_VER) +#include +#endif +#if __cplusplus > 201103 +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 +#endif +#elif PORTABLE_HAS_INCLUDE_STDALIGN +#include +#elif !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) +#include +#elif defined(HAVE_STDALIGN_H) +#include +#endif + +#endif /* __alignas_is_defined */ + +#ifndef __alignas_is_defined + +#ifdef __cplusplus +extern "C" { +#endif + +#if (!defined(__clang__) && defined(__GNUC__) && \ + ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 7))) +#undef PORTABLE_C11_STDALIGN_MISSING +#define PORTABLE_C11_STDALIGN_MISSING +#endif + +#if defined(__IBMC__) +#undef PORTABLE_C11_STDALIGN_MISSING +#define PORTABLE_C11_STDALIGN_MISSING +#endif + +#if ((defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) && \ + !defined(PORTABLE_C11_STDALIGN_MISSING)) +/* C11 or newer */ +#include +#else +#if defined(__GNUC__) || defined(__IBM_ALIGNOF__) || defined(__clang__) + +#ifndef _Alignas +#define _Alignas(t) __attribute__((__aligned__(t))) +#endif + +#ifndef _Alignof +#define _Alignof(t) __alignof__(t) +#endif + +#elif defined(_MSC_VER) + +#define _Alignas(t) __declspec (align(t)) +#define _Alignof(t) __alignof(t) + +#elif defined(__TINYC__) + +/* Supports `_Alignas(integer-expression)`, but not `_Alignas(type)`. */ +#define _Alignas(t) __attribute__(aligned(t)) +#define _Alignof(t) __alignof__(t) + +#else +#error please update pstdalign.h with support for current compiler and library +#endif + +#endif /* __STDC__ */ + +// For C23, alignas/alignof are keywords and will warn (-Wkeyword-macro) when #defined here +// GH-801: 202000L is the value used by Apple clang-16 when compiling with -std=gnu2x (i.e., +// the draft standard at the time), which reflects the GitHub Actions runner at the time of this +// writing. +#if !(defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L) + +#ifndef alignas +#define alignas _Alignas +#endif + +#ifndef alignof +#define alignof _Alignof +#endif + +#endif + +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 + +#ifdef __cplusplus +} +#endif + +#endif /* __alignas__is_defined */ + +#include "paligned_alloc.h" + +#endif /* PSTDALIGN_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pstdint.h b/third_party/nanoarrow/include/flatcc/portable/pstdint.h new file mode 100644 index 0000000..14444aa --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pstdint.h @@ -0,0 +1,898 @@ +/* A portable stdint.h + **************************************************************************** + * BSD License: + **************************************************************************** + * + * Copyright (c) 2005-2016 Paul Hsieh + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************** + * + * Version 0.1.15.2 + * + * The ANSI C standard committee, for the C99 standard, specified the + * inclusion of a new standard include file called stdint.h. This is + * a very useful and long desired include file which contains several + * very precise definitions for integer scalar types that is + * critically important for making portable several classes of + * applications including cryptography, hashing, variable length + * integer libraries and so on. But for most developers its likely + * useful just for programming sanity. + * + * The problem is that some compiler vendors chose to ignore the C99 + * standard and some older compilers have no opportunity to be updated. + * Because of this situation, simply including stdint.h in your code + * makes it unportable. + * + * So that's what this file is all about. Its an attempt to build a + * single universal include file that works on as many platforms as + * possible to deliver what stdint.h is supposed to. Even compilers + * that already come with stdint.h can use this file instead without + * any loss of functionality. A few things that should be noted about + * this file: + * + * 1) It is not guaranteed to be portable and/or present an identical + * interface on all platforms. The extreme variability of the + * ANSI C standard makes this an impossibility right from the + * very get go. Its really only meant to be useful for the vast + * majority of platforms that possess the capability of + * implementing usefully and precisely defined, standard sized + * integer scalars. Systems which are not intrinsically 2s + * complement may produce invalid constants. + * + * 2) There is an unavoidable use of non-reserved symbols. + * + * 3) Other standard include files are invoked. + * + * 4) This file may come in conflict with future platforms that do + * include stdint.h. The hope is that one or the other can be + * used with no real difference. + * + * 5) In the current verison, if your platform can't represent + * int32_t, int16_t and int8_t, it just dumps out with a compiler + * error. + * + * 6) 64 bit integers may or may not be defined. Test for their + * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX. + * Note that this is different from the C99 specification which + * requires the existence of 64 bit support in the compiler. If + * this is not defined for your platform, yet it is capable of + * dealing with 64 bits then it is because this file has not yet + * been extended to cover all of your system's capabilities. + * + * 7) (u)intptr_t may or may not be defined. Test for its presence + * with the test: #ifdef PTRDIFF_MAX. If this is not defined + * for your platform, then it is because this file has not yet + * been extended to cover all of your system's capabilities, not + * because its optional. + * + * 8) The following might not been defined even if your platform is + * capable of defining it: + * + * WCHAR_MIN + * WCHAR_MAX + * (u)int64_t + * PTRDIFF_MIN + * PTRDIFF_MAX + * (u)intptr_t + * + * 9) The following have not been defined: + * + * WINT_MIN + * WINT_MAX + * + * 10) The criteria for defining (u)int_least(*)_t isn't clear, + * except for systems which don't have a type that precisely + * defined 8, 16, or 32 bit types (which this include file does + * not support anyways). Default definitions have been given. + * + * 11) The criteria for defining (u)int_fast(*)_t isn't something I + * would trust to any particular compiler vendor or the ANSI C + * committee. It is well known that "compatible systems" are + * commonly created that have very different performance + * characteristics from the systems they are compatible with, + * especially those whose vendors make both the compiler and the + * system. Default definitions have been given, but its strongly + * recommended that users never use these definitions for any + * reason (they do *NOT* deliver any serious guarantee of + * improved performance -- not in this file, nor any vendor's + * stdint.h). + * + * 12) The following macros: + * + * PRINTF_INTMAX_MODIFIER + * PRINTF_INT64_MODIFIER + * PRINTF_INT32_MODIFIER + * PRINTF_INT16_MODIFIER + * PRINTF_LEAST64_MODIFIER + * PRINTF_LEAST32_MODIFIER + * PRINTF_LEAST16_MODIFIER + * PRINTF_INTPTR_MODIFIER + * + * are strings which have been defined as the modifiers required + * for the "d", "u" and "x" printf formats to correctly output + * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t, + * (u)least32_t, (u)least16_t and (u)intptr_t types respectively. + * PRINTF_INTPTR_MODIFIER is not defined for some systems which + * provide their own stdint.h. PRINTF_INT64_MODIFIER is not + * defined if INT64_MAX is not defined. These are an extension + * beyond what C99 specifies must be in stdint.h. + * + * In addition, the following macros are defined: + * + * PRINTF_INTMAX_HEX_WIDTH + * PRINTF_INT64_HEX_WIDTH + * PRINTF_INT32_HEX_WIDTH + * PRINTF_INT16_HEX_WIDTH + * PRINTF_INT8_HEX_WIDTH + * PRINTF_INTMAX_DEC_WIDTH + * PRINTF_INT64_DEC_WIDTH + * PRINTF_INT32_DEC_WIDTH + * PRINTF_INT16_DEC_WIDTH + * PRINTF_UINT8_DEC_WIDTH + * PRINTF_UINTMAX_DEC_WIDTH + * PRINTF_UINT64_DEC_WIDTH + * PRINTF_UINT32_DEC_WIDTH + * PRINTF_UINT16_DEC_WIDTH + * PRINTF_UINT8_DEC_WIDTH + * + * Which specifies the maximum number of characters required to + * print the number of that type in either hexadecimal or decimal. + * These are an extension beyond what C99 specifies must be in + * stdint.h. + * + * Compilers tested (all with 0 warnings at their highest respective + * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32 + * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio + * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3 + * + * This file should be considered a work in progress. Suggestions for + * improvements, especially those which increase coverage are strongly + * encouraged. + * + * Acknowledgements + * + * The following people have made significant contributions to the + * development and testing of this file: + * + * Chris Howie + * John Steele Scott + * Dave Thorup + * John Dill + * Florian Wobbe + * Christopher Sean Morrison + * Mikkel Fahnoe Jorgensen + * + */ + +#include +#include +#include + +/* + * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and + * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_. + */ + +#if ((defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED) +#include +#define _PSTDINT_H_INCLUDED +# if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__)) && !(defined(__APPLE__) && defined(__MACH__)) +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "l" +# endif +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "" +# endif +# else +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "ll" +# endif +# ifndef PRINTF_INT32_MODIFIER +# if (UINT_MAX == UINT32_MAX) +# define PRINTF_INT32_MODIFIER "" +# else +# define PRINTF_INT32_MODIFIER "l" +# endif +# endif +# endif +# ifndef PRINTF_INT16_MODIFIER +# define PRINTF_INT16_MODIFIER "h" +# endif +# ifndef PRINTF_INTMAX_MODIFIER +# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER +# endif +# ifndef PRINTF_INT64_HEX_WIDTH +# define PRINTF_INT64_HEX_WIDTH "16" +# endif +# ifndef PRINTF_UINT64_HEX_WIDTH +# define PRINTF_UINT64_HEX_WIDTH "16" +# endif +# ifndef PRINTF_INT32_HEX_WIDTH +# define PRINTF_INT32_HEX_WIDTH "8" +# endif +# ifndef PRINTF_UINT32_HEX_WIDTH +# define PRINTF_UINT32_HEX_WIDTH "8" +# endif +# ifndef PRINTF_INT16_HEX_WIDTH +# define PRINTF_INT16_HEX_WIDTH "4" +# endif +# ifndef PRINTF_UINT16_HEX_WIDTH +# define PRINTF_UINT16_HEX_WIDTH "4" +# endif +# ifndef PRINTF_INT8_HEX_WIDTH +# define PRINTF_INT8_HEX_WIDTH "2" +# endif +# ifndef PRINTF_UINT8_HEX_WIDTH +# define PRINTF_UINT8_HEX_WIDTH "2" +# endif +# ifndef PRINTF_INT64_DEC_WIDTH +# define PRINTF_INT64_DEC_WIDTH "19" +# endif +# ifndef PRINTF_UINT64_DEC_WIDTH +# define PRINTF_UINT64_DEC_WIDTH "20" +# endif +# ifndef PRINTF_INT32_DEC_WIDTH +# define PRINTF_INT32_DEC_WIDTH "10" +# endif +# ifndef PRINTF_UINT32_DEC_WIDTH +# define PRINTF_UINT32_DEC_WIDTH "10" +# endif +# ifndef PRINTF_INT16_DEC_WIDTH +# define PRINTF_INT16_DEC_WIDTH "5" +# endif +# ifndef PRINTF_UINT16_DEC_WIDTH +# define PRINTF_UINT16_DEC_WIDTH "5" +# endif +# ifndef PRINTF_INT8_DEC_WIDTH +# define PRINTF_INT8_DEC_WIDTH "3" +# endif +# ifndef PRINTF_UINT8_DEC_WIDTH +# define PRINTF_UINT8_DEC_WIDTH "3" +# endif +# ifndef PRINTF_INTMAX_HEX_WIDTH +# define PRINTF_INTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH +# endif +# ifndef PRINTF_UINTMAX_HEX_WIDTH +# define PRINTF_UINTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH +# endif +# ifndef PRINTF_INTMAX_DEC_WIDTH +# define PRINTF_INTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH +# endif +# ifndef PRINTF_UINTMAX_DEC_WIDTH +# define PRINTF_UINTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH +# endif + +/* + * Something really weird is going on with Open Watcom. Just pull some of + * these duplicated definitions from Open Watcom's stdint.h file for now. + */ + +# if defined (__WATCOMC__) && __WATCOMC__ >= 1250 +# if !defined (INT64_C) +# define INT64_C(x) (x + (INT64_MAX - INT64_MAX)) +# endif +# if !defined (UINT64_C) +# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) +# endif +# if !defined (INT32_C) +# define INT32_C(x) (x + (INT32_MAX - INT32_MAX)) +# endif +# if !defined (UINT32_C) +# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX)) +# endif +# if !defined (INT16_C) +# define INT16_C(x) (x) +# endif +# if !defined (UINT16_C) +# define UINT16_C(x) (x) +# endif +# if !defined (INT8_C) +# define INT8_C(x) (x) +# endif +# if !defined (UINT8_C) +# define UINT8_C(x) (x) +# endif +# if !defined (UINT64_MAX) +# define UINT64_MAX 18446744073709551615ULL +# endif +# if !defined (INT64_MAX) +# define INT64_MAX 9223372036854775807LL +# endif +# if !defined (UINT32_MAX) +# define UINT32_MAX 4294967295UL +# endif +# if !defined (INT32_MAX) +# define INT32_MAX 2147483647L +# endif +# if !defined (INTMAX_MAX) +# define INTMAX_MAX INT64_MAX +# endif +# if !defined (INTMAX_MIN) +# define INTMAX_MIN INT64_MIN +# endif +# endif +#endif + +#ifndef _PSTDINT_H_INCLUDED +#define _PSTDINT_H_INCLUDED + +#ifndef SIZE_MAX +# define SIZE_MAX (~(size_t)0) +#endif + +/* + * Deduce the type assignments from limits.h under the assumption that + * integer sizes in bits are powers of 2, and follow the ANSI + * definitions. + */ + +#ifndef UINT8_MAX +# define UINT8_MAX 0xff +#endif +#if !defined(uint8_t) && !defined(_UINT8_T) +# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S) + typedef unsigned char uint8_t; +# define UINT8_C(v) ((uint8_t) v) +# else +# error "Platform not supported" +# endif +#endif + +#ifndef INT8_MAX +# define INT8_MAX 0x7f +#endif +#ifndef INT8_MIN +# define INT8_MIN INT8_C(0x80) +#endif +#if !defined(int8_t) && !defined(_INT8_T) +# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S) + typedef signed char int8_t; +# define INT8_C(v) ((int8_t) v) +# else +# error "Platform not supported" +# endif +#endif + +#ifndef UINT16_MAX +# define UINT16_MAX 0xffff +#endif +#if !defined(uint16_t) && !defined(_UINT16_T) +#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S) + typedef unsigned int uint16_t; +# ifndef PRINTF_INT16_MODIFIER +# define PRINTF_INT16_MODIFIER "" +# endif +# define UINT16_C(v) ((uint16_t) (v)) +#elif (USHRT_MAX == UINT16_MAX) + typedef unsigned short uint16_t; +# define UINT16_C(v) ((uint16_t) (v)) +# ifndef PRINTF_INT16_MODIFIER +# define PRINTF_INT16_MODIFIER "h" +# endif +#else +#error "Platform not supported" +#endif +#endif + +#ifndef INT16_MAX +# define INT16_MAX 0x7fff +#endif +#ifndef INT16_MIN +# define INT16_MIN INT16_C(0x8000) +#endif +#if !defined(int16_t) && !defined(_INT16_T) +#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S) + typedef signed int int16_t; +# define INT16_C(v) ((int16_t) (v)) +# ifndef PRINTF_INT16_MODIFIER +# define PRINTF_INT16_MODIFIER "" +# endif +#elif (SHRT_MAX == INT16_MAX) + typedef signed short int16_t; +# define INT16_C(v) ((int16_t) (v)) +# ifndef PRINTF_INT16_MODIFIER +# define PRINTF_INT16_MODIFIER "h" +# endif +#else +#error "Platform not supported" +#endif +#endif + +#ifndef UINT32_MAX +# define UINT32_MAX (0xffffffffUL) +#endif +#if !defined(uint32_t) && !defined(_UINT32_T) +#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) + typedef unsigned long uint32_t; +# define UINT32_C(v) v ## UL +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "l" +# endif +#elif (UINT_MAX == UINT32_MAX) + typedef unsigned int uint32_t; +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "" +# endif +# define UINT32_C(v) v ## U +#elif (USHRT_MAX == UINT32_MAX) + typedef unsigned short uint32_t; +# define UINT32_C(v) ((unsigned short) (v)) +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "" +# endif +#else +#error "Platform not supported" +#endif +#endif + +#ifndef INT32_MAX +# define INT32_MAX (0x7fffffffL) +#endif +#ifndef INT32_MIN +# define INT32_MIN INT32_C(0x80000000) +#endif +#if !defined(int32_t) && !defined(_INT32_T) +#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) + typedef signed long int32_t; +# define INT32_C(v) v ## L +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "l" +# endif +#elif (INT_MAX == INT32_MAX) + typedef signed int int32_t; +# define INT32_C(v) v +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "" +# endif +#elif (SHRT_MAX == INT32_MAX) + typedef signed short int32_t; +# define INT32_C(v) ((short) (v)) +# ifndef PRINTF_INT32_MODIFIER +# define PRINTF_INT32_MODIFIER "" +# endif +#else +#error "Platform not supported" +#endif +#endif + +/* + * The macro stdint_int64_defined is temporarily used to record + * whether or not 64 integer support is available. It must be + * defined for any 64 integer extensions for new platforms that are + * added. + */ + +#undef stdint_int64_defined +#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S) +# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S) +# define stdint_int64_defined + typedef long long int64_t; + typedef unsigned long long uint64_t; +# define UINT64_C(v) v ## ULL +# define INT64_C(v) v ## LL +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "ll" +# endif +# endif +#endif + +#if !defined (stdint_int64_defined) +# if defined(__GNUC__) +# define stdint_int64_defined + __extension__ typedef long long int64_t; + __extension__ typedef unsigned long long uint64_t; +# define UINT64_C(v) v ## ULL +# define INT64_C(v) v ## LL +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "ll" +# endif +# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S) +# define stdint_int64_defined + typedef long long int64_t; + typedef unsigned long long uint64_t; +# define UINT64_C(v) v ## ULL +# define INT64_C(v) v ## LL +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "ll" +# endif +# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC) +# define stdint_int64_defined + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +# define UINT64_C(v) v ## UI64 +# define INT64_C(v) v ## I64 +# ifndef PRINTF_INT64_MODIFIER +# define PRINTF_INT64_MODIFIER "I64" +# endif +# endif +#endif + +#if !defined (LONG_LONG_MAX) && defined (INT64_C) +# define LONG_LONG_MAX INT64_C (9223372036854775807) +#endif +#ifndef ULONG_LONG_MAX +# define ULONG_LONG_MAX UINT64_C (18446744073709551615) +#endif + +#if !defined (INT64_MAX) && defined (INT64_C) +# define INT64_MAX INT64_C (9223372036854775807) +#endif +#if !defined (INT64_MIN) && defined (INT64_C) +# define INT64_MIN INT64_C (-9223372036854775808) +#endif +#if !defined (UINT64_MAX) && defined (INT64_C) +# define UINT64_MAX UINT64_C (18446744073709551615) +#endif + +/* + * Width of hexadecimal for number field. + */ + +#ifndef PRINTF_INT64_HEX_WIDTH +# define PRINTF_INT64_HEX_WIDTH "16" +#endif +#ifndef PRINTF_INT32_HEX_WIDTH +# define PRINTF_INT32_HEX_WIDTH "8" +#endif +#ifndef PRINTF_INT16_HEX_WIDTH +# define PRINTF_INT16_HEX_WIDTH "4" +#endif +#ifndef PRINTF_INT8_HEX_WIDTH +# define PRINTF_INT8_HEX_WIDTH "2" +#endif +#ifndef PRINTF_INT64_DEC_WIDTH +# define PRINTF_INT64_DEC_WIDTH "19" +#endif +#ifndef PRINTF_INT32_DEC_WIDTH +# define PRINTF_INT32_DEC_WIDTH "10" +#endif +#ifndef PRINTF_INT16_DEC_WIDTH +# define PRINTF_INT16_DEC_WIDTH "5" +#endif +#ifndef PRINTF_INT8_DEC_WIDTH +# define PRINTF_INT8_DEC_WIDTH "3" +#endif +#ifndef PRINTF_UINT64_DEC_WIDTH +# define PRINTF_UINT64_DEC_WIDTH "20" +#endif +#ifndef PRINTF_UINT32_DEC_WIDTH +# define PRINTF_UINT32_DEC_WIDTH "10" +#endif +#ifndef PRINTF_UINT16_DEC_WIDTH +# define PRINTF_UINT16_DEC_WIDTH "5" +#endif +#ifndef PRINTF_UINT8_DEC_WIDTH +# define PRINTF_UINT8_DEC_WIDTH "3" +#endif + +/* + * Ok, lets not worry about 128 bit integers for now. Moore's law says + * we don't need to worry about that until about 2040 at which point + * we'll have bigger things to worry about. + */ + +#ifdef stdint_int64_defined + typedef int64_t intmax_t; + typedef uint64_t uintmax_t; +# define INTMAX_MAX INT64_MAX +# define INTMAX_MIN INT64_MIN +# define UINTMAX_MAX UINT64_MAX +# define UINTMAX_C(v) UINT64_C(v) +# define INTMAX_C(v) INT64_C(v) +# ifndef PRINTF_INTMAX_MODIFIER +# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER +# endif +# ifndef PRINTF_INTMAX_HEX_WIDTH +# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH +# endif +# ifndef PRINTF_INTMAX_DEC_WIDTH +# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH +# endif +#else + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +# define INTMAX_MAX INT32_MAX +# define UINTMAX_MAX UINT32_MAX +# define UINTMAX_C(v) UINT32_C(v) +# define INTMAX_C(v) INT32_C(v) +# ifndef PRINTF_INTMAX_MODIFIER +# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER +# endif +# ifndef PRINTF_INTMAX_HEX_WIDTH +# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH +# endif +# ifndef PRINTF_INTMAX_DEC_WIDTH +# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH +# endif +#endif + +/* + * Because this file currently only supports platforms which have + * precise powers of 2 as bit sizes for the default integers, the + * least definitions are all trivial. Its possible that a future + * version of this file could have different definitions. + */ + +#ifndef stdint_least_defined + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; +# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER +# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER +# define UINT_LEAST8_MAX UINT8_MAX +# define INT_LEAST8_MAX INT8_MAX +# define UINT_LEAST16_MAX UINT16_MAX +# define INT_LEAST16_MAX INT16_MAX +# define UINT_LEAST32_MAX UINT32_MAX +# define INT_LEAST32_MAX INT32_MAX +# define INT_LEAST8_MIN INT8_MIN +# define INT_LEAST16_MIN INT16_MIN +# define INT_LEAST32_MIN INT32_MIN +# ifdef stdint_int64_defined + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; +# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER +# define UINT_LEAST64_MAX UINT64_MAX +# define INT_LEAST64_MAX INT64_MAX +# define INT_LEAST64_MIN INT64_MIN +# endif +#endif +#undef stdint_least_defined + +/* + * The ANSI C committee pretending to know or specify anything about + * performance is the epitome of misguided arrogance. The mandate of + * this file is to *ONLY* ever support that absolute minimum + * definition of the fast integer types, for compatibility purposes. + * No extensions, and no attempt to suggest what may or may not be a + * faster integer type will ever be made in this file. Developers are + * warned to stay away from these types when using this or any other + * stdint.h. + */ + +typedef int_least8_t int_fast8_t; +typedef uint_least8_t uint_fast8_t; +typedef int_least16_t int_fast16_t; +typedef uint_least16_t uint_fast16_t; +typedef int_least32_t int_fast32_t; +typedef uint_least32_t uint_fast32_t; +#define UINT_FAST8_MAX UINT_LEAST8_MAX +#define INT_FAST8_MAX INT_LEAST8_MAX +#define UINT_FAST16_MAX UINT_LEAST16_MAX +#define INT_FAST16_MAX INT_LEAST16_MAX +#define UINT_FAST32_MAX UINT_LEAST32_MAX +#define INT_FAST32_MAX INT_LEAST32_MAX +#define INT_FAST8_MIN INT_LEAST8_MIN +#define INT_FAST16_MIN INT_LEAST16_MIN +#define INT_FAST32_MIN INT_LEAST32_MIN +#ifdef stdint_int64_defined + typedef int_least64_t int_fast64_t; + typedef uint_least64_t uint_fast64_t; +# define UINT_FAST64_MAX UINT_LEAST64_MAX +# define INT_FAST64_MAX INT_LEAST64_MAX +# define INT_FAST64_MIN INT_LEAST64_MIN +#endif + +#undef stdint_int64_defined + +/* + * Whatever piecemeal, per compiler thing we can do about the wchar_t + * type limits. + */ + +#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) +# include +# ifndef WCHAR_MIN +# define WCHAR_MIN 0 +# endif +# ifndef WCHAR_MAX +# define WCHAR_MAX ((wchar_t)-1) +# endif +#endif + +/* + * Whatever piecemeal, per compiler/platform thing we can do about the + * (u)intptr_t types and limits. + */ + +#if (defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)) || defined (_UINTPTR_T) +# define STDINT_H_UINTPTR_T_DEFINED +#endif + +#ifndef STDINT_H_UINTPTR_T_DEFINED +# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) || defined (__ppc64__) +# define stdint_intptr_bits 64 +# elif defined (__WATCOMC__) || defined (__TURBOC__) +# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__) +# define stdint_intptr_bits 16 +# else +# define stdint_intptr_bits 32 +# endif +# elif defined (__i386__) || defined (_WIN32) || defined (WIN32) || defined (__ppc64__) +# define stdint_intptr_bits 32 +# elif defined (__INTEL_COMPILER) +/* TODO -- what did Intel do about x86-64? */ +# else +/* #error "This platform might not be supported yet" */ +# endif + +# ifdef stdint_intptr_bits +# define stdint_intptr_glue3_i(a,b,c) a##b##c +# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c) +# ifndef PRINTF_INTPTR_MODIFIER +# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER) +# endif +# ifndef PTRDIFF_MAX +# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) +# endif +# ifndef PTRDIFF_MIN +# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) +# endif +# ifndef UINTPTR_MAX +# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX) +# endif +# ifndef INTPTR_MAX +# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) +# endif +# ifndef INTPTR_MIN +# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) +# endif +# ifndef INTPTR_C +# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x) +# endif +# ifndef UINTPTR_C +# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x) +# endif + typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t; + typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t; +# else +/* TODO -- This following is likely wrong for some platforms, and does + nothing for the definition of uintptr_t. */ + typedef ptrdiff_t intptr_t; +# endif +# define STDINT_H_UINTPTR_T_DEFINED +#endif + +/* + * Assumes sig_atomic_t is signed and we have a 2s complement machine. + */ + +#ifndef SIG_ATOMIC_MAX +# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1) +#endif + +#endif + +#if defined (__TEST_PSTDINT_FOR_CORRECTNESS) + +/* + * Please compile with the maximum warning settings to make sure macros are + * not defined more than once. + */ + +#include +#include +#include + +#define glue3_aux(x,y,z) x ## y ## z +#define glue3(x,y,z) glue3_aux(x,y,z) + +#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0); +#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0); + +#define DECL(us,bits) glue3(DECL,us,) (bits) + +#define TESTUMAX(bits) glue3(u,bits,) = ~glue3(u,bits,); if (glue3(UINT,bits,_MAX) != glue3(u,bits,)) printf ("Something wrong with UINT%d_MAX\n", bits) + +#define REPORTERROR(msg) { err_n++; if (err_first <= 0) err_first = __LINE__; printf msg; } + +int main () { + int err_n = 0; + int err_first = 0; + DECL(I,8) + DECL(U,8) + DECL(I,16) + DECL(U,16) + DECL(I,32) + DECL(U,32) +#ifdef INT64_MAX + DECL(I,64) + DECL(U,64) +#endif + intmax_t imax = INTMAX_C(0); + uintmax_t umax = UINTMAX_C(0); + char str0[256], str1[256]; + + sprintf (str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647)); + if (0 != strcmp (str0, "2147483647")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0)); + if (atoi(PRINTF_INT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", PRINTF_INT32_DEC_WIDTH)); + sprintf (str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295)); + if (0 != strcmp (str0, "4294967295")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0)); + if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", PRINTF_UINT32_DEC_WIDTH)); +#ifdef INT64_MAX + sprintf (str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807)); + if (0 != strcmp (str1, "9223372036854775807")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1)); + if (atoi(PRINTF_INT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_INT64_DEC_WIDTH : %s, %d\n", PRINTF_INT64_DEC_WIDTH, (int) strlen(str1))); + sprintf (str1, "%" PRINTF_INT64_MODIFIER "u", UINT64_C(18446744073709550591)); + if (0 != strcmp (str1, "18446744073709550591")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1)); + if (atoi(PRINTF_UINT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_UINT64_DEC_WIDTH : %s, %d\n", PRINTF_UINT64_DEC_WIDTH, (int) strlen(str1))); +#endif + + sprintf (str0, "%d %x\n", 0, ~0); + + sprintf (str1, "%d %x\n", i8, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i8 : %s\n", str1)); + sprintf (str1, "%u %x\n", u8, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u8 : %s\n", str1)); + sprintf (str1, "%d %x\n", i16, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i16 : %s\n", str1)); + sprintf (str1, "%u %x\n", u16, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u16 : %s\n", str1)); + sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i32 : %s\n", str1)); + sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u32 : %s\n", str1)); +#ifdef INT64_MAX + sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i64 : %s\n", str1)); +#endif + sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with imax : %s\n", str1)); + sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0); + if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with umax : %s\n", str1)); + + TESTUMAX(8); + TESTUMAX(16); + TESTUMAX(32); +#ifdef INT64_MAX + TESTUMAX(64); +#endif + +#define STR(v) #v +#define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v)); + if (err_n) { + printf ("pstdint.h is not correct. Please use sizes below to correct it:\n"); + } + + Q(int) + Q(unsigned) + Q(long int) + Q(short int) + Q(int8_t) + Q(int16_t) + Q(int32_t) +#ifdef INT64_MAX + Q(int64_t) +#endif + + return EXIT_SUCCESS; +} + +#endif diff --git a/third_party/nanoarrow/include/flatcc/portable/punaligned.h b/third_party/nanoarrow/include/flatcc/portable/punaligned.h new file mode 100644 index 0000000..a7e1f23 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/punaligned.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2016 Mikkel Fahnøe Jørgensen, dvide.com + * + * (MIT License) + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + +#ifndef PUNLIGNED_H +#define PUNLIGNED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PORTABLE_UNALIGNED_ACCESS + +#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) +#define PORTABLE_UNALIGNED_ACCESS 1 +#else +#define PORTABLE_UNALIGNED_ACCESS 0 +#endif + +#endif + +/* `unaligned_read_16` might not be defined if endianness was not determined. */ +#if !defined(unaligned_read_le16toh) + +#include "pendian.h" + +#ifndef UINT8_MAX +#include +#endif + +#if PORTABLE_UNALIGNED_ACCESS + +#define unaligned_read_16(p) (*(uint16_t*)(p)) +#define unaligned_read_32(p) (*(uint32_t*)(p)) +#define unaligned_read_64(p) (*(uint64_t*)(p)) + +#define unaligned_read_le16toh(p) le16toh(*(uint16_t*)(p)) +#define unaligned_read_le32toh(p) le32toh(*(uint32_t*)(p)) +#define unaligned_read_le64toh(p) le64toh(*(uint64_t*)(p)) + +#define unaligned_read_be16toh(p) be16toh(*(uint16_t*)(p)) +#define unaligned_read_be32toh(p) be32toh(*(uint32_t*)(p)) +#define unaligned_read_be64toh(p) be64toh(*(uint64_t*)(p)) + +#define unaligned_write_16(p, v) (*(uint16_t*)(p) = (uint16_t)(v)) +#define unaligned_write_32(p, v) (*(uint32_t*)(p) = (uint32_t)(v)) +#define unaligned_write_64(p, v) (*(uint64_t*)(p) = (uint64_t)(v)) + +#define unaligned_write_htole16(p, v) (*(uint16_t*)(p) = htole16(v)) +#define unaligned_write_htole32(p, v) (*(uint32_t*)(p) = htole32(v)) +#define unaligned_write_htole64(p, v) (*(uint64_t*)(p) = htole64(v)) + +#define unaligned_write_htobe16(p, v) (*(uint16_t*)(p) = htobe16(v)) +#define unaligned_write_htobe32(p, v) (*(uint32_t*)(p) = htobe32(v)) +#define unaligned_write_htobe64(p, v) (*(uint64_t*)(p) = htobe64(v)) + +#else + +#define unaligned_read_le16toh(p) ( \ + (((uint16_t)(((uint8_t *)(p))[0])) << 0) | \ + (((uint16_t)(((uint8_t *)(p))[1])) << 8)) + +#define unaligned_read_le32toh(p) ( \ + (((uint32_t)(((uint8_t *)(p))[0])) << 0) | \ + (((uint32_t)(((uint8_t *)(p))[1])) << 8) | \ + (((uint32_t)(((uint8_t *)(p))[2])) << 16) | \ + (((uint32_t)(((uint8_t *)(p))[3])) << 24)) + +#define unaligned_read_le64toh(p) ( \ + (((uint64_t)(((uint8_t *)(p))[0])) << 0) | \ + (((uint64_t)(((uint8_t *)(p))[1])) << 8) | \ + (((uint64_t)(((uint8_t *)(p))[2])) << 16) | \ + (((uint64_t)(((uint8_t *)(p))[3])) << 24) | \ + (((uint64_t)(((uint8_t *)(p))[4])) << 32) | \ + (((uint64_t)(((uint8_t *)(p))[5])) << 40) | \ + (((uint64_t)(((uint8_t *)(p))[6])) << 48) | \ + (((uint64_t)(((uint8_t *)(p))[7])) << 56)) + +#define unaligned_read_be16toh(p) ( \ + (((uint16_t)(((uint8_t *)(p))[0])) << 8) | \ + (((uint16_t)(((uint8_t *)(p))[1])) << 0)) + +#define unaligned_read_be32toh(p) ( \ + (((uint32_t)(((uint8_t *)(p))[0])) << 24) | \ + (((uint32_t)(((uint8_t *)(p))[1])) << 16) | \ + (((uint32_t)(((uint8_t *)(p))[2])) << 8) | \ + (((uint32_t)(((uint8_t *)(p))[3])) << 0)) + +#define unaligned_read_be64toh(p) ( \ + (((uint64_t)(((uint8_t *)(p))[0])) << 56) | \ + (((uint64_t)(((uint8_t *)(p))[1])) << 48) | \ + (((uint64_t)(((uint8_t *)(p))[2])) << 40) | \ + (((uint64_t)(((uint8_t *)(p))[3])) << 32) | \ + (((uint64_t)(((uint8_t *)(p))[4])) << 24) | \ + (((uint64_t)(((uint8_t *)(p))[5])) << 16) | \ + (((uint64_t)(((uint8_t *)(p))[6])) << 8) | \ + (((uint64_t)(((uint8_t *)(p))[7])) << 0)) + +#define unaligned_write_htole16(p, v) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint16_t)(v)) >> 0); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint16_t)(v)) >> 8); \ + } while (0) + +#define unaligned_write_htole32(p, v) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint32_t)(v)) >> 0); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint32_t)(v)) >> 8); \ + ((uint8_t *)(p))[2] = (uint8_t)(((uint32_t)(v)) >> 16); \ + ((uint8_t *)(p))[3] = (uint8_t)(((uint32_t)(v)) >> 24); \ + } while (0) + +#define unaligned_write_htole64(p, v) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint64_t)(v)) >> 0); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint64_t)(v)) >> 8); \ + ((uint8_t *)(p))[2] = (uint8_t)(((uint64_t)(v)) >> 16); \ + ((uint8_t *)(p))[3] = (uint8_t)(((uint64_t)(v)) >> 24); \ + ((uint8_t *)(p))[4] = (uint8_t)(((uint64_t)(v)) >> 32); \ + ((uint8_t *)(p))[5] = (uint8_t)(((uint64_t)(v)) >> 40); \ + ((uint8_t *)(p))[6] = (uint8_t)(((uint64_t)(v)) >> 48); \ + ((uint8_t *)(p))[7] = (uint8_t)(((uint64_t)(v)) >> 56); \ + } while (0) + +#define unaligned_write_htobe16(p, v) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint16_t)(v)) >> 8); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint16_t)(v)) >> 0); \ + } while (0) + +#define unaligned_write_htobe32(p, v) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint32_t)(v)) >> 24); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint32_t)(v)) >> 16); \ + ((uint8_t *)(p))[2] = (uint8_t)(((uint32_t)(v)) >> 8); \ + ((uint8_t *)(p))[3] = (uint8_t)(((uint32_t)(v)) >> 0); \ + } while (0) + +#define unaligned_write_htobe64(p) do { \ + ((uint8_t *)(p))[0] = (uint8_t)(((uint64_t)(v)) >> 56); \ + ((uint8_t *)(p))[1] = (uint8_t)(((uint64_t)(v)) >> 48); \ + ((uint8_t *)(p))[2] = (uint8_t)(((uint64_t)(v)) >> 40); \ + ((uint8_t *)(p))[3] = (uint8_t)(((uint64_t)(v)) >> 32); \ + ((uint8_t *)(p))[4] = (uint8_t)(((uint64_t)(v)) >> 24); \ + ((uint8_t *)(p))[5] = (uint8_t)(((uint64_t)(v)) >> 16); \ + ((uint8_t *)(p))[6] = (uint8_t)(((uint64_t)(v)) >> 8); \ + ((uint8_t *)(p))[7] = (uint8_t)(((uint64_t)(v)) >> 0); \ + } while (0) + +#if __LITTLE_ENDIAN__ +#define unaligned_read_16(p) unaligned_read_le16toh(p) +#define unaligned_read_32(p) unaligned_read_le32toh(p) +#define unaligned_read_64(p) unaligned_read_le64toh(p) + +#define unaligned_write_16(p) unaligned_write_htole16(p) +#define unaligned_write_32(p) unaligned_write_htole32(p) +#define unaligned_write_64(p) unaligned_write_htole64(p) +#endif + +#if __BIG_ENDIAN__ +#define unaligned_read_16(p) unaligned_read_be16toh(p) +#define unaligned_read_32(p) unaligned_read_be32toh(p) +#define unaligned_read_64(p) unaligned_read_be64toh(p) + +#define unaligned_write_16(p) unaligned_write_htobe16(p) +#define unaligned_write_32(p) unaligned_write_htobe32(p) +#define unaligned_write_64(p) unaligned_write_htobe64(p) +#endif + +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PUNALIGNED_H */ diff --git a/third_party/nanoarrow/include/flatcc/portable/pversion.h b/third_party/nanoarrow/include/flatcc/portable/pversion.h new file mode 100644 index 0000000..d434104 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pversion.h @@ -0,0 +1,6 @@ +#define PORTABLE_VERSION_TEXT "0.2.6-pre" +#define PORTABLE_VERSION_MAJOR 0 +#define PORTABLE_VERSION_MINOR 2 +#define PORTABLE_VERSION_PATCH 6 +/* 1 or 0 */ +#define PORTABLE_VERSION_RELEASED 0 diff --git a/third_party/nanoarrow/include/flatcc/portable/pwarnings.h b/third_party/nanoarrow/include/flatcc/portable/pwarnings.h new file mode 100644 index 0000000..f420861 --- /dev/null +++ b/third_party/nanoarrow/include/flatcc/portable/pwarnings.h @@ -0,0 +1,52 @@ +#ifndef PWARNINGS_H +#define PWARNINGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * See also pdiagnostics.h headers for per file control of common + * warnings. + * + * This file is intended for global disabling of warnings that shouldn't + * be present in C11 or perhaps C99, or a generally just noise where + * recent clang / gcc compile cleanly with high warning levels. + */ + +#if defined(_MSC_VER) +/* Needed when flagging code in or out and more. */ +#pragma warning(disable: 4127) /* conditional expression is constant */ +/* happens also in MS's own headers. */ +#pragma warning(disable: 4668) /* preprocessor name not defined */ +/* MSVC does not respect double parenthesis for intent */ +#pragma warning(disable: 4706) /* assignment within conditional expression */ +/* `inline` only advisory anyway. */ +#pragma warning(disable: 4710) /* function not inlined */ +/* Well, we don't intend to add the padding manually. */ +#pragma warning(disable: 4820) /* x bytes padding added in struct */ + +/* + * Don't warn that fopen etc. are unsafe + * + * Define a compiler flag like `-D_CRT_SECURE_NO_WARNINGS` in the build. + * For some reason it doesn't work when defined here. + * + * #define _CRT_SECURE_NO_WARNINGS + */ + +/* + * Anonymous union in struct is valid in C11 and has been supported in + * GCC and Clang for a while, but it is not C99. MSVC also handles it, + * but warns. Truly portable code should perhaps not use this feature, + * but this is not the place to complain about it. + */ +#pragma warning(disable: 4201) /* nonstandard extension used: nameless struct/union */ + +#endif /* _MSV_VER */ + +#ifdef __cplusplus +} +#endif + +#endif /* PWARNINGS_H */ diff --git a/third_party/nanoarrow/include/nanoarrow/nanoarrow.h b/third_party/nanoarrow/include/nanoarrow/nanoarrow.h new file mode 100644 index 0000000..7654fda --- /dev/null +++ b/third_party/nanoarrow/include/nanoarrow/nanoarrow.h @@ -0,0 +1,4482 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_CONFIG_H_INCLUDED +#define NANOARROW_CONFIG_H_INCLUDED + +#define NANOARROW_VERSION_MAJOR 0 +#define NANOARROW_VERSION_MINOR 8 +#define NANOARROW_VERSION_PATCH 0 +#define NANOARROW_VERSION "0.8.0" + +#define NANOARROW_VERSION_INT \ + (NANOARROW_VERSION_MAJOR * 10000 + NANOARROW_VERSION_MINOR * 100 + \ + NANOARROW_VERSION_PATCH) + +#define NANOARROW_NAMESPACE PgStatCh + +#if !defined(NANOARROW_CXX_NAMESPACE) +#define NANOARROW_CXX_NAMESPACE nanoarrow +#endif + +#define NANOARROW_CXX_NAMESPACE_BEGIN namespace NANOARROW_CXX_NAMESPACE { +#define NANOARROW_CXX_NAMESPACE_END } + +#endif +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_NANOARROW_TYPES_H_INCLUDED +#define NANOARROW_NANOARROW_TYPES_H_INCLUDED + +#include +#include + + + +#if defined(NANOARROW_DEBUG) && !defined(NANOARROW_PRINT_AND_DIE) +#include +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// Extra guard for versions of Arrow without the canonical guard +#ifndef ARROW_FLAG_DICTIONARY_ORDERED + +/// \defgroup nanoarrow-arrow-cdata Arrow C Data interface +/// +/// The Arrow C Data (https://arrow.apache.org/docs/format/CDataInterface.html) +/// and Arrow C Stream (https://arrow.apache.org/docs/format/CStreamInterface.html) +/// interfaces are part of the +/// Arrow Columnar Format specification +/// (https://arrow.apache.org/docs/format/Columnar.html). See the Arrow documentation for +/// documentation of these structures. +/// +/// @{ + +#ifndef ARROW_C_DATA_INTERFACE +#define ARROW_C_DATA_INTERFACE + +#define ARROW_FLAG_DICTIONARY_ORDERED 1 +#define ARROW_FLAG_NULLABLE 2 +#define ARROW_FLAG_MAP_KEYS_SORTED 4 + +struct ArrowSchema { + // Array type description + const char* format; + const char* name; + const char* metadata; + int64_t flags; + int64_t n_children; + struct ArrowSchema** children; + struct ArrowSchema* dictionary; + + // Release callback + void (*release)(struct ArrowSchema*); + // Opaque producer-specific data + void* private_data; +}; + +struct ArrowArray { + // Array data description + int64_t length; + int64_t null_count; + int64_t offset; + int64_t n_buffers; + int64_t n_children; + const void** buffers; + struct ArrowArray** children; + struct ArrowArray* dictionary; + + // Release callback + void (*release)(struct ArrowArray*); + // Opaque producer-specific data + void* private_data; +}; + +#endif // ARROW_C_DATA_INTERFACE + +#ifndef ARROW_C_STREAM_INTERFACE +#define ARROW_C_STREAM_INTERFACE + +struct ArrowArrayStream { + // Callback to get the stream type + // (will be the same for all arrays in the stream). + // + // Return value: 0 if successful, an `errno`-compatible error code otherwise. + // + // If successful, the ArrowSchema must be released independently from the stream. + int (*get_schema)(struct ArrowArrayStream*, struct ArrowSchema* out); + + // Callback to get the next array + // (if no error and the array is released, the stream has ended) + // + // Return value: 0 if successful, an `errno`-compatible error code otherwise. + // + // If successful, the ArrowArray must be released independently from the stream. + int (*get_next)(struct ArrowArrayStream*, struct ArrowArray* out); + + // Callback to get optional detailed error information. + // This must only be called if the last stream operation failed + // with a non-0 return code. + // + // Return value: pointer to a null-terminated character array describing + // the last error, or NULL if no description is available. + // + // The returned pointer is only valid until the next operation on this stream + // (including release). + const char* (*get_last_error)(struct ArrowArrayStream*); + + // Release callback: release the stream's own resources. + // Note that arrays returned by `get_next` must be individually released. + void (*release)(struct ArrowArrayStream*); + + // Opaque producer-specific data + void* private_data; +}; + +#endif // ARROW_C_STREAM_INTERFACE +#endif // ARROW_FLAG_DICTIONARY_ORDERED + +/// @} + +// Utility macros +#define _NANOARROW_CONCAT(x, y) x##y +#define _NANOARROW_MAKE_NAME(x, y) _NANOARROW_CONCAT(x, y) + +#define _NANOARROW_RETURN_NOT_OK_IMPL(NAME, EXPR) \ + do { \ + const int NAME = (EXPR); \ + if (NAME) return NAME; \ + } while (0) + +#define _NANOARROW_CHECK_RANGE(x_, min_, max_) \ + NANOARROW_RETURN_NOT_OK((x_ >= min_ && x_ <= max_) ? NANOARROW_OK : EINVAL) + +#define _NANOARROW_CHECK_UPPER_LIMIT(x_, max_) \ + NANOARROW_RETURN_NOT_OK((x_ <= max_) ? NANOARROW_OK : EINVAL) + +#if defined(NANOARROW_DEBUG) +#define _NANOARROW_RETURN_NOT_OK_WITH_ERROR_IMPL(NAME, EXPR, ERROR_PTR_EXPR, EXPR_STR) \ + do { \ + const int NAME = (EXPR); \ + if (NAME) { \ + ArrowErrorSet((ERROR_PTR_EXPR), "%s failed with errno %d\n* %s:%d", EXPR_STR, \ + NAME, __FILE__, __LINE__); \ + return NAME; \ + } \ + } while (0) +#else +#define _NANOARROW_RETURN_NOT_OK_WITH_ERROR_IMPL(NAME, EXPR, ERROR_PTR_EXPR, EXPR_STR) \ + do { \ + const int NAME = (EXPR); \ + if (NAME) { \ + ArrowErrorSet((ERROR_PTR_EXPR), "%s failed with errno %d", EXPR_STR, NAME); \ + return NAME; \ + } \ + } while (0) +#endif + +#if defined(NANOARROW_DEBUG) +// For checking ArrowErrorSet() calls for valid printf format strings/arguments +// If using mingw's c99-compliant printf, we need a different format-checking attribute +#if defined(__USE_MINGW_ANSI_STDIO) && defined(__MINGW_PRINTF_FORMAT) +#define NANOARROW_CHECK_PRINTF_ATTRIBUTE \ + __attribute__((format(__MINGW_PRINTF_FORMAT, 2, 3))) +#elif defined(__GNUC__) +#define NANOARROW_CHECK_PRINTF_ATTRIBUTE __attribute__((format(printf, 2, 3))) +#else +#define NANOARROW_CHECK_PRINTF_ATTRIBUTE +#endif + +// For checking calls to functions that return ArrowErrorCode +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define NANOARROW_CHECK_RETURN_ATTRIBUTE __attribute__((warn_unused_result)) +#elif defined(_MSC_VER) && (_MSC_VER >= 1700) +#define NANOARROW_CHECK_RETURN_ATTRIBUTE _Check_return_ +#else +#define NANOARROW_CHECK_RETURN_ATTRIBUTE +#endif + +#else +#define NANOARROW_CHECK_RETURN_ATTRIBUTE +#define NANOARROW_CHECK_PRINTF_ATTRIBUTE +#endif + +#define NANOARROW_UNUSED(x) (void)(x) + +/// \brief Return code for success. +/// \ingroup nanoarrow-errors +#define NANOARROW_OK 0 + +/// \brief Represents an errno-compatible error code +/// \ingroup nanoarrow-errors +typedef int ArrowErrorCode; + +#if defined(NANOARROW_DEBUG) +#define ArrowErrorCode NANOARROW_CHECK_RETURN_ATTRIBUTE ArrowErrorCode +#endif + +/// \brief Flags supported by ArrowSchemaViewInit() +/// \ingroup nanoarrow-schema-view +#define NANOARROW_FLAG_ALL_SUPPORTED \ + (ARROW_FLAG_DICTIONARY_ORDERED | ARROW_FLAG_NULLABLE | ARROW_FLAG_MAP_KEYS_SORTED) + +/// \brief Error type containing a UTF-8 encoded message. +/// \ingroup nanoarrow-errors +struct ArrowError { + /// \brief A character buffer with space for an error message. + char message[1024]; +}; + +/// \brief Ensure an ArrowError is null-terminated by zeroing the first character. +/// \ingroup nanoarrow-errors +/// +/// If error is NULL, this function does nothing. +static inline void ArrowErrorInit(struct ArrowError* error) { + if (error != NULL) { + error->message[0] = '\0'; + } +} + +/// \brief Get the contents of an error +/// \ingroup nanoarrow-errors +/// +/// If error is NULL, returns "", or returns the contents of the error message +/// otherwise. +static inline const char* ArrowErrorMessage(struct ArrowError* error) { + if (error == NULL) { + return ""; + } else { + return error->message; + } +} + +/// \brief Set the contents of an error from an existing null-terminated string +/// \ingroup nanoarrow-errors +/// +/// If error is NULL, this function does nothing. +static inline void ArrowErrorSetString(struct ArrowError* error, const char* src) { + if (error == NULL) { + return; + } + + int64_t src_len = strlen(src); + if (src_len >= ((int64_t)sizeof(error->message))) { + memcpy(error->message, src, sizeof(error->message) - 1); + error->message[sizeof(error->message) - 1] = '\0'; + } else { + memcpy(error->message, src, src_len); + error->message[src_len] = '\0'; + } +} + +/// \brief Check the result of an expression and return it if not NANOARROW_OK +/// \ingroup nanoarrow-errors +#define NANOARROW_RETURN_NOT_OK(EXPR) \ + _NANOARROW_RETURN_NOT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR) + +/// \brief Check the result of an expression and return it if not NANOARROW_OK, +/// adding an auto-generated message to an ArrowError. +/// \ingroup nanoarrow-errors +/// +/// This macro is used to ensure that functions that accept an ArrowError +/// as input always set its message when returning an error code (e.g., when calling +/// a nanoarrow function that does *not* accept ArrowError). +#define NANOARROW_RETURN_NOT_OK_WITH_ERROR(EXPR, ERROR_EXPR) \ + _NANOARROW_RETURN_NOT_OK_WITH_ERROR_IMPL( \ + _NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, ERROR_EXPR, #EXPR) + +#if defined(NANOARROW_DEBUG) && !defined(NANOARROW_PRINT_AND_DIE) +#define NANOARROW_PRINT_AND_DIE(VALUE, EXPR_STR) \ + do { \ + fprintf(stderr, "%s failed with code %d\n* %s:%d\n", EXPR_STR, (int)(VALUE), \ + __FILE__, (int)__LINE__); \ + abort(); \ + } while (0) +#endif + +#if defined(NANOARROW_DEBUG) +#define _NANOARROW_ASSERT_OK_IMPL(NAME, EXPR, EXPR_STR) \ + do { \ + const int NAME = (EXPR); \ + if (NAME) NANOARROW_PRINT_AND_DIE(NAME, EXPR_STR); \ + } while (0) + +/// \brief Assert that an expression's value is NANOARROW_OK +/// \ingroup nanoarrow-errors +/// +/// If nanoarrow was built in debug mode (i.e., defined(NANOARROW_DEBUG) is true), +/// print a message to stderr and abort. If nanoarrow was built in release mode, +/// this statement has no effect. You can customize fatal error behaviour +/// be defining the NANOARROW_PRINT_AND_DIE macro before including nanoarrow.h +/// This macro is provided as a convenience for users and is not used internally. +#define NANOARROW_ASSERT_OK(EXPR) \ + _NANOARROW_ASSERT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, #EXPR) + +#define _NANOARROW_DCHECK_IMPL(EXPR, EXPR_STR) \ + do { \ + if (!(EXPR)) NANOARROW_PRINT_AND_DIE(-1, EXPR_STR); \ + } while (0) + +#define NANOARROW_DCHECK(EXPR) _NANOARROW_DCHECK_IMPL(EXPR, #EXPR) +#else +#define NANOARROW_ASSERT_OK(EXPR) (void)(EXPR) +#define NANOARROW_DCHECK(EXPR) +#endif + +static inline void ArrowSchemaMove(struct ArrowSchema* src, struct ArrowSchema* dst) { + NANOARROW_DCHECK(src != NULL); + NANOARROW_DCHECK(dst != NULL); + + memcpy(dst, src, sizeof(struct ArrowSchema)); + src->release = NULL; +} + +static inline void ArrowSchemaRelease(struct ArrowSchema* schema) { + NANOARROW_DCHECK(schema != NULL); + schema->release(schema); + NANOARROW_DCHECK(schema->release == NULL); +} + +static inline void ArrowArrayMove(struct ArrowArray* src, struct ArrowArray* dst) { + NANOARROW_DCHECK(src != NULL); + NANOARROW_DCHECK(dst != NULL); + + memcpy(dst, src, sizeof(struct ArrowArray)); + src->release = NULL; +} + +static inline void ArrowArrayRelease(struct ArrowArray* array) { + NANOARROW_DCHECK(array != NULL); + array->release(array); + NANOARROW_DCHECK(array->release == NULL); +} + +static inline void ArrowArrayStreamMove(struct ArrowArrayStream* src, + struct ArrowArrayStream* dst) { + NANOARROW_DCHECK(src != NULL); + NANOARROW_DCHECK(dst != NULL); + + memcpy(dst, src, sizeof(struct ArrowArrayStream)); + src->release = NULL; +} + +static inline const char* ArrowArrayStreamGetLastError( + struct ArrowArrayStream* array_stream) { + NANOARROW_DCHECK(array_stream != NULL); + + const char* value = array_stream->get_last_error(array_stream); + if (value == NULL) { + return ""; + } else { + return value; + } +} + +static inline ArrowErrorCode ArrowArrayStreamGetSchema( + struct ArrowArrayStream* array_stream, struct ArrowSchema* out, + struct ArrowError* error) { + NANOARROW_DCHECK(array_stream != NULL); + + int result = array_stream->get_schema(array_stream, out); + if (result != NANOARROW_OK && error != NULL) { + ArrowErrorSetString(error, ArrowArrayStreamGetLastError(array_stream)); + } + + return result; +} + +static inline ArrowErrorCode ArrowArrayStreamGetNext( + struct ArrowArrayStream* array_stream, struct ArrowArray* out, + struct ArrowError* error) { + NANOARROW_DCHECK(array_stream != NULL); + + int result = array_stream->get_next(array_stream, out); + if (result != NANOARROW_OK && error != NULL) { + ArrowErrorSetString(error, ArrowArrayStreamGetLastError(array_stream)); + } + + return result; +} + +static inline void ArrowArrayStreamRelease(struct ArrowArrayStream* array_stream) { + NANOARROW_DCHECK(array_stream != NULL); + array_stream->release(array_stream); + NANOARROW_DCHECK(array_stream->release == NULL); +} + +static char _ArrowIsLittleEndian(void) { + uint32_t check = 1; + char first_byte; + memcpy(&first_byte, &check, sizeof(char)); + return first_byte; +} + +/// \brief Arrow type enumerator +/// \ingroup nanoarrow-utils +/// +/// These names are intended to map to the corresponding arrow::Type::type +/// enumerator; however, the numeric values are specifically not equal +/// (i.e., do not rely on numeric comparison). +enum ArrowType { + NANOARROW_TYPE_UNINITIALIZED = 0, + NANOARROW_TYPE_NA = 1, + NANOARROW_TYPE_BOOL, + NANOARROW_TYPE_UINT8, + NANOARROW_TYPE_INT8, + NANOARROW_TYPE_UINT16, + NANOARROW_TYPE_INT16, + NANOARROW_TYPE_UINT32, + NANOARROW_TYPE_INT32, + NANOARROW_TYPE_UINT64, + NANOARROW_TYPE_INT64, + NANOARROW_TYPE_HALF_FLOAT, + NANOARROW_TYPE_FLOAT, + NANOARROW_TYPE_DOUBLE, + NANOARROW_TYPE_STRING, + NANOARROW_TYPE_BINARY, + NANOARROW_TYPE_FIXED_SIZE_BINARY, + NANOARROW_TYPE_DATE32, + NANOARROW_TYPE_DATE64, + NANOARROW_TYPE_TIMESTAMP, + NANOARROW_TYPE_TIME32, + NANOARROW_TYPE_TIME64, + NANOARROW_TYPE_INTERVAL_MONTHS, + NANOARROW_TYPE_INTERVAL_DAY_TIME, + NANOARROW_TYPE_DECIMAL128, + NANOARROW_TYPE_DECIMAL256, + NANOARROW_TYPE_LIST, + NANOARROW_TYPE_STRUCT, + NANOARROW_TYPE_SPARSE_UNION, + NANOARROW_TYPE_DENSE_UNION, + NANOARROW_TYPE_DICTIONARY, + NANOARROW_TYPE_MAP, + NANOARROW_TYPE_EXTENSION, + NANOARROW_TYPE_FIXED_SIZE_LIST, + NANOARROW_TYPE_DURATION, + NANOARROW_TYPE_LARGE_STRING, + NANOARROW_TYPE_LARGE_BINARY, + NANOARROW_TYPE_LARGE_LIST, + NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO, + NANOARROW_TYPE_RUN_END_ENCODED, + NANOARROW_TYPE_BINARY_VIEW, + NANOARROW_TYPE_STRING_VIEW, + NANOARROW_TYPE_DECIMAL32, + NANOARROW_TYPE_DECIMAL64, + NANOARROW_TYPE_LIST_VIEW, + NANOARROW_TYPE_LARGE_LIST_VIEW, +}; + +/// \brief Get a string value of an enum ArrowType value +/// \ingroup nanoarrow-utils +/// +/// Returns NULL for invalid values for type +static inline const char* ArrowTypeString(enum ArrowType type); + +static inline const char* ArrowTypeString(enum ArrowType type) { + switch (type) { + case NANOARROW_TYPE_NA: + return "na"; + case NANOARROW_TYPE_BOOL: + return "bool"; + case NANOARROW_TYPE_UINT8: + return "uint8"; + case NANOARROW_TYPE_INT8: + return "int8"; + case NANOARROW_TYPE_UINT16: + return "uint16"; + case NANOARROW_TYPE_INT16: + return "int16"; + case NANOARROW_TYPE_UINT32: + return "uint32"; + case NANOARROW_TYPE_INT32: + return "int32"; + case NANOARROW_TYPE_UINT64: + return "uint64"; + case NANOARROW_TYPE_INT64: + return "int64"; + case NANOARROW_TYPE_HALF_FLOAT: + return "half_float"; + case NANOARROW_TYPE_FLOAT: + return "float"; + case NANOARROW_TYPE_DOUBLE: + return "double"; + case NANOARROW_TYPE_STRING: + return "string"; + case NANOARROW_TYPE_BINARY: + return "binary"; + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + return "fixed_size_binary"; + case NANOARROW_TYPE_DATE32: + return "date32"; + case NANOARROW_TYPE_DATE64: + return "date64"; + case NANOARROW_TYPE_TIMESTAMP: + return "timestamp"; + case NANOARROW_TYPE_TIME32: + return "time32"; + case NANOARROW_TYPE_TIME64: + return "time64"; + case NANOARROW_TYPE_INTERVAL_MONTHS: + return "interval_months"; + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + return "interval_day_time"; + case NANOARROW_TYPE_DECIMAL32: + return "decimal32"; + case NANOARROW_TYPE_DECIMAL64: + return "decimal64"; + case NANOARROW_TYPE_DECIMAL128: + return "decimal128"; + case NANOARROW_TYPE_DECIMAL256: + return "decimal256"; + case NANOARROW_TYPE_LIST: + return "list"; + case NANOARROW_TYPE_STRUCT: + return "struct"; + case NANOARROW_TYPE_SPARSE_UNION: + return "sparse_union"; + case NANOARROW_TYPE_DENSE_UNION: + return "dense_union"; + case NANOARROW_TYPE_DICTIONARY: + return "dictionary"; + case NANOARROW_TYPE_MAP: + return "map"; + case NANOARROW_TYPE_EXTENSION: + return "extension"; + case NANOARROW_TYPE_FIXED_SIZE_LIST: + return "fixed_size_list"; + case NANOARROW_TYPE_DURATION: + return "duration"; + case NANOARROW_TYPE_LARGE_STRING: + return "large_string"; + case NANOARROW_TYPE_LARGE_BINARY: + return "large_binary"; + case NANOARROW_TYPE_LARGE_LIST: + return "large_list"; + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + return "interval_month_day_nano"; + case NANOARROW_TYPE_RUN_END_ENCODED: + return "run_end_encoded"; + case NANOARROW_TYPE_BINARY_VIEW: + return "binary_view"; + case NANOARROW_TYPE_STRING_VIEW: + return "string_view"; + case NANOARROW_TYPE_LIST_VIEW: + return "list_view"; + case NANOARROW_TYPE_LARGE_LIST_VIEW: + return "large_list_view"; + default: + return NULL; + } +} + +/// \brief Arrow time unit enumerator +/// \ingroup nanoarrow-utils +/// +/// These names and values map to the corresponding arrow::TimeUnit::type +/// enumerator. +enum ArrowTimeUnit { + NANOARROW_TIME_UNIT_SECOND = 0, + NANOARROW_TIME_UNIT_MILLI = 1, + NANOARROW_TIME_UNIT_MICRO = 2, + NANOARROW_TIME_UNIT_NANO = 3 +}; + +/// \brief Validation level enumerator +/// \ingroup nanoarrow-array +enum ArrowValidationLevel { + /// \brief Do not validate buffer sizes or content. + NANOARROW_VALIDATION_LEVEL_NONE = 0, + + /// \brief Validate buffer sizes that depend on array length but do not validate buffer + /// sizes that depend on buffer data access. + NANOARROW_VALIDATION_LEVEL_MINIMAL = 1, + + /// \brief Validate all buffer sizes, including those that require buffer data access, + /// but do not perform any checks that are O(1) along the length of the buffers. + NANOARROW_VALIDATION_LEVEL_DEFAULT = 2, + + /// \brief Validate all buffer sizes and all buffer content. This is useful in the + /// context of untrusted input or input that may have been corrupted in transit. + NANOARROW_VALIDATION_LEVEL_FULL = 3 +}; + +/// \brief Comparison level enumerator +/// \ingroup nanoarrow-utils +enum ArrowCompareLevel { + /// \brief Consider arrays equal if buffers contain identical content + /// and have identical offset, null count, and length. Note that this is + /// a much stricter check than logical equality, which would take into + /// account potentially different content of null slots, arrays with a + /// non-zero offset, and other considerations. + NANOARROW_COMPARE_IDENTICAL, +}; + +/// \brief Get a string value of an enum ArrowTimeUnit value +/// \ingroup nanoarrow-utils +/// +/// Returns NULL for invalid values for time_unit +static inline const char* ArrowTimeUnitString(enum ArrowTimeUnit time_unit); + +static inline const char* ArrowTimeUnitString(enum ArrowTimeUnit time_unit) { + switch (time_unit) { + case NANOARROW_TIME_UNIT_SECOND: + return "s"; + case NANOARROW_TIME_UNIT_MILLI: + return "ms"; + case NANOARROW_TIME_UNIT_MICRO: + return "us"; + case NANOARROW_TIME_UNIT_NANO: + return "ns"; + default: + return NULL; + } +} + +/// \brief Functional types of buffers as described in the Arrow Columnar Specification +/// \ingroup nanoarrow-array-view +enum ArrowBufferType { + NANOARROW_BUFFER_TYPE_NONE, + NANOARROW_BUFFER_TYPE_VALIDITY, + NANOARROW_BUFFER_TYPE_TYPE_ID, + NANOARROW_BUFFER_TYPE_UNION_OFFSET, + NANOARROW_BUFFER_TYPE_DATA_OFFSET, + NANOARROW_BUFFER_TYPE_DATA, + NANOARROW_BUFFER_TYPE_VARIADIC_DATA, + NANOARROW_BUFFER_TYPE_VARIADIC_SIZE, + NANOARROW_BUFFER_TYPE_VIEW_OFFSET, + NANOARROW_BUFFER_TYPE_SIZE, +}; + +/// \brief The maximum number of fixed buffers in an ArrowArrayView or ArrowLayout +/// \ingroup nanoarrow-array-view +#define NANOARROW_MAX_FIXED_BUFFERS 3 + +/// \brief An non-owning view of a string +/// \ingroup nanoarrow-utils +struct ArrowStringView { + /// \brief A pointer to the start of the string + /// + /// If size_bytes is 0, this value may be NULL. + const char* data; + + /// \brief The size of the string in bytes, + /// + /// (Not including the null terminator.) + int64_t size_bytes; +}; + +/// \brief Return a view of a const C string +/// \ingroup nanoarrow-utils +static inline struct ArrowStringView ArrowCharView(const char* value); + +static inline struct ArrowStringView ArrowCharView(const char* value) { + struct ArrowStringView out; + + out.data = value; + if (value) { + out.size_bytes = (int64_t)strlen(value); + } else { + out.size_bytes = 0; + } + + return out; +} + +union ArrowBufferViewData { + const void* data; + const int8_t* as_int8; + const uint8_t* as_uint8; + const int16_t* as_int16; + const uint16_t* as_uint16; + const int32_t* as_int32; + const uint32_t* as_uint32; + const int64_t* as_int64; + const uint64_t* as_uint64; + const double* as_double; + const float* as_float; + const char* as_char; + const union ArrowBinaryView* as_binary_view; +}; + +/// \brief An non-owning view of a buffer +/// \ingroup nanoarrow-utils +struct ArrowBufferView { + /// \brief A pointer to the start of the buffer + /// + /// If size_bytes is 0, this value may be NULL. + union ArrowBufferViewData data; + + /// \brief The size of the buffer in bytes + int64_t size_bytes; +}; + +/// \brief Array buffer allocation and deallocation +/// \ingroup nanoarrow-buffer +/// +/// Container for allocate, reallocate, and free methods that can be used +/// to customize allocation and deallocation of buffers when constructing +/// an ArrowArray. +struct ArrowBufferAllocator { + /// \brief Reallocate a buffer or return NULL if it cannot be reallocated + uint8_t* (*reallocate)(struct ArrowBufferAllocator* allocator, uint8_t* ptr, + int64_t old_size, int64_t new_size); + + /// \brief Deallocate a buffer allocated by this allocator + void (*free)(struct ArrowBufferAllocator* allocator, uint8_t* ptr, int64_t size); + + /// \brief Opaque data specific to the allocator + void* private_data; +}; + +typedef void (*ArrowBufferDeallocatorCallback)(struct ArrowBufferAllocator* allocator, + uint8_t* ptr, int64_t size); + +/// \brief An owning mutable view of a buffer +/// \ingroup nanoarrow-buffer +struct ArrowBuffer { + /// \brief A pointer to the start of the buffer + /// + /// If capacity_bytes is 0, this value may be NULL. + uint8_t* data; + + /// \brief The size of the buffer in bytes + int64_t size_bytes; + + /// \brief The capacity of the buffer in bytes + int64_t capacity_bytes; + + /// \brief The allocator that will be used to reallocate and/or free the buffer + struct ArrowBufferAllocator allocator; +}; + +/// \brief An owning mutable view of a bitmap +/// \ingroup nanoarrow-bitmap +struct ArrowBitmap { + /// \brief An ArrowBuffer to hold the allocated memory + struct ArrowBuffer buffer; + + /// \brief The number of bits that have been appended to the bitmap + int64_t size_bits; +}; + +/// \brief A description of an arrangement of buffers +/// \ingroup nanoarrow-utils +/// +/// Contains the minimum amount of information required to +/// calculate the size of each buffer in an ArrowArray knowing only +/// the length and offset of the array. +struct ArrowLayout { + /// \brief The function of each buffer + enum ArrowBufferType buffer_type[NANOARROW_MAX_FIXED_BUFFERS]; + + /// \brief The data type of each buffer + enum ArrowType buffer_data_type[NANOARROW_MAX_FIXED_BUFFERS]; + + /// \brief The size of an element each buffer or 0 if this size is variable or unknown + int64_t element_size_bits[NANOARROW_MAX_FIXED_BUFFERS]; + + /// \brief The number of elements in the child array per element in this array for a + /// fixed-size list + int64_t child_size_elements; +}; + +/// \brief A non-owning view of an ArrowArray +/// \ingroup nanoarrow-array-view +/// +/// This data structure provides access to the values contained within +/// an ArrowArray with fields provided in a more readily-extractible +/// form. You can re-use an ArrowArrayView for multiple ArrowArrays +/// with the same storage type, use it to represent a hypothetical +/// ArrowArray that does not exist yet, or use it to validate the buffers +/// of a future ArrowArray. +struct ArrowArrayView { + /// \brief The underlying ArrowArray or NULL if it has not been set or + /// if the buffers in this ArrowArrayView are not backed by an ArrowArray. + const struct ArrowArray* array; + + /// \brief The number of elements from the physical start of the buffers. + int64_t offset; + + /// \brief The number of elements in this view. + int64_t length; + + /// \brief A cached null count or -1 to indicate that this value is unknown. + int64_t null_count; + + /// \brief The type used to store values in this array + /// + /// This type represents only the minimum required information to + /// extract values from the array buffers (e.g., for a Date32 array, + /// this value will be NANOARROW_TYPE_INT32). For dictionary-encoded + /// arrays, this will be the index type. + enum ArrowType storage_type; + + /// \brief The buffer types, strides, and sizes of this Array's buffers + struct ArrowLayout layout; + + /// \brief This Array's buffers as ArrowBufferView objects + struct ArrowBufferView buffer_views[NANOARROW_MAX_FIXED_BUFFERS]; + + /// \brief The number of children of this view + int64_t n_children; + + /// \brief Pointers to views of this array's children + struct ArrowArrayView** children; + + /// \brief Pointer to a view of this array's dictionary + struct ArrowArrayView* dictionary; + + /// \brief Union type id to child index mapping + /// + /// If storage_type is a union type, a 256-byte ArrowMalloc()ed buffer + /// such that child_index == union_type_id_map[type_id] and + /// type_id == union_type_id_map[128 + child_index]. This value may be + /// NULL in the case where child_id == type_id. + int8_t* union_type_id_map; + + /// \brief Number of variadic buffers + int32_t n_variadic_buffers; + + /// \brief Pointers to variadic buffers of binary/string_view arrays + const void** variadic_buffers; + + /// \brief Size of each variadic buffer + int64_t* variadic_buffer_sizes; +}; + +// Used as the private data member for ArrowArrays allocated here and accessed +// internally within inline ArrowArray* helpers. +struct ArrowArrayPrivateData { + // Holder for the validity buffer (or first buffer for union types, which are + // the only type whose first buffer is not a valdiity buffer) + struct ArrowBitmap bitmap; + + // Holder for additional buffers as required + struct ArrowBuffer buffers[NANOARROW_MAX_FIXED_BUFFERS - 1]; + + // The array of pointers to buffers. This must be updated after a sequence + // of appends to synchronize its values with the actual buffer addresses + // (which may have been reallocated during that time) + const void** buffer_data; + + // The storage data type, or NANOARROW_TYPE_UNINITIALIZED if unknown + enum ArrowType storage_type; + + // The buffer arrangement for the storage type + struct ArrowLayout layout; + + // Flag to indicate if there are non-sequence union type ids. + // In the future this could be replaced with a type id<->child mapping + // to support constructing unions in append mode where type_id != child_index + int8_t union_type_id_is_child_index; + + // Number of variadic buffers for binary view types + int32_t n_variadic_buffers; + + // Variadic buffers for binary view types + struct ArrowBuffer* variadic_buffers; + + // The current offset used to build list views + int64_t list_view_offset; +}; + +/// \brief A representation of an interval. +/// \ingroup nanoarrow-utils +struct ArrowInterval { + /// \brief The type of interval being used + enum ArrowType type; + /// \brief The number of months represented by the interval + int32_t months; + /// \brief The number of days represented by the interval + int32_t days; + /// \brief The number of ms represented by the interval + int32_t ms; + /// \brief The number of ns represented by the interval + int64_t ns; +}; + +/// \brief Zero initialize an Interval with a given unit +/// \ingroup nanoarrow-utils +static inline void ArrowIntervalInit(struct ArrowInterval* interval, + enum ArrowType type) { + memset(interval, 0, sizeof(struct ArrowInterval)); + interval->type = type; +} + +/// \brief A representation of a fixed-precision decimal number +/// \ingroup nanoarrow-utils +/// +/// This structure should be initialized with ArrowDecimalInit() once and +/// values set using ArrowDecimalSetInt(), ArrowDecimalSetBytes128(), +/// or ArrowDecimalSetBytes256(). +struct ArrowDecimal { + /// \brief An array of 64-bit integers of n_words length defined in native-endian order. + /// For a 32-bit decimal value, index 0 will be a 32-bit integer value. + uint64_t words[4]; + + /// \brief The number of significant digits this decimal number can represent + int32_t precision; + + /// \brief The number of digits after the decimal point. This can be negative. + int32_t scale; + + /// \brief The number of 64-bit words in the words array. For the special case of a + /// 32-bit decimal value, this will be 0. + int n_words; + + /// \brief Cached value used by the implementation + int high_word_index; + + /// \brief Cached value used by the implementation + int low_word_index; +}; + +/// \brief Initialize a decimal with a given set of type parameters +/// \ingroup nanoarrow-utils +static inline void ArrowDecimalInit(struct ArrowDecimal* decimal, int32_t bitwidth, + int32_t precision, int32_t scale) { + memset(decimal->words, 0, sizeof(decimal->words)); + decimal->precision = precision; + decimal->scale = scale; + // n_words will be 0 for bitwidth == 32 + decimal->n_words = (int)(bitwidth / 8 / sizeof(uint64_t)); + + if (_ArrowIsLittleEndian()) { + decimal->low_word_index = 0; + decimal->high_word_index = decimal->n_words > 0 ? decimal->n_words - 1 : 0; + } else { + decimal->low_word_index = decimal->n_words > 0 ? decimal->n_words - 1 : 0; + decimal->high_word_index = 0; + } +} + +/// \brief Get a signed integer value of a sufficiently small ArrowDecimal +/// +/// This does not check if the decimal's precision sufficiently small to fit +/// within the signed 64-bit integer range (A precision less than or equal +/// to 18 is sufficiently small). +static inline int64_t ArrowDecimalGetIntUnsafe(const struct ArrowDecimal* decimal) { + if (decimal->n_words == 0) { + int32_t value; + memcpy(&value, decimal->words, sizeof(int32_t)); + return value; + } + + return (int64_t)decimal->words[decimal->low_word_index]; +} + +/// \brief Copy the bytes of this decimal into a sufficiently large buffer +/// \ingroup nanoarrow-utils +static inline void ArrowDecimalGetBytes(const struct ArrowDecimal* decimal, + uint8_t* out) { + if (decimal->n_words == 0) { + memcpy(out, decimal->words, sizeof(int32_t)); + } else { + memcpy(out, decimal->words, decimal->n_words * sizeof(uint64_t)); + } +} + +/// \brief Returns 1 if the value represented by decimal is >= 0 or -1 otherwise +/// \ingroup nanoarrow-utils +static inline int64_t ArrowDecimalSign(const struct ArrowDecimal* decimal) { + if (decimal->n_words == 0) { + return ArrowDecimalGetIntUnsafe(decimal) >= 0 ? 1 : -1; + } else { + return 1 | ((int64_t)(decimal->words[decimal->high_word_index]) >> 63); + } +} + +/// \brief Sets the integer value of this decimal +/// \ingroup nanoarrow-utils +static inline void ArrowDecimalSetInt(struct ArrowDecimal* decimal, int64_t value) { + if (decimal->n_words == 0) { + int32_t value32 = (int32_t)value; + memcpy(decimal->words, &value32, sizeof(int32_t)); + return; + } + + if (value < 0) { + memset(decimal->words, 0xff, decimal->n_words * sizeof(uint64_t)); + } else { + memset(decimal->words, 0, decimal->n_words * sizeof(uint64_t)); + } + + decimal->words[decimal->low_word_index] = value; +} + +/// \brief Negate the value of this decimal in place +/// \ingroup nanoarrow-utils +static inline void ArrowDecimalNegate(struct ArrowDecimal* decimal) { + if (decimal->n_words == 0) { + int32_t value; + memcpy(&value, decimal->words, sizeof(int32_t)); + value = -value; + memcpy(decimal->words, &value, sizeof(int32_t)); + return; + } + + uint64_t carry = 1; + + if (decimal->low_word_index == 0) { + for (int i = 0; i < decimal->n_words; i++) { + uint64_t elem = decimal->words[i]; + elem = ~elem + carry; + carry &= (elem == 0); + decimal->words[i] = elem; + } + } else { + for (int i = decimal->low_word_index; i >= 0; i--) { + uint64_t elem = decimal->words[i]; + elem = ~elem + carry; + carry &= (elem == 0); + decimal->words[i] = elem; + } + } +} + +/// \brief Copy bytes from a buffer into this decimal +/// \ingroup nanoarrow-utils +static inline void ArrowDecimalSetBytes(struct ArrowDecimal* decimal, + const uint8_t* value) { + if (decimal->n_words == 0) { + memcpy(decimal->words, value, sizeof(int32_t)); + } else { + memcpy(decimal->words, value, decimal->n_words * sizeof(uint64_t)); + } +} + +#ifdef __cplusplus +} +#endif + +#endif +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_H_INCLUDED +#define NANOARROW_H_INCLUDED + +#include +#include +#include + + + +// If using CMake, optionally pass -DNANOARROW_NAMESPACE=MyNamespace which will set this +// define in nanoarrow_config.h. If not, you can optionally #define NANOARROW_NAMESPACE +// MyNamespace here. + +// This section remaps the non-prefixed symbols to the prefixed symbols so that +// code written against this build can be used independent of the value of +// NANOARROW_NAMESPACE. +#ifdef NANOARROW_NAMESPACE +#define NANOARROW_CAT(A, B) A##B +#define NANOARROW_SYMBOL(A, B) NANOARROW_CAT(A, B) + +#define ArrowNanoarrowVersion NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowNanoarrowVersion) +#define ArrowNanoarrowVersionInt \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowNanoarrowVersionInt) +#define ArrowMalloc NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMalloc) +#define ArrowRealloc NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowRealloc) +#define ArrowFree NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowFree) +#define ArrowBufferAllocatorDefault \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBufferAllocatorDefault) +#define ArrowBufferDeallocator \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBufferDeallocator) +#define ArrowErrorSet NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowErrorSet) +#define ArrowLayoutInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowLayoutInit) +#define ArrowDecimalSetDigits NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowDecimalSetDigits) +#define ArrowDecimalAppendDigitsToBuffer \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowDecimalAppendDigitsToBuffer) +#define ArrowDecimalAppendStringToBuffer \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowDecimalAppendStringToBuffer) +#define ArrowSchemaInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInit) +#define ArrowSchemaInitFromType \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitFromType) +#define ArrowSchemaSetType NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetType) +#define ArrowSchemaSetTypeStruct \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeStruct) +#define ArrowSchemaSetTypeFixedSize \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeFixedSize) +#define ArrowSchemaSetTypeDecimal \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDecimal) +#define ArrowSchemaSetTypeRunEndEncoded \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeRunEndEncoded) +#define ArrowSchemaSetTypeDateTime \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDateTime) +#define ArrowSchemaSetTypeUnion \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeUnion) +#define ArrowSchemaDeepCopy NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaDeepCopy) +#define ArrowSchemaSetFormat NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetFormat) +#define ArrowSchemaSetName NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetName) +#define ArrowSchemaSetMetadata \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetMetadata) +#define ArrowSchemaAllocateChildren \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaAllocateChildren) +#define ArrowSchemaAllocateDictionary \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaAllocateDictionary) +#define ArrowMetadataReaderInit \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataReaderInit) +#define ArrowMetadataReaderRead \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataReaderRead) +#define ArrowMetadataSizeOf NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataSizeOf) +#define ArrowMetadataHasKey NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataHasKey) +#define ArrowMetadataGetValue NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataGetValue) +#define ArrowMetadataBuilderInit \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderInit) +#define ArrowMetadataBuilderAppend \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderAppend) +#define ArrowMetadataBuilderSet \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderSet) +#define ArrowMetadataBuilderRemove \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderRemove) +#define ArrowSchemaViewInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaViewInit) +#define ArrowSchemaToString NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaToString) +#define ArrowArrayInitFromType \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromType) +#define ArrowArrayInitFromSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromSchema) +#define ArrowArrayInitFromArrayView \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromArrayView) +#define ArrowArrayInitFromArrayView \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromArrayView) +#define ArrowArrayAllocateChildren \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayAllocateChildren) +#define ArrowArrayAllocateDictionary \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayAllocateDictionary) +#define ArrowArraySetValidityBitmap \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArraySetValidityBitmap) +#define ArrowArraySetBuffer NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArraySetBuffer) +#define ArrowArrayReserve NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayReserve) +#define ArrowArrayFinishBuilding \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayFinishBuilding) +#define ArrowArrayFinishBuildingDefault \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayFinishBuildingDefault) +#define ArrowArrayViewInitFromType \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromType) +#define ArrowArrayViewInitFromSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromSchema) +#define ArrowArrayViewAllocateChildren \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewAllocateChildren) +#define ArrowArrayViewAllocateDictionary \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewAllocateDictionary) +#define ArrowArrayViewSetLength \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetLength) +#define ArrowArrayViewSetArray \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetArray) +#define ArrowArrayViewSetArrayMinimal \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetArrayMinimal) +#define ArrowArrayViewValidate \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewValidate) +#define ArrowArrayViewCompare NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewCompare) +#define ArrowArrayViewReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewReset) +#define ArrowBasicArrayStreamInit \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamInit) +#define ArrowBasicArrayStreamSetArray \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamSetArray) +#define ArrowBasicArrayStreamValidate \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamValidate) + +#endif + +#if (defined _WIN32 || defined __CYGWIN__) && defined(NANOARROW_BUILD_DLL) +#if defined(NANOARROW_EXPORT_DLL) +#define NANOARROW_DLL __declspec(dllexport) +#else +#define NANOARROW_DLL __declspec(dllimport) +#endif // defined(NANOARROW_EXPORT_DLL) +#elif !defined(NANOARROW_DLL) +#if defined(__GNUC__) && __GNUC__ >= 4 +#define NANOARROW_DLL __attribute__((visibility("default"))) +#else +#define NANOARROW_DLL +#endif // __GNUC__ >= 4 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/// \defgroup nanoarrow Nanoarrow C library +/// +/// Except where noted, objects are not thread-safe and clients should +/// take care to serialize accesses to methods. +/// +/// Because this library is intended to be vendored, it provides full type +/// definitions and encourages clients to stack or statically allocate +/// where convenient. + +/// \defgroup nanoarrow-malloc Memory management +/// +/// Non-buffer members of a struct ArrowSchema and struct ArrowArray +/// must be allocated using ArrowMalloc() or ArrowRealloc() and freed +/// using ArrowFree() for schemas and arrays allocated here. Buffer members +/// are allocated using an ArrowBufferAllocator. +/// +/// @{ + +/// \brief Allocate like malloc() +NANOARROW_DLL void* ArrowMalloc(int64_t size); + +/// \brief Reallocate like realloc() +NANOARROW_DLL void* ArrowRealloc(void* ptr, int64_t size); + +/// \brief Free a pointer allocated using ArrowMalloc() or ArrowRealloc(). +NANOARROW_DLL void ArrowFree(void* ptr); + +/// \brief Return the default allocator +/// +/// The default allocator uses ArrowMalloc(), ArrowRealloc(), and +/// ArrowFree(). +NANOARROW_DLL struct ArrowBufferAllocator ArrowBufferAllocatorDefault(void); + +/// \brief Create a custom deallocator +/// +/// Creates a buffer allocator with only a free method that can be used to +/// attach a custom deallocator to an ArrowBuffer. This may be used to +/// avoid copying an existing buffer that was not allocated using the +/// infrastructure provided here (e.g., by an R or Python object). +NANOARROW_DLL struct ArrowBufferAllocator ArrowBufferDeallocator( + ArrowBufferDeallocatorCallback, void* private_data); + +/// @} + +/// \brief Move the contents of an src ArrowSchema into dst and set src->release to NULL +/// \ingroup nanoarrow-arrow-cdata +static inline void ArrowSchemaMove(struct ArrowSchema* src, struct ArrowSchema* dst); + +/// \brief Call the release callback of an ArrowSchema +/// \ingroup nanoarrow-arrow-cdata +static inline void ArrowSchemaRelease(struct ArrowSchema* schema); + +/// \brief Move the contents of an src ArrowArray into dst and set src->release to NULL +/// \ingroup nanoarrow-arrow-cdata +static inline void ArrowArrayMove(struct ArrowArray* src, struct ArrowArray* dst); + +/// \brief Call the release callback of an ArrowArray +static inline void ArrowArrayRelease(struct ArrowArray* array); + +/// \brief Move the contents of an src ArrowArrayStream into dst and set src->release to +/// NULL \ingroup nanoarrow-arrow-cdata +static inline void ArrowArrayStreamMove(struct ArrowArrayStream* src, + struct ArrowArrayStream* dst); + +/// \brief Call the get_schema callback of an ArrowArrayStream +/// \ingroup nanoarrow-arrow-cdata +/// +/// Unlike the get_schema callback, this wrapper checks the return code +/// and propagates the error reported by get_last_error into error. This +/// makes it significantly less verbose to iterate over array streams +/// using NANOARROW_RETURN_NOT_OK()-style error handling. +static inline ArrowErrorCode ArrowArrayStreamGetSchema( + struct ArrowArrayStream* array_stream, struct ArrowSchema* out, + struct ArrowError* error); + +/// \brief Call the get_next callback of an ArrowArrayStream +/// \ingroup nanoarrow-arrow-cdata +/// +/// Unlike the get_next callback, this wrapper checks the return code +/// and propagates the error reported by get_last_error into error. This +/// makes it significantly less verbose to iterate over array streams +/// using NANOARROW_RETURN_NOT_OK()-style error handling. +static inline ArrowErrorCode ArrowArrayStreamGetNext( + struct ArrowArrayStream* array_stream, struct ArrowArray* out, + struct ArrowError* error); + +/// \brief Call the get_last_error callback of an ArrowArrayStream +/// \ingroup nanoarrow-arrow-cdata +/// +/// Unlike the get_last_error callback, this function never returns NULL (i.e., +/// its result is safe to use in printf-style error formatters). Null values +/// from the original callback are reported as +/// "". +static inline const char* ArrowArrayStreamGetLastError( + struct ArrowArrayStream* array_stream); + +/// \brief Call the release callback of an ArrowArrayStream +static inline void ArrowArrayStreamRelease(struct ArrowArrayStream* array_stream); + +/// \defgroup nanoarrow-errors Error handling +/// +/// Functions generally return an errno-compatible error code; functions that +/// need to communicate more verbose error information accept a pointer +/// to an ArrowError. This can be stack or statically allocated. The +/// content of the message is undefined unless an error code has been +/// returned. If a nanoarrow function is passed a non-null ArrowError pointer, the +/// ArrowError pointed to by the argument will be propagated with a +/// null-terminated error message. It is safe to pass a NULL ArrowError anywhere +/// in the nanoarrow API. +/// +/// Except where documented, it is generally not safe to continue after a +/// function has returned a non-zero ArrowErrorCode. The NANOARROW_RETURN_NOT_OK and +/// NANOARROW_ASSERT_OK macros are provided to help propagate errors. C++ clients can use +/// the helpers provided in the nanoarrow.hpp header to facilitate using C++ idioms +/// for memory management and error propgagtion. +/// +/// @{ + +/// \brief Set the contents of an error using printf syntax. +/// +/// If error is NULL, this function does nothing and returns NANOARROW_OK. +NANOARROW_DLL NANOARROW_CHECK_PRINTF_ATTRIBUTE int ArrowErrorSet(struct ArrowError* error, + const char* fmt, ...); + +/// @} + +/// \defgroup nanoarrow-utils Utility data structures +/// +/// @{ + +/// \brief Return a version string in the form "major.minor.patch" +NANOARROW_DLL const char* ArrowNanoarrowVersion(void); + +/// \brief Return an integer that can be used to compare versions sequentially +NANOARROW_DLL int ArrowNanoarrowVersionInt(void); + +/// \brief Initialize a description of buffer arrangements from a storage type +NANOARROW_DLL void ArrowLayoutInit(struct ArrowLayout* layout, + enum ArrowType storage_type); + +/// \brief Create a string view from a null-terminated string +static inline struct ArrowStringView ArrowCharView(const char* value); + +/// \brief Sets the integer value of an ArrowDecimal from a string +NANOARROW_DLL ArrowErrorCode ArrowDecimalSetDigits(struct ArrowDecimal* decimal, + struct ArrowStringView value); + +/// \brief Get the integer value of an ArrowDecimal as string +NANOARROW_DLL ArrowErrorCode ArrowDecimalAppendDigitsToBuffer( + const struct ArrowDecimal* decimal, struct ArrowBuffer* buffer); + +/// \brief Get the decimal value of an ArrowDecimal as a string +NANOARROW_DLL ArrowErrorCode ArrowDecimalAppendStringToBuffer( + const struct ArrowDecimal* decimal, struct ArrowBuffer* buffer); + +/// \brief Get the half float value of a float +static inline uint16_t ArrowFloatToHalfFloat(float value); + +/// \brief Get the float value of a half float +static inline float ArrowHalfFloatToFloat(uint16_t value); + +/// \brief Resolve a chunk index from increasing int64_t offsets +/// +/// Given a buffer of increasing int64_t offsets that begin with 0 (e.g., offset buffer +/// of a large type, run ends of a chunked array implementation), resolve a value v +/// where lo <= v < hi such that offsets[v] <= index < offsets[v + 1]. +static inline int64_t ArrowResolveChunk64(int64_t index, const int64_t* offsets, + int64_t lo, int64_t hi); + +/// @} + +/// \defgroup nanoarrow-schema Creating schemas +/// +/// These functions allocate, copy, and destroy ArrowSchema structures +/// +/// @{ + +/// \brief Initialize an ArrowSchema +/// +/// Initializes the fields and release callback of schema_out. Caller +/// is responsible for calling the schema->release callback if +/// NANOARROW_OK is returned. +NANOARROW_DLL void ArrowSchemaInit(struct ArrowSchema* schema); + +/// \brief Initialize an ArrowSchema from an ArrowType +/// +/// A convenience constructor for that calls ArrowSchemaInit() and +/// ArrowSchemaSetType() for the common case of constructing an +/// unparameterized type. The caller is responsible for calling the schema->release +/// callback if NANOARROW_OK is returned. +NANOARROW_DLL ArrowErrorCode ArrowSchemaInitFromType(struct ArrowSchema* schema, + enum ArrowType type); + +/// \brief Get a human-readable summary of a Schema +/// +/// Writes a summary of an ArrowSchema to out (up to n - 1 characters) +/// and returns the number of characters required for the output if +/// n were sufficiently large. If recursive is non-zero, the result will +/// also include children. +NANOARROW_DLL int64_t ArrowSchemaToString(const struct ArrowSchema* schema, char* out, + int64_t n, char recursive); + +/// \brief Set the format field of a schema from an ArrowType +/// +/// Initializes the fields and release callback of schema_out. For +/// NANOARROW_TYPE_LIST, NANOARROW_TYPE_LARGE_LIST, and +/// NANOARROW_TYPE_MAP, the appropriate number of children are +/// allocated, initialized, and named; however, the caller must +/// ArrowSchemaSetType() on the preinitialized children. Schema must have been initialized +/// using ArrowSchemaInit() or ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetType(struct ArrowSchema* schema, + enum ArrowType type); + +/// \brief Set the format field and initialize children of a struct schema +/// +/// The specified number of children are initialized; however, the caller is responsible +/// for calling ArrowSchemaSetType() and ArrowSchemaSetName() on each child. +/// Schema must have been initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeStruct(struct ArrowSchema* schema, + int64_t n_children); + +/// \brief Set the format field of a fixed-size schema +/// +/// Returns EINVAL for fixed_size <= 0 or for type that is not +/// NANOARROW_TYPE_FIXED_SIZE_BINARY or NANOARROW_TYPE_FIXED_SIZE_LIST. +/// For NANOARROW_TYPE_FIXED_SIZE_LIST, the appropriate number of children are +/// allocated, initialized, and named; however, the caller must +/// ArrowSchemaSetType() the first child. Schema must have been initialized using +/// ArrowSchemaInit() or ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeFixedSize(struct ArrowSchema* schema, + enum ArrowType type, + int32_t fixed_size); + +/// \brief Set the format field of a decimal schema +/// +/// Returns EINVAL for scale <= 0 or for type that is not +/// NANOARROW_TYPE_DECIMAL32, NANOARROW_TYPE_DECIMAL64, NANOARROW_TYPE_DECIMAL128 or +/// NANOARROW_TYPE_DECIMAL256. Schema must have been initialized using +/// ArrowSchemaInit() or ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeDecimal(struct ArrowSchema* schema, + enum ArrowType type, + int32_t decimal_precision, + int32_t decimal_scale); + +/// \brief Set the format field of a run-end encoded schema +/// +/// Returns EINVAL for run_end_type that is not +/// NANOARROW_TYPE_INT16, NANOARROW_TYPE_INT32 or NANOARROW_TYPE_INT64. +/// Schema must have been initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy(). +/// The caller must call `ArrowSchemaSetTypeXXX(schema->children[1])` to +/// set the value type. Note that when building arrays using the `ArrowArrayAppendXXX()` +/// functions, the run-end encoded array's logical length must be updated manually. +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeRunEndEncoded(struct ArrowSchema* schema, + enum ArrowType run_end_type); + +/// \brief Set the format field of a time, timestamp, or duration schema +/// +/// Returns EINVAL for type that is not +/// NANOARROW_TYPE_TIME32, NANOARROW_TYPE_TIME64, +/// NANOARROW_TYPE_TIMESTAMP, or NANOARROW_TYPE_DURATION. The +/// timezone parameter must be NULL for a non-timestamp type. Schema must have been +/// initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeDateTime(struct ArrowSchema* schema, + enum ArrowType type, + enum ArrowTimeUnit time_unit, + const char* timezone); + +/// \brief Set the format field of a union schema +/// +/// Returns EINVAL for a type that is not NANOARROW_TYPE_DENSE_UNION +/// or NANOARROW_TYPE_SPARSE_UNION. The specified number of children are +/// allocated, and initialized. +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetTypeUnion(struct ArrowSchema* schema, + enum ArrowType type, + int64_t n_children); + +/// \brief Make a (recursive) copy of a schema +/// +/// Allocates and copies fields of schema into schema_out. +NANOARROW_DLL ArrowErrorCode ArrowSchemaDeepCopy(const struct ArrowSchema* schema, + struct ArrowSchema* schema_out); + +/// \brief Copy format into schema->format +/// +/// schema must have been allocated using ArrowSchemaInitFromType() or +/// ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetFormat(struct ArrowSchema* schema, + const char* format); + +/// \brief Copy name into schema->name +/// +/// schema must have been allocated using ArrowSchemaInitFromType() or +/// ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetName(struct ArrowSchema* schema, + const char* name); + +/// \brief Copy metadata into schema->metadata +/// +/// schema must have been allocated using ArrowSchemaInitFromType() or +/// ArrowSchemaDeepCopy. +NANOARROW_DLL ArrowErrorCode ArrowSchemaSetMetadata(struct ArrowSchema* schema, + const char* metadata); + +/// \brief Allocate the schema->children array +/// +/// Includes the memory for each child struct ArrowSchema. +/// schema must have been allocated using ArrowSchemaInitFromType() or +/// ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaAllocateChildren(struct ArrowSchema* schema, + int64_t n_children); + +/// \brief Allocate the schema->dictionary member +/// +/// schema must have been allocated using ArrowSchemaInitFromType() or +/// ArrowSchemaDeepCopy(). +NANOARROW_DLL ArrowErrorCode ArrowSchemaAllocateDictionary(struct ArrowSchema* schema); + +/// @} + +/// \defgroup nanoarrow-metadata Create, read, and modify schema metadata +/// +/// @{ + +/// \brief Reader for key/value pairs in schema metadata +/// +/// The ArrowMetadataReader does not own any data and is only valid +/// for the lifetime of the underlying metadata pointer. +struct ArrowMetadataReader { + /// \brief A metadata string from a schema->metadata field. + const char* metadata; + + /// \brief The current offset into the metadata string + int64_t offset; + + /// \brief The number of remaining keys + int32_t remaining_keys; +}; + +/// \brief Initialize an ArrowMetadataReader +NANOARROW_DLL ArrowErrorCode ArrowMetadataReaderInit(struct ArrowMetadataReader* reader, + const char* metadata); + +/// \brief Read the next key/value pair from an ArrowMetadataReader +NANOARROW_DLL ArrowErrorCode ArrowMetadataReaderRead(struct ArrowMetadataReader* reader, + struct ArrowStringView* key_out, + struct ArrowStringView* value_out); + +/// \brief The number of bytes in in a key/value metadata string +NANOARROW_DLL int64_t ArrowMetadataSizeOf(const char* metadata); + +/// \brief Check for a key in schema metadata +NANOARROW_DLL char ArrowMetadataHasKey(const char* metadata, struct ArrowStringView key); + +/// \brief Extract a value from schema metadata +/// +/// If key does not exist in metadata, value_out is unmodified +NANOARROW_DLL ArrowErrorCode ArrowMetadataGetValue(const char* metadata, + struct ArrowStringView key, + struct ArrowStringView* value_out); + +/// \brief Initialize a builder for schema metadata from key/value pairs +/// +/// metadata can be an existing metadata string or NULL to initialize +/// an empty metadata string. +NANOARROW_DLL ArrowErrorCode ArrowMetadataBuilderInit(struct ArrowBuffer* buffer, + const char* metadata); + +/// \brief Append a key/value pair to a buffer containing serialized metadata +NANOARROW_DLL ArrowErrorCode ArrowMetadataBuilderAppend(struct ArrowBuffer* buffer, + struct ArrowStringView key, + struct ArrowStringView value); + +/// \brief Set a key/value pair to a buffer containing serialized metadata +/// +/// Ensures that the only entry for key in the metadata is set to value. +/// This function maintains the existing position of (the first instance of) +/// key if present in the data. +NANOARROW_DLL ArrowErrorCode ArrowMetadataBuilderSet(struct ArrowBuffer* buffer, + struct ArrowStringView key, + struct ArrowStringView value); + +/// \brief Remove a key from a buffer containing serialized metadata +NANOARROW_DLL ArrowErrorCode ArrowMetadataBuilderRemove(struct ArrowBuffer* buffer, + struct ArrowStringView key); + +/// @} + +/// \defgroup nanoarrow-schema-view Reading schemas +/// +/// @{ + +/// \brief A non-owning view of a parsed ArrowSchema +/// +/// Contains more readily extractable values than a raw ArrowSchema. +/// Clients can stack or statically allocate this structure but are +/// encouraged to use the provided getters to ensure forward +/// compatibility. +struct ArrowSchemaView { + /// \brief A pointer to the schema represented by this view + const struct ArrowSchema* schema; + + /// \brief The data type represented by the schema + /// + /// This value may be NANOARROW_TYPE_DICTIONARY if the schema has a + /// non-null dictionary member; datetime types are valid values. + /// This value will never be NANOARROW_TYPE_EXTENSION (see + /// extension_name and/or extension_metadata to check for + /// an extension type). + enum ArrowType type; + + /// \brief The storage data type represented by the schema + /// + /// This value will never be NANOARROW_TYPE_DICTIONARY, NANOARROW_TYPE_EXTENSION + /// or any datetime type. This value represents only the type required to + /// interpret the buffers in the array. + enum ArrowType storage_type; + + /// \brief The storage layout represented by the schema + struct ArrowLayout layout; + + /// \brief The extension type name if it exists + /// + /// If the ARROW:extension:name key is present in schema.metadata, + /// extension_name.data will be non-NULL. + struct ArrowStringView extension_name; + + /// \brief The extension type metadata if it exists + /// + /// If the ARROW:extension:metadata key is present in schema.metadata, + /// extension_metadata.data will be non-NULL. + struct ArrowStringView extension_metadata; + + /// \brief Format fixed size parameter + /// + /// This value is set when parsing a fixed-size binary or fixed-size + /// list schema; this value is undefined for other types. For a + /// fixed-size binary schema this value is in bytes; for a fixed-size + /// list schema this value refers to the number of child elements for + /// each element of the parent. + int32_t fixed_size; + + /// \brief Decimal bitwidth + /// + /// This value is set when parsing a decimal type schema; + /// this value is undefined for other types. + int32_t decimal_bitwidth; + + /// \brief Decimal precision + /// + /// This value is set when parsing a decimal type schema; + /// this value is undefined for other types. + int32_t decimal_precision; + + /// \brief Decimal scale + /// + /// This value is set when parsing a decimal type schema; + /// this value is undefined for other types. + int32_t decimal_scale; + + /// \brief Format time unit parameter + /// + /// This value is set when parsing a date/time type. The value is + /// undefined for other types. + enum ArrowTimeUnit time_unit; + + /// \brief Format timezone parameter + /// + /// This value is set when parsing a timestamp type and represents + /// the timezone format parameter. This value points to + /// data within the schema and is undefined for other types. + const char* timezone; + + /// \brief Union type ids parameter + /// + /// This value is set when parsing a union type and represents + /// type ids parameter. This value points to + /// data within the schema and is undefined for other types. + const char* union_type_ids; +}; + +/// \brief Initialize an ArrowSchemaView +NANOARROW_DLL ArrowErrorCode ArrowSchemaViewInit(struct ArrowSchemaView* schema_view, + const struct ArrowSchema* schema, + struct ArrowError* error); + +/// @} + +/// \defgroup nanoarrow-buffer Owning, growable buffers +/// +/// @{ + +/// \brief Initialize an ArrowBuffer +/// +/// Initialize a buffer with a NULL, zero-size buffer using the default +/// buffer allocator. +static inline void ArrowBufferInit(struct ArrowBuffer* buffer); + +/// \brief Set a newly-initialized buffer's allocator +/// +/// Returns EINVAL if the buffer has already been allocated. +static inline ArrowErrorCode ArrowBufferSetAllocator( + struct ArrowBuffer* buffer, struct ArrowBufferAllocator allocator); + +/// \brief Reset an ArrowBuffer +/// +/// Releases the buffer using the allocator's free method if +/// the buffer's data member is non-null, sets the data member +/// to NULL, and sets the buffer's size and capacity to 0. +static inline void ArrowBufferReset(struct ArrowBuffer* buffer); + +/// \brief Move an ArrowBuffer +/// +/// Transfers the buffer data and lifecycle management to another +/// address and resets buffer. +static inline void ArrowBufferMove(struct ArrowBuffer* src, struct ArrowBuffer* dst); + +/// \brief Grow or shrink a buffer to a given size +/// +/// When shrinking the size of the buffer, the buffer is only reallocated +/// if shrink_to_fit is non-zero. +static inline ArrowErrorCode ArrowBufferResize(struct ArrowBuffer* buffer, + int64_t new_size_bytes, + char shrink_to_fit); + +/// \brief Ensure a buffer has at least a given additional capacity +/// +/// Ensures that the buffer has space to append at least +/// additional_size_bytes, overallocating when required. +static inline ArrowErrorCode ArrowBufferReserve(struct ArrowBuffer* buffer, + int64_t additional_size_bytes); + +/// \brief Write data to buffer and increment the buffer size +/// +/// This function does not check that buffer has the required capacity +static inline void ArrowBufferAppendUnsafe(struct ArrowBuffer* buffer, const void* data, + int64_t size_bytes); + +/// \brief Write data to buffer and increment the buffer size +/// +/// This function writes and ensures that the buffer has the required capacity, +/// possibly by reallocating the buffer. Like ArrowBufferReserve, this will +/// overallocate when reallocation is required. +static inline ArrowErrorCode ArrowBufferAppend(struct ArrowBuffer* buffer, + const void* data, int64_t size_bytes); + +/// \brief Write fill to buffer and increment the buffer size +/// +/// This function writes the specified number of fill bytes and +/// ensures that the buffer has the required capacity, +static inline ArrowErrorCode ArrowBufferAppendFill(struct ArrowBuffer* buffer, + uint8_t value, int64_t size_bytes); + +/// \brief Write an 8-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendInt8(struct ArrowBuffer* buffer, + int8_t value); + +/// \brief Write an unsigned 8-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendUInt8(struct ArrowBuffer* buffer, + uint8_t value); + +/// \brief Write a 16-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendInt16(struct ArrowBuffer* buffer, + int16_t value); + +/// \brief Write an unsigned 16-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendUInt16(struct ArrowBuffer* buffer, + uint16_t value); + +/// \brief Write a 32-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendInt32(struct ArrowBuffer* buffer, + int32_t value); + +/// \brief Write an unsigned 32-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendUInt32(struct ArrowBuffer* buffer, + uint32_t value); + +/// \brief Write a 64-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendInt64(struct ArrowBuffer* buffer, + int64_t value); + +/// \brief Write an unsigned 64-bit integer to a buffer +static inline ArrowErrorCode ArrowBufferAppendUInt64(struct ArrowBuffer* buffer, + uint64_t value); + +/// \brief Write a double to a buffer +static inline ArrowErrorCode ArrowBufferAppendDouble(struct ArrowBuffer* buffer, + double value); + +/// \brief Write a float to a buffer +static inline ArrowErrorCode ArrowBufferAppendFloat(struct ArrowBuffer* buffer, + float value); + +/// \brief Write an ArrowStringView to a buffer +static inline ArrowErrorCode ArrowBufferAppendStringView(struct ArrowBuffer* buffer, + struct ArrowStringView value); + +/// \brief Write an ArrowBufferView to a buffer +static inline ArrowErrorCode ArrowBufferAppendBufferView(struct ArrowBuffer* buffer, + struct ArrowBufferView value); + +/// @} + +/// \defgroup nanoarrow-bitmap Bitmap utilities +/// +/// @{ + +/// \brief Extract a boolean value from a bitmap +static inline int8_t ArrowBitGet(const uint8_t* bits, int64_t i); + +/// \brief Set a boolean value to a bitmap to true +static inline void ArrowBitSet(uint8_t* bits, int64_t i); + +/// \brief Set a boolean value to a bitmap to false +static inline void ArrowBitClear(uint8_t* bits, int64_t i); + +/// \brief Set a boolean value to a bitmap +static inline void ArrowBitSetTo(uint8_t* bits, int64_t i, uint8_t value); + +/// \brief Set a boolean value to a range in a bitmap +static inline void ArrowBitsSetTo(uint8_t* bits, int64_t start_offset, int64_t length, + uint8_t bits_are_set); + +/// \brief Count true values in a bitmap +static inline int64_t ArrowBitCountSet(const uint8_t* bits, int64_t i_from, int64_t i_to); + +/// \brief Extract int8 boolean values from a range in a bitmap +static inline void ArrowBitsUnpackInt8(const uint8_t* bits, int64_t start_offset, + int64_t length, int8_t* out); + +/// \brief Extract int32 boolean values from a range in a bitmap +static inline void ArrowBitsUnpackInt32(const uint8_t* bits, int64_t start_offset, + int64_t length, int32_t* out); + +/// \brief Initialize an ArrowBitmap +/// +/// Initialize the builder's buffer, empty its cache, and reset the size to zero +static inline void ArrowBitmapInit(struct ArrowBitmap* bitmap); + +/// \brief Move an ArrowBitmap +/// +/// Transfers the underlying buffer data and lifecycle management to another +/// address and resets the bitmap. +static inline void ArrowBitmapMove(struct ArrowBitmap* src, struct ArrowBitmap* dst); + +/// \brief Ensure a bitmap builder has at least a given additional capacity +/// +/// Ensures that the buffer has space to append at least +/// additional_size_bits, overallocating when required. +static inline ArrowErrorCode ArrowBitmapReserve(struct ArrowBitmap* bitmap, + int64_t additional_size_bits); + +/// \brief Grow or shrink a bitmap to a given size +/// +/// When shrinking the size of the bitmap, the bitmap is only reallocated +/// if shrink_to_fit is non-zero. +static inline ArrowErrorCode ArrowBitmapResize(struct ArrowBitmap* bitmap, + int64_t new_size_bits, char shrink_to_fit); + +/// \brief Reserve space for and append zero or more of the same boolean value to a bitmap +static inline ArrowErrorCode ArrowBitmapAppend(struct ArrowBitmap* bitmap, + uint8_t bits_are_set, int64_t length); + +/// \brief Append zero or more of the same boolean value to a bitmap +static inline void ArrowBitmapAppendUnsafe(struct ArrowBitmap* bitmap, + uint8_t bits_are_set, int64_t length); + +/// \brief Append boolean values encoded as int8_t to a bitmap +/// +/// The values must all be 0 or 1. +static inline void ArrowBitmapAppendInt8Unsafe(struct ArrowBitmap* bitmap, + const int8_t* values, int64_t n_values); + +/// \brief Append boolean values encoded as int32_t to a bitmap +/// +/// The values must all be 0 or 1. +static inline void ArrowBitmapAppendInt32Unsafe(struct ArrowBitmap* bitmap, + const int32_t* values, int64_t n_values); + +/// \brief Reset a bitmap builder +/// +/// Releases any memory held by buffer, empties the cache, and resets the size to zero +static inline void ArrowBitmapReset(struct ArrowBitmap* bitmap); + +/// @} + +/// \defgroup nanoarrow-array Creating arrays +/// +/// These functions allocate, copy, and destroy ArrowArray structures. +/// Once an ArrowArray has been initialized via ArrowArrayInitFromType() +/// or ArrowArrayInitFromSchema(), the caller is responsible for releasing +/// it using the embedded release callback. +/// +/// @{ + +/// \brief Initialize the fields of an array +/// +/// Initializes the fields and release callback of array. Caller +/// is responsible for calling the array->release callback if +/// NANOARROW_OK is returned. +NANOARROW_DLL ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray* array, + enum ArrowType storage_type); + +/// \brief Initialize the contents of an ArrowArray from an ArrowSchema +/// +/// Caller is responsible for calling the array->release callback if +/// NANOARROW_OK is returned. +NANOARROW_DLL ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array, + const struct ArrowSchema* schema, + struct ArrowError* error); + +/// \brief Initialize the contents of an ArrowArray from an ArrowArrayView +/// +/// Caller is responsible for calling the array->release callback if +/// NANOARROW_OK is returned. +NANOARROW_DLL ArrowErrorCode ArrowArrayInitFromArrayView( + struct ArrowArray* array, const struct ArrowArrayView* array_view, + struct ArrowError* error); + +/// \brief Allocate the array->children array +/// +/// Includes the memory for each child struct ArrowArray, +/// whose members are marked as released and may be subsequently initialized +/// with ArrowArrayInitFromType() or moved from an existing ArrowArray. +/// schema must have been allocated using ArrowArrayInitFromType(). +NANOARROW_DLL ArrowErrorCode ArrowArrayAllocateChildren(struct ArrowArray* array, + int64_t n_children); + +/// \brief Allocate the array->dictionary member +/// +/// Includes the memory for the struct ArrowArray, whose contents +/// is marked as released and may be subsequently initialized +/// with ArrowArrayInitFromType() or moved from an existing ArrowArray. +/// array must have been allocated using ArrowArrayInitFromType() +NANOARROW_DLL ArrowErrorCode ArrowArrayAllocateDictionary(struct ArrowArray* array); + +/// \brief Set the validity bitmap of an ArrowArray +/// +/// array must have been allocated using ArrowArrayInitFromType() +NANOARROW_DLL void ArrowArraySetValidityBitmap(struct ArrowArray* array, + struct ArrowBitmap* bitmap); + +/// \brief Set a buffer of an ArrowArray +/// +/// array must have been allocated using ArrowArrayInitFromType() +NANOARROW_DLL ArrowErrorCode ArrowArraySetBuffer(struct ArrowArray* array, int64_t i, + struct ArrowBuffer* buffer); + +/// \brief Add variadic buffers to a string or binary view array +/// +/// array must have been allocated using ArrowArrayInitFromType() +static inline ArrowErrorCode ArrowArrayAddVariadicBuffers(struct ArrowArray* array, + int32_t n_buffers); + +/// \brief Get the validity bitmap of an ArrowArray +/// +/// array must have been allocated using ArrowArrayInitFromType() +static inline struct ArrowBitmap* ArrowArrayValidityBitmap(struct ArrowArray* array); + +/// \brief Get a buffer of an ArrowArray +/// +/// array must have been allocated using ArrowArrayInitFromType() +static inline struct ArrowBuffer* ArrowArrayBuffer(struct ArrowArray* array, int64_t i); + +/// \brief Start element-wise appending to an ArrowArray +/// +/// Initializes any values needed to use ArrowArrayAppend*() functions. +/// All element-wise appenders append by value and return EINVAL if the exact value +/// cannot be represented by the underlying storage type. +/// array must have been allocated using ArrowArrayInitFromType() +static inline ArrowErrorCode ArrowArrayStartAppending(struct ArrowArray* array); + +/// \brief Reserve space for future appends +/// +/// For buffer sizes that can be calculated (i.e., not string data buffers or +/// child array sizes for non-fixed-size arrays), recursively reserve space for +/// additional elements. This is useful for reducing the number of reallocations +/// that occur using the item-wise appenders. +NANOARROW_DLL ArrowErrorCode ArrowArrayReserve(struct ArrowArray* array, + int64_t additional_size_elements); + +/// \brief Append a null value to an array +static inline ArrowErrorCode ArrowArrayAppendNull(struct ArrowArray* array, int64_t n); + +/// \brief Append an empty, non-null value to an array +static inline ArrowErrorCode ArrowArrayAppendEmpty(struct ArrowArray* array, int64_t n); + +/// \brief Append a signed integer value to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type or EINVAL otherwise (e.g., value +/// is outside the valid array range). +static inline ArrowErrorCode ArrowArrayAppendInt(struct ArrowArray* array, int64_t value); + +/// \brief Append an unsigned integer value to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type or EINVAL otherwise (e.g., value +/// is outside the valid array range). +static inline ArrowErrorCode ArrowArrayAppendUInt(struct ArrowArray* array, + uint64_t value); + +/// \brief Append a double value to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type or EINVAL otherwise (e.g., value +/// is outside the valid array range or there is an attempt to append +/// a non-integer to an array with an integer storage type). +static inline ArrowErrorCode ArrowArrayAppendDouble(struct ArrowArray* array, + double value); + +/// \brief Append a string of bytes to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type, EOVERFLOW if appending value would overflow +/// the offset type (e.g., if the data buffer would be larger than 2 GB for a +/// non-large string type), or EINVAL otherwise (e.g., the underlying array is not a +/// binary, string, large binary, large string, or fixed-size binary array, or value is +/// the wrong size for a fixed-size binary array). +static inline ArrowErrorCode ArrowArrayAppendBytes(struct ArrowArray* array, + struct ArrowBufferView value); + +/// \brief Append a string value to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type, EOVERFLOW if appending value would overflow +/// the offset type (e.g., if the data buffer would be larger than 2 GB for a +/// non-large string type), or EINVAL otherwise (e.g., the underlying array is not a +/// string or large string array). +static inline ArrowErrorCode ArrowArrayAppendString(struct ArrowArray* array, + struct ArrowStringView value); + +/// \brief Append a Interval to an array +/// +/// Returns NANOARROW_OK if value can be exactly represented by +/// the underlying storage type or EINVAL otherwise. +static inline ArrowErrorCode ArrowArrayAppendInterval(struct ArrowArray* array, + const struct ArrowInterval* value); + +/// \brief Append a decimal value to an array +/// +/// Returns NANOARROW_OK if array is a decimal array with the appropriate +/// bitwidth or EINVAL otherwise. +static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array, + const struct ArrowDecimal* value); + +/// \brief Finish a nested array element +/// +/// Appends a non-null element to the array based on the first child's current +/// length. Returns NANOARROW_OK if the item was successfully added, EOVERFLOW +/// if the child of a list or map array would exceed INT_MAX elements, or EINVAL +/// if the underlying storage type is not a struct, list, large list, or fixed-size +/// list, or if there was an attempt to add a struct or fixed-size list element where the +/// length of the child array(s) did not match the expected length. +static inline ArrowErrorCode ArrowArrayFinishElement(struct ArrowArray* array); + +/// \brief Finish a union array element +/// +/// Appends an element to the union type ids buffer and increments array->length. +/// For sparse unions, up to one element is added to non type-id children. Returns +/// EINVAL if the underlying storage type is not a union, if type_id is not valid, +/// or if child sizes after appending are inconsistent. +static inline ArrowErrorCode ArrowArrayFinishUnionElement(struct ArrowArray* array, + int8_t type_id); + +/// \brief Shrink buffer capacity to the size required +/// +/// Also applies shrinking to any child arrays. array must have been allocated using +/// ArrowArrayInitFromType +static inline ArrowErrorCode ArrowArrayShrinkToFit(struct ArrowArray* array); + +/// \brief Finish building an ArrowArray +/// +/// Flushes any pointers from internal buffers that may have been reallocated +/// into array->buffers and checks the actual size of the buffers +/// against the expected size based on the final length. +/// array must have been allocated using ArrowArrayInitFromType() +NANOARROW_DLL ArrowErrorCode ArrowArrayFinishBuildingDefault(struct ArrowArray* array, + struct ArrowError* error); + +/// \brief Finish building an ArrowArray with explicit validation +/// +/// Finish building with an explicit validation level. This could perform less validation +/// (i.e. NANOARROW_VALIDATION_LEVEL_NONE or NANOARROW_VALIDATION_LEVEL_MINIMAL) if CPU +/// buffer data access is not possible or more validation (i.e., +/// NANOARROW_VALIDATION_LEVEL_FULL) if buffer content was obtained from an untrusted or +/// corruptible source. +NANOARROW_DLL ArrowErrorCode ArrowArrayFinishBuilding( + struct ArrowArray* array, enum ArrowValidationLevel validation_level, + struct ArrowError* error); + +/// @} + +/// \defgroup nanoarrow-array-view Reading arrays +/// +/// These functions read and validate the contents ArrowArray structures. +/// +/// @{ + +/// \brief Initialize the contents of an ArrowArrayView +NANOARROW_DLL void ArrowArrayViewInitFromType(struct ArrowArrayView* array_view, + enum ArrowType storage_type); + +/// \brief Move an ArrowArrayView +/// +/// Transfers the ArrowArrayView data and lifecycle management to another +/// address and resets the contents of src. +static inline void ArrowArrayViewMove(struct ArrowArrayView* src, + struct ArrowArrayView* dst); + +/// \brief Initialize the contents of an ArrowArrayView from an ArrowSchema +NANOARROW_DLL ArrowErrorCode +ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view, + const struct ArrowSchema* schema, struct ArrowError* error); + +/// \brief Allocate the array_view->children array +/// +/// Includes the memory for each child struct ArrowArrayView +NANOARROW_DLL ArrowErrorCode +ArrowArrayViewAllocateChildren(struct ArrowArrayView* array_view, int64_t n_children); + +/// \brief Allocate array_view->dictionary +NANOARROW_DLL ArrowErrorCode +ArrowArrayViewAllocateDictionary(struct ArrowArrayView* array_view); + +/// \brief Set data-independent buffer sizes from length +NANOARROW_DLL void ArrowArrayViewSetLength(struct ArrowArrayView* array_view, + int64_t length); + +/// \brief Set buffer sizes and data pointers from an ArrowArray +NANOARROW_DLL ArrowErrorCode ArrowArrayViewSetArray(struct ArrowArrayView* array_view, + const struct ArrowArray* array, + struct ArrowError* error); + +/// \brief Set buffer sizes and data pointers from an ArrowArray except for those +/// that require dereferencing buffer content. +NANOARROW_DLL ArrowErrorCode +ArrowArrayViewSetArrayMinimal(struct ArrowArrayView* array_view, + const struct ArrowArray* array, struct ArrowError* error); + +/// \brief Get the number of buffers +/// +/// The number of buffers referred to by this ArrowArrayView. In may cases this can also +/// be calculated from the ArrowLayout member of the ArrowArrayView or ArrowSchemaView; +/// however, for binary view and string view types, the number of total buffers depends on +/// the number of variadic buffers. +static inline int64_t ArrowArrayViewGetNumBuffers(struct ArrowArrayView* array_view); + +/// \brief Get a view of a specific buffer from an ArrowArrayView +/// +/// This is the ArrowArrayView equivalent of ArrowArray::buffers[i] that includes +/// size information (if known). +static inline struct ArrowBufferView ArrowArrayViewGetBufferView( + struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get the function of a specific buffer in an ArrowArrayView +/// +/// In may cases this can also be obtained from the ArrowLayout member of the +/// ArrowArrayView or ArrowSchemaView; however, for binary view and string view types, +/// the function of each buffer may be different between two arrays of the same type +/// depending on the number of variadic buffers. +static inline enum ArrowBufferType ArrowArrayViewGetBufferType( + struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get the data type of a specific buffer in an ArrowArrayView +/// +/// In may cases this can also be obtained from the ArrowLayout member of the +/// ArrowArrayView or ArrowSchemaView; however, for binary view and string view types, +/// the data type of each buffer may be different between two arrays of the same type +/// depending on the number of variadic buffers. +static inline enum ArrowType ArrowArrayViewGetBufferDataType( + struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get the element size (in bits) of a specific buffer in an ArrowArrayView +/// +/// In may cases this can also be obtained from the ArrowLayout member of the +/// ArrowArrayView or ArrowSchemaView; however, for binary view and string view types, +/// the element width of each buffer may be different between two arrays of the same type +/// depending on the number of variadic buffers. +static inline int64_t ArrowArrayViewGetBufferElementSizeBits( + struct ArrowArrayView* array_view, int64_t i); + +/// \brief Performs checks on the content of an ArrowArrayView +/// +/// If using ArrowArrayViewSetArray() to back array_view with an ArrowArray, +/// the buffer sizes and some content (fist and last offset) have already +/// been validated at the "default" level. If setting the buffer pointers +/// and sizes otherwise, you may wish to perform checks at a different level. See +/// documentation for ArrowValidationLevel for the details of checks performed +/// at each level. +NANOARROW_DLL ArrowErrorCode ArrowArrayViewValidate( + struct ArrowArrayView* array_view, enum ArrowValidationLevel validation_level, + struct ArrowError* error); + +/// \brief Compare two ArrowArrayView objects for equality +/// +/// Given two ArrowArrayView instances, place either 0 (not equal) and +/// 1 (equal) at the address pointed to by out. If the comparison determines +/// that actual and expected are not equal, a reason will be communicated via +/// error if error is non-NULL. +/// +/// Returns NANOARROW_OK if the comparison completed successfully. +NANOARROW_DLL ArrowErrorCode ArrowArrayViewCompare(const struct ArrowArrayView* actual, + const struct ArrowArrayView* expected, + enum ArrowCompareLevel level, int* out, + struct ArrowError* reason); + +/// \brief Reset the contents of an ArrowArrayView and frees resources +NANOARROW_DLL void ArrowArrayViewReset(struct ArrowArrayView* array_view); + +/// \brief Check for a null element in an ArrowArrayView +static inline int8_t ArrowArrayViewIsNull(const struct ArrowArrayView* array_view, + int64_t i); + +/// \brief Compute null count for an ArrowArrayView +static inline int64_t ArrowArrayViewComputeNullCount( + const struct ArrowArrayView* array_view); + +/// \brief Get the type id of a union array element +static inline int8_t ArrowArrayViewUnionTypeId(const struct ArrowArrayView* array_view, + int64_t i); + +/// \brief Get the child index of a union array element +static inline int8_t ArrowArrayViewUnionChildIndex( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get the index to use into the relevant union child array +static inline int64_t ArrowArrayViewUnionChildOffset( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get an element in an ArrowArrayView as an integer +/// +/// This function does not check for null values, that values are actually integers, or +/// that values are within a valid range for an int64. +static inline int64_t ArrowArrayViewGetIntUnsafe(const struct ArrowArrayView* array_view, + int64_t i); + +/// \brief Get an element in an ArrowArrayView as an unsigned integer +/// +/// This function does not check for null values, that values are actually integers, or +/// that values are within a valid range for a uint64. +static inline uint64_t ArrowArrayViewGetUIntUnsafe( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get an element in an ArrowArrayView as a double +/// +/// This function does not check for null values, or +/// that values are within a valid range for a double. +static inline double ArrowArrayViewGetDoubleUnsafe( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get an element in an ArrowArrayView as an ArrowStringView +/// +/// This function does not check for null values. +static inline struct ArrowStringView ArrowArrayViewGetStringUnsafe( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get an element in an ArrowArrayView as an ArrowBufferView +/// +/// This function does not check for null values. +static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe( + const struct ArrowArrayView* array_view, int64_t i); + +/// \brief Get an element in an ArrowArrayView as an ArrowDecimal +/// +/// This function does not check for null values. The out parameter must +/// be initialized with ArrowDecimalInit() with the proper parameters for this +/// type before calling this for the first time. +static inline void ArrowArrayViewGetDecimalUnsafe(const struct ArrowArrayView* array_view, + int64_t i, struct ArrowDecimal* out); + +/// @} + +/// \defgroup nanoarrow-basic-array-stream Basic ArrowArrayStream implementation +/// +/// An implementation of an ArrowArrayStream based on a collection of +/// zero or more previously-existing ArrowArray objects. Users should +/// initialize and/or validate the contents before transferring the +/// responsibility of the ArrowArrayStream elsewhere. +/// +/// @{ + +/// \brief Initialize an ArrowArrayStream backed by this implementation +/// +/// This function moves the ownership of schema to the array_stream. If +/// this function returns NANOARROW_OK, the caller is responsible for +/// releasing the ArrowArrayStream. +NANOARROW_DLL ArrowErrorCode ArrowBasicArrayStreamInit( + struct ArrowArrayStream* array_stream, struct ArrowSchema* schema, int64_t n_arrays); + +/// \brief Set the ith ArrowArray in this ArrowArrayStream. +/// +/// array_stream must have been initialized with ArrowBasicArrayStreamInit(). +/// This function moves the ownership of array to the array_stream. i must +/// be greater than or equal to zero and less than the value of n_arrays passed in +/// ArrowBasicArrayStreamInit(). Callers are not required to fill all +/// n_arrays members (i.e., n_arrays is a maximum bound). +NANOARROW_DLL void ArrowBasicArrayStreamSetArray(struct ArrowArrayStream* array_stream, + int64_t i, struct ArrowArray* array); + +/// \brief Validate the contents of this ArrowArrayStream +/// +/// array_stream must have been initialized with ArrowBasicArrayStreamInit(). +/// This function uses ArrowArrayStreamInitFromSchema() and ArrowArrayStreamSetArray() +/// to validate the contents of the arrays. +NANOARROW_DLL ArrowErrorCode ArrowBasicArrayStreamValidate( + const struct ArrowArrayStream* array_stream, struct ArrowError* error); + +/// @} + +// Undefine ArrowErrorCode, which may have been defined to annotate functions that return +// it to warn for an unused result. +#if defined(ArrowErrorCode) +#undef ArrowErrorCode +#endif + +// Inline function definitions + + + +#ifdef __cplusplus +} +#endif + +#endif +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_BUFFER_INLINE_H_INCLUDED +#define NANOARROW_BUFFER_INLINE_H_INCLUDED + +#include +#include +#include + + + +#ifdef __cplusplus +extern "C" { +#endif + +// Modified from Arrow C++ (1eb46f76) cpp/src/arrow/chunk_resolver.h#L133-L162 +static inline int64_t ArrowResolveChunk64(int64_t index, const int64_t* offsets, + int64_t lo, int64_t hi) { + // Similar to std::upper_bound(), but slightly different as our offsets + // array always starts with 0. + int64_t n = hi - lo; + // First iteration does not need to check for n > 1 + // (lo < hi is guaranteed by the precondition). + NANOARROW_DCHECK(n > 1); + do { + const int64_t m = n >> 1; + const int64_t mid = lo + m; + if (index >= offsets[mid]) { + lo = mid; + n -= m; + } else { + n = m; + } + } while (n > 1); + return lo; +} + +static inline int64_t ArrowResolveChunk32(int32_t index, const int32_t* offsets, + int32_t lo, int32_t hi) { + // Similar to std::upper_bound(), but slightly different as our offsets + // array always starts with 0. + int32_t n = hi - lo; + // First iteration does not need to check for n > 1 + // (lo < hi is guaranteed by the precondition). + NANOARROW_DCHECK(n > 1); + do { + const int32_t m = n >> 1; + const int32_t mid = lo + m; + if (index >= offsets[mid]) { + lo = mid; + n -= m; + } else { + n = m; + } + } while (n > 1); + return lo; +} + +static inline int64_t _ArrowGrowByFactor(int64_t current_capacity, int64_t new_capacity) { + int64_t doubled_capacity = current_capacity * 2; + if (doubled_capacity > new_capacity) { + return doubled_capacity; + } else { + return new_capacity; + } +} + +// float to half float conversion, adapted from Arrow Go +// https://github.com/apache/arrow/blob/main/go/arrow/float16/float16.go +static inline uint16_t ArrowFloatToHalfFloat(float value) { + union { + float f; + uint32_t b; + } u; + u.f = value; + + uint16_t sn = (uint16_t)((u.b >> 31) & 0x1); + uint16_t exp = (u.b >> 23) & 0xff; + int16_t res = (int16_t)(exp - 127 + 15); + uint16_t fc = (uint16_t)(u.b >> 13) & 0x3ff; + + if (exp == 0) { + res = 0; + } else if (exp == 0xff) { + res = 0x1f; + } else if (res > 0x1e) { + res = 0x1f; + fc = 0; + } else if (res < 0x01) { + res = 0; + fc = 0; + } + + return (uint16_t)((sn << 15) | (uint16_t)(res << 10) | fc); +} + +// half float to float conversion, adapted from Arrow Go +// https://github.com/apache/arrow/blob/main/go/arrow/float16/float16.go +static inline float ArrowHalfFloatToFloat(uint16_t value) { + uint32_t sn = (uint32_t)((value >> 15) & 0x1); + uint32_t exp = (value >> 10) & 0x1f; + uint32_t res = exp + 127 - 15; + uint32_t fc = value & 0x3ff; + + if (exp == 0) { + res = 0; + } else if (exp == 0x1f) { + res = 0xff; + } + + union { + float f; + uint32_t b; + } u; + u.b = (uint32_t)(sn << 31) | (uint32_t)(res << 23) | (uint32_t)(fc << 13); + return u.f; +} + +static inline void ArrowBufferInit(struct ArrowBuffer* buffer) { + buffer->data = NULL; + buffer->size_bytes = 0; + buffer->capacity_bytes = 0; + buffer->allocator = ArrowBufferAllocatorDefault(); +} + +static inline ArrowErrorCode ArrowBufferSetAllocator( + struct ArrowBuffer* buffer, struct ArrowBufferAllocator allocator) { + // This is not a perfect test for "has a buffer already been allocated" + // but is likely to catch most cases. + if (buffer->data == NULL) { + buffer->allocator = allocator; + return NANOARROW_OK; + } else { + return EINVAL; + } +} + +static inline void ArrowBufferReset(struct ArrowBuffer* buffer) { + buffer->allocator.free(&buffer->allocator, (uint8_t*)buffer->data, + buffer->capacity_bytes); + ArrowBufferInit(buffer); +} + +static inline void ArrowBufferMove(struct ArrowBuffer* src, struct ArrowBuffer* dst) { + memcpy(dst, src, sizeof(struct ArrowBuffer)); + src->data = NULL; + ArrowBufferInit(src); +} + +static inline ArrowErrorCode ArrowBufferResize(struct ArrowBuffer* buffer, + int64_t new_size_bytes, + char shrink_to_fit) { + if (new_size_bytes < 0) { + return EINVAL; + } + + int needs_reallocation = new_size_bytes > buffer->capacity_bytes || + (shrink_to_fit && new_size_bytes < buffer->capacity_bytes); + + if (needs_reallocation) { + buffer->data = buffer->allocator.reallocate(&buffer->allocator, buffer->data, + buffer->capacity_bytes, new_size_bytes); + + if (buffer->data == NULL && new_size_bytes > 0) { + buffer->capacity_bytes = 0; + buffer->size_bytes = 0; + return ENOMEM; + } + + buffer->capacity_bytes = new_size_bytes; + } + + buffer->size_bytes = new_size_bytes; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowBufferReserve(struct ArrowBuffer* buffer, + int64_t additional_size_bytes) { + int64_t min_capacity_bytes = buffer->size_bytes + additional_size_bytes; + if (min_capacity_bytes <= buffer->capacity_bytes) { + return NANOARROW_OK; + } + + int64_t new_capacity_bytes = + _ArrowGrowByFactor(buffer->capacity_bytes, min_capacity_bytes); + buffer->data = buffer->allocator.reallocate(&buffer->allocator, buffer->data, + buffer->capacity_bytes, new_capacity_bytes); + + if (buffer->data == NULL && new_capacity_bytes > 0) { + buffer->capacity_bytes = 0; + buffer->size_bytes = 0; + return ENOMEM; + } + + buffer->capacity_bytes = new_capacity_bytes; + return NANOARROW_OK; +} + +static inline void ArrowBufferAppendUnsafe(struct ArrowBuffer* buffer, const void* data, + int64_t size_bytes) { + if (size_bytes > 0) { + NANOARROW_DCHECK(buffer->data != NULL); + memcpy(buffer->data + buffer->size_bytes, data, size_bytes); + buffer->size_bytes += size_bytes; + } +} + +static inline ArrowErrorCode ArrowBufferAppend(struct ArrowBuffer* buffer, + const void* data, int64_t size_bytes) { + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes)); + + ArrowBufferAppendUnsafe(buffer, data, size_bytes); + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowBufferAppendInt8(struct ArrowBuffer* buffer, + int8_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(int8_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendUInt8(struct ArrowBuffer* buffer, + uint8_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(uint8_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendInt16(struct ArrowBuffer* buffer, + int16_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(int16_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendUInt16(struct ArrowBuffer* buffer, + uint16_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(uint16_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendInt32(struct ArrowBuffer* buffer, + int32_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(int32_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendUInt32(struct ArrowBuffer* buffer, + uint32_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(uint32_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendInt64(struct ArrowBuffer* buffer, + int64_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(int64_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendUInt64(struct ArrowBuffer* buffer, + uint64_t value) { + return ArrowBufferAppend(buffer, &value, sizeof(uint64_t)); +} + +static inline ArrowErrorCode ArrowBufferAppendDouble(struct ArrowBuffer* buffer, + double value) { + return ArrowBufferAppend(buffer, &value, sizeof(double)); +} + +static inline ArrowErrorCode ArrowBufferAppendFloat(struct ArrowBuffer* buffer, + float value) { + return ArrowBufferAppend(buffer, &value, sizeof(float)); +} + +static inline ArrowErrorCode ArrowBufferAppendStringView(struct ArrowBuffer* buffer, + struct ArrowStringView value) { + return ArrowBufferAppend(buffer, value.data, value.size_bytes); +} + +static inline ArrowErrorCode ArrowBufferAppendBufferView(struct ArrowBuffer* buffer, + struct ArrowBufferView value) { + return ArrowBufferAppend(buffer, value.data.data, value.size_bytes); +} + +static inline ArrowErrorCode ArrowBufferAppendFill(struct ArrowBuffer* buffer, + uint8_t value, int64_t size_bytes) { + if (size_bytes == 0) { + return NANOARROW_OK; + } + + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes)); + + NANOARROW_DCHECK(buffer->data != NULL); // To help clang-tidy + memset(buffer->data + buffer->size_bytes, value, size_bytes); + buffer->size_bytes += size_bytes; + + return NANOARROW_OK; +} + +static const uint8_t _ArrowkBitmask[] = {1, 2, 4, 8, 16, 32, 64, 128}; +static const uint8_t _ArrowkFlippedBitmask[] = {254, 253, 251, 247, 239, 223, 191, 127}; +static const uint8_t _ArrowkPrecedingBitmask[] = {0, 1, 3, 7, 15, 31, 63, 127}; +static const uint8_t _ArrowkTrailingBitmask[] = {255, 254, 252, 248, 240, 224, 192, 128}; + +static const uint8_t _ArrowkBytePopcount[] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, + 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, + 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, + 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, + 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, + 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, + 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, + 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, + 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; + +static inline int64_t _ArrowRoundUpToMultipleOf8(int64_t value) { + return (value + 7) & ~((int64_t)7); +} + +static inline int64_t _ArrowRoundDownToMultipleOf8(int64_t value) { + return (value / 8) * 8; +} + +static inline int64_t _ArrowBytesForBits(int64_t bits) { + return (bits >> 3) + ((bits & 7) != 0); +} + +static inline void _ArrowBitsUnpackInt8(const uint8_t word, int8_t* out) { + out[0] = (word & 0x1) != 0; + out[1] = (word & 0x2) != 0; + out[2] = (word & 0x4) != 0; + out[3] = (word & 0x8) != 0; + out[4] = (word & 0x10) != 0; + out[5] = (word & 0x20) != 0; + out[6] = (word & 0x40) != 0; + out[7] = (word & 0x80) != 0; +} + +static inline void _ArrowBitsUnpackInt32(const uint8_t word, int32_t* out) { + out[0] = (word & 0x1) != 0; + out[1] = (word & 0x2) != 0; + out[2] = (word & 0x4) != 0; + out[3] = (word & 0x8) != 0; + out[4] = (word & 0x10) != 0; + out[5] = (word & 0x20) != 0; + out[6] = (word & 0x40) != 0; + out[7] = (word & 0x80) != 0; +} + +static inline void _ArrowBitmapPackInt8(const int8_t* values, uint8_t* out) { + *out = (uint8_t)(values[0] | ((values[1] + 0x1) & 0x2) | ((values[2] + 0x3) & 0x4) | + ((values[3] + 0x7) & 0x8) | ((values[4] + 0xf) & 0x10) | + ((values[5] + 0x1f) & 0x20) | ((values[6] + 0x3f) & 0x40) | + ((values[7] + 0x7f) & 0x80)); +} + +static inline void _ArrowBitmapPackInt32(const int32_t* values, uint8_t* out) { + *out = (uint8_t)(values[0] | ((values[1] + 0x1) & 0x2) | ((values[2] + 0x3) & 0x4) | + ((values[3] + 0x7) & 0x8) | ((values[4] + 0xf) & 0x10) | + ((values[5] + 0x1f) & 0x20) | ((values[6] + 0x3f) & 0x40) | + ((values[7] + 0x7f) & 0x80)); +} + +static inline int8_t ArrowBitGet(const uint8_t* bits, int64_t i) { + return (bits[i >> 3] >> (i & 0x07)) & 1; +} + +static inline void ArrowBitsUnpackInt8(const uint8_t* bits, int64_t start_offset, + int64_t length, int8_t* out) { + if (length == 0) { + return; + } + + const int64_t i_begin = start_offset; + const int64_t i_end = start_offset + length; + const int64_t i_last_valid = i_end - 1; + + const int64_t bytes_begin = i_begin / 8; + const int64_t bytes_last_valid = i_last_valid / 8; + + if (bytes_begin == bytes_last_valid) { + for (int i = 0; i < length; i++) { + out[i] = ArrowBitGet(&bits[bytes_begin], i + i_begin % 8); + } + + return; + } + + // first byte + for (int i = 0; i < 8 - (i_begin % 8); i++) { + *out++ = ArrowBitGet(&bits[bytes_begin], i + i_begin % 8); + } + + // middle bytes + for (int64_t i = bytes_begin + 1; i < bytes_last_valid; i++) { + _ArrowBitsUnpackInt8(bits[i], out); + out += 8; + } + + // last byte + const int bits_remaining = (int)(i_end % 8 == 0 ? 8 : i_end % 8); + for (int i = 0; i < bits_remaining; i++) { + *out++ = ArrowBitGet(&bits[bytes_last_valid], i); + } +} + +static inline void ArrowBitsUnpackInt32(const uint8_t* bits, int64_t start_offset, + int64_t length, int32_t* out) { + if (length == 0) { + return; + } + + NANOARROW_DCHECK(bits != NULL && out != NULL); + + const int64_t i_begin = start_offset; + const int64_t i_end = start_offset + length; + const int64_t i_last_valid = i_end - 1; + + const int64_t bytes_begin = i_begin / 8; + const int64_t bytes_last_valid = i_last_valid / 8; + + if (bytes_begin == bytes_last_valid) { + for (int i = 0; i < length; i++) { + out[i] = ArrowBitGet(&bits[bytes_begin], i + i_begin % 8); + } + + return; + } + + // first byte + for (int i = 0; i < 8 - (i_begin % 8); i++) { + *out++ = ArrowBitGet(&bits[bytes_begin], i + i_begin % 8); + } + + // middle bytes + for (int64_t i = bytes_begin + 1; i < bytes_last_valid; i++) { + _ArrowBitsUnpackInt32(bits[i], out); + out += 8; + } + + // last byte + const int bits_remaining = (int)(i_end % 8 == 0 ? 8 : i_end % 8); + for (int i = 0; i < bits_remaining; i++) { + *out++ = ArrowBitGet(&bits[bytes_last_valid], i); + } +} + +static inline void ArrowBitSet(uint8_t* bits, int64_t i) { + bits[i / 8] |= _ArrowkBitmask[i % 8]; +} + +static inline void ArrowBitClear(uint8_t* bits, int64_t i) { + bits[i / 8] &= _ArrowkFlippedBitmask[i % 8]; +} + +static inline void ArrowBitSetTo(uint8_t* bits, int64_t i, uint8_t bit_is_set) { + bits[i / 8] ^= (uint8_t)(((uint8_t)(-((uint8_t)(bit_is_set != 0)) ^ bits[i / 8])) & + _ArrowkBitmask[i % 8]); +} + +static inline void ArrowBitsSetTo(uint8_t* bits, int64_t start_offset, int64_t length, + uint8_t bits_are_set) { + if (length == 0) { + return; + } + + NANOARROW_DCHECK(bits != NULL); + + const int64_t i_begin = start_offset; + const int64_t i_end = start_offset + length; + const uint8_t fill_byte = (uint8_t)(-bits_are_set); + + const int64_t bytes_begin = i_begin / 8; + const int64_t bytes_end = i_end / 8 + 1; + + const uint8_t first_byte_mask = _ArrowkPrecedingBitmask[i_begin % 8]; + const uint8_t last_byte_mask = _ArrowkTrailingBitmask[i_end % 8]; + + if (bytes_end == bytes_begin + 1) { + // set bits within a single byte + const uint8_t only_byte_mask = + i_end % 8 == 0 ? first_byte_mask : (uint8_t)(first_byte_mask | last_byte_mask); + bits[bytes_begin] &= only_byte_mask; + bits[bytes_begin] |= (uint8_t)(fill_byte & ~only_byte_mask); + return; + } + + // set/clear trailing bits of first byte + bits[bytes_begin] &= first_byte_mask; + bits[bytes_begin] |= (uint8_t)(fill_byte & ~first_byte_mask); + + if (bytes_end - bytes_begin > 2) { + // set/clear whole bytes + memset(bits + bytes_begin + 1, fill_byte, (size_t)(bytes_end - bytes_begin - 2)); + } + + if (i_end % 8 == 0) { + return; + } + + // set/clear leading bits of last byte + bits[bytes_end - 1] &= last_byte_mask; + bits[bytes_end - 1] |= (uint8_t)(fill_byte & ~last_byte_mask); +} + +static inline int64_t ArrowBitCountSet(const uint8_t* bits, int64_t start_offset, + int64_t length) { + if (length == 0) { + return 0; + } + + NANOARROW_DCHECK(bits != NULL); + + const int64_t i_begin = start_offset; + const int64_t i_end = start_offset + length; + const int64_t i_last_valid = i_end - 1; + + const int64_t bytes_begin = i_begin / 8; + const int64_t bytes_last_valid = i_last_valid / 8; + + if (bytes_begin == bytes_last_valid) { + // count bits within a single byte + const uint8_t first_byte_mask = _ArrowkPrecedingBitmask[i_end % 8]; + const uint8_t last_byte_mask = _ArrowkTrailingBitmask[i_begin % 8]; + + const uint8_t only_byte_mask = + i_end % 8 == 0 ? last_byte_mask : (uint8_t)(first_byte_mask & last_byte_mask); + + const uint8_t byte_masked = bits[bytes_begin] & only_byte_mask; + return _ArrowkBytePopcount[byte_masked]; + } + + const uint8_t first_byte_mask = _ArrowkPrecedingBitmask[i_begin % 8]; + const uint8_t last_byte_mask = i_end % 8 == 0 ? 0 : _ArrowkTrailingBitmask[i_end % 8]; + int64_t count = 0; + + // first byte + count += _ArrowkBytePopcount[bits[bytes_begin] & ~first_byte_mask]; + + // middle bytes + for (int64_t i = bytes_begin + 1; i < bytes_last_valid; i++) { + count += _ArrowkBytePopcount[bits[i]]; + } + + // last byte + count += _ArrowkBytePopcount[bits[bytes_last_valid] & ~last_byte_mask]; + + return count; +} + +static inline void ArrowBitmapInit(struct ArrowBitmap* bitmap) { + ArrowBufferInit(&bitmap->buffer); + bitmap->size_bits = 0; +} + +static inline void ArrowBitmapMove(struct ArrowBitmap* src, struct ArrowBitmap* dst) { + ArrowBufferMove(&src->buffer, &dst->buffer); + dst->size_bits = src->size_bits; + src->size_bits = 0; +} + +static inline ArrowErrorCode ArrowBitmapReserve(struct ArrowBitmap* bitmap, + int64_t additional_size_bits) { + int64_t min_capacity_bits = bitmap->size_bits + additional_size_bits; + int64_t min_capacity_bytes = _ArrowBytesForBits(min_capacity_bits); + int64_t current_size_bytes = bitmap->buffer.size_bytes; + int64_t current_capacity_bytes = bitmap->buffer.capacity_bytes; + + if (min_capacity_bytes <= current_capacity_bytes) { + return NANOARROW_OK; + } + + int64_t additional_capacity_bytes = min_capacity_bytes - current_size_bytes; + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(&bitmap->buffer, additional_capacity_bytes)); + + // Zero out the last byte for deterministic output in the common case + // of reserving a known remaining size. We should have returned above + // if there was not at least one additional byte to allocate; however, + // DCHECK() just to be sure. + NANOARROW_DCHECK(bitmap->buffer.capacity_bytes > current_capacity_bytes); + bitmap->buffer.data[bitmap->buffer.capacity_bytes - 1] = 0; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowBitmapResize(struct ArrowBitmap* bitmap, + int64_t new_size_bits, + char shrink_to_fit) { + if (new_size_bits < 0) { + return EINVAL; + } + + int64_t new_size_bytes = _ArrowBytesForBits(new_size_bits); + NANOARROW_RETURN_NOT_OK( + ArrowBufferResize(&bitmap->buffer, new_size_bytes, shrink_to_fit)); + + bitmap->size_bits = new_size_bits; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowBitmapAppend(struct ArrowBitmap* bitmap, + uint8_t bits_are_set, int64_t length) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapReserve(bitmap, length)); + + ArrowBitmapAppendUnsafe(bitmap, bits_are_set, length); + return NANOARROW_OK; +} + +static inline void ArrowBitmapAppendUnsafe(struct ArrowBitmap* bitmap, + uint8_t bits_are_set, int64_t length) { + ArrowBitsSetTo(bitmap->buffer.data, bitmap->size_bits, length, bits_are_set); + bitmap->size_bits += length; + bitmap->buffer.size_bytes = _ArrowBytesForBits(bitmap->size_bits); +} + +static inline void ArrowBitmapAppendInt8Unsafe(struct ArrowBitmap* bitmap, + const int8_t* values, int64_t n_values) { + if (n_values == 0) { + return; + } + + NANOARROW_DCHECK(bitmap->buffer.data != NULL); + NANOARROW_DCHECK(values != NULL); + + const int8_t* values_cursor = values; + int64_t n_remaining = n_values; + int64_t out_i_cursor = bitmap->size_bits; + uint8_t* out_cursor = bitmap->buffer.data + bitmap->size_bits / 8; + + // First byte + if ((out_i_cursor % 8) != 0) { + int64_t n_partial_bits = _ArrowRoundUpToMultipleOf8(out_i_cursor) - out_i_cursor; + for (int i = 0; i < n_partial_bits; i++) { + ArrowBitSetTo(bitmap->buffer.data, out_i_cursor++, values[i]); + } + + out_cursor++; + values_cursor += n_partial_bits; + n_remaining -= n_partial_bits; + } + + // Middle bytes + int64_t n_full_bytes = n_remaining / 8; + for (int64_t i = 0; i < n_full_bytes; i++) { + _ArrowBitmapPackInt8(values_cursor, out_cursor); + values_cursor += 8; + out_cursor++; + } + + // Last byte + out_i_cursor += n_full_bytes * 8; + n_remaining -= n_full_bytes * 8; + if (n_remaining > 0) { + // Zero out the last byte + *out_cursor = 0x00; + for (int i = 0; i < n_remaining; i++) { + ArrowBitSetTo(bitmap->buffer.data, out_i_cursor++, values_cursor[i]); + } + out_cursor++; + } + + bitmap->size_bits += n_values; + bitmap->buffer.size_bytes = out_cursor - bitmap->buffer.data; +} + +static inline void ArrowBitmapAppendInt32Unsafe(struct ArrowBitmap* bitmap, + const int32_t* values, int64_t n_values) { + if (n_values == 0) { + return; + } + + NANOARROW_DCHECK(bitmap->buffer.data != NULL); + NANOARROW_DCHECK(values != NULL); + + const int32_t* values_cursor = values; + int64_t n_remaining = n_values; + int64_t out_i_cursor = bitmap->size_bits; + uint8_t* out_cursor = bitmap->buffer.data + bitmap->size_bits / 8; + + // First byte + if ((out_i_cursor % 8) != 0) { + int64_t n_partial_bits = _ArrowRoundUpToMultipleOf8(out_i_cursor) - out_i_cursor; + for (int i = 0; i < n_partial_bits; i++) { + ArrowBitSetTo(bitmap->buffer.data, out_i_cursor++, (uint8_t)values[i]); + } + + out_cursor++; + values_cursor += n_partial_bits; + n_remaining -= n_partial_bits; + } + + // Middle bytes + int64_t n_full_bytes = n_remaining / 8; + for (int64_t i = 0; i < n_full_bytes; i++) { + _ArrowBitmapPackInt32(values_cursor, out_cursor); + values_cursor += 8; + out_cursor++; + } + + // Last byte + out_i_cursor += n_full_bytes * 8; + n_remaining -= n_full_bytes * 8; + if (n_remaining > 0) { + // Zero out the last byte + *out_cursor = 0x00; + for (int i = 0; i < n_remaining; i++) { + ArrowBitSetTo(bitmap->buffer.data, out_i_cursor++, (uint8_t)values_cursor[i]); + } + out_cursor++; + } + + bitmap->size_bits += n_values; + bitmap->buffer.size_bytes = out_cursor - bitmap->buffer.data; +} + +static inline void ArrowBitmapReset(struct ArrowBitmap* bitmap) { + ArrowBufferReset(&bitmap->buffer); + bitmap->size_bits = 0; +} + +#ifdef __cplusplus +} +#endif + +#endif +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_ARRAY_INLINE_H_INCLUDED +#define NANOARROW_ARRAY_INLINE_H_INCLUDED + +#include +#include +#include +#include +#include + + + + +#ifdef __cplusplus +extern "C" { +#endif + +static inline struct ArrowBitmap* ArrowArrayValidityBitmap(struct ArrowArray* array) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + return &private_data->bitmap; +} + +static inline struct ArrowBuffer* ArrowArrayBuffer(struct ArrowArray* array, int64_t i) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + switch (i) { + case 0: + return &private_data->bitmap.buffer; + case 1: + return private_data->buffers; + default: + if (array->n_buffers > 3 && i == (array->n_buffers - 1)) { + // The variadic buffer sizes buffer if for a BinaryView/String view array + // is always stored in private_data->buffers[1]; however, from the numbered + // buffers perspective this is the array->buffers[array->n_buffers - 1]. + return private_data->buffers + 1; + } else if (array->n_buffers > 3) { + // If there are one or more variadic buffers, they are stored in + // private_data->variadic_buffers + return private_data->variadic_buffers + (i - 2); + } else { + // Otherwise, we're just accessing buffer at index 2 (e.g., String/Binary + // data buffer or variadic sizes buffer for the case where there are no + // variadic buffers) + NANOARROW_DCHECK(i == 2); + return private_data->buffers + i - 1; + } + } +} + +// We don't currently support the case of unions where type_id != child_index; +// however, these functions are used to keep track of where that assumption +// is made. +static inline int8_t _ArrowArrayUnionChildIndex(struct ArrowArray* array, + int8_t type_id) { + NANOARROW_UNUSED(array); + return type_id; +} + +static inline int8_t _ArrowArrayUnionTypeId(struct ArrowArray* array, + int8_t child_index) { + NANOARROW_UNUSED(array); + return child_index; +} + +static inline int32_t _ArrowParseUnionTypeIds(const char* type_ids, int8_t* out) { + if (*type_ids == '\0') { + return 0; + } + + int32_t i = 0; + long type_id; + char* end_ptr; + do { + type_id = strtol(type_ids, &end_ptr, 10); + if (end_ptr == type_ids || type_id < 0 || type_id > 127) { + return -1; + } + + if (out != NULL) { + out[i] = (int8_t)type_id; + } + + i++; + + type_ids = end_ptr; + if (*type_ids == '\0') { + return i; + } else if (*type_ids != ',') { + return -1; + } else { + type_ids++; + } + } while (1); + + return -1; +} + +static inline int8_t _ArrowParsedUnionTypeIdsWillEqualChildIndices(const int8_t* type_ids, + int64_t n_type_ids, + int64_t n_children) { + if (n_type_ids != n_children) { + return 0; + } + + for (int8_t i = 0; i < n_type_ids; i++) { + if (type_ids[i] != i) { + return 0; + } + } + + return 1; +} + +static inline int8_t _ArrowUnionTypeIdsWillEqualChildIndices(const char* type_id_str, + int64_t n_children) { + int8_t type_ids[128]; + int32_t n_type_ids = _ArrowParseUnionTypeIds(type_id_str, type_ids); + return _ArrowParsedUnionTypeIdsWillEqualChildIndices(type_ids, n_type_ids, n_children); +} + +static inline ArrowErrorCode ArrowArrayStartAppending(struct ArrowArray* array) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + switch (private_data->storage_type) { + case NANOARROW_TYPE_UNINITIALIZED: + return EINVAL; + case NANOARROW_TYPE_SPARSE_UNION: + case NANOARROW_TYPE_DENSE_UNION: + // Note that this value could be -1 if the type_ids string was invalid + if (private_data->union_type_id_is_child_index != 1) { + return EINVAL; + } else { + break; + } + default: + break; + } + if (private_data->storage_type == NANOARROW_TYPE_UNINITIALIZED) { + return EINVAL; + } + + // Initialize any data offset buffer with a single zero + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + if (private_data->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_DATA_OFFSET && + private_data->layout.element_size_bits[i] == 64) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt64(ArrowArrayBuffer(array, i), 0)); + } else if (private_data->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_DATA_OFFSET && + private_data->layout.element_size_bits[i] == 32) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(ArrowArrayBuffer(array, i), 0)); + } + } + + // Start building any child arrays or dictionaries + for (int64_t i = 0; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayStartAppending(array->children[i])); + } + + if (array->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowArrayStartAppending(array->dictionary)); + } + + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayShrinkToFit(struct ArrowArray* array) { + for (int64_t i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + struct ArrowBuffer* buffer = ArrowArrayBuffer(array, i); + NANOARROW_RETURN_NOT_OK(ArrowBufferResize(buffer, buffer->size_bytes, 1)); + } + + for (int64_t i = 0; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayShrinkToFit(array->children[i])); + } + + if (array->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowArrayShrinkToFit(array->dictionary)); + } + + return NANOARROW_OK; +} + +static inline ArrowErrorCode _ArrowArrayAppendBits(struct ArrowArray* array, + int64_t buffer_i, uint8_t value, + int64_t n) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + struct ArrowBuffer* buffer = ArrowArrayBuffer(array, buffer_i); + int64_t bytes_required = + _ArrowRoundUpToMultipleOf8(private_data->layout.element_size_bits[buffer_i] * + (array->length + 1)) / + 8; + if (bytes_required > buffer->size_bytes) { + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendFill(buffer, 0, bytes_required - buffer->size_bytes)); + } + + ArrowBitsSetTo(buffer->data, array->length, n, value); + return NANOARROW_OK; +} + +static inline ArrowErrorCode _ArrowArrayAppendEmptyInternal(struct ArrowArray* array, + int64_t n, uint8_t is_valid) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + if (n == 0) { + return NANOARROW_OK; + } + + // Some type-specific handling + switch (private_data->storage_type) { + case NANOARROW_TYPE_NA: + // (An empty value for a null array *is* a null) + array->null_count += n; + array->length += n; + return NANOARROW_OK; + + case NANOARROW_TYPE_DENSE_UNION: { + // Add one null to the first child and append n references to that child + int8_t type_id = _ArrowArrayUnionTypeId(array, 0); + NANOARROW_RETURN_NOT_OK( + _ArrowArrayAppendEmptyInternal(array->children[0], 1, is_valid)); + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendFill(ArrowArrayBuffer(array, 0), type_id, n)); + for (int64_t i = 0; i < n; i++) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32( + ArrowArrayBuffer(array, 1), (int32_t)array->children[0]->length - 1)); + } + // For the purposes of array->null_count, union elements are never considered "null" + // even if some children contain nulls. + array->length += n; + return NANOARROW_OK; + } + + case NANOARROW_TYPE_SPARSE_UNION: { + // Add n nulls to the first child and append n references to that child + int8_t type_id = _ArrowArrayUnionTypeId(array, 0); + NANOARROW_RETURN_NOT_OK( + _ArrowArrayAppendEmptyInternal(array->children[0], n, is_valid)); + for (int64_t i = 1; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayAppendEmpty(array->children[i], n)); + } + + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendFill(ArrowArrayBuffer(array, 0), type_id, n)); + // For the purposes of array->null_count, union elements are never considered "null" + // even if some children contain nulls. + array->length += n; + return NANOARROW_OK; + } + + case NANOARROW_TYPE_FIXED_SIZE_LIST: + NANOARROW_RETURN_NOT_OK(ArrowArrayAppendEmpty( + array->children[0], n * private_data->layout.child_size_elements)); + break; + case NANOARROW_TYPE_STRUCT: + for (int64_t i = 0; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayAppendEmpty(array->children[i], n)); + } + break; + + default: + break; + } + + // Append n is_valid bits to the validity bitmap. If we haven't allocated a bitmap yet + // and we need to append nulls, do it now. + if (!is_valid && private_data->bitmap.buffer.data == NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapReserve(&private_data->bitmap, array->length + n)); + ArrowBitmapAppendUnsafe(&private_data->bitmap, 1, array->length); + ArrowBitmapAppendUnsafe(&private_data->bitmap, is_valid, n); + } else if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapReserve(&private_data->bitmap, n)); + ArrowBitmapAppendUnsafe(&private_data->bitmap, is_valid, n); + } + + // Add appropriate buffer fill + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + struct ArrowBuffer* buffer = ArrowArrayBuffer(array, i); + int64_t size_bytes = private_data->layout.element_size_bits[i] / 8; + + switch (private_data->layout.buffer_type[i]) { + case NANOARROW_BUFFER_TYPE_NONE: + case NANOARROW_BUFFER_TYPE_VARIADIC_DATA: + case NANOARROW_BUFFER_TYPE_VARIADIC_SIZE: + case NANOARROW_BUFFER_TYPE_VALIDITY: + // These buffer types don't require initialization for empty appends: + // - NONE: No buffer exists + // - VARIADIC_*: Handled by child arrays + // - VALIDITY: Already handled in previous bitmap logic + break; + + case NANOARROW_BUFFER_TYPE_SIZE: + // Size buffers (e.g., string/array lengths) should be zero-initialized: + // This ensures empty elements have logical zero-length + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n)); + break; + + case NANOARROW_BUFFER_TYPE_DATA_OFFSET: + // Offset buffers require special handling to maintain continuity. + // 1. Reserve space for new offset entries + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes * n)); + + // 2. Duplicate last offset value for each new (empty) element + for (int64_t j = 0; j < n; j++) { + ArrowBufferAppendUnsafe(buffer, buffer->data + size_bytes * (array->length + j), + size_bytes); + } + + // 3. Skip next buffer (DATA) since it's paired with offsets + // Rationale: Offset buffers are always followed by data buffers + // that don't require separate initialization here + i++; + break; + + case NANOARROW_BUFFER_TYPE_DATA: + // Fixed-width data buffers require zero-initialization: + if (private_data->layout.element_size_bits[i] % 8 == 0) { + // Byte-aligned: use efficient memset-style fill + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n)); + } else { + // Bit-packed: use special bitwise initialization + NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, i, 0, n)); + } + break; + + case NANOARROW_BUFFER_TYPE_VIEW_OFFSET: + // View offset buffers (for string/binary view types) require zero-initialization. + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes * n)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n)); + break; + + case NANOARROW_BUFFER_TYPE_TYPE_ID: + case NANOARROW_BUFFER_TYPE_UNION_OFFSET: + // These buffer types should have been handled by the outer type switch and + // are not expected here, indicating an internal logic error. + return EINVAL; + } + } + + array->length += n; + array->null_count += n * !is_valid; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendNull(struct ArrowArray* array, int64_t n) { + return _ArrowArrayAppendEmptyInternal(array, n, 0); +} + +static inline ArrowErrorCode ArrowArrayAppendEmpty(struct ArrowArray* array, int64_t n) { + return _ArrowArrayAppendEmptyInternal(array, n, 1); +} + +static inline ArrowErrorCode ArrowArrayAppendInt(struct ArrowArray* array, + int64_t value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + + switch (private_data->storage_type) { + case NANOARROW_TYPE_INT64: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_buffer, &value, sizeof(int64_t))); + break; + case NANOARROW_TYPE_INT32: + _NANOARROW_CHECK_RANGE(value, INT32_MIN, INT32_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, (int32_t)value)); + break; + case NANOARROW_TYPE_INT16: + _NANOARROW_CHECK_RANGE(value, INT16_MIN, INT16_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt16(data_buffer, (int16_t)value)); + break; + case NANOARROW_TYPE_INT8: + _NANOARROW_CHECK_RANGE(value, INT8_MIN, INT8_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt8(data_buffer, (int8_t)value)); + break; + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_UINT8: + _NANOARROW_CHECK_RANGE(value, 0, INT64_MAX); + return ArrowArrayAppendUInt(array, value); + case NANOARROW_TYPE_DOUBLE: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendDouble(data_buffer, (double)value)); + break; + case NANOARROW_TYPE_FLOAT: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFloat(data_buffer, (float)value)); + break; + case NANOARROW_TYPE_HALF_FLOAT: + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendUInt16(data_buffer, ArrowFloatToHalfFloat((float)value))); + break; + case NANOARROW_TYPE_BOOL: + NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, 1, value != 0, 1)); + break; + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendUInt(struct ArrowArray* array, + uint64_t value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + + switch (private_data->storage_type) { + case NANOARROW_TYPE_UINT64: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_buffer, &value, sizeof(uint64_t))); + break; + case NANOARROW_TYPE_UINT32: + _NANOARROW_CHECK_UPPER_LIMIT(value, UINT32_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendUInt32(data_buffer, (uint32_t)value)); + break; + case NANOARROW_TYPE_UINT16: + _NANOARROW_CHECK_UPPER_LIMIT(value, UINT16_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendUInt16(data_buffer, (uint16_t)value)); + break; + case NANOARROW_TYPE_UINT8: + _NANOARROW_CHECK_UPPER_LIMIT(value, UINT8_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendUInt8(data_buffer, (uint8_t)value)); + break; + case NANOARROW_TYPE_INT64: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_INT8: + _NANOARROW_CHECK_UPPER_LIMIT(value, INT64_MAX); + return ArrowArrayAppendInt(array, value); + case NANOARROW_TYPE_DOUBLE: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendDouble(data_buffer, (double)value)); + break; + case NANOARROW_TYPE_FLOAT: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFloat(data_buffer, (float)value)); + break; + case NANOARROW_TYPE_HALF_FLOAT: + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendUInt16(data_buffer, ArrowFloatToHalfFloat((float)value))); + break; + case NANOARROW_TYPE_BOOL: + NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, 1, value != 0, 1)); + break; + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendDouble(struct ArrowArray* array, + double value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + + switch (private_data->storage_type) { + case NANOARROW_TYPE_DOUBLE: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_buffer, &value, sizeof(double))); + break; + case NANOARROW_TYPE_FLOAT: + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFloat(data_buffer, (float)value)); + break; + case NANOARROW_TYPE_HALF_FLOAT: + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendUInt16(data_buffer, ArrowFloatToHalfFloat((float)value))); + break; + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +// Binary views only have two fixed buffers, but be aware that they must also +// always have more 1 buffer to store variadic buffer sizes (even if there are none) +#define NANOARROW_BINARY_VIEW_FIXED_BUFFERS 2 +#define NANOARROW_BINARY_VIEW_INLINE_SIZE 12 +#define NANOARROW_BINARY_VIEW_PREFIX_SIZE 4 +#define NANOARROW_BINARY_VIEW_BLOCK_SIZE (32 << 10) // 32KB + +// The Arrow C++ implementation uses anonymous structs as members +// of the ArrowBinaryView. For Cython support in this library, we define +// those structs outside of the ArrowBinaryView +struct ArrowBinaryViewInlined { + int32_t size; + uint8_t data[NANOARROW_BINARY_VIEW_INLINE_SIZE]; +}; + +struct ArrowBinaryViewRef { + int32_t size; + uint8_t prefix[NANOARROW_BINARY_VIEW_PREFIX_SIZE]; + int32_t buffer_index; + int32_t offset; +}; + +union ArrowBinaryView { + struct ArrowBinaryViewInlined inlined; + struct ArrowBinaryViewRef ref; + int64_t alignment_dummy; +}; + +static inline int32_t ArrowArrayVariadicBufferCount(struct ArrowArray* array) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + return private_data->n_variadic_buffers; +} + +static inline ArrowErrorCode ArrowArrayAddVariadicBuffers(struct ArrowArray* array, + int32_t n_buffers) { + const int32_t n_current_bufs = ArrowArrayVariadicBufferCount(array); + const int32_t nvariadic_bufs_needed = n_current_bufs + n_buffers; + + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + private_data->variadic_buffers = (struct ArrowBuffer*)ArrowRealloc( + private_data->variadic_buffers, sizeof(struct ArrowBuffer) * nvariadic_bufs_needed); + if (private_data->variadic_buffers == NULL) { + return ENOMEM; + } + + private_data->n_variadic_buffers = nvariadic_bufs_needed; + array->n_buffers = NANOARROW_BINARY_VIEW_FIXED_BUFFERS + 1 + nvariadic_bufs_needed; + + private_data->buffer_data = (const void**)ArrowRealloc( + private_data->buffer_data, array->n_buffers * sizeof(void*)); + + for (int32_t i = n_current_bufs; i < nvariadic_bufs_needed; i++) { + ArrowBufferInit(&private_data->variadic_buffers[i]); + private_data->buffer_data[NANOARROW_BINARY_VIEW_FIXED_BUFFERS + i] = NULL; + } + + // Zero out memory for the final buffer (variadic sizes buffer we haven't built yet) + private_data->buffer_data[NANOARROW_BINARY_VIEW_FIXED_BUFFERS + nvariadic_bufs_needed] = + NULL; + + // Ensure array->buffers points to a valid value + array->buffers = private_data->buffer_data; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendBytes(struct ArrowArray* array, + struct ArrowBufferView value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + if (private_data->storage_type == NANOARROW_TYPE_STRING_VIEW || + private_data->storage_type == NANOARROW_TYPE_BINARY_VIEW) { + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + union ArrowBinaryView bvt; + bvt.inlined.size = (int32_t)value.size_bytes; + + if (value.size_bytes <= NANOARROW_BINARY_VIEW_INLINE_SIZE) { + memcpy(bvt.inlined.data, value.data.as_char, value.size_bytes); + memset(bvt.inlined.data + bvt.inlined.size, 0, + NANOARROW_BINARY_VIEW_INLINE_SIZE - bvt.inlined.size); + } else { + int32_t current_n_vbufs = ArrowArrayVariadicBufferCount(array); + if (current_n_vbufs == 0 || + private_data->variadic_buffers[current_n_vbufs - 1].size_bytes + + value.size_bytes > + NANOARROW_BINARY_VIEW_BLOCK_SIZE) { + const int32_t additional_bufs_needed = 1; + NANOARROW_RETURN_NOT_OK( + ArrowArrayAddVariadicBuffers(array, additional_bufs_needed)); + current_n_vbufs += additional_bufs_needed; + } + + const int32_t buf_index = current_n_vbufs - 1; + struct ArrowBuffer* variadic_buf = &private_data->variadic_buffers[buf_index]; + memcpy(bvt.ref.prefix, value.data.as_char, NANOARROW_BINARY_VIEW_PREFIX_SIZE); + bvt.ref.buffer_index = (int32_t)buf_index; + bvt.ref.offset = (int32_t)variadic_buf->size_bytes; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(variadic_buf, value.data.as_char, value.size_bytes)); + } + NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_buffer, &bvt, sizeof(bvt))); + } else { + struct ArrowBuffer* offset_buffer = ArrowArrayBuffer(array, 1); + struct ArrowBuffer* data_buffer = ArrowArrayBuffer( + array, 1 + (private_data->storage_type != NANOARROW_TYPE_FIXED_SIZE_BINARY)); + int32_t offset; + int64_t large_offset; + int64_t fixed_size_bytes = private_data->layout.element_size_bits[1] / 8; + + switch (private_data->storage_type) { + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + offset = ((int32_t*)offset_buffer->data)[array->length]; + if ((((int64_t)offset) + value.size_bytes) > INT32_MAX) { + return EOVERFLOW; + } + + offset += (int32_t)value.size_bytes; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(offset_buffer, &offset, sizeof(int32_t))); + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value.data.data, value.size_bytes)); + break; + + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_LARGE_BINARY: + large_offset = ((int64_t*)offset_buffer->data)[array->length]; + large_offset += value.size_bytes; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(offset_buffer, &large_offset, sizeof(int64_t))); + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value.data.data, value.size_bytes)); + break; + + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + if (value.size_bytes != fixed_size_bytes) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value.data.data, value.size_bytes)); + break; + default: + return EINVAL; + } + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendString(struct ArrowArray* array, + struct ArrowStringView value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + struct ArrowBufferView buffer_view; + buffer_view.data.data = value.data; + buffer_view.size_bytes = value.size_bytes; + + switch (private_data->storage_type) { + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_STRING_VIEW: + case NANOARROW_TYPE_BINARY: + case NANOARROW_TYPE_LARGE_BINARY: + case NANOARROW_TYPE_BINARY_VIEW: + return ArrowArrayAppendBytes(array, buffer_view); + default: + return EINVAL; + } +} + +static inline ArrowErrorCode ArrowArrayAppendInterval(struct ArrowArray* array, + const struct ArrowInterval* value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + + switch (private_data->storage_type) { + case NANOARROW_TYPE_INTERVAL_MONTHS: { + if (value->type != NANOARROW_TYPE_INTERVAL_MONTHS) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, value->months)); + break; + } + case NANOARROW_TYPE_INTERVAL_DAY_TIME: { + if (value->type != NANOARROW_TYPE_INTERVAL_DAY_TIME) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, value->days)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, value->ms)); + break; + } + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: { + if (value->type != NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, value->months)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(data_buffer, value->days)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt64(data_buffer, value->ns)); + break; + } + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array, + const struct ArrowDecimal* value) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1); + + switch (private_data->storage_type) { + case NANOARROW_TYPE_DECIMAL32: + if (value->n_words != 0) { + return EINVAL; + } else { + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value->words, sizeof(uint32_t))); + break; + } + case NANOARROW_TYPE_DECIMAL64: + if (value->n_words != 1) { + return EINVAL; + } else { + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value->words, sizeof(uint64_t))); + break; + } + case NANOARROW_TYPE_DECIMAL128: + if (value->n_words != 2) { + return EINVAL; + } else { + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value->words, 2 * sizeof(uint64_t))); + break; + } + case NANOARROW_TYPE_DECIMAL256: + if (value->n_words != 4) { + return EINVAL; + } else { + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppend(data_buffer, value->words, 4 * sizeof(uint64_t))); + break; + } + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayFinishElement(struct ArrowArray* array) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + int64_t child_length; + + switch (private_data->storage_type) { + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_MAP: + child_length = array->children[0]->length; + if (child_length > INT32_MAX) { + return EOVERFLOW; + } + + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt32(ArrowArrayBuffer(array, 1), (int32_t)child_length)); + break; + case NANOARROW_TYPE_LARGE_LIST: + child_length = array->children[0]->length; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt64(ArrowArrayBuffer(array, 1), child_length)); + break; + case NANOARROW_TYPE_FIXED_SIZE_LIST: + child_length = array->children[0]->length; + if (child_length != + ((array->length + 1) * private_data->layout.child_size_elements)) { + return EINVAL; + } + break; + case NANOARROW_TYPE_LIST_VIEW: { + child_length = array->children[0]->length; + if (child_length > INT32_MAX) { + return EOVERFLOW; + } + + const int32_t last_valid_offset = (int32_t)private_data->list_view_offset; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt32(ArrowArrayBuffer(array, 1), last_valid_offset)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32( + ArrowArrayBuffer(array, 2), (int32_t)child_length - last_valid_offset)); + private_data->list_view_offset = child_length; + break; + } + case NANOARROW_TYPE_LARGE_LIST_VIEW: { + child_length = array->children[0]->length; + const int64_t last_valid_offset = private_data->list_view_offset; + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt64(ArrowArrayBuffer(array, 1), last_valid_offset)); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt64(ArrowArrayBuffer(array, 2), + child_length - last_valid_offset)); + private_data->list_view_offset = child_length; + break; + } + + case NANOARROW_TYPE_STRUCT: + for (int64_t i = 0; i < array->n_children; i++) { + child_length = array->children[i]->length; + if (child_length != (array->length + 1)) { + return EINVAL; + } + } + break; + default: + return EINVAL; + } + + if (private_data->bitmap.buffer.data != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowBitmapAppend(ArrowArrayValidityBitmap(array), 1, 1)); + } + + array->length++; + return NANOARROW_OK; +} + +static inline ArrowErrorCode ArrowArrayFinishUnionElement(struct ArrowArray* array, + int8_t type_id) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + int64_t child_index = _ArrowArrayUnionChildIndex(array, type_id); + if (child_index < 0 || child_index >= array->n_children) { + return EINVAL; + } + + switch (private_data->storage_type) { + case NANOARROW_TYPE_DENSE_UNION: + // Append the target child length to the union offsets buffer + _NANOARROW_CHECK_RANGE(array->children[child_index]->length, 0, INT32_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32( + ArrowArrayBuffer(array, 1), (int32_t)array->children[child_index]->length - 1)); + break; + case NANOARROW_TYPE_SPARSE_UNION: + // Append one empty to any non-target column that isn't already the right length + // or abort if appending a null will result in a column with invalid length + for (int64_t i = 0; i < array->n_children; i++) { + if (i == child_index || array->children[i]->length == (array->length + 1)) { + continue; + } + + if (array->children[i]->length != array->length) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowArrayAppendEmpty(array->children[i], 1)); + } + + break; + default: + return EINVAL; + } + + // Write to the type_ids buffer + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt8(ArrowArrayBuffer(array, 0), (int8_t)type_id)); + array->length++; + return NANOARROW_OK; +} + +static inline void ArrowArrayViewMove(struct ArrowArrayView* src, + struct ArrowArrayView* dst) { + memcpy(dst, src, sizeof(struct ArrowArrayView)); + ArrowArrayViewInitFromType(src, NANOARROW_TYPE_UNINITIALIZED); +} + +static inline int64_t ArrowArrayViewGetNumBuffers(struct ArrowArrayView* array_view) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + return NANOARROW_BINARY_VIEW_FIXED_BUFFERS + array_view->n_variadic_buffers + 1; + default: + break; + } + + int64_t n_buffers = 0; + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + if (array_view->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_NONE) { + break; + } + + n_buffers++; + } + + return n_buffers; +} + +static inline struct ArrowBufferView ArrowArrayViewGetBufferView( + struct ArrowArrayView* array_view, int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + if (i < NANOARROW_BINARY_VIEW_FIXED_BUFFERS) { + return array_view->buffer_views[i]; + } else if (i >= + (array_view->n_variadic_buffers + NANOARROW_BINARY_VIEW_FIXED_BUFFERS)) { + struct ArrowBufferView view; + view.data.as_int64 = array_view->variadic_buffer_sizes; + view.size_bytes = array_view->n_variadic_buffers * sizeof(double); + return view; + } else { + struct ArrowBufferView view; + view.data.data = + array_view->variadic_buffers[i - NANOARROW_BINARY_VIEW_FIXED_BUFFERS]; + view.size_bytes = + array_view->variadic_buffer_sizes[i - NANOARROW_BINARY_VIEW_FIXED_BUFFERS]; + return view; + } + default: + // We need this check to avoid -Warray-bounds from complaining + if (i >= NANOARROW_MAX_FIXED_BUFFERS) { + struct ArrowBufferView view; + view.data.data = NULL; + view.size_bytes = 0; + return view; + } else { + return array_view->buffer_views[i]; + } + } +} + +enum ArrowBufferType ArrowArrayViewGetBufferType(struct ArrowArrayView* array_view, + int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + if (i < NANOARROW_BINARY_VIEW_FIXED_BUFFERS) { + return array_view->layout.buffer_type[i]; + } else if (i == + (array_view->n_variadic_buffers + NANOARROW_BINARY_VIEW_FIXED_BUFFERS)) { + return NANOARROW_BUFFER_TYPE_VARIADIC_SIZE; + } else { + return NANOARROW_BUFFER_TYPE_VARIADIC_DATA; + } + default: + // We need this check to avoid -Warray-bounds from complaining + if (i >= NANOARROW_MAX_FIXED_BUFFERS) { + return NANOARROW_BUFFER_TYPE_NONE; + } else { + return array_view->layout.buffer_type[i]; + } + } +} + +static inline enum ArrowType ArrowArrayViewGetBufferDataType( + struct ArrowArrayView* array_view, int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + if (i < NANOARROW_BINARY_VIEW_FIXED_BUFFERS) { + return array_view->layout.buffer_data_type[i]; + } else if (i >= + (array_view->n_variadic_buffers + NANOARROW_BINARY_VIEW_FIXED_BUFFERS)) { + return NANOARROW_TYPE_INT64; + } else if (array_view->storage_type == NANOARROW_TYPE_BINARY_VIEW) { + return NANOARROW_TYPE_BINARY; + } else { + return NANOARROW_TYPE_STRING; + } + default: + // We need this check to avoid -Warray-bounds from complaining + if (i >= NANOARROW_MAX_FIXED_BUFFERS) { + return NANOARROW_TYPE_UNINITIALIZED; + } else { + return array_view->layout.buffer_data_type[i]; + } + } +} + +static inline int64_t ArrowArrayViewGetBufferElementSizeBits( + struct ArrowArrayView* array_view, int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + if (i < NANOARROW_BINARY_VIEW_FIXED_BUFFERS) { + return array_view->layout.element_size_bits[i]; + } else if (i >= + (array_view->n_variadic_buffers + NANOARROW_BINARY_VIEW_FIXED_BUFFERS)) { + return sizeof(int64_t) * 8; + } else { + return 0; + } + default: + // We need this check to avoid -Warray-bounds from complaining + if (i >= NANOARROW_MAX_FIXED_BUFFERS) { + return 0; + } else { + return array_view->layout.element_size_bits[i]; + } + } +} + +static inline int8_t ArrowArrayViewIsNull(const struct ArrowArrayView* array_view, + int64_t i) { + const uint8_t* validity_buffer = array_view->buffer_views[0].data.as_uint8; + i += array_view->offset; + switch (array_view->storage_type) { + case NANOARROW_TYPE_NA: + return 0x01; + case NANOARROW_TYPE_DENSE_UNION: + case NANOARROW_TYPE_SPARSE_UNION: + // Unions are "never null" in Arrow land + return 0x00; + default: + return validity_buffer != NULL && !ArrowBitGet(validity_buffer, i); + } +} + +static inline int64_t ArrowArrayViewComputeNullCount( + const struct ArrowArrayView* array_view) { + if (array_view->length == 0) { + return 0; + } + + switch (array_view->storage_type) { + case NANOARROW_TYPE_NA: + return array_view->length; + case NANOARROW_TYPE_DENSE_UNION: + case NANOARROW_TYPE_SPARSE_UNION: + // Unions are "never null" in Arrow land + return 0; + default: + break; + } + + const uint8_t* validity_buffer = array_view->buffer_views[0].data.as_uint8; + if (validity_buffer == NULL) { + return 0; + } + return array_view->length - + ArrowBitCountSet(validity_buffer, array_view->offset, array_view->length); +} + +static inline int8_t ArrowArrayViewUnionTypeId(const struct ArrowArrayView* array_view, + int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_DENSE_UNION: + case NANOARROW_TYPE_SPARSE_UNION: + return array_view->buffer_views[0].data.as_int8[array_view->offset + i]; + default: + return -1; + } +} + +static inline int8_t ArrowArrayViewUnionChildIndex( + const struct ArrowArrayView* array_view, int64_t i) { + int8_t type_id = ArrowArrayViewUnionTypeId(array_view, i); + if (array_view->union_type_id_map == NULL) { + return type_id; + } else { + return array_view->union_type_id_map[type_id]; + } +} + +static inline int64_t ArrowArrayViewUnionChildOffset( + const struct ArrowArrayView* array_view, int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_DENSE_UNION: + return array_view->buffer_views[1].data.as_int32[array_view->offset + i]; + case NANOARROW_TYPE_SPARSE_UNION: + return array_view->offset + i; + default: + return -1; + } +} + +static inline int64_t ArrowArrayViewListChildOffset( + const struct ArrowArrayView* array_view, int64_t i) { + switch (array_view->storage_type) { + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_MAP: + case NANOARROW_TYPE_LIST_VIEW: + return array_view->buffer_views[1].data.as_int32[i]; + case NANOARROW_TYPE_LARGE_LIST: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + return array_view->buffer_views[1].data.as_int64[i]; + default: + return -1; + } +} + +static struct ArrowBufferView ArrowArrayViewGetBytesFromViewArrayUnsafe( + const struct ArrowArrayView* array_view, int64_t i) { + const union ArrowBinaryView* bv = &array_view->buffer_views[1].data.as_binary_view[i]; + struct ArrowBufferView out = {{NULL}, bv->inlined.size}; + if (bv->inlined.size <= NANOARROW_BINARY_VIEW_INLINE_SIZE) { + out.data.as_uint8 = bv->inlined.data; + return out; + } + + out.data.data = array_view->variadic_buffers[bv->ref.buffer_index]; + out.data.as_uint8 += bv->ref.offset; + return out; +} + +static inline int64_t ArrowArrayViewGetIntUnsafe(const struct ArrowArrayView* array_view, + int64_t i) { + const struct ArrowBufferView* data_view = &array_view->buffer_views[1]; + i += array_view->offset; + switch (array_view->storage_type) { + case NANOARROW_TYPE_INT64: + return data_view->data.as_int64[i]; + case NANOARROW_TYPE_UINT64: + return data_view->data.as_uint64[i]; + case NANOARROW_TYPE_INTERVAL_MONTHS: + case NANOARROW_TYPE_INT32: + return data_view->data.as_int32[i]; + case NANOARROW_TYPE_UINT32: + return data_view->data.as_uint32[i]; + case NANOARROW_TYPE_INT16: + return data_view->data.as_int16[i]; + case NANOARROW_TYPE_UINT16: + return data_view->data.as_uint16[i]; + case NANOARROW_TYPE_INT8: + return data_view->data.as_int8[i]; + case NANOARROW_TYPE_UINT8: + return data_view->data.as_uint8[i]; + case NANOARROW_TYPE_DOUBLE: + return (int64_t)data_view->data.as_double[i]; + case NANOARROW_TYPE_FLOAT: + return (int64_t)data_view->data.as_float[i]; + case NANOARROW_TYPE_HALF_FLOAT: + return (int64_t)ArrowHalfFloatToFloat(data_view->data.as_uint16[i]); + case NANOARROW_TYPE_BOOL: + return ArrowBitGet(data_view->data.as_uint8, i); + default: + return INT64_MAX; + } +} + +static inline uint64_t ArrowArrayViewGetUIntUnsafe( + const struct ArrowArrayView* array_view, int64_t i) { + i += array_view->offset; + const struct ArrowBufferView* data_view = &array_view->buffer_views[1]; + switch (array_view->storage_type) { + case NANOARROW_TYPE_INT64: + return data_view->data.as_int64[i]; + case NANOARROW_TYPE_UINT64: + return data_view->data.as_uint64[i]; + case NANOARROW_TYPE_INTERVAL_MONTHS: + case NANOARROW_TYPE_INT32: + return data_view->data.as_int32[i]; + case NANOARROW_TYPE_UINT32: + return data_view->data.as_uint32[i]; + case NANOARROW_TYPE_INT16: + return data_view->data.as_int16[i]; + case NANOARROW_TYPE_UINT16: + return data_view->data.as_uint16[i]; + case NANOARROW_TYPE_INT8: + return data_view->data.as_int8[i]; + case NANOARROW_TYPE_UINT8: + return data_view->data.as_uint8[i]; + case NANOARROW_TYPE_DOUBLE: + return (uint64_t)data_view->data.as_double[i]; + case NANOARROW_TYPE_FLOAT: + return (uint64_t)data_view->data.as_float[i]; + case NANOARROW_TYPE_HALF_FLOAT: + return (uint64_t)ArrowHalfFloatToFloat(data_view->data.as_uint16[i]); + case NANOARROW_TYPE_BOOL: + return ArrowBitGet(data_view->data.as_uint8, i); + default: + return UINT64_MAX; + } +} + +static inline double ArrowArrayViewGetDoubleUnsafe( + const struct ArrowArrayView* array_view, int64_t i) { + i += array_view->offset; + const struct ArrowBufferView* data_view = &array_view->buffer_views[1]; + switch (array_view->storage_type) { + case NANOARROW_TYPE_INT64: + return (double)data_view->data.as_int64[i]; + case NANOARROW_TYPE_UINT64: + return (double)data_view->data.as_uint64[i]; + case NANOARROW_TYPE_INT32: + return data_view->data.as_int32[i]; + case NANOARROW_TYPE_UINT32: + return data_view->data.as_uint32[i]; + case NANOARROW_TYPE_INT16: + return data_view->data.as_int16[i]; + case NANOARROW_TYPE_UINT16: + return data_view->data.as_uint16[i]; + case NANOARROW_TYPE_INT8: + return data_view->data.as_int8[i]; + case NANOARROW_TYPE_UINT8: + return data_view->data.as_uint8[i]; + case NANOARROW_TYPE_DOUBLE: + return data_view->data.as_double[i]; + case NANOARROW_TYPE_FLOAT: + return data_view->data.as_float[i]; + case NANOARROW_TYPE_HALF_FLOAT: + return ArrowHalfFloatToFloat(data_view->data.as_uint16[i]); + case NANOARROW_TYPE_BOOL: + return ArrowBitGet(data_view->data.as_uint8, i); + default: + return DBL_MAX; + } +} + +static inline struct ArrowStringView ArrowArrayViewGetStringUnsafe( + const struct ArrowArrayView* array_view, int64_t i) { + i += array_view->offset; + const struct ArrowBufferView* offsets_view = &array_view->buffer_views[1]; + const char* data_view = array_view->buffer_views[2].data.as_char; + + struct ArrowStringView view; + switch (array_view->storage_type) { + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + view.data = data_view + offsets_view->data.as_int32[i]; + view.size_bytes = + (int64_t)offsets_view->data.as_int32[i + 1] - offsets_view->data.as_int32[i]; + break; + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_LARGE_BINARY: + view.data = data_view + offsets_view->data.as_int64[i]; + view.size_bytes = + offsets_view->data.as_int64[i + 1] - offsets_view->data.as_int64[i]; + break; + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + view.size_bytes = array_view->layout.element_size_bits[1] / 8; + view.data = array_view->buffer_views[1].data.as_char + (i * view.size_bytes); + break; + case NANOARROW_TYPE_STRING_VIEW: + case NANOARROW_TYPE_BINARY_VIEW: { + struct ArrowBufferView buf_view = + ArrowArrayViewGetBytesFromViewArrayUnsafe(array_view, i); + view.data = buf_view.data.as_char; + view.size_bytes = buf_view.size_bytes; + break; + } + default: + view.data = NULL; + view.size_bytes = 0; + break; + } + + return view; +} + +static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe( + const struct ArrowArrayView* array_view, int64_t i) { + i += array_view->offset; + const struct ArrowBufferView* offsets_view = &array_view->buffer_views[1]; + const uint8_t* data_view = array_view->buffer_views[2].data.as_uint8; + + struct ArrowBufferView view; + switch (array_view->storage_type) { + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + view.size_bytes = + (int64_t)offsets_view->data.as_int32[i + 1] - offsets_view->data.as_int32[i]; + view.data.as_uint8 = data_view + offsets_view->data.as_int32[i]; + break; + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_LARGE_BINARY: + view.size_bytes = + offsets_view->data.as_int64[i + 1] - offsets_view->data.as_int64[i]; + view.data.as_uint8 = data_view + offsets_view->data.as_int64[i]; + break; + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + view.size_bytes = array_view->layout.element_size_bits[1] / 8; + view.data.as_uint8 = + array_view->buffer_views[1].data.as_uint8 + (i * view.size_bytes); + break; + case NANOARROW_TYPE_STRING_VIEW: + case NANOARROW_TYPE_BINARY_VIEW: + view = ArrowArrayViewGetBytesFromViewArrayUnsafe(array_view, i); + break; + default: + view.data.data = NULL; + view.size_bytes = 0; + break; + } + + return view; +} + +static inline void ArrowArrayViewGetIntervalUnsafe( + const struct ArrowArrayView* array_view, int64_t i, struct ArrowInterval* out) { + const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8; + const int64_t offset = array_view->offset; + const int64_t index = offset + i; + switch (array_view->storage_type) { + case NANOARROW_TYPE_INTERVAL_MONTHS: { + const size_t size = sizeof(int32_t); + memcpy(&out->months, data_view + index * size, sizeof(int32_t)); + break; + } + case NANOARROW_TYPE_INTERVAL_DAY_TIME: { + const size_t size = sizeof(int32_t) + sizeof(int32_t); + memcpy(&out->days, data_view + index * size, sizeof(int32_t)); + memcpy(&out->ms, data_view + index * size + 4, sizeof(int32_t)); + break; + } + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: { + const size_t size = sizeof(int32_t) + sizeof(int32_t) + sizeof(int64_t); + memcpy(&out->months, data_view + index * size, sizeof(int32_t)); + memcpy(&out->days, data_view + index * size + 4, sizeof(int32_t)); + memcpy(&out->ns, data_view + index * size + 8, sizeof(int64_t)); + break; + } + default: + break; + } +} + +static inline void ArrowArrayViewGetDecimalUnsafe(const struct ArrowArrayView* array_view, + int64_t i, struct ArrowDecimal* out) { + i += array_view->offset; + const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8; + switch (array_view->storage_type) { + case NANOARROW_TYPE_DECIMAL32: + ArrowDecimalSetBytes(out, data_view + (i * 4)); + break; + case NANOARROW_TYPE_DECIMAL64: + ArrowDecimalSetBytes(out, data_view + (i * 8)); + break; + case NANOARROW_TYPE_DECIMAL128: + ArrowDecimalSetBytes(out, data_view + (i * 16)); + break; + case NANOARROW_TYPE_DECIMAL256: + ArrowDecimalSetBytes(out, data_view + (i * 32)); + break; + default: + memset(out->words, 0, sizeof(out->words)); + break; + } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/nanoarrow/include/nanoarrow/nanoarrow_ipc.h b/third_party/nanoarrow/include/nanoarrow/nanoarrow_ipc.h new file mode 100644 index 0000000..b9251a6 --- /dev/null +++ b/third_party/nanoarrow/include/nanoarrow/nanoarrow_ipc.h @@ -0,0 +1,779 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef NANOARROW_IPC_H_INCLUDED +#define NANOARROW_IPC_H_INCLUDED + +#include "nanoarrow/nanoarrow.h" + +#ifdef NANOARROW_NAMESPACE + +#define ArrowIpcCheckRuntime NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcCheckRuntime) +#define ArrowIpcSharedBufferIsThreadSafe \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcSharedBufferIsThreadSafe) +#define ArrowIpcSharedBufferInit \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcSharedBufferInit) +#define ArrowIpcSharedBufferReset \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcSharedBufferReset) +#define ArrowIpcGetZstdDecompressionFunction \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcGetZstdDecompressionFunction) +#define ArrowIpcGetLZ4DecompressionFunction \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcGetLZ4DecompressionFunction) +#define ArrowIpcSerialDecompressor \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcSerialDecompressor) +#define ArrowIpcSerialDecompressorSetFunction \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcSerialDecompressorSetFunction) +#define ArrowIpcDecoderInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderInit) +#define ArrowIpcDecoderReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderReset) +#define ArrowIpcDecoderSetDecompressor \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderSetDecompressor) +#define ArrowIpcDecoderPeekHeader \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderPeekHeader) +#define ArrowIpcDecoderVerifyHeader \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderVerifyHeader) +#define ArrowIpcDecoderDecodeHeader \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeHeader) +#define ArrowIpcDecoderDecodeSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeSchema) +#define ArrowIpcDecoderDecodeArrayView \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeArrayView) +#define ArrowIpcDecoderDecodeArray \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeArray) +#define ArrowIpcDecoderDecodeArrayFromShared \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeArrayFromShared) +#define ArrowIpcDecoderSetSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderSetSchema) +#define ArrowIpcDecoderSetEndianness \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderSetEndianness) +#define ArrowIpcDecoderPeekFooter \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderPeekFooter) +#define ArrowIpcDecoderVerifyFooter \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderVerifyFooter) +#define ArrowIpcDecoderDecodeFooter \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcDecoderDecodeFooter) +#define ArrowIpcInputStreamInitBuffer \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcInputStreamInitBuffer) +#define ArrowIpcInputStreamInitFile \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcInputStreamInitFile) +#define ArrowIpcInputStreamMove \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcInputStreamMove) +#define ArrowIpcArrayStreamReaderInit \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcArrayStreamReaderInit) +#define ArrowIpcEncoderInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderInit) +#define ArrowIpcEncoderReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderReset) +#define ArrowIpcEncoderFinalizeBuffer \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderFinalizeBuffer) +#define ArrowIpcEncoderEncodeSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderEncodeSchema) +#define ArrowIpcEncoderEncodeSimpleRecordBatch \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderEncodeSimpleRecordBatch) +#define ArrowIpcOutputStreamInitBuffer \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcOutputStreamInitBuffer) +#define ArrowIpcOutputStreamInitFile \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcOutputStreamInitFile) +#define ArrowIpcOutputStreamWrite \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcOutputStreamWrite) +#define ArrowIpcOutputStreamMove \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcOutputStreamMove) +#define ArrowIpcWriterInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterInit) +#define ArrowIpcWriterReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterReset) +#define ArrowIpcWriterWriteSchema \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterWriteSchema) +#define ArrowIpcWriterWriteArrayView \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterWriteArrayView) +#define ArrowIpcWriterWriteArrayStream \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterWriteArrayStream) +#define ArrowIpcWriterStartFile \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterStartFile) +#define ArrowIpcWriterFinalizeFile \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcWriterFinalizeFile) +#define ArrowIpcFooterInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcFooterInit) +#define ArrowIpcFooterReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcFooterReset) +#define ArrowIpcEncoderEncodeFooter \ + NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowIpcEncoderEncodeFooter) + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/// \defgroup nanoarrow_ipc Nanoarrow IPC extension +/// +/// Except where noted, objects are not thread-safe and clients should +/// take care to serialize accesses to methods. +/// +/// Because this library is intended to be vendored, it provides full type +/// definitions and encourages clients to stack or statically allocate +/// where convenient. +/// +/// @{ + +/// \brief Metadata version enumerator +enum ArrowIpcMetadataVersion { + NANOARROW_IPC_METADATA_VERSION_V1, + NANOARROW_IPC_METADATA_VERSION_V2, + NANOARROW_IPC_METADATA_VERSION_V3, + NANOARROW_IPC_METADATA_VERSION_V4, + NANOARROW_IPC_METADATA_VERSION_V5 +}; + +/// \brief Message type enumerator +enum ArrowIpcMessageType { + NANOARROW_IPC_MESSAGE_TYPE_UNINITIALIZED, + NANOARROW_IPC_MESSAGE_TYPE_SCHEMA, + NANOARROW_IPC_MESSAGE_TYPE_DICTIONARY_BATCH, + NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH, + NANOARROW_IPC_MESSAGE_TYPE_TENSOR, + NANOARROW_IPC_MESSAGE_TYPE_SPARSE_TENSOR +}; + +/// \brief Endianness enumerator +enum ArrowIpcEndianness { + NANOARROW_IPC_ENDIANNESS_UNINITIALIZED, + NANOARROW_IPC_ENDIANNESS_LITTLE, + NANOARROW_IPC_ENDIANNESS_BIG +}; + +/// \brief Compression type enumerator +enum ArrowIpcCompressionType { + NANOARROW_IPC_COMPRESSION_TYPE_NONE, + NANOARROW_IPC_COMPRESSION_TYPE_LZ4_FRAME, + NANOARROW_IPC_COMPRESSION_TYPE_ZSTD +}; + +/// \brief Feature flag for a stream that uses dictionary replacement +#define NANOARROW_IPC_FEATURE_DICTIONARY_REPLACEMENT 1 + +/// \brief Feature flag for a stream that uses compression +#define NANOARROW_IPC_FEATURE_COMPRESSED_BODY 2 + +/// \brief Checks the nanoarrow runtime to make sure the run/build versions match +NANOARROW_DLL ArrowErrorCode ArrowIpcCheckRuntime(struct ArrowError* error); + +/// \brief Get the endianness of the current runtime +static inline enum ArrowIpcEndianness ArrowIpcSystemEndianness(void) { + uint32_t check = 1; + char first_byte; + memcpy(&first_byte, &check, sizeof(char)); + if (first_byte) { + return NANOARROW_IPC_ENDIANNESS_LITTLE; + } else { + return NANOARROW_IPC_ENDIANNESS_BIG; + } +} + +/// \brief A structure representing a reference-counted buffer that may be passed to +/// ArrowIpcDecoderDecodeArrayFromShared(). +struct ArrowIpcSharedBuffer { + struct ArrowBuffer private_src; +}; + +/// \brief Initialize the contents of a ArrowIpcSharedBuffer struct +/// +/// If NANOARROW_OK is returned, the ArrowIpcSharedBuffer takes ownership of +/// src. +NANOARROW_DLL ArrowErrorCode ArrowIpcSharedBufferInit(struct ArrowIpcSharedBuffer* shared, + struct ArrowBuffer* src); + +/// \brief Release the caller's copy of the shared buffer +/// +/// When finished, the caller must relinquish its own copy of the shared data +/// using this function. The original buffer will continue to exist until all +/// ArrowArray objects that refer to it have also been released. +NANOARROW_DLL void ArrowIpcSharedBufferReset(struct ArrowIpcSharedBuffer* shared); + +/// \brief Check for shared buffer thread safety +/// +/// Thread-safe shared buffers require C11 and the stdatomic.h header. +/// If either are unavailable, shared buffers are still possible but +/// the resulting arrays must not be passed to other threads to be released. +NANOARROW_DLL int ArrowIpcSharedBufferIsThreadSafe(void); + +/// \brief A user-extensible decompressor +/// +/// The ArrowIpcDecompressor is the underlying object that enables decompression in the +/// ArrowIpcDecoder. Its structure allows it to be backed by a multithreaded +/// implementation; however, this is not required and the default implementation does not +/// implement this. An implementation of a decompressor may support more than one +/// ArrowIpcCompressionType. +struct ArrowIpcDecompressor { + /// \brief Queue a buffer for decompression + /// + /// The values pointed to by dst and dst_size after a call to decompress_add + /// are undefined until the next call to decompress_wait returns NANOARROW_OK. + ArrowErrorCode (*decompress_add)(struct ArrowIpcDecompressor* decompressor, + enum ArrowIpcCompressionType compression_type, + struct ArrowBufferView src, uint8_t* dst, + int64_t dst_size, struct ArrowError* error); + + /// \brief Wait for any unfinished calls to decompress_add to complete + /// + /// Returns NANOARROW_OK if all pending calls completed. Returns ETIMEOUT + /// if not all remaining calls completed. + ArrowErrorCode (*decompress_wait)(struct ArrowIpcDecompressor* decompressor, + int64_t timeout_ms, struct ArrowError* error); + + /// \brief Release the decompressor and any resources it may be holding + /// + /// Release callback implementations must set the release member to NULL. + /// Callers must check that the release callback is not NULL before calling + /// decompress() or release(). + void (*release)(struct ArrowIpcDecompressor* decompressor); + + /// \brief Implementation-specific opaque data + void* private_data; +}; + +/// \brief A self-contained decompression function +/// +/// For the most common compression type, ZSTD, this function is sufficient to +/// capture the type of decompression that Arrow IPC requires (i.e., decompression +/// where the uncompressed size was recorded). For other compression types, it +/// may be more efficient to implement a full ArrowIpcDecompressor, which allows +/// for persistent state/allocations between decodes. +typedef ArrowErrorCode (*ArrowIpcDecompressFunction)(struct ArrowBufferView src, + uint8_t* dst, int64_t dst_size, + struct ArrowError* error); + +/// \brief Get the decompression function for ZSTD +/// +/// The result will be NULL if nanoarrow was not built with NANOARROW_IPC_WITH_ZSTD. +NANOARROW_DLL ArrowIpcDecompressFunction ArrowIpcGetZstdDecompressionFunction(void); + +/// \brief Get the decompression function for LZ4 +/// +/// The result will be NULL if nanoarrow was not built with NANOARROW_IPC_WITH_LZ4. +NANOARROW_DLL ArrowIpcDecompressFunction ArrowIpcGetLZ4DecompressionFunction(void); + +/// \brief An ArrowIpcDecompressor implementation that performs decompression in serial +NANOARROW_DLL ArrowErrorCode +ArrowIpcSerialDecompressor(struct ArrowIpcDecompressor* decompressor); + +/// \brief Override the ArrowIpcDecompressFunction used for a specific compression type +/// +/// This may be used to inject support for a particular type of decompression if used +/// with a version of nanoarrow with unknown or minimal capabilities. +NANOARROW_DLL ArrowErrorCode +ArrowIpcSerialDecompressorSetFunction(struct ArrowIpcDecompressor* decompressor, + enum ArrowIpcCompressionType compression_type, + ArrowIpcDecompressFunction decompress_function); + +/// \brief Decoder for Arrow IPC messages +/// +/// This structure is intended to be allocated by the caller, +/// initialized using ArrowIpcDecoderInit(), and released with +/// ArrowIpcDecoderReset(). These fields should not be modified +/// by the caller but can be read following a call to +/// ArrowIpcDecoderPeekHeader(), ArrowIpcDecoderVerifyHeader(), or +/// ArrowIpcDecoderDecodeHeader(). +struct ArrowIpcDecoder { + /// \brief The last verified or decoded message type + enum ArrowIpcMessageType message_type; + + /// \brief The metadata version as indicated by the current schema message + enum ArrowIpcMetadataVersion metadata_version; + + /// \brief Buffer endianness as indicated by the current schema message + enum ArrowIpcEndianness endianness; + + /// \brief Arrow IPC Features used as indicated by the current Schema message + int32_t feature_flags; + + /// \brief Compression used by the current RecordBatch message + enum ArrowIpcCompressionType codec; + + /// \brief The number of bytes in the current header message + /// + /// This value includes the 8 bytes before the start of the header message + /// content and any padding bytes required to make the header message size + /// be a multiple of 8 bytes. + int32_t header_size_bytes; + + /// \brief The number of bytes in the forthcoming body message. + int64_t body_size_bytes; + + /// \brief The last decoded Footer + /// + /// \warning This API is currently only public for use in integration testing; + /// use at your own risk. + struct ArrowIpcFooter* footer; + + /// \brief Private resources managed by this library + void* private_data; +}; + +/// \brief Initialize a decoder +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderInit(struct ArrowIpcDecoder* decoder); + +/// \brief Release all resources attached to a decoder +NANOARROW_DLL void ArrowIpcDecoderReset(struct ArrowIpcDecoder* decoder); + +/// \brief Set the decompressor implementation used by this decoder +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderSetDecompressor( + struct ArrowIpcDecoder* decoder, struct ArrowIpcDecompressor* decompressor); + +/// \brief Peek at a message header +/// +/// The first 8 bytes of an Arrow IPC message are 0xFFFFFFFF followed by the size +/// of the header as a little-endian 32-bit integer. ArrowIpcDecoderPeekHeader() reads +/// these bytes and returns ESPIPE if there are not enough remaining bytes in data to read +/// the entire header message, EINVAL if the first 8 bytes are not valid, ENODATA if the +/// Arrow end-of-stream indicator has been reached, or NANOARROW_OK otherwise. +/// +/// Pre-1.0 messages were not prefixed with 0xFFFFFFFF. For these messages, a value +/// of 4 will be placed into prefix_size_bytes; otherwise a value of 8 will be placed +/// into prefix_size_bytes. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderPeekHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + int32_t* prefix_size_bytes, + struct ArrowError* error); + +/// \brief Verify a message header +/// +/// Runs ArrowIpcDecoderPeekHeader() to ensure data is sufficiently large but additionally +/// runs flatbuffer verification to ensure that decoding the data will not access +/// memory outside of the buffer specified by data. ArrowIpcDecoderVerifyHeader() will +/// also set decoder.header_size_bytes, decoder.body_size_bytes, decoder.metadata_version, +/// and decoder.message_type. +/// +/// Returns as ArrowIpcDecoderPeekHeader() and additionally will +/// return EINVAL if flatbuffer verification fails. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderVerifyHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error); + +/// \brief Decode a message header +/// +/// Runs ArrowIpcDecoderPeekHeader() to ensure data is sufficiently large and decodes +/// the content of the message header. If data contains a schema message, +/// decoder.endianness and decoder.feature_flags is set and ArrowIpcDecoderDecodeSchema() +/// can be used to obtain the decoded schema. If data contains a record batch message, +/// decoder.codec is set and a successful call can be followed by a call to +/// ArrowIpcDecoderDecodeArray(). +/// +/// In almost all cases this should be preceded by a call to +/// ArrowIpcDecoderVerifyHeader() to ensure decoding does not access data outside of the +/// specified buffer. +/// +/// Returns EINVAL if the content of the message cannot be decoded or ENOTSUP if the +/// content of the message uses features not supported by this library. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error); + +/// \brief Decode an ArrowSchema +/// +/// After a successful call to ArrowIpcDecoderDecodeHeader(), retrieve an ArrowSchema. +/// The caller is responsible for releasing the schema if NANOARROW_OK is returned. +/// +/// Returns EINVAL if the decoder did not just decode a schema message or +/// NANOARROW_OK otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeSchema(struct ArrowIpcDecoder* decoder, + struct ArrowSchema* out, + struct ArrowError* error); + +/// \brief Set the ArrowSchema used to decode future record batch messages +/// +/// Prepares the decoder for future record batch messages +/// of this type. The decoder takes ownership of schema if NANOARROW_OK is returned. +/// Note that you must call this explicitly after decoding a +/// Schema message (i.e., the decoder does not assume that the last-decoded +/// schema message applies to future record batch messages). +/// +/// Returns EINVAL if schema validation fails or NANOARROW_OK otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderSetSchema(struct ArrowIpcDecoder* decoder, + struct ArrowSchema* schema, + struct ArrowError* error); + +/// \brief Set the endianness used to decode future record batch messages +/// +/// Prepares the decoder for future record batch messages with the specified +/// endianness. Note that you must call this explicitly after decoding a +/// Schema message (i.e., the decoder does not assume that the last-decoded +/// schema message applies to future record batch messages). +/// +/// Returns NANOARROW_OK on success. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderSetEndianness( + struct ArrowIpcDecoder* decoder, enum ArrowIpcEndianness endianness); + +/// \brief Decode an ArrowArrayView +/// +/// After a successful call to ArrowIpcDecoderDecodeHeader(), deserialize the content +/// of body into an internally-managed ArrowArrayView and return it. Note that field index +/// does not equate to column index if any columns contain nested types. Use a value of -1 +/// to decode the entire array into a struct. The pointed-to ArrowArrayView is owned by +/// the ArrowIpcDecoder and must not be released. +/// +/// For streams that match system endianness and do not use compression, this operation +/// will not perform any heap allocations; however, the buffers referred to by the +/// returned ArrowArrayView are only valid as long as the buffer referred to by body stays +/// valid. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeArrayView( + struct ArrowIpcDecoder* decoder, struct ArrowBufferView body, int64_t i, + struct ArrowArrayView** out, struct ArrowError* error); + +/// \brief Decode an ArrowArray +/// +/// After a successful call to ArrowIpcDecoderDecodeHeader(), assemble an ArrowArray given +/// a message body and a field index. Note that field index does not equate to column +/// index if any columns contain nested types. Use a value of -1 to decode the entire +/// array into a struct. The caller is responsible for releasing the array if +/// NANOARROW_OK is returned. +/// +/// Returns EINVAL if the decoder did not just decode a record batch message, ENOTSUP +/// if the message uses features not supported by this library, or or NANOARROW_OK +/// otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeArray( + struct ArrowIpcDecoder* decoder, struct ArrowBufferView body, int64_t i, + struct ArrowArray* out, enum ArrowValidationLevel validation_level, + struct ArrowError* error); + +/// \brief Decode an ArrowArray from an owned buffer +/// +/// This implementation takes advantage of the fact that it can avoid copying individual +/// buffers. In all cases the caller must ArrowIpcSharedBufferReset() body after one or +/// more calls to ArrowIpcDecoderDecodeArrayFromShared(). If +/// ArrowIpcSharedBufferIsThreadSafe() returns 0, out must not be released by another +/// thread. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeArrayFromShared( + struct ArrowIpcDecoder* decoder, struct ArrowIpcSharedBuffer* shared, int64_t i, + struct ArrowArray* out, enum ArrowValidationLevel validation_level, + struct ArrowError* error); + +/// \brief An user-extensible input data source +struct ArrowIpcInputStream { + /// \brief Read up to buf_size_bytes from stream into buf + /// + /// The actual number of bytes read is placed in the value pointed to by + /// size_read_out. Returns NANOARROW_OK on success. + ArrowErrorCode (*read)(struct ArrowIpcInputStream* stream, uint8_t* buf, + int64_t buf_size_bytes, int64_t* size_read_out, + struct ArrowError* error); + + /// \brief Release the stream and any resources it may be holding + /// + /// Release callback implementations must set the release member to NULL. + /// Callers must check that the release callback is not NULL before calling + /// read() or release(). + void (*release)(struct ArrowIpcInputStream* stream); + + /// \brief Private implementation-defined data + void* private_data; +}; + +/// \brief Transfer ownership of an ArrowIpcInputStream +NANOARROW_DLL void ArrowIpcInputStreamMove(struct ArrowIpcInputStream* src, + struct ArrowIpcInputStream* dst); + +/// \brief Create an input stream from an ArrowBuffer +/// +/// The stream takes ownership of the buffer and reads bytes from it. +NANOARROW_DLL ArrowErrorCode ArrowIpcInputStreamInitBuffer( + struct ArrowIpcInputStream* stream, struct ArrowBuffer* input); + +/// \brief Create an input stream from a C FILE* pointer +/// +/// Note that the ArrowIpcInputStream has no mechanism to communicate an error +/// if file_ptr fails to close. If this behaviour is needed, pass false to +/// close_on_release and handle closing the file independently from stream. +NANOARROW_DLL ArrowErrorCode ArrowIpcInputStreamInitFile( + struct ArrowIpcInputStream* stream, void* file_ptr, int close_on_release); + +/// \brief Options for ArrowIpcArrayStreamReaderInit() +struct ArrowIpcArrayStreamReaderOptions { + /// \brief The field index to extract. + /// + /// Defaults to -1 (i.e., read all fields). Note that this field index refers to + /// the flattened tree of children and not necessarily the column index. + int64_t field_index; + + /// \brief Set to a non-zero value to share the message body buffer among decoded arrays + /// + /// Sharing buffers is a good choice when (1) using memory-mapped IO + /// (since unreferenced portions of the file are often not loaded into memory) or + /// (2) if all data from all columns are about to be referenced anyway. When loading + /// a single field there is probably no advantage to using shared buffers. + /// Defaults to the value of ArrowIpcSharedBufferIsThreadSafe(). + int use_shared_buffers; +}; + +/// \brief Initialize an ArrowArrayStream from an input stream of bytes +/// +/// The stream of bytes must begin with a Schema message and be followed by +/// zero or more RecordBatch messages as described in the Arrow IPC stream +/// format specification. Returns NANOARROW_OK on success. If NANOARROW_OK +/// is returned, the ArrowArrayStream takes ownership of input_stream and +/// the caller is responsible for releasing out. +NANOARROW_DLL ArrowErrorCode ArrowIpcArrayStreamReaderInit( + struct ArrowArrayStream* out, struct ArrowIpcInputStream* input_stream, + struct ArrowIpcArrayStreamReaderOptions* options); + +/// \brief Encoder for Arrow IPC messages +/// +/// This structure is intended to be allocated by the caller, +/// initialized using ArrowIpcEncoderInit(), and released with +/// ArrowIpcEncoderReset(). +struct ArrowIpcEncoder { + /// \brief Private resources managed by this library + void* private_data; +}; + +/// \brief Initialize an encoder +/// +/// If NANOARROW_OK is returned, the caller must call ArrowIpcEncoderReset() +/// to release resources allocated by this function. +NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderInit(struct ArrowIpcEncoder* encoder); + +/// \brief Release all resources attached to an encoder +NANOARROW_DLL void ArrowIpcEncoderReset(struct ArrowIpcEncoder* encoder); + +/// \brief Finalize the most recently encoded message into a buffer +/// +/// If specified, the message will be encapsulated (prefixed with the continuation +/// marker and the header size and 0-padded to a multiple of 8 bytes). +/// +/// The bytes of the encoded message will be appended to the provided buffer. +NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderFinalizeBuffer( + struct ArrowIpcEncoder* encoder, char encapsulate, struct ArrowBuffer* out); + +/// \brief Encode an ArrowSchema +/// +/// Returns ENOMEM if allocation fails, NANOARROW_OK otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderEncodeSchema(struct ArrowIpcEncoder* encoder, + const struct ArrowSchema* schema, + struct ArrowError* error); + +/// \brief Encode a struct typed ArrayView to a flatbuffer RecordBatch, embedded in a +/// Message. +/// +/// Body buffers are concatenated into a contiguous, padded body_buffer. +/// +/// Returns ENOMEM if allocation fails, NANOARROW_OK otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderEncodeSimpleRecordBatch( + struct ArrowIpcEncoder* encoder, const struct ArrowArrayView* array_view, + struct ArrowBuffer* body_buffer, struct ArrowError* error); + +/// \brief An user-extensible output data sink +struct ArrowIpcOutputStream { + /// \brief Write up to buf_size_bytes from stream into buf + /// + /// The actual number of bytes written is placed in the value pointed to by + /// size_read_out. Returns NANOARROW_OK on success. + ArrowErrorCode (*write)(struct ArrowIpcOutputStream* stream, const void* buf, + int64_t buf_size_bytes, int64_t* size_written_out, + struct ArrowError* error); + + /// \brief Release the stream and any resources it may be holding + /// + /// Release callback implementations must set the release member to NULL. + /// Callers must check that the release callback is not NULL before calling + /// read() or release(). + void (*release)(struct ArrowIpcOutputStream* stream); + + /// \brief Private implementation-defined data + void* private_data; +}; + +/// \brief Transfer ownership of an ArrowIpcOutputStream +NANOARROW_DLL void ArrowIpcOutputStreamMove(struct ArrowIpcOutputStream* src, + struct ArrowIpcOutputStream* dst); + +/// \brief Create an output stream from an ArrowBuffer +/// +/// All bytes witten to the stream will be appended to the buffer. +/// The stream does not take ownership of the buffer. +NANOARROW_DLL ArrowErrorCode ArrowIpcOutputStreamInitBuffer( + struct ArrowIpcOutputStream* stream, struct ArrowBuffer* output); + +/// \brief Create an output stream from a C FILE* pointer +/// +/// Note that the ArrowIpcOutputStream has no mechanism to communicate an error +/// if file_ptr fails to close. If this behaviour is needed, pass false to +/// close_on_release and handle closing the file independently from stream. +NANOARROW_DLL ArrowErrorCode ArrowIpcOutputStreamInitFile( + struct ArrowIpcOutputStream* stream, void* file_ptr, int close_on_release); + +/// \brief Write to a stream, trying again until all are written or the stream errors. +NANOARROW_DLL ArrowErrorCode +ArrowIpcOutputStreamWrite(struct ArrowIpcOutputStream* stream, + struct ArrowBufferView data, struct ArrowError* error); + +/// \brief A stream writer which encodes Schemas and ArrowArrays into an IPC byte stream +/// +/// This structure is intended to be allocated by the caller, +/// initialized using ArrowIpcWriterInit(), and released with +/// ArrowIpcWriterReset(). +struct ArrowIpcWriter { + /// \brief Private resources managed by this library + void* private_data; +}; + +/// \brief Initialize an output stream of bytes from an ArrowArrayStream +/// +/// Returns NANOARROW_OK on success. If NANOARROW_OK is returned the writer +/// takes ownership of the output byte stream, and the caller is +/// responsible for releasing the writer by calling ArrowIpcWriterReset(). +NANOARROW_DLL ArrowErrorCode ArrowIpcWriterInit( + struct ArrowIpcWriter* writer, struct ArrowIpcOutputStream* output_stream); + +/// \brief Release all resources attached to a writer +NANOARROW_DLL void ArrowIpcWriterReset(struct ArrowIpcWriter* writer); + +/// \brief Write a schema to the output byte stream +/// +/// Errors are propagated from the underlying encoder and output byte stream. +NANOARROW_DLL ArrowErrorCode ArrowIpcWriterWriteSchema(struct ArrowIpcWriter* writer, + const struct ArrowSchema* in, + struct ArrowError* error); + +/// \brief Write an array view to the output byte stream +/// +/// The array view may be NULL, in which case an EOS will be written. +/// The writer does not check that a schema was already written. +/// +/// Errors are propagated from the underlying encoder and output byte stream, +NANOARROW_DLL ArrowErrorCode ArrowIpcWriterWriteArrayView(struct ArrowIpcWriter* writer, + const struct ArrowArrayView* in, + struct ArrowError* error); + +/// \brief Write an entire stream (including EOS) to the output byte stream +/// +/// Errors are propagated from the underlying encoder, array stream, and output byte +/// stream. +NANOARROW_DLL ArrowErrorCode ArrowIpcWriterWriteArrayStream(struct ArrowIpcWriter* writer, + struct ArrowArrayStream* in, + struct ArrowError* error); + +/// \brief Start writing an IPC file +/// +/// Writes the Arrow IPC magic and sets the writer up to track written blocks. +ArrowErrorCode ArrowIpcWriterStartFile(struct ArrowIpcWriter* writer, + struct ArrowError* error); + +/// \brief Finish writing an IPC file +/// +/// Writes the IPC file's footer, footer size, and ending magic. +NANOARROW_DLL ArrowErrorCode ArrowIpcWriterFinalizeFile(struct ArrowIpcWriter* writer, + struct ArrowError* error); +/// @} + +// Internal APIs: + +/// \brief Represents a byte range in an IPC file. +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +struct ArrowIpcFileBlock { + /// \brief offset relative to the first byte of the file. + int64_t offset; + /// \brief length of encapsulated metadata Message (including padding) + int32_t metadata_length; + /// \brief length of contiguous body buffers (including padding) + int64_t body_length; +}; + +/// \brief A footer for use in an IPC file +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +/// +/// This structure is intended to be allocated by the caller, initialized using +/// ArrowIpcFooterInit(), and released with ArrowIpcFooterReset(). +struct ArrowIpcFooter { + /// \brief the Footer's embedded Schema + struct ArrowSchema schema; + /// \brief all blocks containing RecordBatch Messages + struct ArrowBuffer record_batch_blocks; +}; + +/// \brief Initialize a footer +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +NANOARROW_DLL void ArrowIpcFooterInit(struct ArrowIpcFooter* footer); + +/// \brief Release all resources attached to an footer +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +NANOARROW_DLL void ArrowIpcFooterReset(struct ArrowIpcFooter* footer); + +/// \brief Encode a footer for use in an IPC file +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +/// +/// Returns ENOMEM if allocation fails, NANOARROW_OK otherwise. +NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderEncodeFooter( + struct ArrowIpcEncoder* encoder, const struct ArrowIpcFooter* footer, + struct ArrowError* error); + +/// \brief Peek at a footer +/// +/// The last 10 bytes of an Arrow IPC file are the footer size as a little-endian +/// 32-bit integer followed by the ARROW1 magic. ArrowIpcDecoderPeekFooter() reads +/// these bytes and returns ESPIPE if there are not enough remaining bytes in data +/// to read the entire footer, EINVAL if the last 10 bytes are not valid, +/// or NANOARROW_OK otherwise. +/// +/// The footer size will be stored in decoder.header_size_bytes. +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderPeekFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error); + +/// \brief Verify a footer +/// +/// Runs ArrowIpcDecoderPeekFooter() to ensure data is sufficiently large but additionally +/// runs flatbuffer verification to ensure that decoding the data will not access +/// memory outside of the buffer specified by data. ArrowIpcDecoderVerifyFooter() will +/// also set decoder.header_size_bytes and decoder.metadata_version. +/// +/// Returns as ArrowIpcDecoderPeekFooter() and additionally will +/// return EINVAL if flatbuffer verification fails. +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderVerifyFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error); + +/// \brief Decode a footer +/// +/// Runs ArrowIpcDecoderPeekFooter() to ensure data is sufficiently large and decodes +/// the content of the footer. decoder.footer will be set for access to the file's +/// schema and record batches. In almost all cases this should be preceded by a call to +/// ArrowIpcDecoderVerifyFooter() to ensure decoding does not access data outside of the +/// specified buffer. +/// +/// Returns EINVAL if the content of the footer cannot be decoded or ENOTSUP if the +/// content of the footer uses features not supported by this library. +/// +/// \warning This API is currently only public for use in integration testing; +/// use at your own risk. +NANOARROW_DLL ArrowErrorCode ArrowIpcDecoderDecodeFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/third_party/nanoarrow/src/flatcc.c b/third_party/nanoarrow/src/flatcc.c new file mode 100644 index 0000000..a08754a --- /dev/null +++ b/third_party/nanoarrow/src/flatcc.c @@ -0,0 +1,3247 @@ +/* + * Codegenerator for C, building FlatBuffers. + * + * There are several approaches, some light, some requiring a library, + * some with vectored I/O etc. + * + * Here we focus on a reasonable balance of light code and efficiency. + * + * Builder code is generated to a separate file that includes the + * generated read-only code. + * + * Mutable buffers are not supported in this version. + * + */ + +#include +#include + +#include "flatcc/flatcc_builder.h" +#include "flatcc/flatcc_emitter.h" + +/* + * `check` is designed to handle incorrect use errors that can be + * ignored in production of a tested product. + * + * `check_error` fails if condition is false and is designed to return an + * error code in production. + */ + +#if FLATCC_BUILDER_ASSERT_ON_ERROR +#define check(cond, reason) FLATCC_BUILDER_ASSERT(cond, reason) +#else +#define check(cond, reason) ((void)0) +#endif + +#if FLATCC_BUILDER_SKIP_CHECKS +#define check_error(cond, err, reason) ((void)0) +#else +#define check_error(cond, err, reason) if (!(cond)) { check(cond, reason); return err; } +#endif + +/* `strnlen` not widely supported. */ +static inline size_t pstrnlen(const char *s, size_t max_len) +{ + const char *end = memchr(s, 0, max_len); + return end ? (size_t)(end - s) : max_len; +} +#undef strnlen +#define strnlen pstrnlen + +/* Padding can be up to 255 zeroes, and 1 zero string termination byte. + * When two paddings are combined at nested buffers, we need twice that. + * Visible to emitter so it can test for zero padding in iov. */ +const uint8_t flatcc_builder_padding_base[512] = { 0 }; +#define _pad flatcc_builder_padding_base + +#define uoffset_t flatbuffers_uoffset_t +#define soffset_t flatbuffers_soffset_t +#define voffset_t flatbuffers_voffset_t +#define utype_t flatbuffers_utype_t + +#define write_uoffset __flatbuffers_uoffset_write_to_pe +#define write_voffset __flatbuffers_voffset_write_to_pe +#define write_identifier __flatbuffers_uoffset_write_to_pe +#define write_utype __flatbuffers_utype_write_to_pe + +#define field_size sizeof(uoffset_t) +#define max_offset_count FLATBUFFERS_COUNT_MAX(field_size) +#define union_size sizeof(flatcc_builder_union_ref_t) +#define max_union_count FLATBUFFERS_COUNT_MAX(union_size) +#define utype_size sizeof(utype_t) +#define max_utype_count FLATBUFFERS_COUNT_MAX(utype_size) + +#define max_string_len FLATBUFFERS_COUNT_MAX(1) +#define identifier_size FLATBUFFERS_IDENTIFIER_SIZE + + +#define iovec_t flatcc_iovec_t +#define frame_size sizeof(__flatcc_builder_frame_t) +#define frame(x) (B->frame[0].x) + + +/* `align` must be a power of 2. */ +static inline uoffset_t alignup_uoffset(uoffset_t x, size_t align) +{ + return (x + (uoffset_t)align - 1u) & ~((uoffset_t)align - 1u); +} + +static inline size_t alignup_size(size_t x, size_t align) +{ + return (x + align - 1u) & ~(align - 1u); +} + + +typedef struct vtable_descriptor vtable_descriptor_t; +struct vtable_descriptor { + /* Where the vtable is emitted. */ + flatcc_builder_ref_t vt_ref; + /* Which buffer it was emitted to. */ + uoffset_t nest_id; + /* Where the vtable is cached. */ + uoffset_t vb_start; + /* Hash table collision chain. */ + uoffset_t next; +}; + +typedef struct flatcc_iov_state flatcc_iov_state_t; +struct flatcc_iov_state { + size_t len; + int count; + flatcc_iovec_t iov[FLATCC_IOV_COUNT_MAX]; +}; + +#define iov_state_t flatcc_iov_state_t + +/* This assumes `iov_state_t iov;` has been declared in scope */ +#define push_iov_cond(base, size, cond) if ((size) > 0 && (cond)) { iov.len += size;\ + iov.iov[iov.count].iov_base = (void *)(base); iov.iov[iov.count].iov_len = (size); ++iov.count; } +#define push_iov(base, size) push_iov_cond(base, size, 1) +#define init_iov() { iov.len = 0; iov.count = 0; } + + +int flatcc_builder_default_alloc(void *alloc_context, iovec_t *b, size_t request, int zero_fill, int hint) +{ + void *p; + size_t n; + + (void)alloc_context; + + if (request == 0) { + if (b->iov_base) { + FLATCC_BUILDER_FREE(b->iov_base); + b->iov_base = 0; + b->iov_len = 0; + } + return 0; + } + switch (hint) { + case flatcc_builder_alloc_ds: + n = 256; + break; + case flatcc_builder_alloc_ht: + /* Should be exact size, or space size is just wasted. */ + n = request; + break; + case flatcc_builder_alloc_fs: + n = sizeof(__flatcc_builder_frame_t) * 8; + break; + case flatcc_builder_alloc_us: + n = 64; + break; + default: + /* + * We have many small structures - vs stack for tables with few + * elements, and few offset fields in patch log. No need to + * overallocate in case of busy small messages. + */ + n = 32; + break; + } + while (n < request) { + n *= 2; + } + if (request <= b->iov_len && b->iov_len / 2 >= n) { + /* Add hysteresis to shrink. */ + return 0; + } + if (!(p = FLATCC_BUILDER_REALLOC(b->iov_base, n))) { + return -1; + } + /* Realloc might also shrink. */ + if (zero_fill && b->iov_len < n) { + memset((uint8_t *)p + b->iov_len, 0, n - b->iov_len); + } + b->iov_base = p; + b->iov_len = n; + return 0; +} + +#define T_ptr(base, pos) ((void *)((size_t)(base) + (size_t)(pos))) +#define ds_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_ds].iov_base, (pos))) +#define vs_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_vs].iov_base, (pos))) +#define pl_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_pl].iov_base, (pos))) +#define us_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_us].iov_base, (pos))) +#define vd_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_vd].iov_base, (pos))) +#define vb_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_vb].iov_base, (pos))) +#define vs_offset(ptr) ((uoffset_t)((size_t)(ptr) - (size_t)B->buffers[flatcc_builder_alloc_vs].iov_base)) +#define pl_offset(ptr) ((uoffset_t)((size_t)(ptr) - (size_t)B->buffers[flatcc_builder_alloc_pl].iov_base)) +#define us_offset(ptr) ((uoffset_t)((size_t)(ptr) - (size_t)B->buffers[flatcc_builder_alloc_us].iov_base)) + +#define table_limit (FLATBUFFERS_VOFFSET_MAX - field_size + 1) +#define data_limit (FLATBUFFERS_UOFFSET_MAX - field_size + 1) + +#define set_identifier(id) memcpy(&B->identifier, (id) ? (void *)(id) : (void *)_pad, identifier_size) + +/* Must also return true when no buffer has been started. */ +#define is_top_buffer(B) (B->nest_id == 0) + +/* + * Tables use a stack represention better suited for quickly adding + * fields to tables, but it must occasionally be refreshed following + * reallocation or reentry from child frame. + */ +static inline void refresh_ds(flatcc_builder_t *B, uoffset_t type_limit) +{ + iovec_t *buf = B->buffers + flatcc_builder_alloc_ds; + + B->ds = ds_ptr(B->ds_first); + B->ds_limit = (uoffset_t)buf->iov_len - B->ds_first; + /* + * So we don't allocate outside tables representation size, nor our + * current buffer size. + */ + if (B->ds_limit > type_limit) { + B->ds_limit = type_limit; + } + /* So exit frame can refresh fast. */ + frame(type_limit) = type_limit; +} + +static int reserve_ds(flatcc_builder_t *B, size_t need, uoffset_t limit) +{ + iovec_t *buf = B->buffers + flatcc_builder_alloc_ds; + + if (B->alloc(B->alloc_context, buf, B->ds_first + need, 1, flatcc_builder_alloc_ds)) { + return -1; + } + refresh_ds(B, limit); + return 0; +} + +/* + * Make sure there is always an extra zero termination on stack + * even if it isn't emitted such that string updates may count + * on zero termination being present always. + */ +static inline void *push_ds(flatcc_builder_t *B, uoffset_t size) +{ + size_t offset; + + offset = B->ds_offset; + if ((B->ds_offset += size) >= B->ds_limit) { + if (reserve_ds(B, B->ds_offset + 1, data_limit)) { + return 0; + } + } + return B->ds + offset; +} + +static inline void unpush_ds(flatcc_builder_t *B, uoffset_t size) +{ + B->ds_offset -= size; + memset(B->ds + B->ds_offset, 0, size); +} + +static inline void *push_ds_copy(flatcc_builder_t *B, const void *data, uoffset_t size) +{ + void *p; + + if (!(p = push_ds(B, size))) { + return 0; + } + memcpy(p, data, size); + return p; +} + +static inline void *push_ds_field(flatcc_builder_t *B, uoffset_t size, uint16_t align, voffset_t id) +{ + uoffset_t offset; + + /* + * We calculate table field alignment relative to first entry, not + * header field with vtable offset. + * + * Note: >= comparison handles special case where B->ds is not + * allocated yet and size is 0 so the return value would be mistaken + * for an error. + */ + offset = alignup_uoffset(B->ds_offset, align); + if ((B->ds_offset = offset + size) >= B->ds_limit) { + if (reserve_ds(B, B->ds_offset + 1, table_limit)) { + return 0; + } + } + B->vs[id] = (voffset_t)(offset + field_size); + if (id >= B->id_end) { + B->id_end = id + 1u; + } + return B->ds + offset; +} + +static inline void *push_ds_offset_field(flatcc_builder_t *B, voffset_t id) +{ + uoffset_t offset; + + offset = alignup_uoffset(B->ds_offset, field_size); + if ((B->ds_offset = offset + field_size) > B->ds_limit) { + if (reserve_ds(B, B->ds_offset, table_limit)) { + return 0; + } + } + B->vs[id] = (voffset_t)(offset + field_size); + if (id >= B->id_end) { + B->id_end = id + 1u; + } + *B->pl++ = (flatbuffers_voffset_t)offset; + return B->ds + offset; +} + +static inline void *reserve_buffer(flatcc_builder_t *B, int alloc_type, size_t used, size_t need, int zero_init) +{ + iovec_t *buf = B->buffers + alloc_type; + + if (used + need > buf->iov_len) { + if (B->alloc(B->alloc_context, buf, used + need, zero_init, alloc_type)) { + check(0, "memory allocation failed"); + return 0; + } + } + return (void *)((size_t)buf->iov_base + used); +} + +static inline int reserve_fields(flatcc_builder_t *B, int count) +{ + size_t used, need; + + /* Provide faster stack operations for common table operations. */ + used = frame(container.table.vs_end) + frame(container.table.id_end) * sizeof(voffset_t); + need = (size_t)(count + 2) * sizeof(voffset_t); + if (!(B->vs = reserve_buffer(B, flatcc_builder_alloc_vs, used, need, 1))) { + return -1; + } + /* Move past header for convenience. */ + B->vs += 2; + used = frame(container.table.pl_end); + /* Add one to handle special case of first table being empty. */ + need = (size_t)count * sizeof(*(B->pl)) + 1; + if (!(B->pl = reserve_buffer(B, flatcc_builder_alloc_pl, used, need, 0))) { + return -1; + } + return 0; +} + +static int alloc_ht(flatcc_builder_t *B) +{ + iovec_t *buf = B->buffers + flatcc_builder_alloc_ht; + + size_t size, k; + /* Allocate null entry so we can check for return errors. */ + FLATCC_ASSERT(B->vd_end == 0); + if (!reserve_buffer(B, flatcc_builder_alloc_vd, B->vd_end, sizeof(vtable_descriptor_t), 0)) { + return -1; + } + B->vd_end = sizeof(vtable_descriptor_t); + size = field_size * FLATCC_BUILDER_MIN_HASH_COUNT; + if (B->alloc(B->alloc_context, buf, size, 1, flatcc_builder_alloc_ht)) { + return -1; + } + while (size * 2 <= buf->iov_len) { + size *= 2; + } + size /= field_size; + for (k = 0; (((size_t)1) << k) < size; ++k) { + } + B->ht_width = k; + return 0; +} + +static inline uoffset_t *lookup_ht(flatcc_builder_t *B, uint32_t hash) +{ + uoffset_t *T; + + if (B->ht_width == 0) { + if (alloc_ht(B)) { + return 0; + } + } + T = B->buffers[flatcc_builder_alloc_ht].iov_base; + + return &T[FLATCC_BUILDER_BUCKET_VT_HASH(hash, B->ht_width)]; +} + +void flatcc_builder_flush_vtable_cache(flatcc_builder_t *B) +{ + iovec_t *buf = B->buffers + flatcc_builder_alloc_ht; + + if (B->ht_width == 0) { + return; + } + memset(buf->iov_base, 0, buf->iov_len); + /* Reserve the null entry. */ + B->vd_end = sizeof(vtable_descriptor_t); + B->vb_end = 0; +} + +int flatcc_builder_custom_init(flatcc_builder_t *B, + flatcc_builder_emit_fun *emit, void *emit_context, + flatcc_builder_alloc_fun *alloc, void *alloc_context) +{ + /* + * Do not allocate anything here. Only the required buffers will be + * allocated. For simple struct buffers, no allocation is required + * at all. + */ + memset(B, 0, sizeof(*B)); + + if (emit == 0) { + B->is_default_emitter = 1; + emit = flatcc_emitter; + emit_context = &B->default_emit_context; + } + if (alloc == 0) { + alloc = flatcc_builder_default_alloc; + } + B->alloc_context = alloc_context; + B->alloc = alloc; + B->emit_context = emit_context; + B->emit = emit; + return 0; +} + +int flatcc_builder_init(flatcc_builder_t *B) +{ + return flatcc_builder_custom_init(B, 0, 0, 0, 0); +} + +int flatcc_builder_custom_reset(flatcc_builder_t *B, int set_defaults, int reduce_buffers) +{ + iovec_t *buf; + int i; + + for (i = 0; i < FLATCC_BUILDER_ALLOC_BUFFER_COUNT; ++i) { + buf = B->buffers + i; + if (buf->iov_base) { + /* Don't try to reduce the hash table. */ + if (i != flatcc_builder_alloc_ht && + reduce_buffers && B->alloc(B->alloc_context, buf, 1, 1, i)) { + return -1; + } + memset(buf->iov_base, 0, buf->iov_len); + } else { + FLATCC_ASSERT(buf->iov_len == 0); + } + } + B->vb_end = 0; + if (B->vd_end > 0) { + /* Reset past null entry. */ + B->vd_end = sizeof(vtable_descriptor_t); + } + B->min_align = 0; + B->emit_start = 0; + B->emit_end = 0; + B->level = 0; + B->limit_level = 0; + B->ds_offset = 0; + B->ds_limit = 0; + B->nest_count = 0; + B->nest_id = 0; + /* Needed for correct offset calculation. */ + B->ds = B->buffers[flatcc_builder_alloc_ds].iov_base; + B->pl = B->buffers[flatcc_builder_alloc_pl].iov_base; + B->vs = B->buffers[flatcc_builder_alloc_vs].iov_base; + B->frame = 0; + if (set_defaults) { + B->vb_flush_limit = 0; + B->max_level = 0; + B->disable_vt_clustering = 0; + } + if (B->is_default_emitter) { + flatcc_emitter_reset(&B->default_emit_context); + } + if (B->refmap) { + flatcc_refmap_reset(B->refmap); + } + return 0; +} + +int flatcc_builder_reset(flatcc_builder_t *B) +{ + return flatcc_builder_custom_reset(B, 0, 0); +} + +void flatcc_builder_clear(flatcc_builder_t *B) +{ + iovec_t *buf; + int i; + + for (i = 0; i < FLATCC_BUILDER_ALLOC_BUFFER_COUNT; ++i) { + buf = B->buffers + i; + B->alloc(B->alloc_context, buf, 0, 0, i); + } + if (B->is_default_emitter) { + flatcc_emitter_clear(&B->default_emit_context); + } + if (B->refmap) { + flatcc_refmap_clear(B->refmap); + } + memset(B, 0, sizeof(*B)); +} + +static inline void set_min_align(flatcc_builder_t *B, uint16_t align) +{ + if (B->min_align < align) { + B->min_align = align; + } +} + +/* + * It's a max, but the minimum viable alignment is the largest observed + * alignment requirement, but no larger. + */ +static inline void get_min_align(uint16_t *align, uint16_t b) +{ + if (*align < b) { + *align = b; + } +} + +void *flatcc_builder_enter_user_frame_ptr(flatcc_builder_t *B, size_t size) +{ + size_t *frame; + + size = alignup_size(size, sizeof(size_t)) + sizeof(size_t); + + if (!(frame = reserve_buffer(B, flatcc_builder_alloc_us, B->user_frame_end, size, 0))) { + return 0; + } + memset(frame, 0, size); + *frame++ = B->user_frame_offset; + B->user_frame_offset = B->user_frame_end + sizeof(size_t); + B->user_frame_end += size; + return frame; +} + +size_t flatcc_builder_enter_user_frame(flatcc_builder_t *B, size_t size) +{ + size_t *frame; + + size = alignup_size(size, sizeof(size_t)) + sizeof(size_t); + + if (!(frame = reserve_buffer(B, flatcc_builder_alloc_us, B->user_frame_end, size, 0))) { + return 0; + } + memset(frame, 0, size); + *frame++ = B->user_frame_offset; + B->user_frame_offset = B->user_frame_end + sizeof(size_t); + B->user_frame_end += size; + return B->user_frame_offset; +} + + +size_t flatcc_builder_exit_user_frame(flatcc_builder_t *B) +{ + size_t *hdr; + + FLATCC_ASSERT(B->user_frame_offset > 0); + + hdr = us_ptr(B->user_frame_offset); + B->user_frame_end = B->user_frame_offset - sizeof(size_t); + return B->user_frame_offset = hdr[-1]; +} + +size_t flatcc_builder_exit_user_frame_at(flatcc_builder_t *B, size_t handle) +{ + FLATCC_ASSERT(B->user_frame_offset >= handle); + + B->user_frame_offset = handle; + return flatcc_builder_exit_user_frame(B); +} + +size_t flatcc_builder_get_current_user_frame(flatcc_builder_t *B) +{ + return B->user_frame_offset; +} + +void *flatcc_builder_get_user_frame_ptr(flatcc_builder_t *B, size_t handle) +{ + return us_ptr(handle); +} + +static int enter_frame(flatcc_builder_t *B, uint16_t align) +{ + if (++B->level > B->limit_level) { + if (B->max_level > 0 && B->level > B->max_level) { + return -1; + } + if (!(B->frame = reserve_buffer(B, flatcc_builder_alloc_fs, + (size_t)(B->level - 1) * frame_size, frame_size, 0))) { + return -1; + } + B->limit_level = (int)(B->buffers[flatcc_builder_alloc_fs].iov_len / frame_size); + if (B->max_level > 0 && B->max_level < B->limit_level) { + B->limit_level = B->max_level; + } + } else { + ++B->frame; + } + frame(ds_offset) = B->ds_offset; + frame(align) = B->align; + B->align = align; + /* Note: do not assume padding before first has been allocated! */ + frame(ds_first) = B->ds_first; + frame(type_limit) = data_limit; + B->ds_first = alignup_uoffset(B->ds_first + B->ds_offset, 8); + B->ds_offset = 0; + return 0; +} + +static inline void exit_frame(flatcc_builder_t *B) +{ + memset(B->ds, 0, B->ds_offset); + B->ds_offset = frame(ds_offset); + B->ds_first = frame(ds_first); + refresh_ds(B, frame(type_limit)); + + /* + * Restore local alignment: e.g. a table should not change alignment + * because a child table was just created elsewhere in the buffer, + * but the overall alignment (min align), should be aware of it. + * Each buffer has its own min align that then migrates up without + * being affected by sibling or child buffers. + */ + set_min_align(B, B->align); + B->align = frame(align); + + --B->frame; + --B->level; +} + +static inline uoffset_t front_pad(flatcc_builder_t *B, uoffset_t size, uint16_t align) +{ + return (uoffset_t)(B->emit_start - (flatcc_builder_ref_t)size) & (align - 1u); +} + +static inline uoffset_t back_pad(flatcc_builder_t *B, uint16_t align) +{ + return (uoffset_t)(B->emit_end) & (align - 1u); +} + +static inline flatcc_builder_ref_t emit_front(flatcc_builder_t *B, iov_state_t *iov) +{ + flatcc_builder_ref_t ref; + + /* + * We might have overflow when including headers, but without + * headers we should have checks to prevent overflow in the + * uoffset_t range, hence we subtract 16 to be safe. With that + * guarantee we can also make a safe check on the soffset_t range. + * + * We only allow buffers half the theoritical size of + * FLATBUFFERS_UOFFSET_MAX so we can safely use signed references. + * + * NOTE: vtables vt_offset field is signed, and the check in create + * table only ensures the signed limit. The check would fail if the + * total buffer size could grow beyond UOFFSET_MAX, and we prevent + * that by limiting the lower end to SOFFSET_MIN, and the upper end + * at emit_back to SOFFSET_MAX. + */ + ref = B->emit_start - (flatcc_builder_ref_t)iov->len; + if ((iov->len > 16 && iov->len - 16 > FLATBUFFERS_UOFFSET_MAX) || ref >= B->emit_start) { + check(0, "buffer too large to represent"); + return 0; + } + if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) { + check(0, "emitter rejected buffer content"); + return 0; + } + return B->emit_start = ref; +} + +static inline flatcc_builder_ref_t emit_back(flatcc_builder_t *B, iov_state_t *iov) +{ + flatcc_builder_ref_t ref; + + ref = B->emit_end; + B->emit_end = ref + (flatcc_builder_ref_t)iov->len; + /* + * Similar to emit_front check, but since we only emit vtables and + * padding at the back, we are not concerned with iov->len overflow, + * only total buffer overflow. + * + * With this check, vtable soffset references at table header can + * still overflow in extreme cases, so this must be checked + * separately. + */ + if (B->emit_end < ref) { + check(0, "buffer too large to represent"); + return 0; + } + if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) { + check(0, "emitter rejected buffer content"); + return 0; + } + /* + * Back references always return ref + 1 because ref == 0 is valid and + * should not be mistaken for error. vtables understand this. + */ + return ref + 1; +} + +/* If nested we cannot pad the end of the buffer without moving the entire buffer, so we don't. */ +static int align_buffer_end(flatcc_builder_t *B, uint16_t *align, uint16_t block_align, int is_nested) +{ + size_t end_pad; + iov_state_t iov; + + block_align = block_align ? block_align : B->block_align ? B->block_align : 1; + get_min_align(align, field_size); + get_min_align(align, block_align); + /* Pad end of buffer to multiple. */ + if (!is_nested) { + end_pad = back_pad(B, *align); + if (end_pad) { + init_iov(); + push_iov(_pad, end_pad); + if (0 == emit_back(B, &iov)) { + check(0, "emitter rejected buffer content"); + return -1; + } + } + } + return 0; +} + +flatcc_builder_ref_t flatcc_builder_embed_buffer(flatcc_builder_t *B, + uint16_t block_align, + const void *data, size_t size, uint16_t align, flatcc_builder_buffer_flags_t flags) +{ + uoffset_t size_field, pad; + iov_state_t iov; + int with_size = (flags & flatcc_builder_with_size) != 0; + + if (align_buffer_end(B, &align, block_align, !is_top_buffer(B))) { + return 0; + } + pad = front_pad(B, (uoffset_t)(size + (with_size ? field_size : 0)), align); + write_uoffset(&size_field, (uoffset_t)size + pad); + init_iov(); + /* Add ubyte vector size header if nested buffer. */ + push_iov_cond(&size_field, field_size, !is_top_buffer(B)); + push_iov(data, size); + push_iov(_pad, pad); + return emit_front(B, &iov); +} + +flatcc_builder_ref_t flatcc_builder_create_buffer(flatcc_builder_t *B, + const char identifier[identifier_size], uint16_t block_align, + flatcc_builder_ref_t object_ref, uint16_t align, flatcc_builder_buffer_flags_t flags) +{ + flatcc_builder_ref_t buffer_ref; + uoffset_t header_pad, id_size = 0; + uoffset_t object_offset, buffer_size, buffer_base; + iov_state_t iov; + flatcc_builder_identifier_t id_out = 0; + int is_nested = (flags & flatcc_builder_is_nested) != 0; + int with_size = (flags & flatcc_builder_with_size) != 0; + + if (align_buffer_end(B, &align, block_align, is_nested)) { + return 0; + } + set_min_align(B, align); + if (identifier) { + FLATCC_ASSERT(sizeof(flatcc_builder_identifier_t) == identifier_size); + FLATCC_ASSERT(sizeof(flatcc_builder_identifier_t) == field_size); + memcpy(&id_out, identifier, identifier_size); + id_out = __flatbuffers_thash_read_from_le(&id_out); + write_identifier(&id_out, id_out); + } + id_size = id_out ? identifier_size : 0; + header_pad = front_pad(B, field_size + id_size + (uoffset_t)(with_size ? field_size : 0), align); + init_iov(); + /* ubyte vectors size field wrapping nested buffer. */ + push_iov_cond(&buffer_size, field_size, is_nested || with_size); + push_iov(&object_offset, field_size); + /* Identifiers are not always present in buffer. */ + push_iov(&id_out, id_size); + push_iov(_pad, header_pad); + buffer_base = (uoffset_t)B->emit_start - (uoffset_t)iov.len + (uoffset_t)((is_nested || with_size) ? field_size : 0); + if (is_nested) { + write_uoffset(&buffer_size, (uoffset_t)B->buffer_mark - buffer_base); + } else { + /* Also include clustered vtables. */ + write_uoffset(&buffer_size, (uoffset_t)B->emit_end - buffer_base); + } + write_uoffset(&object_offset, (uoffset_t)object_ref - buffer_base); + if (0 == (buffer_ref = emit_front(B, &iov))) { + check(0, "emitter rejected buffer content"); + return 0; + } + return buffer_ref; +} + +flatcc_builder_ref_t flatcc_builder_create_struct(flatcc_builder_t *B, const void *data, size_t size, uint16_t align) +{ + size_t pad; + iov_state_t iov; + + check(align >= 1, "align cannot be 0"); + set_min_align(B, align); + pad = front_pad(B, (uoffset_t)size, align); + init_iov(); + push_iov(data, size); + /* + * Normally structs will already be a multiple of their alignment, + * so this padding will not likely be emitted. + */ + push_iov(_pad, pad); + return emit_front(B, &iov); +} + +int flatcc_builder_start_buffer(flatcc_builder_t *B, + const char identifier[identifier_size], uint16_t block_align, flatcc_builder_buffer_flags_t flags) +{ + /* + * This saves the parent `min_align` in the align field since we + * shouldn't use that for the current buffer. `exit_frame` + * automatically aggregates align up, so it is updated when the + * buffer frame exits. + */ + if (enter_frame(B, B->min_align)) { + return -1; + } + /* B->align now has parent min_align, and child frames will save it. */ + /* Since we allow objects to be created before the buffer at top level, + we need to respect min_align in that case. */ + if (!is_top_buffer(B) || B->min_align == 0) { + B->min_align = 1; + } + /* Save the parent block align, and set proper defaults for this buffer. */ + frame(container.buffer.block_align) = B->block_align; + B->block_align = block_align; + frame(container.buffer.flags = B->buffer_flags); + B->buffer_flags = (uint16_t)flags; + frame(container.buffer.mark) = B->buffer_mark; + frame(container.buffer.nest_id) = B->nest_id; + /* + * End of buffer when nested. Not defined for top-level because we + * here (on only here) permit strings etc. to be created before buffer start and + * because top-level buffer vtables can be clustered. + */ + B->buffer_mark = B->emit_start; + /* Must be 0 before and after entering top-level buffer, and unique otherwise. */ + B->nest_id = B->nest_count++; + frame(container.buffer.identifier) = B->identifier; + set_identifier(identifier); + frame(type) = flatcc_builder_buffer; + return 0; +} + +flatcc_builder_ref_t flatcc_builder_end_buffer(flatcc_builder_t *B, flatcc_builder_ref_t root) +{ + flatcc_builder_ref_t buffer_ref; + flatcc_builder_buffer_flags_t flags; + + flags = (flatcc_builder_buffer_flags_t)B->buffer_flags & flatcc_builder_with_size; + flags |= is_top_buffer(B) ? 0 : flatcc_builder_is_nested; + check(frame(type) == flatcc_builder_buffer, "expected buffer frame"); + set_min_align(B, B->block_align); + if (0 == (buffer_ref = flatcc_builder_create_buffer(B, (void *)&B->identifier, + B->block_align, root, B->min_align, flags))) { + return 0; + } + B->buffer_mark = frame(container.buffer.mark); + B->nest_id = frame(container.buffer.nest_id); + B->identifier = frame(container.buffer.identifier); + B->buffer_flags = frame(container.buffer.flags); + B->block_align = frame(container.buffer.block_align); + + exit_frame(B); + return buffer_ref; +} + +void *flatcc_builder_start_struct(flatcc_builder_t *B, size_t size, uint16_t align) +{ + /* Allocate space for the struct on the ds stack. */ + if (enter_frame(B, align)) { + return 0; + } + frame(type) = flatcc_builder_struct; + refresh_ds(B, data_limit); + return push_ds(B, (uoffset_t)size); +} + +void *flatcc_builder_struct_edit(flatcc_builder_t *B) +{ + return B->ds; +} + +flatcc_builder_ref_t flatcc_builder_end_struct(flatcc_builder_t *B) +{ + flatcc_builder_ref_t object_ref; + + check(frame(type) == flatcc_builder_struct, "expected struct frame"); + if (0 == (object_ref = flatcc_builder_create_struct(B, B->ds, B->ds_offset, B->align))) { + return 0; + } + exit_frame(B); + return object_ref; +} + +static inline int vector_count_add(flatcc_builder_t *B, uoffset_t count, uoffset_t max_count) +{ + uoffset_t n, n1; + n = frame(container.vector.count); + n1 = n + count; + /* + * This prevents elem_size * count from overflowing iff max_vector + * has been set sensible. Without this check we might allocate to + * little on the ds stack and return a buffer the user thinks is + * much larger which of course is bad even though the buffer eventually + * would fail anyway. + */ + check_error(n <= n1 && n1 <= max_count, -1, "vector too large to represent"); + frame(container.vector.count) = n1; + return 0; +} + +void *flatcc_builder_extend_vector(flatcc_builder_t *B, size_t count) +{ + if (vector_count_add(B, (uoffset_t)count, frame(container.vector.max_count))) { + return 0; + } + return push_ds(B, frame(container.vector.elem_size) * (uoffset_t)count); +} + +void *flatcc_builder_vector_push(flatcc_builder_t *B, const void *data) +{ + check(frame(type) == flatcc_builder_vector, "expected vector frame"); + check_error(frame(container.vector.count) <= frame(container.vector.max_count), 0, "vector max count exceeded"); + frame(container.vector.count) += 1; + return push_ds_copy(B, data, frame(container.vector.elem_size)); +} + +void *flatcc_builder_append_vector(flatcc_builder_t *B, const void *data, size_t count) +{ + check(frame(type) == flatcc_builder_vector, "expected vector frame"); + if (vector_count_add(B, (uoffset_t)count, frame(container.vector.max_count))) { + return 0; + } + return push_ds_copy(B, data, frame(container.vector.elem_size) * (uoffset_t)count); +} + +flatcc_builder_ref_t *flatcc_builder_extend_offset_vector(flatcc_builder_t *B, size_t count) +{ + if (vector_count_add(B, (uoffset_t)count, max_offset_count)) { + return 0; + } + return push_ds(B, (uoffset_t)(field_size * count)); +} + +flatcc_builder_ref_t *flatcc_builder_offset_vector_push(flatcc_builder_t *B, flatcc_builder_ref_t ref) +{ + flatcc_builder_ref_t *p; + + check(frame(type) == flatcc_builder_offset_vector, "expected offset vector frame"); + if (frame(container.vector.count) == max_offset_count) { + return 0; + } + frame(container.vector.count) += 1; + if (0 == (p = push_ds(B, field_size))) { + return 0; + } + *p = ref; + return p; +} + +flatcc_builder_ref_t *flatcc_builder_append_offset_vector(flatcc_builder_t *B, const flatcc_builder_ref_t *refs, size_t count) +{ + check(frame(type) == flatcc_builder_offset_vector, "expected offset vector frame"); + if (vector_count_add(B, (uoffset_t)count, max_offset_count)) { + return 0; + } + return push_ds_copy(B, refs, (uoffset_t)(field_size * count)); +} + +char *flatcc_builder_extend_string(flatcc_builder_t *B, size_t len) +{ + check(frame(type) == flatcc_builder_string, "expected string frame"); + if (vector_count_add(B, (uoffset_t)len, max_string_len)) { + return 0; + } + return push_ds(B, (uoffset_t)len); +} + +char *flatcc_builder_append_string(flatcc_builder_t *B, const char *s, size_t len) +{ + check(frame(type) == flatcc_builder_string, "expected string frame"); + if (vector_count_add(B, (uoffset_t)len, max_string_len)) { + return 0; + } + return push_ds_copy(B, s, (uoffset_t)len); +} + +char *flatcc_builder_append_string_str(flatcc_builder_t *B, const char *s) +{ + return flatcc_builder_append_string(B, s, strlen(s)); +} + +char *flatcc_builder_append_string_strn(flatcc_builder_t *B, const char *s, size_t max_len) +{ + return flatcc_builder_append_string(B, s, strnlen(s, max_len)); +} + +int flatcc_builder_truncate_vector(flatcc_builder_t *B, size_t count) +{ + check(frame(type) == flatcc_builder_vector, "expected vector frame"); + check_error(frame(container.vector.count) >= count, -1, "cannot truncate vector past empty"); + frame(container.vector.count) -= (uoffset_t)count; + unpush_ds(B, frame(container.vector.elem_size) * (uoffset_t)count); + return 0; +} + +int flatcc_builder_truncate_offset_vector(flatcc_builder_t *B, size_t count) +{ + check(frame(type) == flatcc_builder_offset_vector, "expected offset vector frame"); + check_error(frame(container.vector.count) >= (uoffset_t)count, -1, "cannot truncate vector past empty"); + frame(container.vector.count) -= (uoffset_t)count; + unpush_ds(B, frame(container.vector.elem_size) * (uoffset_t)count); + return 0; +} + +int flatcc_builder_truncate_string(flatcc_builder_t *B, size_t len) +{ + check(frame(type) == flatcc_builder_string, "expected string frame"); + check_error(frame(container.vector.count) >= len, -1, "cannot truncate string past empty"); + frame(container.vector.count) -= (uoffset_t)len; + unpush_ds(B, (uoffset_t)len); + return 0; +} + +int flatcc_builder_start_vector(flatcc_builder_t *B, size_t elem_size, uint16_t align, size_t max_count) +{ + get_min_align(&align, field_size); + if (enter_frame(B, align)) { + return -1; + } + frame(container.vector.elem_size) = (uoffset_t)elem_size; + frame(container.vector.count) = 0; + frame(container.vector.max_count) = (uoffset_t)max_count; + frame(type) = flatcc_builder_vector; + refresh_ds(B, data_limit); + return 0; +} + +int flatcc_builder_start_offset_vector(flatcc_builder_t *B) +{ + if (enter_frame(B, field_size)) { + return -1; + } + frame(container.vector.elem_size) = field_size; + frame(container.vector.count) = 0; + frame(type) = flatcc_builder_offset_vector; + refresh_ds(B, data_limit); + return 0; +} + +flatcc_builder_ref_t flatcc_builder_create_offset_vector(flatcc_builder_t *B, + const flatcc_builder_ref_t *vec, size_t count) +{ + flatcc_builder_ref_t *_vec; + + if (flatcc_builder_start_offset_vector(B)) { + return 0; + } + if (!(_vec = flatcc_builder_extend_offset_vector(B, count))) { + return 0; + } + memcpy(_vec, vec, count * field_size); + return flatcc_builder_end_offset_vector(B); +} + +int flatcc_builder_start_string(flatcc_builder_t *B) +{ + if (enter_frame(B, 1)) { + return -1; + } + frame(container.vector.elem_size) = 1; + frame(container.vector.count) = 0; + frame(type) = flatcc_builder_string; + refresh_ds(B, data_limit); + return 0; +} + +int flatcc_builder_reserve_table(flatcc_builder_t *B, int count) +{ + check(count >= 0, "cannot reserve negative count"); + return reserve_fields(B, count); +} + +int flatcc_builder_start_table(flatcc_builder_t *B, int count) +{ + if (enter_frame(B, field_size)) { + return -1; + } + frame(container.table.vs_end) = vs_offset(B->vs); + frame(container.table.pl_end) = pl_offset(B->pl); + frame(container.table.vt_hash) = B->vt_hash; + frame(container.table.id_end) = B->id_end; + B->vt_hash = 0; + FLATCC_BUILDER_INIT_VT_HASH(B->vt_hash); + B->id_end = 0; + frame(type) = flatcc_builder_table; + if (reserve_fields(B, count)) { + return -1; + } + refresh_ds(B, table_limit); + return 0; +} + +flatcc_builder_vt_ref_t flatcc_builder_create_vtable(flatcc_builder_t *B, + const voffset_t *vt, voffset_t vt_size) +{ + flatcc_builder_vt_ref_t vt_ref; + iov_state_t iov; + voffset_t *vt_; + size_t i; + + /* + * Only top-level buffer can cluster vtables because only it can + * extend beyond the end. + * + * We write the vtable after the referencing table to maintain + * the construction invariant that any offset reference has + * valid emitted data at a higher address, and also that any + * issued negative emit address represents an offset reference + * to some flatbuffer object or vector (or possibly a root + * struct). + * + * The vt_ref is stored as the reference + 1 to avoid having 0 as a + * valid reference (which usally means error). It also idententifies + * vtable references as the only uneven references, and the only + * references that can be used multiple times in the same buffer. + * + * We do the vtable conversion here so cached vtables can be built + * hashed and compared more efficiently, and so end users with + * direct vtable construction don't have to worry about endianness. + * This also ensures the hash function works the same wrt. + * collision frequency. + */ + + if (!flatbuffers_is_native_pe()) { + /* Make space in vtable cache for temporary endian conversion. */ + if (!(vt_ = reserve_buffer(B, flatcc_builder_alloc_vb, B->vb_end, vt_size, 0))) { + return 0; + } + for (i = 0; i < vt_size / sizeof(voffset_t); ++i) { + write_voffset(&vt_[i], vt[i]); + } + vt = vt_; + /* We don't need to free the reservation since we don't advance any base pointer. */ + } + + init_iov(); + push_iov(vt, vt_size); + if (is_top_buffer(B) && !B->disable_vt_clustering) { + /* Note that `emit_back` already returns ref + 1 as we require for vtables. */ + if (0 == (vt_ref = emit_back(B, &iov))) { + return 0; + } + } else { + if (0 == (vt_ref = emit_front(B, &iov))) { + return 0; + } + /* + * We don't have a valid 0 ref here, but to be consistent with + * clustered vtables we offset by one. This cannot be zero + * either. + */ + vt_ref += 1; + } + return vt_ref; +} + +flatcc_builder_vt_ref_t flatcc_builder_create_cached_vtable(flatcc_builder_t *B, + const voffset_t *vt, voffset_t vt_size, uint32_t vt_hash) +{ + vtable_descriptor_t *vd, *vd2; + uoffset_t *pvd, *pvd_head; + uoffset_t next; + voffset_t *vt_; + + /* This just gets the hash table slot, we still have to inspect it. */ + if (!(pvd_head = lookup_ht(B, vt_hash))) { + return 0; + } + pvd = pvd_head; + next = *pvd; + /* Tracks if there already is a cached copy. */ + vd2 = 0; + while (next) { + vd = vd_ptr(next); + vt_ = vb_ptr(vd->vb_start); + if (vt_[0] != vt_size || 0 != memcmp(vt, vt_, vt_size)) { + pvd = &vd->next; + next = vd->next; + continue; + } + /* Can't share emitted vtables between buffers, */ + if (vd->nest_id != B->nest_id) { + /* but we don't have to resubmit to cache. */ + vd2 = vd; + /* See if there is a better match. */ + pvd = &vd->next; + next = vd->next; + continue; + } + /* Move to front hash strategy. */ + if (pvd != pvd_head) { + *pvd = vd->next; + vd->next = *pvd_head; + *pvd_head = next; + } + /* vtable exists and has been emitted within current buffer. */ + return vd->vt_ref; + } + /* Allocate new descriptor. */ + if (!(vd = reserve_buffer(B, flatcc_builder_alloc_vd, B->vd_end, sizeof(vtable_descriptor_t), 0))) { + return 0; + } + next = B->vd_end; + B->vd_end += (uoffset_t)sizeof(vtable_descriptor_t); + + /* Identify the buffer this vtable descriptor belongs to. */ + vd->nest_id = B->nest_id; + + /* Move to front hash strategy. */ + vd->next = *pvd_head; + *pvd_head = next; + if (0 == (vd->vt_ref = flatcc_builder_create_vtable(B, vt, vt_size))) { + return 0; + } + if (vd2) { + /* Reuse cached copy. */ + vd->vb_start = vd2->vb_start; + } else { + if (B->vb_flush_limit && B->vb_flush_limit < B->vb_end + vt_size) { + flatcc_builder_flush_vtable_cache(B); + } else { + /* Make space in vtable cache. */ + if (!(vt_ = reserve_buffer(B, flatcc_builder_alloc_vb, B->vb_end, vt_size, 0))) { + return -1; + } + vd->vb_start = B->vb_end; + B->vb_end += vt_size; + memcpy(vt_, vt, vt_size); + } + } + return vd->vt_ref; +} + +flatcc_builder_ref_t flatcc_builder_create_table(flatcc_builder_t *B, const void *data, size_t size, uint16_t align, + flatbuffers_voffset_t *offsets, int offset_count, flatcc_builder_vt_ref_t vt_ref) +{ + int i; + uoffset_t pad, vt_offset, vt_offset_field, vt_base, base, offset, *offset_field; + iov_state_t iov; + + check(offset_count >= 0, "expected non-negative offset_count"); + /* + * vtable references are offset by 1 to avoid confusion with + * 0 as an error reference. It also uniquely identifies them + * as vtables being the only uneven reference type. + */ + check(vt_ref & 1, "invalid vtable referenc"); + get_min_align(&align, field_size); + set_min_align(B, align); + /* Alignment is calculated for the first element, not the header. */ + pad = front_pad(B, (uoffset_t)size, align); + base = (uoffset_t)B->emit_start - (uoffset_t)(pad + size + field_size); + /* Adjust by 1 to get unencoded vtable reference. */ + vt_base = (uoffset_t)(vt_ref - 1); + vt_offset = base - vt_base; + /* Avoid overflow. */ + if (base - vt_offset != vt_base) { + return -1; + } + /* Protocol endian encoding. */ + write_uoffset(&vt_offset_field, vt_offset); + for (i = 0; i < offset_count; ++i) { + offset_field = (uoffset_t *)((size_t)data + offsets[i]); + offset = *offset_field - base - offsets[i] - (uoffset_t)field_size; + write_uoffset(offset_field, offset); + } + init_iov(); + push_iov(&vt_offset_field, field_size); + push_iov(data, size); + push_iov(_pad, pad); + return emit_front(B, &iov); +} + +int flatcc_builder_check_required_field(flatcc_builder_t *B, flatbuffers_voffset_t id) +{ + check(frame(type) == flatcc_builder_table, "expected table frame"); + + return id < B->id_end && B->vs[id] != 0; +} + +int flatcc_builder_check_union_field(flatcc_builder_t *B, flatbuffers_voffset_t id) +{ + check(frame(type) == flatcc_builder_table, "expected table frame"); + + if (id == 0 || id >= B->id_end) { + return 0; + } + if (B->vs[id - 1] == 0) { + return B->vs[id] == 0; + } + if (*(uint8_t *)(B->ds + B->vs[id - 1])) { + return B->vs[id] != 0; + } + return B->vs[id] == 0; +} + +int flatcc_builder_check_required(flatcc_builder_t *B, const flatbuffers_voffset_t *required, int count) +{ + int i; + + check(frame(type) == flatcc_builder_table, "expected table frame"); + + if (B->id_end < count) { + return 0; + } + for (i = 0; i < count; ++i) { + if (B->vs[required[i]] == 0) { + return 0; + } + } + return 1; +} + +flatcc_builder_ref_t flatcc_builder_end_table(flatcc_builder_t *B) +{ + voffset_t *vt, vt_size; + flatcc_builder_ref_t table_ref, vt_ref; + int pl_count; + voffset_t *pl; + size_t tsize; + + check(frame(type) == flatcc_builder_table, "expected table frame"); + + /* We have `ds_limit`, so we should not have to check for overflow here. */ + + vt = B->vs - 2; + vt_size = (voffset_t)(sizeof(voffset_t) * (B->id_end + 2u)); + /* Update vtable header fields, first vtable size, then object table size. */ + vt[0] = vt_size; + /* + * The `ds` buffer is always at least `field_size` aligned but excludes the + * initial vtable offset field. Therefore `field_size` is added here + * to the total table size in the vtable. + */ + tsize = (size_t)(B->ds_offset + field_size); + /* + * Tables are limited to 64K in standard FlatBuffers format due to the voffset + * 16 bit size, but we must also be able to store the table size, so the + * table payload has to be slightly less than that. + */ + check(tsize <= FLATBUFFERS_VOFFSET_MAX, "table too large"); + vt[1] = (voffset_t)tsize; + FLATCC_BUILDER_UPDATE_VT_HASH(B->vt_hash, (uint32_t)vt[0], (uint32_t)vt[1]); + /* Find already emitted vtable, or emit a new one. */ + if (!(vt_ref = flatcc_builder_create_cached_vtable(B, vt, vt_size, B->vt_hash))) { + return 0; + } + /* Clear vs stack so it is ready for the next vtable (ds stack is cleared by exit frame). */ + memset(vt, 0, vt_size); + + pl = pl_ptr(frame(container.table.pl_end)); + pl_count = (int)(B->pl - pl); + if (0 == (table_ref = flatcc_builder_create_table(B, B->ds, B->ds_offset, B->align, pl, pl_count, vt_ref))) { + return 0; + } + B->vt_hash = frame(container.table.vt_hash); + B->id_end = frame(container.table.id_end); + B->vs = vs_ptr(frame(container.table.vs_end)); + B->pl = pl_ptr(frame(container.table.pl_end)); + exit_frame(B); + return table_ref; +} + +flatcc_builder_ref_t flatcc_builder_create_vector(flatcc_builder_t *B, + const void *data, size_t count, size_t elem_size, uint16_t align, size_t max_count) +{ + /* + * Note: it is important that vec_size is uoffset not size_t + * in case sizeof(uoffset_t) > sizeof(size_t) because max_count is + * defined in terms of uoffset_t representation size, and also + * because we risk accepting too large a vector even if max_count is + * not violated. + */ + uoffset_t vec_size, vec_pad, length_prefix; + iov_state_t iov; + + check_error(count <= max_count, 0, "vector max_count violated"); + get_min_align(&align, field_size); + set_min_align(B, align); + vec_size = (uoffset_t)count * (uoffset_t)elem_size; + /* + * That can happen on 32 bit systems when uoffset_t is defined as 64-bit. + * `emit_front/back` captures overflow, but not if our size type wraps first. + */ +#if FLATBUFFERS_UOFFSET_MAX > SIZE_MAX + check_error(vec_size < SIZE_MAX, 0, "vector larger than address space"); +#endif + write_uoffset(&length_prefix, (uoffset_t)count); + /* Alignment is calculated for the first element, not the header. */ + vec_pad = front_pad(B, vec_size, align); + init_iov(); + push_iov(&length_prefix, field_size); + push_iov(data, vec_size); + push_iov(_pad, vec_pad); + return emit_front(B, &iov); +} + +/* + * Note: FlatBuffers official documentation states that the size field of a + * vector is a 32-bit element count. It is not quite clear if the + * intention is to have the size field be of type uoffset_t since tables + * also have a uoffset_t sized header, or if the vector size should + * remain unchanged if uoffset is changed to 16- or 64-bits + * respectively. Since it makes most sense to have a vector compatible + * with the addressable space, we choose to use uoffset_t as size field, + * which remains compatible with the default 32-bit version of uoffset_t. + */ +flatcc_builder_ref_t flatcc_builder_end_vector(flatcc_builder_t *B) +{ + flatcc_builder_ref_t vector_ref; + + check(frame(type) == flatcc_builder_vector, "expected vector frame"); + + if (0 == (vector_ref = flatcc_builder_create_vector(B, B->ds, + frame(container.vector.count), frame(container.vector.elem_size), + B->align, frame(container.vector.max_count)))) { + return 0; + } + exit_frame(B); + return vector_ref; +} + +size_t flatcc_builder_vector_count(flatcc_builder_t *B) +{ + return frame(container.vector.count); +} + +void *flatcc_builder_vector_edit(flatcc_builder_t *B) +{ + return B->ds; +} + +/* This function destroys the source content but avoids stack allocation. */ +static flatcc_builder_ref_t _create_offset_vector_direct(flatcc_builder_t *B, + flatcc_builder_ref_t *vec, size_t count, const utype_t *types) +{ + uoffset_t vec_size, vec_pad; + uoffset_t length_prefix, offset; + uoffset_t i; + soffset_t base; + iov_state_t iov; + + if ((uoffset_t)count > max_offset_count) { + return 0; + } + set_min_align(B, field_size); + vec_size = (uoffset_t)(count * field_size); + write_uoffset(&length_prefix, (uoffset_t)count); + /* Alignment is calculated for the first element, not the header. */ + vec_pad = front_pad(B, vec_size, field_size); + init_iov(); + push_iov(&length_prefix, field_size); + push_iov(vec, vec_size); + push_iov(_pad, vec_pad); + base = B->emit_start - (soffset_t)iov.len; + for (i = 0; i < (uoffset_t)count; ++i) { + /* + * 0 is either end of buffer, start of vtables, or start of + * buffer depending on the direction in which the buffer is + * built. None of these can create a valid 0 reference but it + * is easy to create by mistake when manually building offset + * vectors. + * + * Unions do permit nulls, but only when the type is NONE. + */ + if (vec[i] != 0) { + offset = (uoffset_t) + (vec[i] - base - (soffset_t)(i * field_size) - (soffset_t)field_size); + write_uoffset(&vec[i], offset); + if (types) { + check(types[i] != 0, "union vector cannot have non-null element with type NONE"); + } + } else { + if (types) { + check(types[i] == 0, "union vector cannot have null element without type NONE"); + } else { + check(0, "offset vector cannot have null element"); + } + } + } + return emit_front(B, &iov); +} + +flatcc_builder_ref_t flatcc_builder_create_offset_vector_direct(flatcc_builder_t *B, + flatcc_builder_ref_t *vec, size_t count) +{ + return _create_offset_vector_direct(B, vec, count, 0); +} + +flatcc_builder_ref_t flatcc_builder_end_offset_vector(flatcc_builder_t *B) +{ + flatcc_builder_ref_t vector_ref; + + check(frame(type) == flatcc_builder_offset_vector, "expected offset vector frame"); + if (0 == (vector_ref = flatcc_builder_create_offset_vector_direct(B, + (flatcc_builder_ref_t *)B->ds, frame(container.vector.count)))) { + return 0; + } + exit_frame(B); + return vector_ref; +} + +flatcc_builder_ref_t flatcc_builder_end_offset_vector_for_unions(flatcc_builder_t *B, const utype_t *types) +{ + flatcc_builder_ref_t vector_ref; + + check(frame(type) == flatcc_builder_offset_vector, "expected offset vector frame"); + if (0 == (vector_ref = _create_offset_vector_direct(B, + (flatcc_builder_ref_t *)B->ds, frame(container.vector.count), types))) { + return 0; + } + exit_frame(B); + return vector_ref; +} + +void *flatcc_builder_offset_vector_edit(flatcc_builder_t *B) +{ + return B->ds; +} + +size_t flatcc_builder_offset_vector_count(flatcc_builder_t *B) +{ + return frame(container.vector.count); +} + +int flatcc_builder_table_add_union(flatcc_builder_t *B, int id, + flatcc_builder_union_ref_t uref) +{ + flatcc_builder_ref_t *pref; + flatcc_builder_utype_t *putype; + + check(frame(type) == flatcc_builder_table, "expected table frame"); + check_error(uref.type != 0 || uref.value == 0, -1, "expected null value for type NONE"); + if (uref.value != 0) { + pref = flatcc_builder_table_add_offset(B, id); + check_error(pref != 0, -1, "unable to add union value"); + *pref = uref.value; + } + putype = flatcc_builder_table_add(B, id - 1, utype_size, utype_size); + check_error(putype != 0, -1, "unable to add union type"); + write_utype(putype, uref.type); + return 0; +} + +int flatcc_builder_table_add_union_vector(flatcc_builder_t *B, int id, + flatcc_builder_union_vec_ref_t uvref) +{ + flatcc_builder_ref_t *pref; + + check(frame(type) == flatcc_builder_table, "expected table frame"); + check_error((uvref.type == 0) == (uvref.value == 0), -1, "expected both type and value vector, or neither"); + if (uvref.type != 0) { + pref = flatcc_builder_table_add_offset(B, id - 1); + check_error(pref != 0, -1, "unable to add union member"); + *pref = uvref.type; + + pref = flatcc_builder_table_add_offset(B, id); + check_error(pref != 0, -1, "unable to add union member"); + *pref = uvref.value; + } + return 0; +} + +flatcc_builder_union_vec_ref_t flatcc_builder_create_union_vector(flatcc_builder_t *B, + const flatcc_builder_union_ref_t *urefs, size_t count) +{ + flatcc_builder_union_vec_ref_t uvref = { 0, 0 }; + flatcc_builder_utype_t *types; + flatcc_builder_ref_t *refs; + size_t i; + + if (flatcc_builder_start_offset_vector(B)) { + return uvref; + } + if (0 == flatcc_builder_extend_offset_vector(B, count)) { + return uvref; + } + if (0 == (types = push_ds(B, (uoffset_t)(utype_size * count)))) { + return uvref; + } + + /* Safe even if push_ds caused stack reallocation. */ + refs = flatcc_builder_offset_vector_edit(B); + + for (i = 0; i < count; ++i) { + types[i] = urefs[i].type; + refs[i] = urefs[i].value; + } + uvref = flatcc_builder_create_union_vector_direct(B, + types, refs, count); + /* No need to clean up after out temporary types vector. */ + exit_frame(B); + return uvref; +} + +flatcc_builder_union_vec_ref_t flatcc_builder_create_union_vector_direct(flatcc_builder_t *B, + const flatcc_builder_utype_t *types, flatcc_builder_ref_t *data, size_t count) +{ + flatcc_builder_union_vec_ref_t uvref = { 0, 0 }; + + if (0 == (uvref.value = _create_offset_vector_direct(B, data, count, types))) { + return uvref; + } + if (0 == (uvref.type = flatcc_builder_create_type_vector(B, types, count))) { + return uvref; + } + return uvref; +} + +flatcc_builder_ref_t flatcc_builder_create_type_vector(flatcc_builder_t *B, + const flatcc_builder_utype_t *types, size_t count) +{ + return flatcc_builder_create_vector(B, types, count, + utype_size, utype_size, max_utype_count); +} + +int flatcc_builder_start_union_vector(flatcc_builder_t *B) +{ + if (enter_frame(B, field_size)) { + return -1; + } + frame(container.vector.elem_size) = union_size; + frame(container.vector.count) = 0; + frame(type) = flatcc_builder_union_vector; + refresh_ds(B, data_limit); + return 0; +} + +flatcc_builder_union_vec_ref_t flatcc_builder_end_union_vector(flatcc_builder_t *B) +{ + flatcc_builder_union_vec_ref_t uvref = { 0, 0 }; + flatcc_builder_utype_t *types; + flatcc_builder_union_ref_t *urefs; + flatcc_builder_ref_t *refs; + size_t i, count; + + check(frame(type) == flatcc_builder_union_vector, "expected union vector frame"); + + /* + * We could split the union vector in-place, but then we would have + * to deal with strict pointer aliasing rules which is not worthwhile + * so we create a new offset and type vector on the stack. + * + * We assume the stack is sufficiently aligned as is. + */ + count = flatcc_builder_union_vector_count(B); + if (0 == (refs = push_ds(B, (uoffset_t)(count * (utype_size + field_size))))) { + return uvref; + } + types = (flatcc_builder_utype_t *)(refs + count); + + /* Safe even if push_ds caused stack reallocation. */ + urefs = flatcc_builder_union_vector_edit(B); + + for (i = 0; i < count; ++i) { + types[i] = urefs[i].type; + refs[i] = urefs[i].value; + } + uvref = flatcc_builder_create_union_vector_direct(B, types, refs, count); + /* No need to clean up after out temporary types vector. */ + exit_frame(B); + return uvref; +} + +void *flatcc_builder_union_vector_edit(flatcc_builder_t *B) +{ + return B->ds; +} + +size_t flatcc_builder_union_vector_count(flatcc_builder_t *B) +{ + return frame(container.vector.count); +} + +flatcc_builder_union_ref_t *flatcc_builder_extend_union_vector(flatcc_builder_t *B, size_t count) +{ + if (vector_count_add(B, (uoffset_t)count, max_union_count)) { + return 0; + } + return push_ds(B, (uoffset_t)(union_size * count)); +} + +int flatcc_builder_truncate_union_vector(flatcc_builder_t *B, size_t count) +{ + check(frame(type) == flatcc_builder_union_vector, "expected union vector frame"); + check_error(frame(container.vector.count) >= (uoffset_t)count, -1, "cannot truncate vector past empty"); + frame(container.vector.count) -= (uoffset_t)count; + unpush_ds(B, frame(container.vector.elem_size) * (uoffset_t)count); + return 0; +} + +flatcc_builder_union_ref_t *flatcc_builder_union_vector_push(flatcc_builder_t *B, + flatcc_builder_union_ref_t uref) +{ + flatcc_builder_union_ref_t *p; + + check(frame(type) == flatcc_builder_union_vector, "expected union vector frame"); + if (frame(container.vector.count) == max_union_count) { + return 0; + } + frame(container.vector.count) += 1; + if (0 == (p = push_ds(B, union_size))) { + return 0; + } + *p = uref; + return p; +} + +flatcc_builder_union_ref_t *flatcc_builder_append_union_vector(flatcc_builder_t *B, + const flatcc_builder_union_ref_t *urefs, size_t count) +{ + check(frame(type) == flatcc_builder_union_vector, "expected union vector frame"); + if (vector_count_add(B, (uoffset_t)count, max_union_count)) { + return 0; + } + return push_ds_copy(B, urefs, (uoffset_t)(union_size * count)); +} + +flatcc_builder_ref_t flatcc_builder_create_string(flatcc_builder_t *B, const char *s, size_t len) +{ + uoffset_t s_pad; + uoffset_t length_prefix; + iov_state_t iov; + + if (len > max_string_len) { + return 0; + } + write_uoffset(&length_prefix, (uoffset_t)len); + /* Add 1 for zero termination. */ + s_pad = front_pad(B, (uoffset_t)len + 1, field_size) + 1; + init_iov(); + push_iov(&length_prefix, field_size); + push_iov(s, len); + push_iov(_pad, s_pad); + return emit_front(B, &iov); +} + +flatcc_builder_ref_t flatcc_builder_create_string_str(flatcc_builder_t *B, const char *s) +{ + return flatcc_builder_create_string(B, s, strlen(s)); +} + +flatcc_builder_ref_t flatcc_builder_create_string_strn(flatcc_builder_t *B, const char *s, size_t max_len) +{ + return flatcc_builder_create_string(B, s, strnlen(s, max_len)); +} + +flatcc_builder_ref_t flatcc_builder_end_string(flatcc_builder_t *B) +{ + flatcc_builder_ref_t string_ref; + + check(frame(type) == flatcc_builder_string, "expected string frame"); + FLATCC_ASSERT(frame(container.vector.count) == B->ds_offset); + if (0 == (string_ref = flatcc_builder_create_string(B, + (const char *)B->ds, B->ds_offset))) { + return 0; + } + exit_frame(B); + return string_ref; +} + +char *flatcc_builder_string_edit(flatcc_builder_t *B) +{ + return (char *)B->ds; +} + +size_t flatcc_builder_string_len(flatcc_builder_t *B) +{ + return frame(container.vector.count); +} + +void *flatcc_builder_table_add(flatcc_builder_t *B, int id, size_t size, uint16_t align) +{ + /* + * We align the offset relative to the first table field, excluding + * the header holding the vtable reference. On the stack, `ds_first` + * is aligned to 8 bytes thanks to the `enter_frame` logic, and this + * provides a safe way to update the fields on the stack, but here + * we are concerned with the target buffer alignment. + * + * We could also have aligned relative to the end of the table which + * would allow us to emit each field immediately, but it would be a + * confusing user experience wrt. field ordering, and it would add + * more variability to vtable layouts, thus reducing reuse, and + * frequent emissions to external emitter interface would be + * sub-optimal. Also, with that appoach, the vtable offsets would + * have to be adjusted at table end. + * + * As we have it, each emit occur at table end, vector end, string + * end, or buffer end, which might be helpful to various backend + * processors. + */ + check(frame(type) == flatcc_builder_table, "expected table frame"); + check(id >= 0 && id <= (int)FLATBUFFERS_ID_MAX, "table id out of range"); + if (align > B->align) { + B->align = align; + } +#if FLATCC_BUILDER_ALLOW_REPEAT_TABLE_ADD + if (B->vs[id] != 0) { + return B->ds + B->vs[id] - field_size; + } +#else + if (B->vs[id] != 0) { + check(0, "table field already set"); + return 0; + } +#endif + FLATCC_BUILDER_UPDATE_VT_HASH(B->vt_hash, (uint32_t)id, (uint32_t)size); + return push_ds_field(B, (uoffset_t)size, align, (voffset_t)id); +} + +void *flatcc_builder_table_edit(flatcc_builder_t *B, size_t size) +{ + check(frame(type) == flatcc_builder_table, "expected table frame"); + + return B->ds + B->ds_offset - size; +} + +void *flatcc_builder_table_add_copy(flatcc_builder_t *B, int id, const void *data, size_t size, uint16_t align) +{ + void *p; + + if ((p = flatcc_builder_table_add(B, id, size, align))) { + memcpy(p, data, size); + } + return p; +} + +flatcc_builder_ref_t *flatcc_builder_table_add_offset(flatcc_builder_t *B, int id) +{ + check(frame(type) == flatcc_builder_table, "expected table frame"); + check(id >= 0 && id <= (int)FLATBUFFERS_ID_MAX, "table id out of range"); +#if FLATCC_BUILDER_ALLOW_REPEAT_TABLE_ADD + if (B->vs[id] != 0) { + return B->ds + B->vs[id] - field_size; + } +#else + if (B->vs[id] != 0) { + check(0, "table field already set"); + return 0; + } +#endif + FLATCC_BUILDER_UPDATE_VT_HASH(B->vt_hash, (uint32_t)id, (uint32_t)field_size); + return push_ds_offset_field(B, (voffset_t)id); +} + +uint16_t flatcc_builder_push_buffer_alignment(flatcc_builder_t *B) +{ + uint16_t old_min_align = B->min_align; + + B->min_align = field_size; + return old_min_align; +} + +void flatcc_builder_pop_buffer_alignment(flatcc_builder_t *B, uint16_t pushed_align) +{ + set_min_align(B, pushed_align); +} + +uint16_t flatcc_builder_get_buffer_alignment(flatcc_builder_t *B) +{ + return B->min_align; +} + +void flatcc_builder_set_vtable_clustering(flatcc_builder_t *B, int enable) +{ + /* Inverted because we zero all memory in B on init. */ + B->disable_vt_clustering = !enable; +} + +void flatcc_builder_set_block_align(flatcc_builder_t *B, uint16_t align) +{ + B->block_align = align; +} + +int flatcc_builder_get_level(flatcc_builder_t *B) +{ + return B->level; +} + +void flatcc_builder_set_max_level(flatcc_builder_t *B, int max_level) +{ + B->max_level = max_level; + if (B->limit_level < B->max_level) { + B->limit_level = B->max_level; + } +} + +size_t flatcc_builder_get_buffer_size(flatcc_builder_t *B) +{ + return (size_t)(B->emit_end - B->emit_start); +} + +flatcc_builder_ref_t flatcc_builder_get_buffer_start(flatcc_builder_t *B) +{ + return B->emit_start; +} + +flatcc_builder_ref_t flatcc_builder_get_buffer_end(flatcc_builder_t *B) +{ + return B->emit_end; +} + +void flatcc_builder_set_vtable_cache_limit(flatcc_builder_t *B, size_t size) +{ + B->vb_flush_limit = size; +} + +void flatcc_builder_set_identifier(flatcc_builder_t *B, const char identifier[identifier_size]) +{ + set_identifier(identifier); +} + +enum flatcc_builder_type flatcc_builder_get_type(flatcc_builder_t *B) +{ + return B->frame ? frame(type) : flatcc_builder_empty; +} + +enum flatcc_builder_type flatcc_builder_get_type_at(flatcc_builder_t *B, int level) +{ + if (level < 1 || level > B->level) { + return flatcc_builder_empty; + } + return B->frame[level - B->level].type; +} + +void *flatcc_builder_get_direct_buffer(flatcc_builder_t *B, size_t *size_out) +{ + if (B->is_default_emitter) { + return flatcc_emitter_get_direct_buffer(&B->default_emit_context, size_out); + } else { + if (size_out) { + *size_out = 0; + } + } + return 0; +} + +void *flatcc_builder_copy_buffer(flatcc_builder_t *B, void *buffer, size_t size) +{ + /* User is allowed to call tentatively to see if there is support. */ + if (!B->is_default_emitter) { + return 0; + } + buffer = flatcc_emitter_copy_buffer(&B->default_emit_context, buffer, size); + check(buffer, "default emitter declined to copy buffer"); + return buffer; +} + +void *flatcc_builder_finalize_buffer(flatcc_builder_t *B, size_t *size_out) +{ + void * buffer; + size_t size; + + size = flatcc_builder_get_buffer_size(B); + + if (size_out) { + *size_out = size; + } + + buffer = FLATCC_BUILDER_ALLOC(size); + + if (!buffer) { + check(0, "failed to allocated memory for finalized buffer"); + goto done; + } + if (!flatcc_builder_copy_buffer(B, buffer, size)) { + check(0, "default emitter declined to copy buffer"); + FLATCC_BUILDER_FREE(buffer); + buffer = 0; + } +done: + if (!buffer && size_out) { + *size_out = 0; + } + return buffer; +} + +void *flatcc_builder_finalize_aligned_buffer(flatcc_builder_t *B, size_t *size_out) +{ + void * buffer; + size_t align; + size_t size; + + size = flatcc_builder_get_buffer_size(B); + + if (size_out) { + *size_out = size; + } + align = flatcc_builder_get_buffer_alignment(B); + + size = (size + align - 1) & ~(align - 1); + buffer = FLATCC_BUILDER_ALIGNED_ALLOC(align, size); + + if (!buffer) { + goto done; + } + if (!flatcc_builder_copy_buffer(B, buffer, size)) { + FLATCC_BUILDER_ALIGNED_FREE(buffer); + buffer = 0; + goto done; + } +done: + if (!buffer && size_out) { + *size_out = 0; + } + return buffer; +} + +void *flatcc_builder_aligned_alloc(size_t alignment, size_t size) +{ + return FLATCC_BUILDER_ALIGNED_ALLOC(alignment, size); +} + +void flatcc_builder_aligned_free(void *p) +{ + FLATCC_BUILDER_ALIGNED_FREE(p); +} + +void *flatcc_builder_alloc(size_t size) +{ + return FLATCC_BUILDER_ALLOC(size); +} + +void flatcc_builder_free(void *p) +{ + FLATCC_BUILDER_FREE(p); +} + +void *flatcc_builder_get_emit_context(flatcc_builder_t *B) +{ + return B->emit_context; +} +#include + +#include "flatcc/flatcc_rtconfig.h" +#include "flatcc/flatcc_emitter.h" + +static int advance_front(flatcc_emitter_t *E) +{ + flatcc_emitter_page_t *p = 0; + + if (E->front && E->front->prev != E->back) { + E->front->prev->page_offset = E->front->page_offset - FLATCC_EMITTER_PAGE_SIZE; + E->front = E->front->prev; + goto done; + } + if (!(p = FLATCC_EMITTER_ALLOC(sizeof(flatcc_emitter_page_t)))) { + return -1; + } + E->capacity += FLATCC_EMITTER_PAGE_SIZE; + if (E->front) { + p->prev = E->back; + p->next = E->front; + E->front->prev = p; + E->back->next = p; + E->front = p; + goto done; + } + /* + * The first page is shared between front and back to avoid + * double unecessary extra allocation. + */ + E->front = p; + E->back = p; + p->next = p; + p->prev = p; + E->front_cursor = E->front->page + FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_cursor = E->front_cursor; + E->front_left = FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_left = FLATCC_EMITTER_PAGE_SIZE - E->front_left; + p->page_offset = -(flatbuffers_soffset_t)E->front_left; + return 0; +done: + E->front_cursor = E->front->page + FLATCC_EMITTER_PAGE_SIZE; + E->front_left = FLATCC_EMITTER_PAGE_SIZE; + E->front->page_offset = E->front->next->page_offset - FLATCC_EMITTER_PAGE_SIZE; + return 0; +} + +static int advance_back(flatcc_emitter_t *E) +{ + flatcc_emitter_page_t *p = 0; + + if (E->back && E->back->next != E->front) { + E->back = E->back->next; + goto done; + } + if (!(p = FLATCC_EMITTER_ALLOC(sizeof(flatcc_emitter_page_t)))) { + return -1; + } + E->capacity += FLATCC_EMITTER_PAGE_SIZE; + if (E->back) { + p->prev = E->back; + p->next = E->front; + E->front->prev = p; + E->back->next = p; + E->back = p; + goto done; + } + /* + * The first page is shared between front and back to avoid + * double unecessary extra allocation. + */ + E->front = p; + E->back = p; + p->next = p; + p->prev = p; + E->front_cursor = E->front->page + FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_cursor = E->front_cursor; + E->front_left = FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_left = FLATCC_EMITTER_PAGE_SIZE - E->front_left; + p->page_offset = -(flatbuffers_soffset_t)E->front_left; + return 0; +done: + E->back_cursor = E->back->page; + E->back_left = FLATCC_EMITTER_PAGE_SIZE; + E->back->page_offset = E->back->prev->page_offset + FLATCC_EMITTER_PAGE_SIZE; + return 0; +} + +static int copy_front(flatcc_emitter_t *E, uint8_t *data, size_t size) +{ + size_t k; + + data += size; + while (size) { + k = size; + if (k > E->front_left) { + k = E->front_left; + if (k == 0) { + if (advance_front(E)) { + return -1; + } + continue; + } + } + E->front_cursor -= k; + E->front_left -= k; + data -= k; + size -= k; + memcpy(E->front_cursor, data, k); + }; + return 0; +} + +static int copy_back(flatcc_emitter_t *E, uint8_t *data, size_t size) +{ + size_t k; + + while (size) { + k = size; + if (k > E->back_left) { + k = E->back_left; + if (k == 0) { + if (advance_back(E)) { + return -1; + } + continue; + } + } + memcpy(E->back_cursor, data, k); + size -= k; + data += k; + E->back_cursor += k; + E->back_left -= k; + } + return 0; +} + +int flatcc_emitter_recycle_page(flatcc_emitter_t *E, flatcc_emitter_page_t *p) +{ + if (p == E->front || p == E->back) { + return -1; + } + p->next->prev = p->prev; + p->prev->next = p->next; + p->prev = E->front->prev; + p->next = E->front; + p->prev->next = p; + p->next->prev = p; + return 0; +} + +void flatcc_emitter_reset(flatcc_emitter_t *E) +{ + flatcc_emitter_page_t *p = E->front; // NOLINT(clang-analyzer-deadcode.DeadStores) + + if (!E->front) { + return; + } + E->back = E->front; + E->front_cursor = E->front->page + FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_cursor = E->front_cursor; + E->front_left = FLATCC_EMITTER_PAGE_SIZE / 2; + E->back_left = FLATCC_EMITTER_PAGE_SIZE - FLATCC_EMITTER_PAGE_SIZE / 2; + E->front->page_offset = -(flatbuffers_soffset_t)E->front_left; + /* Heuristic to reduce peak allocation over time. */ + if (E->used_average == 0) { + E->used_average = E->used; + } + E->used_average = E->used_average * 3 / 4 + E->used / 4; + E->used = 0; + while (E->used_average * 2 < E->capacity && E->back->next != E->front) { + /* We deallocate the page after back since it is less likely to be hot in cache. */ + p = E->back->next; + E->back->next = p->next; + p->next->prev = E->back; + FLATCC_EMITTER_FREE(p); + E->capacity -= FLATCC_EMITTER_PAGE_SIZE; + } +} + +void flatcc_emitter_clear(flatcc_emitter_t *E) +{ + flatcc_emitter_page_t *p = E->front; + + if (!p) { + return; + } + p->prev->next = 0; + while (p->next) { + p = p->next; + FLATCC_EMITTER_FREE(p->prev); + } + FLATCC_EMITTER_FREE(p); + memset(E, 0, sizeof(*E)); +} + +int flatcc_emitter(void *emit_context, + const flatcc_iovec_t *iov, int iov_count, + flatbuffers_soffset_t offset, size_t len) +{ + flatcc_emitter_t *E = emit_context; + uint8_t *p; + + E->used += len; + if (offset < 0) { + if (len <= E->front_left) { + E->front_cursor -= len; + E->front_left -= len; + p = E->front_cursor; + goto copy; + } + iov += iov_count; + while (iov_count--) { + --iov; + if (copy_front(E, iov->iov_base, iov->iov_len)) { + return -1; + } + } + } else { + if (len <= E->back_left) { + p = E->back_cursor; + E->back_cursor += len; + E->back_left -= len; + goto copy; + } + while (iov_count--) { + if (copy_back(E, iov->iov_base, iov->iov_len)) { + return -1; + } + ++iov; + } + } + return 0; +copy: + while (iov_count--) { + memcpy(p, iov->iov_base, iov->iov_len); + p += iov->iov_len; + ++iov; + } + return 0; +} + +void *flatcc_emitter_copy_buffer(flatcc_emitter_t *E, void *buf, size_t size) +{ + flatcc_emitter_page_t *p; + size_t len; + + if (size < E->used) { + return 0; + } + if (!E->front) { + return 0; + } + if (E->front == E->back) { + memcpy(buf, E->front_cursor, E->used); + return buf; + } + len = FLATCC_EMITTER_PAGE_SIZE - E->front_left; + memcpy(buf, E->front_cursor, len); + buf = (uint8_t *)buf + len; + p = E->front->next; + while (p != E->back) { + memcpy(buf, p->page, FLATCC_EMITTER_PAGE_SIZE); + buf = (uint8_t *)buf + FLATCC_EMITTER_PAGE_SIZE; + p = p->next; + } + memcpy(buf, p->page, FLATCC_EMITTER_PAGE_SIZE - E->back_left); + return buf; +} +/* + * Runtime support for verifying flatbuffers. + * + * Depends mutually on generated verifier functions for table types that + * call into this library. + */ +#include + +#include "flatcc/flatcc_rtconfig.h" +#include "flatcc/flatcc_flatbuffers.h" +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_identifier.h" + +/* Customization for testing. */ +#if FLATCC_DEBUG_VERIFY +#define FLATCC_VERIFIER_ASSERT_ON_ERROR 1 +#include +#define FLATCC_VERIFIER_ASSERT(cond, reason) \ + if (!(cond)) { fprintf(stderr, "verifier assert: %s\n", \ + flatcc_verify_error_string(reason)); FLATCC_ASSERT(0); return reason; } +#endif + +#if FLATCC_TRACE_VERIFY +#include +#define trace_verify(s, p) \ + fprintf(stderr, "trace verify: %s: 0x%02x\n", (s), (unsigned)(size_t)(p)); +#else +#define trace_verify(s, p) ((void)0) +#endif + +/* The runtime library does not use the global config file. */ + +/* This is a guideline, not an exact measure. */ +#ifndef FLATCC_VERIFIER_MAX_LEVELS +#define FLATCC_VERIFIER_MAX_LEVELS 100 +#endif + +#ifndef FLATCC_VERIFIER_ASSERT_ON_ERROR +#define FLATCC_VERIFIER_ASSERT_ON_ERROR 0 +#endif + +/* + * Generally a check should tell if a buffer is valid or not such + * that runtime can take appropriate actions rather than crash, + * also in debug, but assertions are helpful in debugging a problem. + * + * This must be compiled into the debug runtime library to take effect. + */ +#ifndef FLATCC_VERIFIER_ASSERT_ON_ERROR +#define FLATCC_VERIFIER_ASSERT_ON_ERROR 1 +#endif + +/* May be redefined for logging purposes. */ +#ifndef FLATCC_VERIFIER_ASSERT +#define FLATCC_VERIFIER_ASSERT(cond, reason) FLATCC_ASSERT(cond) +#endif + +#if FLATCC_VERIFIER_ASSERT_ON_ERROR +#define flatcc_verify(cond, reason) if (!(cond)) { FLATCC_VERIFIER_ASSERT(cond, reason); return reason; } +#else +#define flatcc_verify(cond, reason) if (!(cond)) { return reason; } +#endif + + +#define uoffset_t flatbuffers_uoffset_t +#define soffset_t flatbuffers_soffset_t +#define voffset_t flatbuffers_voffset_t +#define utype_t flatbuffers_utype_t +#define thash_t flatbuffers_thash_t + +#define uoffset_size sizeof(uoffset_t) +#define soffset_size sizeof(soffset_t) +#define voffset_size sizeof(voffset_t) +#define utype_size sizeof(utype_t) +#define thash_size sizeof(thash_t) +#define offset_size uoffset_size + +const char *flatcc_verify_error_string(int err) +{ + switch (err) { +#define XX(no, str) \ + case flatcc_verify_error_##no: \ + return str; + FLATCC_VERIFY_ERROR_MAP(XX) +#undef XX + default: + return "unknown"; + } +} + +/* `cond` may have side effects. */ +#define verify(cond, reason) do { int c = (cond); flatcc_verify(c, reason); } while(0) + +/* + * Identify checks related to runtime conditions (buffer size and + * alignment) as seperate from those related to buffer content. + */ +#define verify_runtime(cond, reason) verify(cond, reason) + +#define check_result(x) if (x) { return (x); } + +#define check_field(td, id, required, base) do { \ + int ret = get_offset_field(td, id, required, &base); \ + if (ret || !base) { return ret; }} while (0) + +static inline uoffset_t read_uoffset(const void *p, uoffset_t base) +{ + return __flatbuffers_uoffset_read_from_pe((uint8_t *)p + base); +} + +static inline thash_t read_thash_identifier(const char *identifier) +{ + return flatbuffers_type_hash_from_string(identifier); +} + +static inline thash_t read_thash(const void *p, uoffset_t base) +{ + return __flatbuffers_thash_read_from_pe((uint8_t *)p + base); +} + +static inline voffset_t read_voffset(const void *p, uoffset_t base) +{ + return __flatbuffers_voffset_read_from_pe((uint8_t *)p + base); +} + +static inline int check_header(uoffset_t end, uoffset_t base, uoffset_t offset) +{ + uoffset_t k = base + offset; + + if (uoffset_size <= voffset_size && k + offset_size < k) { + return 0; + } + + /* The `k > base` rather than `k >= base` is to avoid null offsets. */ + return k > base && k + offset_size <= end && !(k & (offset_size - 1)); +} + +static inline int verify_struct(uoffset_t end, uoffset_t base, uoffset_t offset, uoffset_t size, uint16_t align) +{ + /* Structs can have zero size so `end` is a valid value. */ + if (offset == 0 || base + offset > end) { + return flatcc_verify_error_offset_out_of_range; + } + base += offset; + verify(base + size >= base, flatcc_verify_error_struct_size_overflow); + verify(base + size <= end, flatcc_verify_error_struct_out_of_range); + verify (!(base & (align - 1u)), flatcc_verify_error_struct_unaligned); + return flatcc_verify_ok; +} + +static inline voffset_t read_vt_entry(flatcc_table_verifier_descriptor_t *td, voffset_t id) +{ + voffset_t vo = (id + 2u) * sizeof(voffset_t); + + /* Assumes tsize has been verified for alignment. */ + if (vo >= td->vsize) { + return 0; + } + return read_voffset(td->vtable, vo); +} + +static inline const void *get_field_ptr(flatcc_table_verifier_descriptor_t *td, voffset_t id) +{ + voffset_t vte = read_vt_entry(td, id); + return vte ? (const uint8_t *)td->buf + td->table + vte : 0; +} + +static int verify_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, uoffset_t size, uint16_t align) +{ + uoffset_t k, k2; + voffset_t vte; + uoffset_t base = (uoffset_t)(size_t)td->buf; + + + /* + * Otherwise range check assumptions break, and normal access code likely also. + * We don't require voffset_size < uoffset_size, but some checks are faster if true. + */ + FLATCC_ASSERT(uoffset_size >= voffset_size); + FLATCC_ASSERT(soffset_size == uoffset_size); + + vte = read_vt_entry(td, id); + if (!vte) { + verify(!required, flatcc_verify_error_required_field_missing); + return flatcc_verify_ok; + } + trace_verify("table buffer", td->buf); + trace_verify("table", td->table); + trace_verify("id", id); + trace_verify("vte", vte); + + /* + * Note that we don't add td.table to k and we test against table + * size not table end or buffer end. Otherwise it would not be safe + * to optimized out the k <= k2 check for normal uoffset and voffset + * configurations. + */ + k = vte; + k2 = k + size; + verify(k2 <= td->tsize, flatcc_verify_error_table_field_out_of_range); + /* This normally optimizes to nop. */ + verify(uoffset_size > voffset_size || k <= k2, flatcc_verify_error_table_field_size_overflow); + trace_verify("table + vte", vte + td->table); + k += td->table + base; + trace_verify("entry: buf + table + vte", k); + trace_verify("align", align); + trace_verify("align masked entry", k & (align - 1u)); + verify(!(k & (align - 1u)), flatcc_verify_error_table_field_not_aligned); + /* We assume the table size has already been verified. */ + return flatcc_verify_ok; +} + +static int get_offset_field(flatcc_table_verifier_descriptor_t *td, voffset_t id, int required, uoffset_t *out) +{ + uoffset_t k, k2; + voffset_t vte; + + vte = read_vt_entry(td, id); + if (!vte) { + *out = 0; + if (required) { + return flatcc_verify_error_required_field_missing; + } + /* Missing, but not invalid. */ + return flatcc_verify_ok; + } + /* + * Note that we don't add td.table to k and we test against table + * size not table end or buffer end. Otherwise it would not be safe + * to optimized out the k <= k2 check for normal uoffset and voffset + * configurations. + */ + k = vte; + k2 = k + offset_size; + verify(k2 <= td->tsize, flatcc_verify_error_table_field_out_of_range); + /* This normally optimizes to nop. */ + verify(uoffset_size > voffset_size || k <= k2, flatcc_verify_error_table_field_size_overflow); + k += td->table; + verify(!(k & (offset_size - 1u)), flatcc_verify_error_table_field_not_aligned); + /* We assume the table size has already been verified. */ + *out = k; + return flatcc_verify_ok; +} + +static inline int verify_string(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset) +{ + uoffset_t n; + + verify(check_header(end, base, offset), flatcc_verify_error_string_header_out_of_range_or_unaligned); + base += offset; + n = read_uoffset(buf, base); + base += offset_size; + verify(end - base > n, flatcc_verify_error_string_out_of_range); + verify(((uint8_t *)buf + base)[n] == 0, flatcc_verify_error_string_not_zero_terminated); + return flatcc_verify_ok; +} + +/* + * Keep interface somwewhat similar ot flatcc_builder_start_vector. + * `max_count` is a precomputed division to manage overflow check on vector length. + */ +static inline int verify_vector(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset, uoffset_t elem_size, uint16_t align, uoffset_t max_count) +{ + uoffset_t n; + + verify(check_header(end, base, offset), flatcc_verify_error_vector_header_out_of_range_or_unaligned); + base += offset; + + n = read_uoffset(buf, base); + base += offset_size; + +#if !FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS + /* This is due to incorrect buffers from other builders than cannot easily be ignored. */ + align = n == 0 ? uoffset_size : align; +#endif + verify(!(base & ((align - 1u) | (uoffset_size - 1u))), flatcc_verify_error_vector_header_out_of_range_or_unaligned); + /* `n * elem_size` can overflow uncontrollably otherwise. */ + verify(n <= max_count, flatcc_verify_error_vector_count_exceeds_representable_vector_size); + verify(end - base >= n * elem_size, flatcc_verify_error_vector_out_of_range); + return flatcc_verify_ok; +} + +static inline int verify_string_vector(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset) +{ + uoffset_t i, n; + + check_result(verify_vector(buf, end, base, offset, offset_size, offset_size, FLATBUFFERS_COUNT_MAX(offset_size))); + base += offset; + n = read_uoffset(buf, base); + base += offset_size; + for (i = 0; i < n; ++i, base += offset_size) { + check_result(verify_string(buf, end, base, read_uoffset(buf, base))); + } + return flatcc_verify_ok; +} + +static inline int verify_table(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset, + int ttl, flatcc_table_verifier_f tvf) +{ + uoffset_t vbase, vend; + flatcc_table_verifier_descriptor_t td; + + verify((td.ttl = ttl - 1), flatcc_verify_error_max_nesting_level_reached); + verify(check_header(end, base, offset), flatcc_verify_error_table_header_out_of_range_or_unaligned); + td.table = base + offset; + /* Read vtable offset - it is signed, but we want it unsigned, assuming 2's complement works. */ + vbase = td.table - read_uoffset(buf, td.table); + verify((soffset_t)vbase >= 0 && !(vbase & (voffset_size - 1)), flatcc_verify_error_vtable_offset_out_of_range_or_unaligned); + verify(vbase + voffset_size <= end, flatcc_verify_error_vtable_header_out_of_range); + /* Read vtable size. */ + td.vsize = read_voffset(buf, vbase); + vend = vbase + td.vsize; + verify(vend <= end && !(td.vsize & (voffset_size - 1)), flatcc_verify_error_vtable_size_out_of_range_or_unaligned); + /* Optimizes away overflow check if uoffset_t is large enough. */ + verify(uoffset_size > voffset_size || vend >= vbase, flatcc_verify_error_vtable_size_overflow); + + verify(td.vsize >= 2 * voffset_size, flatcc_verify_error_vtable_header_too_small); + /* Read table size. */ + td.tsize = read_voffset(buf, vbase + voffset_size); + verify(end - td.table >= td.tsize, flatcc_verify_error_table_size_out_of_range); + td.vtable = (uint8_t *)buf + vbase; + td.buf = buf; + td.end = end; + return tvf(&td); +} + +static inline int verify_table_vector(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset, int ttl, flatcc_table_verifier_f tvf) +{ + uoffset_t i, n; + + verify(ttl-- > 0, flatcc_verify_error_max_nesting_level_reached); + check_result(verify_vector(buf, end, base, offset, offset_size, offset_size, FLATBUFFERS_COUNT_MAX(offset_size))); + base += offset; + n = read_uoffset(buf, base); + base += offset_size; + for (i = 0; i < n; ++i, base += offset_size) { + check_result(verify_table(buf, end, base, read_uoffset(buf, base), ttl, tvf)); + } + return flatcc_verify_ok; +} + +static inline int verify_union_vector(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset, + uoffset_t count, const utype_t *types, int ttl, flatcc_union_verifier_f uvf) +{ + uoffset_t i, n, elem; + flatcc_union_verifier_descriptor_t ud; + + verify(ttl-- > 0, flatcc_verify_error_max_nesting_level_reached); + check_result(verify_vector(buf, end, base, offset, offset_size, offset_size, FLATBUFFERS_COUNT_MAX(offset_size))); + base += offset; + n = read_uoffset(buf, base); + verify(n == count, flatcc_verify_error_union_vector_length_mismatch); + base += offset_size; + + ud.buf = buf; + ud.end = end; + ud.ttl = ttl; + + for (i = 0; i < n; ++i, base += offset_size) { + /* Table vectors can never be null, but unions can when the type is NONE. */ + elem = read_uoffset(buf, base); + if (elem == 0) { + verify(types[i] == 0, flatcc_verify_error_union_element_absent_without_type_NONE); + } else { + verify(types[i] != 0, flatcc_verify_error_union_element_present_with_type_NONE); + ud.type = types[i]; + ud.base = base; + ud.offset = elem; + check_result(uvf(&ud)); + } + } + return flatcc_verify_ok; +} + +int flatcc_verify_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, size_t size, uint16_t align) +{ + check_result(verify_field(td, id, 0, (uoffset_t)size, align)); + return flatcc_verify_ok; +} + +int flatcc_verify_string_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required) +{ + uoffset_t base; + + check_field(td, id, required, base); + return verify_string(td->buf, td->end, base, read_uoffset(td->buf, base)); +} + +int flatcc_verify_vector_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, size_t elem_size, uint16_t align, size_t max_count) +{ + uoffset_t base; + + check_field(td, id, required, base); + return verify_vector(td->buf, td->end, base, read_uoffset(td->buf, base), + (uoffset_t)elem_size, align, (uoffset_t)max_count); +} + +int flatcc_verify_string_vector_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required) +{ + uoffset_t base; + + check_field(td, id, required, base); + return verify_string_vector(td->buf, td->end, base, read_uoffset(td->buf, base)); +} + +int flatcc_verify_table_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, flatcc_table_verifier_f tvf) +{ + uoffset_t base; + + check_field(td, id, required, base); + return verify_table(td->buf, td->end, base, read_uoffset(td->buf, base), td->ttl, tvf); +} + +int flatcc_verify_table_vector_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, flatcc_table_verifier_f tvf) +{ + uoffset_t base; + + check_field(td, id, required, base); + return verify_table_vector(td->buf, td->end, base, read_uoffset(td->buf, base), td->ttl, tvf); +} + +int flatcc_verify_union_table(flatcc_union_verifier_descriptor_t *ud, flatcc_table_verifier_f *tvf) +{ + return verify_table(ud->buf, ud->end, ud->base, ud->offset, ud->ttl, tvf); +} + +int flatcc_verify_union_struct(flatcc_union_verifier_descriptor_t *ud, size_t size, uint16_t align) +{ + return verify_struct(ud->end, ud->base, ud->offset, (uoffset_t)size, align); +} + +int flatcc_verify_union_string(flatcc_union_verifier_descriptor_t *ud) +{ + return verify_string(ud->buf, ud->end, ud->base, ud->offset); +} + +int flatcc_verify_buffer_header(const void *buf, size_t bufsiz, const char *fid) +{ + thash_t id, id2; + + verify_runtime(!(((size_t)buf) & (offset_size - 1)), flatcc_verify_error_runtime_buffer_header_not_aligned); + /* -8 ensures no scalar or offset field size can overflow. */ + verify_runtime(bufsiz <= FLATBUFFERS_UOFFSET_MAX - 8, flatcc_verify_error_runtime_buffer_size_too_large); + /* + * Even if we specify no fid, the user might later. Therefore + * require space for it. Not all buffer generators will take this + * into account, so it is possible to fail an otherwise valid buffer + * - but such buffers aren't safe. + */ + verify(bufsiz >= offset_size + FLATBUFFERS_IDENTIFIER_SIZE, flatcc_verify_error_buffer_header_too_small); + if (fid != 0) { + id2 = read_thash_identifier(fid); + id = read_thash(buf, offset_size); + verify(id2 == 0 || id == id2, flatcc_verify_error_identifier_mismatch); + } + return flatcc_verify_ok; +} + +int flatcc_verify_buffer_header_with_size(const void *buf, size_t *bufsiz, const char *fid) +{ + thash_t id, id2; + size_t size_field; + + verify_runtime(!(((size_t)buf) & (offset_size - 1)), flatcc_verify_error_runtime_buffer_header_not_aligned); + /* -8 ensures no scalar or offset field size can overflow. */ + verify_runtime(*bufsiz <= FLATBUFFERS_UOFFSET_MAX - 8, flatcc_verify_error_runtime_buffer_size_too_large); + + /* Size field, offset field, optional identifier field that must be read even if not present. */ + verify(*bufsiz >= 2 * offset_size + FLATBUFFERS_IDENTIFIER_SIZE, flatcc_verify_error_buffer_header_too_small); + + size_field = (size_t)read_uoffset(buf, 0); + verify_runtime(size_field <= *bufsiz - offset_size, flatcc_verify_error_runtime_buffer_size_less_than_size_field); + if (fid != 0) { + id2 = read_thash_identifier(fid); + id = read_thash(buf, offset_size); + verify(id2 == 0 || id == id2, flatcc_verify_error_identifier_mismatch); + } + *bufsiz = size_field + offset_size; + return flatcc_verify_ok; +} + +int flatcc_verify_typed_buffer_header(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + thash_t id, id2; + + verify_runtime(!(((size_t)buf) & (offset_size - 1)), flatcc_verify_error_runtime_buffer_header_not_aligned); + /* -8 ensures no scalar or offset field size can overflow. */ + verify_runtime(bufsiz <= FLATBUFFERS_UOFFSET_MAX - 8, flatcc_verify_error_runtime_buffer_size_too_large); + /* + * Even if we specify no fid, the user might later. Therefore + * require space for it. Not all buffer generators will take this + * into account, so it is possible to fail an otherwise valid buffer + * - but such buffers aren't safe. + */ + verify(bufsiz >= offset_size + FLATBUFFERS_IDENTIFIER_SIZE, flatcc_verify_error_buffer_header_too_small); + if (thash != 0) { + id2 = thash; + id = read_thash(buf, offset_size); + verify(id2 == 0 || id == id2, flatcc_verify_error_identifier_mismatch); + } + return flatcc_verify_ok; +} + +int flatcc_verify_typed_buffer_header_with_size(const void *buf, size_t *bufsiz, flatbuffers_thash_t thash) +{ + thash_t id, id2; + size_t size_field; + + verify_runtime(!(((size_t)buf) & (offset_size - 1)), flatcc_verify_error_runtime_buffer_header_not_aligned); + /* -8 ensures no scalar or offset field size can overflow. */ + verify_runtime(*bufsiz <= FLATBUFFERS_UOFFSET_MAX - 8, flatcc_verify_error_runtime_buffer_size_too_large); + + /* Size field, offset field, optional identifier field that must be read even if not present. */ + verify(*bufsiz >= 2 * offset_size + FLATBUFFERS_IDENTIFIER_SIZE, flatcc_verify_error_buffer_header_too_small); + + size_field = (size_t)read_uoffset(buf, 0); + verify_runtime(size_field <= *bufsiz - offset_size, flatcc_verify_error_runtime_buffer_size_less_than_size_field); + if (thash != 0) { + id2 = thash; + id = read_thash(buf, offset_size); + verify(id2 == 0 || id == id2, flatcc_verify_error_identifier_mismatch); + } + *bufsiz = size_field + offset_size; + return flatcc_verify_ok; +} + +int flatcc_verify_struct_as_root(const void *buf, size_t bufsiz, const char *fid, size_t size, uint16_t align) +{ + check_result(flatcc_verify_buffer_header(buf, bufsiz, fid)); + return verify_struct((uoffset_t)bufsiz, 0, read_uoffset(buf, 0), (uoffset_t)size, align); +} + +int flatcc_verify_struct_as_root_with_size(const void *buf, size_t bufsiz, const char *fid, size_t size, uint16_t align) +{ + check_result(flatcc_verify_buffer_header_with_size(buf, &bufsiz, fid)); + return verify_struct((uoffset_t)bufsiz, 0, read_uoffset(buf, 0), (uoffset_t)size, align); +} + +int flatcc_verify_struct_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, size_t size, uint16_t align) +{ + check_result(flatcc_verify_typed_buffer_header(buf, bufsiz, thash)); + return verify_struct((uoffset_t)bufsiz, 0, read_uoffset(buf, 0), (uoffset_t)size, align); +} + +int flatcc_verify_struct_as_typed_root_with_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, size_t size, uint16_t align) +{ + check_result(flatcc_verify_typed_buffer_header_with_size(buf, &bufsiz, thash)); + return verify_struct((uoffset_t)bufsiz, uoffset_size, read_uoffset(buf, uoffset_size), (uoffset_t)size, align); +} + +int flatcc_verify_table_as_root(const void *buf, size_t bufsiz, const char *fid, flatcc_table_verifier_f *tvf) +{ + check_result(flatcc_verify_buffer_header(buf, bufsiz, fid)); + return verify_table(buf, (uoffset_t)bufsiz, 0, read_uoffset(buf, 0), FLATCC_VERIFIER_MAX_LEVELS, tvf); +} + +int flatcc_verify_table_as_root_with_size(const void *buf, size_t bufsiz, const char *fid, flatcc_table_verifier_f *tvf) +{ + check_result(flatcc_verify_buffer_header_with_size(buf, &bufsiz, fid)); + return verify_table(buf, (uoffset_t)bufsiz, uoffset_size, read_uoffset(buf, uoffset_size), FLATCC_VERIFIER_MAX_LEVELS, tvf); +} + +int flatcc_verify_table_as_typed_root(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, flatcc_table_verifier_f *tvf) +{ + check_result(flatcc_verify_typed_buffer_header(buf, bufsiz, thash)); + return verify_table(buf, (uoffset_t)bufsiz, 0, read_uoffset(buf, 0), FLATCC_VERIFIER_MAX_LEVELS, tvf); +} + +int flatcc_verify_table_as_typed_root_with_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash, flatcc_table_verifier_f *tvf) +{ + check_result(flatcc_verify_typed_buffer_header_with_size(buf, &bufsiz, thash)); + return verify_table(buf, (uoffset_t)bufsiz, uoffset_size, read_uoffset(buf, uoffset_size), FLATCC_VERIFIER_MAX_LEVELS, tvf); +} + +int flatcc_verify_struct_as_nested_root(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, const char *fid, size_t size, uint16_t align) +{ + const uoffset_t *buf; + uoffset_t bufsiz; + + check_result(flatcc_verify_vector_field(td, id, required, align, 1, FLATBUFFERS_COUNT_MAX(1))); + if (0 == (buf = get_field_ptr(td, id))) { + return flatcc_verify_ok; + } + buf = (const uoffset_t *)((size_t)buf + read_uoffset(buf, 0)); + bufsiz = read_uoffset(buf, 0); + ++buf; + return flatcc_verify_struct_as_root(buf, bufsiz, fid, size, align); +} + +int flatcc_verify_table_as_nested_root(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, const char *fid, + uint16_t align, flatcc_table_verifier_f tvf) +{ + const uoffset_t *buf; + uoffset_t bufsiz; + + check_result(flatcc_verify_vector_field(td, id, required, align, 1, FLATBUFFERS_COUNT_MAX(1))); + if (0 == (buf = get_field_ptr(td, id))) { + return flatcc_verify_ok; + } + buf = (const uoffset_t *)((size_t)buf + read_uoffset(buf, 0)); + bufsiz = read_uoffset(buf, 0); + ++buf; + /* + * Don't verify nested buffers identifier - information is difficult to get and + * might not be what is desired anyway. User can do it later. + */ + check_result(flatcc_verify_buffer_header(buf, bufsiz, fid)); + return verify_table(buf, bufsiz, 0, read_uoffset(buf, 0), td->ttl, tvf); +} + +int flatcc_verify_union_field(flatcc_table_verifier_descriptor_t *td, + voffset_t id, int required, flatcc_union_verifier_f uvf) +{ + voffset_t vte_type, vte_table; + const uint8_t *type; + uoffset_t base; + flatcc_union_verifier_descriptor_t ud; + + if (0 == (vte_type = read_vt_entry(td, id - 1))) { + vte_table = read_vt_entry(td, id); + verify(vte_table == 0, flatcc_verify_error_union_cannot_have_a_table_without_a_type); + verify(!required, flatcc_verify_error_type_field_absent_from_required_union_field); + return flatcc_verify_ok; + } + /* No need to check required here. */ + check_result(verify_field(td, id - 1, 0, 1, 1)); + /* Only now is it safe to read the type. */ + vte_table = read_vt_entry(td, id); + type = (const uint8_t *)td->buf + td->table + vte_type; + verify(*type || vte_table == 0, flatcc_verify_error_union_type_NONE_cannot_have_a_value); + + if (*type == 0) { + return flatcc_verify_ok; + } + check_field(td, id, required, base); + ud.buf = td->buf; + ud.end = td->end; + ud.ttl = td->ttl; + ud.base = base; + ud.offset = read_uoffset(td->buf, base); + ud.type = *type; + return uvf(&ud); +} + +int flatcc_verify_union_vector_field(flatcc_table_verifier_descriptor_t *td, + flatbuffers_voffset_t id, int required, flatcc_union_verifier_f uvf) +{ + voffset_t vte_type, vte_table; + const uoffset_t *buf; + const utype_t *types; + uoffset_t count, base; + + if (0 == (vte_type = read_vt_entry(td, id - 1))) { // NOLINT(clang-analyzer-deadcode.DeadStores) + if (0 == (vte_table = read_vt_entry(td, id))) { // NOLINT(clang-analyzer-deadcode.DeadStores) + verify(!required, flatcc_verify_error_type_field_absent_from_required_union_vector_field); + } + } + check_result(flatcc_verify_vector_field(td, id - 1, required, + utype_size, utype_size, FLATBUFFERS_COUNT_MAX(utype_size))); + if (0 == (buf = get_field_ptr(td, id - 1))) { + return flatcc_verify_ok; + } + buf = (const uoffset_t *)((size_t)buf + read_uoffset(buf, 0)); + count = read_uoffset(buf, 0); + ++buf; + types = (utype_t *)buf; + + check_field(td, id, required, base); + return verify_union_vector(td->buf, td->end, base, read_uoffset(td->buf, base), + count, types, td->ttl, uvf); +} +/* + * Optional file that can be included in runtime library to support DAG + * cloning with the builder and may also be used for custom purposes + * standalone. See also comments in `flatcc/flatcc_builder.h`. + * + * Note that dynamic construction takes place and that large offset + * vectors might consume significant space if there are not many shared + * references. In the basic use case no allocation takes place because a + * few references can be held using only a small stack allocated hash + * table. + */ + +#include +#include + +#include "flatcc/flatcc_rtconfig.h" +#include "flatcc/flatcc_refmap.h" +#include "flatcc/flatcc_alloc.h" +#include "flatcc/flatcc_assert.h" + +#define _flatcc_refmap_calloc FLATCC_CALLOC +#define _flatcc_refmap_free FLATCC_FREE + +/* Can be used as a primitive defense against collision attacks. */ +#ifdef FLATCC_HASH_SEED +#define _flatcc_refmap_seed FLATCC_HASH_SEED +#else +#define _flatcc_refmap_seed 0x2f693b52 +#endif + +static inline size_t _flatcc_refmap_above_load_factor(size_t count, size_t buckets) +{ + static const size_t d = 256; + static const size_t n = (size_t)((FLATCC_REFMAP_LOAD_FACTOR) * 256.0f); + + return count >= buckets * n / d; +} + +#define _flatcc_refmap_probe(k, i, N) ((k + i) & N) + +void flatcc_refmap_clear(flatcc_refmap_t *refmap) +{ + if (refmap->table && refmap->table != refmap->min_table) { + _flatcc_refmap_free(refmap->table); + } + flatcc_refmap_init(refmap); +} + +static inline size_t _flatcc_refmap_hash(const void *src) +{ + /* MurmurHash3 64-bit finalizer */ + uint64_t x; + + x = (uint64_t)((size_t)src) ^ _flatcc_refmap_seed; + + x ^= x >> 33; + x *= 0xff51afd7ed558ccdULL; + x ^= x >> 33; + x *= 0xc4ceb9fe1a85ec53ULL; + x ^= x >> 33; + return (size_t)x; +} + +void flatcc_refmap_reset(flatcc_refmap_t *refmap) +{ + if (refmap->count) { + memset(refmap->table, 0, sizeof(refmap->table[0]) * refmap->buckets); + } + refmap->count = 0; +} + +/* + * Technically resize also supports shrinking which may be useful for + * adapations, but the current hash table never deletes individual items. + */ +int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count) +{ + const size_t min_buckets = sizeof(refmap->min_table) / sizeof(refmap->min_table[0]); + + size_t i; + size_t buckets; + size_t buckets_old; + struct flatcc_refmap_item *T_old; + + if (count < refmap->count) { + count = refmap->count; + } + buckets = min_buckets; + + while (_flatcc_refmap_above_load_factor(count, buckets)) { + buckets *= 2; + } + if (refmap->buckets == buckets) { + return 0; + } + T_old = refmap->table; + buckets_old = refmap->buckets; + if (buckets == min_buckets) { + memset(refmap->min_table, 0, sizeof(refmap->min_table)); + refmap->table = refmap->min_table; + } else { + refmap->table = _flatcc_refmap_calloc(buckets, sizeof(refmap->table[0])); + if (refmap->table == 0) { + refmap->table = T_old; + FLATCC_ASSERT(0); /* out of memory */ + return -1; + } + } + refmap->buckets = buckets; + refmap->count = 0; + for (i = 0; i < buckets_old; ++i) { + if (T_old[i].src) { + flatcc_refmap_insert(refmap, T_old[i].src, T_old[i].ref); + } + } + if (T_old && T_old != refmap->min_table) { + _flatcc_refmap_free(T_old); + } + return 0; +} + +flatcc_refmap_ref_t flatcc_refmap_insert(flatcc_refmap_t *refmap, const void *src, flatcc_refmap_ref_t ref) +{ + struct flatcc_refmap_item *T; + size_t N, i, j, k; + + if (src == 0) return ref; + if (_flatcc_refmap_above_load_factor(refmap->count, refmap->buckets)) { + if (flatcc_refmap_resize(refmap, refmap->count * 2)) { + return flatcc_refmap_not_found; /* alloc failed */ + } + } + T = refmap->table; + N = refmap->buckets - 1; + k = _flatcc_refmap_hash(src); + i = 0; + j = _flatcc_refmap_probe(k, i, N); + while (T[j].src) { + if (T[j].src == src) { + return T[j].ref = ref; + } + ++i; + j = _flatcc_refmap_probe(k, i, N); + } + ++refmap->count; + T[j].src = src; + return T[j].ref = ref; +} + +flatcc_refmap_ref_t flatcc_refmap_find(flatcc_refmap_t *refmap, const void *src) +{ + struct flatcc_refmap_item *T; + size_t N, i, j, k; + + if (refmap->count == 0) { + return flatcc_refmap_not_found; + } + T = refmap->table; + N = refmap->buckets - 1; + k = _flatcc_refmap_hash(src); + i = 0; + j = _flatcc_refmap_probe(k, i, N); + while (T[j].src) { + if (T[j].src == src) return T[j].ref; + ++i; + j = _flatcc_refmap_probe(k, i, N); + } + return flatcc_refmap_not_found; +} + +/* + * To run test from project root: + * + * cc -D FLATCC_REFMAP_TEST -I include src/runtime/refmap.c -o test_refmap && ./test_refmap + * + */ +#ifdef FLATCC_REFMAP_TEST + +#include + +#ifndef FLATCC_REFMAP_H +#include "flatcc/flatcc_refmap.h" +#endif + +#define test(x) do { if (!(x)) { fprintf(stderr, "%02d: refmap test failed\n", __LINE__); exit(-1); } } while (0) +#define test_start() fprintf(stderr, "starting refmap test ...\n") +#define test_ok() fprintf(stderr, "refmap test succeeded\n") + +int main() +{ + int i; + int data[1000]; + int a = 1; + int b = 2; + int c = 3; + flatcc_refmap_t refmap; + + flatcc_refmap_init(&refmap); + + test(flatcc_refmap_find(&refmap, &a) == flatcc_refmap_not_found); + test(flatcc_refmap_find(&refmap, &b) == flatcc_refmap_not_found); + test(flatcc_refmap_find(&refmap, &c) == flatcc_refmap_not_found); + test(flatcc_refmap_find(&refmap, 0) == flatcc_refmap_not_found); + test(flatcc_refmap_find(&refmap, &a) == 0); + + test(flatcc_refmap_insert(&refmap, &a, 42) == 42); + test(flatcc_refmap_find(&refmap, &a) == 42); + test(flatcc_refmap_find(&refmap, &b) == flatcc_refmap_not_found); + test(flatcc_refmap_find(&refmap, &c) == flatcc_refmap_not_found); + test(flatcc_refmap_insert(&refmap, &a, 42) == 42); + test(flatcc_refmap_find(&refmap, &a) == 42); + test(refmap.count == 1); + test(flatcc_refmap_insert(&refmap, &a, 43) == 43); + test(flatcc_refmap_find(&refmap, &a) == 43); + test(refmap.count == 1); + test(flatcc_refmap_insert(&refmap, &b, -10) == -10); + test(flatcc_refmap_insert(&refmap, &c, 100) == 100); + test(refmap.count == 3); + test(flatcc_refmap_find(&refmap, &a) == 43); + test(flatcc_refmap_find(&refmap, &b) == -10); + test(flatcc_refmap_find(&refmap, &c) == 100); + + test(flatcc_refmap_insert(&refmap, 0, 1000) == 1000); + test(flatcc_refmap_find(&refmap, 0) == 0); + test(refmap.count == 3); + + test(flatcc_refmap_insert(&refmap, &b, 0) == 0); + test(flatcc_refmap_find(&refmap, &b) == 0); + test(refmap.count == 3); + + flatcc_refmap_reset(&refmap); + test(refmap.count == 0); + test(refmap.buckets > 0); + for (i = 0; i < 1000; ++i) { + test(flatcc_refmap_insert(&refmap, data + i, i + 42) == i + 42); + } + test(refmap.count == 1000); + for (i = 0; i < 1000; ++i) { + test(flatcc_refmap_find(&refmap, data + i) == i + 42); + } + flatcc_refmap_clear(&refmap); + test(refmap.count == 0); + test(refmap.buckets == 0); + test_ok(); + return 0; +} + +#endif /* FLATCC_REFMAP_TEST */ diff --git a/third_party/nanoarrow/src/nanoarrow.c b/third_party/nanoarrow/src/nanoarrow.c new file mode 100644 index 0000000..da621c9 --- /dev/null +++ b/third_party/nanoarrow/src/nanoarrow.c @@ -0,0 +1,4117 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include +#include +#include +#include + +#include "nanoarrow/nanoarrow.h" + +const char* ArrowNanoarrowVersion(void) { return NANOARROW_VERSION; } + +int ArrowNanoarrowVersionInt(void) { return NANOARROW_VERSION_INT; } + +ArrowErrorCode ArrowErrorSet(struct ArrowError* error, const char* fmt, ...) { + if (error == NULL) { + return NANOARROW_OK; + } + + memset(error->message, 0, sizeof(error->message)); + + va_list args; + va_start(args, fmt); + int chars_needed = vsnprintf(error->message, sizeof(error->message), fmt, args); + va_end(args); + + if (chars_needed < 0) { + return EINVAL; + } else if (((size_t)chars_needed) >= sizeof(error->message)) { + return ERANGE; + } else { + return NANOARROW_OK; + } +} + +void ArrowLayoutInit(struct ArrowLayout* layout, enum ArrowType storage_type) { + layout->buffer_type[0] = NANOARROW_BUFFER_TYPE_VALIDITY; + layout->buffer_data_type[0] = NANOARROW_TYPE_BOOL; + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[1] = storage_type; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_NONE; + layout->buffer_data_type[2] = NANOARROW_TYPE_UNINITIALIZED; + + layout->element_size_bits[0] = 1; + layout->element_size_bits[1] = 0; + layout->element_size_bits[2] = 0; + + layout->child_size_elements = 0; + + switch (storage_type) { + case NANOARROW_TYPE_UNINITIALIZED: + case NANOARROW_TYPE_NA: + case NANOARROW_TYPE_RUN_END_ENCODED: + layout->buffer_type[0] = NANOARROW_BUFFER_TYPE_NONE; + layout->buffer_data_type[0] = NANOARROW_TYPE_UNINITIALIZED; + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_NONE; + layout->buffer_data_type[1] = NANOARROW_TYPE_UNINITIALIZED; + layout->element_size_bits[0] = 0; + break; + + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_MAP: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT32; + layout->element_size_bits[1] = 32; + break; + + case NANOARROW_TYPE_LARGE_LIST: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT64; + layout->element_size_bits[1] = 64; + break; + + case NANOARROW_TYPE_STRUCT: + case NANOARROW_TYPE_FIXED_SIZE_LIST: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_NONE; + layout->buffer_data_type[1] = NANOARROW_TYPE_UNINITIALIZED; + break; + + case NANOARROW_TYPE_BOOL: + layout->element_size_bits[1] = 1; + break; + + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_INT8: + layout->element_size_bits[1] = 8; + break; + + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_HALF_FLOAT: + layout->element_size_bits[1] = 16; + break; + + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_FLOAT: + case NANOARROW_TYPE_DECIMAL32: + layout->element_size_bits[1] = 32; + break; + case NANOARROW_TYPE_INTERVAL_MONTHS: + layout->buffer_data_type[1] = NANOARROW_TYPE_INT32; + layout->element_size_bits[1] = 32; + break; + + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_INT64: + case NANOARROW_TYPE_DOUBLE: + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + case NANOARROW_TYPE_DECIMAL64: + layout->element_size_bits[1] = 64; + break; + + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + layout->element_size_bits[1] = 128; + break; + + case NANOARROW_TYPE_DECIMAL256: + layout->element_size_bits[1] = 256; + break; + + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + layout->buffer_data_type[1] = NANOARROW_TYPE_BINARY; + break; + + case NANOARROW_TYPE_DENSE_UNION: + layout->buffer_type[0] = NANOARROW_BUFFER_TYPE_TYPE_ID; + layout->buffer_data_type[0] = NANOARROW_TYPE_INT8; + layout->element_size_bits[0] = 8; + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_UNION_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT32; + layout->element_size_bits[1] = 32; + break; + + case NANOARROW_TYPE_SPARSE_UNION: + layout->buffer_type[0] = NANOARROW_BUFFER_TYPE_TYPE_ID; + layout->buffer_data_type[0] = NANOARROW_TYPE_INT8; + layout->element_size_bits[0] = 8; + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_NONE; + layout->buffer_data_type[1] = NANOARROW_TYPE_UNINITIALIZED; + break; + + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT32; + layout->element_size_bits[1] = 32; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[2] = storage_type; + break; + + case NANOARROW_TYPE_LARGE_STRING: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT64; + layout->element_size_bits[1] = 64; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[2] = NANOARROW_TYPE_STRING; + break; + case NANOARROW_TYPE_LARGE_BINARY: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT64; + layout->element_size_bits[1] = 64; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[2] = NANOARROW_TYPE_BINARY; + break; + + case NANOARROW_TYPE_BINARY_VIEW: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[1] = NANOARROW_TYPE_BINARY_VIEW; + layout->element_size_bits[1] = 128; + break; + case NANOARROW_TYPE_STRING_VIEW: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_DATA; + layout->buffer_data_type[1] = NANOARROW_TYPE_STRING_VIEW; + layout->element_size_bits[1] = 128; + break; + + case NANOARROW_TYPE_LIST_VIEW: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_VIEW_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT32; + layout->element_size_bits[1] = 32; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_SIZE; + layout->buffer_data_type[2] = NANOARROW_TYPE_INT32; + layout->element_size_bits[2] = 32; + break; + case NANOARROW_TYPE_LARGE_LIST_VIEW: + layout->buffer_type[1] = NANOARROW_BUFFER_TYPE_VIEW_OFFSET; + layout->buffer_data_type[1] = NANOARROW_TYPE_INT64; + layout->element_size_bits[1] = 64; + layout->buffer_type[2] = NANOARROW_BUFFER_TYPE_SIZE; + layout->buffer_data_type[2] = NANOARROW_TYPE_INT64; + layout->element_size_bits[2] = 64; + break; + + default: + break; + } +} + +void* ArrowMalloc(int64_t size) { return malloc(size); } + +void* ArrowRealloc(void* ptr, int64_t size) { return realloc(ptr, size); } + +void ArrowFree(void* ptr) { free(ptr); } + +static uint8_t* ArrowBufferAllocatorMallocReallocate( + struct ArrowBufferAllocator* allocator, uint8_t* ptr, int64_t old_size, + int64_t new_size) { + NANOARROW_UNUSED(allocator); + NANOARROW_UNUSED(old_size); + return (uint8_t*)ArrowRealloc(ptr, new_size); +} + +static void ArrowBufferAllocatorMallocFree(struct ArrowBufferAllocator* allocator, + uint8_t* ptr, int64_t size) { + NANOARROW_UNUSED(allocator); + NANOARROW_UNUSED(size); + if (ptr != NULL) { + ArrowFree(ptr); + } +} + +static struct ArrowBufferAllocator ArrowBufferAllocatorMalloc = { + &ArrowBufferAllocatorMallocReallocate, &ArrowBufferAllocatorMallocFree, NULL}; + +struct ArrowBufferAllocator ArrowBufferAllocatorDefault(void) { + return ArrowBufferAllocatorMalloc; +} + +static uint8_t* ArrowBufferDeallocatorReallocate(struct ArrowBufferAllocator* allocator, + uint8_t* ptr, int64_t old_size, + int64_t new_size) { + NANOARROW_UNUSED(new_size); + + // Attempting to reallocate a buffer with a custom deallocator is + // a programming error. In debug mode, crash here. +#if defined(NANOARROW_DEBUG) + NANOARROW_PRINT_AND_DIE(ENOMEM, + "It is an error to reallocate a buffer whose allocator is " + "ArrowBufferDeallocator()"); +#endif + + // In release mode, ensure the the deallocator is called exactly + // once using the pointer it was given and return NULL, which + // will trigger the caller to return ENOMEM. + allocator->free(allocator, ptr, old_size); + *allocator = ArrowBufferAllocatorDefault(); + return NULL; +} + +struct ArrowBufferAllocator ArrowBufferDeallocator( + void (*custom_free)(struct ArrowBufferAllocator* allocator, uint8_t* ptr, + int64_t size), + void* private_data) { + struct ArrowBufferAllocator allocator; + allocator.reallocate = &ArrowBufferDeallocatorReallocate; + allocator.free = custom_free; + allocator.private_data = private_data; + return allocator; +} + +static const int kInt32DecimalDigits = 9; + +static const uint64_t kUInt32PowersOfTen[] = { + 1ULL, 10ULL, 100ULL, 1000ULL, 10000ULL, + 100000ULL, 1000000ULL, 10000000ULL, 100000000ULL, 1000000000ULL}; + +// Adapted from Arrow C++ to use 32-bit words for better C portability +// https://github.com/apache/arrow/blob/cd3321b28b0c9703e5d7105d6146c1270bbadd7f/cpp/src/arrow/util/decimal.cc#L524-L544 +static void ShiftAndAdd(struct ArrowStringView value, uint32_t* out, int64_t out_size) { + // We use strtoll for parsing, which needs input that is null-terminated + char chunk_string[16]; + + for (int64_t posn = 0; posn < value.size_bytes;) { + int64_t remaining = value.size_bytes - posn; + + int64_t group_size; + if (remaining > kInt32DecimalDigits) { + group_size = kInt32DecimalDigits; + } else { + group_size = remaining; + } + + const uint64_t multiple = kUInt32PowersOfTen[group_size]; + + memcpy(chunk_string, value.data + posn, group_size); + chunk_string[group_size] = '\0'; + uint32_t chunk = (uint32_t)strtoll(chunk_string, NULL, 10); + + for (int64_t i = 0; i < out_size; i++) { + uint64_t tmp = out[i]; + tmp *= multiple; + tmp += chunk; + out[i] = (uint32_t)(tmp & 0xFFFFFFFFULL); + chunk = (uint32_t)(tmp >> 32); + } + posn += group_size; + } +} + +ArrowErrorCode ArrowDecimalSetDigits(struct ArrowDecimal* decimal, + struct ArrowStringView value) { + // Check for sign + int is_negative = value.data[0] == '-'; + int has_sign = is_negative || value.data[0] == '+'; + value.data += has_sign; + value.size_bytes -= has_sign; + + // Check all characters are digits that are not the negative sign + for (int64_t i = 0; i < value.size_bytes; i++) { + char c = value.data[i]; + if (c < '0' || c > '9') { + return EINVAL; + } + } + + // Skip over leading 0s + int64_t n_leading_zeroes = 0; + for (int64_t i = 0; i < value.size_bytes; i++) { + if (value.data[i] == '0') { + n_leading_zeroes++; + } else { + break; + } + } + + value.data += n_leading_zeroes; + value.size_bytes -= n_leading_zeroes; + + // Use 32-bit words for portability + uint32_t words32[8]; + memset(words32, 0, sizeof(words32)); + int n_words32 = decimal->n_words > 0 ? decimal->n_words * 2 : 1; + NANOARROW_DCHECK(n_words32 <= 8); + memset(words32, 0, sizeof(words32)); + + ShiftAndAdd(value, words32, n_words32); + + if (_ArrowIsLittleEndian() || n_words32 == 1) { + memcpy(decimal->words, words32, sizeof(uint32_t) * n_words32); + } else { + uint64_t lo; + uint64_t hi; + + for (int i = 0; i < decimal->n_words; i++) { + lo = (uint64_t)words32[i * 2]; + hi = (uint64_t)words32[i * 2 + 1] << 32; + decimal->words[decimal->n_words - i - 1] = lo | hi; + } + } + + if (is_negative) { + ArrowDecimalNegate(decimal); + } + + return NANOARROW_OK; +} + +// Adapted from Arrow C++ for C +// https://github.com/apache/arrow/blob/cd3321b28b0c9703e5d7105d6146c1270bbadd7f/cpp/src/arrow/util/decimal.cc#L365 +ArrowErrorCode ArrowDecimalAppendDigitsToBuffer(const struct ArrowDecimal* decimal, + struct ArrowBuffer* buffer) { + NANOARROW_DCHECK(decimal->n_words == 0 || decimal->n_words == 1 || + decimal->n_words == 2 || decimal->n_words == 4); + + // For the 32-bit case, just use snprintf() + if (decimal->n_words == 0) { + int32_t value; + memcpy(&value, decimal->words, sizeof(int32_t)); + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, 16)); + int n_chars = snprintf((char*)buffer->data + buffer->size_bytes, + (buffer->capacity_bytes - buffer->size_bytes), "%d", value); + if (n_chars <= 0) { + return EINVAL; + } + + buffer->size_bytes += n_chars; + return NANOARROW_OK; + } + + int is_negative = ArrowDecimalSign(decimal) < 0; + + uint64_t words_little_endian[4]; + if (decimal->n_words == 0) { + words_little_endian[0] = 0; + memcpy(words_little_endian, decimal->words, sizeof(uint32_t)); + } else if (decimal->low_word_index == 0) { + memcpy(words_little_endian, decimal->words, decimal->n_words * sizeof(uint64_t)); + } else { + for (int i = 0; i < decimal->n_words; i++) { + words_little_endian[i] = decimal->words[decimal->n_words - i - 1]; + } + } + + // We've already made a copy, so negate that if needed + if (is_negative) { + if (decimal->n_words == 0) { + uint32_t elem = (uint32_t)words_little_endian[0]; + elem = ~elem + 1; + words_little_endian[0] = (int32_t)elem; + } else { + uint64_t carry = 1; + for (int i = 0; i < decimal->n_words; i++) { + uint64_t elem = words_little_endian[i]; + elem = ~elem + carry; + carry &= (elem == 0); + words_little_endian[i] = elem; + } + } + } + + // Find the most significant word that is non-zero + int most_significant_elem_idx = -1; + if (decimal->n_words == 0) { + if (words_little_endian[0] != 0) { + most_significant_elem_idx = 0; + } + } else { + for (int i = decimal->n_words - 1; i >= 0; i--) { + if (words_little_endian[i] != 0) { + most_significant_elem_idx = i; + break; + } + } + } + + // If they are all zero, the output is just '0' + if (most_significant_elem_idx == -1) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt8(buffer, '0')); + return NANOARROW_OK; + } + + // Define segments such that each segment represents 9 digits with the + // least significant group of 9 digits first. For example, if the input represents + // 9876543210123456789, then segments will be [123456789, 876543210, 9]. + // We handle at most a signed 256 bit integer, whose maximum value occupies 77 + // characters. Thus, we need at most 9 segments. + const uint32_t k1e9 = 1000000000U; + int num_segments = 0; + uint32_t segments[9]; + memset(segments, 0, sizeof(segments)); + uint64_t* most_significant_elem = words_little_endian + most_significant_elem_idx; + + do { + // Compute remainder = words_little_endian % 1e9 and words_little_endian = + // words_little_endian / 1e9. + uint32_t remainder = 0; + uint64_t* elem = most_significant_elem; + + do { + // Compute dividend = (remainder << 32) | *elem (a virtual 96-bit integer); + // *elem = dividend / 1e9; + // remainder = dividend % 1e9. + uint32_t hi = (uint32_t)(*elem >> 32); + uint32_t lo = (uint32_t)(*elem & 0xFFFFFFFFULL); + uint64_t dividend_hi = ((uint64_t)(remainder) << 32) | hi; + uint64_t quotient_hi = dividend_hi / k1e9; + remainder = (uint32_t)(dividend_hi % k1e9); + uint64_t dividend_lo = ((uint64_t)(remainder) << 32) | lo; + uint64_t quotient_lo = dividend_lo / k1e9; + remainder = (uint32_t)(dividend_lo % k1e9); + + *elem = (quotient_hi << 32) | quotient_lo; + } while (elem-- != words_little_endian); + + segments[num_segments++] = remainder; + } while (*most_significant_elem != 0 || most_significant_elem-- != words_little_endian); + + // We know our output has no more than 9 digits per segment, plus a negative sign, + // plus any further digits between our output of 9 digits plus enough + // extra characters to ensure that snprintf() with n = 21 (maximum length of %lu + // including a the null terminator) is bounded properly. + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, num_segments * 9 + 1 + 21 - 9)); + if (is_negative) { + buffer->data[buffer->size_bytes++] = '-'; + } + + // The most significant segment should have no leading zeroes + int n_chars = snprintf((char*)buffer->data + buffer->size_bytes, 21, "%lu", + (unsigned long)segments[num_segments - 1]); + + // Ensure that an encoding error from snprintf() does not result + // in an out-of-bounds access. + if (n_chars < 0) { + return ERANGE; + } + + buffer->size_bytes += n_chars; + + // Subsequent output needs to be left-padded with zeroes such that each segment + // takes up exactly 9 digits. + for (int i = num_segments - 2; i >= 0; i--) { + int n_chars = snprintf((char*)buffer->data + buffer->size_bytes, 21, "%09lu", + (unsigned long)segments[i]); + buffer->size_bytes += n_chars; + NANOARROW_DCHECK(buffer->size_bytes <= buffer->capacity_bytes); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowDecimalAppendStringToBuffer(const struct ArrowDecimal* decimal, + struct ArrowBuffer* buffer) { + int64_t buffer_size = buffer->size_bytes; + NANOARROW_RETURN_NOT_OK(ArrowDecimalAppendDigitsToBuffer(decimal, buffer)); + int64_t digits_size = buffer->size_bytes - buffer_size; + + if (decimal->scale <= 0) { + // e.g., digits are -12345 and scale is -2 -> -1234500 + // Just add zeros to the end + for (int i = decimal->scale; i < 0; i++) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt8(buffer, '0')); + } + return NANOARROW_OK; + } + + int is_negative = buffer->data[0] == '-'; + int64_t num_digits = digits_size - is_negative; + if (num_digits <= decimal->scale) { + // e.g., digits are -12345 and scale is 6 -> -0.012345 + // Insert "0." between the (maybe) negative sign and the digits + int64_t num_zeros_after_decimal = decimal->scale - num_digits; + NANOARROW_RETURN_NOT_OK( + ArrowBufferResize(buffer, buffer->size_bytes + num_zeros_after_decimal + 2, 0)); + + uint8_t* digits_start = buffer->data + is_negative; + memmove(digits_start + num_zeros_after_decimal + 2, digits_start, num_digits); + *digits_start++ = '0'; + *digits_start++ = '.'; + for (int i = 0; i < num_zeros_after_decimal; i++) { + *digits_start++ = '0'; + } + + } else { + // e.g., digits are -12345 and scale is 4 -> -1.2345 + // Insert a decimal point before scale digits of output + NANOARROW_RETURN_NOT_OK(ArrowBufferResize(buffer, buffer->size_bytes + 1, 0)); + uint8_t* decimal_point_to_be = buffer->data + buffer->size_bytes - 1 - decimal->scale; + memmove(decimal_point_to_be + 1, decimal_point_to_be, decimal->scale); + *decimal_point_to_be = '.'; + } + + return NANOARROW_OK; +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include +#include +#include + +#include "nanoarrow/nanoarrow.h" + +static void ArrowSchemaReleaseInternal(struct ArrowSchema* schema) { + if (schema->format != NULL) ArrowFree((void*)schema->format); + if (schema->name != NULL) ArrowFree((void*)schema->name); + if (schema->metadata != NULL) ArrowFree((void*)schema->metadata); + + // This object owns the memory for all the children, but those + // children may have been generated elsewhere and might have + // their own release() callback. + if (schema->children != NULL) { + for (int64_t i = 0; i < schema->n_children; i++) { + if (schema->children[i] != NULL) { + if (schema->children[i]->release != NULL) { + ArrowSchemaRelease(schema->children[i]); + } + + ArrowFree(schema->children[i]); + } + } + + ArrowFree(schema->children); + } + + // This object owns the memory for the dictionary but it + // may have been generated somewhere else and have its own + // release() callback. + if (schema->dictionary != NULL) { + if (schema->dictionary->release != NULL) { + ArrowSchemaRelease(schema->dictionary); + } + + ArrowFree(schema->dictionary); + } + + // private data not currently used + if (schema->private_data != NULL) { + ArrowFree(schema->private_data); + } + + schema->release = NULL; +} + +static const char* ArrowSchemaFormatTemplate(enum ArrowType type) { + switch (type) { + case NANOARROW_TYPE_UNINITIALIZED: + return NULL; + case NANOARROW_TYPE_NA: + return "n"; + case NANOARROW_TYPE_BOOL: + return "b"; + + case NANOARROW_TYPE_UINT8: + return "C"; + case NANOARROW_TYPE_INT8: + return "c"; + case NANOARROW_TYPE_UINT16: + return "S"; + case NANOARROW_TYPE_INT16: + return "s"; + case NANOARROW_TYPE_UINT32: + return "I"; + case NANOARROW_TYPE_INT32: + return "i"; + case NANOARROW_TYPE_UINT64: + return "L"; + case NANOARROW_TYPE_INT64: + return "l"; + + case NANOARROW_TYPE_HALF_FLOAT: + return "e"; + case NANOARROW_TYPE_FLOAT: + return "f"; + case NANOARROW_TYPE_DOUBLE: + return "g"; + + case NANOARROW_TYPE_STRING: + return "u"; + case NANOARROW_TYPE_LARGE_STRING: + return "U"; + case NANOARROW_TYPE_STRING_VIEW: + return "vu"; + case NANOARROW_TYPE_BINARY: + return "z"; + case NANOARROW_TYPE_BINARY_VIEW: + return "vz"; + case NANOARROW_TYPE_LARGE_BINARY: + return "Z"; + + case NANOARROW_TYPE_DATE32: + return "tdD"; + case NANOARROW_TYPE_DATE64: + return "tdm"; + case NANOARROW_TYPE_INTERVAL_MONTHS: + return "tiM"; + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + return "tiD"; + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + return "tin"; + + case NANOARROW_TYPE_LIST: + return "+l"; + case NANOARROW_TYPE_LARGE_LIST: + return "+L"; + case NANOARROW_TYPE_LIST_VIEW: + return "+vl"; + case NANOARROW_TYPE_LARGE_LIST_VIEW: + return "+vL"; + case NANOARROW_TYPE_STRUCT: + return "+s"; + case NANOARROW_TYPE_MAP: + return "+m"; + case NANOARROW_TYPE_RUN_END_ENCODED: + return "+r"; + + default: + return NULL; + } +} + +static int ArrowSchemaInitChildrenIfNeeded(struct ArrowSchema* schema, + enum ArrowType type) { + switch (type) { + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_LARGE_LIST: + case NANOARROW_TYPE_FIXED_SIZE_LIST: + case NANOARROW_TYPE_LIST_VIEW: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, 1)); + ArrowSchemaInit(schema->children[0]); + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[0], "item")); + break; + case NANOARROW_TYPE_MAP: + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, 1)); + NANOARROW_RETURN_NOT_OK( + ArrowSchemaInitFromType(schema->children[0], NANOARROW_TYPE_STRUCT)); + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[0], "entries")); + schema->children[0]->flags &= ~ARROW_FLAG_NULLABLE; + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema->children[0], 2)); + ArrowSchemaInit(schema->children[0]->children[0]); + ArrowSchemaInit(schema->children[0]->children[1]); + NANOARROW_RETURN_NOT_OK( + ArrowSchemaSetName(schema->children[0]->children[0], "key")); + schema->children[0]->children[0]->flags &= ~ARROW_FLAG_NULLABLE; + NANOARROW_RETURN_NOT_OK( + ArrowSchemaSetName(schema->children[0]->children[1], "value")); + break; + case NANOARROW_TYPE_RUN_END_ENCODED: + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, 2)); + ArrowSchemaInit(schema->children[0]); + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[0], "run_ends")); + schema->children[0]->flags &= ~ARROW_FLAG_NULLABLE; + ArrowSchemaInit(schema->children[1]); + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[1], "values")); + default: + break; + } + + return NANOARROW_OK; +} + +void ArrowSchemaInit(struct ArrowSchema* schema) { + schema->format = NULL; + schema->name = NULL; + schema->metadata = NULL; + schema->flags = ARROW_FLAG_NULLABLE; + schema->n_children = 0; + schema->children = NULL; + schema->dictionary = NULL; + schema->private_data = NULL; + schema->release = &ArrowSchemaReleaseInternal; +} + +ArrowErrorCode ArrowSchemaSetType(struct ArrowSchema* schema, enum ArrowType type) { + // We don't allocate the dictionary because it has to be nullptr + // for non-dictionary-encoded arrays. + + // Set the format to a valid format string for type + const char* template_format = ArrowSchemaFormatTemplate(type); + + // If type isn't recognized and not explicitly unset + if (template_format == NULL && type != NANOARROW_TYPE_UNINITIALIZED) { + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, template_format)); + + // For types with an umabiguous child structure, allocate children + return ArrowSchemaInitChildrenIfNeeded(schema, type); +} + +ArrowErrorCode ArrowSchemaSetTypeStruct(struct ArrowSchema* schema, int64_t n_children) { + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_STRUCT)); + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, n_children)); + for (int64_t i = 0; i < n_children; i++) { + ArrowSchemaInit(schema->children[i]); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaInitFromType(struct ArrowSchema* schema, enum ArrowType type) { + ArrowSchemaInit(schema); + + int result = ArrowSchemaSetType(schema, type); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema); + return result; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaSetTypeFixedSize(struct ArrowSchema* schema, + enum ArrowType type, int32_t fixed_size) { + if (fixed_size <= 0) { + return EINVAL; + } + + char buffer[64]; + int n_chars; + switch (type) { + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + n_chars = snprintf(buffer, sizeof(buffer), "w:%" PRId32, fixed_size); + break; + case NANOARROW_TYPE_FIXED_SIZE_LIST: + n_chars = snprintf(buffer, sizeof(buffer), "+w:%" PRId32, fixed_size); + break; + default: + return EINVAL; + } + + if (((size_t)n_chars) >= sizeof(buffer) || n_chars < 0) { + return ERANGE; + } + + buffer[n_chars] = '\0'; + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, buffer)); + + if (type == NANOARROW_TYPE_FIXED_SIZE_LIST) { + NANOARROW_RETURN_NOT_OK(ArrowSchemaInitChildrenIfNeeded(schema, type)); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaSetTypeDecimal(struct ArrowSchema* schema, enum ArrowType type, + int32_t decimal_precision, + int32_t decimal_scale) { + if (decimal_precision <= 0) { + return EINVAL; + } + + char buffer[64]; + int n_chars; + switch (type) { + case NANOARROW_TYPE_DECIMAL32: + if (decimal_precision > 9) { + return EINVAL; + } + + n_chars = snprintf(buffer, sizeof(buffer), "d:%d,%d,32", decimal_precision, + decimal_scale); + break; + case NANOARROW_TYPE_DECIMAL64: + if (decimal_precision > 18) { + return EINVAL; + } + + n_chars = snprintf(buffer, sizeof(buffer), "d:%d,%d,64", decimal_precision, + decimal_scale); + break; + case NANOARROW_TYPE_DECIMAL128: + if (decimal_precision > 38) { + return EINVAL; + } + + n_chars = + snprintf(buffer, sizeof(buffer), "d:%d,%d", decimal_precision, decimal_scale); + break; + case NANOARROW_TYPE_DECIMAL256: + if (decimal_precision > 76) { + return EINVAL; + } + + n_chars = snprintf(buffer, sizeof(buffer), "d:%d,%d,256", decimal_precision, + decimal_scale); + break; + default: + return EINVAL; + } + + if (((size_t)n_chars) >= sizeof(buffer) || n_chars < 0) { + return ERANGE; + } + + buffer[n_chars] = '\0'; + return ArrowSchemaSetFormat(schema, buffer); +} + +ArrowErrorCode ArrowSchemaSetTypeRunEndEncoded(struct ArrowSchema* schema, + enum ArrowType run_end_type) { + switch (run_end_type) { + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_INT64: + break; + default: + return EINVAL; + } + + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat( + schema, ArrowSchemaFormatTemplate(NANOARROW_TYPE_RUN_END_ENCODED))); + NANOARROW_RETURN_NOT_OK( + ArrowSchemaInitChildrenIfNeeded(schema, NANOARROW_TYPE_RUN_END_ENCODED)); + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema->children[0], run_end_type)); + NANOARROW_RETURN_NOT_OK( + ArrowSchemaSetType(schema->children[1], NANOARROW_TYPE_UNINITIALIZED)); + + return NANOARROW_OK; +} + +static const char* ArrowTimeUnitFormatString(enum ArrowTimeUnit time_unit) { + switch (time_unit) { + case NANOARROW_TIME_UNIT_SECOND: + return "s"; + case NANOARROW_TIME_UNIT_MILLI: + return "m"; + case NANOARROW_TIME_UNIT_MICRO: + return "u"; + case NANOARROW_TIME_UNIT_NANO: + return "n"; + default: + return NULL; + } +} + +ArrowErrorCode ArrowSchemaSetTypeDateTime(struct ArrowSchema* schema, enum ArrowType type, + enum ArrowTimeUnit time_unit, + const char* timezone) { + const char* time_unit_str = ArrowTimeUnitFormatString(time_unit); + if (time_unit_str == NULL) { + return EINVAL; + } + + char buffer[128]; + int n_chars; + switch (type) { + case NANOARROW_TYPE_TIME32: + if (timezone != NULL) { + return EINVAL; + } + + switch (time_unit) { + case NANOARROW_TIME_UNIT_MICRO: + case NANOARROW_TIME_UNIT_NANO: + return EINVAL; + default: + break; + } + + n_chars = snprintf(buffer, sizeof(buffer), "tt%s", time_unit_str); + break; + case NANOARROW_TYPE_TIME64: + if (timezone != NULL) { + return EINVAL; + } + + switch (time_unit) { + case NANOARROW_TIME_UNIT_SECOND: + case NANOARROW_TIME_UNIT_MILLI: + return EINVAL; + default: + break; + } + + n_chars = snprintf(buffer, sizeof(buffer), "tt%s", time_unit_str); + break; + case NANOARROW_TYPE_TIMESTAMP: + if (timezone == NULL) { + timezone = ""; + } + n_chars = snprintf(buffer, sizeof(buffer), "ts%s:%s", time_unit_str, timezone); + break; + case NANOARROW_TYPE_DURATION: + if (timezone != NULL) { + return EINVAL; + } + n_chars = snprintf(buffer, sizeof(buffer), "tD%s", time_unit_str); + break; + default: + return EINVAL; + } + + if (((size_t)n_chars) >= sizeof(buffer) || n_chars < 0) { + return ERANGE; + } + + buffer[n_chars] = '\0'; + + return ArrowSchemaSetFormat(schema, buffer); +} + +ArrowErrorCode ArrowSchemaSetTypeUnion(struct ArrowSchema* schema, enum ArrowType type, + int64_t n_children) { + if (n_children < 0 || n_children > 127) { + return EINVAL; + } + + // Max valid size would be +ud:0,1,...126 = 401 characters + null terminator + char format_out[512]; + int64_t format_out_size = 512; + memset(format_out, 0, format_out_size); + int n_chars; + char* format_cursor = format_out; + + switch (type) { + case NANOARROW_TYPE_SPARSE_UNION: + n_chars = snprintf(format_cursor, format_out_size, "+us:"); + format_cursor += n_chars; + format_out_size -= n_chars; + break; + case NANOARROW_TYPE_DENSE_UNION: + n_chars = snprintf(format_cursor, format_out_size, "+ud:"); + format_cursor += n_chars; + format_out_size -= n_chars; + break; + default: + return EINVAL; + } + + // Ensure that an encoding error from snprintf() does not result + // in an out-of-bounds access. + if (n_chars < 0) { + return ERANGE; + } + + if (n_children > 0) { + n_chars = snprintf(format_cursor, format_out_size, "0"); + format_cursor += n_chars; + format_out_size -= n_chars; + + for (int64_t i = 1; i < n_children; i++) { + n_chars = snprintf(format_cursor, format_out_size, ",%" PRId64, i); + format_cursor += n_chars; + format_out_size -= n_chars; + } + } + + // Ensure that an encoding error from snprintf() does not result + // in an out-of-bounds access. + if (n_chars < 0) { + return ERANGE; + } + + NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, format_out)); + + NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, n_children)); + for (int64_t i = 0; i < n_children; i++) { + ArrowSchemaInit(schema->children[i]); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaSetFormat(struct ArrowSchema* schema, const char* format) { + if (schema->format != NULL) { + ArrowFree((void*)schema->format); + } + + if (format != NULL) { + size_t format_size = strlen(format) + 1; + schema->format = (const char*)ArrowMalloc(format_size); + if (schema->format == NULL) { + return ENOMEM; + } + + memcpy((void*)schema->format, format, format_size); + } else { + schema->format = NULL; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaSetName(struct ArrowSchema* schema, const char* name) { + if (schema->name != NULL) { + ArrowFree((void*)schema->name); + } + + if (name != NULL) { + size_t name_size = strlen(name) + 1; + schema->name = (const char*)ArrowMalloc(name_size); + if (schema->name == NULL) { + return ENOMEM; + } + + memcpy((void*)schema->name, name, name_size); + } else { + schema->name = NULL; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaSetMetadata(struct ArrowSchema* schema, const char* metadata) { + if (schema->metadata != NULL) { + ArrowFree((void*)schema->metadata); + } + + if (metadata != NULL) { + size_t metadata_size = ArrowMetadataSizeOf(metadata); + schema->metadata = (const char*)ArrowMalloc(metadata_size); + if (schema->metadata == NULL) { + return ENOMEM; + } + + memcpy((void*)schema->metadata, metadata, metadata_size); + } else { + schema->metadata = NULL; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaAllocateChildren(struct ArrowSchema* schema, + int64_t n_children) { + if (schema->children != NULL) { + return EEXIST; + } + + if (n_children > 0) { + schema->children = + (struct ArrowSchema**)ArrowMalloc(n_children * sizeof(struct ArrowSchema*)); + + if (schema->children == NULL) { + return ENOMEM; + } + + schema->n_children = n_children; + + memset(schema->children, 0, n_children * sizeof(struct ArrowSchema*)); + + for (int64_t i = 0; i < n_children; i++) { + schema->children[i] = (struct ArrowSchema*)ArrowMalloc(sizeof(struct ArrowSchema)); + + if (schema->children[i] == NULL) { + return ENOMEM; + } + + schema->children[i]->release = NULL; + } + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaAllocateDictionary(struct ArrowSchema* schema) { + if (schema->dictionary != NULL) { + return EEXIST; + } + + schema->dictionary = (struct ArrowSchema*)ArrowMalloc(sizeof(struct ArrowSchema)); + if (schema->dictionary == NULL) { + return ENOMEM; + } + + schema->dictionary->release = NULL; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaDeepCopy(const struct ArrowSchema* schema, + struct ArrowSchema* schema_out) { + ArrowSchemaInit(schema_out); + + int result = ArrowSchemaSetFormat(schema_out, schema->format); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + + schema_out->flags = schema->flags; + + result = ArrowSchemaSetName(schema_out, schema->name); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + + result = ArrowSchemaSetMetadata(schema_out, schema->metadata); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + + result = ArrowSchemaAllocateChildren(schema_out, schema->n_children); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + + for (int64_t i = 0; i < schema->n_children; i++) { + result = ArrowSchemaDeepCopy(schema->children[i], schema_out->children[i]); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + } + + if (schema->dictionary != NULL) { + result = ArrowSchemaAllocateDictionary(schema_out); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + + result = ArrowSchemaDeepCopy(schema->dictionary, schema_out->dictionary); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(schema_out); + return result; + } + } + + return NANOARROW_OK; +} + +static void ArrowSchemaViewSetPrimitive(struct ArrowSchemaView* schema_view, + enum ArrowType type) { + schema_view->type = type; + schema_view->storage_type = type; +} + +static ArrowErrorCode ArrowSchemaViewParse(struct ArrowSchemaView* schema_view, + const char* format, + const char** format_end_out, + struct ArrowError* error) { + *format_end_out = format; + + // needed for decimal parsing + const char* parse_start; + char* parse_end; + + switch (format[0]) { + case 'n': + schema_view->type = NANOARROW_TYPE_NA; + schema_view->storage_type = NANOARROW_TYPE_NA; + *format_end_out = format + 1; + return NANOARROW_OK; + case 'b': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_BOOL); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'c': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT8); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'C': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_UINT8); + *format_end_out = format + 1; + return NANOARROW_OK; + case 's': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT16); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'S': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_UINT16); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'i': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT32); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'I': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_UINT32); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'l': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'L': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_UINT64); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'e': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_HALF_FLOAT); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'f': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_FLOAT); + *format_end_out = format + 1; + return NANOARROW_OK; + case 'g': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_DOUBLE); + *format_end_out = format + 1; + return NANOARROW_OK; + + // decimal + case 'd': + if (format[1] != ':' || format[2] == '\0') { + ArrowErrorSet(error, "Expected ':precision,scale[,bitwidth]' following 'd'"); + return EINVAL; + } + + parse_start = format + 2; + schema_view->decimal_precision = (int32_t)strtol(parse_start, &parse_end, 10); + if (parse_end == parse_start || parse_end[0] != ',') { + ArrowErrorSet(error, "Expected 'precision,scale[,bitwidth]' following 'd:'"); + return EINVAL; + } + + parse_start = parse_end + 1; + schema_view->decimal_scale = (int32_t)strtol(parse_start, &parse_end, 10); + if (parse_end == parse_start) { + ArrowErrorSet(error, "Expected 'scale[,bitwidth]' following 'd:precision,'"); + return EINVAL; + } else if (parse_end[0] != ',') { + schema_view->decimal_bitwidth = 128; + } else { + parse_start = parse_end + 1; + schema_view->decimal_bitwidth = (int32_t)strtol(parse_start, &parse_end, 10); + if (parse_start == parse_end) { + ArrowErrorSet(error, "Expected precision following 'd:precision,scale,'"); + return EINVAL; + } + } + + *format_end_out = parse_end; + + switch (schema_view->decimal_bitwidth) { + case 32: + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_DECIMAL32); + return NANOARROW_OK; + case 64: + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_DECIMAL64); + return NANOARROW_OK; + case 128: + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_DECIMAL128); + return NANOARROW_OK; + case 256: + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_DECIMAL256); + return NANOARROW_OK; + default: + ArrowErrorSet(error, + "Expected decimal bitwidth of 128 or 256 but found %" PRId32, + schema_view->decimal_bitwidth); + return EINVAL; + } + + // validity + data + case 'w': + schema_view->type = NANOARROW_TYPE_FIXED_SIZE_BINARY; + schema_view->storage_type = NANOARROW_TYPE_FIXED_SIZE_BINARY; + if (format[1] != ':' || format[2] == '\0') { + ArrowErrorSet(error, "Expected ':' following 'w'"); + return EINVAL; + } + + schema_view->fixed_size = (int32_t)strtol(format + 2, (char**)format_end_out, 10); + return NANOARROW_OK; + + // validity + offset + data + case 'z': + schema_view->type = NANOARROW_TYPE_BINARY; + schema_view->storage_type = NANOARROW_TYPE_BINARY; + *format_end_out = format + 1; + return NANOARROW_OK; + case 'u': + schema_view->type = NANOARROW_TYPE_STRING; + schema_view->storage_type = NANOARROW_TYPE_STRING; + *format_end_out = format + 1; + return NANOARROW_OK; + + // validity + large_offset + data + case 'Z': + schema_view->type = NANOARROW_TYPE_LARGE_BINARY; + schema_view->storage_type = NANOARROW_TYPE_LARGE_BINARY; + *format_end_out = format + 1; + return NANOARROW_OK; + case 'U': + schema_view->type = NANOARROW_TYPE_LARGE_STRING; + schema_view->storage_type = NANOARROW_TYPE_LARGE_STRING; + *format_end_out = format + 1; + return NANOARROW_OK; + + // nested types + case '+': + switch (format[1]) { + // list has validity + offset or offset + case 'l': + schema_view->storage_type = NANOARROW_TYPE_LIST; + schema_view->type = NANOARROW_TYPE_LIST; + *format_end_out = format + 2; + return NANOARROW_OK; + + // large list has validity + large_offset or large_offset + case 'L': + schema_view->storage_type = NANOARROW_TYPE_LARGE_LIST; + schema_view->type = NANOARROW_TYPE_LARGE_LIST; + *format_end_out = format + 2; + return NANOARROW_OK; + + // run end encoded has no buffer at all + case 'r': + schema_view->storage_type = NANOARROW_TYPE_RUN_END_ENCODED; + schema_view->type = NANOARROW_TYPE_RUN_END_ENCODED; + *format_end_out = format + 2; + return NANOARROW_OK; + + // just validity buffer + case 'w': + if (format[2] != ':' || format[3] == '\0') { + ArrowErrorSet(error, "Expected ':' following '+w'"); + return EINVAL; + } + + schema_view->storage_type = NANOARROW_TYPE_FIXED_SIZE_LIST; + schema_view->type = NANOARROW_TYPE_FIXED_SIZE_LIST; + schema_view->fixed_size = + (int32_t)strtol(format + 3, (char**)format_end_out, 10); + return NANOARROW_OK; + case 's': + schema_view->storage_type = NANOARROW_TYPE_STRUCT; + schema_view->type = NANOARROW_TYPE_STRUCT; + *format_end_out = format + 2; + return NANOARROW_OK; + case 'm': + schema_view->storage_type = NANOARROW_TYPE_MAP; + schema_view->type = NANOARROW_TYPE_MAP; + *format_end_out = format + 2; + return NANOARROW_OK; + + // unions + case 'u': + switch (format[2]) { + case 'd': + schema_view->storage_type = NANOARROW_TYPE_DENSE_UNION; + schema_view->type = NANOARROW_TYPE_DENSE_UNION; + break; + case 's': + schema_view->storage_type = NANOARROW_TYPE_SPARSE_UNION; + schema_view->type = NANOARROW_TYPE_SPARSE_UNION; + break; + default: + ArrowErrorSet(error, + "Expected union format string +us: or " + "+ud: but found '%s'", + format); + return EINVAL; + } + + if (format[3] == ':') { + schema_view->union_type_ids = format + 4; + int64_t n_type_ids = + _ArrowParseUnionTypeIds(schema_view->union_type_ids, NULL); + if (n_type_ids != schema_view->schema->n_children) { + ArrowErrorSet(error, + "Expected union type_ids parameter to be a comma-separated " + "list of %" PRId64 " values between 0 and 127 but found '%s'", + schema_view->schema->n_children, schema_view->union_type_ids); + return EINVAL; + } + *format_end_out = format + strlen(format); + return NANOARROW_OK; + } else { + ArrowErrorSet(error, + "Expected union format string +us: or +ud: " + "but found '%s'", + format); + return EINVAL; + } + + // views + case 'v': + switch (format[2]) { + case 'l': + schema_view->storage_type = NANOARROW_TYPE_LIST_VIEW; + schema_view->type = NANOARROW_TYPE_LIST_VIEW; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'L': + schema_view->storage_type = NANOARROW_TYPE_LARGE_LIST_VIEW; + schema_view->type = NANOARROW_TYPE_LARGE_LIST_VIEW; + *format_end_out = format + 3; + return NANOARROW_OK; + default: + ArrowErrorSet( + error, "Expected view format string +vl or +vL but found '%s'", format); + return EINVAL; + } + default: + ArrowErrorSet(error, "Expected nested type format string but found '%s'", + format); + return EINVAL; + } + + // date/time types + case 't': + switch (format[1]) { + // date + case 'd': + switch (format[2]) { + case 'D': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT32); + schema_view->type = NANOARROW_TYPE_DATE32; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'm': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_DATE64; + *format_end_out = format + 3; + return NANOARROW_OK; + default: + ArrowErrorSet(error, "Expected 'D' or 'm' following 'td' but found '%s'", + format + 2); + return EINVAL; + } + + // time of day + case 't': + switch (format[2]) { + case 's': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT32); + schema_view->type = NANOARROW_TYPE_TIME32; + schema_view->time_unit = NANOARROW_TIME_UNIT_SECOND; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'm': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT32); + schema_view->type = NANOARROW_TYPE_TIME32; + schema_view->time_unit = NANOARROW_TIME_UNIT_MILLI; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'u': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIME64; + schema_view->time_unit = NANOARROW_TIME_UNIT_MICRO; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'n': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIME64; + schema_view->time_unit = NANOARROW_TIME_UNIT_NANO; + *format_end_out = format + 3; + return NANOARROW_OK; + default: + ArrowErrorSet( + error, "Expected 's', 'm', 'u', or 'n' following 'tt' but found '%s'", + format + 2); + return EINVAL; + } + + // timestamp + case 's': + switch (format[2]) { + case 's': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIMESTAMP; + schema_view->time_unit = NANOARROW_TIME_UNIT_SECOND; + break; + case 'm': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIMESTAMP; + schema_view->time_unit = NANOARROW_TIME_UNIT_MILLI; + break; + case 'u': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIMESTAMP; + schema_view->time_unit = NANOARROW_TIME_UNIT_MICRO; + break; + case 'n': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_TIMESTAMP; + schema_view->time_unit = NANOARROW_TIME_UNIT_NANO; + break; + default: + ArrowErrorSet( + error, "Expected 's', 'm', 'u', or 'n' following 'ts' but found '%s'", + format + 2); + return EINVAL; + } + + if (format[3] != ':') { + ArrowErrorSet(error, "Expected ':' following '%.3s' but found '%s'", format, + format + 3); + return EINVAL; + } + + schema_view->timezone = format + 4; + *format_end_out = format + strlen(format); + return NANOARROW_OK; + + // duration + case 'D': + switch (format[2]) { + case 's': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_DURATION; + schema_view->time_unit = NANOARROW_TIME_UNIT_SECOND; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'm': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_DURATION; + schema_view->time_unit = NANOARROW_TIME_UNIT_MILLI; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'u': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_DURATION; + schema_view->time_unit = NANOARROW_TIME_UNIT_MICRO; + *format_end_out = format + 3; + return NANOARROW_OK; + case 'n': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INT64); + schema_view->type = NANOARROW_TYPE_DURATION; + schema_view->time_unit = NANOARROW_TIME_UNIT_NANO; + *format_end_out = format + 3; + return NANOARROW_OK; + default: + ArrowErrorSet(error, + "Expected 's', 'm', u', or 'n' following 'tD' but found '%s'", + format + 2); + return EINVAL; + } + + // interval + case 'i': + switch (format[2]) { + case 'M': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INTERVAL_MONTHS); + *format_end_out = format + 3; + return NANOARROW_OK; + case 'D': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_INTERVAL_DAY_TIME); + *format_end_out = format + 3; + return NANOARROW_OK; + case 'n': + ArrowSchemaViewSetPrimitive(schema_view, + NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO); + *format_end_out = format + 3; + return NANOARROW_OK; + default: + ArrowErrorSet(error, + "Expected 'M', 'D', or 'n' following 'ti' but found '%s'", + format + 2); + return EINVAL; + } + + default: + ArrowErrorSet( + error, "Expected 'd', 't', 's', 'D', or 'i' following 't' but found '%s'", + format + 1); + return EINVAL; + } + + // view types + case 'v': { + switch (format[1]) { + case 'u': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_STRING_VIEW); + *format_end_out = format + 2; + return NANOARROW_OK; + case 'z': + ArrowSchemaViewSetPrimitive(schema_view, NANOARROW_TYPE_BINARY_VIEW); + *format_end_out = format + 2; + return NANOARROW_OK; + default: + ArrowErrorSet(error, "Expected 'u', or 'z' following 'v' but found '%s'", + format + 1); + return EINVAL; + } + } + + default: + ArrowErrorSet(error, "Unknown format: '%s'", format); + return EINVAL; + } +} + +static ArrowErrorCode ArrowSchemaViewValidateNChildren( + struct ArrowSchemaView* schema_view, int64_t n_children, struct ArrowError* error) { + if (n_children != -1 && schema_view->schema->n_children != n_children) { + ArrowErrorSet( + error, "Expected schema with %" PRId64 " children but found %" PRId64 " children", + n_children, schema_view->schema->n_children); + return EINVAL; + } + + // Don't do a full validation of children but do check that they won't + // segfault if inspected + struct ArrowSchema* child; + for (int64_t i = 0; i < schema_view->schema->n_children; i++) { + child = schema_view->schema->children[i]; + if (child == NULL) { + ArrowErrorSet( + error, "Expected valid schema at schema->children[%" PRId64 "] but found NULL", + i); + return EINVAL; + } else if (child->release == NULL) { + ArrowErrorSet(error, + "Expected valid schema at schema->children[%" PRId64 + "] but found a released schema", + i); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowSchemaViewValidateUnion(struct ArrowSchemaView* schema_view, + struct ArrowError* error) { + return ArrowSchemaViewValidateNChildren(schema_view, -1, error); +} + +static ArrowErrorCode ArrowSchemaViewValidateMap(struct ArrowSchemaView* schema_view, + struct ArrowError* error) { + NANOARROW_RETURN_NOT_OK(ArrowSchemaViewValidateNChildren(schema_view, 1, error)); + + if (schema_view->schema->children[0]->n_children != 2) { + ArrowErrorSet(error, + "Expected child of map type to have 2 children but found %" PRId64, + schema_view->schema->children[0]->n_children); + return EINVAL; + } + + if (strcmp(schema_view->schema->children[0]->format, "+s") != 0) { + ArrowErrorSet(error, "Expected format of child of map type to be '+s' but found '%s'", + schema_view->schema->children[0]->format); + return EINVAL; + } + + if (schema_view->schema->children[0]->flags & ARROW_FLAG_NULLABLE) { + ArrowErrorSet(error, + "Expected child of map type to be non-nullable but was nullable"); + return EINVAL; + } + + if (schema_view->schema->children[0]->children[0]->flags & ARROW_FLAG_NULLABLE) { + ArrowErrorSet(error, "Expected key of map type to be non-nullable but was nullable"); + return EINVAL; + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowSchemaViewValidateDictionary( + struct ArrowSchemaView* schema_view, struct ArrowError* error) { + // check for valid index type + switch (schema_view->storage_type) { + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_INT8: + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_INT64: + break; + default: + ArrowErrorSet( + error, + "Expected dictionary schema index type to be an integral type but found '%s'", + schema_view->schema->format); + return EINVAL; + } + + struct ArrowSchemaView dictionary_schema_view; + return ArrowSchemaViewInit(&dictionary_schema_view, schema_view->schema->dictionary, + error); +} + +static ArrowErrorCode ArrowSchemaViewValidate(struct ArrowSchemaView* schema_view, + enum ArrowType type, + struct ArrowError* error) { + switch (type) { + case NANOARROW_TYPE_NA: + case NANOARROW_TYPE_BOOL: + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_INT8: + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_INT64: + case NANOARROW_TYPE_HALF_FLOAT: + case NANOARROW_TYPE_FLOAT: + case NANOARROW_TYPE_DOUBLE: + case NANOARROW_TYPE_DECIMAL32: + case NANOARROW_TYPE_DECIMAL64: + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_DECIMAL256: + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_BINARY: + case NANOARROW_TYPE_LARGE_BINARY: + case NANOARROW_TYPE_DATE32: + case NANOARROW_TYPE_DATE64: + case NANOARROW_TYPE_INTERVAL_MONTHS: + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + case NANOARROW_TYPE_TIMESTAMP: + case NANOARROW_TYPE_TIME32: + case NANOARROW_TYPE_TIME64: + case NANOARROW_TYPE_DURATION: + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + return ArrowSchemaViewValidateNChildren(schema_view, 0, error); + + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + if (schema_view->fixed_size <= 0) { + ArrowErrorSet(error, "Expected size > 0 for fixed size binary but found size %d", + schema_view->fixed_size); + return EINVAL; + } + return ArrowSchemaViewValidateNChildren(schema_view, 0, error); + + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_LIST_VIEW: + case NANOARROW_TYPE_LARGE_LIST: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + case NANOARROW_TYPE_FIXED_SIZE_LIST: + return ArrowSchemaViewValidateNChildren(schema_view, 1, error); + + case NANOARROW_TYPE_RUN_END_ENCODED: + return ArrowSchemaViewValidateNChildren(schema_view, 2, error); + + case NANOARROW_TYPE_STRUCT: + return ArrowSchemaViewValidateNChildren(schema_view, -1, error); + + case NANOARROW_TYPE_SPARSE_UNION: + case NANOARROW_TYPE_DENSE_UNION: + return ArrowSchemaViewValidateUnion(schema_view, error); + + case NANOARROW_TYPE_MAP: + return ArrowSchemaViewValidateMap(schema_view, error); + + case NANOARROW_TYPE_DICTIONARY: + return ArrowSchemaViewValidateDictionary(schema_view, error); + + default: + ArrowErrorSet(error, "Expected a valid enum ArrowType value but found %d", + schema_view->type); + return EINVAL; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowSchemaViewInit(struct ArrowSchemaView* schema_view, + const struct ArrowSchema* schema, + struct ArrowError* error) { + if (schema == NULL) { + ArrowErrorSet(error, "Expected non-NULL schema"); + return EINVAL; + } + + if (schema->release == NULL) { + ArrowErrorSet(error, "Expected non-released schema"); + return EINVAL; + } + + schema_view->schema = schema; + + const char* format = schema->format; + if (format == NULL) { + ArrowErrorSet( + error, + "Error parsing schema->format: Expected a null-terminated string but found NULL"); + return EINVAL; + } + + size_t format_len = strlen(format); + if (format_len == 0) { + ArrowErrorSet(error, "Error parsing schema->format: Expected a string with size > 0"); + return EINVAL; + } + + const char* format_end_out; + int result = ArrowSchemaViewParse(schema_view, format, &format_end_out, error); + + if (result != NANOARROW_OK) { + if (error != NULL) { + char child_error[1024]; + memcpy(child_error, ArrowErrorMessage(error), 1024); + ArrowErrorSet(error, "Error parsing schema->format: %s", child_error); + } + + return result; + } + + if ((format + format_len) != format_end_out) { + ArrowErrorSet(error, "Error parsing schema->format '%s': parsed %d/%zu characters", + format, (int)(format_end_out - format), format_len); + return EINVAL; + } + + if (schema->dictionary != NULL) { + schema_view->type = NANOARROW_TYPE_DICTIONARY; + } + + NANOARROW_RETURN_NOT_OK( + ArrowSchemaViewValidate(schema_view, schema_view->storage_type, error)); + + if (schema_view->storage_type != schema_view->type) { + NANOARROW_RETURN_NOT_OK( + ArrowSchemaViewValidate(schema_view, schema_view->type, error)); + } + + int64_t unknown_flags = schema->flags & ~NANOARROW_FLAG_ALL_SUPPORTED; + if (unknown_flags != 0) { + ArrowErrorSet(error, "Unknown ArrowSchema flag"); + return EINVAL; + } + + if (schema->flags & ARROW_FLAG_DICTIONARY_ORDERED && + schema_view->type != NANOARROW_TYPE_DICTIONARY) { + ArrowErrorSet(error, + "ARROW_FLAG_DICTIONARY_ORDERED is only relevant for dictionaries"); + return EINVAL; + } + + if (schema->flags & ARROW_FLAG_MAP_KEYS_SORTED && + schema_view->type != NANOARROW_TYPE_MAP) { + ArrowErrorSet(error, "ARROW_FLAG_MAP_KEYS_SORTED is only relevant for a map type"); + return EINVAL; + } + + ArrowLayoutInit(&schema_view->layout, schema_view->storage_type); + if (schema_view->storage_type == NANOARROW_TYPE_FIXED_SIZE_BINARY) { + schema_view->layout.element_size_bits[1] = (int64_t)schema_view->fixed_size * 8; + } else if (schema_view->storage_type == NANOARROW_TYPE_FIXED_SIZE_LIST) { + schema_view->layout.child_size_elements = schema_view->fixed_size; + } + + schema_view->extension_name = ArrowCharView(NULL); + schema_view->extension_metadata = ArrowCharView(NULL); + NANOARROW_RETURN_NOT_OK(ArrowMetadataGetValue(schema->metadata, + ArrowCharView("ARROW:extension:name"), + &schema_view->extension_name)); + NANOARROW_RETURN_NOT_OK(ArrowMetadataGetValue(schema->metadata, + ArrowCharView("ARROW:extension:metadata"), + &schema_view->extension_metadata)); + + return NANOARROW_OK; +} + +static int64_t ArrowSchemaTypeToStringInternal(struct ArrowSchemaView* schema_view, + char* out, int64_t n) { + const char* type_string = ArrowTypeString(schema_view->type); + switch (schema_view->type) { + case NANOARROW_TYPE_DECIMAL32: + case NANOARROW_TYPE_DECIMAL64: + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_DECIMAL256: + return snprintf(out, n, "%s(%" PRId32 ", %" PRId32 ")", type_string, + schema_view->decimal_precision, schema_view->decimal_scale); + case NANOARROW_TYPE_TIMESTAMP: + return snprintf(out, n, "%s('%s', '%s')", type_string, + ArrowTimeUnitString(schema_view->time_unit), schema_view->timezone); + case NANOARROW_TYPE_TIME32: + case NANOARROW_TYPE_TIME64: + case NANOARROW_TYPE_DURATION: + return snprintf(out, n, "%s('%s')", type_string, + ArrowTimeUnitString(schema_view->time_unit)); + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + case NANOARROW_TYPE_FIXED_SIZE_LIST: + return snprintf(out, n, "%s(%" PRId32 ")", type_string, schema_view->fixed_size); + case NANOARROW_TYPE_SPARSE_UNION: + case NANOARROW_TYPE_DENSE_UNION: + return snprintf(out, n, "%s([%s])", type_string, schema_view->union_type_ids); + default: + return snprintf(out, n, "%s", type_string); + } +} + +// Helper for bookkeeping to emulate sprintf()-like behaviour spread +// among multiple sprintf calls. +static inline void ArrowToStringLogChars(char** out, int64_t n_chars_last, + int64_t* n_remaining, int64_t* n_chars) { + // In the unlikely snprintf() returning a negative value (encoding error), + // ensure the result won't cause an out-of-bounds access. + if (n_chars_last < 0) { + n_chars_last = 0; + } + + *n_chars += n_chars_last; + *n_remaining -= n_chars_last; + + // n_remaining is never less than 0 + if (*n_remaining < 0) { + *n_remaining = 0; + } + + // Can't do math on a NULL pointer + if (*out != NULL) { + *out += n_chars_last; + } +} + +int64_t ArrowSchemaToString(const struct ArrowSchema* schema, char* out, int64_t n, + char recursive) { + if (schema == NULL) { + return snprintf(out, n, "[invalid: pointer is null]"); + } + + if (schema->release == NULL) { + return snprintf(out, n, "[invalid: schema is released]"); + } + + struct ArrowSchemaView schema_view; + struct ArrowError error; + + if (ArrowSchemaViewInit(&schema_view, schema, &error) != NANOARROW_OK) { + return snprintf(out, n, "[invalid: %s]", ArrowErrorMessage(&error)); + } + + // Extension type and dictionary should include both the top-level type + // and the storage type. + int is_extension = schema_view.extension_name.size_bytes > 0; + int is_dictionary = schema->dictionary != NULL; + int64_t n_chars = 0; + int64_t n_chars_last = 0; + + // Uncommon but not technically impossible that both are true + if (is_extension && is_dictionary) { + n_chars_last = snprintf( + out, n, "%.*s{dictionary(%s)<", (int)schema_view.extension_name.size_bytes, + schema_view.extension_name.data, ArrowTypeString(schema_view.storage_type)); + } else if (is_extension) { + n_chars_last = snprintf(out, n, "%.*s{", (int)schema_view.extension_name.size_bytes, + schema_view.extension_name.data); + } else if (is_dictionary) { + n_chars_last = + snprintf(out, n, "dictionary(%s)<", ArrowTypeString(schema_view.storage_type)); + } + + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + + if (!is_dictionary) { + n_chars_last = ArrowSchemaTypeToStringInternal(&schema_view, out, n); + } else { + n_chars_last = ArrowSchemaToString(schema->dictionary, out, n, recursive); + } + + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + + if (recursive && schema->format[0] == '+') { + n_chars_last = snprintf(out, n, "<"); + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + + for (int64_t i = 0; i < schema->n_children; i++) { + if (i > 0) { + n_chars_last = snprintf(out, n, ", "); + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + } + + // ArrowSchemaToStringInternal() will validate the child and print the error, + // but we need the name first + if (schema->children[i] != NULL && schema->children[i]->release != NULL && + schema->children[i]->name != NULL) { + n_chars_last = snprintf(out, n, "%s: ", schema->children[i]->name); + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + } + + n_chars_last = ArrowSchemaToString(schema->children[i], out, n, recursive); + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + } + + n_chars_last = snprintf(out, n, ">"); + ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars); + } + + if (is_extension && is_dictionary) { + n_chars += snprintf(out, n, ">}"); + } else if (is_extension) { + n_chars += snprintf(out, n, "}"); + } else if (is_dictionary) { + n_chars += snprintf(out, n, ">"); + } + + // Ensure that we always return a positive result + if (n_chars > 0) { + return n_chars; + } else { + return 0; + } +} + +ArrowErrorCode ArrowMetadataReaderInit(struct ArrowMetadataReader* reader, + const char* metadata) { + reader->metadata = metadata; + + if (reader->metadata == NULL) { + reader->offset = 0; + reader->remaining_keys = 0; + } else { + memcpy(&reader->remaining_keys, reader->metadata, sizeof(int32_t)); + reader->offset = sizeof(int32_t); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowMetadataReaderRead(struct ArrowMetadataReader* reader, + struct ArrowStringView* key_out, + struct ArrowStringView* value_out) { + if (reader->remaining_keys <= 0) { + return EINVAL; + } + + int64_t pos = 0; + + int32_t key_size; + memcpy(&key_size, reader->metadata + reader->offset + pos, sizeof(int32_t)); + pos += sizeof(int32_t); + + key_out->data = reader->metadata + reader->offset + pos; + key_out->size_bytes = key_size; + pos += key_size; + + int32_t value_size; + memcpy(&value_size, reader->metadata + reader->offset + pos, sizeof(int32_t)); + pos += sizeof(int32_t); + + value_out->data = reader->metadata + reader->offset + pos; + value_out->size_bytes = value_size; + pos += value_size; + + reader->offset += pos; + reader->remaining_keys--; + return NANOARROW_OK; +} + +int64_t ArrowMetadataSizeOf(const char* metadata) { + if (metadata == NULL) { + return 0; + } + + struct ArrowMetadataReader reader; + struct ArrowStringView key; + struct ArrowStringView value; + if (ArrowMetadataReaderInit(&reader, metadata) != NANOARROW_OK) { + return 0; + } + + int64_t size = sizeof(int32_t); + while (ArrowMetadataReaderRead(&reader, &key, &value) == NANOARROW_OK) { + size += sizeof(int32_t) + key.size_bytes + sizeof(int32_t) + value.size_bytes; + } + + return size; +} + +static ArrowErrorCode ArrowMetadataGetValueInternal(const char* metadata, + struct ArrowStringView* key, + struct ArrowStringView* value_out) { + struct ArrowMetadataReader reader; + struct ArrowStringView existing_key; + struct ArrowStringView existing_value; + NANOARROW_RETURN_NOT_OK(ArrowMetadataReaderInit(&reader, metadata)); + + while (ArrowMetadataReaderRead(&reader, &existing_key, &existing_value) == + NANOARROW_OK) { + int key_equal = key->size_bytes == existing_key.size_bytes && + strncmp(key->data, existing_key.data, existing_key.size_bytes) == 0; + if (key_equal) { + value_out->data = existing_value.data; + value_out->size_bytes = existing_value.size_bytes; + break; + } + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowMetadataGetValue(const char* metadata, struct ArrowStringView key, + struct ArrowStringView* value_out) { + if (value_out == NULL) { + return EINVAL; + } + + return ArrowMetadataGetValueInternal(metadata, &key, value_out); +} + +char ArrowMetadataHasKey(const char* metadata, struct ArrowStringView key) { + struct ArrowStringView value = ArrowCharView(NULL); + if (ArrowMetadataGetValue(metadata, key, &value) != NANOARROW_OK) { + return 0; + } + + return value.data != NULL; +} + +ArrowErrorCode ArrowMetadataBuilderInit(struct ArrowBuffer* buffer, + const char* metadata) { + ArrowBufferInit(buffer); + return ArrowBufferAppend(buffer, metadata, ArrowMetadataSizeOf(metadata)); +} + +static ArrowErrorCode ArrowMetadataBuilderAppendInternal(struct ArrowBuffer* buffer, + struct ArrowStringView* key, + struct ArrowStringView* value) { + if (value == NULL) { + return NANOARROW_OK; + } + + if (buffer->capacity_bytes == 0) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(buffer, 0)); + } + + if (((size_t)buffer->capacity_bytes) < sizeof(int32_t)) { + return EINVAL; + } + + int32_t n_keys; + memcpy(&n_keys, buffer->data, sizeof(int32_t)); + + int32_t key_size = (int32_t)key->size_bytes; + int32_t value_size = (int32_t)value->size_bytes; + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve( + buffer, sizeof(int32_t) + key_size + sizeof(int32_t) + value_size)); + + ArrowBufferAppendUnsafe(buffer, &key_size, sizeof(int32_t)); + ArrowBufferAppendUnsafe(buffer, key->data, key_size); + ArrowBufferAppendUnsafe(buffer, &value_size, sizeof(int32_t)); + ArrowBufferAppendUnsafe(buffer, value->data, value_size); + + n_keys++; + memcpy(buffer->data, &n_keys, sizeof(int32_t)); + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowMetadataBuilderSetInternal(struct ArrowBuffer* buffer, + struct ArrowStringView* key, + struct ArrowStringView* value) { + // Inspect the current value to see if we can avoid copying the buffer + struct ArrowStringView current_value = ArrowCharView(NULL); + NANOARROW_RETURN_NOT_OK( + ArrowMetadataGetValueInternal((const char*)buffer->data, key, ¤t_value)); + + // The key should be removed but no key exists + if (value == NULL && current_value.data == NULL) { + return NANOARROW_OK; + } + + // The key/value can be appended because no key exists + if (value != NULL && current_value.data == NULL) { + return ArrowMetadataBuilderAppendInternal(buffer, key, value); + } + + struct ArrowMetadataReader reader; + struct ArrowStringView existing_key; + struct ArrowStringView existing_value; + NANOARROW_RETURN_NOT_OK(ArrowMetadataReaderInit(&reader, (const char*)buffer->data)); + + struct ArrowBuffer new_buffer; + NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderInit(&new_buffer, NULL)); + + while (reader.remaining_keys > 0) { + int result = ArrowMetadataReaderRead(&reader, &existing_key, &existing_value); + if (result != NANOARROW_OK) { + ArrowBufferReset(&new_buffer); + return result; + } + + if (key->size_bytes == existing_key.size_bytes && + strncmp((const char*)key->data, (const char*)existing_key.data, + existing_key.size_bytes) == 0) { + result = ArrowMetadataBuilderAppendInternal(&new_buffer, key, value); + value = NULL; + } else { + result = + ArrowMetadataBuilderAppendInternal(&new_buffer, &existing_key, &existing_value); + } + + if (result != NANOARROW_OK) { + ArrowBufferReset(&new_buffer); + return result; + } + } + + ArrowBufferReset(buffer); + ArrowBufferMove(&new_buffer, buffer); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowMetadataBuilderAppend(struct ArrowBuffer* buffer, + struct ArrowStringView key, + struct ArrowStringView value) { + return ArrowMetadataBuilderAppendInternal(buffer, &key, &value); +} + +ArrowErrorCode ArrowMetadataBuilderSet(struct ArrowBuffer* buffer, + struct ArrowStringView key, + struct ArrowStringView value) { + return ArrowMetadataBuilderSetInternal(buffer, &key, &value); +} + +ArrowErrorCode ArrowMetadataBuilderRemove(struct ArrowBuffer* buffer, + struct ArrowStringView key) { + return ArrowMetadataBuilderSetInternal(buffer, &key, NULL); +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include +#include +#include +#include +#include + +#include "nanoarrow/nanoarrow.h" + +static void ArrowArrayReleaseInternal(struct ArrowArray* array) { + // Release buffers held by this array + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + if (private_data != NULL) { + ArrowBitmapReset(&private_data->bitmap); + ArrowBufferReset(&private_data->buffers[0]); + ArrowBufferReset(&private_data->buffers[1]); + ArrowFree(private_data->buffer_data); + for (int32_t i = 0; i < private_data->n_variadic_buffers; ++i) { + ArrowBufferReset(&private_data->variadic_buffers[i]); + } + ArrowFree(private_data->variadic_buffers); + ArrowFree(private_data); + } + + // This object owns the memory for all the children, but those + // children may have been generated elsewhere and might have + // their own release() callback. + if (array->children != NULL) { + for (int64_t i = 0; i < array->n_children; i++) { + if (array->children[i] != NULL) { + if (array->children[i]->release != NULL) { + ArrowArrayRelease(array->children[i]); + } + + ArrowFree(array->children[i]); + } + } + + ArrowFree(array->children); + } + + // This object owns the memory for the dictionary but it + // may have been generated somewhere else and have its own + // release() callback. + if (array->dictionary != NULL) { + if (array->dictionary->release != NULL) { + ArrowArrayRelease(array->dictionary); + } + + ArrowFree(array->dictionary); + } + + // Mark released + array->release = NULL; +} + +static int ArrowArrayIsInternal(struct ArrowArray* array) { + return array->release == &ArrowArrayReleaseInternal; +} + +static ArrowErrorCode ArrowArraySetStorageType(struct ArrowArray* array, + enum ArrowType storage_type) { + switch (storage_type) { + case NANOARROW_TYPE_UNINITIALIZED: + case NANOARROW_TYPE_NA: + case NANOARROW_TYPE_RUN_END_ENCODED: + array->n_buffers = 0; + break; + + case NANOARROW_TYPE_FIXED_SIZE_LIST: + case NANOARROW_TYPE_STRUCT: + case NANOARROW_TYPE_SPARSE_UNION: + array->n_buffers = 1; + break; + + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_LARGE_LIST: + case NANOARROW_TYPE_MAP: + case NANOARROW_TYPE_BOOL: + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_INT8: + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_INT16: + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_INT32: + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_INT64: + case NANOARROW_TYPE_HALF_FLOAT: + case NANOARROW_TYPE_FLOAT: + case NANOARROW_TYPE_DOUBLE: + case NANOARROW_TYPE_DECIMAL32: + case NANOARROW_TYPE_DECIMAL64: + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_DECIMAL256: + case NANOARROW_TYPE_INTERVAL_MONTHS: + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + case NANOARROW_TYPE_DENSE_UNION: + array->n_buffers = 2; + break; + case NANOARROW_TYPE_BINARY_VIEW: + case NANOARROW_TYPE_STRING_VIEW: + array->n_buffers = NANOARROW_BINARY_VIEW_FIXED_BUFFERS + 1; + break; + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_BINARY: + case NANOARROW_TYPE_LARGE_BINARY: + case NANOARROW_TYPE_LIST_VIEW: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + array->n_buffers = 3; + break; + + default: + return EINVAL; + + return NANOARROW_OK; + } + + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + private_data->storage_type = storage_type; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray* array, + enum ArrowType storage_type) { + array->length = 0; + array->null_count = 0; + array->offset = 0; + array->n_buffers = 0; + array->n_children = 0; + array->buffers = NULL; + array->children = NULL; + array->dictionary = NULL; + array->release = &ArrowArrayReleaseInternal; + array->private_data = NULL; + + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)ArrowMalloc(sizeof(struct ArrowArrayPrivateData)); + if (private_data == NULL) { + array->release = NULL; + return ENOMEM; + } + + ArrowBitmapInit(&private_data->bitmap); + ArrowBufferInit(&private_data->buffers[0]); + ArrowBufferInit(&private_data->buffers[1]); + private_data->buffer_data = + (const void**)ArrowMalloc(sizeof(void*) * NANOARROW_MAX_FIXED_BUFFERS); + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; ++i) { + private_data->buffer_data[i] = NULL; + } + private_data->n_variadic_buffers = 0; + private_data->variadic_buffers = NULL; + private_data->list_view_offset = 0; + + array->private_data = private_data; + array->buffers = (const void**)(private_data->buffer_data); + + // These are not technically "storage" in the sense that they do not appear + // in the ArrowSchemaView's storage_type member; however, allowing them here + // is helpful to maximize the number of types that can avoid going through + // ArrowArrayInitFromSchema(). + switch (storage_type) { + case NANOARROW_TYPE_DURATION: + case NANOARROW_TYPE_TIMESTAMP: + case NANOARROW_TYPE_TIME64: + case NANOARROW_TYPE_DATE64: + storage_type = NANOARROW_TYPE_INT64; + break; + case NANOARROW_TYPE_TIME32: + case NANOARROW_TYPE_DATE32: + storage_type = NANOARROW_TYPE_INT32; + break; + default: + break; + } + + int result = ArrowArraySetStorageType(array, storage_type); + if (result != NANOARROW_OK) { + ArrowArrayRelease(array); + return result; + } + + ArrowLayoutInit(&private_data->layout, storage_type); + // We can only know this not to be true when initializing based on a schema + // so assume this to be true. + private_data->union_type_id_is_child_index = 1; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayInitFromArrayView(struct ArrowArray* array, + const struct ArrowArrayView* array_view, + struct ArrowError* error) { + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowArrayInitFromType(array, array_view->storage_type), error); + int result; + + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + private_data->layout = array_view->layout; + + if (array_view->n_children > 0) { + result = ArrowArrayAllocateChildren(array, array_view->n_children); + if (result != NANOARROW_OK) { + ArrowArrayRelease(array); + return result; + } + + for (int64_t i = 0; i < array_view->n_children; i++) { + result = + ArrowArrayInitFromArrayView(array->children[i], array_view->children[i], error); + if (result != NANOARROW_OK) { + ArrowArrayRelease(array); + return result; + } + } + } + + if (array_view->dictionary != NULL) { + result = ArrowArrayAllocateDictionary(array); + if (result != NANOARROW_OK) { + ArrowArrayRelease(array); + return result; + } + + result = + ArrowArrayInitFromArrayView(array->dictionary, array_view->dictionary, error); + if (result != NANOARROW_OK) { + ArrowArrayRelease(array); + return result; + } + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array, + const struct ArrowSchema* schema, + struct ArrowError* error) { + struct ArrowArrayView array_view; + NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromSchema(&array_view, schema, error)); + NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromArrayView(array, &array_view, error)); + if (array_view.storage_type == NANOARROW_TYPE_DENSE_UNION || + array_view.storage_type == NANOARROW_TYPE_SPARSE_UNION) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + // We can still build arrays if this isn't true; however, the append + // functions won't work. Instead, we store this value and error only + // when StartAppending is called. + private_data->union_type_id_is_child_index = + _ArrowUnionTypeIdsWillEqualChildIndices(schema->format + 4, schema->n_children); + } + + ArrowArrayViewReset(&array_view); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayAllocateChildren(struct ArrowArray* array, int64_t n_children) { + if (array->children != NULL) { + return EINVAL; + } + + if (n_children == 0) { + return NANOARROW_OK; + } + + array->children = + (struct ArrowArray**)ArrowMalloc(n_children * sizeof(struct ArrowArray*)); + if (array->children == NULL) { + return ENOMEM; + } + + memset(array->children, 0, n_children * sizeof(struct ArrowArray*)); + + for (int64_t i = 0; i < n_children; i++) { + array->children[i] = (struct ArrowArray*)ArrowMalloc(sizeof(struct ArrowArray)); + if (array->children[i] == NULL) { + return ENOMEM; + } + array->children[i]->release = NULL; + } + + array->n_children = n_children; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayAllocateDictionary(struct ArrowArray* array) { + if (array->dictionary != NULL) { + return EINVAL; + } + + array->dictionary = (struct ArrowArray*)ArrowMalloc(sizeof(struct ArrowArray)); + if (array->dictionary == NULL) { + return ENOMEM; + } + + array->dictionary->release = NULL; + return NANOARROW_OK; +} + +void ArrowArraySetValidityBitmap(struct ArrowArray* array, struct ArrowBitmap* bitmap) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + ArrowBufferMove(&bitmap->buffer, &private_data->bitmap.buffer); + private_data->bitmap.size_bits = bitmap->size_bits; + bitmap->size_bits = 0; + private_data->buffer_data[0] = private_data->bitmap.buffer.data; + array->null_count = -1; +} + +ArrowErrorCode ArrowArraySetBuffer(struct ArrowArray* array, int64_t i, + struct ArrowBuffer* buffer) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + if (i >= array->n_buffers || i < 0) { + return EINVAL; + } + + // Find the `i`th buffer, release what is currently there, and move the + // supplied buffer into that slot. + struct ArrowBuffer* dst = ArrowArrayBuffer(array, i); + ArrowBufferReset(dst); + ArrowBufferMove(buffer, dst); + + // Flush the pointer into array->buffers. In theory clients should call + // ArrowArrayFinishBuilding() to flush the pointer values before passing + // this array elsewhere; however, in early nanoarrow versions this was not + // needed and some code may depend on this being true. + private_data->buffer_data[i] = dst->data; + array->buffers = private_data->buffer_data; + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowArrayViewInitFromArray(struct ArrowArrayView* array_view, + struct ArrowArray* array, + struct ArrowError* error) { + if (!ArrowArrayIsInternal(array)) { + ArrowErrorSet(error, + "Can't initialize internal ArrowArrayView from external ArrowArray"); + return EINVAL; + } + + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + ArrowArrayViewInitFromType(array_view, private_data->storage_type); + array_view->layout = private_data->layout; + array_view->array = array; + array_view->length = array->length; + array_view->offset = array->offset; + array_view->null_count = array->null_count; + + array_view->buffer_views[0].data.as_uint8 = private_data->bitmap.buffer.data; + array_view->buffer_views[0].size_bytes = private_data->bitmap.buffer.size_bytes; + array_view->buffer_views[1].data.as_uint8 = private_data->buffers[0].data; + array_view->buffer_views[1].size_bytes = private_data->buffers[0].size_bytes; + array_view->buffer_views[2].data.as_uint8 = private_data->buffers[1].data; + array_view->buffer_views[2].size_bytes = private_data->buffers[1].size_bytes; + + int result = ArrowArrayViewAllocateChildren(array_view, array->n_children); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + + for (int64_t i = 0; i < array->n_children; i++) { + result = + ArrowArrayViewInitFromArray(array_view->children[i], array->children[i], error); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + } + + if (array->dictionary != NULL) { + result = ArrowArrayViewAllocateDictionary(array_view); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + + result = + ArrowArrayViewInitFromArray(array_view->dictionary, array->dictionary, error); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowArrayReserveInternal(struct ArrowArray* array, + struct ArrowArrayView* array_view) { + // Loop through buffers and reserve the extra space that we know about + for (int64_t i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + // Don't reserve on a validity buffer that hasn't been allocated yet + if (array_view->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_VALIDITY && + ArrowArrayBuffer(array, i)->data == NULL) { + continue; + } + + int64_t additional_size_bytes = + array_view->buffer_views[i].size_bytes - ArrowArrayBuffer(array, i)->size_bytes; + + if (additional_size_bytes > 0) { + NANOARROW_RETURN_NOT_OK( + ArrowBufferReserve(ArrowArrayBuffer(array, i), additional_size_bytes)); + } + } + + // Recursively reserve children + for (int64_t i = 0; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayReserveInternal(array->children[i], array_view->children[i])); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayReserve(struct ArrowArray* array, + int64_t additional_size_elements) { + struct ArrowArrayView array_view; + NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromArray(&array_view, array, NULL)); + + // Calculate theoretical buffer sizes (recursively) + ArrowArrayViewSetLength(&array_view, array->length + additional_size_elements); + + // Walk the structure (recursively) + int result = ArrowArrayReserveInternal(array, &array_view); + ArrowArrayViewReset(&array_view); + if (result != NANOARROW_OK) { + return result; + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowArrayFinalizeBuffers(struct ArrowArray* array) { + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + if (private_data->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_VALIDITY || + private_data->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_NONE) { + continue; + } + + struct ArrowBuffer* buffer = ArrowArrayBuffer(array, i); + if (buffer->data == NULL) { + NANOARROW_RETURN_NOT_OK((ArrowBufferReserve(buffer, 1))); + } + } + + for (int64_t i = 0; i < array->n_children; i++) { + if (ArrowArrayIsInternal(array->children[i])) { + NANOARROW_RETURN_NOT_OK(ArrowArrayFinalizeBuffers(array->children[i])); + } + } + + if (array->dictionary != NULL && ArrowArrayIsInternal(array->dictionary)) { + NANOARROW_RETURN_NOT_OK(ArrowArrayFinalizeBuffers(array->dictionary)); + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowArrayFlushInternalPointers(struct ArrowArray* array) { + NANOARROW_DCHECK(ArrowArrayIsInternal(array)); + struct ArrowArrayPrivateData* private_data = + (struct ArrowArrayPrivateData*)array->private_data; + + if (array->n_buffers > NANOARROW_MAX_FIXED_BUFFERS) { + // If the variadic sizes buffer was not set and there is at least one variadic + // buffer, populate it now (if there are no variadic buffers there will be exactly + // three total buffers and we don't need to do anything special here). Notably, this + // will occur when building a BinaryView/StringView array by element using the + // appender. + struct ArrowBuffer* sizes_buffer = ArrowArrayBuffer(array, array->n_buffers - 1); + if (sizes_buffer->data == NULL && sizes_buffer->size_bytes == 0) { + NANOARROW_RETURN_NOT_OK( + ArrowBufferReserve(sizes_buffer, private_data->n_variadic_buffers)); + for (int64_t i = 0; i < private_data->n_variadic_buffers; i++) { + struct ArrowBuffer* variadic_buffer = + ArrowArrayBuffer(array, i + NANOARROW_BINARY_VIEW_FIXED_BUFFERS); + NANOARROW_RETURN_NOT_OK( + ArrowBufferAppendInt64(sizes_buffer, variadic_buffer->size_bytes)); + } + } + } + + for (int32_t i = 0; i < array->n_buffers; i++) { + private_data->buffer_data[i] = ArrowArrayBuffer(array, i)->data; + } + + array->buffers = (const void**)(private_data->buffer_data); + + // Flush internal pointers for child/dictionary arrays if we allocated them. Clients + // building arrays by buffer might have moved arrays from some other source (e.g., + // to create a record batch) and calling this function in that case will cause a crash. + for (int64_t i = 0; i < array->n_children; i++) { + if (ArrowArrayIsInternal(array->children[i])) { + NANOARROW_RETURN_NOT_OK(ArrowArrayFlushInternalPointers(array->children[i])); + } + } + + if (array->dictionary != NULL && ArrowArrayIsInternal(array->dictionary)) { + NANOARROW_RETURN_NOT_OK(ArrowArrayFlushInternalPointers(array->dictionary)); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayFinishBuilding(struct ArrowArray* array, + enum ArrowValidationLevel validation_level, + struct ArrowError* error) { + // Even if the data buffer is size zero, the pointer value needed to be non-null + // in some implementations (at least one version of Arrow C++ at the time this + // was added and C# as later discovered). Only do this fix if we can assume + // CPU data access. + if (validation_level >= NANOARROW_VALIDATION_LEVEL_DEFAULT) { + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowArrayFinalizeBuffers(array), error); + } + + // Make sure the value we get with array->buffers[i] is set to the actual + // pointer (which may have changed from the original due to reallocation) + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowArrayFlushInternalPointers(array), error); + + if (validation_level == NANOARROW_VALIDATION_LEVEL_NONE) { + return NANOARROW_OK; + } + + // For validation, initialize an ArrowArrayView with our known buffer sizes + struct ArrowArrayView array_view; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowArrayViewInitFromArray(&array_view, array, error), error); + int result = ArrowArrayViewValidate(&array_view, validation_level, error); + ArrowArrayViewReset(&array_view); + return result; +} + +ArrowErrorCode ArrowArrayFinishBuildingDefault(struct ArrowArray* array, + struct ArrowError* error) { + return ArrowArrayFinishBuilding(array, NANOARROW_VALIDATION_LEVEL_DEFAULT, error); +} + +void ArrowArrayViewInitFromType(struct ArrowArrayView* array_view, + enum ArrowType storage_type) { + memset(array_view, 0, sizeof(struct ArrowArrayView)); + array_view->storage_type = storage_type; + ArrowLayoutInit(&array_view->layout, storage_type); +} + +ArrowErrorCode ArrowArrayViewAllocateChildren(struct ArrowArrayView* array_view, + int64_t n_children) { + if (array_view->children != NULL) { + return EINVAL; + } + + if (n_children == 0) { + array_view->n_children = 0; + return NANOARROW_OK; + } + + array_view->children = + (struct ArrowArrayView**)ArrowMalloc(n_children * sizeof(struct ArrowArrayView*)); + if (array_view->children == NULL) { + return ENOMEM; + } + + for (int64_t i = 0; i < n_children; i++) { + array_view->children[i] = NULL; + } + + array_view->n_children = n_children; + + for (int64_t i = 0; i < n_children; i++) { + array_view->children[i] = + (struct ArrowArrayView*)ArrowMalloc(sizeof(struct ArrowArrayView)); + if (array_view->children[i] == NULL) { + return ENOMEM; + } + ArrowArrayViewInitFromType(array_view->children[i], NANOARROW_TYPE_UNINITIALIZED); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayViewAllocateDictionary(struct ArrowArrayView* array_view) { + if (array_view->dictionary != NULL) { + return EINVAL; + } + + array_view->dictionary = + (struct ArrowArrayView*)ArrowMalloc(sizeof(struct ArrowArrayView)); + if (array_view->dictionary == NULL) { + return ENOMEM; + } + + ArrowArrayViewInitFromType(array_view->dictionary, NANOARROW_TYPE_UNINITIALIZED); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view, + const struct ArrowSchema* schema, + struct ArrowError* error) { + struct ArrowSchemaView schema_view; + int result = ArrowSchemaViewInit(&schema_view, schema, error); + if (result != NANOARROW_OK) { + return result; + } + + ArrowArrayViewInitFromType(array_view, schema_view.storage_type); + array_view->layout = schema_view.layout; + + result = ArrowArrayViewAllocateChildren(array_view, schema->n_children); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowArrayViewAllocateChildren() failed"); + ArrowArrayViewReset(array_view); + return result; + } + + for (int64_t i = 0; i < schema->n_children; i++) { + result = + ArrowArrayViewInitFromSchema(array_view->children[i], schema->children[i], error); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + } + + if (schema->dictionary != NULL) { + result = ArrowArrayViewAllocateDictionary(array_view); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + + result = + ArrowArrayViewInitFromSchema(array_view->dictionary, schema->dictionary, error); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(array_view); + return result; + } + } + + if (array_view->storage_type == NANOARROW_TYPE_SPARSE_UNION || + array_view->storage_type == NANOARROW_TYPE_DENSE_UNION) { + array_view->union_type_id_map = (int8_t*)ArrowMalloc(256 * sizeof(int8_t)); + if (array_view->union_type_id_map == NULL) { + return ENOMEM; + } + + memset(array_view->union_type_id_map, -1, 256); + int32_t n_type_ids = _ArrowParseUnionTypeIds(schema_view.union_type_ids, + array_view->union_type_id_map + 128); + for (int8_t child_index = 0; child_index < n_type_ids; child_index++) { + int8_t type_id = array_view->union_type_id_map[128 + child_index]; + array_view->union_type_id_map[type_id] = child_index; + } + } + + return NANOARROW_OK; +} + +void ArrowArrayViewReset(struct ArrowArrayView* array_view) { + if (array_view->children != NULL) { + for (int64_t i = 0; i < array_view->n_children; i++) { + if (array_view->children[i] != NULL) { + ArrowArrayViewReset(array_view->children[i]); + ArrowFree(array_view->children[i]); + } + } + + ArrowFree(array_view->children); + } + + if (array_view->dictionary != NULL) { + ArrowArrayViewReset(array_view->dictionary); + ArrowFree(array_view->dictionary); + } + + if (array_view->union_type_id_map != NULL) { + ArrowFree(array_view->union_type_id_map); + } + + ArrowArrayViewInitFromType(array_view, NANOARROW_TYPE_UNINITIALIZED); +} + +void ArrowArrayViewSetLength(struct ArrowArrayView* array_view, int64_t length) { + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + int64_t element_size_bytes = array_view->layout.element_size_bits[i] / 8; + + switch (array_view->layout.buffer_type[i]) { + case NANOARROW_BUFFER_TYPE_VALIDITY: + array_view->buffer_views[i].size_bytes = _ArrowBytesForBits(length); + continue; + case NANOARROW_BUFFER_TYPE_DATA_OFFSET: + // Probably don't want/need to rely on the producer to have allocated an + // offsets buffer of length 1 for a zero-size array + array_view->buffer_views[i].size_bytes = + (length != 0) * element_size_bytes * (length + 1); + continue; + case NANOARROW_BUFFER_TYPE_DATA: + array_view->buffer_views[i].size_bytes = + _ArrowRoundUpToMultipleOf8(array_view->layout.element_size_bits[i] * length) / + 8; + continue; + case NANOARROW_BUFFER_TYPE_TYPE_ID: + case NANOARROW_BUFFER_TYPE_UNION_OFFSET: + case NANOARROW_BUFFER_TYPE_VIEW_OFFSET: + case NANOARROW_BUFFER_TYPE_SIZE: + array_view->buffer_views[i].size_bytes = element_size_bytes * length; + continue; + case NANOARROW_BUFFER_TYPE_VARIADIC_DATA: + case NANOARROW_BUFFER_TYPE_VARIADIC_SIZE: + case NANOARROW_BUFFER_TYPE_NONE: + array_view->buffer_views[i].size_bytes = 0; + continue; + } + } + + switch (array_view->storage_type) { + case NANOARROW_TYPE_STRUCT: + case NANOARROW_TYPE_SPARSE_UNION: + for (int64_t i = 0; i < array_view->n_children; i++) { + ArrowArrayViewSetLength(array_view->children[i], length); + } + break; + case NANOARROW_TYPE_FIXED_SIZE_LIST: + if (array_view->n_children >= 1) { + ArrowArrayViewSetLength(array_view->children[0], + length * array_view->layout.child_size_elements); + } + default: + break; + } +} + +// This version recursively extracts information from the array and stores it +// in the array view, performing any checks that require the original array. +static int ArrowArrayViewSetArrayInternal(struct ArrowArrayView* array_view, + const struct ArrowArray* array, + struct ArrowError* error) { + array_view->array = array; + array_view->offset = array->offset; + array_view->length = array->length; + array_view->null_count = array->null_count; + array_view->variadic_buffer_sizes = NULL; + array_view->variadic_buffers = NULL; + array_view->n_variadic_buffers = 0; + + int64_t buffers_required = 0; + const int nfixed_buf = array_view->storage_type == NANOARROW_TYPE_STRING_VIEW || + array_view->storage_type == NANOARROW_TYPE_BINARY_VIEW + ? NANOARROW_BINARY_VIEW_FIXED_BUFFERS + : NANOARROW_MAX_FIXED_BUFFERS; + for (int i = 0; i < nfixed_buf; i++) { + if (array_view->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_NONE) { + break; + } + + buffers_required++; + + // Set buffer pointer + array_view->buffer_views[i].data.data = array->buffers[i]; + + // If non-null, set buffer size to unknown. + if (array->buffers[i] == NULL) { + array_view->buffer_views[i].size_bytes = 0; + } else { + array_view->buffer_views[i].size_bytes = -1; + } + } + + if (array_view->storage_type == NANOARROW_TYPE_STRING_VIEW || + array_view->storage_type == NANOARROW_TYPE_BINARY_VIEW) { + const int64_t n_buffers = array->n_buffers; + const int32_t nfixed_buf = NANOARROW_BINARY_VIEW_FIXED_BUFFERS; + + const int32_t nvariadic_buf = (int32_t)(n_buffers - nfixed_buf - 1); + array_view->n_variadic_buffers = nvariadic_buf; + buffers_required += nvariadic_buf + 1; + array_view->variadic_buffers = array->buffers + NANOARROW_BINARY_VIEW_FIXED_BUFFERS; + array_view->variadic_buffer_sizes = (int64_t*)array->buffers[n_buffers - 1]; + } + + if (buffers_required != array->n_buffers) { + ArrowErrorSet(error, + "Expected array with %" PRId64 " buffer(s) but found %" PRId64 + " buffer(s)", + buffers_required, array->n_buffers); + return EINVAL; + } + + // Check number of children + if (array_view->n_children != array->n_children) { + ArrowErrorSet(error, "Expected %" PRId64 " children but found %" PRId64 " children", + array_view->n_children, array->n_children); + return EINVAL; + } + + // Recurse for children + for (int64_t i = 0; i < array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view->children[i], + array->children[i], error)); + } + + // Check dictionary + if (array->dictionary == NULL && array_view->dictionary != NULL) { + ArrowErrorSet(error, "Expected dictionary but found NULL"); + return EINVAL; + } + + if (array->dictionary != NULL && array_view->dictionary == NULL) { + ArrowErrorSet(error, "Expected NULL dictionary but found dictionary member"); + return EINVAL; + } + + if (array->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayViewSetArrayInternal(array_view->dictionary, array->dictionary, error)); + } + + return NANOARROW_OK; +} + +static int ArrowArrayViewValidateMinimal(struct ArrowArrayView* array_view, + struct ArrowError* error) { + if (array_view->length < 0) { + ArrowErrorSet(error, "Expected length >= 0 but found length %" PRId64, + array_view->length); + return EINVAL; + } + + if (array_view->offset < 0) { + ArrowErrorSet(error, "Expected offset >= 0 but found offset %" PRId64, + array_view->offset); + return EINVAL; + } + + // Ensure that offset + length fits within an int64 before a possible overflow + if ((uint64_t)array_view->offset + (uint64_t)array_view->length > (uint64_t)INT64_MAX) { + ArrowErrorSet(error, "Offset + length is > INT64_MAX"); + return EINVAL; + } + + // Calculate buffer sizes that do not require buffer access. If marked as + // unknown, assign the buffer size; otherwise, validate it. + int64_t offset_plus_length = array_view->offset + array_view->length; + + // Only loop over the first two buffers because the size of the third buffer + // is always data dependent for all current Arrow types. + for (int i = 0; i < 2; i++) { + int64_t element_size_bytes = array_view->layout.element_size_bits[i] / 8; + // Initialize with a value that will cause an error if accidentally used uninitialized + // Need to suppress the clang-tidy warning because gcc warns for possible use + int64_t min_buffer_size_bytes = // NOLINT(clang-analyzer-deadcode.DeadStores) + array_view->buffer_views[i].size_bytes + 1; + + switch (array_view->layout.buffer_type[i]) { + case NANOARROW_BUFFER_TYPE_VALIDITY: + if (array_view->null_count == 0 && array_view->buffer_views[i].size_bytes == 0) { + continue; + } + + min_buffer_size_bytes = _ArrowBytesForBits(offset_plus_length); + break; + case NANOARROW_BUFFER_TYPE_SIZE: + min_buffer_size_bytes = element_size_bytes * offset_plus_length; + break; + case NANOARROW_BUFFER_TYPE_DATA_OFFSET: + // Probably don't want/need to rely on the producer to have allocated an + // offsets buffer of length 1 for a zero-size array + min_buffer_size_bytes = + (offset_plus_length != 0) * element_size_bytes * (offset_plus_length + 1); + break; + case NANOARROW_BUFFER_TYPE_VIEW_OFFSET: + min_buffer_size_bytes = + (offset_plus_length != 0) * element_size_bytes * offset_plus_length; + break; + case NANOARROW_BUFFER_TYPE_DATA: + min_buffer_size_bytes = + _ArrowRoundUpToMultipleOf8(array_view->layout.element_size_bits[i] * + offset_plus_length) / + 8; + break; + case NANOARROW_BUFFER_TYPE_TYPE_ID: + case NANOARROW_BUFFER_TYPE_UNION_OFFSET: + min_buffer_size_bytes = element_size_bytes * offset_plus_length; + break; + case NANOARROW_BUFFER_TYPE_VARIADIC_DATA: + case NANOARROW_BUFFER_TYPE_VARIADIC_SIZE: + case NANOARROW_BUFFER_TYPE_NONE: + continue; + } + + // Assign or validate buffer size + if (array_view->buffer_views[i].size_bytes == -1) { + array_view->buffer_views[i].size_bytes = min_buffer_size_bytes; + } else if (array_view->buffer_views[i].size_bytes < min_buffer_size_bytes) { + ArrowErrorSet(error, + "Expected %s array buffer %d to have size >= %" PRId64 + " bytes but found " + "buffer with %" PRId64 " bytes", + ArrowTypeString(array_view->storage_type), i, min_buffer_size_bytes, + array_view->buffer_views[i].size_bytes); + return EINVAL; + } + } + + // For list, fixed-size list and map views, we can validate the number of children + switch (array_view->storage_type) { + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_LARGE_LIST: + case NANOARROW_TYPE_FIXED_SIZE_LIST: + case NANOARROW_TYPE_MAP: + case NANOARROW_TYPE_LIST_VIEW: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + if (array_view->n_children != 1) { + ArrowErrorSet(error, + "Expected 1 child of %s array but found %" PRId64 " child arrays", + ArrowTypeString(array_view->storage_type), array_view->n_children); + return EINVAL; + } + break; + case NANOARROW_TYPE_RUN_END_ENCODED: + if (array_view->n_children != 2) { + ArrowErrorSet( + error, "Expected 2 children for %s array but found %" PRId64 " child arrays", + ArrowTypeString(array_view->storage_type), array_view->n_children); + return EINVAL; + } + break; + default: + break; + } + + // For struct, the sparse union, and the fixed-size list views, we can validate child + // lengths. + int64_t child_min_length; + switch (array_view->storage_type) { + case NANOARROW_TYPE_SPARSE_UNION: + case NANOARROW_TYPE_STRUCT: + child_min_length = (array_view->offset + array_view->length); + for (int64_t i = 0; i < array_view->n_children; i++) { + if (array_view->children[i]->length < child_min_length) { + ArrowErrorSet(error, + "Expected struct child %" PRId64 " to have length >= %" PRId64 + " but found child with " + "length %" PRId64, + i + 1, child_min_length, array_view->children[i]->length); + return EINVAL; + } + } + break; + + case NANOARROW_TYPE_FIXED_SIZE_LIST: + child_min_length = (array_view->offset + array_view->length) * + array_view->layout.child_size_elements; + if (array_view->children[0]->length < child_min_length) { + ArrowErrorSet(error, + "Expected child of fixed_size_list array to have length >= %" PRId64 + " but " + "found array with length %" PRId64, + child_min_length, array_view->children[0]->length); + return EINVAL; + } + break; + + case NANOARROW_TYPE_RUN_END_ENCODED: { + if (array_view->n_children != 2) { + ArrowErrorSet(error, + "Expected 2 children for run-end encoded array but found %" PRId64, + array_view->n_children); + return EINVAL; + } + struct ArrowArrayView* run_ends_view = array_view->children[0]; + struct ArrowArrayView* values_view = array_view->children[1]; + int64_t max_length; + switch (run_ends_view->storage_type) { + case NANOARROW_TYPE_INT16: + max_length = INT16_MAX; + break; + case NANOARROW_TYPE_INT32: + max_length = INT32_MAX; + break; + case NANOARROW_TYPE_INT64: + max_length = INT64_MAX; + break; + default: + ArrowErrorSet( + error, + "Run-end encoded array only supports INT16, INT32 or INT64 run-ends " + "but found run-ends type %s", + ArrowTypeString(run_ends_view->storage_type)); + return EINVAL; + } + + // There is already a check above that offset_plus_length < INT64_MAX + if (offset_plus_length > max_length) { + ArrowErrorSet(error, + "Offset + length of a run-end encoded array must fit in a value" + " of the run end type %s but is %" PRId64 " + %" PRId64, + ArrowTypeString(run_ends_view->storage_type), array_view->offset, + array_view->length); + return EINVAL; + } + + if (run_ends_view->length > values_view->length) { + ArrowErrorSet(error, + "Length of run_ends is greater than the length of values: %" PRId64 + " > %" PRId64, + run_ends_view->length, values_view->length); + return EINVAL; + } + + if (run_ends_view->length == 0 && values_view->length != 0) { + ArrowErrorSet(error, + "Run-end encoded array has zero length %" PRId64 + ", but values array has " + "non-zero length", + values_view->length); + return EINVAL; + } + + if (run_ends_view->null_count != 0) { + ArrowErrorSet(error, "Null count must be 0 for run ends array, but is %" PRId64, + run_ends_view->null_count); + return EINVAL; + } + break; + } + + default: + break; + } + + // Recurse for children + for (int64_t i = 0; i < array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayViewValidateMinimal(array_view->children[i], error)); + } + + // Recurse for dictionary + if (array_view->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateMinimal(array_view->dictionary, error)); + } + + return NANOARROW_OK; +} + +static int ArrowArrayViewValidateDefault(struct ArrowArrayView* array_view, + struct ArrowError* error) { + // Perform minimal validation. This will validate or assign + // buffer sizes as long as buffer access is not required. + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateMinimal(array_view, error)); + + // Calculate buffer sizes or child lengths that require accessing the offsets + // buffer. Where appropriate, validate that the first offset is >= 0. + // If a buffer size is marked as unknown, assign it; otherwise, validate it. + int64_t offset_plus_length = array_view->offset + array_view->length; + + int64_t first_offset; + int64_t last_offset; + switch (array_view->storage_type) { + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + if (array_view->buffer_views[1].size_bytes != 0) { + first_offset = array_view->buffer_views[1].data.as_int32[array_view->offset]; + if (first_offset < 0) { + ArrowErrorSet(error, "Expected first offset >= 0 but found %" PRId64, + first_offset); + return EINVAL; + } + + last_offset = array_view->buffer_views[1].data.as_int32[offset_plus_length]; + if (last_offset < 0) { + ArrowErrorSet(error, "Expected last offset >= 0 but found %" PRId64, + last_offset); + return EINVAL; + } + + // If the data buffer size is unknown, assign it; otherwise, check it + if (array_view->buffer_views[2].size_bytes == -1) { + array_view->buffer_views[2].size_bytes = last_offset; + } else if (array_view->buffer_views[2].size_bytes < last_offset) { + ArrowErrorSet(error, + "Expected %s array buffer 2 to have size >= %" PRId64 + " bytes but found " + "buffer with %" PRId64 " bytes", + ArrowTypeString(array_view->storage_type), last_offset, + array_view->buffer_views[2].size_bytes); + return EINVAL; + } + } else if (array_view->buffer_views[2].size_bytes == -1) { + // If the data buffer size is unknown and there are no bytes in the offset buffer, + // set the data buffer size to 0. + array_view->buffer_views[2].size_bytes = 0; + } + break; + + case NANOARROW_TYPE_LARGE_STRING: + case NANOARROW_TYPE_LARGE_BINARY: + if (array_view->buffer_views[1].size_bytes != 0) { + first_offset = array_view->buffer_views[1].data.as_int64[array_view->offset]; + if (first_offset < 0) { + ArrowErrorSet(error, "Expected first offset >= 0 but found %" PRId64, + first_offset); + return EINVAL; + } + + last_offset = array_view->buffer_views[1].data.as_int64[offset_plus_length]; + if (last_offset < 0) { + ArrowErrorSet(error, "Expected last offset >= 0 but found %" PRId64, + last_offset); + return EINVAL; + } + + // If the data buffer size is unknown, assign it; otherwise, check it + if (array_view->buffer_views[2].size_bytes == -1) { + array_view->buffer_views[2].size_bytes = last_offset; + } else if (array_view->buffer_views[2].size_bytes < last_offset) { + ArrowErrorSet(error, + "Expected %s array buffer 2 to have size >= %" PRId64 + " bytes but found " + "buffer with %" PRId64 " bytes", + ArrowTypeString(array_view->storage_type), last_offset, + array_view->buffer_views[2].size_bytes); + return EINVAL; + } + } else if (array_view->buffer_views[2].size_bytes == -1) { + // If the data buffer size is unknown and there are no bytes in the offset + // buffer, set the data buffer size to 0. + array_view->buffer_views[2].size_bytes = 0; + } + break; + + case NANOARROW_TYPE_STRUCT: + for (int64_t i = 0; i < array_view->n_children; i++) { + if (array_view->children[i]->length < offset_plus_length) { + ArrowErrorSet(error, + "Expected struct child %" PRId64 " to have length >= %" PRId64 + " but found child with " + "length %" PRId64, + i + 1, offset_plus_length, array_view->children[i]->length); + return EINVAL; + } + } + break; + + case NANOARROW_TYPE_LIST: + case NANOARROW_TYPE_MAP: + if (array_view->buffer_views[1].size_bytes != 0) { + first_offset = array_view->buffer_views[1].data.as_int32[array_view->offset]; + if (first_offset < 0) { + ArrowErrorSet(error, "Expected first offset >= 0 but found %" PRId64, + first_offset); + return EINVAL; + } + + last_offset = array_view->buffer_views[1].data.as_int32[offset_plus_length]; + if (last_offset < 0) { + ArrowErrorSet(error, "Expected last offset >= 0 but found %" PRId64, + last_offset); + return EINVAL; + } + + if (array_view->children[0]->length < last_offset) { + ArrowErrorSet(error, + "Expected child of %s array to have length >= %" PRId64 + " but found array with " + "length %" PRId64, + ArrowTypeString(array_view->storage_type), last_offset, + array_view->children[0]->length); + return EINVAL; + } + } + break; + + case NANOARROW_TYPE_LARGE_LIST: + if (array_view->buffer_views[1].size_bytes != 0) { + first_offset = array_view->buffer_views[1].data.as_int64[array_view->offset]; + if (first_offset < 0) { + ArrowErrorSet(error, "Expected first offset >= 0 but found %" PRId64, + first_offset); + return EINVAL; + } + + last_offset = array_view->buffer_views[1].data.as_int64[offset_plus_length]; + if (last_offset < 0) { + ArrowErrorSet(error, "Expected last offset >= 0 but found %" PRId64, + last_offset); + return EINVAL; + } + + if (array_view->children[0]->length < last_offset) { + ArrowErrorSet(error, + "Expected child of %s array to have length >= %" PRId64 + " but found array " + "with length %" PRId64, + ArrowTypeString(array_view->storage_type), last_offset, + array_view->children[0]->length); + return EINVAL; + } + } + break; + + case NANOARROW_TYPE_RUN_END_ENCODED: { + struct ArrowArrayView* run_ends_view = array_view->children[0]; + if (run_ends_view->length == 0) { + break; + } + + int64_t first_run_end = ArrowArrayViewGetIntUnsafe(run_ends_view, 0); + if (first_run_end < 1) { + ArrowErrorSet( + error, + "All run ends must be greater than 0 but the first run end is %" PRId64, + first_run_end); + return EINVAL; + } + + // offset + length < INT64_MAX is checked in ArrowArrayViewValidateMinimal() + int64_t last_run_end = + ArrowArrayViewGetIntUnsafe(run_ends_view, run_ends_view->length - 1); + if (last_run_end < offset_plus_length) { + ArrowErrorSet(error, + "Last run end is %" PRId64 " but it should be >= (%" PRId64 + " + %" PRId64 ")", + last_run_end, array_view->offset, array_view->length); + return EINVAL; + } + break; + } + default: + break; + } + + // Recurse for children + for (int64_t i = 0; i < array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayViewValidateDefault(array_view->children[i], error)); + } + + // Recurse for dictionary + if (array_view->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateDefault(array_view->dictionary, error)); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayViewSetArray(struct ArrowArrayView* array_view, + const struct ArrowArray* array, + struct ArrowError* error) { + // Extract information from the array into the array view + NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view, array, error)); + + // Run default validation. Because we've marked all non-NULL buffers as having unknown + // size, validation will also update the buffer sizes as it goes. + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateDefault(array_view, error)); + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayViewSetArrayMinimal(struct ArrowArrayView* array_view, + const struct ArrowArray* array, + struct ArrowError* error) { + // Extract information from the array into the array view + NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view, array, error)); + + // Run default validation. Because we've marked all non-NULL buffers as having unknown + // size, validation will also update the buffer sizes as it goes. + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateMinimal(array_view, error)); + + return NANOARROW_OK; +} + +static int ArrowAssertIncreasingInt32(struct ArrowBufferView view, + struct ArrowError* error) { + if (view.size_bytes <= (int64_t)sizeof(int32_t)) { + return NANOARROW_OK; + } + + for (int64_t i = 1; i < view.size_bytes / (int64_t)sizeof(int32_t); i++) { + if (view.data.as_int32[i] < view.data.as_int32[i - 1]) { + ArrowErrorSet(error, "[%" PRId64 "] Expected element size >= 0", i); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static int ArrowAssertIncreasingInt64(struct ArrowBufferView view, + struct ArrowError* error) { + if (view.size_bytes <= (int64_t)sizeof(int64_t)) { + return NANOARROW_OK; + } + + for (int64_t i = 1; i < view.size_bytes / (int64_t)sizeof(int64_t); i++) { + if (view.data.as_int64[i] < view.data.as_int64[i - 1]) { + ArrowErrorSet(error, "[%" PRId64 "] Expected element size >= 0", i); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static int ArrowAssertRangeInt8(struct ArrowBufferView view, int8_t min_value, + int8_t max_value, struct ArrowError* error) { + for (int64_t i = 0; i < view.size_bytes; i++) { + if (view.data.as_int8[i] < min_value || view.data.as_int8[i] > max_value) { + ArrowErrorSet(error, + "[%" PRId64 "] Expected buffer value between %" PRId8 " and %" PRId8 + " but found value %" PRId8, + i, min_value, max_value, view.data.as_int8[i]); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static int ArrowAssertInt8In(struct ArrowBufferView view, const int8_t* values, + int64_t n_values, struct ArrowError* error) { + for (int64_t i = 0; i < view.size_bytes; i++) { + int item_found = 0; + for (int64_t j = 0; j < n_values; j++) { + if (view.data.as_int8[i] == values[j]) { + item_found = 1; + break; + } + } + + if (!item_found) { + ArrowErrorSet(error, "[%" PRId64 "] Unexpected buffer value %" PRId8, i, + view.data.as_int8[i]); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static int ArrowArrayViewValidateFull(struct ArrowArrayView* array_view, + struct ArrowError* error) { + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + switch (array_view->layout.buffer_type[i]) { + // Only validate the portion of the buffer that is strictly required, + // which includes not validating the offset buffer of a zero-length array. + case NANOARROW_BUFFER_TYPE_DATA_OFFSET: + if (array_view->length == 0) { + continue; + } + if (array_view->layout.element_size_bits[i] == 32) { + struct ArrowBufferView sliced_offsets; + sliced_offsets.data.as_int32 = + array_view->buffer_views[i].data.as_int32 + array_view->offset; + sliced_offsets.size_bytes = (array_view->length + 1) * sizeof(int32_t); + NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt32(sliced_offsets, error)); + } else { + struct ArrowBufferView sliced_offsets; + sliced_offsets.data.as_int64 = + array_view->buffer_views[i].data.as_int64 + array_view->offset; + sliced_offsets.size_bytes = (array_view->length + 1) * sizeof(int64_t); + NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt64(sliced_offsets, error)); + } + break; + default: + break; + } + } + + if (array_view->storage_type == NANOARROW_TYPE_DENSE_UNION || + array_view->storage_type == NANOARROW_TYPE_SPARSE_UNION) { + struct ArrowBufferView sliced_type_ids; + sliced_type_ids.size_bytes = array_view->length * sizeof(int8_t); + if (array_view->length > 0) { + sliced_type_ids.data.as_int8 = + array_view->buffer_views[0].data.as_int8 + array_view->offset; + } else { + sliced_type_ids.data.as_int8 = NULL; + } + + if (array_view->union_type_id_map == NULL) { + // If the union_type_id map is NULL (e.g., when using ArrowArrayInitFromType() + + // ArrowArrayAllocateChildren() + ArrowArrayFinishBuilding()), we don't have enough + // information to validate this buffer. + ArrowErrorSet(error, + "Insufficient information provided for validation of union array"); + return EINVAL; + } else if (_ArrowParsedUnionTypeIdsWillEqualChildIndices( + array_view->union_type_id_map, array_view->n_children, + array_view->n_children)) { + NANOARROW_RETURN_NOT_OK(ArrowAssertRangeInt8( + sliced_type_ids, 0, (int8_t)(array_view->n_children - 1), error)); + } else { + NANOARROW_RETURN_NOT_OK(ArrowAssertInt8In(sliced_type_ids, + array_view->union_type_id_map + 128, + array_view->n_children, error)); + } + } + + if (array_view->storage_type == NANOARROW_TYPE_DENSE_UNION && + array_view->union_type_id_map != NULL) { + // Check that offsets refer to child elements that actually exist + for (int64_t i = 0; i < array_view->length; i++) { + int8_t child_id = ArrowArrayViewUnionChildIndex(array_view, i); + int64_t offset = ArrowArrayViewUnionChildOffset(array_view, i); + int64_t child_length = array_view->children[child_id]->length; + if (offset < 0 || offset > child_length) { + ArrowErrorSet(error, + "[%" PRId64 "] Expected union offset for child id %" PRId8 + " to be between 0 and %" PRId64 + " but " + "found offset value %" PRId64, + i, child_id, child_length, offset); + return EINVAL; + } + } + } + + if (array_view->storage_type == NANOARROW_TYPE_RUN_END_ENCODED) { + struct ArrowArrayView* run_ends_view = array_view->children[0]; + if (run_ends_view->length > 0) { + int64_t last_run_end = ArrowArrayViewGetIntUnsafe(run_ends_view, 0); + for (int64_t i = 1; i < run_ends_view->length; i++) { + const int64_t run_end = ArrowArrayViewGetIntUnsafe(run_ends_view, i); + if (run_end <= last_run_end) { + ArrowErrorSet( + error, + "Every run end must be strictly greater than the previous run end, " + "but run_ends[%" PRId64 " is %" PRId64 " and run_ends[%" PRId64 + "] is %" PRId64, + i, run_end, i - 1, last_run_end); + return EINVAL; + } + last_run_end = run_end; + } + } + } + + if (array_view->storage_type == NANOARROW_TYPE_LIST_VIEW || + array_view->storage_type == NANOARROW_TYPE_LARGE_LIST_VIEW) { + int64_t child_len = array_view->children[0]->length; + + struct ArrowBufferView offsets, sizes; + offsets.data.data = array_view->buffer_views[1].data.data; + sizes.data.data = array_view->buffer_views[2].data.data; + + for (int64_t i = array_view->offset; i < array_view->length + array_view->offset; + i++) { + int64_t offset, size; + if (array_view->storage_type == NANOARROW_TYPE_LIST_VIEW) { + offset = offsets.data.as_int32[i]; + size = sizes.data.as_int32[i]; + } else { + offset = offsets.data.as_int64[i]; + size = sizes.data.as_int64[i]; + } + + if (offset < 0) { + ArrowErrorSet(error, "Invalid negative offset %" PRId64 " at index %" PRId64, + offset, i); + return EINVAL; + } + + if (size < 0) { + ArrowErrorSet(error, "Invalid negative size %" PRId64 " at index %" PRId64, size, + i); + return EINVAL; + } + + if ((offset + size) > child_len) { + ArrowErrorSet(error, + "Offset: %" PRId64 " + size: %" PRId64 " at index: %" PRId64 + " exceeds length of child view: %" PRId64, + offset, size, i, child_len); + return EINVAL; + } + } + } + + // Recurse for children + for (int64_t i = 0; i < array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateFull(array_view->children[i], error)); + } + + // Dictionary validation not implemented + if (array_view->dictionary != NULL) { + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateFull(array_view->dictionary, error)); + // TODO: validate the indices + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowArrayViewValidate(struct ArrowArrayView* array_view, + enum ArrowValidationLevel validation_level, + struct ArrowError* error) { + switch (validation_level) { + case NANOARROW_VALIDATION_LEVEL_NONE: + return NANOARROW_OK; + case NANOARROW_VALIDATION_LEVEL_MINIMAL: + return ArrowArrayViewValidateMinimal(array_view, error); + case NANOARROW_VALIDATION_LEVEL_DEFAULT: + return ArrowArrayViewValidateDefault(array_view, error); + case NANOARROW_VALIDATION_LEVEL_FULL: + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidateDefault(array_view, error)); + return ArrowArrayViewValidateFull(array_view, error); + } + + ArrowErrorSet(error, "validation_level not recognized"); + return EINVAL; +} + +struct ArrowComparisonInternalState { + enum ArrowCompareLevel level; + int is_equal; + struct ArrowError* reason; +}; + +NANOARROW_CHECK_PRINTF_ATTRIBUTE static void ArrowComparePrependPath( + struct ArrowError* out, const char* fmt, ...) { + if (out == NULL) { + return; + } + + char prefix[128]; + prefix[0] = '\0'; + va_list args; + va_start(args, fmt); + int prefix_len = vsnprintf(prefix, sizeof(prefix), fmt, args); + va_end(args); + + if (prefix_len <= 0) { + return; + } + + size_t out_len = strlen(out->message); + size_t out_len_to_move = sizeof(struct ArrowError) - prefix_len - 1; + if (out_len_to_move > out_len) { + out_len_to_move = out_len; + } + + memmove(out->message + prefix_len, out->message, out_len_to_move); + memcpy(out->message, prefix, prefix_len); + out->message[out_len + prefix_len] = '\0'; +} + +#define SET_NOT_EQUAL_AND_RETURN_IF_IMPL(cond_, state_, reason_) \ + do { \ + if (cond_) { \ + ArrowErrorSet(state_->reason, ": %s", reason_); \ + state_->is_equal = 0; \ + return; \ + } \ + } while (0) + +#define SET_NOT_EQUAL_AND_RETURN_IF(condition_, state_) \ + SET_NOT_EQUAL_AND_RETURN_IF_IMPL(condition_, state_, #condition_) + +static void ArrowArrayViewCompareBuffer(const struct ArrowArrayView* actual, + const struct ArrowArrayView* expected, int i, + struct ArrowComparisonInternalState* state) { + SET_NOT_EQUAL_AND_RETURN_IF( + actual->buffer_views[i].size_bytes != expected->buffer_views[i].size_bytes, state); + + int64_t buffer_size = actual->buffer_views[i].size_bytes; + if (buffer_size > 0) { + SET_NOT_EQUAL_AND_RETURN_IF( + memcmp(actual->buffer_views[i].data.data, expected->buffer_views[i].data.data, + buffer_size) != 0, + state); + } +} + +static void ArrowArrayViewCompareIdentical(const struct ArrowArrayView* actual, + const struct ArrowArrayView* expected, + struct ArrowComparisonInternalState* state) { + SET_NOT_EQUAL_AND_RETURN_IF(actual->storage_type != expected->storage_type, state); + SET_NOT_EQUAL_AND_RETURN_IF(actual->n_children != expected->n_children, state); + SET_NOT_EQUAL_AND_RETURN_IF(actual->dictionary == NULL && expected->dictionary != NULL, + state); + SET_NOT_EQUAL_AND_RETURN_IF(actual->dictionary != NULL && expected->dictionary == NULL, + state); + + SET_NOT_EQUAL_AND_RETURN_IF(actual->length != expected->length, state); + SET_NOT_EQUAL_AND_RETURN_IF(actual->offset != expected->offset, state); + SET_NOT_EQUAL_AND_RETURN_IF(actual->null_count != expected->null_count, state); + + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + ArrowArrayViewCompareBuffer(actual, expected, i, state); + if (!state->is_equal) { + ArrowComparePrependPath(state->reason, ".buffers[%d]", i); + return; + } + } + + for (int64_t i = 0; i < actual->n_children; i++) { + ArrowArrayViewCompareIdentical(actual->children[i], expected->children[i], state); + if (!state->is_equal) { + ArrowComparePrependPath(state->reason, ".children[%" PRId64 "]", i); + return; + } + } + + if (actual->dictionary != NULL) { + ArrowArrayViewCompareIdentical(actual->dictionary, expected->dictionary, state); + if (!state->is_equal) { + ArrowComparePrependPath(state->reason, ".dictionary"); + return; + } + } +} + +// Top-level entry point to take care of creating, cleaning up, and +// propagating the ArrowComparisonInternalState to the caller +ArrowErrorCode ArrowArrayViewCompare(const struct ArrowArrayView* actual, + const struct ArrowArrayView* expected, + enum ArrowCompareLevel level, int* out, + struct ArrowError* reason) { + struct ArrowComparisonInternalState state; + state.level = level; + state.is_equal = 1; + state.reason = reason; + + switch (level) { + case NANOARROW_COMPARE_IDENTICAL: + ArrowArrayViewCompareIdentical(actual, expected, &state); + break; + default: + return EINVAL; + } + + *out = state.is_equal; + if (!state.is_equal) { + ArrowComparePrependPath(state.reason, "root"); + } + + return NANOARROW_OK; +} + +#undef SET_NOT_EQUAL_AND_RETURN_IF +#undef SET_NOT_EQUAL_AND_RETURN_IF_IMPL +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "nanoarrow/nanoarrow.h" + +struct BasicArrayStreamPrivate { + struct ArrowSchema schema; + int64_t n_arrays; + struct ArrowArray* arrays; + int64_t arrays_i; +}; + +static int ArrowBasicArrayStreamGetSchema(struct ArrowArrayStream* array_stream, + struct ArrowSchema* schema) { + if (array_stream == NULL || array_stream->release == NULL) { + return EINVAL; + } + + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)array_stream->private_data; + return ArrowSchemaDeepCopy(&private_data->schema, schema); +} + +static int ArrowBasicArrayStreamGetNext(struct ArrowArrayStream* array_stream, + struct ArrowArray* array) { + if (array_stream == NULL || array_stream->release == NULL) { + return EINVAL; + } + + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)array_stream->private_data; + + if (private_data->arrays_i == private_data->n_arrays) { + array->release = NULL; + return NANOARROW_OK; + } + + ArrowArrayMove(&private_data->arrays[private_data->arrays_i++], array); + return NANOARROW_OK; +} + +static const char* ArrowBasicArrayStreamGetLastError( + struct ArrowArrayStream* array_stream) { + NANOARROW_UNUSED(array_stream); + return NULL; +} + +static void ArrowBasicArrayStreamRelease(struct ArrowArrayStream* array_stream) { + if (array_stream == NULL || array_stream->release == NULL) { + return; + } + + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)array_stream->private_data; + + if (private_data->schema.release != NULL) { + ArrowSchemaRelease(&private_data->schema); + } + + for (int64_t i = 0; i < private_data->n_arrays; i++) { + if (private_data->arrays[i].release != NULL) { + ArrowArrayRelease(&private_data->arrays[i]); + } + } + + if (private_data->arrays != NULL) { + ArrowFree(private_data->arrays); + } + + ArrowFree(private_data); + array_stream->release = NULL; +} + +ArrowErrorCode ArrowBasicArrayStreamInit(struct ArrowArrayStream* array_stream, + struct ArrowSchema* schema, int64_t n_arrays) { + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)ArrowMalloc( + sizeof(struct BasicArrayStreamPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + ArrowSchemaMove(schema, &private_data->schema); + + private_data->n_arrays = n_arrays; + private_data->arrays = NULL; + private_data->arrays_i = 0; + + if (n_arrays > 0) { + private_data->arrays = + (struct ArrowArray*)ArrowMalloc(n_arrays * sizeof(struct ArrowArray)); + if (private_data->arrays == NULL) { + ArrowBasicArrayStreamRelease(array_stream); + ArrowFree(private_data); + return ENOMEM; + } + } + + for (int64_t i = 0; i < private_data->n_arrays; i++) { + private_data->arrays[i].release = NULL; + } + + array_stream->get_schema = &ArrowBasicArrayStreamGetSchema; + array_stream->get_next = &ArrowBasicArrayStreamGetNext; + array_stream->get_last_error = ArrowBasicArrayStreamGetLastError; + array_stream->release = ArrowBasicArrayStreamRelease; + array_stream->private_data = private_data; + return NANOARROW_OK; +} + +void ArrowBasicArrayStreamSetArray(struct ArrowArrayStream* array_stream, int64_t i, + struct ArrowArray* array) { + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)array_stream->private_data; + ArrowArrayMove(array, &private_data->arrays[i]); +} + +ArrowErrorCode ArrowBasicArrayStreamValidate(const struct ArrowArrayStream* array_stream, + struct ArrowError* error) { + struct BasicArrayStreamPrivate* private_data = + (struct BasicArrayStreamPrivate*)array_stream->private_data; + + struct ArrowArrayView array_view; + NANOARROW_RETURN_NOT_OK( + ArrowArrayViewInitFromSchema(&array_view, &private_data->schema, error)); + + for (int64_t i = 0; i < private_data->n_arrays; i++) { + if (private_data->arrays[i].release != NULL) { + int result = ArrowArrayViewSetArray(&array_view, &private_data->arrays[i], error); + if (result != NANOARROW_OK) { + ArrowArrayViewReset(&array_view); + return result; + } + } + } + + ArrowArrayViewReset(&array_view); + return NANOARROW_OK; +} diff --git a/third_party/nanoarrow/src/nanoarrow_ipc.c b/third_party/nanoarrow/src/nanoarrow_ipc.c new file mode 100644 index 0000000..083dfe9 --- /dev/null +++ b/third_party/nanoarrow/src/nanoarrow_ipc.c @@ -0,0 +1,29562 @@ +#ifndef FLATBUFFERS_COMMON_READER_H +#define FLATBUFFERS_COMMON_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +/* Common FlatBuffers read functionality for C. */ + +#include "flatcc/flatcc_prologue.h" +#include "flatcc/flatcc_flatbuffers.h" + + +#define __flatbuffers_read_scalar_at_byteoffset(N, p, o) N ## _read_from_pe((uint8_t *)(p) + (o)) +#define __flatbuffers_read_scalar(N, p) N ## _read_from_pe(p) +#define __flatbuffers_read_vt(ID, offset, t)\ +flatbuffers_voffset_t offset = 0;\ +{ flatbuffers_voffset_t id__tmp, *vt__tmp;\ + FLATCC_ASSERT(t != 0 && "null pointer table access");\ + id__tmp = ID;\ + vt__tmp = (flatbuffers_voffset_t *)((uint8_t *)(t) -\ + __flatbuffers_soffset_read_from_pe(t));\ + if (__flatbuffers_voffset_read_from_pe(vt__tmp) >= sizeof(vt__tmp[0]) * (id__tmp + 3u)) {\ + offset = __flatbuffers_voffset_read_from_pe(vt__tmp + id__tmp + 2);\ + }\ +} +#define __flatbuffers_field_present(ID, t) { __flatbuffers_read_vt(ID, offset__tmp, t) return offset__tmp != 0; } +#define __flatbuffers_scalar_field(T, ID, t)\ +{\ + __flatbuffers_read_vt(ID, offset__tmp, t)\ + if (offset__tmp) {\ + return (const T *)((uint8_t *)(t) + offset__tmp);\ + }\ + return 0;\ +} +#define __flatbuffers_define_scalar_field(ID, N, NK, TK, T, V)\ +static inline T N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +{ __flatbuffers_read_vt(ID, offset__tmp, t__tmp)\ + return offset__tmp ? __flatbuffers_read_scalar_at_byteoffset(TK, t__tmp, offset__tmp) : V;\ +}\ +static inline T N ## _ ## NK(N ## _table_t t__tmp)\ +{ __flatbuffers_read_vt(ID, offset__tmp, t__tmp)\ + return offset__tmp ? __flatbuffers_read_scalar_at_byteoffset(TK, t__tmp, offset__tmp) : V;\ +}\ +static inline const T *N ## _ ## NK ## _get_ptr(N ## _table_t t__tmp)\ +__flatbuffers_scalar_field(T, ID, t__tmp)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__flatbuffers_field_present(ID, t__tmp)\ +__flatbuffers_define_scan_by_scalar_field(N, NK, T) +#define __flatbuffers_define_scalar_optional_field(ID, N, NK, TK, T, V)\ +__flatbuffers_define_scalar_field(ID, N, NK, TK, T, V)\ +static inline TK ## _option_t N ## _ ## NK ## _option(N ## _table_t t__tmp)\ +{ TK ## _option_t ret; __flatbuffers_read_vt(ID, offset__tmp, t__tmp)\ + ret.is_null = offset__tmp == 0; ret.value = offset__tmp ?\ + __flatbuffers_read_scalar_at_byteoffset(TK, t__tmp, offset__tmp) : V;\ + return ret; } +#define __flatbuffers_struct_field(T, ID, t, r)\ +{\ + __flatbuffers_read_vt(ID, offset__tmp, t)\ + if (offset__tmp) {\ + return (T)((uint8_t *)(t) + offset__tmp);\ + }\ + FLATCC_ASSERT(!(r) && "required field missing");\ + return 0;\ +} +#define __flatbuffers_offset_field(T, ID, t, r, adjust)\ +{\ + flatbuffers_uoffset_t *elem__tmp;\ + __flatbuffers_read_vt(ID, offset__tmp, t)\ + if (offset__tmp) {\ + elem__tmp = (flatbuffers_uoffset_t *)((uint8_t *)(t) + offset__tmp);\ + /* Add sizeof so C api can have raw access past header field. */\ + return (T)((uint8_t *)(elem__tmp) + adjust +\ + __flatbuffers_uoffset_read_from_pe(elem__tmp));\ + }\ + FLATCC_ASSERT(!(r) && "required field missing");\ + return 0;\ +} +#define __flatbuffers_vector_field(T, ID, t, r) __flatbuffers_offset_field(T, ID, t, r, sizeof(flatbuffers_uoffset_t)) +#define __flatbuffers_table_field(T, ID, t, r) __flatbuffers_offset_field(T, ID, t, r, 0) +#define __flatbuffers_define_struct_field(ID, N, NK, T, r)\ +static inline T N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +__flatbuffers_struct_field(T, ID, t__tmp, r)\ +static inline T N ## _ ## NK(N ## _table_t t__tmp)\ +__flatbuffers_struct_field(T, ID, t__tmp, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__flatbuffers_field_present(ID, t__tmp) +#define __flatbuffers_define_vector_field(ID, N, NK, T, r)\ +static inline T N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +__flatbuffers_vector_field(T, ID, t__tmp, r)\ +static inline T N ## _ ## NK(N ## _table_t t__tmp)\ +__flatbuffers_vector_field(T, ID, t__tmp, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__flatbuffers_field_present(ID, t__tmp) +#define __flatbuffers_define_table_field(ID, N, NK, T, r)\ +static inline T N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +__flatbuffers_table_field(T, ID, t__tmp, r)\ +static inline T N ## _ ## NK(N ## _table_t t__tmp)\ +__flatbuffers_table_field(T, ID, t__tmp, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__flatbuffers_field_present(ID, t__tmp) +#define __flatbuffers_define_string_field(ID, N, NK, r)\ +static inline flatbuffers_string_t N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +__flatbuffers_vector_field(flatbuffers_string_t, ID, t__tmp, r)\ +static inline flatbuffers_string_t N ## _ ## NK(N ## _table_t t__tmp)\ +__flatbuffers_vector_field(flatbuffers_string_t, ID, t__tmp, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__flatbuffers_field_present(ID, t__tmp)\ +__flatbuffers_define_scan_by_string_field(N, NK) +#define __flatbuffers_vec_len(vec)\ +{ return (vec) ? (size_t)__flatbuffers_uoffset_read_from_pe((flatbuffers_uoffset_t *)vec - 1) : 0; } +#define __flatbuffers_string_len(s) __flatbuffers_vec_len(s) +static inline size_t flatbuffers_vec_len(const void *vec) +__flatbuffers_vec_len(vec) +#define __flatbuffers_scalar_vec_at(N, vec, i)\ +{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\ + return __flatbuffers_read_scalar(N, &(vec)[i]); } +#define __flatbuffers_struct_vec_at(vec, i)\ +{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range"); return (vec) + (i); } +/* `adjust` skips past the header for string vectors. */ +#define __flatbuffers_offset_vec_at(T, vec, i, adjust)\ +{ const flatbuffers_uoffset_t *elem__tmp = (vec) + (i);\ + FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\ + return (T)((uint8_t *)(elem__tmp) + (size_t)__flatbuffers_uoffset_read_from_pe(elem__tmp) + (adjust)); } +#define __flatbuffers_define_scalar_vec_len(N)\ +static inline size_t N ## _vec_len(N ##_vec_t vec__tmp)\ +{ return flatbuffers_vec_len(vec__tmp); } +#define __flatbuffers_define_scalar_vec_at(N, T) \ +static inline T N ## _vec_at(N ## _vec_t vec__tmp, size_t i__tmp)\ +__flatbuffers_scalar_vec_at(N, vec__tmp, i__tmp) +typedef const char *flatbuffers_string_t; +static inline size_t flatbuffers_string_len(flatbuffers_string_t s) +__flatbuffers_string_len(s) +typedef const flatbuffers_uoffset_t *flatbuffers_string_vec_t; +typedef flatbuffers_uoffset_t *flatbuffers_string_mutable_vec_t; +static inline size_t flatbuffers_string_vec_len(flatbuffers_string_vec_t vec) +__flatbuffers_vec_len(vec) +static inline flatbuffers_string_t flatbuffers_string_vec_at(flatbuffers_string_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(flatbuffers_string_t, vec, i, sizeof(vec[0])) +typedef const void *flatbuffers_generic_t; +typedef void *flatbuffers_mutable_generic_t; +static inline flatbuffers_string_t flatbuffers_string_cast_from_generic(const flatbuffers_generic_t p) +{ return p ? ((const char *)p) + __flatbuffers_uoffset__size() : 0; } +typedef const flatbuffers_uoffset_t *flatbuffers_generic_vec_t; +typedef flatbuffers_uoffset_t *flatbuffers_generic_table_mutable_vec_t; +static inline size_t flatbuffers_generic_vec_len(flatbuffers_generic_vec_t vec) +__flatbuffers_vec_len(vec) +static inline flatbuffers_generic_t flatbuffers_generic_vec_at(flatbuffers_generic_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(flatbuffers_generic_t, vec, i, 0) +static inline flatbuffers_generic_t flatbuffers_generic_vec_at_as_string(flatbuffers_generic_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(flatbuffers_generic_t, vec, i, sizeof(vec[0])) +typedef struct flatbuffers_union { + flatbuffers_union_type_t type; + flatbuffers_generic_t value; +} flatbuffers_union_t; +typedef struct flatbuffers_union_vec { + const flatbuffers_union_type_t *type; + const flatbuffers_uoffset_t *value; +} flatbuffers_union_vec_t; +typedef struct flatbuffers_mutable_union { + flatbuffers_union_type_t type; + flatbuffers_mutable_generic_t value; +} flatbuffers_mutable_union_t; +typedef struct flatbuffers_mutable_union_vec { + flatbuffers_union_type_t *type; + flatbuffers_uoffset_t *value; +} flatbuffers_mutable_union_vec_t; +static inline flatbuffers_mutable_union_t flatbuffers_mutable_union_cast(flatbuffers_union_t u__tmp)\ +{ flatbuffers_mutable_union_t mu = { u__tmp.type, (flatbuffers_mutable_generic_t)u__tmp.value };\ + return mu; } +static inline flatbuffers_mutable_union_vec_t flatbuffers_mutable_union_vec_cast(flatbuffers_union_vec_t uv__tmp)\ +{ flatbuffers_mutable_union_vec_t muv =\ + { (flatbuffers_union_type_t *)uv__tmp.type, (flatbuffers_uoffset_t *)uv__tmp.value }; return muv; } +#define __flatbuffers_union_type_field(ID, t)\ +{\ + __flatbuffers_read_vt(ID, offset__tmp, t)\ + return offset__tmp ? __flatbuffers_read_scalar_at_byteoffset(__flatbuffers_utype, t, offset__tmp) : 0;\ +} +static inline flatbuffers_string_t flatbuffers_string_cast_from_union(const flatbuffers_union_t u__tmp)\ +{ return flatbuffers_string_cast_from_generic(u__tmp.value); } +#define __flatbuffers_define_union_field(NS, ID, N, NK, T, r)\ +static inline T ## _union_type_t N ## _ ## NK ## _type_get(N ## _table_t t__tmp)\ +__## NS ## union_type_field(((ID) - 1), t__tmp)\ +static inline NS ## generic_t N ## _ ## NK ## _get(N ## _table_t t__tmp)\ +__## NS ## table_field(NS ## generic_t, ID, t__tmp, r)\ +static inline T ## _union_type_t N ## _ ## NK ## _type(N ## _table_t t__tmp)\ +__## NS ## union_type_field(((ID) - 1), t__tmp)\ +static inline NS ## generic_t N ## _ ## NK(N ## _table_t t__tmp)\ +__## NS ## table_field(NS ## generic_t, ID, t__tmp, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t__tmp)\ +__## NS ## field_present(ID, t__tmp)\ +static inline T ## _union_t N ## _ ## NK ## _union(N ## _table_t t__tmp)\ +{ T ## _union_t u__tmp = { 0, 0 }; u__tmp.type = N ## _ ## NK ## _type_get(t__tmp);\ + if (u__tmp.type == 0) return u__tmp; u__tmp.value = N ## _ ## NK ## _get(t__tmp); return u__tmp; }\ +static inline NS ## string_t N ## _ ## NK ## _as_string(N ## _table_t t__tmp)\ +{ return NS ## string_cast_from_generic(N ## _ ## NK ## _get(t__tmp)); }\ + +#define __flatbuffers_define_union_vector_ops(NS, T)\ +static inline size_t T ## _union_vec_len(T ## _union_vec_t uv__tmp)\ +{ return NS ## vec_len(uv__tmp.type); }\ +static inline T ## _union_t T ## _union_vec_at(T ## _union_vec_t uv__tmp, size_t i__tmp)\ +{ T ## _union_t u__tmp = { 0, 0 }; size_t n__tmp = NS ## vec_len(uv__tmp.type);\ + FLATCC_ASSERT(n__tmp > (i__tmp) && "index out of range"); u__tmp.type = uv__tmp.type[i__tmp];\ + /* Unknown type is treated as NONE for schema evolution. */\ + if (u__tmp.type == 0) return u__tmp;\ + u__tmp.value = NS ## generic_vec_at(uv__tmp.value, i__tmp); return u__tmp; }\ +static inline NS ## string_t T ## _union_vec_at_as_string(T ## _union_vec_t uv__tmp, size_t i__tmp)\ +{ return (NS ## string_t) NS ## generic_vec_at_as_string(uv__tmp.value, i__tmp); }\ + +#define __flatbuffers_define_union_vector(NS, T)\ +typedef NS ## union_vec_t T ## _union_vec_t;\ +typedef NS ## mutable_union_vec_t T ## _mutable_union_vec_t;\ +static inline T ## _mutable_union_vec_t T ## _mutable_union_vec_cast(T ## _union_vec_t u__tmp)\ +{ return NS ## mutable_union_vec_cast(u__tmp); }\ +__## NS ## define_union_vector_ops(NS, T) +#define __flatbuffers_define_union(NS, T)\ +typedef NS ## union_t T ## _union_t;\ +typedef NS ## mutable_union_t T ## _mutable_union_t;\ +static inline T ## _mutable_union_t T ## _mutable_union_cast(T ## _union_t u__tmp)\ +{ return NS ## mutable_union_cast(u__tmp); }\ +__## NS ## define_union_vector(NS, T) +#define __flatbuffers_define_union_vector_field(NS, ID, N, NK, T, r)\ +__## NS ## define_vector_field(ID - 1, N, NK ## _type, T ## _vec_t, r)\ +__## NS ## define_vector_field(ID, N, NK, flatbuffers_generic_vec_t, r)\ +static inline T ## _union_vec_t N ## _ ## NK ## _union(N ## _table_t t__tmp)\ +{ T ## _union_vec_t uv__tmp; uv__tmp.type = N ## _ ## NK ## _type_get(t__tmp);\ + uv__tmp.value = N ## _ ## NK(t__tmp);\ + FLATCC_ASSERT(NS ## vec_len(uv__tmp.type) == NS ## vec_len(uv__tmp.value)\ + && "union vector type length mismatch"); return uv__tmp; } +#include +static const size_t flatbuffers_not_found = (size_t)-1; +static const size_t flatbuffers_end = (size_t)-1; +#define __flatbuffers_identity(n) (n) +#define __flatbuffers_min(a, b) ((a) < (b) ? (a) : (b)) +/* Subtraction doesn't work for unsigned types. */ +#define __flatbuffers_scalar_cmp(x, y, n) ((x) < (y) ? -1 : (x) > (y)) +static inline int __flatbuffers_string_n_cmp(flatbuffers_string_t v, const char *s, size_t n) +{ size_t nv = flatbuffers_string_len(v); int x = strncmp(v, s, nv < n ? nv : n); + return x != 0 ? x : nv < n ? -1 : nv > n; } +/* `n` arg unused, but needed by string find macro expansion. */ +static inline int __flatbuffers_string_cmp(flatbuffers_string_t v, const char *s, size_t n) { (void)n; return strcmp(v, s); } +/* A = identity if searching scalar vectors rather than key fields. */ +/* Returns lowest matching index or not_found. */ +#define __flatbuffers_find_by_field(A, V, E, L, K, Kn, T, D)\ +{ T v__tmp; size_t a__tmp = 0, b__tmp, m__tmp; if (!(b__tmp = L(V))) { return flatbuffers_not_found; }\ + --b__tmp;\ + while (a__tmp < b__tmp) {\ + m__tmp = a__tmp + ((b__tmp - a__tmp) >> 1);\ + v__tmp = A(E(V, m__tmp));\ + if ((D(v__tmp, (K), (Kn))) < 0) {\ + a__tmp = m__tmp + 1;\ + } else {\ + b__tmp = m__tmp;\ + }\ + }\ + if (a__tmp == b__tmp) {\ + v__tmp = A(E(V, a__tmp));\ + if (D(v__tmp, (K), (Kn)) == 0) {\ + return a__tmp;\ + }\ + }\ + return flatbuffers_not_found;\ +} +#define __flatbuffers_find_by_scalar_field(A, V, E, L, K, T)\ +__flatbuffers_find_by_field(A, V, E, L, K, 0, T, __flatbuffers_scalar_cmp) +#define __flatbuffers_find_by_string_field(A, V, E, L, K)\ +__flatbuffers_find_by_field(A, V, E, L, K, 0, flatbuffers_string_t, __flatbuffers_string_cmp) +#define __flatbuffers_find_by_string_n_field(A, V, E, L, K, Kn)\ +__flatbuffers_find_by_field(A, V, E, L, K, Kn, flatbuffers_string_t, __flatbuffers_string_n_cmp) +#define __flatbuffers_define_find_by_scalar_field(N, NK, TK)\ +static inline size_t N ## _vec_find_by_ ## NK(N ## _vec_t vec__tmp, TK key__tmp)\ +__flatbuffers_find_by_scalar_field(N ## _ ## NK, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, TK) +#define __flatbuffers_define_scalar_find(N, T)\ +static inline size_t N ## _vec_find(N ## _vec_t vec__tmp, T key__tmp)\ +__flatbuffers_find_by_scalar_field(__flatbuffers_identity, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T) +#define __flatbuffers_define_find_by_string_field(N, NK) \ +/* Note: find only works on vectors sorted by this field. */\ +static inline size_t N ## _vec_find_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp)\ +__flatbuffers_find_by_string_field(N ## _ ## NK, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp)\ +static inline size_t N ## _vec_find_n_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +__flatbuffers_find_by_string_n_field(N ## _ ## NK, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp, n__tmp) +#define __flatbuffers_define_default_find_by_scalar_field(N, NK, TK)\ +static inline size_t N ## _vec_find(N ## _vec_t vec__tmp, TK key__tmp)\ +{ return N ## _vec_find_by_ ## NK(vec__tmp, key__tmp); } +#define __flatbuffers_define_default_find_by_string_field(N, NK) \ +static inline size_t N ## _vec_find(N ## _vec_t vec__tmp, const char *s__tmp)\ +{ return N ## _vec_find_by_ ## NK(vec__tmp, s__tmp); }\ +static inline size_t N ## _vec_find_n(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +{ return N ## _vec_find_n_by_ ## NK(vec__tmp, s__tmp, n__tmp); } +/* A = identity if searching scalar vectors rather than key fields. */ +/* Returns lowest matching index or not_found. */ +#define __flatbuffers_scan_by_field(b, e, A, V, E, L, K, Kn, T, D)\ +{ T v__tmp; size_t i__tmp;\ + for (i__tmp = b; i__tmp < e; ++i__tmp) {\ + v__tmp = A(E(V, i__tmp));\ + if (D(v__tmp, (K), (Kn)) == 0) {\ + return i__tmp;\ + }\ + }\ + return flatbuffers_not_found;\ +} +#define __flatbuffers_rscan_by_field(b, e, A, V, E, L, K, Kn, T, D)\ +{ T v__tmp; size_t i__tmp = e;\ + while (i__tmp-- > b) {\ + v__tmp = A(E(V, i__tmp));\ + if (D(v__tmp, (K), (Kn)) == 0) {\ + return i__tmp;\ + }\ + }\ + return flatbuffers_not_found;\ +} +#define __flatbuffers_scan_by_scalar_field(b, e, A, V, E, L, K, T)\ +__flatbuffers_scan_by_field(b, e, A, V, E, L, K, 0, T, __flatbuffers_scalar_cmp) +#define __flatbuffers_scan_by_string_field(b, e, A, V, E, L, K)\ +__flatbuffers_scan_by_field(b, e, A, V, E, L, K, 0, flatbuffers_string_t, __flatbuffers_string_cmp) +#define __flatbuffers_scan_by_string_n_field(b, e, A, V, E, L, K, Kn)\ +__flatbuffers_scan_by_field(b, e, A, V, E, L, K, Kn, flatbuffers_string_t, __flatbuffers_string_n_cmp) +#define __flatbuffers_rscan_by_scalar_field(b, e, A, V, E, L, K, T)\ +__flatbuffers_rscan_by_field(b, e, A, V, E, L, K, 0, T, __flatbuffers_scalar_cmp) +#define __flatbuffers_rscan_by_string_field(b, e, A, V, E, L, K)\ +__flatbuffers_rscan_by_field(b, e, A, V, E, L, K, 0, flatbuffers_string_t, __flatbuffers_string_cmp) +#define __flatbuffers_rscan_by_string_n_field(b, e, A, V, E, L, K, Kn)\ +__flatbuffers_rscan_by_field(b, e, A, V, E, L, K, Kn, flatbuffers_string_t, __flatbuffers_string_n_cmp) +#define __flatbuffers_define_scan_by_scalar_field(N, NK, T)\ +static inline size_t N ## _vec_scan_by_ ## NK(N ## _vec_t vec__tmp, T key__tmp)\ +__flatbuffers_scan_by_scalar_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_scan_ex_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, T key__tmp)\ +__flatbuffers_scan_by_scalar_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_rscan_by_ ## NK(N ## _vec_t vec__tmp, T key__tmp)\ +__flatbuffers_rscan_by_scalar_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_rscan_ex_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, T key__tmp)\ +__flatbuffers_rscan_by_scalar_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T) +#define __flatbuffers_define_scalar_scan(N, T)\ +static inline size_t N ## _vec_scan(N ## _vec_t vec__tmp, T key__tmp)\ +__flatbuffers_scan_by_scalar_field(0, N ## _vec_len(vec__tmp), __flatbuffers_identity, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_scan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, T key__tmp)\ +__flatbuffers_scan_by_scalar_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), __flatbuffers_identity, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_rscan(N ## _vec_t vec__tmp, T key__tmp)\ +__flatbuffers_rscan_by_scalar_field(0, N ## _vec_len(vec__tmp), __flatbuffers_identity, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T)\ +static inline size_t N ## _vec_rscan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, T key__tmp)\ +__flatbuffers_rscan_by_scalar_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), __flatbuffers_identity, vec__tmp, N ## _vec_at, N ## _vec_len, key__tmp, T) +#define __flatbuffers_define_scan_by_string_field(N, NK) \ +static inline size_t N ## _vec_scan_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp)\ +__flatbuffers_scan_by_string_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp)\ +static inline size_t N ## _vec_scan_n_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +__flatbuffers_scan_by_string_n_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp, n__tmp)\ +static inline size_t N ## _vec_scan_ex_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp)\ +__flatbuffers_scan_by_string_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp)\ +static inline size_t N ## _vec_scan_ex_n_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp, size_t n__tmp)\ +__flatbuffers_scan_by_string_n_field(begin__tmp, __flatbuffers_min( end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp, n__tmp)\ +static inline size_t N ## _vec_rscan_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp)\ +__flatbuffers_rscan_by_string_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp)\ +static inline size_t N ## _vec_rscan_n_by_ ## NK(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +__flatbuffers_rscan_by_string_n_field(0, N ## _vec_len(vec__tmp), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp, n__tmp)\ +static inline size_t N ## _vec_rscan_ex_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp)\ +__flatbuffers_rscan_by_string_field(begin__tmp, __flatbuffers_min(end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp)\ +static inline size_t N ## _vec_rscan_ex_n_by_ ## NK(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp, size_t n__tmp)\ +__flatbuffers_rscan_by_string_n_field(begin__tmp, __flatbuffers_min( end__tmp, N ## _vec_len(vec__tmp)), N ## _ ## NK ## _get, vec__tmp, N ## _vec_at, N ## _vec_len, s__tmp, n__tmp) +#define __flatbuffers_define_default_scan_by_scalar_field(N, NK, TK)\ +static inline size_t N ## _vec_scan(N ## _vec_t vec__tmp, TK key__tmp)\ +{ return N ## _vec_scan_by_ ## NK(vec__tmp, key__tmp); }\ +static inline size_t N ## _vec_scan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, TK key__tmp)\ +{ return N ## _vec_scan_ex_by_ ## NK(vec__tmp, begin__tmp, end__tmp, key__tmp); }\ +static inline size_t N ## _vec_rscan(N ## _vec_t vec__tmp, TK key__tmp)\ +{ return N ## _vec_rscan_by_ ## NK(vec__tmp, key__tmp); }\ +static inline size_t N ## _vec_rscan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, TK key__tmp)\ +{ return N ## _vec_rscan_ex_by_ ## NK(vec__tmp, begin__tmp, end__tmp, key__tmp); } +#define __flatbuffers_define_default_scan_by_string_field(N, NK) \ +static inline size_t N ## _vec_scan(N ## _vec_t vec__tmp, const char *s__tmp)\ +{ return N ## _vec_scan_by_ ## NK(vec__tmp, s__tmp); }\ +static inline size_t N ## _vec_scan_n(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +{ return N ## _vec_scan_n_by_ ## NK(vec__tmp, s__tmp, n__tmp); }\ +static inline size_t N ## _vec_scan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp)\ +{ return N ## _vec_scan_ex_by_ ## NK(vec__tmp, begin__tmp, end__tmp, s__tmp); }\ +static inline size_t N ## _vec_scan_ex_n(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp, size_t n__tmp)\ +{ return N ## _vec_scan_ex_n_by_ ## NK(vec__tmp, begin__tmp, end__tmp, s__tmp, n__tmp); }\ +static inline size_t N ## _vec_rscan(N ## _vec_t vec__tmp, const char *s__tmp)\ +{ return N ## _vec_rscan_by_ ## NK(vec__tmp, s__tmp); }\ +static inline size_t N ## _vec_rscan_n(N ## _vec_t vec__tmp, const char *s__tmp, size_t n__tmp)\ +{ return N ## _vec_rscan_n_by_ ## NK(vec__tmp, s__tmp, n__tmp); }\ +static inline size_t N ## _vec_rscan_ex(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp)\ +{ return N ## _vec_rscan_ex_by_ ## NK(vec__tmp, begin__tmp, end__tmp, s__tmp); }\ +static inline size_t N ## _vec_rscan_ex_n(N ## _vec_t vec__tmp, size_t begin__tmp, size_t end__tmp, const char *s__tmp, size_t n__tmp)\ +{ return N ## _vec_rscan_ex_n_by_ ## NK(vec__tmp, begin__tmp, end__tmp, s__tmp, n__tmp); } +#define __flatbuffers_heap_sort(N, X, A, E, L, TK, TE, D, S)\ +static inline void __ ## N ## X ## __heap_sift_down(\ + N ## _mutable_vec_t vec__tmp, size_t start__tmp, size_t end__tmp)\ +{ size_t child__tmp, root__tmp; TK v1__tmp, v2__tmp, vroot__tmp;\ + root__tmp = start__tmp;\ + while ((root__tmp << 1) <= end__tmp) {\ + child__tmp = root__tmp << 1;\ + if (child__tmp < end__tmp) {\ + v1__tmp = A(E(vec__tmp, child__tmp));\ + v2__tmp = A(E(vec__tmp, child__tmp + 1));\ + if (D(v1__tmp, v2__tmp) < 0) {\ + child__tmp++;\ + }\ + }\ + vroot__tmp = A(E(vec__tmp, root__tmp));\ + v1__tmp = A(E(vec__tmp, child__tmp));\ + if (D(vroot__tmp, v1__tmp) < 0) {\ + S(vec__tmp, root__tmp, child__tmp, TE);\ + root__tmp = child__tmp;\ + } else {\ + return;\ + }\ + }\ +}\ +static inline void __ ## N ## X ## __heap_sort(N ## _mutable_vec_t vec__tmp)\ +{ size_t start__tmp, end__tmp, size__tmp;\ + size__tmp = L(vec__tmp); if (size__tmp == 0) return; end__tmp = size__tmp - 1; start__tmp = size__tmp >> 1;\ + do { __ ## N ## X ## __heap_sift_down(vec__tmp, start__tmp, end__tmp); } while (start__tmp--);\ + while (end__tmp > 0) { \ + S(vec__tmp, 0, end__tmp, TE);\ + __ ## N ## X ## __heap_sift_down(vec__tmp, 0, --end__tmp); } } +#define __flatbuffers_define_sort_by_field(N, NK, TK, TE, D, S)\ + __flatbuffers_heap_sort(N, _sort_by_ ## NK, N ## _ ## NK ## _get, N ## _vec_at, N ## _vec_len, TK, TE, D, S)\ +static inline void N ## _vec_sort_by_ ## NK(N ## _mutable_vec_t vec__tmp)\ +{ __ ## N ## _sort_by_ ## NK ## __heap_sort(vec__tmp); } +#define __flatbuffers_define_sort(N, TK, TE, D, S)\ +__flatbuffers_heap_sort(N, , __flatbuffers_identity, N ## _vec_at, N ## _vec_len, TK, TE, D, S)\ +static inline void N ## _vec_sort(N ## _mutable_vec_t vec__tmp) { __ ## N ## __heap_sort(vec__tmp); } +#define __flatbuffers_scalar_diff(x, y) ((x) < (y) ? -1 : (x) > (y)) +#define __flatbuffers_string_diff(x, y) __flatbuffers_string_n_cmp((x), (const char *)(y), flatbuffers_string_len(y)) +#define __flatbuffers_value_swap(vec, a, b, TE) { TE x__tmp = vec[b]; vec[b] = vec[a]; vec[a] = x__tmp; } +#define __flatbuffers_uoffset_swap(vec, a, b, TE)\ +{ TE ta__tmp, tb__tmp, d__tmp;\ + d__tmp = (TE)((a - b) * sizeof(vec[0]));\ + ta__tmp = __flatbuffers_uoffset_read_from_pe(vec + b) - d__tmp;\ + tb__tmp = __flatbuffers_uoffset_read_from_pe(vec + a) + d__tmp;\ + __flatbuffers_uoffset_write_to_pe(vec + a, ta__tmp);\ + __flatbuffers_uoffset_write_to_pe(vec + b, tb__tmp); } +#define __flatbuffers_scalar_swap(vec, a, b, TE) __flatbuffers_value_swap(vec, a, b, TE) +#define __flatbuffers_string_swap(vec, a, b, TE) __flatbuffers_uoffset_swap(vec, a, b, TE) +#define __flatbuffers_struct_swap(vec, a, b, TE) __flatbuffers_value_swap(vec, a, b, TE) +#define __flatbuffers_table_swap(vec, a, b, TE) __flatbuffers_uoffset_swap(vec, a, b, TE) +#define __flatbuffers_define_struct_sort_by_scalar_field(N, NK, TK, TE)\ + __flatbuffers_define_sort_by_field(N, NK, TK, TE, __flatbuffers_scalar_diff, __flatbuffers_struct_swap) +#define __flatbuffers_define_table_sort_by_scalar_field(N, NK, TK)\ + __flatbuffers_define_sort_by_field(N, NK, TK, flatbuffers_uoffset_t, __flatbuffers_scalar_diff, __flatbuffers_table_swap) +#define __flatbuffers_define_table_sort_by_string_field(N, NK)\ + __flatbuffers_define_sort_by_field(N, NK, flatbuffers_string_t, flatbuffers_uoffset_t, __flatbuffers_string_diff, __flatbuffers_table_swap) +#define __flatbuffers_define_scalar_sort(N, T) __flatbuffers_define_sort(N, T, T, __flatbuffers_scalar_diff, __flatbuffers_scalar_swap) +#define __flatbuffers_define_string_sort() __flatbuffers_define_sort(flatbuffers_string, flatbuffers_string_t, flatbuffers_uoffset_t, __flatbuffers_string_diff, __flatbuffers_string_swap) +#define __flatbuffers_sort_vector_field(N, NK, T, t)\ +{ T ## _mutable_vec_t v__tmp = (T ## _mutable_vec_t) N ## _ ## NK ## _get(t);\ + if (v__tmp) T ## _vec_sort(v__tmp); } +#define __flatbuffers_sort_table_field(N, NK, T, t)\ +{ T ## _sort((T ## _mutable_table_t)N ## _ ## NK ## _get(t)); } +#define __flatbuffers_sort_union_field(N, NK, T, t)\ +{ T ## _sort(T ## _mutable_union_cast(N ## _ ## NK ## _union(t))); } +#define __flatbuffers_sort_table_vector_field_elements(N, NK, T, t)\ +{ T ## _vec_t v__tmp = N ## _ ## NK ## _get(t); size_t i__tmp, n__tmp;\ + n__tmp = T ## _vec_len(v__tmp); for (i__tmp = 0; i__tmp < n__tmp; ++i__tmp) {\ + T ## _sort((T ## _mutable_table_t)T ## _vec_at(v__tmp, i__tmp)); }} +#define __flatbuffers_sort_union_vector_field_elements(N, NK, T, t)\ +{ T ## _union_vec_t v__tmp = N ## _ ## NK ## _union(t); size_t i__tmp, n__tmp;\ + n__tmp = T ## _union_vec_len(v__tmp); for (i__tmp = 0; i__tmp < n__tmp; ++i__tmp) {\ + T ## _sort(T ## _mutable_union_cast(T ## _union_vec_at(v__tmp, i__tmp))); }} +#define __flatbuffers_define_scalar_vector(N, T)\ +typedef const T *N ## _vec_t;\ +typedef T *N ## _mutable_vec_t;\ +__flatbuffers_define_scalar_vec_len(N)\ +__flatbuffers_define_scalar_vec_at(N, T)\ +__flatbuffers_define_scalar_find(N, T)\ +__flatbuffers_define_scalar_scan(N, T)\ +__flatbuffers_define_scalar_sort(N, T) + +#define __flatbuffers_define_integer_type(N, T, W)\ +__flatcc_define_integer_accessors(N, T, W, flatbuffers_endian)\ +__flatbuffers_define_scalar_vector(N, T) +__flatbuffers_define_scalar_vector(flatbuffers_bool, flatbuffers_bool_t) +__flatbuffers_define_scalar_vector(flatbuffers_char, char) +__flatbuffers_define_scalar_vector(flatbuffers_uint8, uint8_t) +__flatbuffers_define_scalar_vector(flatbuffers_int8, int8_t) +__flatbuffers_define_scalar_vector(flatbuffers_uint16, uint16_t) +__flatbuffers_define_scalar_vector(flatbuffers_int16, int16_t) +__flatbuffers_define_scalar_vector(flatbuffers_uint32, uint32_t) +__flatbuffers_define_scalar_vector(flatbuffers_int32, int32_t) +__flatbuffers_define_scalar_vector(flatbuffers_uint64, uint64_t) +__flatbuffers_define_scalar_vector(flatbuffers_int64, int64_t) +__flatbuffers_define_scalar_vector(flatbuffers_float, float) +__flatbuffers_define_scalar_vector(flatbuffers_double, double) +__flatbuffers_define_scalar_vector(flatbuffers_union_type, flatbuffers_union_type_t) +static inline size_t flatbuffers_string_vec_find(flatbuffers_string_vec_t vec, const char *s) +__flatbuffers_find_by_string_field(__flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) +static inline size_t flatbuffers_string_vec_find_n(flatbuffers_string_vec_t vec, const char *s, size_t n) +__flatbuffers_find_by_string_n_field(__flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s, n) +static inline size_t flatbuffers_string_vec_scan(flatbuffers_string_vec_t vec, const char *s) +__flatbuffers_scan_by_string_field(0, flatbuffers_string_vec_len(vec), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) +static inline size_t flatbuffers_string_vec_scan_n(flatbuffers_string_vec_t vec, const char *s, size_t n) +__flatbuffers_scan_by_string_n_field(0, flatbuffers_string_vec_len(vec), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s, n) +static inline size_t flatbuffers_string_vec_scan_ex(flatbuffers_string_vec_t vec, size_t begin, size_t end, const char *s) +__flatbuffers_scan_by_string_field(begin, __flatbuffers_min(end, flatbuffers_string_vec_len(vec)), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) +static inline size_t flatbuffers_string_vec_scan_ex_n(flatbuffers_string_vec_t vec, size_t begin, size_t end, const char *s, size_t n) +__flatbuffers_scan_by_string_n_field(begin, __flatbuffers_min(end, flatbuffers_string_vec_len(vec)), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s, n) +static inline size_t flatbuffers_string_vec_rscan(flatbuffers_string_vec_t vec, const char *s) +__flatbuffers_rscan_by_string_field(0, flatbuffers_string_vec_len(vec), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) +static inline size_t flatbuffers_string_vec_rscan_n(flatbuffers_string_vec_t vec, const char *s, size_t n) +__flatbuffers_rscan_by_string_n_field(0, flatbuffers_string_vec_len(vec), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s, n) +static inline size_t flatbuffers_string_vec_rscan_ex(flatbuffers_string_vec_t vec, size_t begin, size_t end, const char *s) +__flatbuffers_rscan_by_string_field(begin, __flatbuffers_min(end, flatbuffers_string_vec_len(vec)), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) +static inline size_t flatbuffers_string_vec_rscan_ex_n(flatbuffers_string_vec_t vec, size_t begin, size_t end, const char *s, size_t n) +__flatbuffers_rscan_by_string_n_field(begin, __flatbuffers_min(end, flatbuffers_string_vec_len(vec)), __flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s, n) +__flatbuffers_define_string_sort() +#define __flatbuffers_define_struct_scalar_fixed_array_field(N, NK, TK, T, L)\ +static inline T N ## _ ## NK ## _get(N ## _struct_t t__tmp, size_t i__tmp)\ +{ if (!t__tmp || i__tmp >= L) return 0;\ + return __flatbuffers_read_scalar(TK, &(t__tmp->NK[i__tmp])); }\ +static inline const T *N ## _ ## NK ## _get_ptr(N ## _struct_t t__tmp)\ +{ return t__tmp ? t__tmp->NK : 0; }\ +static inline size_t N ## _ ## NK ## _get_len(void) { return L; }\ +static inline T N ## _ ## NK (N ## _struct_t t__tmp, size_t i__tmp)\ +{ return N ## _ ## NK ## _get(t__tmp, i__tmp); } +#define __flatbuffers_define_struct_struct_fixed_array_field(N, NK, T, L)\ +static inline T N ## _ ## NK ## _get(N ## _struct_t t__tmp, size_t i__tmp)\ +{ if (!t__tmp || i__tmp >= L) return 0; return t__tmp->NK + i__tmp; }static inline T N ## _ ## NK ## _get_ptr(N ## _struct_t t__tmp)\ +{ return t__tmp ? t__tmp->NK : 0; }\ +static inline size_t N ## _ ## NK ## _get_len(void) { return L; }\ +static inline T N ## _ ## NK(N ## _struct_t t__tmp, size_t i__tmp)\ +{ if (!t__tmp || i__tmp >= L) return 0; return t__tmp->NK + i__tmp; } +#define __flatbuffers_define_struct_scalar_field(N, NK, TK, T)\ +static inline T N ## _ ## NK ## _get(N ## _struct_t t__tmp)\ +{ return t__tmp ? __flatbuffers_read_scalar(TK, &(t__tmp->NK)) : 0; }\ +static inline const T *N ## _ ## NK ## _get_ptr(N ## _struct_t t__tmp)\ +{ return t__tmp ? &(t__tmp->NK) : 0; }\ +static inline T N ## _ ## NK (N ## _struct_t t__tmp)\ +{ return t__tmp ? __flatbuffers_read_scalar(TK, &(t__tmp->NK)) : 0; }\ +__flatbuffers_define_scan_by_scalar_field(N, NK, T) +#define __flatbuffers_define_struct_struct_field(N, NK, T)\ +static inline T N ## _ ## NK ## _get(N ## _struct_t t__tmp) { return t__tmp ? &(t__tmp->NK) : 0; }\ +static inline T N ## _ ## NK (N ## _struct_t t__tmp) { return t__tmp ? &(t__tmp->NK) : 0; } +/* If fid is null, the function returns true without testing as buffer is not expected to have any id. */ +static inline int flatbuffers_has_identifier(const void *buffer, const char *fid) +{ flatbuffers_thash_t id, id2 = 0; if (fid == 0) { return 1; }; + id2 = flatbuffers_type_hash_from_string(fid); + id = __flatbuffers_thash_read_from_pe(((flatbuffers_uoffset_t *)buffer) + 1); + return id2 == 0 || id == id2; } +static inline int flatbuffers_has_type_hash(const void *buffer, flatbuffers_thash_t thash) +{ return thash == 0 || (__flatbuffers_thash_read_from_pe((flatbuffers_uoffset_t *)buffer + 1) == thash); } + +static inline flatbuffers_thash_t flatbuffers_get_type_hash(const void *buffer) +{ return __flatbuffers_thash_read_from_pe((flatbuffers_uoffset_t *)buffer + 1); } + +#define flatbuffers_verify_endian() flatbuffers_has_identifier("\x00\x00\x00\x00" "1234", "1234") +static inline void *flatbuffers_read_size_prefix(void *b, size_t *size_out) +{ if (size_out) { *size_out = (size_t)__flatbuffers_uoffset_read_from_pe(b); } + return (uint8_t *)b + sizeof(flatbuffers_uoffset_t); } +/* Null file identifier accepts anything, otherwise fid should be 4 characters. */ +#define __flatbuffers_read_root(T, K, buffer, fid)\ + ((!buffer || !flatbuffers_has_identifier(buffer, fid)) ? 0 :\ + ((T ## _ ## K ## t)(((uint8_t *)buffer) +\ + __flatbuffers_uoffset_read_from_pe(buffer)))) +#define __flatbuffers_read_typed_root(T, K, buffer, thash)\ + ((!buffer || !flatbuffers_has_type_hash(buffer, thash)) ? 0 :\ + ((T ## _ ## K ## t)(((uint8_t *)buffer) +\ + __flatbuffers_uoffset_read_from_pe(buffer)))) +#define __flatbuffers_nested_buffer_as_root(C, N, T, K)\ +static inline T ## _ ## K ## t C ## _ ## N ## _as_root_with_identifier(C ## _ ## table_t t__tmp, const char *fid__tmp)\ +{ const uint8_t *buffer__tmp = C ## _ ## N(t__tmp); return __flatbuffers_read_root(T, K, buffer__tmp, fid__tmp); }\ +static inline T ## _ ## K ## t C ## _ ## N ## _as_typed_root(C ## _ ## table_t t__tmp)\ +{ const uint8_t *buffer__tmp = C ## _ ## N(t__tmp); return __flatbuffers_read_root(T, K, buffer__tmp, C ## _ ## type_identifier); }\ +static inline T ## _ ## K ## t C ## _ ## N ## _as_root(C ## _ ## table_t t__tmp)\ +{ const char *fid__tmp = T ## _file_identifier;\ + const uint8_t *buffer__tmp = C ## _ ## N(t__tmp); return __flatbuffers_read_root(T, K, buffer__tmp, fid__tmp); } +#define __flatbuffers_buffer_as_root(N, K)\ +static inline N ## _ ## K ## t N ## _as_root_with_identifier(const void *buffer__tmp, const char *fid__tmp)\ +{ return __flatbuffers_read_root(N, K, buffer__tmp, fid__tmp); }\ +static inline N ## _ ## K ## t N ## _as_root_with_type_hash(const void *buffer__tmp, flatbuffers_thash_t thash__tmp)\ +{ return __flatbuffers_read_typed_root(N, K, buffer__tmp, thash__tmp); }\ +static inline N ## _ ## K ## t N ## _as_root(const void *buffer__tmp)\ +{ const char *fid__tmp = N ## _file_identifier;\ + return __flatbuffers_read_root(N, K, buffer__tmp, fid__tmp); }\ +static inline N ## _ ## K ## t N ## _as_typed_root(const void *buffer__tmp)\ +{ return __flatbuffers_read_typed_root(N, K, buffer__tmp, N ## _type_hash); } +#define __flatbuffers_struct_as_root(N) __flatbuffers_buffer_as_root(N, struct_) +#define __flatbuffers_table_as_root(N) __flatbuffers_buffer_as_root(N, table_) + +#include "flatcc/flatcc_epilogue.h" +#endif /* FLATBUFFERS_COMMON_H */ +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#define FLATBUFFERS_COMMON_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +/* Common FlatBuffers build functionality for C. */ + +#include "flatcc/flatcc_prologue.h" +#ifndef FLATBUILDER_H +#include "flatcc/flatcc_builder.h" +#endif +typedef flatcc_builder_t flatbuffers_builder_t; +typedef flatcc_builder_ref_t flatbuffers_ref_t; +typedef flatcc_builder_ref_t flatbuffers_vec_ref_t; +typedef flatcc_builder_union_ref_t flatbuffers_union_ref_t; +typedef flatcc_builder_union_vec_ref_t flatbuffers_union_vec_ref_t; +/* integer return code (ref and ptr always fail on 0) */ +#define flatbuffers_failed(x) ((x) < 0) +typedef flatbuffers_ref_t flatbuffers_root_t; +#define flatbuffers_root(ref) ((flatbuffers_root_t)(ref)) + +#define __flatbuffers_memoize_begin(B, src)\ +do { flatcc_builder_ref_t _ref; if ((_ref = flatcc_builder_refmap_find((B), (src)))) return _ref; } while (0) +#define __flatbuffers_memoize_end(B, src, op) do { return flatcc_builder_refmap_insert((B), (src), (op)); } while (0) +#define __flatbuffers_memoize(B, src, op) do { __flatbuffers_memoize_begin(B, src); __flatbuffers_memoize_end(B, src, op); } while (0) + +#define __flatbuffers_build_buffer(NS)\ +typedef NS ## ref_t NS ## buffer_ref_t;\ +static inline int NS ## buffer_start(NS ## builder_t *B, const NS ##fid_t fid)\ +{ return flatcc_builder_start_buffer(B, fid, 0, 0); }\ +static inline int NS ## buffer_start_with_size(NS ## builder_t *B, const NS ##fid_t fid)\ +{ return flatcc_builder_start_buffer(B, fid, 0, flatcc_builder_with_size); }\ +static inline int NS ## buffer_start_aligned(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\ +{ return flatcc_builder_start_buffer(B, fid, block_align, 0); }\ +static inline int NS ## buffer_start_aligned_with_size(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\ +{ return flatcc_builder_start_buffer(B, fid, block_align, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t NS ## buffer_end(NS ## builder_t *B, NS ## ref_t root)\ +{ return flatcc_builder_end_buffer(B, root); } + +#define __flatbuffers_build_table_root(NS, N, FID, TFID)\ +static inline int N ## _start_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, FID) ? -1 : N ## _start(B); }\ +static inline int N ## _start_as_root_with_size(NS ## builder_t *B)\ +{ return NS ## buffer_start_with_size(B, FID) ? -1 : N ## _start(B); }\ +static inline int N ## _start_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, TFID) ? -1 : N ## _start(B); }\ +static inline int N ## _start_as_typed_root_with_size(NS ## builder_t *B)\ +{ return NS ## buffer_start_with_size(B, TFID) ? -1 : N ## _start(B); }\ +static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end(B)); }\ +static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end(B)); }\ +static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\ +{ if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\ +static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\ +{ if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\ +static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\ +{ if (NS ## buffer_start(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\ +static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\ +{ if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _table_t t)\ +{ if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _table_t t)\ +{ if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _table_t t)\ +{ if (NS ## buffer_start(B, TFID)) return 0;return NS ## buffer_end(B, N ## _clone(B, t)); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _table_t t)\ +{ if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); } + +#define __flatbuffers_build_table_prolog(NS, N, FID, TFID)\ +__flatbuffers_build_table_vector_ops(NS, N ## _vec, N)\ +__flatbuffers_build_table_root(NS, N, FID, TFID) + +#define __flatbuffers_build_struct_root(NS, N, A, FID, TFID)\ +static inline N ## _t *N ## _start_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, FID) ? 0 : N ## _start(B); }\ +static inline N ## _t *N ## _start_as_root_with_size(NS ## builder_t *B)\ +{ return NS ## buffer_start_with_size(B, FID) ? 0 : N ## _start(B); }\ +static inline N ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, TFID) ? 0 : N ## _start(B); }\ +static inline N ## _t *N ## _start_as_typed_root_with_size(NS ## builder_t *B)\ +{ return NS ## buffer_start_with_size(B, TFID) ? 0 : N ## _start(B); }\ +static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end(B)); }\ +static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end(B)); }\ +static inline NS ## buffer_ref_t N ## _end_pe_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end_pe(B)); }\ +static inline NS ## buffer_ref_t N ## _end_pe_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_end(B, N ## _end_pe(B)); }\ +static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\ +{ return flatcc_builder_create_buffer(B, FID, 0,\ + N ## _create(B __ ## N ## _call_args), A, 0); }\ +static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\ +{ return flatcc_builder_create_buffer(B, FID, 0,\ + N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\ +{ return flatcc_builder_create_buffer(B, TFID, 0,\ + N ## _create(B __ ## N ## _call_args), A, 0); }\ +static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\ +{ return flatcc_builder_create_buffer(B, TFID, 0,\ + N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, 0); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, 0); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); } + +#define __flatbuffers_build_nested_table_root(NS, N, TN, FID, TFID)\ +static inline int N ## _start_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, FID) ? -1 : TN ## _start(B); }\ +static inline int N ## _start_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, TFID) ? -1 : TN ## _start(B); }\ +static inline int N ## _end_as_root(NS ## builder_t *B)\ +{ return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\ +static inline int N ## _end_as_typed_root(NS ## builder_t *B)\ +{ return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\ +static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\ +{ return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\ + align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\ +static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\ +{ return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\ + align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\ +static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _table_t t)\ +{ return N ## _add(B, TN ## _clone_as_root(B, t)); }\ +static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _table_t t)\ +{ return N ## _add(B, TN ## _clone_as_typed_root(B, t)); } + +#define __flatbuffers_build_nested_struct_root(NS, N, TN, A, FID, TFID)\ +static inline TN ## _t *N ## _start_as_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\ +static inline TN ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\ +{ return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\ +static inline int N ## _end_as_root(NS ## builder_t *B)\ +{ return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\ +static inline int N ## _end_as_typed_root(NS ## builder_t *B)\ +{ return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\ +static inline int N ## _end_pe_as_root(NS ## builder_t *B)\ +{ return N ## _add(B, NS ## buffer_end(B, TN ## _end_pe(B))); }\ +static inline int N ## _create_as_root(NS ## builder_t *B __ ## TN ## _formal_args)\ +{ return N ## _add(B, flatcc_builder_create_buffer(B, FID, 0,\ + TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\ +static inline int N ## _create_as_typed_root(NS ## builder_t *B __ ## TN ## _formal_args)\ +{ return N ## _add(B, flatcc_builder_create_buffer(B, TFID, 0,\ + TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\ +static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\ +{ return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\ + align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\ +static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\ +{ return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\ + align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\ +static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _struct_t p)\ +{ return N ## _add(B, TN ## _clone_as_root(B, p)); }\ +static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _struct_t p)\ +{ return N ## _add(B, TN ## _clone_as_typed_root(B, p)); } + +#define __flatbuffers_build_vector_ops(NS, V, N, TN, T)\ +static inline T *V ## _extend(NS ## builder_t *B, size_t len)\ +{ return (T *)flatcc_builder_extend_vector(B, len); }\ +static inline T *V ## _append(NS ## builder_t *B, const T *data, size_t len)\ +{ return (T *)flatcc_builder_append_vector(B, data, len); }\ +static inline int V ## _truncate(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_truncate_vector(B, len); }\ +static inline T *V ## _edit(NS ## builder_t *B)\ +{ return (T *)flatcc_builder_vector_edit(B); }\ +static inline size_t V ## _reserved_len(NS ## builder_t *B)\ +{ return flatcc_builder_vector_count(B); }\ +static inline T *V ## _push(NS ## builder_t *B, const T *p)\ +{ T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? (memcpy(_p, p, TN ## __size()), _p) : 0; }\ +static inline T *V ## _push_copy(NS ## builder_t *B, const T *p)\ +{ T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\ +static inline T *V ## _push_clone(NS ## builder_t *B, const T *p)\ +{ T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\ +static inline T *V ## _push_create(NS ## builder_t *B __ ## TN ## _formal_args)\ +{ T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _assign(_p __ ## TN ## _call_args) : 0; } + +#define __flatbuffers_build_vector(NS, N, T, S, A)\ +typedef NS ## ref_t N ## _vec_ref_t;\ +static inline int N ## _vec_start(NS ## builder_t *B)\ +{ return flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); }\ +static inline N ## _vec_ref_t N ## _vec_end_pe(NS ## builder_t *B)\ +{ return flatcc_builder_end_vector(B); }\ +static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\ +{ if (!NS ## is_native_pe()) { size_t i, n; T *p = (T *)flatcc_builder_vector_edit(B);\ + for (i = 0, n = flatcc_builder_vector_count(B); i < n; ++i)\ + { N ## _to_pe(N ## __ptr_add(p, i)); }} return flatcc_builder_end_vector(B); }\ +static inline N ## _vec_ref_t N ## _vec_create_pe(NS ## builder_t *B, const T *data, size_t len)\ +{ return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\ +static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const T *data, size_t len)\ +{ if (!NS ## is_native_pe()) { size_t i; T *p; int ret = flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); if (ret) { return ret; }\ + p = (T *)flatcc_builder_extend_vector(B, len); if (!p) return 0;\ + for (i = 0; i < len; ++i) { N ## _copy_to_pe(N ## __ptr_add(p, i), N ## __const_ptr_add(data, i)); }\ + return flatcc_builder_end_vector(B); } else return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\ +static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\ +{ __flatbuffers_memoize(B, vec, flatcc_builder_create_vector(B, vec, N ## _vec_len(vec), S, A, FLATBUFFERS_COUNT_MAX(S))); }\ +static inline N ## _vec_ref_t N ## _vec_slice(NS ## builder_t *B, N ##_vec_t vec, size_t index, size_t len)\ +{ size_t n = N ## _vec_len(vec); if (index >= n) index = n; n -= index; if (len > n) len = n;\ + return flatcc_builder_create_vector(B, N ## __const_ptr_add(vec, index), len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\ +__flatbuffers_build_vector_ops(NS, N ## _vec, N, N, T) + +#define __flatbuffers_build_union_vector_ops(NS, V, N, TN)\ +static inline TN ## _union_ref_t *V ## _extend(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_extend_union_vector(B, len); }\ +static inline TN ## _union_ref_t *V ## _append(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\ +{ return flatcc_builder_append_union_vector(B, data, len); }\ +static inline int V ## _truncate(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_truncate_union_vector(B, len); }\ +static inline TN ## _union_ref_t *V ## _edit(NS ## builder_t *B)\ +{ return (TN ## _union_ref_t *) flatcc_builder_union_vector_edit(B); }\ +static inline size_t V ## _reserved_len(NS ## builder_t *B)\ +{ return flatcc_builder_union_vector_count(B); }\ +static inline TN ## _union_ref_t *V ## _push(NS ## builder_t *B, const TN ## _union_ref_t ref)\ +{ return flatcc_builder_union_vector_push(B, ref); }\ +static inline TN ## _union_ref_t *V ## _push_clone(NS ## builder_t *B, TN ## _union_t u)\ +{ return TN ## _vec_push(B, TN ## _clone(B, u)); } + +#define __flatbuffers_build_union_vector(NS, N)\ +static inline int N ## _vec_start(NS ## builder_t *B)\ +{ return flatcc_builder_start_union_vector(B); }\ +static inline N ## _union_vec_ref_t N ## _vec_end(NS ## builder_t *B)\ +{ return flatcc_builder_end_union_vector(B); }\ +static inline N ## _union_vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _union_ref_t *data, size_t len)\ +{ return flatcc_builder_create_union_vector(B, data, len); }\ +__flatbuffers_build_union_vector_ops(NS, N ## _vec, N, N)\ +/* Preserves DAG structure separately for type and value vector, so a type vector could be shared for many value vectors. */\ +static inline N ## _union_vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_union_vec_t vec)\ +{ N ## _union_vec_ref_t _uvref, _ret = { 0, 0 }; NS ## union_ref_t _uref; size_t _i, _len;\ + if (vec.type == 0) return _ret;\ + _uvref.type = flatcc_builder_refmap_find(B, vec.type); _uvref.value = flatcc_builder_refmap_find(B, vec.value);\ + _len = N ## _union_vec_len(vec); if (_uvref.type == 0) {\ + _uvref.type = flatcc_builder_refmap_insert(B, vec.type, (flatcc_builder_create_type_vector(B, vec.type, _len))); }\ + if (_uvref.type == 0) return _ret; if (_uvref.value == 0) {\ + if (flatcc_builder_start_offset_vector(B)) return _ret;\ + for (_i = 0; _i < _len; ++_i) { _uref = N ## _clone(B, N ## _union_vec_at(vec, _i));\ + if (!_uref.value || !(flatcc_builder_offset_vector_push(B, _uref.value))) return _ret; }\ + _uvref.value = flatcc_builder_refmap_insert(B, vec.value, flatcc_builder_end_offset_vector(B));\ + if (_uvref.value == 0) return _ret; } return _uvref; } + +#define __flatbuffers_build_string_vector_ops(NS, N)\ +static inline int N ## _push_start(NS ## builder_t *B)\ +{ return NS ## string_start(B); }\ +static inline NS ## string_ref_t *N ## _push_end(NS ## builder_t *B)\ +{ return NS ## string_vec_push(B, NS ## string_end(B)); }\ +static inline NS ## string_ref_t *N ## _push_create(NS ## builder_t *B, const char *s, size_t len)\ +{ return NS ## string_vec_push(B, NS ## string_create(B, s, len)); }\ +static inline NS ## string_ref_t *N ## _push_create_str(NS ## builder_t *B, const char *s)\ +{ return NS ## string_vec_push(B, NS ## string_create_str(B, s)); }\ +static inline NS ## string_ref_t *N ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\ +{ return NS ## string_vec_push(B, NS ## string_create_strn(B, s, max_len)); }\ +static inline NS ## string_ref_t *N ## _push_clone(NS ## builder_t *B, NS ## string_t string)\ +{ return NS ## string_vec_push(B, NS ## string_clone(B, string)); }\ +static inline NS ## string_ref_t *N ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\ +{ return NS ## string_vec_push(B, NS ## string_slice(B, string, index, len)); } + +#define __flatbuffers_build_table_vector_ops(NS, N, TN)\ +static inline int N ## _push_start(NS ## builder_t *B)\ +{ return TN ## _start(B); }\ +static inline TN ## _ref_t *N ## _push_end(NS ## builder_t *B)\ +{ return N ## _push(B, TN ## _end(B)); }\ +static inline TN ## _ref_t *N ## _push_create(NS ## builder_t *B __ ## TN ##_formal_args)\ +{ return N ## _push(B, TN ## _create(B __ ## TN ## _call_args)); } + +#define __flatbuffers_build_offset_vector_ops(NS, V, N, TN)\ +static inline TN ## _ref_t *V ## _extend(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_extend_offset_vector(B, len); }\ +static inline TN ## _ref_t *V ## _append(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\ +{ return flatcc_builder_append_offset_vector(B, data, len); }\ +static inline int V ## _truncate(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_truncate_offset_vector(B, len); }\ +static inline TN ## _ref_t *V ## _edit(NS ## builder_t *B)\ +{ return (TN ## _ref_t *)flatcc_builder_offset_vector_edit(B); }\ +static inline size_t V ## _reserved_len(NS ## builder_t *B)\ +{ return flatcc_builder_offset_vector_count(B); }\ +static inline TN ## _ref_t *V ## _push(NS ## builder_t *B, const TN ## _ref_t ref)\ +{ return ref ? flatcc_builder_offset_vector_push(B, ref) : 0; } + +#define __flatbuffers_build_offset_vector(NS, N)\ +typedef NS ## ref_t N ## _vec_ref_t;\ +static inline int N ## _vec_start(NS ## builder_t *B)\ +{ return flatcc_builder_start_offset_vector(B); }\ +static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\ +{ return flatcc_builder_end_offset_vector(B); }\ +static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _ref_t *data, size_t len)\ +{ return flatcc_builder_create_offset_vector(B, data, len); }\ +__flatbuffers_build_offset_vector_ops(NS, N ## _vec, N, N)\ +static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\ +{ int _ret; N ## _ref_t _e; size_t _i, _len; __flatbuffers_memoize_begin(B, vec);\ + _len = N ## _vec_len(vec); if (flatcc_builder_start_offset_vector(B)) return 0;\ + for (_i = 0; _i < _len; ++_i) { if (!(_e = N ## _clone(B, N ## _vec_at(vec, _i)))) return 0;\ + if (!flatcc_builder_offset_vector_push(B, _e)) return 0; }\ + __flatbuffers_memoize_end(B, vec, flatcc_builder_end_offset_vector(B)); }\ + +#define __flatbuffers_build_string_ops(NS, N)\ +static inline char *N ## _append(NS ## builder_t *B, const char *s, size_t len)\ +{ return flatcc_builder_append_string(B, s, len); }\ +static inline char *N ## _append_str(NS ## builder_t *B, const char *s)\ +{ return flatcc_builder_append_string_str(B, s); }\ +static inline char *N ## _append_strn(NS ## builder_t *B, const char *s, size_t len)\ +{ return flatcc_builder_append_string_strn(B, s, len); }\ +static inline size_t N ## _reserved_len(NS ## builder_t *B)\ +{ return flatcc_builder_string_len(B); }\ +static inline char *N ## _extend(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_extend_string(B, len); }\ +static inline char *N ## _edit(NS ## builder_t *B)\ +{ return flatcc_builder_string_edit(B); }\ +static inline int N ## _truncate(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_truncate_string(B, len); } + +#define __flatbuffers_build_string(NS)\ +typedef NS ## ref_t NS ## string_ref_t;\ +static inline int NS ## string_start(NS ## builder_t *B)\ +{ return flatcc_builder_start_string(B); }\ +static inline NS ## string_ref_t NS ## string_end(NS ## builder_t *B)\ +{ return flatcc_builder_end_string(B); }\ +static inline NS ## ref_t NS ## string_create(NS ## builder_t *B, const char *s, size_t len)\ +{ return flatcc_builder_create_string(B, s, len); }\ +static inline NS ## ref_t NS ## string_create_str(NS ## builder_t *B, const char *s)\ +{ return flatcc_builder_create_string_str(B, s); }\ +static inline NS ## ref_t NS ## string_create_strn(NS ## builder_t *B, const char *s, size_t len)\ +{ return flatcc_builder_create_string_strn(B, s, len); }\ +static inline NS ## string_ref_t NS ## string_clone(NS ## builder_t *B, NS ## string_t string)\ +{ __flatbuffers_memoize(B, string, flatcc_builder_create_string(B, string, NS ## string_len(string))); }\ +static inline NS ## string_ref_t NS ## string_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\ +{ size_t n = NS ## string_len(string); if (index >= n) index = n; n -= index; if (len > n) len = n;\ + return flatcc_builder_create_string(B, string + index, len); }\ +__flatbuffers_build_string_ops(NS, NS ## string)\ +__flatbuffers_build_offset_vector(NS, NS ## string) + +#define __flatbuffers_copy_from_pe(P, P2, N) (*(P) = N ## _read_from_pe(P2), (P)) +#define __flatbuffers_from_pe(P, N) (*(P) = N ## _read_from_pe(P), (P)) +#define __flatbuffers_copy_to_pe(P, P2, N) (N ## _write_to_pe((P), *(P2)), (P)) +#define __flatbuffers_to_pe(P, N) (N ## _write_to_pe((P), *(P)), (P)) +#define __flatbuffers_define_fixed_array_primitives(NS, N, T)\ +static inline T *N ## _array_copy(T *p, const T *p2, size_t n)\ +{ memcpy(p, p2, n * sizeof(T)); return p; }\ +static inline T *N ## _array_copy_from_pe(T *p, const T *p2, size_t n)\ +{ size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else\ + for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); return p; }\ +static inline T *N ## _array_copy_to_pe(T *p, const T *p2, size_t n)\ +{ size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else\ + for (i = 0; i < n; ++i) N ## _copy_to_pe(&p[i], &p2[i]); return p; } +#define __flatbuffers_define_scalar_primitives(NS, N, T)\ +static inline T *N ## _from_pe(T *p) { return __ ## NS ## from_pe(p, N); }\ +static inline T *N ## _to_pe(T *p) { return __ ## NS ## to_pe(p, N); }\ +static inline T *N ## _copy(T *p, const T *p2) { *p = *p2; return p; }\ +static inline T *N ## _copy_from_pe(T *p, const T *p2)\ +{ return __ ## NS ## copy_from_pe(p, p2, N); }\ +static inline T *N ## _copy_to_pe(T *p, const T *p2) \ +{ return __ ## NS ## copy_to_pe(p, p2, N); }\ +static inline T *N ## _assign(T *p, const T v0) { *p = v0; return p; }\ +static inline T *N ## _assign_from_pe(T *p, T v0)\ +{ *p = N ## _read_from_pe(&v0); return p; }\ +static inline T *N ## _assign_to_pe(T *p, T v0)\ +{ N ## _write_to_pe(p, v0); return p; } +#define __flatbuffers_build_scalar(NS, N, T)\ +__ ## NS ## define_scalar_primitives(NS, N, T)\ +__ ## NS ## define_fixed_array_primitives(NS, N, T)\ +__ ## NS ## build_vector(NS, N, T, sizeof(T), sizeof(T)) +/* Depends on generated copy_to/from_pe functions, and the type. */ +#define __flatbuffers_define_struct_primitives(NS, N)\ +static inline N ## _t *N ##_to_pe(N ## _t *p)\ +{ if (!NS ## is_native_pe()) { N ## _copy_to_pe(p, p); }; return p; }\ +static inline N ## _t *N ##_from_pe(N ## _t *p)\ +{ if (!NS ## is_native_pe()) { N ## _copy_from_pe(p, p); }; return p; }\ +static inline N ## _t *N ## _clear(N ## _t *p) { return (N ## _t *)memset(p, 0, N ## __size()); } + +/* Depends on generated copy/assign_to/from_pe functions, and the type. */ +#define __flatbuffers_build_struct(NS, N, S, A, FID, TFID)\ +__ ## NS ## define_struct_primitives(NS, N)\ +typedef NS ## ref_t N ## _ref_t;\ +static inline N ## _t *N ## _start(NS ## builder_t *B)\ +{ return (N ## _t *)flatcc_builder_start_struct(B, S, A); }\ +static inline N ## _ref_t N ## _end(NS ## builder_t *B)\ +{ if (!NS ## is_native_pe()) { N ## _to_pe((N ## _t *)flatcc_builder_struct_edit(B)); }\ + return flatcc_builder_end_struct(B); }\ +static inline N ## _ref_t N ## _end_pe(NS ## builder_t *B)\ +{ return flatcc_builder_end_struct(B); }\ +static inline N ## _ref_t N ## _create(NS ## builder_t *B __ ## N ## _formal_args)\ +{ N ## _t *_p = N ## _start(B); if (!_p) return 0; N ##_assign_to_pe(_p __ ## N ## _call_args);\ + return N ## _end_pe(B); }\ +static inline N ## _ref_t N ## _clone(NS ## builder_t *B, N ## _struct_t p)\ +{ N ## _t *_p; __flatbuffers_memoize_begin(B, p); _p = N ## _start(B); if (!_p) return 0;\ + N ## _copy(_p, p); __flatbuffers_memoize_end(B, p, N ##_end_pe(B)); }\ +__flatbuffers_build_vector(NS, N, N ## _t, S, A)\ +__flatbuffers_build_struct_root(NS, N, A, FID, TFID)\ + +#define __flatbuffers_struct_clear_field(p) memset((p), 0, sizeof(*(p))) +#define __flatbuffers_build_table(NS, N, K)\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return flatcc_builder_start_table(B, K); }\ +static inline N ## _ref_t N ## _end(NS ## builder_t *B)\ +{ FLATCC_ASSERT(flatcc_builder_check_required(B, __ ## N ## _required,\ + sizeof(__ ## N ## _required) / sizeof(__ ## N ## _required[0]) - 1));\ + return flatcc_builder_end_table(B); }\ +__flatbuffers_build_offset_vector(NS, N) + +#define __flatbuffers_build_table_field(ID, NS, N, TN, TT)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _ref_t ref)\ +{ TN ## _ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ?\ + ((*_p = ref), 0) : -1; }\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return TN ## _start(B); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, TN ## _end(B)); }\ +static inline TN ## _ref_t N ## _create(NS ## builder_t *B __ ## TN ##_formal_args)\ +{ return N ## _add(B, TN ## _create(B __ ## TN ## _call_args)); }\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _table_t p)\ +{ return N ## _add(B, TN ## _clone(B, p)); }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _table_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; } + +#define __flatbuffers_build_union_field(ID, NS, N, TN, TT)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _union_ref_t uref)\ +{ NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref.value == 0) return -1;\ + if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(*_pt)))) return -1;\ + *_pt = uref.type; if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uref.value; return 0; }\ +static inline int N ## _add_type(NS ## builder_t *B, TN ## _union_type_t type)\ +{ TN ## _union_type_t *_pt; if (type == TN ## _NONE) return 0; return (_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1,\ + sizeof(*_pt), sizeof(*_pt))) ? ((*_pt = type), 0) : -1; }\ +static inline int N ## _add_value(NS ## builder_t *B, TN ## _union_ref_t uref)\ +{ NS ## ref_t *p; if (uref.type == TN ## _NONE) return 0; return (p = flatcc_builder_table_add_offset(B, ID)) ?\ + ((*p = uref.value), 0) : -1; }\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _union_t p)\ +{ return N ## _add(B, TN ## _clone(B, p)); }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _union_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; } + +/* M is the union value name and T is its type, i.e. the qualified name. */ +#define __flatbuffers_build_union_table_value_field(NS, N, NU, M, T)\ +static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\ +{ return N ## _add(B, NU ## _as_ ## M (ref)); }\ +static inline int N ## _ ## M ## _start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline int N ## _ ## M ## _end(NS ## builder_t *B)\ +{ T ## _ref_t ref = T ## _end(B);\ + return ref ? N ## _ ## M ## _add(B, ref) : -1; }\ +static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\ +static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _table_t t)\ +{ T ## _ref_t ref = T ## _clone(B, t);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; } + +/* M is the union value name and T is its type, i.e. the qualified name. */ +#define __flatbuffers_build_union_struct_value_field(NS, N, NU, M, T)\ +static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\ +{ return N ## _add(B, NU ## _as_ ## M (ref)); }\ +static inline T ## _t *N ## _ ## M ## _start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline int N ## _ ## M ## _end(NS ## builder_t *B)\ +{ T ## _ref_t ref = T ## _end(B);\ + return ref ? N ## _ ## M ## _add(B, ref) : -1; }\ +static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\ +static inline int N ## _ ## M ## _end_pe(NS ## builder_t *B)\ +{ T ## _ref_t ref = T ## _end_pe(B);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\ +static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _struct_t p)\ +{ T ## _ref_t ref = T ## _clone(B, p);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; } +#define __flatbuffers_build_union_string_value_field(NS, N, NU, M)\ +static inline int N ## _ ## M ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ return N ## _add(B, NU ## _as_ ## M (ref)); }\ +__flatbuffers_build_string_field_ops(NS, N ## _ ## M) + +/* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type + * S: sizeof of scalar type, A: alignment of type T, default value V of type T. */ +#define __flatbuffers_build_scalar_field(ID, NS, N, TN, T, S, A, V, TT)\ +static inline int N ## _add(NS ## builder_t *B, const T v)\ +{ T *_p; if (v == V) return 0; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\ + TN ## _assign_to_pe(_p, v); return 0; }\ +static inline int N ## _force_add(NS ## builder_t *B, const T v)\ +{ T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\ + TN ## _assign_to_pe(_p, v); return 0; }\ +/* Clone does not skip default values and expects pe endian content. */\ +static inline int N ## _clone(NS ## builder_t *B, const T *p)\ +{ return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\ +/* Transferring a missing field is a nop success with 0 as result. */\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; } + +/* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type + * S: sizeof of scalar type, A: alignment of type T. */ +#define __flatbuffers_build_scalar_optional_field(ID, NS, N, TN, T, S, A, TT)\ +static inline int N ## _add(NS ## builder_t *B, const T v)\ +{ T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\ + TN ## _assign_to_pe(_p, v); return 0; }\ +/* Clone does not skip default values and expects pe endian content. */\ +static inline int N ## _clone(NS ## builder_t *B, const T *p)\ +{ return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\ +/* Transferring a missing field is a nop success with 0 as result. */\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; } + +#define __flatbuffers_build_struct_field(ID, NS, N, TN, S, A, TT)\ +static inline TN ## _t *N ## _start(NS ## builder_t *B)\ +{ return (TN ## _t *)flatcc_builder_table_add(B, ID, S, A); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ if (!NS ## is_native_pe()) { TN ## _to_pe((TN ## _t *)flatcc_builder_table_edit(B, S)); } return 0; }\ +static inline int N ## _end_pe(NS ## builder_t *B) { return 0; }\ +static inline int N ## _create(NS ## builder_t *B __ ## TN ## _formal_args)\ +{ TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_assign_to_pe(_p __ ## TN ## _call_args);\ + return 0; }\ +static inline int N ## _add(NS ## builder_t *B, const TN ## _t *p)\ +{ TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_copy_to_pe(_p, p); return 0; }\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _struct_t p)\ +{ return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _struct_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; } + +#define __flatbuffers_build_vector_field(ID, NS, N, TN, T, TT)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\ +{ TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return TN ## _vec_start(B); }\ +static inline int N ## _end_pe(NS ## builder_t *B)\ +{ return N ## _add(B, TN ## _vec_end_pe(B)); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, TN ## _vec_end(B)); }\ +static inline int N ## _create_pe(NS ## builder_t *B, const T *data, size_t len)\ +{ return N ## _add(B, TN ## _vec_create_pe(B, data, len)); }\ +static inline int N ## _create(NS ## builder_t *B, const T *data, size_t len)\ +{ return N ## _add(B, TN ## _vec_create(B, data, len)); }\ +static inline int N ## _slice(NS ## builder_t *B, TN ## _vec_t vec, size_t index, size_t len)\ +{ return N ## _add(B, TN ## _vec_slice(B, vec, index, len)); }\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\ +{ return N ## _add(B, TN ## _vec_clone(B, vec)); }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }\ +__flatbuffers_build_vector_ops(NS, N, N, TN, T)\ + +#define __flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\ +{ TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return flatcc_builder_start_offset_vector(B); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, flatcc_builder_end_offset_vector(B)); }\ +static inline int N ## _create(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\ +{ return N ## _add(B, flatcc_builder_create_offset_vector(B, data, len)); }\ +__flatbuffers_build_offset_vector_ops(NS, N, N, TN)\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\ +{ return N ## _add(B, TN ## _vec_clone(B, vec)); }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; } + +/* depends on N ## _add which differs for union member fields and ordinary fields */\ +#define __flatbuffers_build_string_field_ops(NS, N)\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return flatcc_builder_start_string(B); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, flatcc_builder_end_string(B)); }\ +static inline int N ## _create(NS ## builder_t *B, const char *s, size_t len)\ +{ return N ## _add(B, flatcc_builder_create_string(B, s, len)); }\ +static inline int N ## _create_str(NS ## builder_t *B, const char *s)\ +{ return N ## _add(B, flatcc_builder_create_string_str(B, s)); }\ +static inline int N ## _create_strn(NS ## builder_t *B, const char *s, size_t max_len)\ +{ return N ## _add(B, flatcc_builder_create_string_strn(B, s, max_len)); }\ +static inline int N ## _clone(NS ## builder_t *B, NS ## string_t string)\ +{ return N ## _add(B, NS ## string_clone(B, string)); }\ +static inline int N ## _slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\ +{ return N ## _add(B, NS ## string_slice(B, string, index, len)); }\ +__flatbuffers_build_string_ops(NS, N) + +#define __flatbuffers_build_string_field(ID, NS, N, TT)\ +static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\ +__flatbuffers_build_string_field_ops(NS, N)\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ NS ## string_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; } + +#define __flatbuffers_build_table_vector_field(ID, NS, N, TN, TT)\ +__flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\ +__flatbuffers_build_table_vector_ops(NS, N, TN) + +#define __flatbuffers_build_union_vector_field(ID, NS, N, TN, TT)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _union_vec_ref_t uvref)\ +{ NS ## vec_ref_t *_p; if (!uvref.type || !uvref.value) return uvref.type == uvref.value ? 0 : -1;\ + if (!(_p = flatcc_builder_table_add_offset(B, ID - 1))) return -1; *_p = uvref.type;\ + if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uvref.value; return 0; }\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return flatcc_builder_start_union_vector(B); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, flatcc_builder_end_union_vector(B)); }\ +static inline int N ## _create(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\ +{ return N ## _add(B, flatcc_builder_create_union_vector(B, data, len)); }\ +__flatbuffers_build_union_vector_ops(NS, N, N, TN)\ +static inline int N ## _clone(NS ## builder_t *B, TN ## _union_vec_t vec)\ +{ return N ## _add(B, TN ## _vec_clone(B, vec)); }\ +static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\ +{ TN ## _union_vec_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; } + +#define __flatbuffers_build_union_table_vector_value_field(NS, N, NU, M, T)\ +static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _table_t t)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, t))); } + +#define __flatbuffers_build_union_struct_vector_value_field(NS, N, NU, M, T)\ +static inline T ## _t *N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _struct_t p)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, p))); } + +#define __flatbuffers_build_union_string_vector_value_field(NS, N, NU, M)\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return NS ## string_start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B, const char *s, size_t len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create(B, s, len))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_str(NS ## builder_t *B, const char *s)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_str(B, s))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_strn(B, s, max_len))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, NS ## string_t string)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_clone(B, string))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_slice(B, string, index, len))); } + +#define __flatbuffers_build_string_vector_field(ID, NS, N, TT)\ +__flatbuffers_build_offset_vector_field(ID, NS, N, NS ## string, TT)\ +__flatbuffers_build_string_vector_ops(NS, N) + +#define __flatbuffers_char_formal_args , char v0 +#define __flatbuffers_char_call_args , v0 +#define __flatbuffers_uint8_formal_args , uint8_t v0 +#define __flatbuffers_uint8_call_args , v0 +#define __flatbuffers_int8_formal_args , int8_t v0 +#define __flatbuffers_int8_call_args , v0 +#define __flatbuffers_bool_formal_args , flatbuffers_bool_t v0 +#define __flatbuffers_bool_call_args , v0 +#define __flatbuffers_uint16_formal_args , uint16_t v0 +#define __flatbuffers_uint16_call_args , v0 +#define __flatbuffers_uint32_formal_args , uint32_t v0 +#define __flatbuffers_uint32_call_args , v0 +#define __flatbuffers_uint64_formal_args , uint64_t v0 +#define __flatbuffers_uint64_call_args , v0 +#define __flatbuffers_int16_formal_args , int16_t v0 +#define __flatbuffers_int16_call_args , v0 +#define __flatbuffers_int32_formal_args , int32_t v0 +#define __flatbuffers_int32_call_args , v0 +#define __flatbuffers_int64_formal_args , int64_t v0 +#define __flatbuffers_int64_call_args , v0 +#define __flatbuffers_float_formal_args , float v0 +#define __flatbuffers_float_call_args , v0 +#define __flatbuffers_double_formal_args , double v0 +#define __flatbuffers_double_call_args , v0 + +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_char, char) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint8, uint8_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_int8, int8_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_bool, flatbuffers_bool_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint16, uint16_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint32, uint32_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint64, uint64_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_int16, int16_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_int32, int32_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_int64, int64_t) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_float, float) +__flatbuffers_build_scalar(flatbuffers_, flatbuffers_double, double) + +__flatbuffers_build_string(flatbuffers_) + +__flatbuffers_build_buffer(flatbuffers_) +#include "flatcc/flatcc_epilogue.h" +#endif /* FLATBUFFERS_COMMON_BUILDER_H */ +#ifndef SCHEMA_READER_H +#define SCHEMA_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Buffer org_apache_arrow_flatbuf_Buffer_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_struct_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_vec_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_table_t; +typedef struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__table_t; +typedef struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_table_t; +typedef struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_table_t; +typedef struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_table_t; +typedef struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_table_t; +typedef struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_table_t; +typedef struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_table_t; +typedef struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_table_t; +typedef struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_table_t; +typedef struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_table_t; +typedef struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_table_t; +typedef struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_table_t; +typedef struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_table_t; +typedef struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_table_t; +typedef struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_table_t; +typedef struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_table_t; +typedef struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_table_t; +typedef struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_table_t; +typedef struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_table_t; +typedef struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_table_t; +typedef struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_table_t; +typedef struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_table_t; +typedef struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_table_t; +typedef struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Null_file_identifier +#define org_apache_arrow_flatbuf_Null_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Null_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Null_identifier +#define org_apache_arrow_flatbuf_Null_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Null_type_hash ((flatbuffers_thash_t)0x7b36a4dd) +#define org_apache_arrow_flatbuf_Null_type_identifier "\xdd\xa4\x36\x7b" +#ifndef org_apache_arrow_flatbuf_Null_file_extension +#define org_apache_arrow_flatbuf_Null_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Struct__file_identifier +#define org_apache_arrow_flatbuf_Struct__file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Struct__file_identifier */ +#ifndef org_apache_arrow_flatbuf_Struct__identifier +#define org_apache_arrow_flatbuf_Struct__identifier 0 +#endif +#define org_apache_arrow_flatbuf_Struct__type_hash ((flatbuffers_thash_t)0x6310f362) +#define org_apache_arrow_flatbuf_Struct__type_identifier "\x62\xf3\x10\x63" +#ifndef org_apache_arrow_flatbuf_Struct__file_extension +#define org_apache_arrow_flatbuf_Struct__file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_List_file_identifier +#define org_apache_arrow_flatbuf_List_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_List_file_identifier */ +#ifndef org_apache_arrow_flatbuf_List_identifier +#define org_apache_arrow_flatbuf_List_identifier 0 +#endif +#define org_apache_arrow_flatbuf_List_type_hash ((flatbuffers_thash_t)0xd4ce5878) +#define org_apache_arrow_flatbuf_List_type_identifier "\x78\x58\xce\xd4" +#ifndef org_apache_arrow_flatbuf_List_file_extension +#define org_apache_arrow_flatbuf_List_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeList_file_identifier +#define org_apache_arrow_flatbuf_LargeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeList_identifier +#define org_apache_arrow_flatbuf_LargeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeList_type_hash ((flatbuffers_thash_t)0x38aa7e27) +#define org_apache_arrow_flatbuf_LargeList_type_identifier "\x27\x7e\xaa\x38" +#ifndef org_apache_arrow_flatbuf_LargeList_file_extension +#define org_apache_arrow_flatbuf_LargeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_ListView_file_identifier +#define org_apache_arrow_flatbuf_ListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_ListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_ListView_identifier +#define org_apache_arrow_flatbuf_ListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_ListView_type_hash ((flatbuffers_thash_t)0x23d37919) +#define org_apache_arrow_flatbuf_ListView_type_identifier "\x19\x79\xd3\x23" +#ifndef org_apache_arrow_flatbuf_ListView_file_extension +#define org_apache_arrow_flatbuf_ListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeListView_file_identifier +#define org_apache_arrow_flatbuf_LargeListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeListView_identifier +#define org_apache_arrow_flatbuf_LargeListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeListView_type_hash ((flatbuffers_thash_t)0x28efac02) +#define org_apache_arrow_flatbuf_LargeListView_type_identifier "\x02\xac\xef\x28" +#ifndef org_apache_arrow_flatbuf_LargeListView_file_extension +#define org_apache_arrow_flatbuf_LargeListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeList_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeList_type_hash ((flatbuffers_thash_t)0xcef245bb) +#define org_apache_arrow_flatbuf_FixedSizeList_type_identifier "\xbb\x45\xf2\xce" +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_extension +#define org_apache_arrow_flatbuf_FixedSizeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Map_file_identifier +#define org_apache_arrow_flatbuf_Map_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Map_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Map_identifier +#define org_apache_arrow_flatbuf_Map_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Map_type_hash ((flatbuffers_thash_t)0xcebef8e6) +#define org_apache_arrow_flatbuf_Map_type_identifier "\xe6\xf8\xbe\xce" +#ifndef org_apache_arrow_flatbuf_Map_file_extension +#define org_apache_arrow_flatbuf_Map_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Union_file_identifier +#define org_apache_arrow_flatbuf_Union_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Union_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Union_identifier +#define org_apache_arrow_flatbuf_Union_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Union_type_hash ((flatbuffers_thash_t)0x896bda57) +#define org_apache_arrow_flatbuf_Union_type_identifier "\x57\xda\x6b\x89" +#ifndef org_apache_arrow_flatbuf_Union_file_extension +#define org_apache_arrow_flatbuf_Union_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Int_file_identifier +#define org_apache_arrow_flatbuf_Int_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Int_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Int_identifier +#define org_apache_arrow_flatbuf_Int_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Int_type_hash ((flatbuffers_thash_t)0x30789001) +#define org_apache_arrow_flatbuf_Int_type_identifier "\x01\x90\x78\x30" +#ifndef org_apache_arrow_flatbuf_Int_file_extension +#define org_apache_arrow_flatbuf_Int_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FloatingPoint_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FloatingPoint_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FloatingPoint_type_hash ((flatbuffers_thash_t)0xf7d06268) +#define org_apache_arrow_flatbuf_FloatingPoint_type_identifier "\x68\x62\xd0\xf7" +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_extension +#define org_apache_arrow_flatbuf_FloatingPoint_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8_file_identifier +#define org_apache_arrow_flatbuf_Utf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8_identifier +#define org_apache_arrow_flatbuf_Utf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8_type_hash ((flatbuffers_thash_t)0x8fe60d37) +#define org_apache_arrow_flatbuf_Utf8_type_identifier "\x37\x0d\xe6\x8f" +#ifndef org_apache_arrow_flatbuf_Utf8_file_extension +#define org_apache_arrow_flatbuf_Utf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Binary_file_identifier +#define org_apache_arrow_flatbuf_Binary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Binary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Binary_identifier +#define org_apache_arrow_flatbuf_Binary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Binary_type_hash ((flatbuffers_thash_t)0x8e21a795) +#define org_apache_arrow_flatbuf_Binary_type_identifier "\x95\xa7\x21\x8e" +#ifndef org_apache_arrow_flatbuf_Binary_file_extension +#define org_apache_arrow_flatbuf_Binary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeUtf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeUtf8_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeUtf8_type_hash ((flatbuffers_thash_t)0x24ed2fb0) +#define org_apache_arrow_flatbuf_LargeUtf8_type_identifier "\xb0\x2f\xed\x24" +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_extension +#define org_apache_arrow_flatbuf_LargeUtf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_identifier +#define org_apache_arrow_flatbuf_LargeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeBinary_identifier +#define org_apache_arrow_flatbuf_LargeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeBinary_type_hash ((flatbuffers_thash_t)0xbd437872) +#define org_apache_arrow_flatbuf_LargeBinary_type_identifier "\x72\x78\x43\xbd" +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_extension +#define org_apache_arrow_flatbuf_LargeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8View_file_identifier +#define org_apache_arrow_flatbuf_Utf8View_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8View_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8View_identifier +#define org_apache_arrow_flatbuf_Utf8View_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8View_type_hash ((flatbuffers_thash_t)0xab7692) +#define org_apache_arrow_flatbuf_Utf8View_type_identifier "\x92\x76\xab\x00" +#ifndef org_apache_arrow_flatbuf_Utf8View_file_extension +#define org_apache_arrow_flatbuf_Utf8View_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BinaryView_file_identifier +#define org_apache_arrow_flatbuf_BinaryView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BinaryView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BinaryView_identifier +#define org_apache_arrow_flatbuf_BinaryView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BinaryView_type_hash ((flatbuffers_thash_t)0x18c52428) +#define org_apache_arrow_flatbuf_BinaryView_type_identifier "\x28\x24\xc5\x18" +#ifndef org_apache_arrow_flatbuf_BinaryView_file_extension +#define org_apache_arrow_flatbuf_BinaryView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_hash ((flatbuffers_thash_t)0x80d0f4ce) +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier "\xce\xf4\xd0\x80" +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_extension +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Bool_file_identifier +#define org_apache_arrow_flatbuf_Bool_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Bool_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Bool_identifier +#define org_apache_arrow_flatbuf_Bool_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Bool_type_hash ((flatbuffers_thash_t)0x96bf83f0) +#define org_apache_arrow_flatbuf_Bool_type_identifier "\xf0\x83\xbf\x96" +#ifndef org_apache_arrow_flatbuf_Bool_file_extension +#define org_apache_arrow_flatbuf_Bool_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RunEndEncoded_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RunEndEncoded_type_hash ((flatbuffers_thash_t)0x5a98bcc) +#define org_apache_arrow_flatbuf_RunEndEncoded_type_identifier "\xcc\x8b\xa9\x05" +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_extension +#define org_apache_arrow_flatbuf_RunEndEncoded_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Decimal_file_identifier +#define org_apache_arrow_flatbuf_Decimal_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Decimal_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Decimal_identifier +#define org_apache_arrow_flatbuf_Decimal_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Decimal_type_hash ((flatbuffers_thash_t)0x91d1beb7) +#define org_apache_arrow_flatbuf_Decimal_type_identifier "\xb7\xbe\xd1\x91" +#ifndef org_apache_arrow_flatbuf_Decimal_file_extension +#define org_apache_arrow_flatbuf_Decimal_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Date_file_identifier +#define org_apache_arrow_flatbuf_Date_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Date_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Date_identifier +#define org_apache_arrow_flatbuf_Date_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Date_type_hash ((flatbuffers_thash_t)0xe0ccf624) +#define org_apache_arrow_flatbuf_Date_type_identifier "\x24\xf6\xcc\xe0" +#ifndef org_apache_arrow_flatbuf_Date_file_extension +#define org_apache_arrow_flatbuf_Date_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Time_file_identifier +#define org_apache_arrow_flatbuf_Time_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Time_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Time_identifier +#define org_apache_arrow_flatbuf_Time_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Time_type_hash ((flatbuffers_thash_t)0x2442a489) +#define org_apache_arrow_flatbuf_Time_type_identifier "\x89\xa4\x42\x24" +#ifndef org_apache_arrow_flatbuf_Time_file_extension +#define org_apache_arrow_flatbuf_Time_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Timestamp_file_identifier +#define org_apache_arrow_flatbuf_Timestamp_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Timestamp_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Timestamp_identifier +#define org_apache_arrow_flatbuf_Timestamp_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Timestamp_type_hash ((flatbuffers_thash_t)0x1fddf080) +#define org_apache_arrow_flatbuf_Timestamp_type_identifier "\x80\xf0\xdd\x1f" +#ifndef org_apache_arrow_flatbuf_Timestamp_file_extension +#define org_apache_arrow_flatbuf_Timestamp_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Interval_file_identifier +#define org_apache_arrow_flatbuf_Interval_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Interval_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Interval_identifier +#define org_apache_arrow_flatbuf_Interval_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Interval_type_hash ((flatbuffers_thash_t)0x1e2d6809) +#define org_apache_arrow_flatbuf_Interval_type_identifier "\x09\x68\x2d\x1e" +#ifndef org_apache_arrow_flatbuf_Interval_file_extension +#define org_apache_arrow_flatbuf_Interval_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Duration_file_identifier +#define org_apache_arrow_flatbuf_Duration_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Duration_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Duration_identifier +#define org_apache_arrow_flatbuf_Duration_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Duration_type_hash ((flatbuffers_thash_t)0x1ecea6b0) +#define org_apache_arrow_flatbuf_Duration_type_identifier "\xb0\xa6\xce\x1e" +#ifndef org_apache_arrow_flatbuf_Duration_file_extension +#define org_apache_arrow_flatbuf_Duration_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_KeyValue_file_identifier +#define org_apache_arrow_flatbuf_KeyValue_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_KeyValue_file_identifier */ +#ifndef org_apache_arrow_flatbuf_KeyValue_identifier +#define org_apache_arrow_flatbuf_KeyValue_identifier 0 +#endif +#define org_apache_arrow_flatbuf_KeyValue_type_hash ((flatbuffers_thash_t)0x3b264744) +#define org_apache_arrow_flatbuf_KeyValue_type_identifier "\x44\x47\x26\x3b" +#ifndef org_apache_arrow_flatbuf_KeyValue_file_extension +#define org_apache_arrow_flatbuf_KeyValue_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_hash ((flatbuffers_thash_t)0x8c703261) +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier "\x61\x32\x70\x8c" +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_extension +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Field_file_identifier +#define org_apache_arrow_flatbuf_Field_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Field_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Field_identifier +#define org_apache_arrow_flatbuf_Field_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Field_type_hash ((flatbuffers_thash_t)0xd981525c) +#define org_apache_arrow_flatbuf_Field_type_identifier "\x5c\x52\x81\xd9" +#ifndef org_apache_arrow_flatbuf_Field_file_extension +#define org_apache_arrow_flatbuf_Field_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Buffer_file_identifier +#define org_apache_arrow_flatbuf_Buffer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Buffer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Buffer_identifier +#define org_apache_arrow_flatbuf_Buffer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Buffer_type_hash ((flatbuffers_thash_t)0x519d7fea) +#define org_apache_arrow_flatbuf_Buffer_type_identifier "\xea\x7f\x9d\x51" +#ifndef org_apache_arrow_flatbuf_Buffer_file_extension +#define org_apache_arrow_flatbuf_Buffer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Schema_file_identifier +#define org_apache_arrow_flatbuf_Schema_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Schema_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Schema_identifier +#define org_apache_arrow_flatbuf_Schema_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Schema_type_hash ((flatbuffers_thash_t)0x406570b) +#define org_apache_arrow_flatbuf_Schema_type_identifier "\x0b\x57\x06\x04" +#ifndef org_apache_arrow_flatbuf_Schema_file_extension +#define org_apache_arrow_flatbuf_Schema_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_MetadataVersion_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 16) +/** 0.1.0 (October 2016). */ +#define org_apache_arrow_flatbuf_MetadataVersion_V1 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_MetadataVersion_V2 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_MetadataVersion_V3 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_MetadataVersion_V4 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(3)) +#define org_apache_arrow_flatbuf_MetadataVersion_V5 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(4)) + +static inline const char *org_apache_arrow_flatbuf_MetadataVersion_name(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return "V1"; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return "V2"; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return "V3"; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return "V4"; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return "V5"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MetadataVersion_is_known_value(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return 1; + default: return 0; + } +} + +/** Represents Arrow Features that might not have full support + * within implementations. This is intended to be used in + * two scenarios: + * 1. A mechanism for readers of Arrow Streams + * and files to understand that the stream or file makes + * use of a feature that isn't supported or unknown to + * the implementation (and therefore can meet the Arrow + * forward compatibility guarantees). + * 2. A means of negotiating between a client and server + * what features a stream is allowed to use. The enums + * values here are intented to represent higher level + * features, additional details maybe negotiated + * with key-value pairs specific to the protocol. + * + * Enums added to this list should be assigned power-of-two values + * to facilitate exchanging and comparing bitmaps for supported + * features. */ +typedef int64_t org_apache_arrow_flatbuf_Feature_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, 64) +/** Needed to make flatbuffers happy. */ +#define org_apache_arrow_flatbuf_Feature_UNUSED ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(0)) +#define org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(1)) +#define org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Feature_name(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return "UNUSED"; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return "DICTIONARY_REPLACEMENT"; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return "COMPRESSED_BODY"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Feature_is_known_value(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return 1; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return 1; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_UnionMode_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 16) +#define org_apache_arrow_flatbuf_UnionMode_Sparse ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_UnionMode_Dense ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_UnionMode_name(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return "Sparse"; + case org_apache_arrow_flatbuf_UnionMode_Dense: return "Dense"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_UnionMode_is_known_value(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return 1; + case org_apache_arrow_flatbuf_UnionMode_Dense: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_Precision_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 16) +#define org_apache_arrow_flatbuf_Precision_HALF ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Precision_SINGLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_Precision_DOUBLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Precision_name(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return "HALF"; + case org_apache_arrow_flatbuf_Precision_SINGLE: return "SINGLE"; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return "DOUBLE"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Precision_is_known_value(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return 1; + case org_apache_arrow_flatbuf_Precision_SINGLE: return 1; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_DateUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_DateUnit_DAY ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_DateUnit_MILLISECOND ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_DateUnit_name(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return "DAY"; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return "MILLISECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DateUnit_is_known_value(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return 1; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_TimeUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_TimeUnit_SECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_TimeUnit_MILLISECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_TimeUnit_MICROSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_TimeUnit_NANOSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(3)) + +static inline const char *org_apache_arrow_flatbuf_TimeUnit_name(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return "SECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return "MILLISECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return "MICROSECOND"; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return "NANOSECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_TimeUnit_is_known_value(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_IntervalUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_IntervalUnit_name(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return "YEAR_MONTH"; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return "DAY_TIME"; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return "MONTH_DAY_NANO"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_IntervalUnit_is_known_value(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Dictionary encoding metadata + * Maintained for forwards compatibility, in the future + * Dictionaries might be explicit maps between integers and values + * allowing for non-contiguous index values */ +typedef int16_t org_apache_arrow_flatbuf_DictionaryKind_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 16) +#define org_apache_arrow_flatbuf_DictionaryKind_DenseArray ((org_apache_arrow_flatbuf_DictionaryKind_enum_t)INT16_C(0)) + +static inline const char *org_apache_arrow_flatbuf_DictionaryKind_name(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return "DenseArray"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DictionaryKind_is_known_value(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Endianness of the platform producing the data */ +typedef int16_t org_apache_arrow_flatbuf_Endianness_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 16) +#define org_apache_arrow_flatbuf_Endianness_Little ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Endianness_Big ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_Endianness_name(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return "Little"; + case org_apache_arrow_flatbuf_Endianness_Big: return "Big"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Endianness_is_known_value(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return 1; + case org_apache_arrow_flatbuf_Endianness_Big: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * A Buffer represents a single contiguous memory segment */ +struct org_apache_arrow_flatbuf_Buffer { + /** The relative offset into the shared memory page where the bytes for this + * buffer starts */ + alignas(8) int64_t offset; + /** The absolute length (in bytes) of the memory buffer. The memory is found + * from offset (inclusive) to offset + length (non-inclusive). When building + * messages using the encapsulated IPC message, padding bytes may be written + * after a buffer, but such padding bytes do not need to be accounted for in + * the size here. */ + alignas(8) int64_t length; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Buffer_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__const_ptr_add(const org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__ptr_add(org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_struct_t org_apache_arrow_flatbuf_Buffer_vec_at(org_apache_arrow_flatbuf_Buffer_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Buffer__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_Buffer_vec_len(org_apache_arrow_flatbuf_Buffer_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Buffer) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, length, flatbuffers_int64, int64_t) + + +/** These are stored in the flatbuffer in the Type union below */ +struct org_apache_arrow_flatbuf_Null_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Null_vec_len(org_apache_arrow_flatbuf_Null_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Null_table_t org_apache_arrow_flatbuf_Null_vec_at(org_apache_arrow_flatbuf_Null_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Null_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Null) + + +/** A Struct_ in the flatbuffer metadata is the same as an Arrow Struct + * (according to the physical memory layout). We used Struct_ here as + * Struct is a reserved word in Flatbuffers */ +struct org_apache_arrow_flatbuf_Struct__table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Struct__vec_len(org_apache_arrow_flatbuf_Struct__vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Struct__table_t org_apache_arrow_flatbuf_Struct__vec_at(org_apache_arrow_flatbuf_Struct__vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Struct__table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Struct_) + + +struct org_apache_arrow_flatbuf_List_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_List_vec_len(org_apache_arrow_flatbuf_List_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_List_table_t org_apache_arrow_flatbuf_List_vec_at(org_apache_arrow_flatbuf_List_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_List_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_List) + + +/** Same as List, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeList_vec_len(org_apache_arrow_flatbuf_LargeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeList_table_t org_apache_arrow_flatbuf_LargeList_vec_at(org_apache_arrow_flatbuf_LargeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeList) + + +/** Represents the same logical types that List can, but contains offsets and + * sizes allowing for writes in any order and sharing of child values among + * list values. */ +struct org_apache_arrow_flatbuf_ListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_ListView_vec_len(org_apache_arrow_flatbuf_ListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_ListView_table_t org_apache_arrow_flatbuf_ListView_vec_at(org_apache_arrow_flatbuf_ListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_ListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_ListView) + + +/** Same as ListView, but with 64-bit offsets and sizes, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeListView_vec_len(org_apache_arrow_flatbuf_LargeListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeListView_table_t org_apache_arrow_flatbuf_LargeListView_vec_at(org_apache_arrow_flatbuf_LargeListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeListView) + + +struct org_apache_arrow_flatbuf_FixedSizeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeList_vec_len(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeList_table_t org_apache_arrow_flatbuf_FixedSizeList_vec_at(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeList) + +/** Number of list items per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeList, listSize, flatbuffers_int32, int32_t, INT32_C(0)) + +/** A Map is a logical nested type that is represented as + * + * List> + * + * In this layout, the keys and values are each respectively contiguous. We do + * not constrain the key and value types, so the application is responsible + * for ensuring that the keys are hashable and unique. Whether the keys are sorted + * may be set in the metadata for this field. + * + * In a field with Map type, the field has a child Struct field, which then + * has two children: key type and the second the value type. The names of the + * child fields may be respectively "entries", "key", and "value", but this is + * not enforced. + * + * Map + * ```text + * - child[0] entries: Struct + * - child[0] key: K + * - child[1] value: V + * ``` + * Neither the "entries" field nor the "key" field may be nullable. + * + * The metadata is structured so that Arrow systems without special handling + * for Map can make Map an alias for List. The "layout" attribute for the Map + * field must have the same contents as a List. */ +struct org_apache_arrow_flatbuf_Map_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Map_vec_len(org_apache_arrow_flatbuf_Map_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Map_table_t org_apache_arrow_flatbuf_Map_vec_at(org_apache_arrow_flatbuf_Map_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Map_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Map) + +/** Set to true if the keys within each value are sorted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Map, keysSorted, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** A union is a complex type with children in Field + * By default ids in the type vector refer to the offsets in the children + * optionally typeIds provides an indirection between the child offset and the type id + * for each child `typeIds[offset]` is the id used in the type vector */ +struct org_apache_arrow_flatbuf_Union_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Union_vec_len(org_apache_arrow_flatbuf_Union_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Union_table_t org_apache_arrow_flatbuf_Union_vec_at(org_apache_arrow_flatbuf_Union_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Union_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Union) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Union, mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Union, typeIds, flatbuffers_int32_vec_t, 0) + +struct org_apache_arrow_flatbuf_Int_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Int_vec_len(org_apache_arrow_flatbuf_Int_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Int_table_t org_apache_arrow_flatbuf_Int_vec_at(org_apache_arrow_flatbuf_Int_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Int_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Int) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Int, bitWidth, flatbuffers_int32, int32_t, INT32_C(0)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Int, is_signed, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +struct org_apache_arrow_flatbuf_FloatingPoint_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FloatingPoint_vec_len(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FloatingPoint_table_t org_apache_arrow_flatbuf_FloatingPoint_vec_at(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FloatingPoint_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FloatingPoint) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FloatingPoint, precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, INT16_C(0)) + +/** Unicode with UTF-8 encoding */ +struct org_apache_arrow_flatbuf_Utf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8_vec_len(org_apache_arrow_flatbuf_Utf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8_table_t org_apache_arrow_flatbuf_Utf8_vec_at(org_apache_arrow_flatbuf_Utf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8) + + +/** Opaque binary data */ +struct org_apache_arrow_flatbuf_Binary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Binary_vec_len(org_apache_arrow_flatbuf_Binary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Binary_table_t org_apache_arrow_flatbuf_Binary_vec_at(org_apache_arrow_flatbuf_Binary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Binary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Binary) + + +/** Same as Utf8, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeUtf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeUtf8_vec_len(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeUtf8_table_t org_apache_arrow_flatbuf_LargeUtf8_vec_at(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeUtf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeUtf8) + + +/** Same as Binary, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeBinary_vec_len(org_apache_arrow_flatbuf_LargeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeBinary_table_t org_apache_arrow_flatbuf_LargeBinary_vec_at(org_apache_arrow_flatbuf_LargeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeBinary) + + +/** Logically the same as Utf8, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_Utf8View_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8View_vec_len(org_apache_arrow_flatbuf_Utf8View_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8View_table_t org_apache_arrow_flatbuf_Utf8View_vec_at(org_apache_arrow_flatbuf_Utf8View_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8View_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8View) + + +/** Logically the same as Binary, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_BinaryView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BinaryView_vec_len(org_apache_arrow_flatbuf_BinaryView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BinaryView_table_t org_apache_arrow_flatbuf_BinaryView_vec_at(org_apache_arrow_flatbuf_BinaryView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BinaryView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BinaryView) + + +struct org_apache_arrow_flatbuf_FixedSizeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_len(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeBinary_table_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeBinary) + +/** Number of bytes per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeBinary, byteWidth, flatbuffers_int32, int32_t, INT32_C(0)) + +struct org_apache_arrow_flatbuf_Bool_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Bool_vec_len(org_apache_arrow_flatbuf_Bool_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Bool_table_t org_apache_arrow_flatbuf_Bool_vec_at(org_apache_arrow_flatbuf_Bool_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Bool_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Bool) + + +/** Contains two child arrays, run_ends and values. + * The run_ends child array must be a 16/32/64-bit integer array + * which encodes the indices at which the run with the value in + * each corresponding index in the values child array ends. + * Like list/struct types, the value array can be of any type. */ +struct org_apache_arrow_flatbuf_RunEndEncoded_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RunEndEncoded_vec_len(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RunEndEncoded_table_t org_apache_arrow_flatbuf_RunEndEncoded_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RunEndEncoded) + + +/** Exact decimal value represented as an integer value in two's + * complement. Currently only 128-bit (16-byte) and 256-bit (32-byte) integers + * are used. The representation uses the endianness indicated + * in the Schema. */ +struct org_apache_arrow_flatbuf_Decimal_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Decimal_vec_len(org_apache_arrow_flatbuf_Decimal_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Decimal_table_t org_apache_arrow_flatbuf_Decimal_vec_at(org_apache_arrow_flatbuf_Decimal_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Decimal_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Decimal) + +/** Total number of decimal digits */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Decimal, precision, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of digits after the decimal point "." */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Decimal, scale, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of bits per value. The only accepted widths are 128 and 256. + * We use bitWidth for consistency with Int::bitWidth. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_Decimal, bitWidth, flatbuffers_int32, int32_t, INT32_C(128)) + +/** Date is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since UNIX epoch (1970-01-01), stored in either of two units: + * + * * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no + * leap seconds), where the values are evenly divisible by 86400000 + * * Days (32 bits) since the UNIX epoch */ +struct org_apache_arrow_flatbuf_Date_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Date_vec_len(org_apache_arrow_flatbuf_Date_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Date_table_t org_apache_arrow_flatbuf_Date_vec_at(org_apache_arrow_flatbuf_Date_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Date_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Date) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Date, unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, INT16_C(1)) + +/** Time is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since midnight, stored in either of four units: seconds, + * milliseconds, microseconds or nanoseconds. + * + * The integer `bitWidth` depends on the `unit` and must be one of the following: + * * SECOND and MILLISECOND: 32 bits + * * MICROSECOND and NANOSECOND: 64 bits + * + * The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds + * (exclusive), adjusted for the time unit (for example, up to 86400000 + * exclusive for the MILLISECOND unit). + * This definition doesn't allow for leap seconds. Time values from + * measurements with leap seconds will need to be corrected when ingesting + * into Arrow (for example by replacing the value 86400 with 86399). */ +struct org_apache_arrow_flatbuf_Time_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Time_vec_len(org_apache_arrow_flatbuf_Time_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Time_table_t org_apache_arrow_flatbuf_Time_vec_at(org_apache_arrow_flatbuf_Time_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Time_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Time) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Time, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Time, bitWidth, flatbuffers_int32, int32_t, INT32_C(32)) + +/** Timestamp is a 64-bit signed integer representing an elapsed time since a + * fixed epoch, stored in either of four units: seconds, milliseconds, + * microseconds or nanoseconds, and is optionally annotated with a timezone. + * + * Timestamp values do not include any leap seconds (in other words, all + * days are considered 86400 seconds long). + * + * Timestamps with a non-empty timezone + * ------------------------------------ + * + * If a Timestamp column has a non-empty timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone + * (the Unix epoch), regardless of the Timestamp's own timezone. + * + * Therefore, timestamp values with a non-empty timezone correspond to + * physical points in time together with some additional information about + * how the data was obtained and/or how to display it (the timezone). + * + * For example, the timestamp value 0 with the timezone string "Europe/Paris" + * corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the + * application may prefer to display it as "January 1st 1970, 01h00" in + * the Europe/Paris timezone (which is the same physical point in time). + * + * One consequence is that timestamp values with a non-empty timezone + * can be compared and ordered directly, since they all share the same + * well-known point of reference (the Unix epoch). + * + * Timestamps with an unset / empty timezone + * ----------------------------------------- + * + * If a Timestamp column has no timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. + * + * Therefore, timestamp values without a timezone cannot be meaningfully + * interpreted as physical points in time, but only as calendar / clock + * indications ("wall clock time") in an unspecified timezone. + * + * For example, the timestamp value 0 with an empty timezone string + * corresponds to "January 1st 1970, 00h00" in an unknown timezone: there + * is not enough information to interpret it as a well-defined physical + * point in time. + * + * One consequence is that timestamp values without a timezone cannot + * be reliably compared or ordered, since they may have different points of + * reference. In particular, it is *not* possible to interpret an unset + * or empty timezone as the same as "UTC". + * + * Conversion between timezones + * ---------------------------- + * + * If a Timestamp column has a non-empty timezone, changing the timezone + * to a different non-empty value is a metadata-only operation: + * the timestamp values need not change as their point of reference remains + * the same (the Unix epoch). + * + * However, if a Timestamp column has no timezone value, changing it to a + * non-empty value requires to think about the desired semantics. + * One possibility is to assume that the original timestamp values are + * relative to the epoch of the timezone being set; timestamp values should + * then adjusted to the Unix epoch (for example, changing the timezone from + * empty to "Europe/Paris" would require converting the timestamp values + * from "Europe/Paris" to "UTC", which seems counter-intuitive but is + * nevertheless correct). + * + * Guidelines for encoding data from external libraries + * ---------------------------------------------------- + * + * Date & time libraries often have multiple different data types for temporal + * data. In order to ease interoperability between different implementations the + * Arrow project has some recommendations for encoding these types into a Timestamp + * column. + * + * An "instant" represents a physical point in time that has no relevant timezone + * (for example, astronomical data). To encode an instant, use a Timestamp with + * the timezone string set to "UTC", and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * A "zoned date-time" represents a physical point in time annotated with an + * informative timezone (for example, the timezone in which the data was + * recorded). To encode a zoned date-time, use a Timestamp with the timezone + * string set to the name of the timezone, and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * (There is some ambiguity between an instant and a zoned date-time with the + * UTC timezone. Both of these are stored the same in Arrow. Typically, + * this distinction does not matter. If it does, then an application should + * use custom metadata or an extension type to distinguish between the two cases.) + * + * An "offset date-time" represents a physical point in time combined with an + * explicit offset from UTC. To encode an offset date-time, use a Timestamp + * with the timezone string set to the numeric timezone offset string + * (e.g. "+03:00"), and make sure the Timestamp values are relative to + * the UTC epoch (January 1st 1970, midnight). + * + * A "naive date-time" (also called "local date-time" in some libraries) + * represents a wall clock time combined with a calendar date, but with + * no indication of how to map this information to a physical point in time. + * Naive date-times must be handled with care because of this missing + * information, and also because daylight saving time (DST) may make + * some values ambiguous or nonexistent. A naive date-time may be + * stored as a struct with Date and Time fields. However, it may also be + * encoded into a Timestamp column with an empty timezone. The timestamp + * values should be computed "as if" the timezone of the date-time values + * was UTC; for example, the naive date-time "January 1st 1970, 00h00" would + * be encoded as timestamp value 0. */ +struct org_apache_arrow_flatbuf_Timestamp_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Timestamp_vec_len(org_apache_arrow_flatbuf_Timestamp_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Timestamp_table_t org_apache_arrow_flatbuf_Timestamp_vec_at(org_apache_arrow_flatbuf_Timestamp_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Timestamp_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Timestamp) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Timestamp, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(0)) +/** The timezone is an optional string indicating the name of a timezone, + * one of: + * + * * As used in the Olson timezone database (the "tz database" or + * "tzdata"), such as "America/New_York". + * * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + * such as "+07:30". + * + * Whether a timezone string is present indicates different semantics about + * the data (see above). */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_Timestamp, timezone, 0) + +struct org_apache_arrow_flatbuf_Interval_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Interval_vec_len(org_apache_arrow_flatbuf_Interval_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Interval_table_t org_apache_arrow_flatbuf_Interval_vec_at(org_apache_arrow_flatbuf_Interval_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Interval_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Interval) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Interval, unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, INT16_C(0)) + +struct org_apache_arrow_flatbuf_Duration_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Duration_vec_len(org_apache_arrow_flatbuf_Duration_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Duration_table_t org_apache_arrow_flatbuf_Duration_vec_at(org_apache_arrow_flatbuf_Duration_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Duration_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Duration) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Duration, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +/** ---------------------------------------------------------------------- + * Top-level Type value, enabling extensible type-specific metadata. We can + * add new logical types to Type without breaking backwards compatibility */ +typedef uint8_t org_apache_arrow_flatbuf_Type_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Type_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_Type) +/** ---------------------------------------------------------------------- + * user defined key value pairs to add custom metadata to arrow + * key namespacing is the responsibility of the user */ +#define org_apache_arrow_flatbuf_Type_NONE ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_Type_Null ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_Type_Int ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_Type_FloatingPoint ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_Type_Binary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_Type_Utf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(5)) +#define org_apache_arrow_flatbuf_Type_Bool ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(6)) +#define org_apache_arrow_flatbuf_Type_Decimal ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(7)) +#define org_apache_arrow_flatbuf_Type_Date ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(8)) +#define org_apache_arrow_flatbuf_Type_Time ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(9)) +#define org_apache_arrow_flatbuf_Type_Timestamp ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(10)) +#define org_apache_arrow_flatbuf_Type_Interval ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(11)) +#define org_apache_arrow_flatbuf_Type_List ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(12)) +#define org_apache_arrow_flatbuf_Type_Struct_ ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(13)) +#define org_apache_arrow_flatbuf_Type_Union ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(14)) +#define org_apache_arrow_flatbuf_Type_FixedSizeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(15)) +#define org_apache_arrow_flatbuf_Type_FixedSizeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(16)) +#define org_apache_arrow_flatbuf_Type_Map ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(17)) +#define org_apache_arrow_flatbuf_Type_Duration ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(18)) +#define org_apache_arrow_flatbuf_Type_LargeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(19)) +#define org_apache_arrow_flatbuf_Type_LargeUtf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(20)) +#define org_apache_arrow_flatbuf_Type_LargeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(21)) +#define org_apache_arrow_flatbuf_Type_RunEndEncoded ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(22)) +#define org_apache_arrow_flatbuf_Type_BinaryView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(23)) +#define org_apache_arrow_flatbuf_Type_Utf8View ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(24)) +#define org_apache_arrow_flatbuf_Type_ListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(25)) +#define org_apache_arrow_flatbuf_Type_LargeListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(26)) + +static inline const char *org_apache_arrow_flatbuf_Type_type_name(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return "NONE"; + case org_apache_arrow_flatbuf_Type_Null: return "Null"; + case org_apache_arrow_flatbuf_Type_Int: return "Int"; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return "FloatingPoint"; + case org_apache_arrow_flatbuf_Type_Binary: return "Binary"; + case org_apache_arrow_flatbuf_Type_Utf8: return "Utf8"; + case org_apache_arrow_flatbuf_Type_Bool: return "Bool"; + case org_apache_arrow_flatbuf_Type_Decimal: return "Decimal"; + case org_apache_arrow_flatbuf_Type_Date: return "Date"; + case org_apache_arrow_flatbuf_Type_Time: return "Time"; + case org_apache_arrow_flatbuf_Type_Timestamp: return "Timestamp"; + case org_apache_arrow_flatbuf_Type_Interval: return "Interval"; + case org_apache_arrow_flatbuf_Type_List: return "List"; + case org_apache_arrow_flatbuf_Type_Struct_: return "Struct_"; + case org_apache_arrow_flatbuf_Type_Union: return "Union"; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return "FixedSizeBinary"; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return "FixedSizeList"; + case org_apache_arrow_flatbuf_Type_Map: return "Map"; + case org_apache_arrow_flatbuf_Type_Duration: return "Duration"; + case org_apache_arrow_flatbuf_Type_LargeBinary: return "LargeBinary"; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return "LargeUtf8"; + case org_apache_arrow_flatbuf_Type_LargeList: return "LargeList"; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return "RunEndEncoded"; + case org_apache_arrow_flatbuf_Type_BinaryView: return "BinaryView"; + case org_apache_arrow_flatbuf_Type_Utf8View: return "Utf8View"; + case org_apache_arrow_flatbuf_Type_ListView: return "ListView"; + case org_apache_arrow_flatbuf_Type_LargeListView: return "LargeListView"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Type_is_known_type(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return 1; + case org_apache_arrow_flatbuf_Type_Null: return 1; + case org_apache_arrow_flatbuf_Type_Int: return 1; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return 1; + case org_apache_arrow_flatbuf_Type_Binary: return 1; + case org_apache_arrow_flatbuf_Type_Utf8: return 1; + case org_apache_arrow_flatbuf_Type_Bool: return 1; + case org_apache_arrow_flatbuf_Type_Decimal: return 1; + case org_apache_arrow_flatbuf_Type_Date: return 1; + case org_apache_arrow_flatbuf_Type_Time: return 1; + case org_apache_arrow_flatbuf_Type_Timestamp: return 1; + case org_apache_arrow_flatbuf_Type_Interval: return 1; + case org_apache_arrow_flatbuf_Type_List: return 1; + case org_apache_arrow_flatbuf_Type_Struct_: return 1; + case org_apache_arrow_flatbuf_Type_Union: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return 1; + case org_apache_arrow_flatbuf_Type_Map: return 1; + case org_apache_arrow_flatbuf_Type_Duration: return 1; + case org_apache_arrow_flatbuf_Type_LargeBinary: return 1; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return 1; + case org_apache_arrow_flatbuf_Type_LargeList: return 1; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return 1; + case org_apache_arrow_flatbuf_Type_BinaryView: return 1; + case org_apache_arrow_flatbuf_Type_Utf8View: return 1; + case org_apache_arrow_flatbuf_Type_ListView: return 1; + case org_apache_arrow_flatbuf_Type_LargeListView: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_KeyValue_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_KeyValue_vec_len(org_apache_arrow_flatbuf_KeyValue_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_KeyValue_table_t org_apache_arrow_flatbuf_KeyValue_vec_at(org_apache_arrow_flatbuf_KeyValue_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_KeyValue_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_KeyValue) + +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_KeyValue, key, 0) +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_KeyValue, value, 0) + +struct org_apache_arrow_flatbuf_DictionaryEncoding_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_len(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryEncoding_table_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryEncoding) + +/** The known dictionary id in the application where this data is used. In + * the file or streaming formats, the dictionary ids are found in the + * DictionaryBatch messages */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryEncoding, id, flatbuffers_int64, int64_t, INT64_C(0)) +/** The dictionary indices are constrained to be non-negative integers. If + * this field is null, the indices must be signed int32. To maximize + * cross-language compatibility and performance, implementations are + * recommended to prefer signed integer types over unsigned integer types + * and to avoid uint64 indices unless they are required by an application. */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryEncoding, indexType, org_apache_arrow_flatbuf_Int_table_t, 0) +/** By default, dictionaries are not ordered, or the order does not have + * semantic meaning. In some statistical, applications, dictionary-encoding + * is used to represent ordered categorical data, and we provide a way to + * preserve that metadata here */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryEncoding, isOrdered, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_DictionaryEncoding, dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, INT16_C(0)) + +/** ---------------------------------------------------------------------- + * A field represents a named column in a record / row batch or child of a + * nested type. */ +struct org_apache_arrow_flatbuf_Field_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Field_vec_len(org_apache_arrow_flatbuf_Field_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Field_table_t org_apache_arrow_flatbuf_Field_vec_at(org_apache_arrow_flatbuf_Field_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Field_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Field) + +/** Name is not required, in i.e. a List */ +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_Field, name, 0) +/** Whether or not this field can contain nulls. Should be true in general. */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Field, nullable, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** This is the type of the decoded value if the field is dictionary encoded. */ +__flatbuffers_define_union_field(flatbuffers_, 3, org_apache_arrow_flatbuf_Field, type, org_apache_arrow_flatbuf_Type, 0) +/** Present only if the field is dictionary encoded. */ +__flatbuffers_define_table_field(4, org_apache_arrow_flatbuf_Field, dictionary, org_apache_arrow_flatbuf_DictionaryEncoding_table_t, 0) +/** children apply only to nested data types like Struct, List and Union. For + * primitive types children will have length 0. */ +__flatbuffers_define_vector_field(5, org_apache_arrow_flatbuf_Field, children, org_apache_arrow_flatbuf_Field_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(6, org_apache_arrow_flatbuf_Field, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + +/** ---------------------------------------------------------------------- + * A Schema describes the columns in a row batch */ +struct org_apache_arrow_flatbuf_Schema_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Schema_vec_len(org_apache_arrow_flatbuf_Schema_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Schema_table_t org_apache_arrow_flatbuf_Schema_vec_at(org_apache_arrow_flatbuf_Schema_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Schema_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Schema) + +/** endianness of the buffer + * it is Little Endian by default + * if endianness doesn't match the underlying system then the vectors need to be converted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Schema, endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Schema, fields, org_apache_arrow_flatbuf_Field_vec_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Schema, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) +/** Features used in the stream/file. */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Schema, features, org_apache_arrow_flatbuf_Feature_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_READER_H */ +#ifndef SCHEMA_BUILDER_H +#define SCHEMA_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_MetadataVersion_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0 +#define __org_apache_arrow_flatbuf_MetadataVersion_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t) +#define __org_apache_arrow_flatbuf_Feature_formal_args , org_apache_arrow_flatbuf_Feature_enum_t v0 +#define __org_apache_arrow_flatbuf_Feature_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t) +#define __org_apache_arrow_flatbuf_UnionMode_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0 +#define __org_apache_arrow_flatbuf_UnionMode_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t) +#define __org_apache_arrow_flatbuf_Precision_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_Precision_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t) +#define __org_apache_arrow_flatbuf_DateUnit_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_DateUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t) +#define __org_apache_arrow_flatbuf_TimeUnit_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_TimeUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t) +#define __org_apache_arrow_flatbuf_IntervalUnit_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_IntervalUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t) +#define __org_apache_arrow_flatbuf_DictionaryKind_formal_args , org_apache_arrow_flatbuf_DictionaryKind_enum_t v0 +#define __org_apache_arrow_flatbuf_DictionaryKind_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t) +#define __org_apache_arrow_flatbuf_Endianness_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0 +#define __org_apache_arrow_flatbuf_Endianness_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t) + +#define __org_apache_arrow_flatbuf_Buffer_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_Buffer_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ p->offset = v0; p->length = v1; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ p->offset = p2->offset; p->length = p2->length; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int64_assign_to_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_to_pe(&p->length, &p2->length); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int64_assign_from_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_from_pe(&p->length, &p2->length); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Buffer_file_identifier, org_apache_arrow_flatbuf_Buffer_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_Type_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_Type_union_vec_ref_t; +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Null_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Null_ref_t; +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Null, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Struct__required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Struct__ref_t; +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Struct_, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_List_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_List_ref_t; +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_List, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeList_ref_t; +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeList, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_ListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_ListView_ref_t; +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_ListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeListView_ref_t; +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeList_ref_t; +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Map_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Map_ref_t; +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Map, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Union_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Union_ref_t; +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Union, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Int_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Int_ref_t; +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Int, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FloatingPoint_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FloatingPoint_ref_t; +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8_ref_t; +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Binary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Binary_ref_t; +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Binary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeUtf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeUtf8_ref_t; +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeBinary_ref_t; +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8View_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8View_ref_t; +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BinaryView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BinaryView_ref_t; +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_ref_t; +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Bool_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Bool_ref_t; +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Bool, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RunEndEncoded_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RunEndEncoded_ref_t; +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Decimal_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Decimal_ref_t; +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Decimal, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Date_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Date_ref_t; +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Date, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Time_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Time_ref_t; +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Time, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Timestamp_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Timestamp_ref_t; +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Interval_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Interval_ref_t; +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Interval, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Duration_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Duration_ref_t; +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Duration, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_KeyValue_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_KeyValue_ref_t; +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryEncoding_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_ref_t; +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Field_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Field_ref_t; +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Field, 7) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Schema_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Schema_ref_t; +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Schema, 4) + +#define __org_apache_arrow_flatbuf_Null_formal_args +#define __org_apache_arrow_flatbuf_Null_call_args +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Null, org_apache_arrow_flatbuf_Null_file_identifier, org_apache_arrow_flatbuf_Null_type_identifier) + +#define __org_apache_arrow_flatbuf_Struct__formal_args +#define __org_apache_arrow_flatbuf_Struct__call_args +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Struct_, org_apache_arrow_flatbuf_Struct__file_identifier, org_apache_arrow_flatbuf_Struct__type_identifier) + +#define __org_apache_arrow_flatbuf_List_formal_args +#define __org_apache_arrow_flatbuf_List_call_args +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_List, org_apache_arrow_flatbuf_List_file_identifier, org_apache_arrow_flatbuf_List_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeList_formal_args +#define __org_apache_arrow_flatbuf_LargeList_call_args +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeList, org_apache_arrow_flatbuf_LargeList_file_identifier, org_apache_arrow_flatbuf_LargeList_type_identifier) + +#define __org_apache_arrow_flatbuf_ListView_formal_args +#define __org_apache_arrow_flatbuf_ListView_call_args +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_ListView, org_apache_arrow_flatbuf_ListView_file_identifier, org_apache_arrow_flatbuf_ListView_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeListView_formal_args +#define __org_apache_arrow_flatbuf_LargeListView_call_args +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, org_apache_arrow_flatbuf_LargeListView_file_identifier, org_apache_arrow_flatbuf_LargeListView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeList_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeList_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList_file_identifier, org_apache_arrow_flatbuf_FixedSizeList_type_identifier) + +#define __org_apache_arrow_flatbuf_Map_formal_args , flatbuffers_bool_t v0 +#define __org_apache_arrow_flatbuf_Map_call_args , v0 +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Map, org_apache_arrow_flatbuf_Map_file_identifier, org_apache_arrow_flatbuf_Map_type_identifier) + +#define __org_apache_arrow_flatbuf_Union_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0, flatbuffers_int32_vec_ref_t v1 +#define __org_apache_arrow_flatbuf_Union_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Union, org_apache_arrow_flatbuf_Union_file_identifier, org_apache_arrow_flatbuf_Union_type_identifier) + +#define __org_apache_arrow_flatbuf_Int_formal_args , int32_t v0, flatbuffers_bool_t v1 +#define __org_apache_arrow_flatbuf_Int_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_Int_file_identifier, org_apache_arrow_flatbuf_Int_type_identifier) + +#define __org_apache_arrow_flatbuf_FloatingPoint_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_FloatingPoint_call_args , v0 +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint_file_identifier, org_apache_arrow_flatbuf_FloatingPoint_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8_formal_args +#define __org_apache_arrow_flatbuf_Utf8_call_args +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8, org_apache_arrow_flatbuf_Utf8_file_identifier, org_apache_arrow_flatbuf_Utf8_type_identifier) + +#define __org_apache_arrow_flatbuf_Binary_formal_args +#define __org_apache_arrow_flatbuf_Binary_call_args +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Binary, org_apache_arrow_flatbuf_Binary_file_identifier, org_apache_arrow_flatbuf_Binary_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeUtf8_formal_args +#define __org_apache_arrow_flatbuf_LargeUtf8_call_args +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8_file_identifier, org_apache_arrow_flatbuf_LargeUtf8_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeBinary_formal_args +#define __org_apache_arrow_flatbuf_LargeBinary_call_args +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, org_apache_arrow_flatbuf_LargeBinary_file_identifier, org_apache_arrow_flatbuf_LargeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8View_formal_args +#define __org_apache_arrow_flatbuf_Utf8View_call_args +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, org_apache_arrow_flatbuf_Utf8View_file_identifier, org_apache_arrow_flatbuf_Utf8View_type_identifier) + +#define __org_apache_arrow_flatbuf_BinaryView_formal_args +#define __org_apache_arrow_flatbuf_BinaryView_call_args +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, org_apache_arrow_flatbuf_BinaryView_file_identifier, org_apache_arrow_flatbuf_BinaryView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeBinary_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Bool_formal_args +#define __org_apache_arrow_flatbuf_Bool_call_args +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Bool, org_apache_arrow_flatbuf_Bool_file_identifier, org_apache_arrow_flatbuf_Bool_type_identifier) + +#define __org_apache_arrow_flatbuf_RunEndEncoded_formal_args +#define __org_apache_arrow_flatbuf_RunEndEncoded_call_args +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded_file_identifier, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier) + +#define __org_apache_arrow_flatbuf_Decimal_formal_args , int32_t v0, int32_t v1, int32_t v2 +#define __org_apache_arrow_flatbuf_Decimal_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Decimal, org_apache_arrow_flatbuf_Decimal_file_identifier, org_apache_arrow_flatbuf_Decimal_type_identifier) + +#define __org_apache_arrow_flatbuf_Date_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Date_call_args , v0 +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Date, org_apache_arrow_flatbuf_Date_file_identifier, org_apache_arrow_flatbuf_Date_type_identifier) + +#define __org_apache_arrow_flatbuf_Time_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, int32_t v1 +#define __org_apache_arrow_flatbuf_Time_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Time, org_apache_arrow_flatbuf_Time_file_identifier, org_apache_arrow_flatbuf_Time_type_identifier) + +#define __org_apache_arrow_flatbuf_Timestamp_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_Timestamp_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, org_apache_arrow_flatbuf_Timestamp_file_identifier, org_apache_arrow_flatbuf_Timestamp_type_identifier) + +#define __org_apache_arrow_flatbuf_Interval_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Interval_call_args , v0 +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Interval, org_apache_arrow_flatbuf_Interval_file_identifier, org_apache_arrow_flatbuf_Interval_type_identifier) + +#define __org_apache_arrow_flatbuf_Duration_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Duration_call_args , v0 +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Duration, org_apache_arrow_flatbuf_Duration_file_identifier, org_apache_arrow_flatbuf_Duration_type_identifier) + +#define __org_apache_arrow_flatbuf_KeyValue_formal_args , flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_KeyValue_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_KeyValue_file_identifier, org_apache_arrow_flatbuf_KeyValue_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args , int64_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, flatbuffers_bool_t v2, org_apache_arrow_flatbuf_DictionaryKind_enum_t v3 +#define __org_apache_arrow_flatbuf_DictionaryEncoding_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier) + +#define __org_apache_arrow_flatbuf_Field_formal_args ,\ + flatbuffers_string_ref_t v0, flatbuffers_bool_t v1, org_apache_arrow_flatbuf_Type_union_ref_t v3, org_apache_arrow_flatbuf_DictionaryEncoding_ref_t v4, org_apache_arrow_flatbuf_Field_vec_ref_t v5, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v6 +#define __org_apache_arrow_flatbuf_Field_call_args ,\ + v0, v1, v3, v4, v5, v6 +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field_file_identifier, org_apache_arrow_flatbuf_Field_type_identifier) + +#define __org_apache_arrow_flatbuf_Schema_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0, org_apache_arrow_flatbuf_Field_vec_ref_t v1, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v2, org_apache_arrow_flatbuf_Feature_vec_ref_t v3 +#define __org_apache_arrow_flatbuf_Schema_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Schema_file_identifier, org_apache_arrow_flatbuf_Schema_type_identifier) + +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_NONE(void) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Null; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Int; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FloatingPoint; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Binary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Bool; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Decimal; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Date; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Time; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Timestamp; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Interval; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_List; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Struct_; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Union; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Map; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Duration; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeUtf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_RunEndEncoded; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_BinaryView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8View; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_ListView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeListView; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_Type) + +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_clone(B, (org_apache_arrow_flatbuf_Null_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_clone(B, (org_apache_arrow_flatbuf_Int_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_clone(B, (org_apache_arrow_flatbuf_FloatingPoint_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_clone(B, (org_apache_arrow_flatbuf_Binary_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_clone(B, (org_apache_arrow_flatbuf_Utf8_table_t)u.value)); + case 6: return org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_clone(B, (org_apache_arrow_flatbuf_Bool_table_t)u.value)); + case 7: return org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_clone(B, (org_apache_arrow_flatbuf_Decimal_table_t)u.value)); + case 8: return org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_clone(B, (org_apache_arrow_flatbuf_Date_table_t)u.value)); + case 9: return org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_clone(B, (org_apache_arrow_flatbuf_Time_table_t)u.value)); + case 10: return org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_clone(B, (org_apache_arrow_flatbuf_Timestamp_table_t)u.value)); + case 11: return org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_clone(B, (org_apache_arrow_flatbuf_Interval_table_t)u.value)); + case 12: return org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_clone(B, (org_apache_arrow_flatbuf_List_table_t)u.value)); + case 13: return org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__clone(B, (org_apache_arrow_flatbuf_Struct__table_t)u.value)); + case 14: return org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_clone(B, (org_apache_arrow_flatbuf_Union_table_t)u.value)); + case 15: return org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_clone(B, (org_apache_arrow_flatbuf_FixedSizeBinary_table_t)u.value)); + case 16: return org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_clone(B, (org_apache_arrow_flatbuf_FixedSizeList_table_t)u.value)); + case 17: return org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_clone(B, (org_apache_arrow_flatbuf_Map_table_t)u.value)); + case 18: return org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_clone(B, (org_apache_arrow_flatbuf_Duration_table_t)u.value)); + case 19: return org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_clone(B, (org_apache_arrow_flatbuf_LargeBinary_table_t)u.value)); + case 20: return org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_clone(B, (org_apache_arrow_flatbuf_LargeUtf8_table_t)u.value)); + case 21: return org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_clone(B, (org_apache_arrow_flatbuf_LargeList_table_t)u.value)); + case 22: return org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_clone(B, (org_apache_arrow_flatbuf_RunEndEncoded_table_t)u.value)); + case 23: return org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_clone(B, (org_apache_arrow_flatbuf_BinaryView_table_t)u.value)); + case 24: return org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_clone(B, (org_apache_arrow_flatbuf_Utf8View_table_t)u.value)); + case 25: return org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_clone(B, (org_apache_arrow_flatbuf_ListView_table_t)u.value)); + case 26: return org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_clone(B, (org_apache_arrow_flatbuf_LargeListView_table_t)u.value)); + default: return org_apache_arrow_flatbuf_Type_as_NONE(); + } +} + + +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args) +{ + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Null_end(B); +} + +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Null_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args) +{ + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Struct__end(B); +} + +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Struct__end(B)); +} + + +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args) +{ + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_List_end(B); +} + +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_List_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeList_end(B); +} + +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeList_end(B)); +} + + +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args) +{ + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_ListView_end(B); +} + +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_ListView_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeListView_end(B); +} + +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeListView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList_listSize, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeList) + +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeList_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeList_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Map_keysSorted, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Map) + +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args) +{ + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Map_end(B); +} + +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Map_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Union_mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Union) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Union_typeIds, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_Union) + +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args) +{ + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_add(B, v1) + || org_apache_arrow_flatbuf_Union_mode_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Union_end(B); +} + +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_pick(B, t) + || org_apache_arrow_flatbuf_Union_mode_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Union_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Int_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Int) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Int_is_signed, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Int) + +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args) +{ + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_add(B, v0) + || org_apache_arrow_flatbuf_Int_is_signed_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_Int_end(B); +} + +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Int_is_signed_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Int_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint_precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_FloatingPoint) + +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args) +{ + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FloatingPoint_end(B); +} + +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FloatingPoint_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8_end(B); +} + +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args) +{ + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Binary_end(B); +} + +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Binary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeUtf8_end(B); +} + +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeUtf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeBinary_end(B); +} + +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8View_end(B); +} + +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8View_end(B)); +} + + +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args) +{ + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_BinaryView_end(B); +} + +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BinaryView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeBinary) + +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeBinary_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args) +{ + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Bool_end(B); +} + +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Bool_end(B)); +} + + +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args) +{ + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_RunEndEncoded_end(B); +} + +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RunEndEncoded_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Decimal_precision, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Decimal_scale, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_Decimal_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(128), org_apache_arrow_flatbuf_Decimal) + +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args) +{ + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_add(B, v0) + || org_apache_arrow_flatbuf_Decimal_scale_add(B, v1) + || org_apache_arrow_flatbuf_Decimal_bitWidth_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_Decimal_end(B); +} + +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_scale_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_bitWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Decimal_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Date_unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Date) + +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args) +{ + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Date_end(B); +} + +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Date_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Time_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Time) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Time_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(32), org_apache_arrow_flatbuf_Time) + +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args) +{ + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_add(B, v1) + || org_apache_arrow_flatbuf_Time_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Time_end(B); +} + +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Time_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Time_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_timezone, org_apache_arrow_flatbuf_Timestamp) + +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args) +{ + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_add(B, v1) + || org_apache_arrow_flatbuf_Timestamp_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Timestamp_end(B); +} + +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_pick(B, t) + || org_apache_arrow_flatbuf_Timestamp_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Timestamp_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Interval_unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Interval) + +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args) +{ + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Interval_end(B); +} + +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Interval_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Duration_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Duration) + +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args) +{ + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Duration_end(B); +} + +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Duration_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_key, org_apache_arrow_flatbuf_KeyValue) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_value, org_apache_arrow_flatbuf_KeyValue) + +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args) +{ + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_add(B, v0) + || org_apache_arrow_flatbuf_KeyValue_value_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_KeyValue_end(B); +} + +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_pick(B, t) + || org_apache_arrow_flatbuf_KeyValue_value_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_KeyValue_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_indexType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) + +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_add(B, v3) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryEncoding_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryEncoding_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_Field_name, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Field_nullable, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_field(3, flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_field(4, flatbuffers_, org_apache_arrow_flatbuf_Field_dictionary, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(5, flatbuffers_, org_apache_arrow_flatbuf_Field_children, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(6, flatbuffers_, org_apache_arrow_flatbuf_Field_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Field) + +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args) +{ + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_add(B, v0) + || org_apache_arrow_flatbuf_Field_type_add_value(B, v3) + || org_apache_arrow_flatbuf_Field_dictionary_add(B, v4) + || org_apache_arrow_flatbuf_Field_children_add(B, v5) + || org_apache_arrow_flatbuf_Field_custom_metadata_add(B, v6) + || org_apache_arrow_flatbuf_Field_nullable_add(B, v1) + || org_apache_arrow_flatbuf_Field_type_add_type(B, v3.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Field_end(B); +} + +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_pick(B, t) + || org_apache_arrow_flatbuf_Field_type_pick(B, t) + || org_apache_arrow_flatbuf_Field_dictionary_pick(B, t) + || org_apache_arrow_flatbuf_Field_children_pick(B, t) + || org_apache_arrow_flatbuf_Field_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Field_nullable_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Field_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Schema_endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Schema_fields, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Schema_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Schema_features, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, org_apache_arrow_flatbuf_Schema) + +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args) +{ + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_add(B, v1) + || org_apache_arrow_flatbuf_Schema_custom_metadata_add(B, v2) + || org_apache_arrow_flatbuf_Schema_features_add(B, v3) + || org_apache_arrow_flatbuf_Schema_endianness_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Schema_end(B); +} + +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_pick(B, t) + || org_apache_arrow_flatbuf_Schema_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Schema_features_pick(B, t) + || org_apache_arrow_flatbuf_Schema_endianness_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Schema_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_BUILDER_H */ +#ifndef SCHEMA_VERIFIER_H +#define SCHEMA_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_Type_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Null_verify_table); /* Null */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Int_verify_table); /* Int */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FloatingPoint_verify_table); /* FloatingPoint */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Binary_verify_table); /* Binary */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8_verify_table); /* Utf8 */ + case 6: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Bool_verify_table); /* Bool */ + case 7: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Decimal_verify_table); /* Decimal */ + case 8: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Date_verify_table); /* Date */ + case 9: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Time_verify_table); /* Time */ + case 10: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Timestamp_verify_table); /* Timestamp */ + case 11: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Interval_verify_table); /* Interval */ + case 12: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_List_verify_table); /* List */ + case 13: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Struct__verify_table); /* Struct_ */ + case 14: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Union_verify_table); /* Union */ + case 15: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); /* FixedSizeBinary */ + case 16: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeList_verify_table); /* FixedSizeList */ + case 17: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Map_verify_table); /* Map */ + case 18: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Duration_verify_table); /* Duration */ + case 19: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeBinary_verify_table); /* LargeBinary */ + case 20: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeUtf8_verify_table); /* LargeUtf8 */ + case 21: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeList_verify_table); /* LargeList */ + case 22: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RunEndEncoded_verify_table); /* RunEndEncoded */ + case 23: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_BinaryView_verify_table); /* BinaryView */ + case 24: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8View_verify_table); /* Utf8View */ + case 25: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_ListView_verify_table); /* ListView */ + case 26: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeListView_verify_table); /* LargeListView */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* listSize */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* keysSorted */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* mode */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 4, 4, INT64_C(1073741823)) /* typeIds */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* bitWidth */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* is_signed */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* precision */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* byteWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* precision */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* scale */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* timezone */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* value */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Int_verify_table) /* indexType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isOrdered */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 2, 2) /* dictionaryKind */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* name */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* nullable */)) return ret; + if ((ret = flatcc_verify_union_field(td, 3, 0, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_field(td, 4, 0, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table) /* dictionary */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 5, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* children */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 6, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* endianness */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 1, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* fields */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* features */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_VERIFIER_H */ +#ifndef FILE_READER_H +#define FILE_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Block org_apache_arrow_flatbuf_Block_t; +typedef const org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_struct_t; +typedef org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_vec_t; +typedef org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Footer_table *org_apache_arrow_flatbuf_Footer_table_t; +typedef struct org_apache_arrow_flatbuf_Footer_table *org_apache_arrow_flatbuf_Footer_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Footer_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Footer_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Footer_file_identifier +#define org_apache_arrow_flatbuf_Footer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Footer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Footer_identifier +#define org_apache_arrow_flatbuf_Footer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Footer_type_hash ((flatbuffers_thash_t)0x65df4be3) +#define org_apache_arrow_flatbuf_Footer_type_identifier "\xe3\x4b\xdf\x65" +#ifndef org_apache_arrow_flatbuf_Footer_file_extension +#define org_apache_arrow_flatbuf_Footer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Block_file_identifier +#define org_apache_arrow_flatbuf_Block_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Block_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Block_identifier +#define org_apache_arrow_flatbuf_Block_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Block_type_hash ((flatbuffers_thash_t)0xdc6d4841) +#define org_apache_arrow_flatbuf_Block_type_identifier "\x41\x48\x6d\xdc" +#ifndef org_apache_arrow_flatbuf_Block_file_extension +#define org_apache_arrow_flatbuf_Block_file_extension "bin" +#endif + + +struct org_apache_arrow_flatbuf_Block { + /** Index to the start of the RecordBlock (note this is past the Message header) */ + alignas(8) int64_t offset; + /** Length of the metadata */ + alignas(4) int32_t metaDataLength; + /** Length of the data (this is aligned so there can be a gap between this and + * the metadata). */ + alignas(8) int64_t bodyLength; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Block_t) == 24, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block__const_ptr_add(const org_apache_arrow_flatbuf_Block_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block__ptr_add(org_apache_arrow_flatbuf_Block_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Block_struct_t org_apache_arrow_flatbuf_Block_vec_at(org_apache_arrow_flatbuf_Block_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Block__size(void) { return 24; } +static inline size_t org_apache_arrow_flatbuf_Block_vec_len(org_apache_arrow_flatbuf_Block_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Block) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Block, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Block, metaDataLength, flatbuffers_int32, int32_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Block, bodyLength, flatbuffers_int64, int64_t) + + +/** ---------------------------------------------------------------------- + * Arrow File metadata + * */ +struct org_apache_arrow_flatbuf_Footer_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Footer_vec_len(org_apache_arrow_flatbuf_Footer_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Footer_table_t org_apache_arrow_flatbuf_Footer_vec_at(org_apache_arrow_flatbuf_Footer_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Footer_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Footer) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Footer, version, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, INT16_C(0)) +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_Footer, schema, org_apache_arrow_flatbuf_Schema_table_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Footer, dictionaries, org_apache_arrow_flatbuf_Block_vec_t, 0) +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Footer, recordBatches, org_apache_arrow_flatbuf_Block_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(4, org_apache_arrow_flatbuf_Footer, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* FILE_READER_H */ +#ifndef FILE_BUILDER_H +#define FILE_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FILE_READER_H +#include "File_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef SCHEMA_BUILDER_H +#include "Schema_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_Block_formal_args , int64_t v0, int32_t v1, int64_t v2 +#define __org_apache_arrow_flatbuf_Block_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_assign(org_apache_arrow_flatbuf_Block_t *p, int64_t v0, int32_t v1, int64_t v2) +{ p->offset = v0; p->metaDataLength = v1; p->bodyLength = v2; + return p; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_copy(org_apache_arrow_flatbuf_Block_t *p, const org_apache_arrow_flatbuf_Block_t *p2) +{ p->offset = p2->offset; p->metaDataLength = p2->metaDataLength; p->bodyLength = p2->bodyLength; + return p; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_assign_to_pe(org_apache_arrow_flatbuf_Block_t *p, int64_t v0, int32_t v1, int64_t v2) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int32_assign_to_pe(&p->metaDataLength, v1); flatbuffers_int64_assign_to_pe(&p->bodyLength, v2); + return p; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_copy_to_pe(org_apache_arrow_flatbuf_Block_t *p, const org_apache_arrow_flatbuf_Block_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int32_copy_to_pe(&p->metaDataLength, &p2->metaDataLength); flatbuffers_int64_copy_to_pe(&p->bodyLength, &p2->bodyLength); + return p; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_assign_from_pe(org_apache_arrow_flatbuf_Block_t *p, int64_t v0, int32_t v1, int64_t v2) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int32_assign_from_pe(&p->metaDataLength, v1); flatbuffers_int64_assign_from_pe(&p->bodyLength, v2); + return p; } +static inline org_apache_arrow_flatbuf_Block_t *org_apache_arrow_flatbuf_Block_copy_from_pe(org_apache_arrow_flatbuf_Block_t *p, const org_apache_arrow_flatbuf_Block_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int32_copy_from_pe(&p->metaDataLength, &p2->metaDataLength); flatbuffers_int64_copy_from_pe(&p->bodyLength, &p2->bodyLength); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Block, 24, 8, org_apache_arrow_flatbuf_Block_file_identifier, org_apache_arrow_flatbuf_Block_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Block, org_apache_arrow_flatbuf_Block_t) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Footer_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Footer_ref_t; +static org_apache_arrow_flatbuf_Footer_ref_t org_apache_arrow_flatbuf_Footer_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Footer_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Footer, 5) + +#define __org_apache_arrow_flatbuf_Footer_formal_args ,\ + org_apache_arrow_flatbuf_MetadataVersion_enum_t v0, org_apache_arrow_flatbuf_Schema_ref_t v1, org_apache_arrow_flatbuf_Block_vec_ref_t v2, org_apache_arrow_flatbuf_Block_vec_ref_t v3, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v4 +#define __org_apache_arrow_flatbuf_Footer_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_Footer_ref_t org_apache_arrow_flatbuf_Footer_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Footer_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Footer, org_apache_arrow_flatbuf_Footer_file_identifier, org_apache_arrow_flatbuf_Footer_type_identifier) + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Footer_version, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Footer) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_Footer_schema, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Footer) +__flatbuffers_build_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Footer_dictionaries, org_apache_arrow_flatbuf_Block, org_apache_arrow_flatbuf_Block_t, org_apache_arrow_flatbuf_Footer) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Footer_recordBatches, org_apache_arrow_flatbuf_Block, org_apache_arrow_flatbuf_Block_t, org_apache_arrow_flatbuf_Footer) +__flatbuffers_build_table_vector_field(4, flatbuffers_, org_apache_arrow_flatbuf_Footer_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Footer) + +static inline org_apache_arrow_flatbuf_Footer_ref_t org_apache_arrow_flatbuf_Footer_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Footer_formal_args) +{ + if (org_apache_arrow_flatbuf_Footer_start(B) + || org_apache_arrow_flatbuf_Footer_schema_add(B, v1) + || org_apache_arrow_flatbuf_Footer_dictionaries_add(B, v2) + || org_apache_arrow_flatbuf_Footer_recordBatches_add(B, v3) + || org_apache_arrow_flatbuf_Footer_custom_metadata_add(B, v4) + || org_apache_arrow_flatbuf_Footer_version_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Footer_end(B); +} + +static org_apache_arrow_flatbuf_Footer_ref_t org_apache_arrow_flatbuf_Footer_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Footer_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Footer_start(B) + || org_apache_arrow_flatbuf_Footer_schema_pick(B, t) + || org_apache_arrow_flatbuf_Footer_dictionaries_pick(B, t) + || org_apache_arrow_flatbuf_Footer_recordBatches_pick(B, t) + || org_apache_arrow_flatbuf_Footer_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Footer_version_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Footer_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* FILE_BUILDER_H */ +#ifndef FILE_VERIFIER_H +#define FILE_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FILE_READER_H +#include "File_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef SCHEMA_VERIFIER_H +#include "Schema_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Footer_verify_table(flatcc_table_verifier_descriptor_t *td); + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Block_identifier, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Block_identifier, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Block_type_hash, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Block_type_hash, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 24, 8); +} + +static inline int org_apache_arrow_flatbuf_Block_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 24, 8); +} + +static int org_apache_arrow_flatbuf_Footer_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* version */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Schema_verify_table) /* schema */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 2, 0, 24, 8, INT64_C(178956970)) /* dictionaries */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 24, 8, INT64_C(178956970)) /* recordBatches */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 4, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Footer_identifier, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Footer_identifier, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Footer_type_identifier, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Footer_type_identifier, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Footer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Footer_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* FILE_VERIFIER_H */ +#ifndef SCHEMA_READER_H +#define SCHEMA_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Buffer org_apache_arrow_flatbuf_Buffer_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_struct_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_vec_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_table_t; +typedef struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__table_t; +typedef struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_table_t; +typedef struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_table_t; +typedef struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_table_t; +typedef struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_table_t; +typedef struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_table_t; +typedef struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_table_t; +typedef struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_table_t; +typedef struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_table_t; +typedef struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_table_t; +typedef struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_table_t; +typedef struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_table_t; +typedef struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_table_t; +typedef struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_table_t; +typedef struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_table_t; +typedef struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_table_t; +typedef struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_table_t; +typedef struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_table_t; +typedef struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_table_t; +typedef struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_table_t; +typedef struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_table_t; +typedef struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_table_t; +typedef struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_table_t; +typedef struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Null_file_identifier +#define org_apache_arrow_flatbuf_Null_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Null_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Null_identifier +#define org_apache_arrow_flatbuf_Null_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Null_type_hash ((flatbuffers_thash_t)0x7b36a4dd) +#define org_apache_arrow_flatbuf_Null_type_identifier "\xdd\xa4\x36\x7b" +#ifndef org_apache_arrow_flatbuf_Null_file_extension +#define org_apache_arrow_flatbuf_Null_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Struct__file_identifier +#define org_apache_arrow_flatbuf_Struct__file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Struct__file_identifier */ +#ifndef org_apache_arrow_flatbuf_Struct__identifier +#define org_apache_arrow_flatbuf_Struct__identifier 0 +#endif +#define org_apache_arrow_flatbuf_Struct__type_hash ((flatbuffers_thash_t)0x6310f362) +#define org_apache_arrow_flatbuf_Struct__type_identifier "\x62\xf3\x10\x63" +#ifndef org_apache_arrow_flatbuf_Struct__file_extension +#define org_apache_arrow_flatbuf_Struct__file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_List_file_identifier +#define org_apache_arrow_flatbuf_List_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_List_file_identifier */ +#ifndef org_apache_arrow_flatbuf_List_identifier +#define org_apache_arrow_flatbuf_List_identifier 0 +#endif +#define org_apache_arrow_flatbuf_List_type_hash ((flatbuffers_thash_t)0xd4ce5878) +#define org_apache_arrow_flatbuf_List_type_identifier "\x78\x58\xce\xd4" +#ifndef org_apache_arrow_flatbuf_List_file_extension +#define org_apache_arrow_flatbuf_List_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeList_file_identifier +#define org_apache_arrow_flatbuf_LargeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeList_identifier +#define org_apache_arrow_flatbuf_LargeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeList_type_hash ((flatbuffers_thash_t)0x38aa7e27) +#define org_apache_arrow_flatbuf_LargeList_type_identifier "\x27\x7e\xaa\x38" +#ifndef org_apache_arrow_flatbuf_LargeList_file_extension +#define org_apache_arrow_flatbuf_LargeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_ListView_file_identifier +#define org_apache_arrow_flatbuf_ListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_ListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_ListView_identifier +#define org_apache_arrow_flatbuf_ListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_ListView_type_hash ((flatbuffers_thash_t)0x23d37919) +#define org_apache_arrow_flatbuf_ListView_type_identifier "\x19\x79\xd3\x23" +#ifndef org_apache_arrow_flatbuf_ListView_file_extension +#define org_apache_arrow_flatbuf_ListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeListView_file_identifier +#define org_apache_arrow_flatbuf_LargeListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeListView_identifier +#define org_apache_arrow_flatbuf_LargeListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeListView_type_hash ((flatbuffers_thash_t)0x28efac02) +#define org_apache_arrow_flatbuf_LargeListView_type_identifier "\x02\xac\xef\x28" +#ifndef org_apache_arrow_flatbuf_LargeListView_file_extension +#define org_apache_arrow_flatbuf_LargeListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeList_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeList_type_hash ((flatbuffers_thash_t)0xcef245bb) +#define org_apache_arrow_flatbuf_FixedSizeList_type_identifier "\xbb\x45\xf2\xce" +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_extension +#define org_apache_arrow_flatbuf_FixedSizeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Map_file_identifier +#define org_apache_arrow_flatbuf_Map_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Map_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Map_identifier +#define org_apache_arrow_flatbuf_Map_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Map_type_hash ((flatbuffers_thash_t)0xcebef8e6) +#define org_apache_arrow_flatbuf_Map_type_identifier "\xe6\xf8\xbe\xce" +#ifndef org_apache_arrow_flatbuf_Map_file_extension +#define org_apache_arrow_flatbuf_Map_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Union_file_identifier +#define org_apache_arrow_flatbuf_Union_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Union_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Union_identifier +#define org_apache_arrow_flatbuf_Union_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Union_type_hash ((flatbuffers_thash_t)0x896bda57) +#define org_apache_arrow_flatbuf_Union_type_identifier "\x57\xda\x6b\x89" +#ifndef org_apache_arrow_flatbuf_Union_file_extension +#define org_apache_arrow_flatbuf_Union_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Int_file_identifier +#define org_apache_arrow_flatbuf_Int_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Int_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Int_identifier +#define org_apache_arrow_flatbuf_Int_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Int_type_hash ((flatbuffers_thash_t)0x30789001) +#define org_apache_arrow_flatbuf_Int_type_identifier "\x01\x90\x78\x30" +#ifndef org_apache_arrow_flatbuf_Int_file_extension +#define org_apache_arrow_flatbuf_Int_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FloatingPoint_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FloatingPoint_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FloatingPoint_type_hash ((flatbuffers_thash_t)0xf7d06268) +#define org_apache_arrow_flatbuf_FloatingPoint_type_identifier "\x68\x62\xd0\xf7" +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_extension +#define org_apache_arrow_flatbuf_FloatingPoint_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8_file_identifier +#define org_apache_arrow_flatbuf_Utf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8_identifier +#define org_apache_arrow_flatbuf_Utf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8_type_hash ((flatbuffers_thash_t)0x8fe60d37) +#define org_apache_arrow_flatbuf_Utf8_type_identifier "\x37\x0d\xe6\x8f" +#ifndef org_apache_arrow_flatbuf_Utf8_file_extension +#define org_apache_arrow_flatbuf_Utf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Binary_file_identifier +#define org_apache_arrow_flatbuf_Binary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Binary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Binary_identifier +#define org_apache_arrow_flatbuf_Binary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Binary_type_hash ((flatbuffers_thash_t)0x8e21a795) +#define org_apache_arrow_flatbuf_Binary_type_identifier "\x95\xa7\x21\x8e" +#ifndef org_apache_arrow_flatbuf_Binary_file_extension +#define org_apache_arrow_flatbuf_Binary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeUtf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeUtf8_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeUtf8_type_hash ((flatbuffers_thash_t)0x24ed2fb0) +#define org_apache_arrow_flatbuf_LargeUtf8_type_identifier "\xb0\x2f\xed\x24" +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_extension +#define org_apache_arrow_flatbuf_LargeUtf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_identifier +#define org_apache_arrow_flatbuf_LargeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeBinary_identifier +#define org_apache_arrow_flatbuf_LargeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeBinary_type_hash ((flatbuffers_thash_t)0xbd437872) +#define org_apache_arrow_flatbuf_LargeBinary_type_identifier "\x72\x78\x43\xbd" +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_extension +#define org_apache_arrow_flatbuf_LargeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8View_file_identifier +#define org_apache_arrow_flatbuf_Utf8View_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8View_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8View_identifier +#define org_apache_arrow_flatbuf_Utf8View_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8View_type_hash ((flatbuffers_thash_t)0xab7692) +#define org_apache_arrow_flatbuf_Utf8View_type_identifier "\x92\x76\xab\x00" +#ifndef org_apache_arrow_flatbuf_Utf8View_file_extension +#define org_apache_arrow_flatbuf_Utf8View_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BinaryView_file_identifier +#define org_apache_arrow_flatbuf_BinaryView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BinaryView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BinaryView_identifier +#define org_apache_arrow_flatbuf_BinaryView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BinaryView_type_hash ((flatbuffers_thash_t)0x18c52428) +#define org_apache_arrow_flatbuf_BinaryView_type_identifier "\x28\x24\xc5\x18" +#ifndef org_apache_arrow_flatbuf_BinaryView_file_extension +#define org_apache_arrow_flatbuf_BinaryView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_hash ((flatbuffers_thash_t)0x80d0f4ce) +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier "\xce\xf4\xd0\x80" +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_extension +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Bool_file_identifier +#define org_apache_arrow_flatbuf_Bool_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Bool_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Bool_identifier +#define org_apache_arrow_flatbuf_Bool_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Bool_type_hash ((flatbuffers_thash_t)0x96bf83f0) +#define org_apache_arrow_flatbuf_Bool_type_identifier "\xf0\x83\xbf\x96" +#ifndef org_apache_arrow_flatbuf_Bool_file_extension +#define org_apache_arrow_flatbuf_Bool_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RunEndEncoded_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RunEndEncoded_type_hash ((flatbuffers_thash_t)0x5a98bcc) +#define org_apache_arrow_flatbuf_RunEndEncoded_type_identifier "\xcc\x8b\xa9\x05" +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_extension +#define org_apache_arrow_flatbuf_RunEndEncoded_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Decimal_file_identifier +#define org_apache_arrow_flatbuf_Decimal_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Decimal_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Decimal_identifier +#define org_apache_arrow_flatbuf_Decimal_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Decimal_type_hash ((flatbuffers_thash_t)0x91d1beb7) +#define org_apache_arrow_flatbuf_Decimal_type_identifier "\xb7\xbe\xd1\x91" +#ifndef org_apache_arrow_flatbuf_Decimal_file_extension +#define org_apache_arrow_flatbuf_Decimal_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Date_file_identifier +#define org_apache_arrow_flatbuf_Date_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Date_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Date_identifier +#define org_apache_arrow_flatbuf_Date_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Date_type_hash ((flatbuffers_thash_t)0xe0ccf624) +#define org_apache_arrow_flatbuf_Date_type_identifier "\x24\xf6\xcc\xe0" +#ifndef org_apache_arrow_flatbuf_Date_file_extension +#define org_apache_arrow_flatbuf_Date_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Time_file_identifier +#define org_apache_arrow_flatbuf_Time_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Time_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Time_identifier +#define org_apache_arrow_flatbuf_Time_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Time_type_hash ((flatbuffers_thash_t)0x2442a489) +#define org_apache_arrow_flatbuf_Time_type_identifier "\x89\xa4\x42\x24" +#ifndef org_apache_arrow_flatbuf_Time_file_extension +#define org_apache_arrow_flatbuf_Time_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Timestamp_file_identifier +#define org_apache_arrow_flatbuf_Timestamp_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Timestamp_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Timestamp_identifier +#define org_apache_arrow_flatbuf_Timestamp_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Timestamp_type_hash ((flatbuffers_thash_t)0x1fddf080) +#define org_apache_arrow_flatbuf_Timestamp_type_identifier "\x80\xf0\xdd\x1f" +#ifndef org_apache_arrow_flatbuf_Timestamp_file_extension +#define org_apache_arrow_flatbuf_Timestamp_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Interval_file_identifier +#define org_apache_arrow_flatbuf_Interval_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Interval_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Interval_identifier +#define org_apache_arrow_flatbuf_Interval_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Interval_type_hash ((flatbuffers_thash_t)0x1e2d6809) +#define org_apache_arrow_flatbuf_Interval_type_identifier "\x09\x68\x2d\x1e" +#ifndef org_apache_arrow_flatbuf_Interval_file_extension +#define org_apache_arrow_flatbuf_Interval_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Duration_file_identifier +#define org_apache_arrow_flatbuf_Duration_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Duration_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Duration_identifier +#define org_apache_arrow_flatbuf_Duration_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Duration_type_hash ((flatbuffers_thash_t)0x1ecea6b0) +#define org_apache_arrow_flatbuf_Duration_type_identifier "\xb0\xa6\xce\x1e" +#ifndef org_apache_arrow_flatbuf_Duration_file_extension +#define org_apache_arrow_flatbuf_Duration_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_KeyValue_file_identifier +#define org_apache_arrow_flatbuf_KeyValue_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_KeyValue_file_identifier */ +#ifndef org_apache_arrow_flatbuf_KeyValue_identifier +#define org_apache_arrow_flatbuf_KeyValue_identifier 0 +#endif +#define org_apache_arrow_flatbuf_KeyValue_type_hash ((flatbuffers_thash_t)0x3b264744) +#define org_apache_arrow_flatbuf_KeyValue_type_identifier "\x44\x47\x26\x3b" +#ifndef org_apache_arrow_flatbuf_KeyValue_file_extension +#define org_apache_arrow_flatbuf_KeyValue_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_hash ((flatbuffers_thash_t)0x8c703261) +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier "\x61\x32\x70\x8c" +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_extension +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Field_file_identifier +#define org_apache_arrow_flatbuf_Field_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Field_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Field_identifier +#define org_apache_arrow_flatbuf_Field_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Field_type_hash ((flatbuffers_thash_t)0xd981525c) +#define org_apache_arrow_flatbuf_Field_type_identifier "\x5c\x52\x81\xd9" +#ifndef org_apache_arrow_flatbuf_Field_file_extension +#define org_apache_arrow_flatbuf_Field_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Buffer_file_identifier +#define org_apache_arrow_flatbuf_Buffer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Buffer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Buffer_identifier +#define org_apache_arrow_flatbuf_Buffer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Buffer_type_hash ((flatbuffers_thash_t)0x519d7fea) +#define org_apache_arrow_flatbuf_Buffer_type_identifier "\xea\x7f\x9d\x51" +#ifndef org_apache_arrow_flatbuf_Buffer_file_extension +#define org_apache_arrow_flatbuf_Buffer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Schema_file_identifier +#define org_apache_arrow_flatbuf_Schema_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Schema_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Schema_identifier +#define org_apache_arrow_flatbuf_Schema_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Schema_type_hash ((flatbuffers_thash_t)0x406570b) +#define org_apache_arrow_flatbuf_Schema_type_identifier "\x0b\x57\x06\x04" +#ifndef org_apache_arrow_flatbuf_Schema_file_extension +#define org_apache_arrow_flatbuf_Schema_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_MetadataVersion_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 16) +/** 0.1.0 (October 2016). */ +#define org_apache_arrow_flatbuf_MetadataVersion_V1 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_MetadataVersion_V2 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_MetadataVersion_V3 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_MetadataVersion_V4 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(3)) +#define org_apache_arrow_flatbuf_MetadataVersion_V5 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(4)) + +static inline const char *org_apache_arrow_flatbuf_MetadataVersion_name(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return "V1"; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return "V2"; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return "V3"; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return "V4"; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return "V5"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MetadataVersion_is_known_value(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return 1; + default: return 0; + } +} + +/** Represents Arrow Features that might not have full support + * within implementations. This is intended to be used in + * two scenarios: + * 1. A mechanism for readers of Arrow Streams + * and files to understand that the stream or file makes + * use of a feature that isn't supported or unknown to + * the implementation (and therefore can meet the Arrow + * forward compatibility guarantees). + * 2. A means of negotiating between a client and server + * what features a stream is allowed to use. The enums + * values here are intented to represent higher level + * features, additional details maybe negotiated + * with key-value pairs specific to the protocol. + * + * Enums added to this list should be assigned power-of-two values + * to facilitate exchanging and comparing bitmaps for supported + * features. */ +typedef int64_t org_apache_arrow_flatbuf_Feature_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, 64) +/** Needed to make flatbuffers happy. */ +#define org_apache_arrow_flatbuf_Feature_UNUSED ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(0)) +#define org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(1)) +#define org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Feature_name(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return "UNUSED"; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return "DICTIONARY_REPLACEMENT"; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return "COMPRESSED_BODY"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Feature_is_known_value(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return 1; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return 1; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_UnionMode_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 16) +#define org_apache_arrow_flatbuf_UnionMode_Sparse ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_UnionMode_Dense ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_UnionMode_name(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return "Sparse"; + case org_apache_arrow_flatbuf_UnionMode_Dense: return "Dense"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_UnionMode_is_known_value(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return 1; + case org_apache_arrow_flatbuf_UnionMode_Dense: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_Precision_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 16) +#define org_apache_arrow_flatbuf_Precision_HALF ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Precision_SINGLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_Precision_DOUBLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Precision_name(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return "HALF"; + case org_apache_arrow_flatbuf_Precision_SINGLE: return "SINGLE"; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return "DOUBLE"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Precision_is_known_value(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return 1; + case org_apache_arrow_flatbuf_Precision_SINGLE: return 1; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_DateUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_DateUnit_DAY ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_DateUnit_MILLISECOND ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_DateUnit_name(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return "DAY"; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return "MILLISECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DateUnit_is_known_value(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return 1; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_TimeUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_TimeUnit_SECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_TimeUnit_MILLISECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_TimeUnit_MICROSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_TimeUnit_NANOSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(3)) + +static inline const char *org_apache_arrow_flatbuf_TimeUnit_name(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return "SECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return "MILLISECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return "MICROSECOND"; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return "NANOSECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_TimeUnit_is_known_value(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_IntervalUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_IntervalUnit_name(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return "YEAR_MONTH"; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return "DAY_TIME"; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return "MONTH_DAY_NANO"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_IntervalUnit_is_known_value(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Dictionary encoding metadata + * Maintained for forwards compatibility, in the future + * Dictionaries might be explicit maps between integers and values + * allowing for non-contiguous index values */ +typedef int16_t org_apache_arrow_flatbuf_DictionaryKind_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 16) +#define org_apache_arrow_flatbuf_DictionaryKind_DenseArray ((org_apache_arrow_flatbuf_DictionaryKind_enum_t)INT16_C(0)) + +static inline const char *org_apache_arrow_flatbuf_DictionaryKind_name(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return "DenseArray"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DictionaryKind_is_known_value(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Endianness of the platform producing the data */ +typedef int16_t org_apache_arrow_flatbuf_Endianness_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 16) +#define org_apache_arrow_flatbuf_Endianness_Little ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Endianness_Big ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_Endianness_name(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return "Little"; + case org_apache_arrow_flatbuf_Endianness_Big: return "Big"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Endianness_is_known_value(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return 1; + case org_apache_arrow_flatbuf_Endianness_Big: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * A Buffer represents a single contiguous memory segment */ +struct org_apache_arrow_flatbuf_Buffer { + /** The relative offset into the shared memory page where the bytes for this + * buffer starts */ + alignas(8) int64_t offset; + /** The absolute length (in bytes) of the memory buffer. The memory is found + * from offset (inclusive) to offset + length (non-inclusive). When building + * messages using the encapsulated IPC message, padding bytes may be written + * after a buffer, but such padding bytes do not need to be accounted for in + * the size here. */ + alignas(8) int64_t length; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Buffer_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__const_ptr_add(const org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__ptr_add(org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_struct_t org_apache_arrow_flatbuf_Buffer_vec_at(org_apache_arrow_flatbuf_Buffer_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Buffer__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_Buffer_vec_len(org_apache_arrow_flatbuf_Buffer_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Buffer) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, length, flatbuffers_int64, int64_t) + + +/** These are stored in the flatbuffer in the Type union below */ +struct org_apache_arrow_flatbuf_Null_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Null_vec_len(org_apache_arrow_flatbuf_Null_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Null_table_t org_apache_arrow_flatbuf_Null_vec_at(org_apache_arrow_flatbuf_Null_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Null_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Null) + + +/** A Struct_ in the flatbuffer metadata is the same as an Arrow Struct + * (according to the physical memory layout). We used Struct_ here as + * Struct is a reserved word in Flatbuffers */ +struct org_apache_arrow_flatbuf_Struct__table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Struct__vec_len(org_apache_arrow_flatbuf_Struct__vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Struct__table_t org_apache_arrow_flatbuf_Struct__vec_at(org_apache_arrow_flatbuf_Struct__vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Struct__table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Struct_) + + +struct org_apache_arrow_flatbuf_List_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_List_vec_len(org_apache_arrow_flatbuf_List_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_List_table_t org_apache_arrow_flatbuf_List_vec_at(org_apache_arrow_flatbuf_List_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_List_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_List) + + +/** Same as List, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeList_vec_len(org_apache_arrow_flatbuf_LargeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeList_table_t org_apache_arrow_flatbuf_LargeList_vec_at(org_apache_arrow_flatbuf_LargeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeList) + + +/** Represents the same logical types that List can, but contains offsets and + * sizes allowing for writes in any order and sharing of child values among + * list values. */ +struct org_apache_arrow_flatbuf_ListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_ListView_vec_len(org_apache_arrow_flatbuf_ListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_ListView_table_t org_apache_arrow_flatbuf_ListView_vec_at(org_apache_arrow_flatbuf_ListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_ListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_ListView) + + +/** Same as ListView, but with 64-bit offsets and sizes, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeListView_vec_len(org_apache_arrow_flatbuf_LargeListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeListView_table_t org_apache_arrow_flatbuf_LargeListView_vec_at(org_apache_arrow_flatbuf_LargeListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeListView) + + +struct org_apache_arrow_flatbuf_FixedSizeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeList_vec_len(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeList_table_t org_apache_arrow_flatbuf_FixedSizeList_vec_at(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeList) + +/** Number of list items per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeList, listSize, flatbuffers_int32, int32_t, INT32_C(0)) + +/** A Map is a logical nested type that is represented as + * + * List> + * + * In this layout, the keys and values are each respectively contiguous. We do + * not constrain the key and value types, so the application is responsible + * for ensuring that the keys are hashable and unique. Whether the keys are sorted + * may be set in the metadata for this field. + * + * In a field with Map type, the field has a child Struct field, which then + * has two children: key type and the second the value type. The names of the + * child fields may be respectively "entries", "key", and "value", but this is + * not enforced. + * + * Map + * ```text + * - child[0] entries: Struct + * - child[0] key: K + * - child[1] value: V + * ``` + * Neither the "entries" field nor the "key" field may be nullable. + * + * The metadata is structured so that Arrow systems without special handling + * for Map can make Map an alias for List. The "layout" attribute for the Map + * field must have the same contents as a List. */ +struct org_apache_arrow_flatbuf_Map_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Map_vec_len(org_apache_arrow_flatbuf_Map_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Map_table_t org_apache_arrow_flatbuf_Map_vec_at(org_apache_arrow_flatbuf_Map_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Map_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Map) + +/** Set to true if the keys within each value are sorted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Map, keysSorted, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** A union is a complex type with children in Field + * By default ids in the type vector refer to the offsets in the children + * optionally typeIds provides an indirection between the child offset and the type id + * for each child `typeIds[offset]` is the id used in the type vector */ +struct org_apache_arrow_flatbuf_Union_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Union_vec_len(org_apache_arrow_flatbuf_Union_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Union_table_t org_apache_arrow_flatbuf_Union_vec_at(org_apache_arrow_flatbuf_Union_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Union_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Union) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Union, mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Union, typeIds, flatbuffers_int32_vec_t, 0) + +struct org_apache_arrow_flatbuf_Int_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Int_vec_len(org_apache_arrow_flatbuf_Int_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Int_table_t org_apache_arrow_flatbuf_Int_vec_at(org_apache_arrow_flatbuf_Int_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Int_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Int) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Int, bitWidth, flatbuffers_int32, int32_t, INT32_C(0)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Int, is_signed, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +struct org_apache_arrow_flatbuf_FloatingPoint_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FloatingPoint_vec_len(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FloatingPoint_table_t org_apache_arrow_flatbuf_FloatingPoint_vec_at(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FloatingPoint_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FloatingPoint) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FloatingPoint, precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, INT16_C(0)) + +/** Unicode with UTF-8 encoding */ +struct org_apache_arrow_flatbuf_Utf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8_vec_len(org_apache_arrow_flatbuf_Utf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8_table_t org_apache_arrow_flatbuf_Utf8_vec_at(org_apache_arrow_flatbuf_Utf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8) + + +/** Opaque binary data */ +struct org_apache_arrow_flatbuf_Binary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Binary_vec_len(org_apache_arrow_flatbuf_Binary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Binary_table_t org_apache_arrow_flatbuf_Binary_vec_at(org_apache_arrow_flatbuf_Binary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Binary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Binary) + + +/** Same as Utf8, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeUtf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeUtf8_vec_len(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeUtf8_table_t org_apache_arrow_flatbuf_LargeUtf8_vec_at(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeUtf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeUtf8) + + +/** Same as Binary, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeBinary_vec_len(org_apache_arrow_flatbuf_LargeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeBinary_table_t org_apache_arrow_flatbuf_LargeBinary_vec_at(org_apache_arrow_flatbuf_LargeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeBinary) + + +/** Logically the same as Utf8, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_Utf8View_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8View_vec_len(org_apache_arrow_flatbuf_Utf8View_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8View_table_t org_apache_arrow_flatbuf_Utf8View_vec_at(org_apache_arrow_flatbuf_Utf8View_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8View_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8View) + + +/** Logically the same as Binary, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_BinaryView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BinaryView_vec_len(org_apache_arrow_flatbuf_BinaryView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BinaryView_table_t org_apache_arrow_flatbuf_BinaryView_vec_at(org_apache_arrow_flatbuf_BinaryView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BinaryView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BinaryView) + + +struct org_apache_arrow_flatbuf_FixedSizeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_len(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeBinary_table_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeBinary) + +/** Number of bytes per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeBinary, byteWidth, flatbuffers_int32, int32_t, INT32_C(0)) + +struct org_apache_arrow_flatbuf_Bool_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Bool_vec_len(org_apache_arrow_flatbuf_Bool_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Bool_table_t org_apache_arrow_flatbuf_Bool_vec_at(org_apache_arrow_flatbuf_Bool_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Bool_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Bool) + + +/** Contains two child arrays, run_ends and values. + * The run_ends child array must be a 16/32/64-bit integer array + * which encodes the indices at which the run with the value in + * each corresponding index in the values child array ends. + * Like list/struct types, the value array can be of any type. */ +struct org_apache_arrow_flatbuf_RunEndEncoded_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RunEndEncoded_vec_len(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RunEndEncoded_table_t org_apache_arrow_flatbuf_RunEndEncoded_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RunEndEncoded) + + +/** Exact decimal value represented as an integer value in two's + * complement. Currently only 128-bit (16-byte) and 256-bit (32-byte) integers + * are used. The representation uses the endianness indicated + * in the Schema. */ +struct org_apache_arrow_flatbuf_Decimal_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Decimal_vec_len(org_apache_arrow_flatbuf_Decimal_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Decimal_table_t org_apache_arrow_flatbuf_Decimal_vec_at(org_apache_arrow_flatbuf_Decimal_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Decimal_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Decimal) + +/** Total number of decimal digits */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Decimal, precision, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of digits after the decimal point "." */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Decimal, scale, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of bits per value. The only accepted widths are 128 and 256. + * We use bitWidth for consistency with Int::bitWidth. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_Decimal, bitWidth, flatbuffers_int32, int32_t, INT32_C(128)) + +/** Date is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since UNIX epoch (1970-01-01), stored in either of two units: + * + * * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no + * leap seconds), where the values are evenly divisible by 86400000 + * * Days (32 bits) since the UNIX epoch */ +struct org_apache_arrow_flatbuf_Date_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Date_vec_len(org_apache_arrow_flatbuf_Date_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Date_table_t org_apache_arrow_flatbuf_Date_vec_at(org_apache_arrow_flatbuf_Date_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Date_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Date) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Date, unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, INT16_C(1)) + +/** Time is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since midnight, stored in either of four units: seconds, + * milliseconds, microseconds or nanoseconds. + * + * The integer `bitWidth` depends on the `unit` and must be one of the following: + * * SECOND and MILLISECOND: 32 bits + * * MICROSECOND and NANOSECOND: 64 bits + * + * The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds + * (exclusive), adjusted for the time unit (for example, up to 86400000 + * exclusive for the MILLISECOND unit). + * This definition doesn't allow for leap seconds. Time values from + * measurements with leap seconds will need to be corrected when ingesting + * into Arrow (for example by replacing the value 86400 with 86399). */ +struct org_apache_arrow_flatbuf_Time_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Time_vec_len(org_apache_arrow_flatbuf_Time_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Time_table_t org_apache_arrow_flatbuf_Time_vec_at(org_apache_arrow_flatbuf_Time_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Time_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Time) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Time, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Time, bitWidth, flatbuffers_int32, int32_t, INT32_C(32)) + +/** Timestamp is a 64-bit signed integer representing an elapsed time since a + * fixed epoch, stored in either of four units: seconds, milliseconds, + * microseconds or nanoseconds, and is optionally annotated with a timezone. + * + * Timestamp values do not include any leap seconds (in other words, all + * days are considered 86400 seconds long). + * + * Timestamps with a non-empty timezone + * ------------------------------------ + * + * If a Timestamp column has a non-empty timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone + * (the Unix epoch), regardless of the Timestamp's own timezone. + * + * Therefore, timestamp values with a non-empty timezone correspond to + * physical points in time together with some additional information about + * how the data was obtained and/or how to display it (the timezone). + * + * For example, the timestamp value 0 with the timezone string "Europe/Paris" + * corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the + * application may prefer to display it as "January 1st 1970, 01h00" in + * the Europe/Paris timezone (which is the same physical point in time). + * + * One consequence is that timestamp values with a non-empty timezone + * can be compared and ordered directly, since they all share the same + * well-known point of reference (the Unix epoch). + * + * Timestamps with an unset / empty timezone + * ----------------------------------------- + * + * If a Timestamp column has no timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. + * + * Therefore, timestamp values without a timezone cannot be meaningfully + * interpreted as physical points in time, but only as calendar / clock + * indications ("wall clock time") in an unspecified timezone. + * + * For example, the timestamp value 0 with an empty timezone string + * corresponds to "January 1st 1970, 00h00" in an unknown timezone: there + * is not enough information to interpret it as a well-defined physical + * point in time. + * + * One consequence is that timestamp values without a timezone cannot + * be reliably compared or ordered, since they may have different points of + * reference. In particular, it is *not* possible to interpret an unset + * or empty timezone as the same as "UTC". + * + * Conversion between timezones + * ---------------------------- + * + * If a Timestamp column has a non-empty timezone, changing the timezone + * to a different non-empty value is a metadata-only operation: + * the timestamp values need not change as their point of reference remains + * the same (the Unix epoch). + * + * However, if a Timestamp column has no timezone value, changing it to a + * non-empty value requires to think about the desired semantics. + * One possibility is to assume that the original timestamp values are + * relative to the epoch of the timezone being set; timestamp values should + * then adjusted to the Unix epoch (for example, changing the timezone from + * empty to "Europe/Paris" would require converting the timestamp values + * from "Europe/Paris" to "UTC", which seems counter-intuitive but is + * nevertheless correct). + * + * Guidelines for encoding data from external libraries + * ---------------------------------------------------- + * + * Date & time libraries often have multiple different data types for temporal + * data. In order to ease interoperability between different implementations the + * Arrow project has some recommendations for encoding these types into a Timestamp + * column. + * + * An "instant" represents a physical point in time that has no relevant timezone + * (for example, astronomical data). To encode an instant, use a Timestamp with + * the timezone string set to "UTC", and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * A "zoned date-time" represents a physical point in time annotated with an + * informative timezone (for example, the timezone in which the data was + * recorded). To encode a zoned date-time, use a Timestamp with the timezone + * string set to the name of the timezone, and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * (There is some ambiguity between an instant and a zoned date-time with the + * UTC timezone. Both of these are stored the same in Arrow. Typically, + * this distinction does not matter. If it does, then an application should + * use custom metadata or an extension type to distinguish between the two cases.) + * + * An "offset date-time" represents a physical point in time combined with an + * explicit offset from UTC. To encode an offset date-time, use a Timestamp + * with the timezone string set to the numeric timezone offset string + * (e.g. "+03:00"), and make sure the Timestamp values are relative to + * the UTC epoch (January 1st 1970, midnight). + * + * A "naive date-time" (also called "local date-time" in some libraries) + * represents a wall clock time combined with a calendar date, but with + * no indication of how to map this information to a physical point in time. + * Naive date-times must be handled with care because of this missing + * information, and also because daylight saving time (DST) may make + * some values ambiguous or nonexistent. A naive date-time may be + * stored as a struct with Date and Time fields. However, it may also be + * encoded into a Timestamp column with an empty timezone. The timestamp + * values should be computed "as if" the timezone of the date-time values + * was UTC; for example, the naive date-time "January 1st 1970, 00h00" would + * be encoded as timestamp value 0. */ +struct org_apache_arrow_flatbuf_Timestamp_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Timestamp_vec_len(org_apache_arrow_flatbuf_Timestamp_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Timestamp_table_t org_apache_arrow_flatbuf_Timestamp_vec_at(org_apache_arrow_flatbuf_Timestamp_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Timestamp_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Timestamp) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Timestamp, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(0)) +/** The timezone is an optional string indicating the name of a timezone, + * one of: + * + * * As used in the Olson timezone database (the "tz database" or + * "tzdata"), such as "America/New_York". + * * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + * such as "+07:30". + * + * Whether a timezone string is present indicates different semantics about + * the data (see above). */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_Timestamp, timezone, 0) + +struct org_apache_arrow_flatbuf_Interval_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Interval_vec_len(org_apache_arrow_flatbuf_Interval_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Interval_table_t org_apache_arrow_flatbuf_Interval_vec_at(org_apache_arrow_flatbuf_Interval_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Interval_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Interval) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Interval, unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, INT16_C(0)) + +struct org_apache_arrow_flatbuf_Duration_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Duration_vec_len(org_apache_arrow_flatbuf_Duration_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Duration_table_t org_apache_arrow_flatbuf_Duration_vec_at(org_apache_arrow_flatbuf_Duration_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Duration_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Duration) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Duration, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +/** ---------------------------------------------------------------------- + * Top-level Type value, enabling extensible type-specific metadata. We can + * add new logical types to Type without breaking backwards compatibility */ +typedef uint8_t org_apache_arrow_flatbuf_Type_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Type_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_Type) +/** ---------------------------------------------------------------------- + * user defined key value pairs to add custom metadata to arrow + * key namespacing is the responsibility of the user */ +#define org_apache_arrow_flatbuf_Type_NONE ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_Type_Null ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_Type_Int ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_Type_FloatingPoint ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_Type_Binary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_Type_Utf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(5)) +#define org_apache_arrow_flatbuf_Type_Bool ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(6)) +#define org_apache_arrow_flatbuf_Type_Decimal ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(7)) +#define org_apache_arrow_flatbuf_Type_Date ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(8)) +#define org_apache_arrow_flatbuf_Type_Time ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(9)) +#define org_apache_arrow_flatbuf_Type_Timestamp ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(10)) +#define org_apache_arrow_flatbuf_Type_Interval ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(11)) +#define org_apache_arrow_flatbuf_Type_List ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(12)) +#define org_apache_arrow_flatbuf_Type_Struct_ ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(13)) +#define org_apache_arrow_flatbuf_Type_Union ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(14)) +#define org_apache_arrow_flatbuf_Type_FixedSizeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(15)) +#define org_apache_arrow_flatbuf_Type_FixedSizeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(16)) +#define org_apache_arrow_flatbuf_Type_Map ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(17)) +#define org_apache_arrow_flatbuf_Type_Duration ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(18)) +#define org_apache_arrow_flatbuf_Type_LargeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(19)) +#define org_apache_arrow_flatbuf_Type_LargeUtf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(20)) +#define org_apache_arrow_flatbuf_Type_LargeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(21)) +#define org_apache_arrow_flatbuf_Type_RunEndEncoded ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(22)) +#define org_apache_arrow_flatbuf_Type_BinaryView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(23)) +#define org_apache_arrow_flatbuf_Type_Utf8View ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(24)) +#define org_apache_arrow_flatbuf_Type_ListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(25)) +#define org_apache_arrow_flatbuf_Type_LargeListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(26)) + +static inline const char *org_apache_arrow_flatbuf_Type_type_name(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return "NONE"; + case org_apache_arrow_flatbuf_Type_Null: return "Null"; + case org_apache_arrow_flatbuf_Type_Int: return "Int"; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return "FloatingPoint"; + case org_apache_arrow_flatbuf_Type_Binary: return "Binary"; + case org_apache_arrow_flatbuf_Type_Utf8: return "Utf8"; + case org_apache_arrow_flatbuf_Type_Bool: return "Bool"; + case org_apache_arrow_flatbuf_Type_Decimal: return "Decimal"; + case org_apache_arrow_flatbuf_Type_Date: return "Date"; + case org_apache_arrow_flatbuf_Type_Time: return "Time"; + case org_apache_arrow_flatbuf_Type_Timestamp: return "Timestamp"; + case org_apache_arrow_flatbuf_Type_Interval: return "Interval"; + case org_apache_arrow_flatbuf_Type_List: return "List"; + case org_apache_arrow_flatbuf_Type_Struct_: return "Struct_"; + case org_apache_arrow_flatbuf_Type_Union: return "Union"; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return "FixedSizeBinary"; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return "FixedSizeList"; + case org_apache_arrow_flatbuf_Type_Map: return "Map"; + case org_apache_arrow_flatbuf_Type_Duration: return "Duration"; + case org_apache_arrow_flatbuf_Type_LargeBinary: return "LargeBinary"; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return "LargeUtf8"; + case org_apache_arrow_flatbuf_Type_LargeList: return "LargeList"; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return "RunEndEncoded"; + case org_apache_arrow_flatbuf_Type_BinaryView: return "BinaryView"; + case org_apache_arrow_flatbuf_Type_Utf8View: return "Utf8View"; + case org_apache_arrow_flatbuf_Type_ListView: return "ListView"; + case org_apache_arrow_flatbuf_Type_LargeListView: return "LargeListView"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Type_is_known_type(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return 1; + case org_apache_arrow_flatbuf_Type_Null: return 1; + case org_apache_arrow_flatbuf_Type_Int: return 1; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return 1; + case org_apache_arrow_flatbuf_Type_Binary: return 1; + case org_apache_arrow_flatbuf_Type_Utf8: return 1; + case org_apache_arrow_flatbuf_Type_Bool: return 1; + case org_apache_arrow_flatbuf_Type_Decimal: return 1; + case org_apache_arrow_flatbuf_Type_Date: return 1; + case org_apache_arrow_flatbuf_Type_Time: return 1; + case org_apache_arrow_flatbuf_Type_Timestamp: return 1; + case org_apache_arrow_flatbuf_Type_Interval: return 1; + case org_apache_arrow_flatbuf_Type_List: return 1; + case org_apache_arrow_flatbuf_Type_Struct_: return 1; + case org_apache_arrow_flatbuf_Type_Union: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return 1; + case org_apache_arrow_flatbuf_Type_Map: return 1; + case org_apache_arrow_flatbuf_Type_Duration: return 1; + case org_apache_arrow_flatbuf_Type_LargeBinary: return 1; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return 1; + case org_apache_arrow_flatbuf_Type_LargeList: return 1; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return 1; + case org_apache_arrow_flatbuf_Type_BinaryView: return 1; + case org_apache_arrow_flatbuf_Type_Utf8View: return 1; + case org_apache_arrow_flatbuf_Type_ListView: return 1; + case org_apache_arrow_flatbuf_Type_LargeListView: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_KeyValue_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_KeyValue_vec_len(org_apache_arrow_flatbuf_KeyValue_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_KeyValue_table_t org_apache_arrow_flatbuf_KeyValue_vec_at(org_apache_arrow_flatbuf_KeyValue_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_KeyValue_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_KeyValue) + +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_KeyValue, key, 0) +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_KeyValue, value, 0) + +struct org_apache_arrow_flatbuf_DictionaryEncoding_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_len(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryEncoding_table_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryEncoding) + +/** The known dictionary id in the application where this data is used. In + * the file or streaming formats, the dictionary ids are found in the + * DictionaryBatch messages */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryEncoding, id, flatbuffers_int64, int64_t, INT64_C(0)) +/** The dictionary indices are constrained to be non-negative integers. If + * this field is null, the indices must be signed int32. To maximize + * cross-language compatibility and performance, implementations are + * recommended to prefer signed integer types over unsigned integer types + * and to avoid uint64 indices unless they are required by an application. */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryEncoding, indexType, org_apache_arrow_flatbuf_Int_table_t, 0) +/** By default, dictionaries are not ordered, or the order does not have + * semantic meaning. In some statistical, applications, dictionary-encoding + * is used to represent ordered categorical data, and we provide a way to + * preserve that metadata here */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryEncoding, isOrdered, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_DictionaryEncoding, dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, INT16_C(0)) + +/** ---------------------------------------------------------------------- + * A field represents a named column in a record / row batch or child of a + * nested type. */ +struct org_apache_arrow_flatbuf_Field_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Field_vec_len(org_apache_arrow_flatbuf_Field_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Field_table_t org_apache_arrow_flatbuf_Field_vec_at(org_apache_arrow_flatbuf_Field_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Field_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Field) + +/** Name is not required, in i.e. a List */ +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_Field, name, 0) +/** Whether or not this field can contain nulls. Should be true in general. */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Field, nullable, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** This is the type of the decoded value if the field is dictionary encoded. */ +__flatbuffers_define_union_field(flatbuffers_, 3, org_apache_arrow_flatbuf_Field, type, org_apache_arrow_flatbuf_Type, 0) +/** Present only if the field is dictionary encoded. */ +__flatbuffers_define_table_field(4, org_apache_arrow_flatbuf_Field, dictionary, org_apache_arrow_flatbuf_DictionaryEncoding_table_t, 0) +/** children apply only to nested data types like Struct, List and Union. For + * primitive types children will have length 0. */ +__flatbuffers_define_vector_field(5, org_apache_arrow_flatbuf_Field, children, org_apache_arrow_flatbuf_Field_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(6, org_apache_arrow_flatbuf_Field, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + +/** ---------------------------------------------------------------------- + * A Schema describes the columns in a row batch */ +struct org_apache_arrow_flatbuf_Schema_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Schema_vec_len(org_apache_arrow_flatbuf_Schema_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Schema_table_t org_apache_arrow_flatbuf_Schema_vec_at(org_apache_arrow_flatbuf_Schema_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Schema_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Schema) + +/** endianness of the buffer + * it is Little Endian by default + * if endianness doesn't match the underlying system then the vectors need to be converted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Schema, endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Schema, fields, org_apache_arrow_flatbuf_Field_vec_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Schema, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) +/** Features used in the stream/file. */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Schema, features, org_apache_arrow_flatbuf_Feature_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_READER_H */ +#ifndef SCHEMA_BUILDER_H +#define SCHEMA_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_MetadataVersion_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0 +#define __org_apache_arrow_flatbuf_MetadataVersion_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t) +#define __org_apache_arrow_flatbuf_Feature_formal_args , org_apache_arrow_flatbuf_Feature_enum_t v0 +#define __org_apache_arrow_flatbuf_Feature_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t) +#define __org_apache_arrow_flatbuf_UnionMode_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0 +#define __org_apache_arrow_flatbuf_UnionMode_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t) +#define __org_apache_arrow_flatbuf_Precision_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_Precision_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t) +#define __org_apache_arrow_flatbuf_DateUnit_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_DateUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t) +#define __org_apache_arrow_flatbuf_TimeUnit_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_TimeUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t) +#define __org_apache_arrow_flatbuf_IntervalUnit_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_IntervalUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t) +#define __org_apache_arrow_flatbuf_DictionaryKind_formal_args , org_apache_arrow_flatbuf_DictionaryKind_enum_t v0 +#define __org_apache_arrow_flatbuf_DictionaryKind_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t) +#define __org_apache_arrow_flatbuf_Endianness_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0 +#define __org_apache_arrow_flatbuf_Endianness_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t) + +#define __org_apache_arrow_flatbuf_Buffer_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_Buffer_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ p->offset = v0; p->length = v1; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ p->offset = p2->offset; p->length = p2->length; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int64_assign_to_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_to_pe(&p->length, &p2->length); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int64_assign_from_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_from_pe(&p->length, &p2->length); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Buffer_file_identifier, org_apache_arrow_flatbuf_Buffer_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_Type_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_Type_union_vec_ref_t; +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Null_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Null_ref_t; +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Null, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Struct__required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Struct__ref_t; +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Struct_, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_List_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_List_ref_t; +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_List, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeList_ref_t; +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeList, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_ListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_ListView_ref_t; +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_ListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeListView_ref_t; +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeList_ref_t; +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Map_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Map_ref_t; +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Map, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Union_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Union_ref_t; +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Union, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Int_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Int_ref_t; +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Int, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FloatingPoint_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FloatingPoint_ref_t; +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8_ref_t; +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Binary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Binary_ref_t; +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Binary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeUtf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeUtf8_ref_t; +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeBinary_ref_t; +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8View_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8View_ref_t; +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BinaryView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BinaryView_ref_t; +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_ref_t; +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Bool_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Bool_ref_t; +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Bool, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RunEndEncoded_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RunEndEncoded_ref_t; +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Decimal_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Decimal_ref_t; +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Decimal, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Date_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Date_ref_t; +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Date, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Time_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Time_ref_t; +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Time, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Timestamp_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Timestamp_ref_t; +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Interval_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Interval_ref_t; +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Interval, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Duration_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Duration_ref_t; +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Duration, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_KeyValue_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_KeyValue_ref_t; +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryEncoding_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_ref_t; +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Field_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Field_ref_t; +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Field, 7) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Schema_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Schema_ref_t; +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Schema, 4) + +#define __org_apache_arrow_flatbuf_Null_formal_args +#define __org_apache_arrow_flatbuf_Null_call_args +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Null, org_apache_arrow_flatbuf_Null_file_identifier, org_apache_arrow_flatbuf_Null_type_identifier) + +#define __org_apache_arrow_flatbuf_Struct__formal_args +#define __org_apache_arrow_flatbuf_Struct__call_args +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Struct_, org_apache_arrow_flatbuf_Struct__file_identifier, org_apache_arrow_flatbuf_Struct__type_identifier) + +#define __org_apache_arrow_flatbuf_List_formal_args +#define __org_apache_arrow_flatbuf_List_call_args +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_List, org_apache_arrow_flatbuf_List_file_identifier, org_apache_arrow_flatbuf_List_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeList_formal_args +#define __org_apache_arrow_flatbuf_LargeList_call_args +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeList, org_apache_arrow_flatbuf_LargeList_file_identifier, org_apache_arrow_flatbuf_LargeList_type_identifier) + +#define __org_apache_arrow_flatbuf_ListView_formal_args +#define __org_apache_arrow_flatbuf_ListView_call_args +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_ListView, org_apache_arrow_flatbuf_ListView_file_identifier, org_apache_arrow_flatbuf_ListView_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeListView_formal_args +#define __org_apache_arrow_flatbuf_LargeListView_call_args +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, org_apache_arrow_flatbuf_LargeListView_file_identifier, org_apache_arrow_flatbuf_LargeListView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeList_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeList_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList_file_identifier, org_apache_arrow_flatbuf_FixedSizeList_type_identifier) + +#define __org_apache_arrow_flatbuf_Map_formal_args , flatbuffers_bool_t v0 +#define __org_apache_arrow_flatbuf_Map_call_args , v0 +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Map, org_apache_arrow_flatbuf_Map_file_identifier, org_apache_arrow_flatbuf_Map_type_identifier) + +#define __org_apache_arrow_flatbuf_Union_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0, flatbuffers_int32_vec_ref_t v1 +#define __org_apache_arrow_flatbuf_Union_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Union, org_apache_arrow_flatbuf_Union_file_identifier, org_apache_arrow_flatbuf_Union_type_identifier) + +#define __org_apache_arrow_flatbuf_Int_formal_args , int32_t v0, flatbuffers_bool_t v1 +#define __org_apache_arrow_flatbuf_Int_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_Int_file_identifier, org_apache_arrow_flatbuf_Int_type_identifier) + +#define __org_apache_arrow_flatbuf_FloatingPoint_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_FloatingPoint_call_args , v0 +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint_file_identifier, org_apache_arrow_flatbuf_FloatingPoint_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8_formal_args +#define __org_apache_arrow_flatbuf_Utf8_call_args +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8, org_apache_arrow_flatbuf_Utf8_file_identifier, org_apache_arrow_flatbuf_Utf8_type_identifier) + +#define __org_apache_arrow_flatbuf_Binary_formal_args +#define __org_apache_arrow_flatbuf_Binary_call_args +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Binary, org_apache_arrow_flatbuf_Binary_file_identifier, org_apache_arrow_flatbuf_Binary_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeUtf8_formal_args +#define __org_apache_arrow_flatbuf_LargeUtf8_call_args +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8_file_identifier, org_apache_arrow_flatbuf_LargeUtf8_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeBinary_formal_args +#define __org_apache_arrow_flatbuf_LargeBinary_call_args +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, org_apache_arrow_flatbuf_LargeBinary_file_identifier, org_apache_arrow_flatbuf_LargeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8View_formal_args +#define __org_apache_arrow_flatbuf_Utf8View_call_args +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, org_apache_arrow_flatbuf_Utf8View_file_identifier, org_apache_arrow_flatbuf_Utf8View_type_identifier) + +#define __org_apache_arrow_flatbuf_BinaryView_formal_args +#define __org_apache_arrow_flatbuf_BinaryView_call_args +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, org_apache_arrow_flatbuf_BinaryView_file_identifier, org_apache_arrow_flatbuf_BinaryView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeBinary_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Bool_formal_args +#define __org_apache_arrow_flatbuf_Bool_call_args +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Bool, org_apache_arrow_flatbuf_Bool_file_identifier, org_apache_arrow_flatbuf_Bool_type_identifier) + +#define __org_apache_arrow_flatbuf_RunEndEncoded_formal_args +#define __org_apache_arrow_flatbuf_RunEndEncoded_call_args +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded_file_identifier, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier) + +#define __org_apache_arrow_flatbuf_Decimal_formal_args , int32_t v0, int32_t v1, int32_t v2 +#define __org_apache_arrow_flatbuf_Decimal_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Decimal, org_apache_arrow_flatbuf_Decimal_file_identifier, org_apache_arrow_flatbuf_Decimal_type_identifier) + +#define __org_apache_arrow_flatbuf_Date_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Date_call_args , v0 +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Date, org_apache_arrow_flatbuf_Date_file_identifier, org_apache_arrow_flatbuf_Date_type_identifier) + +#define __org_apache_arrow_flatbuf_Time_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, int32_t v1 +#define __org_apache_arrow_flatbuf_Time_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Time, org_apache_arrow_flatbuf_Time_file_identifier, org_apache_arrow_flatbuf_Time_type_identifier) + +#define __org_apache_arrow_flatbuf_Timestamp_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_Timestamp_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, org_apache_arrow_flatbuf_Timestamp_file_identifier, org_apache_arrow_flatbuf_Timestamp_type_identifier) + +#define __org_apache_arrow_flatbuf_Interval_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Interval_call_args , v0 +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Interval, org_apache_arrow_flatbuf_Interval_file_identifier, org_apache_arrow_flatbuf_Interval_type_identifier) + +#define __org_apache_arrow_flatbuf_Duration_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Duration_call_args , v0 +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Duration, org_apache_arrow_flatbuf_Duration_file_identifier, org_apache_arrow_flatbuf_Duration_type_identifier) + +#define __org_apache_arrow_flatbuf_KeyValue_formal_args , flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_KeyValue_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_KeyValue_file_identifier, org_apache_arrow_flatbuf_KeyValue_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args , int64_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, flatbuffers_bool_t v2, org_apache_arrow_flatbuf_DictionaryKind_enum_t v3 +#define __org_apache_arrow_flatbuf_DictionaryEncoding_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier) + +#define __org_apache_arrow_flatbuf_Field_formal_args ,\ + flatbuffers_string_ref_t v0, flatbuffers_bool_t v1, org_apache_arrow_flatbuf_Type_union_ref_t v3, org_apache_arrow_flatbuf_DictionaryEncoding_ref_t v4, org_apache_arrow_flatbuf_Field_vec_ref_t v5, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v6 +#define __org_apache_arrow_flatbuf_Field_call_args ,\ + v0, v1, v3, v4, v5, v6 +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field_file_identifier, org_apache_arrow_flatbuf_Field_type_identifier) + +#define __org_apache_arrow_flatbuf_Schema_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0, org_apache_arrow_flatbuf_Field_vec_ref_t v1, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v2, org_apache_arrow_flatbuf_Feature_vec_ref_t v3 +#define __org_apache_arrow_flatbuf_Schema_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Schema_file_identifier, org_apache_arrow_flatbuf_Schema_type_identifier) + +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_NONE(void) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Null; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Int; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FloatingPoint; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Binary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Bool; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Decimal; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Date; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Time; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Timestamp; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Interval; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_List; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Struct_; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Union; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Map; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Duration; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeUtf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_RunEndEncoded; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_BinaryView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8View; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_ListView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeListView; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_Type) + +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_clone(B, (org_apache_arrow_flatbuf_Null_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_clone(B, (org_apache_arrow_flatbuf_Int_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_clone(B, (org_apache_arrow_flatbuf_FloatingPoint_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_clone(B, (org_apache_arrow_flatbuf_Binary_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_clone(B, (org_apache_arrow_flatbuf_Utf8_table_t)u.value)); + case 6: return org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_clone(B, (org_apache_arrow_flatbuf_Bool_table_t)u.value)); + case 7: return org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_clone(B, (org_apache_arrow_flatbuf_Decimal_table_t)u.value)); + case 8: return org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_clone(B, (org_apache_arrow_flatbuf_Date_table_t)u.value)); + case 9: return org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_clone(B, (org_apache_arrow_flatbuf_Time_table_t)u.value)); + case 10: return org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_clone(B, (org_apache_arrow_flatbuf_Timestamp_table_t)u.value)); + case 11: return org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_clone(B, (org_apache_arrow_flatbuf_Interval_table_t)u.value)); + case 12: return org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_clone(B, (org_apache_arrow_flatbuf_List_table_t)u.value)); + case 13: return org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__clone(B, (org_apache_arrow_flatbuf_Struct__table_t)u.value)); + case 14: return org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_clone(B, (org_apache_arrow_flatbuf_Union_table_t)u.value)); + case 15: return org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_clone(B, (org_apache_arrow_flatbuf_FixedSizeBinary_table_t)u.value)); + case 16: return org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_clone(B, (org_apache_arrow_flatbuf_FixedSizeList_table_t)u.value)); + case 17: return org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_clone(B, (org_apache_arrow_flatbuf_Map_table_t)u.value)); + case 18: return org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_clone(B, (org_apache_arrow_flatbuf_Duration_table_t)u.value)); + case 19: return org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_clone(B, (org_apache_arrow_flatbuf_LargeBinary_table_t)u.value)); + case 20: return org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_clone(B, (org_apache_arrow_flatbuf_LargeUtf8_table_t)u.value)); + case 21: return org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_clone(B, (org_apache_arrow_flatbuf_LargeList_table_t)u.value)); + case 22: return org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_clone(B, (org_apache_arrow_flatbuf_RunEndEncoded_table_t)u.value)); + case 23: return org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_clone(B, (org_apache_arrow_flatbuf_BinaryView_table_t)u.value)); + case 24: return org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_clone(B, (org_apache_arrow_flatbuf_Utf8View_table_t)u.value)); + case 25: return org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_clone(B, (org_apache_arrow_flatbuf_ListView_table_t)u.value)); + case 26: return org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_clone(B, (org_apache_arrow_flatbuf_LargeListView_table_t)u.value)); + default: return org_apache_arrow_flatbuf_Type_as_NONE(); + } +} + + +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args) +{ + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Null_end(B); +} + +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Null_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args) +{ + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Struct__end(B); +} + +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Struct__end(B)); +} + + +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args) +{ + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_List_end(B); +} + +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_List_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeList_end(B); +} + +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeList_end(B)); +} + + +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args) +{ + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_ListView_end(B); +} + +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_ListView_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeListView_end(B); +} + +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeListView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList_listSize, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeList) + +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeList_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeList_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Map_keysSorted, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Map) + +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args) +{ + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Map_end(B); +} + +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Map_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Union_mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Union) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Union_typeIds, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_Union) + +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args) +{ + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_add(B, v1) + || org_apache_arrow_flatbuf_Union_mode_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Union_end(B); +} + +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_pick(B, t) + || org_apache_arrow_flatbuf_Union_mode_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Union_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Int_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Int) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Int_is_signed, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Int) + +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args) +{ + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_add(B, v0) + || org_apache_arrow_flatbuf_Int_is_signed_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_Int_end(B); +} + +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Int_is_signed_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Int_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint_precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_FloatingPoint) + +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args) +{ + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FloatingPoint_end(B); +} + +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FloatingPoint_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8_end(B); +} + +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args) +{ + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Binary_end(B); +} + +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Binary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeUtf8_end(B); +} + +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeUtf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeBinary_end(B); +} + +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8View_end(B); +} + +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8View_end(B)); +} + + +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args) +{ + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_BinaryView_end(B); +} + +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BinaryView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeBinary) + +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeBinary_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args) +{ + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Bool_end(B); +} + +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Bool_end(B)); +} + + +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args) +{ + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_RunEndEncoded_end(B); +} + +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RunEndEncoded_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Decimal_precision, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Decimal_scale, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_Decimal_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(128), org_apache_arrow_flatbuf_Decimal) + +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args) +{ + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_add(B, v0) + || org_apache_arrow_flatbuf_Decimal_scale_add(B, v1) + || org_apache_arrow_flatbuf_Decimal_bitWidth_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_Decimal_end(B); +} + +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_scale_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_bitWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Decimal_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Date_unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Date) + +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args) +{ + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Date_end(B); +} + +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Date_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Time_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Time) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Time_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(32), org_apache_arrow_flatbuf_Time) + +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args) +{ + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_add(B, v1) + || org_apache_arrow_flatbuf_Time_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Time_end(B); +} + +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Time_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Time_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_timezone, org_apache_arrow_flatbuf_Timestamp) + +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args) +{ + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_add(B, v1) + || org_apache_arrow_flatbuf_Timestamp_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Timestamp_end(B); +} + +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_pick(B, t) + || org_apache_arrow_flatbuf_Timestamp_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Timestamp_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Interval_unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Interval) + +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args) +{ + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Interval_end(B); +} + +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Interval_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Duration_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Duration) + +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args) +{ + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Duration_end(B); +} + +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Duration_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_key, org_apache_arrow_flatbuf_KeyValue) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_value, org_apache_arrow_flatbuf_KeyValue) + +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args) +{ + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_add(B, v0) + || org_apache_arrow_flatbuf_KeyValue_value_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_KeyValue_end(B); +} + +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_pick(B, t) + || org_apache_arrow_flatbuf_KeyValue_value_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_KeyValue_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_indexType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) + +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_add(B, v3) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryEncoding_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryEncoding_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_Field_name, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Field_nullable, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_field(3, flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_field(4, flatbuffers_, org_apache_arrow_flatbuf_Field_dictionary, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(5, flatbuffers_, org_apache_arrow_flatbuf_Field_children, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(6, flatbuffers_, org_apache_arrow_flatbuf_Field_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Field) + +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args) +{ + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_add(B, v0) + || org_apache_arrow_flatbuf_Field_type_add_value(B, v3) + || org_apache_arrow_flatbuf_Field_dictionary_add(B, v4) + || org_apache_arrow_flatbuf_Field_children_add(B, v5) + || org_apache_arrow_flatbuf_Field_custom_metadata_add(B, v6) + || org_apache_arrow_flatbuf_Field_nullable_add(B, v1) + || org_apache_arrow_flatbuf_Field_type_add_type(B, v3.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Field_end(B); +} + +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_pick(B, t) + || org_apache_arrow_flatbuf_Field_type_pick(B, t) + || org_apache_arrow_flatbuf_Field_dictionary_pick(B, t) + || org_apache_arrow_flatbuf_Field_children_pick(B, t) + || org_apache_arrow_flatbuf_Field_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Field_nullable_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Field_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Schema_endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Schema_fields, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Schema_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Schema_features, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, org_apache_arrow_flatbuf_Schema) + +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args) +{ + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_add(B, v1) + || org_apache_arrow_flatbuf_Schema_custom_metadata_add(B, v2) + || org_apache_arrow_flatbuf_Schema_features_add(B, v3) + || org_apache_arrow_flatbuf_Schema_endianness_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Schema_end(B); +} + +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_pick(B, t) + || org_apache_arrow_flatbuf_Schema_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Schema_features_pick(B, t) + || org_apache_arrow_flatbuf_Schema_endianness_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Schema_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_BUILDER_H */ +#ifndef SCHEMA_VERIFIER_H +#define SCHEMA_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_Type_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Null_verify_table); /* Null */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Int_verify_table); /* Int */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FloatingPoint_verify_table); /* FloatingPoint */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Binary_verify_table); /* Binary */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8_verify_table); /* Utf8 */ + case 6: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Bool_verify_table); /* Bool */ + case 7: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Decimal_verify_table); /* Decimal */ + case 8: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Date_verify_table); /* Date */ + case 9: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Time_verify_table); /* Time */ + case 10: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Timestamp_verify_table); /* Timestamp */ + case 11: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Interval_verify_table); /* Interval */ + case 12: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_List_verify_table); /* List */ + case 13: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Struct__verify_table); /* Struct_ */ + case 14: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Union_verify_table); /* Union */ + case 15: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); /* FixedSizeBinary */ + case 16: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeList_verify_table); /* FixedSizeList */ + case 17: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Map_verify_table); /* Map */ + case 18: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Duration_verify_table); /* Duration */ + case 19: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeBinary_verify_table); /* LargeBinary */ + case 20: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeUtf8_verify_table); /* LargeUtf8 */ + case 21: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeList_verify_table); /* LargeList */ + case 22: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RunEndEncoded_verify_table); /* RunEndEncoded */ + case 23: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_BinaryView_verify_table); /* BinaryView */ + case 24: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8View_verify_table); /* Utf8View */ + case 25: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_ListView_verify_table); /* ListView */ + case 26: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeListView_verify_table); /* LargeListView */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* listSize */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* keysSorted */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* mode */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 4, 4, INT64_C(1073741823)) /* typeIds */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* bitWidth */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* is_signed */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* precision */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* byteWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* precision */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* scale */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* timezone */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* value */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Int_verify_table) /* indexType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isOrdered */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 2, 2) /* dictionaryKind */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* name */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* nullable */)) return ret; + if ((ret = flatcc_verify_union_field(td, 3, 0, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_field(td, 4, 0, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table) /* dictionary */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 5, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* children */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 6, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* endianness */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 1, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* fields */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* features */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_VERIFIER_H */ +#ifndef TENSOR_READER_H +#define TENSOR_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_table_t; +typedef struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_table_t; +typedef struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_TensorDim_file_identifier +#define org_apache_arrow_flatbuf_TensorDim_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_TensorDim_file_identifier */ +#ifndef org_apache_arrow_flatbuf_TensorDim_identifier +#define org_apache_arrow_flatbuf_TensorDim_identifier 0 +#endif +#define org_apache_arrow_flatbuf_TensorDim_type_hash ((flatbuffers_thash_t)0xbc6d7b25) +#define org_apache_arrow_flatbuf_TensorDim_type_identifier "\x25\x7b\x6d\xbc" +#ifndef org_apache_arrow_flatbuf_TensorDim_file_extension +#define org_apache_arrow_flatbuf_TensorDim_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Tensor_file_identifier +#define org_apache_arrow_flatbuf_Tensor_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Tensor_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Tensor_identifier +#define org_apache_arrow_flatbuf_Tensor_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Tensor_type_hash ((flatbuffers_thash_t)0x1764df19) +#define org_apache_arrow_flatbuf_Tensor_type_identifier "\x19\xdf\x64\x17" +#ifndef org_apache_arrow_flatbuf_Tensor_file_extension +#define org_apache_arrow_flatbuf_Tensor_file_extension "bin" +#endif + + + +/** ---------------------------------------------------------------------- + * Data structures for dense tensors + * Shape data for a single axis in a tensor */ +struct org_apache_arrow_flatbuf_TensorDim_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_TensorDim_vec_len(org_apache_arrow_flatbuf_TensorDim_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_TensorDim_table_t org_apache_arrow_flatbuf_TensorDim_vec_at(org_apache_arrow_flatbuf_TensorDim_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_TensorDim_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_TensorDim) + +/** Length of dimension */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_TensorDim, size, flatbuffers_int64, int64_t, INT64_C(0)) +/** Name of the dimension, optional */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_TensorDim, name, 0) + +struct org_apache_arrow_flatbuf_Tensor_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Tensor_vec_len(org_apache_arrow_flatbuf_Tensor_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Tensor_table_t org_apache_arrow_flatbuf_Tensor_vec_at(org_apache_arrow_flatbuf_Tensor_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Tensor_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Tensor) + +/** The type of data contained in a value cell. Currently only fixed-width + * value types are supported, no strings or nested types */ +__flatbuffers_define_union_field(flatbuffers_, 1, org_apache_arrow_flatbuf_Tensor, type, org_apache_arrow_flatbuf_Type, 1) +/** The dimensions of the tensor, optionally named */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Tensor, shape, org_apache_arrow_flatbuf_TensorDim_vec_t, 1) +/** Non-negative byte offsets to advance one value cell along each dimension + * If omitted, default to row-major order (C-like). */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Tensor, strides, flatbuffers_int64_vec_t, 0) +/** The location and size of the tensor's data */ +__flatbuffers_define_struct_field(4, org_apache_arrow_flatbuf_Tensor, data, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_READER_H */ +#ifndef TENSOR_BUILDER_H +#define TENSOR_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef SCHEMA_BUILDER_H +#include "Schema_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_TensorDim_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_TensorDim_ref_t; +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Tensor_required[] = { 1, 2, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Tensor_ref_t; +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Tensor, 5) + +#define __org_apache_arrow_flatbuf_TensorDim_formal_args , int64_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_TensorDim_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_TensorDim_file_identifier, org_apache_arrow_flatbuf_TensorDim_type_identifier) + +#define __org_apache_arrow_flatbuf_Tensor_formal_args , org_apache_arrow_flatbuf_Type_union_ref_t v1, org_apache_arrow_flatbuf_TensorDim_vec_ref_t v2, flatbuffers_int64_vec_ref_t v3, org_apache_arrow_flatbuf_Buffer_t *v4 +#define __org_apache_arrow_flatbuf_Tensor_call_args , v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Tensor, org_apache_arrow_flatbuf_Tensor_file_identifier, org_apache_arrow_flatbuf_Tensor_type_identifier) + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_size, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_TensorDim) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_name, org_apache_arrow_flatbuf_TensorDim) + +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args) +{ + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_add(B, v0) + || org_apache_arrow_flatbuf_TensorDim_name_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_TensorDim_end(B); +} + +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_pick(B, t) + || org_apache_arrow_flatbuf_TensorDim_name_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_TensorDim_end(B)); +} + +__flatbuffers_build_union_field(1, flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Tensor_shape, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Tensor_strides, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_struct_field(4, flatbuffers_, org_apache_arrow_flatbuf_Tensor_data, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Tensor) + +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args) +{ + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_add(B, v4) + || org_apache_arrow_flatbuf_Tensor_type_add_value(B, v1) + || org_apache_arrow_flatbuf_Tensor_shape_add(B, v2) + || org_apache_arrow_flatbuf_Tensor_strides_add(B, v3) + || org_apache_arrow_flatbuf_Tensor_type_add_type(B, v1.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Tensor_end(B); +} + +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_type_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_shape_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_strides_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Tensor_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_BUILDER_H */ +#ifndef TENSOR_VERIFIER_H +#define TENSOR_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef SCHEMA_VERIFIER_H +#include "Schema_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* size */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* name */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_union_field(td, 1, 1, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 1, &org_apache_arrow_flatbuf_TensorDim_verify_table) /* shape */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* strides */)) return ret; + if ((ret = flatcc_verify_field(td, 4, 16, 8) /* data */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_VERIFIER_H */ +#ifndef SPARSETENSOR_READER_H +#define SPARSETENSOR_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table *org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table *org_apache_arrow_flatbuf_SparseTensorIndexCOO_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCOO_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t; +typedef struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table *org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table *org_apache_arrow_flatbuf_SparseTensorIndexCSF_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCSF_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseTensor_table *org_apache_arrow_flatbuf_SparseTensor_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensor_table *org_apache_arrow_flatbuf_SparseTensor_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensor_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensor_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_hash ((flatbuffers_thash_t)0x3b31385a) +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier "\x5a\x38\x31\x3b" +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_extension +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_hash ((flatbuffers_thash_t)0xec57ea87) +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier "\x87\xea\x57\xec" +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_extension +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_hash ((flatbuffers_thash_t)0xf44edda9) +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier "\xa9\xdd\x4e\xf4" +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_extension +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseTensor_file_identifier +#define org_apache_arrow_flatbuf_SparseTensor_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensor_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensor_identifier +#define org_apache_arrow_flatbuf_SparseTensor_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensor_type_hash ((flatbuffers_thash_t)0xae6f7239) +#define org_apache_arrow_flatbuf_SparseTensor_type_identifier "\x39\x72\x6f\xae" +#ifndef org_apache_arrow_flatbuf_SparseTensor_file_extension +#define org_apache_arrow_flatbuf_SparseTensor_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, 16) +#define org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row ((org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column ((org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_name(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row: return "Row"; + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column: return "Column"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_is_known_value(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row: return 1; + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column: return 1; + default: return 0; + } +} + + + +/** ---------------------------------------------------------------------- + * EXPERIMENTAL: Data structures for sparse tensors + * Coordinate (COO) format of sparse tensor index. + * + * COO's index list are represented as a NxM matrix, + * where N is the number of non-zero values, + * and M is the number of dimensions of a sparse tensor. + * + * indicesBuffer stores the location and size of the data of this indices + * matrix. The value type and the stride of the indices matrix is + * specified in indicesType and indicesStrides fields. + * + * For example, let X be a 2x3x4x5 tensor, and it has the following + * 6 non-zero values: + * ```text + * X[0, 1, 2, 0] := 1 + * X[1, 1, 2, 3] := 2 + * X[0, 2, 1, 0] := 3 + * X[0, 1, 3, 0] := 4 + * X[0, 1, 2, 1] := 5 + * X[1, 2, 0, 4] := 6 + * ``` + * In COO format, the index matrix of X is the following 4x6 matrix: + * ```text + * [[0, 0, 0, 0, 1, 1], + * [1, 1, 1, 2, 1, 2], + * [2, 2, 3, 1, 2, 0], + * [0, 1, 0, 0, 3, 4]] + * ``` + * When isCanonical is true, the indices is sorted in lexicographical order + * (row-major order), and it does not have duplicated entries. Otherwise, + * the indices may not be sorted, or may have duplicated entries. */ +struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_len(org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensorIndexCOO) + +/** The type of values in indicesBuffer */ +__flatbuffers_define_table_field(0, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** Non-negative byte offsets to advance one value cell along each dimension + * If omitted, default to row-major order (C-like). */ +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesStrides, flatbuffers_int64_vec_t, 0) +/** The location and size of the indices matrix's data */ +__flatbuffers_define_struct_field(2, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) +/** This flag is true if and only if the indices matrix is sorted in + * row-major order, and does not have duplicated entries. + * This sort order is the same as of Tensorflow's SparseTensor, + * but it is inverse order of SciPy's canonical coo_matrix + * (SciPy employs column-major order for its coo_matrix). */ +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_SparseTensorIndexCOO, isCanonical, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** Compressed Sparse format, that is matrix-specific. */ +struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_len(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_at(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseMatrixIndexCSX) + +/** Which axis, row or column, is compressed */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, compressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, INT16_C(0)) +/** The type of values in indptrBuffer */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indptrType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indptrBuffer stores the location and size of indptr array that + * represents the range of the rows. + * The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. + * The length of this array is 1 + (the number of rows), and the type + * of index value is long. + * + * For example, let X be the following 6x4 matrix: + * ```text + * X := [[0, 1, 2, 0], + * [0, 0, 3, 0], + * [0, 4, 0, 5], + * [0, 0, 0, 0], + * [6, 0, 7, 8], + * [0, 9, 0, 0]]. + * ``` + * The array of non-zero values in X is: + * ```text + * values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. + * ``` + * And the indptr of X is: + * ```text + * indptr(X) = [0, 2, 3, 5, 5, 8, 10]. + * ``` */ +__flatbuffers_define_struct_field(2, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indptrBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) +/** The type of values in indicesBuffer */ +__flatbuffers_define_table_field(3, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indicesBuffer stores the location and size of the array that + * contains the column indices of the corresponding non-zero values. + * The type of index value is long. + * + * For example, the indices of the above X is: + * ```text + * indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. + * ``` + * Note that the indices are sorted in lexicographical order for each row. */ +__flatbuffers_define_struct_field(4, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indicesBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + +/** Compressed Sparse Fiber (CSF) sparse tensor index. */ +struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_len(org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensorIndexCSF) + +/** CSF is a generalization of compressed sparse row (CSR) index. + * See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) + * + * CSF index recursively compresses each dimension of a tensor into a set + * of prefix trees. Each path from a root to leaf forms one tensor + * non-zero index. CSF is implemented with two arrays of buffers and one + * arrays of integers. + * + * For example, let X be a 2x3x4x5 tensor and let it have the following + * 8 non-zero values: + * ```text + * X[0, 0, 0, 1] := 1 + * X[0, 0, 0, 2] := 2 + * X[0, 1, 0, 0] := 3 + * X[0, 1, 0, 2] := 4 + * X[0, 1, 1, 0] := 5 + * X[1, 1, 1, 0] := 6 + * X[1, 1, 1, 1] := 7 + * X[1, 1, 1, 2] := 8 + * ``` + * As a prefix tree this would be represented as: + * ```text + * 0 1 + * / \ | + * 0 1 1 + * / / \ | + * 0 0 1 1 + * /| /| | /| | + * 1 2 0 2 0 0 1 2 + * ``` + * The type of values in indptrBuffers */ +__flatbuffers_define_table_field(0, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indptrType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indptrBuffers stores the sparsity structure. + * Each two consecutive dimensions in a tensor correspond to a buffer in + * indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` + * and `indptrBuffers[dim][i + 1]` signify a range of nodes in + * `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. + * + * For example, the indptrBuffers for the above X is: + * ```text + * indptrBuffer(X) = [ + * [0, 2, 3], + * [0, 1, 3, 4], + * [0, 2, 4, 5, 8] + * ]. + * ``` */ +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indptrBuffers, org_apache_arrow_flatbuf_Buffer_vec_t, 1) +/** The type of values in indicesBuffers */ +__flatbuffers_define_table_field(2, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indicesBuffers stores values of nodes. + * Each tensor dimension corresponds to a buffer in indicesBuffers. + * For example, the indicesBuffers for the above X is: + * ```text + * indicesBuffer(X) = [ + * [0, 1], + * [0, 1, 1], + * [0, 0, 1, 1], + * [1, 2, 0, 2, 0, 0, 1, 2] + * ]. + * ``` */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indicesBuffers, org_apache_arrow_flatbuf_Buffer_vec_t, 1) +/** axisOrder stores the sequence in which dimensions were traversed to + * produce the prefix tree. + * For example, the axisOrder for the above X is: + * ```text + * axisOrder(X) = [0, 1, 2, 3]. + * ``` */ +__flatbuffers_define_vector_field(4, org_apache_arrow_flatbuf_SparseTensorIndexCSF, axisOrder, flatbuffers_int32_vec_t, 1) +typedef uint8_t org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_SparseTensorIndex, org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndex) +#define org_apache_arrow_flatbuf_SparseTensorIndex_NONE ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(3)) + +static inline const char *org_apache_arrow_flatbuf_SparseTensorIndex_type_name(org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_SparseTensorIndex_NONE: return "NONE"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO: return "SparseTensorIndexCOO"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX: return "SparseMatrixIndexCSX"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF: return "SparseTensorIndexCSF"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndex_is_known_type(org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_SparseTensorIndex_NONE: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_SparseTensor_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensor_vec_len(org_apache_arrow_flatbuf_SparseTensor_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensor_table_t org_apache_arrow_flatbuf_SparseTensor_vec_at(org_apache_arrow_flatbuf_SparseTensor_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensor_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensor) + +/** The type of data contained in a value cell. + * Currently only fixed-width value types are supported, + * no strings or nested types. */ +__flatbuffers_define_union_field(flatbuffers_, 1, org_apache_arrow_flatbuf_SparseTensor, type, org_apache_arrow_flatbuf_Type, 1) +/** The dimensions of the tensor, optionally named. */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_SparseTensor, shape, org_apache_arrow_flatbuf_TensorDim_vec_t, 1) +/** The number of non-zero values in a sparse tensor. */ +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_SparseTensor, non_zero_length, flatbuffers_int64, int64_t, INT64_C(0)) +/** Sparse tensor index */ +__flatbuffers_define_union_field(flatbuffers_, 5, org_apache_arrow_flatbuf_SparseTensor, sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, 1) +/** The location and size of the tensor's data */ +__flatbuffers_define_struct_field(6, org_apache_arrow_flatbuf_SparseTensor, data, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_READER_H */ +#ifndef SPARSETENSOR_BUILDER_H +#define SPARSETENSOR_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SPARSETENSOR_READER_H +#include "SparseTensor_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef TENSOR_BUILDER_H +#include "Tensor_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_formal_args , org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t v0 +#define __org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_union_vec_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndex_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensorIndexCOO_required[] = { 0, 2, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_required[] = { 1, 2, 3, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t; +static org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, 5) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensorIndexCSF_required[] = { 0, 1, 2, 3, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF, 5) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensor_required[] = { 1, 2, 5, 6, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensor_ref_t; +static org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensor_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor, 7) + +#define __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args , org_apache_arrow_flatbuf_Int_ref_t v0, flatbuffers_int64_vec_ref_t v1, org_apache_arrow_flatbuf_Buffer_t *v2, flatbuffers_bool_t v3 +#define __org_apache_arrow_flatbuf_SparseTensorIndexCOO_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO, org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args ,\ + org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, org_apache_arrow_flatbuf_Buffer_t *v2, org_apache_arrow_flatbuf_Int_ref_t v3, org_apache_arrow_flatbuf_Buffer_t *v4 +#define __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args ,\ + org_apache_arrow_flatbuf_Int_ref_t v0, org_apache_arrow_flatbuf_Buffer_vec_ref_t v1, org_apache_arrow_flatbuf_Int_ref_t v2, org_apache_arrow_flatbuf_Buffer_vec_ref_t v3, flatbuffers_int32_vec_ref_t v4 +#define __org_apache_arrow_flatbuf_SparseTensorIndexCSF_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF, org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseTensor_formal_args ,\ + org_apache_arrow_flatbuf_Type_union_ref_t v1, org_apache_arrow_flatbuf_TensorDim_vec_ref_t v2, int64_t v3, org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t v5, org_apache_arrow_flatbuf_Buffer_t *v6 +#define __org_apache_arrow_flatbuf_SparseTensor_call_args ,\ + v1, v2, v3, v5, v6 +static inline org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensor_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor, org_apache_arrow_flatbuf_SparseTensor_file_identifier, org_apache_arrow_flatbuf_SparseTensor_type_identifier) + +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_NONE(void) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCOO(org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseMatrixIndexCSX(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCSF(org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndex) + +static org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndex_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCOO(org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(B, (org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseMatrixIndexCSX(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(B, (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCSF(org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(B, (org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t)u.value)); + default: return org_apache_arrow_flatbuf_SparseTensorIndex_as_NONE(); + } +} + +__flatbuffers_build_table_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_struct_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_SparseTensorIndexCOO) + +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensorIndexCOO_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType_add(B, v0) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides_add(B, v1) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical_add(B, v3)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensorIndexCOO_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensorIndexCOO_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensorIndexCOO_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_struct_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_table_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_struct_field(4, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) + +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_start(B) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer_add(B, v2) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer_add(B, v4) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType_add(B, v1) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType_add(B, v3) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseMatrixIndexCSX_end(B); +} + +static org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_start(B) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_end(B)); +} + +__flatbuffers_build_table_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_table_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(4, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) + +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensorIndexCSF_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType_add(B, v0) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers_add(B, v1) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers_add(B, v3) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder_add(B, v4)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensorIndexCSF_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensorIndexCSF_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensorIndexCSF_end(B)); +} + +__flatbuffers_build_union_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_shape, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_non_zero_length, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_field(5, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseTensorIndexCOO, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseMatrixIndexCSX, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseTensorIndexCSF, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_struct_field(6, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_data, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseTensor) + +static inline org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensor_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensor_start(B) + || org_apache_arrow_flatbuf_SparseTensor_non_zero_length_add(B, v3) + || org_apache_arrow_flatbuf_SparseTensor_data_add(B, v6) + || org_apache_arrow_flatbuf_SparseTensor_type_add_value(B, v1) + || org_apache_arrow_flatbuf_SparseTensor_shape_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_add_value(B, v5) + || org_apache_arrow_flatbuf_SparseTensor_type_add_type(B, v1.type) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_add_type(B, v5.type)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensor_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensor_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensor_start(B) + || org_apache_arrow_flatbuf_SparseTensor_non_zero_length_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_data_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_type_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_shape_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensor_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_BUILDER_H */ +#ifndef SPARSETENSOR_VERIFIER_H +#define SPARSETENSOR_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SPARSETENSOR_READER_H +#include "SparseTensor_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef TENSOR_VERIFIER_H +#include "Tensor_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseTensor_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_SparseTensorIndex_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); /* SparseTensorIndexCOO */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); /* SparseMatrixIndexCSX */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); /* SparseTensorIndexCSF */ + default: return flatcc_verify_ok; + } +} + +static int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_table_field(td, 0, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 8, 8, INT64_C(536870911)) /* indicesStrides */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 16, 8) /* indicesBuffer */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 1, 1) /* isCanonical */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* compressedAxis */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indptrType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 16, 8) /* indptrBuffer */)) return ret; + if ((ret = flatcc_verify_table_field(td, 3, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_field(td, 4, 16, 8) /* indicesBuffer */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_table_field(td, 0, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indptrType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 1, 16, 8, INT64_C(268435455)) /* indptrBuffers */)) return ret; + if ((ret = flatcc_verify_table_field(td, 2, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 1, 16, 8, INT64_C(268435455)) /* indicesBuffers */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 4, 1, 4, 4, INT64_C(1073741823)) /* axisOrder */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseTensor_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_union_field(td, 1, 1, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 1, &org_apache_arrow_flatbuf_TensorDim_verify_table) /* shape */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 8, 8) /* non_zero_length */)) return ret; + if ((ret = flatcc_verify_union_field(td, 5, 1, &org_apache_arrow_flatbuf_SparseTensorIndex_union_verifier) /* sparseIndex */)) return ret; + if ((ret = flatcc_verify_field(td, 6, 16, 8) /* data */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_type_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_type_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_VERIFIER_H */ +#ifndef MESSAGE_READER_H +#define MESSAGE_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#ifndef SPARSETENSOR_READER_H +#include "SparseTensor_reader.h" +#endif +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_FieldNode org_apache_arrow_flatbuf_FieldNode_t; +typedef const org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_struct_t; +typedef org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_vec_t; +typedef org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_BodyCompression_table *org_apache_arrow_flatbuf_BodyCompression_table_t; +typedef struct org_apache_arrow_flatbuf_BodyCompression_table *org_apache_arrow_flatbuf_BodyCompression_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BodyCompression_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BodyCompression_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RecordBatch_table *org_apache_arrow_flatbuf_RecordBatch_table_t; +typedef struct org_apache_arrow_flatbuf_RecordBatch_table *org_apache_arrow_flatbuf_RecordBatch_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RecordBatch_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RecordBatch_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryBatch_table *org_apache_arrow_flatbuf_DictionaryBatch_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryBatch_table *org_apache_arrow_flatbuf_DictionaryBatch_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryBatch_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryBatch_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Message_table *org_apache_arrow_flatbuf_Message_table_t; +typedef struct org_apache_arrow_flatbuf_Message_table *org_apache_arrow_flatbuf_Message_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Message_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Message_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_FieldNode_file_identifier +#define org_apache_arrow_flatbuf_FieldNode_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FieldNode_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FieldNode_identifier +#define org_apache_arrow_flatbuf_FieldNode_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FieldNode_type_hash ((flatbuffers_thash_t)0x931857b8) +#define org_apache_arrow_flatbuf_FieldNode_type_identifier "\xb8\x57\x18\x93" +#ifndef org_apache_arrow_flatbuf_FieldNode_file_extension +#define org_apache_arrow_flatbuf_FieldNode_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BodyCompression_file_identifier +#define org_apache_arrow_flatbuf_BodyCompression_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BodyCompression_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BodyCompression_identifier +#define org_apache_arrow_flatbuf_BodyCompression_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BodyCompression_type_hash ((flatbuffers_thash_t)0xbc821116) +#define org_apache_arrow_flatbuf_BodyCompression_type_identifier "\x16\x11\x82\xbc" +#ifndef org_apache_arrow_flatbuf_BodyCompression_file_extension +#define org_apache_arrow_flatbuf_BodyCompression_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RecordBatch_file_identifier +#define org_apache_arrow_flatbuf_RecordBatch_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RecordBatch_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RecordBatch_identifier +#define org_apache_arrow_flatbuf_RecordBatch_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RecordBatch_type_hash ((flatbuffers_thash_t)0x43c558b) +#define org_apache_arrow_flatbuf_RecordBatch_type_identifier "\x8b\x55\x3c\x04" +#ifndef org_apache_arrow_flatbuf_RecordBatch_file_extension +#define org_apache_arrow_flatbuf_RecordBatch_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryBatch_file_identifier +#define org_apache_arrow_flatbuf_DictionaryBatch_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryBatch_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryBatch_identifier +#define org_apache_arrow_flatbuf_DictionaryBatch_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryBatch_type_hash ((flatbuffers_thash_t)0x5c6da7bc) +#define org_apache_arrow_flatbuf_DictionaryBatch_type_identifier "\xbc\xa7\x6d\x5c" +#ifndef org_apache_arrow_flatbuf_DictionaryBatch_file_extension +#define org_apache_arrow_flatbuf_DictionaryBatch_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Message_file_identifier +#define org_apache_arrow_flatbuf_Message_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Message_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Message_identifier +#define org_apache_arrow_flatbuf_Message_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Message_type_hash ((flatbuffers_thash_t)0xc3efd227) +#define org_apache_arrow_flatbuf_Message_type_identifier "\x27\xd2\xef\xc3" +#ifndef org_apache_arrow_flatbuf_Message_file_extension +#define org_apache_arrow_flatbuf_Message_file_extension "bin" +#endif + +typedef int8_t org_apache_arrow_flatbuf_CompressionType_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_CompressionType, org_apache_arrow_flatbuf_CompressionType_enum_t, 8) +#define org_apache_arrow_flatbuf_CompressionType_LZ4_FRAME ((org_apache_arrow_flatbuf_CompressionType_enum_t)INT8_C(0)) +#define org_apache_arrow_flatbuf_CompressionType_ZSTD ((org_apache_arrow_flatbuf_CompressionType_enum_t)INT8_C(1)) + +static inline const char *org_apache_arrow_flatbuf_CompressionType_name(org_apache_arrow_flatbuf_CompressionType_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_CompressionType_LZ4_FRAME: return "LZ4_FRAME"; + case org_apache_arrow_flatbuf_CompressionType_ZSTD: return "ZSTD"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_CompressionType_is_known_value(org_apache_arrow_flatbuf_CompressionType_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_CompressionType_LZ4_FRAME: return 1; + case org_apache_arrow_flatbuf_CompressionType_ZSTD: return 1; + default: return 0; + } +} + +/** Provided for forward compatibility in case we need to support different + * strategies for compressing the IPC message body (like whole-body + * compression rather than buffer-level) in the future */ +typedef int8_t org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_BodyCompressionMethod, org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t, 8) +/** Each constituent buffer is first compressed with the indicated + * compressor, and then written with the uncompressed length in the first 8 + * bytes as a 64-bit little-endian signed integer followed by the compressed + * buffer bytes (and then padding as required by the protocol). The + * uncompressed length may be set to -1 to indicate that the data that + * follows is not compressed, which can be useful for cases where + * compression does not yield appreciable savings. */ +#define org_apache_arrow_flatbuf_BodyCompressionMethod_BUFFER ((org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t)INT8_C(0)) + +static inline const char *org_apache_arrow_flatbuf_BodyCompressionMethod_name(org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_BodyCompressionMethod_BUFFER: return "BUFFER"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_BodyCompressionMethod_is_known_value(org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_BodyCompressionMethod_BUFFER: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * Data structures for describing a table row batch (a collection of + * equal-length Arrow arrays) + * Metadata about a field at some level of a nested type tree (but not + * its children). + * + * For example, a List with values `[[1, 2, 3], null, [4], [5, 6], null]` + * would have {length: 5, null_count: 2} for its List node, and {length: 6, + * null_count: 0} for its Int16 node, as separate FieldNode structs */ +struct org_apache_arrow_flatbuf_FieldNode { + /** The number of value slots in the Arrow array at this level of a nested + * tree */ + alignas(8) int64_t length; + /** The number of observed nulls. Fields with null_count == 0 may choose not + * to write their physical validity bitmap out as a materialized buffer, + * instead setting the length of the bitmap buffer to 0. */ + alignas(8) int64_t null_count; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_FieldNode_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode__const_ptr_add(const org_apache_arrow_flatbuf_FieldNode_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode__ptr_add(org_apache_arrow_flatbuf_FieldNode_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_FieldNode_struct_t org_apache_arrow_flatbuf_FieldNode_vec_at(org_apache_arrow_flatbuf_FieldNode_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_FieldNode__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_FieldNode_vec_len(org_apache_arrow_flatbuf_FieldNode_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_FieldNode) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_FieldNode, length, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_FieldNode, null_count, flatbuffers_int64, int64_t) + + +/** Optional compression for the memory buffers constituting IPC message + * bodies. Intended for use with RecordBatch but could be used for other + * message types */ +struct org_apache_arrow_flatbuf_BodyCompression_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BodyCompression_vec_len(org_apache_arrow_flatbuf_BodyCompression_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BodyCompression_table_t org_apache_arrow_flatbuf_BodyCompression_vec_at(org_apache_arrow_flatbuf_BodyCompression_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BodyCompression_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BodyCompression) + +/** Compressor library. + * For LZ4_FRAME, each compressed buffer must consist of a single frame. */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_BodyCompression, codec, org_apache_arrow_flatbuf_CompressionType, org_apache_arrow_flatbuf_CompressionType_enum_t, INT8_C(0)) +/** Indicates the way the record batch body was compressed */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_BodyCompression, method, org_apache_arrow_flatbuf_BodyCompressionMethod, org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t, INT8_C(0)) + +/** A data header describing the shared memory layout of a "record" or "row" + * batch. Some systems call this a "row batch" internally and others a "record + * batch". */ +struct org_apache_arrow_flatbuf_RecordBatch_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RecordBatch_vec_len(org_apache_arrow_flatbuf_RecordBatch_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RecordBatch_table_t org_apache_arrow_flatbuf_RecordBatch_vec_at(org_apache_arrow_flatbuf_RecordBatch_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RecordBatch_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RecordBatch) + +/** number of records / rows. The arrays in the batch should all have this + * length */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_RecordBatch, length, flatbuffers_int64, int64_t, INT64_C(0)) +/** Nodes correspond to the pre-ordered flattened logical schema */ +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_RecordBatch, nodes, org_apache_arrow_flatbuf_FieldNode_vec_t, 0) +/** Buffers correspond to the pre-ordered flattened buffer tree + * + * The number of buffers appended to this list depends on the schema. For + * example, most primitive arrays will have 2 buffers, 1 for the validity + * bitmap and 1 for the values. For struct arrays, there will only be a + * single buffer for the validity (nulls) bitmap */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_RecordBatch, buffers, org_apache_arrow_flatbuf_Buffer_vec_t, 0) +/** Optional compression of the message body */ +__flatbuffers_define_table_field(3, org_apache_arrow_flatbuf_RecordBatch, compression, org_apache_arrow_flatbuf_BodyCompression_table_t, 0) +/** Some types such as Utf8View are represented using a variable number of buffers. + * For each such Field in the pre-ordered flattened logical schema, there will be + * an entry in variadicBufferCounts to indicate the number of number of variadic + * buffers which belong to that Field in the current RecordBatch. + * + * For example, the schema + * col1: Struct + * col2: Utf8View + * contains two Fields with variadic buffers so variadicBufferCounts will have + * two entries, the first counting the variadic buffers of `col1.beta` and the + * second counting `col2`'s. + * + * This field may be omitted if and only if the schema contains no Fields with + * a variable number of buffers, such as BinaryView and Utf8View. */ +__flatbuffers_define_vector_field(4, org_apache_arrow_flatbuf_RecordBatch, variadicBufferCounts, flatbuffers_int64_vec_t, 0) + +/** For sending dictionary encoding information. Any Field can be + * dictionary-encoded, but in this case none of its children may be + * dictionary-encoded. + * There is one vector / column per dictionary, but that vector / column + * may be spread across multiple dictionary batches by using the isDelta + * flag */ +struct org_apache_arrow_flatbuf_DictionaryBatch_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryBatch_vec_len(org_apache_arrow_flatbuf_DictionaryBatch_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryBatch_table_t org_apache_arrow_flatbuf_DictionaryBatch_vec_at(org_apache_arrow_flatbuf_DictionaryBatch_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryBatch_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryBatch) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryBatch, id, flatbuffers_int64, int64_t, INT64_C(0)) +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryBatch, data, org_apache_arrow_flatbuf_RecordBatch_table_t, 0) +/** If isDelta is true the values in the dictionary are to be appended to a + * dictionary with the indicated id. If isDelta is false this dictionary + * should replace the existing dictionary. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryBatch, isDelta, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** ---------------------------------------------------------------------- + * The root Message type + * This union enables us to easily send different message types without + * redundant storage, and in the future we can easily add new message types. + * + * Arrow implementations do not need to implement all of the message types, + * which may include experimental metadata types. For maximum compatibility, + * it is best to send data using RecordBatch */ +typedef uint8_t org_apache_arrow_flatbuf_MessageHeader_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MessageHeader, org_apache_arrow_flatbuf_MessageHeader_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_MessageHeader) +#define org_apache_arrow_flatbuf_MessageHeader_NONE ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_MessageHeader_Schema ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_MessageHeader_DictionaryBatch ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_MessageHeader_RecordBatch ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_MessageHeader_Tensor ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_MessageHeader_SparseTensor ((org_apache_arrow_flatbuf_MessageHeader_union_type_t)UINT8_C(5)) + +static inline const char *org_apache_arrow_flatbuf_MessageHeader_type_name(org_apache_arrow_flatbuf_MessageHeader_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_MessageHeader_NONE: return "NONE"; + case org_apache_arrow_flatbuf_MessageHeader_Schema: return "Schema"; + case org_apache_arrow_flatbuf_MessageHeader_DictionaryBatch: return "DictionaryBatch"; + case org_apache_arrow_flatbuf_MessageHeader_RecordBatch: return "RecordBatch"; + case org_apache_arrow_flatbuf_MessageHeader_Tensor: return "Tensor"; + case org_apache_arrow_flatbuf_MessageHeader_SparseTensor: return "SparseTensor"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MessageHeader_is_known_type(org_apache_arrow_flatbuf_MessageHeader_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_MessageHeader_NONE: return 1; + case org_apache_arrow_flatbuf_MessageHeader_Schema: return 1; + case org_apache_arrow_flatbuf_MessageHeader_DictionaryBatch: return 1; + case org_apache_arrow_flatbuf_MessageHeader_RecordBatch: return 1; + case org_apache_arrow_flatbuf_MessageHeader_Tensor: return 1; + case org_apache_arrow_flatbuf_MessageHeader_SparseTensor: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_Message_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Message_vec_len(org_apache_arrow_flatbuf_Message_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Message_table_t org_apache_arrow_flatbuf_Message_vec_at(org_apache_arrow_flatbuf_Message_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Message_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Message) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Message, version, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, INT16_C(0)) +__flatbuffers_define_union_field(flatbuffers_, 2, org_apache_arrow_flatbuf_Message, header, org_apache_arrow_flatbuf_MessageHeader, 0) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_Message, bodyLength, flatbuffers_int64, int64_t, INT64_C(0)) +__flatbuffers_define_vector_field(4, org_apache_arrow_flatbuf_Message, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* MESSAGE_READER_H */ +#ifndef MESSAGE_BUILDER_H +#define MESSAGE_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef MESSAGE_READER_H +#include "Message_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef TENSOR_BUILDER_H +#include "Tensor_builder.h" +#endif +#ifndef SPARSETENSOR_BUILDER_H +#include "SparseTensor_builder.h" +#endif +#ifndef SCHEMA_BUILDER_H +#include "Schema_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_CompressionType_formal_args , org_apache_arrow_flatbuf_CompressionType_enum_t v0 +#define __org_apache_arrow_flatbuf_CompressionType_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_CompressionType, org_apache_arrow_flatbuf_CompressionType_enum_t) +#define __org_apache_arrow_flatbuf_BodyCompressionMethod_formal_args , org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t v0 +#define __org_apache_arrow_flatbuf_BodyCompressionMethod_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_BodyCompressionMethod, org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t) + +#define __org_apache_arrow_flatbuf_FieldNode_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_FieldNode_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_assign(org_apache_arrow_flatbuf_FieldNode_t *p, int64_t v0, int64_t v1) +{ p->length = v0; p->null_count = v1; + return p; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_copy(org_apache_arrow_flatbuf_FieldNode_t *p, const org_apache_arrow_flatbuf_FieldNode_t *p2) +{ p->length = p2->length; p->null_count = p2->null_count; + return p; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_assign_to_pe(org_apache_arrow_flatbuf_FieldNode_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->length, v0); flatbuffers_int64_assign_to_pe(&p->null_count, v1); + return p; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_copy_to_pe(org_apache_arrow_flatbuf_FieldNode_t *p, const org_apache_arrow_flatbuf_FieldNode_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->length, &p2->length); flatbuffers_int64_copy_to_pe(&p->null_count, &p2->null_count); + return p; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_assign_from_pe(org_apache_arrow_flatbuf_FieldNode_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->length, v0); flatbuffers_int64_assign_from_pe(&p->null_count, v1); + return p; } +static inline org_apache_arrow_flatbuf_FieldNode_t *org_apache_arrow_flatbuf_FieldNode_copy_from_pe(org_apache_arrow_flatbuf_FieldNode_t *p, const org_apache_arrow_flatbuf_FieldNode_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->length, &p2->length); flatbuffers_int64_copy_from_pe(&p->null_count, &p2->null_count); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_FieldNode, 16, 8, org_apache_arrow_flatbuf_FieldNode_file_identifier, org_apache_arrow_flatbuf_FieldNode_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_FieldNode, org_apache_arrow_flatbuf_FieldNode_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_MessageHeader_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_MessageHeader_union_vec_ref_t; +static org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_MessageHeader_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BodyCompression_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BodyCompression_ref_t; +static org_apache_arrow_flatbuf_BodyCompression_ref_t org_apache_arrow_flatbuf_BodyCompression_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BodyCompression_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BodyCompression, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RecordBatch_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RecordBatch_ref_t; +static org_apache_arrow_flatbuf_RecordBatch_ref_t org_apache_arrow_flatbuf_RecordBatch_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RecordBatch_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RecordBatch, 5) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryBatch_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryBatch_ref_t; +static org_apache_arrow_flatbuf_DictionaryBatch_ref_t org_apache_arrow_flatbuf_DictionaryBatch_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryBatch_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryBatch, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Message_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Message_ref_t; +static org_apache_arrow_flatbuf_Message_ref_t org_apache_arrow_flatbuf_Message_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Message_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Message, 5) + +#define __org_apache_arrow_flatbuf_BodyCompression_formal_args , org_apache_arrow_flatbuf_CompressionType_enum_t v0, org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t v1 +#define __org_apache_arrow_flatbuf_BodyCompression_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_BodyCompression_ref_t org_apache_arrow_flatbuf_BodyCompression_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BodyCompression_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BodyCompression, org_apache_arrow_flatbuf_BodyCompression_file_identifier, org_apache_arrow_flatbuf_BodyCompression_type_identifier) + +#define __org_apache_arrow_flatbuf_RecordBatch_formal_args ,\ + int64_t v0, org_apache_arrow_flatbuf_FieldNode_vec_ref_t v1, org_apache_arrow_flatbuf_Buffer_vec_ref_t v2, org_apache_arrow_flatbuf_BodyCompression_ref_t v3, flatbuffers_int64_vec_ref_t v4 +#define __org_apache_arrow_flatbuf_RecordBatch_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_RecordBatch_ref_t org_apache_arrow_flatbuf_RecordBatch_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RecordBatch_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RecordBatch, org_apache_arrow_flatbuf_RecordBatch_file_identifier, org_apache_arrow_flatbuf_RecordBatch_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryBatch_formal_args , int64_t v0, org_apache_arrow_flatbuf_RecordBatch_ref_t v1, flatbuffers_bool_t v2 +#define __org_apache_arrow_flatbuf_DictionaryBatch_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_DictionaryBatch_ref_t org_apache_arrow_flatbuf_DictionaryBatch_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryBatch_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryBatch, org_apache_arrow_flatbuf_DictionaryBatch_file_identifier, org_apache_arrow_flatbuf_DictionaryBatch_type_identifier) + +#define __org_apache_arrow_flatbuf_Message_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0, org_apache_arrow_flatbuf_MessageHeader_union_ref_t v2, int64_t v3, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v4 +#define __org_apache_arrow_flatbuf_Message_call_args , v0, v2, v3, v4 +static inline org_apache_arrow_flatbuf_Message_ref_t org_apache_arrow_flatbuf_Message_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Message_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Message, org_apache_arrow_flatbuf_Message_file_identifier, org_apache_arrow_flatbuf_Message_type_identifier) + +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_NONE(void) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_Schema(org_apache_arrow_flatbuf_Schema_ref_t ref) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_Schema; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_DictionaryBatch(org_apache_arrow_flatbuf_DictionaryBatch_ref_t ref) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_DictionaryBatch; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_RecordBatch(org_apache_arrow_flatbuf_RecordBatch_ref_t ref) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_RecordBatch; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_Tensor(org_apache_arrow_flatbuf_Tensor_ref_t ref) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_Tensor; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_as_SparseTensor(org_apache_arrow_flatbuf_SparseTensor_ref_t ref) +{ org_apache_arrow_flatbuf_MessageHeader_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_MessageHeader_SparseTensor; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_MessageHeader) + +static org_apache_arrow_flatbuf_MessageHeader_union_ref_t org_apache_arrow_flatbuf_MessageHeader_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_MessageHeader_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_MessageHeader_as_Schema(org_apache_arrow_flatbuf_Schema_clone(B, (org_apache_arrow_flatbuf_Schema_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_MessageHeader_as_DictionaryBatch(org_apache_arrow_flatbuf_DictionaryBatch_clone(B, (org_apache_arrow_flatbuf_DictionaryBatch_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_MessageHeader_as_RecordBatch(org_apache_arrow_flatbuf_RecordBatch_clone(B, (org_apache_arrow_flatbuf_RecordBatch_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_MessageHeader_as_Tensor(org_apache_arrow_flatbuf_Tensor_clone(B, (org_apache_arrow_flatbuf_Tensor_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_MessageHeader_as_SparseTensor(org_apache_arrow_flatbuf_SparseTensor_clone(B, (org_apache_arrow_flatbuf_SparseTensor_table_t)u.value)); + default: return org_apache_arrow_flatbuf_MessageHeader_as_NONE(); + } +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_BodyCompression_codec, org_apache_arrow_flatbuf_CompressionType, org_apache_arrow_flatbuf_CompressionType_enum_t, 1, 1, INT8_C(0), org_apache_arrow_flatbuf_BodyCompression) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_BodyCompression_method, org_apache_arrow_flatbuf_BodyCompressionMethod, org_apache_arrow_flatbuf_BodyCompressionMethod_enum_t, 1, 1, INT8_C(0), org_apache_arrow_flatbuf_BodyCompression) + +static inline org_apache_arrow_flatbuf_BodyCompression_ref_t org_apache_arrow_flatbuf_BodyCompression_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BodyCompression_formal_args) +{ + if (org_apache_arrow_flatbuf_BodyCompression_start(B) + || org_apache_arrow_flatbuf_BodyCompression_codec_add(B, v0) + || org_apache_arrow_flatbuf_BodyCompression_method_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_BodyCompression_end(B); +} + +static org_apache_arrow_flatbuf_BodyCompression_ref_t org_apache_arrow_flatbuf_BodyCompression_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BodyCompression_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BodyCompression_start(B) + || org_apache_arrow_flatbuf_BodyCompression_codec_pick(B, t) + || org_apache_arrow_flatbuf_BodyCompression_method_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BodyCompression_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_RecordBatch_length, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_RecordBatch) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_RecordBatch_nodes, org_apache_arrow_flatbuf_FieldNode, org_apache_arrow_flatbuf_FieldNode_t, org_apache_arrow_flatbuf_RecordBatch) +__flatbuffers_build_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_RecordBatch_buffers, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t, org_apache_arrow_flatbuf_RecordBatch) +__flatbuffers_build_table_field(3, flatbuffers_, org_apache_arrow_flatbuf_RecordBatch_compression, org_apache_arrow_flatbuf_BodyCompression, org_apache_arrow_flatbuf_RecordBatch) +__flatbuffers_build_vector_field(4, flatbuffers_, org_apache_arrow_flatbuf_RecordBatch_variadicBufferCounts, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_RecordBatch) + +static inline org_apache_arrow_flatbuf_RecordBatch_ref_t org_apache_arrow_flatbuf_RecordBatch_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RecordBatch_formal_args) +{ + if (org_apache_arrow_flatbuf_RecordBatch_start(B) + || org_apache_arrow_flatbuf_RecordBatch_length_add(B, v0) + || org_apache_arrow_flatbuf_RecordBatch_nodes_add(B, v1) + || org_apache_arrow_flatbuf_RecordBatch_buffers_add(B, v2) + || org_apache_arrow_flatbuf_RecordBatch_compression_add(B, v3) + || org_apache_arrow_flatbuf_RecordBatch_variadicBufferCounts_add(B, v4)) { + return 0; + } + return org_apache_arrow_flatbuf_RecordBatch_end(B); +} + +static org_apache_arrow_flatbuf_RecordBatch_ref_t org_apache_arrow_flatbuf_RecordBatch_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RecordBatch_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RecordBatch_start(B) + || org_apache_arrow_flatbuf_RecordBatch_length_pick(B, t) + || org_apache_arrow_flatbuf_RecordBatch_nodes_pick(B, t) + || org_apache_arrow_flatbuf_RecordBatch_buffers_pick(B, t) + || org_apache_arrow_flatbuf_RecordBatch_compression_pick(B, t) + || org_apache_arrow_flatbuf_RecordBatch_variadicBufferCounts_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RecordBatch_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryBatch_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryBatch) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryBatch_data, org_apache_arrow_flatbuf_RecordBatch, org_apache_arrow_flatbuf_DictionaryBatch) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryBatch_isDelta, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryBatch) + +static inline org_apache_arrow_flatbuf_DictionaryBatch_ref_t org_apache_arrow_flatbuf_DictionaryBatch_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryBatch_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryBatch_start(B) + || org_apache_arrow_flatbuf_DictionaryBatch_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryBatch_data_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryBatch_isDelta_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryBatch_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryBatch_ref_t org_apache_arrow_flatbuf_DictionaryBatch_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryBatch_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryBatch_start(B) + || org_apache_arrow_flatbuf_DictionaryBatch_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryBatch_data_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryBatch_isDelta_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryBatch_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Message_version, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Message) +__flatbuffers_build_union_field(2, flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, org_apache_arrow_flatbuf_Message) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, Schema, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, DictionaryBatch, org_apache_arrow_flatbuf_DictionaryBatch) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, RecordBatch, org_apache_arrow_flatbuf_RecordBatch) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, Tensor, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Message_header, org_apache_arrow_flatbuf_MessageHeader, SparseTensor, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_Message_bodyLength, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_Message) +__flatbuffers_build_table_vector_field(4, flatbuffers_, org_apache_arrow_flatbuf_Message_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Message) + +static inline org_apache_arrow_flatbuf_Message_ref_t org_apache_arrow_flatbuf_Message_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Message_formal_args) +{ + if (org_apache_arrow_flatbuf_Message_start(B) + || org_apache_arrow_flatbuf_Message_bodyLength_add(B, v3) + || org_apache_arrow_flatbuf_Message_header_add_value(B, v2) + || org_apache_arrow_flatbuf_Message_custom_metadata_add(B, v4) + || org_apache_arrow_flatbuf_Message_version_add(B, v0) + || org_apache_arrow_flatbuf_Message_header_add_type(B, v2.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Message_end(B); +} + +static org_apache_arrow_flatbuf_Message_ref_t org_apache_arrow_flatbuf_Message_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Message_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Message_start(B) + || org_apache_arrow_flatbuf_Message_bodyLength_pick(B, t) + || org_apache_arrow_flatbuf_Message_header_pick(B, t) + || org_apache_arrow_flatbuf_Message_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Message_version_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Message_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* MESSAGE_BUILDER_H */ +#ifndef MESSAGE_VERIFIER_H +#define MESSAGE_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef MESSAGE_READER_H +#include "Message_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef TENSOR_VERIFIER_H +#include "Tensor_verifier.h" +#endif +#ifndef SPARSETENSOR_VERIFIER_H +#include "SparseTensor_verifier.h" +#endif +#ifndef SCHEMA_VERIFIER_H +#include "Schema_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_BodyCompression_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RecordBatch_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryBatch_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Message_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_MessageHeader_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Schema_verify_table); /* Schema */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_DictionaryBatch_verify_table); /* DictionaryBatch */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RecordBatch_verify_table); /* RecordBatch */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Tensor_verify_table); /* Tensor */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseTensor_verify_table); /* SparseTensor */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FieldNode_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FieldNode_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_FieldNode_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FieldNode_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_FieldNode_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_BodyCompression_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* codec */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* method */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BodyCompression_identifier, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BodyCompression_identifier, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BodyCompression_type_identifier, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BodyCompression_type_identifier, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BodyCompression_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BodyCompression_verify_table); +} + +static int org_apache_arrow_flatbuf_RecordBatch_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* length */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 16, 8, INT64_C(268435455)) /* nodes */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 2, 0, 16, 8, INT64_C(268435455)) /* buffers */)) return ret; + if ((ret = flatcc_verify_table_field(td, 3, 0, &org_apache_arrow_flatbuf_BodyCompression_verify_table) /* compression */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 4, 0, 8, 8, INT64_C(536870911)) /* variadicBufferCounts */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RecordBatch_identifier, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RecordBatch_identifier, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RecordBatch_type_identifier, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RecordBatch_type_identifier, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RecordBatch_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RecordBatch_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryBatch_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_RecordBatch_verify_table) /* data */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isDelta */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryBatch_identifier, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryBatch_identifier, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryBatch_type_identifier, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryBatch_type_identifier, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryBatch_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryBatch_verify_table); +} + +static int org_apache_arrow_flatbuf_Message_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* version */)) return ret; + if ((ret = flatcc_verify_union_field(td, 2, 0, &org_apache_arrow_flatbuf_MessageHeader_union_verifier) /* header */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 8, 8) /* bodyLength */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 4, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Message_identifier, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Message_identifier, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Message_type_identifier, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Message_type_identifier, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Message_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Message_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Message_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* MESSAGE_VERIFIER_H */ +#ifndef SCHEMA_READER_H +#define SCHEMA_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Buffer org_apache_arrow_flatbuf_Buffer_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_struct_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_vec_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_table_t; +typedef struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__table_t; +typedef struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_table_t; +typedef struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_table_t; +typedef struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_table_t; +typedef struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_table_t; +typedef struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_table_t; +typedef struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_table_t; +typedef struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_table_t; +typedef struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_table_t; +typedef struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_table_t; +typedef struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_table_t; +typedef struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_table_t; +typedef struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_table_t; +typedef struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_table_t; +typedef struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_table_t; +typedef struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_table_t; +typedef struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_table_t; +typedef struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_table_t; +typedef struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_table_t; +typedef struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_table_t; +typedef struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_table_t; +typedef struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_table_t; +typedef struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_table_t; +typedef struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Null_file_identifier +#define org_apache_arrow_flatbuf_Null_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Null_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Null_identifier +#define org_apache_arrow_flatbuf_Null_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Null_type_hash ((flatbuffers_thash_t)0x7b36a4dd) +#define org_apache_arrow_flatbuf_Null_type_identifier "\xdd\xa4\x36\x7b" +#ifndef org_apache_arrow_flatbuf_Null_file_extension +#define org_apache_arrow_flatbuf_Null_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Struct__file_identifier +#define org_apache_arrow_flatbuf_Struct__file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Struct__file_identifier */ +#ifndef org_apache_arrow_flatbuf_Struct__identifier +#define org_apache_arrow_flatbuf_Struct__identifier 0 +#endif +#define org_apache_arrow_flatbuf_Struct__type_hash ((flatbuffers_thash_t)0x6310f362) +#define org_apache_arrow_flatbuf_Struct__type_identifier "\x62\xf3\x10\x63" +#ifndef org_apache_arrow_flatbuf_Struct__file_extension +#define org_apache_arrow_flatbuf_Struct__file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_List_file_identifier +#define org_apache_arrow_flatbuf_List_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_List_file_identifier */ +#ifndef org_apache_arrow_flatbuf_List_identifier +#define org_apache_arrow_flatbuf_List_identifier 0 +#endif +#define org_apache_arrow_flatbuf_List_type_hash ((flatbuffers_thash_t)0xd4ce5878) +#define org_apache_arrow_flatbuf_List_type_identifier "\x78\x58\xce\xd4" +#ifndef org_apache_arrow_flatbuf_List_file_extension +#define org_apache_arrow_flatbuf_List_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeList_file_identifier +#define org_apache_arrow_flatbuf_LargeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeList_identifier +#define org_apache_arrow_flatbuf_LargeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeList_type_hash ((flatbuffers_thash_t)0x38aa7e27) +#define org_apache_arrow_flatbuf_LargeList_type_identifier "\x27\x7e\xaa\x38" +#ifndef org_apache_arrow_flatbuf_LargeList_file_extension +#define org_apache_arrow_flatbuf_LargeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_ListView_file_identifier +#define org_apache_arrow_flatbuf_ListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_ListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_ListView_identifier +#define org_apache_arrow_flatbuf_ListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_ListView_type_hash ((flatbuffers_thash_t)0x23d37919) +#define org_apache_arrow_flatbuf_ListView_type_identifier "\x19\x79\xd3\x23" +#ifndef org_apache_arrow_flatbuf_ListView_file_extension +#define org_apache_arrow_flatbuf_ListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeListView_file_identifier +#define org_apache_arrow_flatbuf_LargeListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeListView_identifier +#define org_apache_arrow_flatbuf_LargeListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeListView_type_hash ((flatbuffers_thash_t)0x28efac02) +#define org_apache_arrow_flatbuf_LargeListView_type_identifier "\x02\xac\xef\x28" +#ifndef org_apache_arrow_flatbuf_LargeListView_file_extension +#define org_apache_arrow_flatbuf_LargeListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeList_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeList_type_hash ((flatbuffers_thash_t)0xcef245bb) +#define org_apache_arrow_flatbuf_FixedSizeList_type_identifier "\xbb\x45\xf2\xce" +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_extension +#define org_apache_arrow_flatbuf_FixedSizeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Map_file_identifier +#define org_apache_arrow_flatbuf_Map_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Map_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Map_identifier +#define org_apache_arrow_flatbuf_Map_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Map_type_hash ((flatbuffers_thash_t)0xcebef8e6) +#define org_apache_arrow_flatbuf_Map_type_identifier "\xe6\xf8\xbe\xce" +#ifndef org_apache_arrow_flatbuf_Map_file_extension +#define org_apache_arrow_flatbuf_Map_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Union_file_identifier +#define org_apache_arrow_flatbuf_Union_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Union_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Union_identifier +#define org_apache_arrow_flatbuf_Union_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Union_type_hash ((flatbuffers_thash_t)0x896bda57) +#define org_apache_arrow_flatbuf_Union_type_identifier "\x57\xda\x6b\x89" +#ifndef org_apache_arrow_flatbuf_Union_file_extension +#define org_apache_arrow_flatbuf_Union_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Int_file_identifier +#define org_apache_arrow_flatbuf_Int_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Int_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Int_identifier +#define org_apache_arrow_flatbuf_Int_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Int_type_hash ((flatbuffers_thash_t)0x30789001) +#define org_apache_arrow_flatbuf_Int_type_identifier "\x01\x90\x78\x30" +#ifndef org_apache_arrow_flatbuf_Int_file_extension +#define org_apache_arrow_flatbuf_Int_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FloatingPoint_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FloatingPoint_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FloatingPoint_type_hash ((flatbuffers_thash_t)0xf7d06268) +#define org_apache_arrow_flatbuf_FloatingPoint_type_identifier "\x68\x62\xd0\xf7" +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_extension +#define org_apache_arrow_flatbuf_FloatingPoint_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8_file_identifier +#define org_apache_arrow_flatbuf_Utf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8_identifier +#define org_apache_arrow_flatbuf_Utf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8_type_hash ((flatbuffers_thash_t)0x8fe60d37) +#define org_apache_arrow_flatbuf_Utf8_type_identifier "\x37\x0d\xe6\x8f" +#ifndef org_apache_arrow_flatbuf_Utf8_file_extension +#define org_apache_arrow_flatbuf_Utf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Binary_file_identifier +#define org_apache_arrow_flatbuf_Binary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Binary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Binary_identifier +#define org_apache_arrow_flatbuf_Binary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Binary_type_hash ((flatbuffers_thash_t)0x8e21a795) +#define org_apache_arrow_flatbuf_Binary_type_identifier "\x95\xa7\x21\x8e" +#ifndef org_apache_arrow_flatbuf_Binary_file_extension +#define org_apache_arrow_flatbuf_Binary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeUtf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeUtf8_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeUtf8_type_hash ((flatbuffers_thash_t)0x24ed2fb0) +#define org_apache_arrow_flatbuf_LargeUtf8_type_identifier "\xb0\x2f\xed\x24" +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_extension +#define org_apache_arrow_flatbuf_LargeUtf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_identifier +#define org_apache_arrow_flatbuf_LargeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeBinary_identifier +#define org_apache_arrow_flatbuf_LargeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeBinary_type_hash ((flatbuffers_thash_t)0xbd437872) +#define org_apache_arrow_flatbuf_LargeBinary_type_identifier "\x72\x78\x43\xbd" +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_extension +#define org_apache_arrow_flatbuf_LargeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8View_file_identifier +#define org_apache_arrow_flatbuf_Utf8View_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8View_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8View_identifier +#define org_apache_arrow_flatbuf_Utf8View_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8View_type_hash ((flatbuffers_thash_t)0xab7692) +#define org_apache_arrow_flatbuf_Utf8View_type_identifier "\x92\x76\xab\x00" +#ifndef org_apache_arrow_flatbuf_Utf8View_file_extension +#define org_apache_arrow_flatbuf_Utf8View_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BinaryView_file_identifier +#define org_apache_arrow_flatbuf_BinaryView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BinaryView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BinaryView_identifier +#define org_apache_arrow_flatbuf_BinaryView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BinaryView_type_hash ((flatbuffers_thash_t)0x18c52428) +#define org_apache_arrow_flatbuf_BinaryView_type_identifier "\x28\x24\xc5\x18" +#ifndef org_apache_arrow_flatbuf_BinaryView_file_extension +#define org_apache_arrow_flatbuf_BinaryView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_hash ((flatbuffers_thash_t)0x80d0f4ce) +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier "\xce\xf4\xd0\x80" +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_extension +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Bool_file_identifier +#define org_apache_arrow_flatbuf_Bool_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Bool_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Bool_identifier +#define org_apache_arrow_flatbuf_Bool_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Bool_type_hash ((flatbuffers_thash_t)0x96bf83f0) +#define org_apache_arrow_flatbuf_Bool_type_identifier "\xf0\x83\xbf\x96" +#ifndef org_apache_arrow_flatbuf_Bool_file_extension +#define org_apache_arrow_flatbuf_Bool_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RunEndEncoded_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RunEndEncoded_type_hash ((flatbuffers_thash_t)0x5a98bcc) +#define org_apache_arrow_flatbuf_RunEndEncoded_type_identifier "\xcc\x8b\xa9\x05" +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_extension +#define org_apache_arrow_flatbuf_RunEndEncoded_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Decimal_file_identifier +#define org_apache_arrow_flatbuf_Decimal_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Decimal_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Decimal_identifier +#define org_apache_arrow_flatbuf_Decimal_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Decimal_type_hash ((flatbuffers_thash_t)0x91d1beb7) +#define org_apache_arrow_flatbuf_Decimal_type_identifier "\xb7\xbe\xd1\x91" +#ifndef org_apache_arrow_flatbuf_Decimal_file_extension +#define org_apache_arrow_flatbuf_Decimal_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Date_file_identifier +#define org_apache_arrow_flatbuf_Date_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Date_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Date_identifier +#define org_apache_arrow_flatbuf_Date_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Date_type_hash ((flatbuffers_thash_t)0xe0ccf624) +#define org_apache_arrow_flatbuf_Date_type_identifier "\x24\xf6\xcc\xe0" +#ifndef org_apache_arrow_flatbuf_Date_file_extension +#define org_apache_arrow_flatbuf_Date_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Time_file_identifier +#define org_apache_arrow_flatbuf_Time_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Time_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Time_identifier +#define org_apache_arrow_flatbuf_Time_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Time_type_hash ((flatbuffers_thash_t)0x2442a489) +#define org_apache_arrow_flatbuf_Time_type_identifier "\x89\xa4\x42\x24" +#ifndef org_apache_arrow_flatbuf_Time_file_extension +#define org_apache_arrow_flatbuf_Time_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Timestamp_file_identifier +#define org_apache_arrow_flatbuf_Timestamp_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Timestamp_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Timestamp_identifier +#define org_apache_arrow_flatbuf_Timestamp_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Timestamp_type_hash ((flatbuffers_thash_t)0x1fddf080) +#define org_apache_arrow_flatbuf_Timestamp_type_identifier "\x80\xf0\xdd\x1f" +#ifndef org_apache_arrow_flatbuf_Timestamp_file_extension +#define org_apache_arrow_flatbuf_Timestamp_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Interval_file_identifier +#define org_apache_arrow_flatbuf_Interval_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Interval_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Interval_identifier +#define org_apache_arrow_flatbuf_Interval_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Interval_type_hash ((flatbuffers_thash_t)0x1e2d6809) +#define org_apache_arrow_flatbuf_Interval_type_identifier "\x09\x68\x2d\x1e" +#ifndef org_apache_arrow_flatbuf_Interval_file_extension +#define org_apache_arrow_flatbuf_Interval_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Duration_file_identifier +#define org_apache_arrow_flatbuf_Duration_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Duration_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Duration_identifier +#define org_apache_arrow_flatbuf_Duration_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Duration_type_hash ((flatbuffers_thash_t)0x1ecea6b0) +#define org_apache_arrow_flatbuf_Duration_type_identifier "\xb0\xa6\xce\x1e" +#ifndef org_apache_arrow_flatbuf_Duration_file_extension +#define org_apache_arrow_flatbuf_Duration_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_KeyValue_file_identifier +#define org_apache_arrow_flatbuf_KeyValue_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_KeyValue_file_identifier */ +#ifndef org_apache_arrow_flatbuf_KeyValue_identifier +#define org_apache_arrow_flatbuf_KeyValue_identifier 0 +#endif +#define org_apache_arrow_flatbuf_KeyValue_type_hash ((flatbuffers_thash_t)0x3b264744) +#define org_apache_arrow_flatbuf_KeyValue_type_identifier "\x44\x47\x26\x3b" +#ifndef org_apache_arrow_flatbuf_KeyValue_file_extension +#define org_apache_arrow_flatbuf_KeyValue_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_hash ((flatbuffers_thash_t)0x8c703261) +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier "\x61\x32\x70\x8c" +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_extension +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Field_file_identifier +#define org_apache_arrow_flatbuf_Field_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Field_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Field_identifier +#define org_apache_arrow_flatbuf_Field_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Field_type_hash ((flatbuffers_thash_t)0xd981525c) +#define org_apache_arrow_flatbuf_Field_type_identifier "\x5c\x52\x81\xd9" +#ifndef org_apache_arrow_flatbuf_Field_file_extension +#define org_apache_arrow_flatbuf_Field_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Buffer_file_identifier +#define org_apache_arrow_flatbuf_Buffer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Buffer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Buffer_identifier +#define org_apache_arrow_flatbuf_Buffer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Buffer_type_hash ((flatbuffers_thash_t)0x519d7fea) +#define org_apache_arrow_flatbuf_Buffer_type_identifier "\xea\x7f\x9d\x51" +#ifndef org_apache_arrow_flatbuf_Buffer_file_extension +#define org_apache_arrow_flatbuf_Buffer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Schema_file_identifier +#define org_apache_arrow_flatbuf_Schema_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Schema_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Schema_identifier +#define org_apache_arrow_flatbuf_Schema_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Schema_type_hash ((flatbuffers_thash_t)0x406570b) +#define org_apache_arrow_flatbuf_Schema_type_identifier "\x0b\x57\x06\x04" +#ifndef org_apache_arrow_flatbuf_Schema_file_extension +#define org_apache_arrow_flatbuf_Schema_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_MetadataVersion_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 16) +/** 0.1.0 (October 2016). */ +#define org_apache_arrow_flatbuf_MetadataVersion_V1 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_MetadataVersion_V2 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_MetadataVersion_V3 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_MetadataVersion_V4 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(3)) +#define org_apache_arrow_flatbuf_MetadataVersion_V5 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(4)) + +static inline const char *org_apache_arrow_flatbuf_MetadataVersion_name(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return "V1"; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return "V2"; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return "V3"; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return "V4"; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return "V5"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MetadataVersion_is_known_value(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return 1; + default: return 0; + } +} + +/** Represents Arrow Features that might not have full support + * within implementations. This is intended to be used in + * two scenarios: + * 1. A mechanism for readers of Arrow Streams + * and files to understand that the stream or file makes + * use of a feature that isn't supported or unknown to + * the implementation (and therefore can meet the Arrow + * forward compatibility guarantees). + * 2. A means of negotiating between a client and server + * what features a stream is allowed to use. The enums + * values here are intented to represent higher level + * features, additional details maybe negotiated + * with key-value pairs specific to the protocol. + * + * Enums added to this list should be assigned power-of-two values + * to facilitate exchanging and comparing bitmaps for supported + * features. */ +typedef int64_t org_apache_arrow_flatbuf_Feature_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, 64) +/** Needed to make flatbuffers happy. */ +#define org_apache_arrow_flatbuf_Feature_UNUSED ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(0)) +#define org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(1)) +#define org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Feature_name(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return "UNUSED"; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return "DICTIONARY_REPLACEMENT"; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return "COMPRESSED_BODY"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Feature_is_known_value(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return 1; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return 1; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_UnionMode_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 16) +#define org_apache_arrow_flatbuf_UnionMode_Sparse ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_UnionMode_Dense ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_UnionMode_name(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return "Sparse"; + case org_apache_arrow_flatbuf_UnionMode_Dense: return "Dense"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_UnionMode_is_known_value(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return 1; + case org_apache_arrow_flatbuf_UnionMode_Dense: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_Precision_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 16) +#define org_apache_arrow_flatbuf_Precision_HALF ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Precision_SINGLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_Precision_DOUBLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Precision_name(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return "HALF"; + case org_apache_arrow_flatbuf_Precision_SINGLE: return "SINGLE"; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return "DOUBLE"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Precision_is_known_value(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return 1; + case org_apache_arrow_flatbuf_Precision_SINGLE: return 1; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_DateUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_DateUnit_DAY ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_DateUnit_MILLISECOND ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_DateUnit_name(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return "DAY"; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return "MILLISECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DateUnit_is_known_value(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return 1; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_TimeUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_TimeUnit_SECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_TimeUnit_MILLISECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_TimeUnit_MICROSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_TimeUnit_NANOSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(3)) + +static inline const char *org_apache_arrow_flatbuf_TimeUnit_name(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return "SECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return "MILLISECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return "MICROSECOND"; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return "NANOSECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_TimeUnit_is_known_value(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_IntervalUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_IntervalUnit_name(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return "YEAR_MONTH"; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return "DAY_TIME"; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return "MONTH_DAY_NANO"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_IntervalUnit_is_known_value(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Dictionary encoding metadata + * Maintained for forwards compatibility, in the future + * Dictionaries might be explicit maps between integers and values + * allowing for non-contiguous index values */ +typedef int16_t org_apache_arrow_flatbuf_DictionaryKind_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 16) +#define org_apache_arrow_flatbuf_DictionaryKind_DenseArray ((org_apache_arrow_flatbuf_DictionaryKind_enum_t)INT16_C(0)) + +static inline const char *org_apache_arrow_flatbuf_DictionaryKind_name(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return "DenseArray"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DictionaryKind_is_known_value(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Endianness of the platform producing the data */ +typedef int16_t org_apache_arrow_flatbuf_Endianness_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 16) +#define org_apache_arrow_flatbuf_Endianness_Little ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Endianness_Big ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_Endianness_name(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return "Little"; + case org_apache_arrow_flatbuf_Endianness_Big: return "Big"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Endianness_is_known_value(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return 1; + case org_apache_arrow_flatbuf_Endianness_Big: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * A Buffer represents a single contiguous memory segment */ +struct org_apache_arrow_flatbuf_Buffer { + /** The relative offset into the shared memory page where the bytes for this + * buffer starts */ + alignas(8) int64_t offset; + /** The absolute length (in bytes) of the memory buffer. The memory is found + * from offset (inclusive) to offset + length (non-inclusive). When building + * messages using the encapsulated IPC message, padding bytes may be written + * after a buffer, but such padding bytes do not need to be accounted for in + * the size here. */ + alignas(8) int64_t length; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Buffer_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__const_ptr_add(const org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__ptr_add(org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_struct_t org_apache_arrow_flatbuf_Buffer_vec_at(org_apache_arrow_flatbuf_Buffer_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Buffer__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_Buffer_vec_len(org_apache_arrow_flatbuf_Buffer_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Buffer) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, length, flatbuffers_int64, int64_t) + + +/** These are stored in the flatbuffer in the Type union below */ +struct org_apache_arrow_flatbuf_Null_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Null_vec_len(org_apache_arrow_flatbuf_Null_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Null_table_t org_apache_arrow_flatbuf_Null_vec_at(org_apache_arrow_flatbuf_Null_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Null_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Null) + + +/** A Struct_ in the flatbuffer metadata is the same as an Arrow Struct + * (according to the physical memory layout). We used Struct_ here as + * Struct is a reserved word in Flatbuffers */ +struct org_apache_arrow_flatbuf_Struct__table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Struct__vec_len(org_apache_arrow_flatbuf_Struct__vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Struct__table_t org_apache_arrow_flatbuf_Struct__vec_at(org_apache_arrow_flatbuf_Struct__vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Struct__table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Struct_) + + +struct org_apache_arrow_flatbuf_List_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_List_vec_len(org_apache_arrow_flatbuf_List_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_List_table_t org_apache_arrow_flatbuf_List_vec_at(org_apache_arrow_flatbuf_List_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_List_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_List) + + +/** Same as List, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeList_vec_len(org_apache_arrow_flatbuf_LargeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeList_table_t org_apache_arrow_flatbuf_LargeList_vec_at(org_apache_arrow_flatbuf_LargeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeList) + + +/** Represents the same logical types that List can, but contains offsets and + * sizes allowing for writes in any order and sharing of child values among + * list values. */ +struct org_apache_arrow_flatbuf_ListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_ListView_vec_len(org_apache_arrow_flatbuf_ListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_ListView_table_t org_apache_arrow_flatbuf_ListView_vec_at(org_apache_arrow_flatbuf_ListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_ListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_ListView) + + +/** Same as ListView, but with 64-bit offsets and sizes, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeListView_vec_len(org_apache_arrow_flatbuf_LargeListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeListView_table_t org_apache_arrow_flatbuf_LargeListView_vec_at(org_apache_arrow_flatbuf_LargeListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeListView) + + +struct org_apache_arrow_flatbuf_FixedSizeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeList_vec_len(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeList_table_t org_apache_arrow_flatbuf_FixedSizeList_vec_at(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeList) + +/** Number of list items per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeList, listSize, flatbuffers_int32, int32_t, INT32_C(0)) + +/** A Map is a logical nested type that is represented as + * + * List> + * + * In this layout, the keys and values are each respectively contiguous. We do + * not constrain the key and value types, so the application is responsible + * for ensuring that the keys are hashable and unique. Whether the keys are sorted + * may be set in the metadata for this field. + * + * In a field with Map type, the field has a child Struct field, which then + * has two children: key type and the second the value type. The names of the + * child fields may be respectively "entries", "key", and "value", but this is + * not enforced. + * + * Map + * ```text + * - child[0] entries: Struct + * - child[0] key: K + * - child[1] value: V + * ``` + * Neither the "entries" field nor the "key" field may be nullable. + * + * The metadata is structured so that Arrow systems without special handling + * for Map can make Map an alias for List. The "layout" attribute for the Map + * field must have the same contents as a List. */ +struct org_apache_arrow_flatbuf_Map_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Map_vec_len(org_apache_arrow_flatbuf_Map_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Map_table_t org_apache_arrow_flatbuf_Map_vec_at(org_apache_arrow_flatbuf_Map_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Map_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Map) + +/** Set to true if the keys within each value are sorted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Map, keysSorted, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** A union is a complex type with children in Field + * By default ids in the type vector refer to the offsets in the children + * optionally typeIds provides an indirection between the child offset and the type id + * for each child `typeIds[offset]` is the id used in the type vector */ +struct org_apache_arrow_flatbuf_Union_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Union_vec_len(org_apache_arrow_flatbuf_Union_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Union_table_t org_apache_arrow_flatbuf_Union_vec_at(org_apache_arrow_flatbuf_Union_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Union_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Union) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Union, mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Union, typeIds, flatbuffers_int32_vec_t, 0) + +struct org_apache_arrow_flatbuf_Int_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Int_vec_len(org_apache_arrow_flatbuf_Int_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Int_table_t org_apache_arrow_flatbuf_Int_vec_at(org_apache_arrow_flatbuf_Int_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Int_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Int) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Int, bitWidth, flatbuffers_int32, int32_t, INT32_C(0)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Int, is_signed, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +struct org_apache_arrow_flatbuf_FloatingPoint_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FloatingPoint_vec_len(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FloatingPoint_table_t org_apache_arrow_flatbuf_FloatingPoint_vec_at(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FloatingPoint_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FloatingPoint) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FloatingPoint, precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, INT16_C(0)) + +/** Unicode with UTF-8 encoding */ +struct org_apache_arrow_flatbuf_Utf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8_vec_len(org_apache_arrow_flatbuf_Utf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8_table_t org_apache_arrow_flatbuf_Utf8_vec_at(org_apache_arrow_flatbuf_Utf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8) + + +/** Opaque binary data */ +struct org_apache_arrow_flatbuf_Binary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Binary_vec_len(org_apache_arrow_flatbuf_Binary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Binary_table_t org_apache_arrow_flatbuf_Binary_vec_at(org_apache_arrow_flatbuf_Binary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Binary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Binary) + + +/** Same as Utf8, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeUtf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeUtf8_vec_len(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeUtf8_table_t org_apache_arrow_flatbuf_LargeUtf8_vec_at(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeUtf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeUtf8) + + +/** Same as Binary, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeBinary_vec_len(org_apache_arrow_flatbuf_LargeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeBinary_table_t org_apache_arrow_flatbuf_LargeBinary_vec_at(org_apache_arrow_flatbuf_LargeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeBinary) + + +/** Logically the same as Utf8, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_Utf8View_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8View_vec_len(org_apache_arrow_flatbuf_Utf8View_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8View_table_t org_apache_arrow_flatbuf_Utf8View_vec_at(org_apache_arrow_flatbuf_Utf8View_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8View_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8View) + + +/** Logically the same as Binary, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_BinaryView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BinaryView_vec_len(org_apache_arrow_flatbuf_BinaryView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BinaryView_table_t org_apache_arrow_flatbuf_BinaryView_vec_at(org_apache_arrow_flatbuf_BinaryView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BinaryView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BinaryView) + + +struct org_apache_arrow_flatbuf_FixedSizeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_len(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeBinary_table_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeBinary) + +/** Number of bytes per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeBinary, byteWidth, flatbuffers_int32, int32_t, INT32_C(0)) + +struct org_apache_arrow_flatbuf_Bool_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Bool_vec_len(org_apache_arrow_flatbuf_Bool_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Bool_table_t org_apache_arrow_flatbuf_Bool_vec_at(org_apache_arrow_flatbuf_Bool_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Bool_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Bool) + + +/** Contains two child arrays, run_ends and values. + * The run_ends child array must be a 16/32/64-bit integer array + * which encodes the indices at which the run with the value in + * each corresponding index in the values child array ends. + * Like list/struct types, the value array can be of any type. */ +struct org_apache_arrow_flatbuf_RunEndEncoded_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RunEndEncoded_vec_len(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RunEndEncoded_table_t org_apache_arrow_flatbuf_RunEndEncoded_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RunEndEncoded) + + +/** Exact decimal value represented as an integer value in two's + * complement. Currently only 128-bit (16-byte) and 256-bit (32-byte) integers + * are used. The representation uses the endianness indicated + * in the Schema. */ +struct org_apache_arrow_flatbuf_Decimal_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Decimal_vec_len(org_apache_arrow_flatbuf_Decimal_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Decimal_table_t org_apache_arrow_flatbuf_Decimal_vec_at(org_apache_arrow_flatbuf_Decimal_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Decimal_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Decimal) + +/** Total number of decimal digits */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Decimal, precision, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of digits after the decimal point "." */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Decimal, scale, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of bits per value. The only accepted widths are 128 and 256. + * We use bitWidth for consistency with Int::bitWidth. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_Decimal, bitWidth, flatbuffers_int32, int32_t, INT32_C(128)) + +/** Date is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since UNIX epoch (1970-01-01), stored in either of two units: + * + * * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no + * leap seconds), where the values are evenly divisible by 86400000 + * * Days (32 bits) since the UNIX epoch */ +struct org_apache_arrow_flatbuf_Date_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Date_vec_len(org_apache_arrow_flatbuf_Date_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Date_table_t org_apache_arrow_flatbuf_Date_vec_at(org_apache_arrow_flatbuf_Date_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Date_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Date) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Date, unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, INT16_C(1)) + +/** Time is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since midnight, stored in either of four units: seconds, + * milliseconds, microseconds or nanoseconds. + * + * The integer `bitWidth` depends on the `unit` and must be one of the following: + * * SECOND and MILLISECOND: 32 bits + * * MICROSECOND and NANOSECOND: 64 bits + * + * The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds + * (exclusive), adjusted for the time unit (for example, up to 86400000 + * exclusive for the MILLISECOND unit). + * This definition doesn't allow for leap seconds. Time values from + * measurements with leap seconds will need to be corrected when ingesting + * into Arrow (for example by replacing the value 86400 with 86399). */ +struct org_apache_arrow_flatbuf_Time_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Time_vec_len(org_apache_arrow_flatbuf_Time_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Time_table_t org_apache_arrow_flatbuf_Time_vec_at(org_apache_arrow_flatbuf_Time_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Time_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Time) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Time, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Time, bitWidth, flatbuffers_int32, int32_t, INT32_C(32)) + +/** Timestamp is a 64-bit signed integer representing an elapsed time since a + * fixed epoch, stored in either of four units: seconds, milliseconds, + * microseconds or nanoseconds, and is optionally annotated with a timezone. + * + * Timestamp values do not include any leap seconds (in other words, all + * days are considered 86400 seconds long). + * + * Timestamps with a non-empty timezone + * ------------------------------------ + * + * If a Timestamp column has a non-empty timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone + * (the Unix epoch), regardless of the Timestamp's own timezone. + * + * Therefore, timestamp values with a non-empty timezone correspond to + * physical points in time together with some additional information about + * how the data was obtained and/or how to display it (the timezone). + * + * For example, the timestamp value 0 with the timezone string "Europe/Paris" + * corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the + * application may prefer to display it as "January 1st 1970, 01h00" in + * the Europe/Paris timezone (which is the same physical point in time). + * + * One consequence is that timestamp values with a non-empty timezone + * can be compared and ordered directly, since they all share the same + * well-known point of reference (the Unix epoch). + * + * Timestamps with an unset / empty timezone + * ----------------------------------------- + * + * If a Timestamp column has no timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. + * + * Therefore, timestamp values without a timezone cannot be meaningfully + * interpreted as physical points in time, but only as calendar / clock + * indications ("wall clock time") in an unspecified timezone. + * + * For example, the timestamp value 0 with an empty timezone string + * corresponds to "January 1st 1970, 00h00" in an unknown timezone: there + * is not enough information to interpret it as a well-defined physical + * point in time. + * + * One consequence is that timestamp values without a timezone cannot + * be reliably compared or ordered, since they may have different points of + * reference. In particular, it is *not* possible to interpret an unset + * or empty timezone as the same as "UTC". + * + * Conversion between timezones + * ---------------------------- + * + * If a Timestamp column has a non-empty timezone, changing the timezone + * to a different non-empty value is a metadata-only operation: + * the timestamp values need not change as their point of reference remains + * the same (the Unix epoch). + * + * However, if a Timestamp column has no timezone value, changing it to a + * non-empty value requires to think about the desired semantics. + * One possibility is to assume that the original timestamp values are + * relative to the epoch of the timezone being set; timestamp values should + * then adjusted to the Unix epoch (for example, changing the timezone from + * empty to "Europe/Paris" would require converting the timestamp values + * from "Europe/Paris" to "UTC", which seems counter-intuitive but is + * nevertheless correct). + * + * Guidelines for encoding data from external libraries + * ---------------------------------------------------- + * + * Date & time libraries often have multiple different data types for temporal + * data. In order to ease interoperability between different implementations the + * Arrow project has some recommendations for encoding these types into a Timestamp + * column. + * + * An "instant" represents a physical point in time that has no relevant timezone + * (for example, astronomical data). To encode an instant, use a Timestamp with + * the timezone string set to "UTC", and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * A "zoned date-time" represents a physical point in time annotated with an + * informative timezone (for example, the timezone in which the data was + * recorded). To encode a zoned date-time, use a Timestamp with the timezone + * string set to the name of the timezone, and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * (There is some ambiguity between an instant and a zoned date-time with the + * UTC timezone. Both of these are stored the same in Arrow. Typically, + * this distinction does not matter. If it does, then an application should + * use custom metadata or an extension type to distinguish between the two cases.) + * + * An "offset date-time" represents a physical point in time combined with an + * explicit offset from UTC. To encode an offset date-time, use a Timestamp + * with the timezone string set to the numeric timezone offset string + * (e.g. "+03:00"), and make sure the Timestamp values are relative to + * the UTC epoch (January 1st 1970, midnight). + * + * A "naive date-time" (also called "local date-time" in some libraries) + * represents a wall clock time combined with a calendar date, but with + * no indication of how to map this information to a physical point in time. + * Naive date-times must be handled with care because of this missing + * information, and also because daylight saving time (DST) may make + * some values ambiguous or nonexistent. A naive date-time may be + * stored as a struct with Date and Time fields. However, it may also be + * encoded into a Timestamp column with an empty timezone. The timestamp + * values should be computed "as if" the timezone of the date-time values + * was UTC; for example, the naive date-time "January 1st 1970, 00h00" would + * be encoded as timestamp value 0. */ +struct org_apache_arrow_flatbuf_Timestamp_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Timestamp_vec_len(org_apache_arrow_flatbuf_Timestamp_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Timestamp_table_t org_apache_arrow_flatbuf_Timestamp_vec_at(org_apache_arrow_flatbuf_Timestamp_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Timestamp_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Timestamp) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Timestamp, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(0)) +/** The timezone is an optional string indicating the name of a timezone, + * one of: + * + * * As used in the Olson timezone database (the "tz database" or + * "tzdata"), such as "America/New_York". + * * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + * such as "+07:30". + * + * Whether a timezone string is present indicates different semantics about + * the data (see above). */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_Timestamp, timezone, 0) + +struct org_apache_arrow_flatbuf_Interval_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Interval_vec_len(org_apache_arrow_flatbuf_Interval_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Interval_table_t org_apache_arrow_flatbuf_Interval_vec_at(org_apache_arrow_flatbuf_Interval_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Interval_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Interval) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Interval, unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, INT16_C(0)) + +struct org_apache_arrow_flatbuf_Duration_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Duration_vec_len(org_apache_arrow_flatbuf_Duration_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Duration_table_t org_apache_arrow_flatbuf_Duration_vec_at(org_apache_arrow_flatbuf_Duration_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Duration_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Duration) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Duration, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +/** ---------------------------------------------------------------------- + * Top-level Type value, enabling extensible type-specific metadata. We can + * add new logical types to Type without breaking backwards compatibility */ +typedef uint8_t org_apache_arrow_flatbuf_Type_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Type_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_Type) +/** ---------------------------------------------------------------------- + * user defined key value pairs to add custom metadata to arrow + * key namespacing is the responsibility of the user */ +#define org_apache_arrow_flatbuf_Type_NONE ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_Type_Null ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_Type_Int ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_Type_FloatingPoint ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_Type_Binary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_Type_Utf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(5)) +#define org_apache_arrow_flatbuf_Type_Bool ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(6)) +#define org_apache_arrow_flatbuf_Type_Decimal ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(7)) +#define org_apache_arrow_flatbuf_Type_Date ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(8)) +#define org_apache_arrow_flatbuf_Type_Time ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(9)) +#define org_apache_arrow_flatbuf_Type_Timestamp ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(10)) +#define org_apache_arrow_flatbuf_Type_Interval ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(11)) +#define org_apache_arrow_flatbuf_Type_List ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(12)) +#define org_apache_arrow_flatbuf_Type_Struct_ ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(13)) +#define org_apache_arrow_flatbuf_Type_Union ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(14)) +#define org_apache_arrow_flatbuf_Type_FixedSizeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(15)) +#define org_apache_arrow_flatbuf_Type_FixedSizeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(16)) +#define org_apache_arrow_flatbuf_Type_Map ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(17)) +#define org_apache_arrow_flatbuf_Type_Duration ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(18)) +#define org_apache_arrow_flatbuf_Type_LargeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(19)) +#define org_apache_arrow_flatbuf_Type_LargeUtf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(20)) +#define org_apache_arrow_flatbuf_Type_LargeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(21)) +#define org_apache_arrow_flatbuf_Type_RunEndEncoded ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(22)) +#define org_apache_arrow_flatbuf_Type_BinaryView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(23)) +#define org_apache_arrow_flatbuf_Type_Utf8View ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(24)) +#define org_apache_arrow_flatbuf_Type_ListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(25)) +#define org_apache_arrow_flatbuf_Type_LargeListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(26)) + +static inline const char *org_apache_arrow_flatbuf_Type_type_name(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return "NONE"; + case org_apache_arrow_flatbuf_Type_Null: return "Null"; + case org_apache_arrow_flatbuf_Type_Int: return "Int"; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return "FloatingPoint"; + case org_apache_arrow_flatbuf_Type_Binary: return "Binary"; + case org_apache_arrow_flatbuf_Type_Utf8: return "Utf8"; + case org_apache_arrow_flatbuf_Type_Bool: return "Bool"; + case org_apache_arrow_flatbuf_Type_Decimal: return "Decimal"; + case org_apache_arrow_flatbuf_Type_Date: return "Date"; + case org_apache_arrow_flatbuf_Type_Time: return "Time"; + case org_apache_arrow_flatbuf_Type_Timestamp: return "Timestamp"; + case org_apache_arrow_flatbuf_Type_Interval: return "Interval"; + case org_apache_arrow_flatbuf_Type_List: return "List"; + case org_apache_arrow_flatbuf_Type_Struct_: return "Struct_"; + case org_apache_arrow_flatbuf_Type_Union: return "Union"; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return "FixedSizeBinary"; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return "FixedSizeList"; + case org_apache_arrow_flatbuf_Type_Map: return "Map"; + case org_apache_arrow_flatbuf_Type_Duration: return "Duration"; + case org_apache_arrow_flatbuf_Type_LargeBinary: return "LargeBinary"; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return "LargeUtf8"; + case org_apache_arrow_flatbuf_Type_LargeList: return "LargeList"; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return "RunEndEncoded"; + case org_apache_arrow_flatbuf_Type_BinaryView: return "BinaryView"; + case org_apache_arrow_flatbuf_Type_Utf8View: return "Utf8View"; + case org_apache_arrow_flatbuf_Type_ListView: return "ListView"; + case org_apache_arrow_flatbuf_Type_LargeListView: return "LargeListView"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Type_is_known_type(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return 1; + case org_apache_arrow_flatbuf_Type_Null: return 1; + case org_apache_arrow_flatbuf_Type_Int: return 1; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return 1; + case org_apache_arrow_flatbuf_Type_Binary: return 1; + case org_apache_arrow_flatbuf_Type_Utf8: return 1; + case org_apache_arrow_flatbuf_Type_Bool: return 1; + case org_apache_arrow_flatbuf_Type_Decimal: return 1; + case org_apache_arrow_flatbuf_Type_Date: return 1; + case org_apache_arrow_flatbuf_Type_Time: return 1; + case org_apache_arrow_flatbuf_Type_Timestamp: return 1; + case org_apache_arrow_flatbuf_Type_Interval: return 1; + case org_apache_arrow_flatbuf_Type_List: return 1; + case org_apache_arrow_flatbuf_Type_Struct_: return 1; + case org_apache_arrow_flatbuf_Type_Union: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return 1; + case org_apache_arrow_flatbuf_Type_Map: return 1; + case org_apache_arrow_flatbuf_Type_Duration: return 1; + case org_apache_arrow_flatbuf_Type_LargeBinary: return 1; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return 1; + case org_apache_arrow_flatbuf_Type_LargeList: return 1; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return 1; + case org_apache_arrow_flatbuf_Type_BinaryView: return 1; + case org_apache_arrow_flatbuf_Type_Utf8View: return 1; + case org_apache_arrow_flatbuf_Type_ListView: return 1; + case org_apache_arrow_flatbuf_Type_LargeListView: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_KeyValue_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_KeyValue_vec_len(org_apache_arrow_flatbuf_KeyValue_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_KeyValue_table_t org_apache_arrow_flatbuf_KeyValue_vec_at(org_apache_arrow_flatbuf_KeyValue_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_KeyValue_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_KeyValue) + +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_KeyValue, key, 0) +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_KeyValue, value, 0) + +struct org_apache_arrow_flatbuf_DictionaryEncoding_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_len(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryEncoding_table_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryEncoding) + +/** The known dictionary id in the application where this data is used. In + * the file or streaming formats, the dictionary ids are found in the + * DictionaryBatch messages */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryEncoding, id, flatbuffers_int64, int64_t, INT64_C(0)) +/** The dictionary indices are constrained to be non-negative integers. If + * this field is null, the indices must be signed int32. To maximize + * cross-language compatibility and performance, implementations are + * recommended to prefer signed integer types over unsigned integer types + * and to avoid uint64 indices unless they are required by an application. */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryEncoding, indexType, org_apache_arrow_flatbuf_Int_table_t, 0) +/** By default, dictionaries are not ordered, or the order does not have + * semantic meaning. In some statistical, applications, dictionary-encoding + * is used to represent ordered categorical data, and we provide a way to + * preserve that metadata here */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryEncoding, isOrdered, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_DictionaryEncoding, dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, INT16_C(0)) + +/** ---------------------------------------------------------------------- + * A field represents a named column in a record / row batch or child of a + * nested type. */ +struct org_apache_arrow_flatbuf_Field_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Field_vec_len(org_apache_arrow_flatbuf_Field_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Field_table_t org_apache_arrow_flatbuf_Field_vec_at(org_apache_arrow_flatbuf_Field_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Field_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Field) + +/** Name is not required, in i.e. a List */ +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_Field, name, 0) +/** Whether or not this field can contain nulls. Should be true in general. */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Field, nullable, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** This is the type of the decoded value if the field is dictionary encoded. */ +__flatbuffers_define_union_field(flatbuffers_, 3, org_apache_arrow_flatbuf_Field, type, org_apache_arrow_flatbuf_Type, 0) +/** Present only if the field is dictionary encoded. */ +__flatbuffers_define_table_field(4, org_apache_arrow_flatbuf_Field, dictionary, org_apache_arrow_flatbuf_DictionaryEncoding_table_t, 0) +/** children apply only to nested data types like Struct, List and Union. For + * primitive types children will have length 0. */ +__flatbuffers_define_vector_field(5, org_apache_arrow_flatbuf_Field, children, org_apache_arrow_flatbuf_Field_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(6, org_apache_arrow_flatbuf_Field, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + +/** ---------------------------------------------------------------------- + * A Schema describes the columns in a row batch */ +struct org_apache_arrow_flatbuf_Schema_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Schema_vec_len(org_apache_arrow_flatbuf_Schema_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Schema_table_t org_apache_arrow_flatbuf_Schema_vec_at(org_apache_arrow_flatbuf_Schema_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Schema_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Schema) + +/** endianness of the buffer + * it is Little Endian by default + * if endianness doesn't match the underlying system then the vectors need to be converted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Schema, endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Schema, fields, org_apache_arrow_flatbuf_Field_vec_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Schema, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) +/** Features used in the stream/file. */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Schema, features, org_apache_arrow_flatbuf_Feature_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_READER_H */ +#ifndef SCHEMA_BUILDER_H +#define SCHEMA_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_MetadataVersion_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0 +#define __org_apache_arrow_flatbuf_MetadataVersion_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t) +#define __org_apache_arrow_flatbuf_Feature_formal_args , org_apache_arrow_flatbuf_Feature_enum_t v0 +#define __org_apache_arrow_flatbuf_Feature_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t) +#define __org_apache_arrow_flatbuf_UnionMode_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0 +#define __org_apache_arrow_flatbuf_UnionMode_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t) +#define __org_apache_arrow_flatbuf_Precision_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_Precision_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t) +#define __org_apache_arrow_flatbuf_DateUnit_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_DateUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t) +#define __org_apache_arrow_flatbuf_TimeUnit_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_TimeUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t) +#define __org_apache_arrow_flatbuf_IntervalUnit_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_IntervalUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t) +#define __org_apache_arrow_flatbuf_DictionaryKind_formal_args , org_apache_arrow_flatbuf_DictionaryKind_enum_t v0 +#define __org_apache_arrow_flatbuf_DictionaryKind_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t) +#define __org_apache_arrow_flatbuf_Endianness_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0 +#define __org_apache_arrow_flatbuf_Endianness_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t) + +#define __org_apache_arrow_flatbuf_Buffer_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_Buffer_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ p->offset = v0; p->length = v1; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ p->offset = p2->offset; p->length = p2->length; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int64_assign_to_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_to_pe(&p->length, &p2->length); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int64_assign_from_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_from_pe(&p->length, &p2->length); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Buffer_file_identifier, org_apache_arrow_flatbuf_Buffer_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_Type_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_Type_union_vec_ref_t; +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Null_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Null_ref_t; +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Null, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Struct__required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Struct__ref_t; +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Struct_, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_List_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_List_ref_t; +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_List, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeList_ref_t; +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeList, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_ListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_ListView_ref_t; +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_ListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeListView_ref_t; +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeList_ref_t; +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Map_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Map_ref_t; +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Map, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Union_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Union_ref_t; +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Union, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Int_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Int_ref_t; +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Int, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FloatingPoint_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FloatingPoint_ref_t; +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8_ref_t; +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Binary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Binary_ref_t; +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Binary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeUtf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeUtf8_ref_t; +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeBinary_ref_t; +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8View_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8View_ref_t; +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BinaryView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BinaryView_ref_t; +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_ref_t; +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Bool_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Bool_ref_t; +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Bool, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RunEndEncoded_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RunEndEncoded_ref_t; +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Decimal_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Decimal_ref_t; +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Decimal, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Date_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Date_ref_t; +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Date, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Time_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Time_ref_t; +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Time, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Timestamp_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Timestamp_ref_t; +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Interval_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Interval_ref_t; +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Interval, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Duration_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Duration_ref_t; +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Duration, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_KeyValue_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_KeyValue_ref_t; +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryEncoding_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_ref_t; +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Field_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Field_ref_t; +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Field, 7) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Schema_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Schema_ref_t; +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Schema, 4) + +#define __org_apache_arrow_flatbuf_Null_formal_args +#define __org_apache_arrow_flatbuf_Null_call_args +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Null, org_apache_arrow_flatbuf_Null_file_identifier, org_apache_arrow_flatbuf_Null_type_identifier) + +#define __org_apache_arrow_flatbuf_Struct__formal_args +#define __org_apache_arrow_flatbuf_Struct__call_args +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Struct_, org_apache_arrow_flatbuf_Struct__file_identifier, org_apache_arrow_flatbuf_Struct__type_identifier) + +#define __org_apache_arrow_flatbuf_List_formal_args +#define __org_apache_arrow_flatbuf_List_call_args +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_List, org_apache_arrow_flatbuf_List_file_identifier, org_apache_arrow_flatbuf_List_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeList_formal_args +#define __org_apache_arrow_flatbuf_LargeList_call_args +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeList, org_apache_arrow_flatbuf_LargeList_file_identifier, org_apache_arrow_flatbuf_LargeList_type_identifier) + +#define __org_apache_arrow_flatbuf_ListView_formal_args +#define __org_apache_arrow_flatbuf_ListView_call_args +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_ListView, org_apache_arrow_flatbuf_ListView_file_identifier, org_apache_arrow_flatbuf_ListView_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeListView_formal_args +#define __org_apache_arrow_flatbuf_LargeListView_call_args +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, org_apache_arrow_flatbuf_LargeListView_file_identifier, org_apache_arrow_flatbuf_LargeListView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeList_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeList_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList_file_identifier, org_apache_arrow_flatbuf_FixedSizeList_type_identifier) + +#define __org_apache_arrow_flatbuf_Map_formal_args , flatbuffers_bool_t v0 +#define __org_apache_arrow_flatbuf_Map_call_args , v0 +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Map, org_apache_arrow_flatbuf_Map_file_identifier, org_apache_arrow_flatbuf_Map_type_identifier) + +#define __org_apache_arrow_flatbuf_Union_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0, flatbuffers_int32_vec_ref_t v1 +#define __org_apache_arrow_flatbuf_Union_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Union, org_apache_arrow_flatbuf_Union_file_identifier, org_apache_arrow_flatbuf_Union_type_identifier) + +#define __org_apache_arrow_flatbuf_Int_formal_args , int32_t v0, flatbuffers_bool_t v1 +#define __org_apache_arrow_flatbuf_Int_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_Int_file_identifier, org_apache_arrow_flatbuf_Int_type_identifier) + +#define __org_apache_arrow_flatbuf_FloatingPoint_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_FloatingPoint_call_args , v0 +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint_file_identifier, org_apache_arrow_flatbuf_FloatingPoint_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8_formal_args +#define __org_apache_arrow_flatbuf_Utf8_call_args +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8, org_apache_arrow_flatbuf_Utf8_file_identifier, org_apache_arrow_flatbuf_Utf8_type_identifier) + +#define __org_apache_arrow_flatbuf_Binary_formal_args +#define __org_apache_arrow_flatbuf_Binary_call_args +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Binary, org_apache_arrow_flatbuf_Binary_file_identifier, org_apache_arrow_flatbuf_Binary_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeUtf8_formal_args +#define __org_apache_arrow_flatbuf_LargeUtf8_call_args +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8_file_identifier, org_apache_arrow_flatbuf_LargeUtf8_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeBinary_formal_args +#define __org_apache_arrow_flatbuf_LargeBinary_call_args +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, org_apache_arrow_flatbuf_LargeBinary_file_identifier, org_apache_arrow_flatbuf_LargeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8View_formal_args +#define __org_apache_arrow_flatbuf_Utf8View_call_args +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, org_apache_arrow_flatbuf_Utf8View_file_identifier, org_apache_arrow_flatbuf_Utf8View_type_identifier) + +#define __org_apache_arrow_flatbuf_BinaryView_formal_args +#define __org_apache_arrow_flatbuf_BinaryView_call_args +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, org_apache_arrow_flatbuf_BinaryView_file_identifier, org_apache_arrow_flatbuf_BinaryView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeBinary_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Bool_formal_args +#define __org_apache_arrow_flatbuf_Bool_call_args +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Bool, org_apache_arrow_flatbuf_Bool_file_identifier, org_apache_arrow_flatbuf_Bool_type_identifier) + +#define __org_apache_arrow_flatbuf_RunEndEncoded_formal_args +#define __org_apache_arrow_flatbuf_RunEndEncoded_call_args +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded_file_identifier, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier) + +#define __org_apache_arrow_flatbuf_Decimal_formal_args , int32_t v0, int32_t v1, int32_t v2 +#define __org_apache_arrow_flatbuf_Decimal_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Decimal, org_apache_arrow_flatbuf_Decimal_file_identifier, org_apache_arrow_flatbuf_Decimal_type_identifier) + +#define __org_apache_arrow_flatbuf_Date_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Date_call_args , v0 +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Date, org_apache_arrow_flatbuf_Date_file_identifier, org_apache_arrow_flatbuf_Date_type_identifier) + +#define __org_apache_arrow_flatbuf_Time_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, int32_t v1 +#define __org_apache_arrow_flatbuf_Time_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Time, org_apache_arrow_flatbuf_Time_file_identifier, org_apache_arrow_flatbuf_Time_type_identifier) + +#define __org_apache_arrow_flatbuf_Timestamp_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_Timestamp_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, org_apache_arrow_flatbuf_Timestamp_file_identifier, org_apache_arrow_flatbuf_Timestamp_type_identifier) + +#define __org_apache_arrow_flatbuf_Interval_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Interval_call_args , v0 +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Interval, org_apache_arrow_flatbuf_Interval_file_identifier, org_apache_arrow_flatbuf_Interval_type_identifier) + +#define __org_apache_arrow_flatbuf_Duration_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Duration_call_args , v0 +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Duration, org_apache_arrow_flatbuf_Duration_file_identifier, org_apache_arrow_flatbuf_Duration_type_identifier) + +#define __org_apache_arrow_flatbuf_KeyValue_formal_args , flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_KeyValue_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_KeyValue_file_identifier, org_apache_arrow_flatbuf_KeyValue_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args , int64_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, flatbuffers_bool_t v2, org_apache_arrow_flatbuf_DictionaryKind_enum_t v3 +#define __org_apache_arrow_flatbuf_DictionaryEncoding_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier) + +#define __org_apache_arrow_flatbuf_Field_formal_args ,\ + flatbuffers_string_ref_t v0, flatbuffers_bool_t v1, org_apache_arrow_flatbuf_Type_union_ref_t v3, org_apache_arrow_flatbuf_DictionaryEncoding_ref_t v4, org_apache_arrow_flatbuf_Field_vec_ref_t v5, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v6 +#define __org_apache_arrow_flatbuf_Field_call_args ,\ + v0, v1, v3, v4, v5, v6 +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field_file_identifier, org_apache_arrow_flatbuf_Field_type_identifier) + +#define __org_apache_arrow_flatbuf_Schema_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0, org_apache_arrow_flatbuf_Field_vec_ref_t v1, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v2, org_apache_arrow_flatbuf_Feature_vec_ref_t v3 +#define __org_apache_arrow_flatbuf_Schema_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Schema_file_identifier, org_apache_arrow_flatbuf_Schema_type_identifier) + +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_NONE(void) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Null; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Int; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FloatingPoint; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Binary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Bool; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Decimal; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Date; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Time; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Timestamp; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Interval; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_List; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Struct_; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Union; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Map; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Duration; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeUtf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_RunEndEncoded; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_BinaryView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8View; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_ListView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeListView; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_Type) + +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_clone(B, (org_apache_arrow_flatbuf_Null_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_clone(B, (org_apache_arrow_flatbuf_Int_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_clone(B, (org_apache_arrow_flatbuf_FloatingPoint_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_clone(B, (org_apache_arrow_flatbuf_Binary_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_clone(B, (org_apache_arrow_flatbuf_Utf8_table_t)u.value)); + case 6: return org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_clone(B, (org_apache_arrow_flatbuf_Bool_table_t)u.value)); + case 7: return org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_clone(B, (org_apache_arrow_flatbuf_Decimal_table_t)u.value)); + case 8: return org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_clone(B, (org_apache_arrow_flatbuf_Date_table_t)u.value)); + case 9: return org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_clone(B, (org_apache_arrow_flatbuf_Time_table_t)u.value)); + case 10: return org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_clone(B, (org_apache_arrow_flatbuf_Timestamp_table_t)u.value)); + case 11: return org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_clone(B, (org_apache_arrow_flatbuf_Interval_table_t)u.value)); + case 12: return org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_clone(B, (org_apache_arrow_flatbuf_List_table_t)u.value)); + case 13: return org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__clone(B, (org_apache_arrow_flatbuf_Struct__table_t)u.value)); + case 14: return org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_clone(B, (org_apache_arrow_flatbuf_Union_table_t)u.value)); + case 15: return org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_clone(B, (org_apache_arrow_flatbuf_FixedSizeBinary_table_t)u.value)); + case 16: return org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_clone(B, (org_apache_arrow_flatbuf_FixedSizeList_table_t)u.value)); + case 17: return org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_clone(B, (org_apache_arrow_flatbuf_Map_table_t)u.value)); + case 18: return org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_clone(B, (org_apache_arrow_flatbuf_Duration_table_t)u.value)); + case 19: return org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_clone(B, (org_apache_arrow_flatbuf_LargeBinary_table_t)u.value)); + case 20: return org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_clone(B, (org_apache_arrow_flatbuf_LargeUtf8_table_t)u.value)); + case 21: return org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_clone(B, (org_apache_arrow_flatbuf_LargeList_table_t)u.value)); + case 22: return org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_clone(B, (org_apache_arrow_flatbuf_RunEndEncoded_table_t)u.value)); + case 23: return org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_clone(B, (org_apache_arrow_flatbuf_BinaryView_table_t)u.value)); + case 24: return org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_clone(B, (org_apache_arrow_flatbuf_Utf8View_table_t)u.value)); + case 25: return org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_clone(B, (org_apache_arrow_flatbuf_ListView_table_t)u.value)); + case 26: return org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_clone(B, (org_apache_arrow_flatbuf_LargeListView_table_t)u.value)); + default: return org_apache_arrow_flatbuf_Type_as_NONE(); + } +} + + +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args) +{ + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Null_end(B); +} + +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Null_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args) +{ + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Struct__end(B); +} + +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Struct__end(B)); +} + + +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args) +{ + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_List_end(B); +} + +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_List_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeList_end(B); +} + +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeList_end(B)); +} + + +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args) +{ + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_ListView_end(B); +} + +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_ListView_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeListView_end(B); +} + +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeListView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList_listSize, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeList) + +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeList_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeList_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Map_keysSorted, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Map) + +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args) +{ + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Map_end(B); +} + +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Map_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Union_mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Union) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Union_typeIds, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_Union) + +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args) +{ + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_add(B, v1) + || org_apache_arrow_flatbuf_Union_mode_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Union_end(B); +} + +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_pick(B, t) + || org_apache_arrow_flatbuf_Union_mode_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Union_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Int_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Int) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Int_is_signed, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Int) + +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args) +{ + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_add(B, v0) + || org_apache_arrow_flatbuf_Int_is_signed_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_Int_end(B); +} + +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Int_is_signed_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Int_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint_precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_FloatingPoint) + +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args) +{ + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FloatingPoint_end(B); +} + +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FloatingPoint_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8_end(B); +} + +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args) +{ + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Binary_end(B); +} + +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Binary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeUtf8_end(B); +} + +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeUtf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeBinary_end(B); +} + +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8View_end(B); +} + +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8View_end(B)); +} + + +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args) +{ + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_BinaryView_end(B); +} + +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BinaryView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeBinary) + +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeBinary_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args) +{ + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Bool_end(B); +} + +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Bool_end(B)); +} + + +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args) +{ + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_RunEndEncoded_end(B); +} + +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RunEndEncoded_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Decimal_precision, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Decimal_scale, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_Decimal_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(128), org_apache_arrow_flatbuf_Decimal) + +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args) +{ + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_add(B, v0) + || org_apache_arrow_flatbuf_Decimal_scale_add(B, v1) + || org_apache_arrow_flatbuf_Decimal_bitWidth_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_Decimal_end(B); +} + +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_scale_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_bitWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Decimal_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Date_unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Date) + +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args) +{ + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Date_end(B); +} + +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Date_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Time_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Time) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Time_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(32), org_apache_arrow_flatbuf_Time) + +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args) +{ + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_add(B, v1) + || org_apache_arrow_flatbuf_Time_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Time_end(B); +} + +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Time_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Time_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_timezone, org_apache_arrow_flatbuf_Timestamp) + +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args) +{ + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_add(B, v1) + || org_apache_arrow_flatbuf_Timestamp_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Timestamp_end(B); +} + +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_pick(B, t) + || org_apache_arrow_flatbuf_Timestamp_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Timestamp_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Interval_unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Interval) + +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args) +{ + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Interval_end(B); +} + +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Interval_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Duration_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Duration) + +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args) +{ + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Duration_end(B); +} + +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Duration_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_key, org_apache_arrow_flatbuf_KeyValue) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_value, org_apache_arrow_flatbuf_KeyValue) + +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args) +{ + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_add(B, v0) + || org_apache_arrow_flatbuf_KeyValue_value_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_KeyValue_end(B); +} + +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_pick(B, t) + || org_apache_arrow_flatbuf_KeyValue_value_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_KeyValue_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_indexType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) + +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_add(B, v3) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryEncoding_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryEncoding_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_Field_name, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Field_nullable, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_field(3, flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_field(4, flatbuffers_, org_apache_arrow_flatbuf_Field_dictionary, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(5, flatbuffers_, org_apache_arrow_flatbuf_Field_children, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(6, flatbuffers_, org_apache_arrow_flatbuf_Field_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Field) + +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args) +{ + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_add(B, v0) + || org_apache_arrow_flatbuf_Field_type_add_value(B, v3) + || org_apache_arrow_flatbuf_Field_dictionary_add(B, v4) + || org_apache_arrow_flatbuf_Field_children_add(B, v5) + || org_apache_arrow_flatbuf_Field_custom_metadata_add(B, v6) + || org_apache_arrow_flatbuf_Field_nullable_add(B, v1) + || org_apache_arrow_flatbuf_Field_type_add_type(B, v3.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Field_end(B); +} + +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_pick(B, t) + || org_apache_arrow_flatbuf_Field_type_pick(B, t) + || org_apache_arrow_flatbuf_Field_dictionary_pick(B, t) + || org_apache_arrow_flatbuf_Field_children_pick(B, t) + || org_apache_arrow_flatbuf_Field_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Field_nullable_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Field_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Schema_endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Schema_fields, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Schema_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Schema_features, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, org_apache_arrow_flatbuf_Schema) + +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args) +{ + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_add(B, v1) + || org_apache_arrow_flatbuf_Schema_custom_metadata_add(B, v2) + || org_apache_arrow_flatbuf_Schema_features_add(B, v3) + || org_apache_arrow_flatbuf_Schema_endianness_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Schema_end(B); +} + +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_pick(B, t) + || org_apache_arrow_flatbuf_Schema_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Schema_features_pick(B, t) + || org_apache_arrow_flatbuf_Schema_endianness_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Schema_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_BUILDER_H */ +#ifndef SCHEMA_VERIFIER_H +#define SCHEMA_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_Type_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Null_verify_table); /* Null */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Int_verify_table); /* Int */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FloatingPoint_verify_table); /* FloatingPoint */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Binary_verify_table); /* Binary */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8_verify_table); /* Utf8 */ + case 6: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Bool_verify_table); /* Bool */ + case 7: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Decimal_verify_table); /* Decimal */ + case 8: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Date_verify_table); /* Date */ + case 9: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Time_verify_table); /* Time */ + case 10: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Timestamp_verify_table); /* Timestamp */ + case 11: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Interval_verify_table); /* Interval */ + case 12: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_List_verify_table); /* List */ + case 13: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Struct__verify_table); /* Struct_ */ + case 14: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Union_verify_table); /* Union */ + case 15: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); /* FixedSizeBinary */ + case 16: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeList_verify_table); /* FixedSizeList */ + case 17: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Map_verify_table); /* Map */ + case 18: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Duration_verify_table); /* Duration */ + case 19: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeBinary_verify_table); /* LargeBinary */ + case 20: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeUtf8_verify_table); /* LargeUtf8 */ + case 21: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeList_verify_table); /* LargeList */ + case 22: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RunEndEncoded_verify_table); /* RunEndEncoded */ + case 23: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_BinaryView_verify_table); /* BinaryView */ + case 24: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8View_verify_table); /* Utf8View */ + case 25: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_ListView_verify_table); /* ListView */ + case 26: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeListView_verify_table); /* LargeListView */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* listSize */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* keysSorted */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* mode */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 4, 4, INT64_C(1073741823)) /* typeIds */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* bitWidth */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* is_signed */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* precision */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* byteWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* precision */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* scale */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* timezone */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* value */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Int_verify_table) /* indexType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isOrdered */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 2, 2) /* dictionaryKind */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* name */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* nullable */)) return ret; + if ((ret = flatcc_verify_union_field(td, 3, 0, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_field(td, 4, 0, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table) /* dictionary */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 5, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* children */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 6, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* endianness */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 1, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* fields */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* features */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_VERIFIER_H */ +#ifndef SCHEMA_READER_H +#define SCHEMA_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Buffer org_apache_arrow_flatbuf_Buffer_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_struct_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_vec_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_table_t; +typedef struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__table_t; +typedef struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_table_t; +typedef struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_table_t; +typedef struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_table_t; +typedef struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_table_t; +typedef struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_table_t; +typedef struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_table_t; +typedef struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_table_t; +typedef struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_table_t; +typedef struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_table_t; +typedef struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_table_t; +typedef struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_table_t; +typedef struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_table_t; +typedef struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_table_t; +typedef struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_table_t; +typedef struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_table_t; +typedef struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_table_t; +typedef struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_table_t; +typedef struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_table_t; +typedef struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_table_t; +typedef struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_table_t; +typedef struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_table_t; +typedef struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_table_t; +typedef struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Null_file_identifier +#define org_apache_arrow_flatbuf_Null_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Null_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Null_identifier +#define org_apache_arrow_flatbuf_Null_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Null_type_hash ((flatbuffers_thash_t)0x7b36a4dd) +#define org_apache_arrow_flatbuf_Null_type_identifier "\xdd\xa4\x36\x7b" +#ifndef org_apache_arrow_flatbuf_Null_file_extension +#define org_apache_arrow_flatbuf_Null_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Struct__file_identifier +#define org_apache_arrow_flatbuf_Struct__file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Struct__file_identifier */ +#ifndef org_apache_arrow_flatbuf_Struct__identifier +#define org_apache_arrow_flatbuf_Struct__identifier 0 +#endif +#define org_apache_arrow_flatbuf_Struct__type_hash ((flatbuffers_thash_t)0x6310f362) +#define org_apache_arrow_flatbuf_Struct__type_identifier "\x62\xf3\x10\x63" +#ifndef org_apache_arrow_flatbuf_Struct__file_extension +#define org_apache_arrow_flatbuf_Struct__file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_List_file_identifier +#define org_apache_arrow_flatbuf_List_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_List_file_identifier */ +#ifndef org_apache_arrow_flatbuf_List_identifier +#define org_apache_arrow_flatbuf_List_identifier 0 +#endif +#define org_apache_arrow_flatbuf_List_type_hash ((flatbuffers_thash_t)0xd4ce5878) +#define org_apache_arrow_flatbuf_List_type_identifier "\x78\x58\xce\xd4" +#ifndef org_apache_arrow_flatbuf_List_file_extension +#define org_apache_arrow_flatbuf_List_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeList_file_identifier +#define org_apache_arrow_flatbuf_LargeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeList_identifier +#define org_apache_arrow_flatbuf_LargeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeList_type_hash ((flatbuffers_thash_t)0x38aa7e27) +#define org_apache_arrow_flatbuf_LargeList_type_identifier "\x27\x7e\xaa\x38" +#ifndef org_apache_arrow_flatbuf_LargeList_file_extension +#define org_apache_arrow_flatbuf_LargeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_ListView_file_identifier +#define org_apache_arrow_flatbuf_ListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_ListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_ListView_identifier +#define org_apache_arrow_flatbuf_ListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_ListView_type_hash ((flatbuffers_thash_t)0x23d37919) +#define org_apache_arrow_flatbuf_ListView_type_identifier "\x19\x79\xd3\x23" +#ifndef org_apache_arrow_flatbuf_ListView_file_extension +#define org_apache_arrow_flatbuf_ListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeListView_file_identifier +#define org_apache_arrow_flatbuf_LargeListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeListView_identifier +#define org_apache_arrow_flatbuf_LargeListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeListView_type_hash ((flatbuffers_thash_t)0x28efac02) +#define org_apache_arrow_flatbuf_LargeListView_type_identifier "\x02\xac\xef\x28" +#ifndef org_apache_arrow_flatbuf_LargeListView_file_extension +#define org_apache_arrow_flatbuf_LargeListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeList_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeList_type_hash ((flatbuffers_thash_t)0xcef245bb) +#define org_apache_arrow_flatbuf_FixedSizeList_type_identifier "\xbb\x45\xf2\xce" +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_extension +#define org_apache_arrow_flatbuf_FixedSizeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Map_file_identifier +#define org_apache_arrow_flatbuf_Map_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Map_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Map_identifier +#define org_apache_arrow_flatbuf_Map_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Map_type_hash ((flatbuffers_thash_t)0xcebef8e6) +#define org_apache_arrow_flatbuf_Map_type_identifier "\xe6\xf8\xbe\xce" +#ifndef org_apache_arrow_flatbuf_Map_file_extension +#define org_apache_arrow_flatbuf_Map_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Union_file_identifier +#define org_apache_arrow_flatbuf_Union_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Union_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Union_identifier +#define org_apache_arrow_flatbuf_Union_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Union_type_hash ((flatbuffers_thash_t)0x896bda57) +#define org_apache_arrow_flatbuf_Union_type_identifier "\x57\xda\x6b\x89" +#ifndef org_apache_arrow_flatbuf_Union_file_extension +#define org_apache_arrow_flatbuf_Union_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Int_file_identifier +#define org_apache_arrow_flatbuf_Int_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Int_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Int_identifier +#define org_apache_arrow_flatbuf_Int_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Int_type_hash ((flatbuffers_thash_t)0x30789001) +#define org_apache_arrow_flatbuf_Int_type_identifier "\x01\x90\x78\x30" +#ifndef org_apache_arrow_flatbuf_Int_file_extension +#define org_apache_arrow_flatbuf_Int_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FloatingPoint_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FloatingPoint_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FloatingPoint_type_hash ((flatbuffers_thash_t)0xf7d06268) +#define org_apache_arrow_flatbuf_FloatingPoint_type_identifier "\x68\x62\xd0\xf7" +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_extension +#define org_apache_arrow_flatbuf_FloatingPoint_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8_file_identifier +#define org_apache_arrow_flatbuf_Utf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8_identifier +#define org_apache_arrow_flatbuf_Utf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8_type_hash ((flatbuffers_thash_t)0x8fe60d37) +#define org_apache_arrow_flatbuf_Utf8_type_identifier "\x37\x0d\xe6\x8f" +#ifndef org_apache_arrow_flatbuf_Utf8_file_extension +#define org_apache_arrow_flatbuf_Utf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Binary_file_identifier +#define org_apache_arrow_flatbuf_Binary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Binary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Binary_identifier +#define org_apache_arrow_flatbuf_Binary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Binary_type_hash ((flatbuffers_thash_t)0x8e21a795) +#define org_apache_arrow_flatbuf_Binary_type_identifier "\x95\xa7\x21\x8e" +#ifndef org_apache_arrow_flatbuf_Binary_file_extension +#define org_apache_arrow_flatbuf_Binary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeUtf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeUtf8_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeUtf8_type_hash ((flatbuffers_thash_t)0x24ed2fb0) +#define org_apache_arrow_flatbuf_LargeUtf8_type_identifier "\xb0\x2f\xed\x24" +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_extension +#define org_apache_arrow_flatbuf_LargeUtf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_identifier +#define org_apache_arrow_flatbuf_LargeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeBinary_identifier +#define org_apache_arrow_flatbuf_LargeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeBinary_type_hash ((flatbuffers_thash_t)0xbd437872) +#define org_apache_arrow_flatbuf_LargeBinary_type_identifier "\x72\x78\x43\xbd" +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_extension +#define org_apache_arrow_flatbuf_LargeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8View_file_identifier +#define org_apache_arrow_flatbuf_Utf8View_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8View_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8View_identifier +#define org_apache_arrow_flatbuf_Utf8View_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8View_type_hash ((flatbuffers_thash_t)0xab7692) +#define org_apache_arrow_flatbuf_Utf8View_type_identifier "\x92\x76\xab\x00" +#ifndef org_apache_arrow_flatbuf_Utf8View_file_extension +#define org_apache_arrow_flatbuf_Utf8View_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BinaryView_file_identifier +#define org_apache_arrow_flatbuf_BinaryView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BinaryView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BinaryView_identifier +#define org_apache_arrow_flatbuf_BinaryView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BinaryView_type_hash ((flatbuffers_thash_t)0x18c52428) +#define org_apache_arrow_flatbuf_BinaryView_type_identifier "\x28\x24\xc5\x18" +#ifndef org_apache_arrow_flatbuf_BinaryView_file_extension +#define org_apache_arrow_flatbuf_BinaryView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_hash ((flatbuffers_thash_t)0x80d0f4ce) +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier "\xce\xf4\xd0\x80" +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_extension +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Bool_file_identifier +#define org_apache_arrow_flatbuf_Bool_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Bool_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Bool_identifier +#define org_apache_arrow_flatbuf_Bool_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Bool_type_hash ((flatbuffers_thash_t)0x96bf83f0) +#define org_apache_arrow_flatbuf_Bool_type_identifier "\xf0\x83\xbf\x96" +#ifndef org_apache_arrow_flatbuf_Bool_file_extension +#define org_apache_arrow_flatbuf_Bool_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RunEndEncoded_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RunEndEncoded_type_hash ((flatbuffers_thash_t)0x5a98bcc) +#define org_apache_arrow_flatbuf_RunEndEncoded_type_identifier "\xcc\x8b\xa9\x05" +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_extension +#define org_apache_arrow_flatbuf_RunEndEncoded_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Decimal_file_identifier +#define org_apache_arrow_flatbuf_Decimal_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Decimal_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Decimal_identifier +#define org_apache_arrow_flatbuf_Decimal_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Decimal_type_hash ((flatbuffers_thash_t)0x91d1beb7) +#define org_apache_arrow_flatbuf_Decimal_type_identifier "\xb7\xbe\xd1\x91" +#ifndef org_apache_arrow_flatbuf_Decimal_file_extension +#define org_apache_arrow_flatbuf_Decimal_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Date_file_identifier +#define org_apache_arrow_flatbuf_Date_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Date_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Date_identifier +#define org_apache_arrow_flatbuf_Date_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Date_type_hash ((flatbuffers_thash_t)0xe0ccf624) +#define org_apache_arrow_flatbuf_Date_type_identifier "\x24\xf6\xcc\xe0" +#ifndef org_apache_arrow_flatbuf_Date_file_extension +#define org_apache_arrow_flatbuf_Date_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Time_file_identifier +#define org_apache_arrow_flatbuf_Time_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Time_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Time_identifier +#define org_apache_arrow_flatbuf_Time_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Time_type_hash ((flatbuffers_thash_t)0x2442a489) +#define org_apache_arrow_flatbuf_Time_type_identifier "\x89\xa4\x42\x24" +#ifndef org_apache_arrow_flatbuf_Time_file_extension +#define org_apache_arrow_flatbuf_Time_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Timestamp_file_identifier +#define org_apache_arrow_flatbuf_Timestamp_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Timestamp_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Timestamp_identifier +#define org_apache_arrow_flatbuf_Timestamp_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Timestamp_type_hash ((flatbuffers_thash_t)0x1fddf080) +#define org_apache_arrow_flatbuf_Timestamp_type_identifier "\x80\xf0\xdd\x1f" +#ifndef org_apache_arrow_flatbuf_Timestamp_file_extension +#define org_apache_arrow_flatbuf_Timestamp_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Interval_file_identifier +#define org_apache_arrow_flatbuf_Interval_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Interval_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Interval_identifier +#define org_apache_arrow_flatbuf_Interval_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Interval_type_hash ((flatbuffers_thash_t)0x1e2d6809) +#define org_apache_arrow_flatbuf_Interval_type_identifier "\x09\x68\x2d\x1e" +#ifndef org_apache_arrow_flatbuf_Interval_file_extension +#define org_apache_arrow_flatbuf_Interval_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Duration_file_identifier +#define org_apache_arrow_flatbuf_Duration_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Duration_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Duration_identifier +#define org_apache_arrow_flatbuf_Duration_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Duration_type_hash ((flatbuffers_thash_t)0x1ecea6b0) +#define org_apache_arrow_flatbuf_Duration_type_identifier "\xb0\xa6\xce\x1e" +#ifndef org_apache_arrow_flatbuf_Duration_file_extension +#define org_apache_arrow_flatbuf_Duration_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_KeyValue_file_identifier +#define org_apache_arrow_flatbuf_KeyValue_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_KeyValue_file_identifier */ +#ifndef org_apache_arrow_flatbuf_KeyValue_identifier +#define org_apache_arrow_flatbuf_KeyValue_identifier 0 +#endif +#define org_apache_arrow_flatbuf_KeyValue_type_hash ((flatbuffers_thash_t)0x3b264744) +#define org_apache_arrow_flatbuf_KeyValue_type_identifier "\x44\x47\x26\x3b" +#ifndef org_apache_arrow_flatbuf_KeyValue_file_extension +#define org_apache_arrow_flatbuf_KeyValue_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_hash ((flatbuffers_thash_t)0x8c703261) +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier "\x61\x32\x70\x8c" +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_extension +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Field_file_identifier +#define org_apache_arrow_flatbuf_Field_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Field_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Field_identifier +#define org_apache_arrow_flatbuf_Field_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Field_type_hash ((flatbuffers_thash_t)0xd981525c) +#define org_apache_arrow_flatbuf_Field_type_identifier "\x5c\x52\x81\xd9" +#ifndef org_apache_arrow_flatbuf_Field_file_extension +#define org_apache_arrow_flatbuf_Field_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Buffer_file_identifier +#define org_apache_arrow_flatbuf_Buffer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Buffer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Buffer_identifier +#define org_apache_arrow_flatbuf_Buffer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Buffer_type_hash ((flatbuffers_thash_t)0x519d7fea) +#define org_apache_arrow_flatbuf_Buffer_type_identifier "\xea\x7f\x9d\x51" +#ifndef org_apache_arrow_flatbuf_Buffer_file_extension +#define org_apache_arrow_flatbuf_Buffer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Schema_file_identifier +#define org_apache_arrow_flatbuf_Schema_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Schema_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Schema_identifier +#define org_apache_arrow_flatbuf_Schema_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Schema_type_hash ((flatbuffers_thash_t)0x406570b) +#define org_apache_arrow_flatbuf_Schema_type_identifier "\x0b\x57\x06\x04" +#ifndef org_apache_arrow_flatbuf_Schema_file_extension +#define org_apache_arrow_flatbuf_Schema_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_MetadataVersion_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 16) +/** 0.1.0 (October 2016). */ +#define org_apache_arrow_flatbuf_MetadataVersion_V1 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_MetadataVersion_V2 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_MetadataVersion_V3 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_MetadataVersion_V4 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(3)) +#define org_apache_arrow_flatbuf_MetadataVersion_V5 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(4)) + +static inline const char *org_apache_arrow_flatbuf_MetadataVersion_name(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return "V1"; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return "V2"; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return "V3"; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return "V4"; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return "V5"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MetadataVersion_is_known_value(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return 1; + default: return 0; + } +} + +/** Represents Arrow Features that might not have full support + * within implementations. This is intended to be used in + * two scenarios: + * 1. A mechanism for readers of Arrow Streams + * and files to understand that the stream or file makes + * use of a feature that isn't supported or unknown to + * the implementation (and therefore can meet the Arrow + * forward compatibility guarantees). + * 2. A means of negotiating between a client and server + * what features a stream is allowed to use. The enums + * values here are intented to represent higher level + * features, additional details maybe negotiated + * with key-value pairs specific to the protocol. + * + * Enums added to this list should be assigned power-of-two values + * to facilitate exchanging and comparing bitmaps for supported + * features. */ +typedef int64_t org_apache_arrow_flatbuf_Feature_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, 64) +/** Needed to make flatbuffers happy. */ +#define org_apache_arrow_flatbuf_Feature_UNUSED ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(0)) +#define org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(1)) +#define org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Feature_name(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return "UNUSED"; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return "DICTIONARY_REPLACEMENT"; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return "COMPRESSED_BODY"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Feature_is_known_value(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return 1; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return 1; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_UnionMode_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 16) +#define org_apache_arrow_flatbuf_UnionMode_Sparse ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_UnionMode_Dense ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_UnionMode_name(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return "Sparse"; + case org_apache_arrow_flatbuf_UnionMode_Dense: return "Dense"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_UnionMode_is_known_value(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return 1; + case org_apache_arrow_flatbuf_UnionMode_Dense: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_Precision_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 16) +#define org_apache_arrow_flatbuf_Precision_HALF ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Precision_SINGLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_Precision_DOUBLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Precision_name(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return "HALF"; + case org_apache_arrow_flatbuf_Precision_SINGLE: return "SINGLE"; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return "DOUBLE"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Precision_is_known_value(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return 1; + case org_apache_arrow_flatbuf_Precision_SINGLE: return 1; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_DateUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_DateUnit_DAY ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_DateUnit_MILLISECOND ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_DateUnit_name(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return "DAY"; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return "MILLISECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DateUnit_is_known_value(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return 1; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_TimeUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_TimeUnit_SECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_TimeUnit_MILLISECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_TimeUnit_MICROSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_TimeUnit_NANOSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(3)) + +static inline const char *org_apache_arrow_flatbuf_TimeUnit_name(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return "SECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return "MILLISECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return "MICROSECOND"; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return "NANOSECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_TimeUnit_is_known_value(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_IntervalUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_IntervalUnit_name(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return "YEAR_MONTH"; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return "DAY_TIME"; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return "MONTH_DAY_NANO"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_IntervalUnit_is_known_value(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Dictionary encoding metadata + * Maintained for forwards compatibility, in the future + * Dictionaries might be explicit maps between integers and values + * allowing for non-contiguous index values */ +typedef int16_t org_apache_arrow_flatbuf_DictionaryKind_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 16) +#define org_apache_arrow_flatbuf_DictionaryKind_DenseArray ((org_apache_arrow_flatbuf_DictionaryKind_enum_t)INT16_C(0)) + +static inline const char *org_apache_arrow_flatbuf_DictionaryKind_name(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return "DenseArray"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DictionaryKind_is_known_value(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Endianness of the platform producing the data */ +typedef int16_t org_apache_arrow_flatbuf_Endianness_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 16) +#define org_apache_arrow_flatbuf_Endianness_Little ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Endianness_Big ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_Endianness_name(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return "Little"; + case org_apache_arrow_flatbuf_Endianness_Big: return "Big"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Endianness_is_known_value(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return 1; + case org_apache_arrow_flatbuf_Endianness_Big: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * A Buffer represents a single contiguous memory segment */ +struct org_apache_arrow_flatbuf_Buffer { + /** The relative offset into the shared memory page where the bytes for this + * buffer starts */ + alignas(8) int64_t offset; + /** The absolute length (in bytes) of the memory buffer. The memory is found + * from offset (inclusive) to offset + length (non-inclusive). When building + * messages using the encapsulated IPC message, padding bytes may be written + * after a buffer, but such padding bytes do not need to be accounted for in + * the size here. */ + alignas(8) int64_t length; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Buffer_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__const_ptr_add(const org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__ptr_add(org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_struct_t org_apache_arrow_flatbuf_Buffer_vec_at(org_apache_arrow_flatbuf_Buffer_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Buffer__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_Buffer_vec_len(org_apache_arrow_flatbuf_Buffer_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Buffer) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, length, flatbuffers_int64, int64_t) + + +/** These are stored in the flatbuffer in the Type union below */ +struct org_apache_arrow_flatbuf_Null_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Null_vec_len(org_apache_arrow_flatbuf_Null_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Null_table_t org_apache_arrow_flatbuf_Null_vec_at(org_apache_arrow_flatbuf_Null_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Null_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Null) + + +/** A Struct_ in the flatbuffer metadata is the same as an Arrow Struct + * (according to the physical memory layout). We used Struct_ here as + * Struct is a reserved word in Flatbuffers */ +struct org_apache_arrow_flatbuf_Struct__table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Struct__vec_len(org_apache_arrow_flatbuf_Struct__vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Struct__table_t org_apache_arrow_flatbuf_Struct__vec_at(org_apache_arrow_flatbuf_Struct__vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Struct__table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Struct_) + + +struct org_apache_arrow_flatbuf_List_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_List_vec_len(org_apache_arrow_flatbuf_List_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_List_table_t org_apache_arrow_flatbuf_List_vec_at(org_apache_arrow_flatbuf_List_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_List_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_List) + + +/** Same as List, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeList_vec_len(org_apache_arrow_flatbuf_LargeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeList_table_t org_apache_arrow_flatbuf_LargeList_vec_at(org_apache_arrow_flatbuf_LargeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeList) + + +/** Represents the same logical types that List can, but contains offsets and + * sizes allowing for writes in any order and sharing of child values among + * list values. */ +struct org_apache_arrow_flatbuf_ListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_ListView_vec_len(org_apache_arrow_flatbuf_ListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_ListView_table_t org_apache_arrow_flatbuf_ListView_vec_at(org_apache_arrow_flatbuf_ListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_ListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_ListView) + + +/** Same as ListView, but with 64-bit offsets and sizes, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeListView_vec_len(org_apache_arrow_flatbuf_LargeListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeListView_table_t org_apache_arrow_flatbuf_LargeListView_vec_at(org_apache_arrow_flatbuf_LargeListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeListView) + + +struct org_apache_arrow_flatbuf_FixedSizeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeList_vec_len(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeList_table_t org_apache_arrow_flatbuf_FixedSizeList_vec_at(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeList) + +/** Number of list items per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeList, listSize, flatbuffers_int32, int32_t, INT32_C(0)) + +/** A Map is a logical nested type that is represented as + * + * List> + * + * In this layout, the keys and values are each respectively contiguous. We do + * not constrain the key and value types, so the application is responsible + * for ensuring that the keys are hashable and unique. Whether the keys are sorted + * may be set in the metadata for this field. + * + * In a field with Map type, the field has a child Struct field, which then + * has two children: key type and the second the value type. The names of the + * child fields may be respectively "entries", "key", and "value", but this is + * not enforced. + * + * Map + * ```text + * - child[0] entries: Struct + * - child[0] key: K + * - child[1] value: V + * ``` + * Neither the "entries" field nor the "key" field may be nullable. + * + * The metadata is structured so that Arrow systems without special handling + * for Map can make Map an alias for List. The "layout" attribute for the Map + * field must have the same contents as a List. */ +struct org_apache_arrow_flatbuf_Map_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Map_vec_len(org_apache_arrow_flatbuf_Map_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Map_table_t org_apache_arrow_flatbuf_Map_vec_at(org_apache_arrow_flatbuf_Map_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Map_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Map) + +/** Set to true if the keys within each value are sorted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Map, keysSorted, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** A union is a complex type with children in Field + * By default ids in the type vector refer to the offsets in the children + * optionally typeIds provides an indirection between the child offset and the type id + * for each child `typeIds[offset]` is the id used in the type vector */ +struct org_apache_arrow_flatbuf_Union_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Union_vec_len(org_apache_arrow_flatbuf_Union_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Union_table_t org_apache_arrow_flatbuf_Union_vec_at(org_apache_arrow_flatbuf_Union_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Union_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Union) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Union, mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Union, typeIds, flatbuffers_int32_vec_t, 0) + +struct org_apache_arrow_flatbuf_Int_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Int_vec_len(org_apache_arrow_flatbuf_Int_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Int_table_t org_apache_arrow_flatbuf_Int_vec_at(org_apache_arrow_flatbuf_Int_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Int_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Int) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Int, bitWidth, flatbuffers_int32, int32_t, INT32_C(0)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Int, is_signed, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +struct org_apache_arrow_flatbuf_FloatingPoint_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FloatingPoint_vec_len(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FloatingPoint_table_t org_apache_arrow_flatbuf_FloatingPoint_vec_at(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FloatingPoint_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FloatingPoint) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FloatingPoint, precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, INT16_C(0)) + +/** Unicode with UTF-8 encoding */ +struct org_apache_arrow_flatbuf_Utf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8_vec_len(org_apache_arrow_flatbuf_Utf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8_table_t org_apache_arrow_flatbuf_Utf8_vec_at(org_apache_arrow_flatbuf_Utf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8) + + +/** Opaque binary data */ +struct org_apache_arrow_flatbuf_Binary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Binary_vec_len(org_apache_arrow_flatbuf_Binary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Binary_table_t org_apache_arrow_flatbuf_Binary_vec_at(org_apache_arrow_flatbuf_Binary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Binary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Binary) + + +/** Same as Utf8, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeUtf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeUtf8_vec_len(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeUtf8_table_t org_apache_arrow_flatbuf_LargeUtf8_vec_at(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeUtf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeUtf8) + + +/** Same as Binary, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeBinary_vec_len(org_apache_arrow_flatbuf_LargeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeBinary_table_t org_apache_arrow_flatbuf_LargeBinary_vec_at(org_apache_arrow_flatbuf_LargeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeBinary) + + +/** Logically the same as Utf8, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_Utf8View_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8View_vec_len(org_apache_arrow_flatbuf_Utf8View_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8View_table_t org_apache_arrow_flatbuf_Utf8View_vec_at(org_apache_arrow_flatbuf_Utf8View_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8View_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8View) + + +/** Logically the same as Binary, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_BinaryView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BinaryView_vec_len(org_apache_arrow_flatbuf_BinaryView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BinaryView_table_t org_apache_arrow_flatbuf_BinaryView_vec_at(org_apache_arrow_flatbuf_BinaryView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BinaryView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BinaryView) + + +struct org_apache_arrow_flatbuf_FixedSizeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_len(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeBinary_table_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeBinary) + +/** Number of bytes per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeBinary, byteWidth, flatbuffers_int32, int32_t, INT32_C(0)) + +struct org_apache_arrow_flatbuf_Bool_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Bool_vec_len(org_apache_arrow_flatbuf_Bool_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Bool_table_t org_apache_arrow_flatbuf_Bool_vec_at(org_apache_arrow_flatbuf_Bool_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Bool_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Bool) + + +/** Contains two child arrays, run_ends and values. + * The run_ends child array must be a 16/32/64-bit integer array + * which encodes the indices at which the run with the value in + * each corresponding index in the values child array ends. + * Like list/struct types, the value array can be of any type. */ +struct org_apache_arrow_flatbuf_RunEndEncoded_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RunEndEncoded_vec_len(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RunEndEncoded_table_t org_apache_arrow_flatbuf_RunEndEncoded_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RunEndEncoded) + + +/** Exact decimal value represented as an integer value in two's + * complement. Currently only 128-bit (16-byte) and 256-bit (32-byte) integers + * are used. The representation uses the endianness indicated + * in the Schema. */ +struct org_apache_arrow_flatbuf_Decimal_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Decimal_vec_len(org_apache_arrow_flatbuf_Decimal_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Decimal_table_t org_apache_arrow_flatbuf_Decimal_vec_at(org_apache_arrow_flatbuf_Decimal_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Decimal_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Decimal) + +/** Total number of decimal digits */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Decimal, precision, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of digits after the decimal point "." */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Decimal, scale, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of bits per value. The only accepted widths are 128 and 256. + * We use bitWidth for consistency with Int::bitWidth. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_Decimal, bitWidth, flatbuffers_int32, int32_t, INT32_C(128)) + +/** Date is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since UNIX epoch (1970-01-01), stored in either of two units: + * + * * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no + * leap seconds), where the values are evenly divisible by 86400000 + * * Days (32 bits) since the UNIX epoch */ +struct org_apache_arrow_flatbuf_Date_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Date_vec_len(org_apache_arrow_flatbuf_Date_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Date_table_t org_apache_arrow_flatbuf_Date_vec_at(org_apache_arrow_flatbuf_Date_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Date_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Date) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Date, unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, INT16_C(1)) + +/** Time is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since midnight, stored in either of four units: seconds, + * milliseconds, microseconds or nanoseconds. + * + * The integer `bitWidth` depends on the `unit` and must be one of the following: + * * SECOND and MILLISECOND: 32 bits + * * MICROSECOND and NANOSECOND: 64 bits + * + * The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds + * (exclusive), adjusted for the time unit (for example, up to 86400000 + * exclusive for the MILLISECOND unit). + * This definition doesn't allow for leap seconds. Time values from + * measurements with leap seconds will need to be corrected when ingesting + * into Arrow (for example by replacing the value 86400 with 86399). */ +struct org_apache_arrow_flatbuf_Time_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Time_vec_len(org_apache_arrow_flatbuf_Time_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Time_table_t org_apache_arrow_flatbuf_Time_vec_at(org_apache_arrow_flatbuf_Time_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Time_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Time) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Time, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Time, bitWidth, flatbuffers_int32, int32_t, INT32_C(32)) + +/** Timestamp is a 64-bit signed integer representing an elapsed time since a + * fixed epoch, stored in either of four units: seconds, milliseconds, + * microseconds or nanoseconds, and is optionally annotated with a timezone. + * + * Timestamp values do not include any leap seconds (in other words, all + * days are considered 86400 seconds long). + * + * Timestamps with a non-empty timezone + * ------------------------------------ + * + * If a Timestamp column has a non-empty timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone + * (the Unix epoch), regardless of the Timestamp's own timezone. + * + * Therefore, timestamp values with a non-empty timezone correspond to + * physical points in time together with some additional information about + * how the data was obtained and/or how to display it (the timezone). + * + * For example, the timestamp value 0 with the timezone string "Europe/Paris" + * corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the + * application may prefer to display it as "January 1st 1970, 01h00" in + * the Europe/Paris timezone (which is the same physical point in time). + * + * One consequence is that timestamp values with a non-empty timezone + * can be compared and ordered directly, since they all share the same + * well-known point of reference (the Unix epoch). + * + * Timestamps with an unset / empty timezone + * ----------------------------------------- + * + * If a Timestamp column has no timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. + * + * Therefore, timestamp values without a timezone cannot be meaningfully + * interpreted as physical points in time, but only as calendar / clock + * indications ("wall clock time") in an unspecified timezone. + * + * For example, the timestamp value 0 with an empty timezone string + * corresponds to "January 1st 1970, 00h00" in an unknown timezone: there + * is not enough information to interpret it as a well-defined physical + * point in time. + * + * One consequence is that timestamp values without a timezone cannot + * be reliably compared or ordered, since they may have different points of + * reference. In particular, it is *not* possible to interpret an unset + * or empty timezone as the same as "UTC". + * + * Conversion between timezones + * ---------------------------- + * + * If a Timestamp column has a non-empty timezone, changing the timezone + * to a different non-empty value is a metadata-only operation: + * the timestamp values need not change as their point of reference remains + * the same (the Unix epoch). + * + * However, if a Timestamp column has no timezone value, changing it to a + * non-empty value requires to think about the desired semantics. + * One possibility is to assume that the original timestamp values are + * relative to the epoch of the timezone being set; timestamp values should + * then adjusted to the Unix epoch (for example, changing the timezone from + * empty to "Europe/Paris" would require converting the timestamp values + * from "Europe/Paris" to "UTC", which seems counter-intuitive but is + * nevertheless correct). + * + * Guidelines for encoding data from external libraries + * ---------------------------------------------------- + * + * Date & time libraries often have multiple different data types for temporal + * data. In order to ease interoperability between different implementations the + * Arrow project has some recommendations for encoding these types into a Timestamp + * column. + * + * An "instant" represents a physical point in time that has no relevant timezone + * (for example, astronomical data). To encode an instant, use a Timestamp with + * the timezone string set to "UTC", and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * A "zoned date-time" represents a physical point in time annotated with an + * informative timezone (for example, the timezone in which the data was + * recorded). To encode a zoned date-time, use a Timestamp with the timezone + * string set to the name of the timezone, and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * (There is some ambiguity between an instant and a zoned date-time with the + * UTC timezone. Both of these are stored the same in Arrow. Typically, + * this distinction does not matter. If it does, then an application should + * use custom metadata or an extension type to distinguish between the two cases.) + * + * An "offset date-time" represents a physical point in time combined with an + * explicit offset from UTC. To encode an offset date-time, use a Timestamp + * with the timezone string set to the numeric timezone offset string + * (e.g. "+03:00"), and make sure the Timestamp values are relative to + * the UTC epoch (January 1st 1970, midnight). + * + * A "naive date-time" (also called "local date-time" in some libraries) + * represents a wall clock time combined with a calendar date, but with + * no indication of how to map this information to a physical point in time. + * Naive date-times must be handled with care because of this missing + * information, and also because daylight saving time (DST) may make + * some values ambiguous or nonexistent. A naive date-time may be + * stored as a struct with Date and Time fields. However, it may also be + * encoded into a Timestamp column with an empty timezone. The timestamp + * values should be computed "as if" the timezone of the date-time values + * was UTC; for example, the naive date-time "January 1st 1970, 00h00" would + * be encoded as timestamp value 0. */ +struct org_apache_arrow_flatbuf_Timestamp_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Timestamp_vec_len(org_apache_arrow_flatbuf_Timestamp_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Timestamp_table_t org_apache_arrow_flatbuf_Timestamp_vec_at(org_apache_arrow_flatbuf_Timestamp_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Timestamp_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Timestamp) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Timestamp, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(0)) +/** The timezone is an optional string indicating the name of a timezone, + * one of: + * + * * As used in the Olson timezone database (the "tz database" or + * "tzdata"), such as "America/New_York". + * * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + * such as "+07:30". + * + * Whether a timezone string is present indicates different semantics about + * the data (see above). */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_Timestamp, timezone, 0) + +struct org_apache_arrow_flatbuf_Interval_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Interval_vec_len(org_apache_arrow_flatbuf_Interval_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Interval_table_t org_apache_arrow_flatbuf_Interval_vec_at(org_apache_arrow_flatbuf_Interval_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Interval_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Interval) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Interval, unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, INT16_C(0)) + +struct org_apache_arrow_flatbuf_Duration_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Duration_vec_len(org_apache_arrow_flatbuf_Duration_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Duration_table_t org_apache_arrow_flatbuf_Duration_vec_at(org_apache_arrow_flatbuf_Duration_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Duration_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Duration) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Duration, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +/** ---------------------------------------------------------------------- + * Top-level Type value, enabling extensible type-specific metadata. We can + * add new logical types to Type without breaking backwards compatibility */ +typedef uint8_t org_apache_arrow_flatbuf_Type_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Type_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_Type) +/** ---------------------------------------------------------------------- + * user defined key value pairs to add custom metadata to arrow + * key namespacing is the responsibility of the user */ +#define org_apache_arrow_flatbuf_Type_NONE ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_Type_Null ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_Type_Int ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_Type_FloatingPoint ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_Type_Binary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_Type_Utf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(5)) +#define org_apache_arrow_flatbuf_Type_Bool ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(6)) +#define org_apache_arrow_flatbuf_Type_Decimal ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(7)) +#define org_apache_arrow_flatbuf_Type_Date ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(8)) +#define org_apache_arrow_flatbuf_Type_Time ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(9)) +#define org_apache_arrow_flatbuf_Type_Timestamp ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(10)) +#define org_apache_arrow_flatbuf_Type_Interval ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(11)) +#define org_apache_arrow_flatbuf_Type_List ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(12)) +#define org_apache_arrow_flatbuf_Type_Struct_ ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(13)) +#define org_apache_arrow_flatbuf_Type_Union ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(14)) +#define org_apache_arrow_flatbuf_Type_FixedSizeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(15)) +#define org_apache_arrow_flatbuf_Type_FixedSizeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(16)) +#define org_apache_arrow_flatbuf_Type_Map ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(17)) +#define org_apache_arrow_flatbuf_Type_Duration ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(18)) +#define org_apache_arrow_flatbuf_Type_LargeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(19)) +#define org_apache_arrow_flatbuf_Type_LargeUtf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(20)) +#define org_apache_arrow_flatbuf_Type_LargeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(21)) +#define org_apache_arrow_flatbuf_Type_RunEndEncoded ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(22)) +#define org_apache_arrow_flatbuf_Type_BinaryView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(23)) +#define org_apache_arrow_flatbuf_Type_Utf8View ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(24)) +#define org_apache_arrow_flatbuf_Type_ListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(25)) +#define org_apache_arrow_flatbuf_Type_LargeListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(26)) + +static inline const char *org_apache_arrow_flatbuf_Type_type_name(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return "NONE"; + case org_apache_arrow_flatbuf_Type_Null: return "Null"; + case org_apache_arrow_flatbuf_Type_Int: return "Int"; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return "FloatingPoint"; + case org_apache_arrow_flatbuf_Type_Binary: return "Binary"; + case org_apache_arrow_flatbuf_Type_Utf8: return "Utf8"; + case org_apache_arrow_flatbuf_Type_Bool: return "Bool"; + case org_apache_arrow_flatbuf_Type_Decimal: return "Decimal"; + case org_apache_arrow_flatbuf_Type_Date: return "Date"; + case org_apache_arrow_flatbuf_Type_Time: return "Time"; + case org_apache_arrow_flatbuf_Type_Timestamp: return "Timestamp"; + case org_apache_arrow_flatbuf_Type_Interval: return "Interval"; + case org_apache_arrow_flatbuf_Type_List: return "List"; + case org_apache_arrow_flatbuf_Type_Struct_: return "Struct_"; + case org_apache_arrow_flatbuf_Type_Union: return "Union"; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return "FixedSizeBinary"; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return "FixedSizeList"; + case org_apache_arrow_flatbuf_Type_Map: return "Map"; + case org_apache_arrow_flatbuf_Type_Duration: return "Duration"; + case org_apache_arrow_flatbuf_Type_LargeBinary: return "LargeBinary"; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return "LargeUtf8"; + case org_apache_arrow_flatbuf_Type_LargeList: return "LargeList"; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return "RunEndEncoded"; + case org_apache_arrow_flatbuf_Type_BinaryView: return "BinaryView"; + case org_apache_arrow_flatbuf_Type_Utf8View: return "Utf8View"; + case org_apache_arrow_flatbuf_Type_ListView: return "ListView"; + case org_apache_arrow_flatbuf_Type_LargeListView: return "LargeListView"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Type_is_known_type(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return 1; + case org_apache_arrow_flatbuf_Type_Null: return 1; + case org_apache_arrow_flatbuf_Type_Int: return 1; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return 1; + case org_apache_arrow_flatbuf_Type_Binary: return 1; + case org_apache_arrow_flatbuf_Type_Utf8: return 1; + case org_apache_arrow_flatbuf_Type_Bool: return 1; + case org_apache_arrow_flatbuf_Type_Decimal: return 1; + case org_apache_arrow_flatbuf_Type_Date: return 1; + case org_apache_arrow_flatbuf_Type_Time: return 1; + case org_apache_arrow_flatbuf_Type_Timestamp: return 1; + case org_apache_arrow_flatbuf_Type_Interval: return 1; + case org_apache_arrow_flatbuf_Type_List: return 1; + case org_apache_arrow_flatbuf_Type_Struct_: return 1; + case org_apache_arrow_flatbuf_Type_Union: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return 1; + case org_apache_arrow_flatbuf_Type_Map: return 1; + case org_apache_arrow_flatbuf_Type_Duration: return 1; + case org_apache_arrow_flatbuf_Type_LargeBinary: return 1; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return 1; + case org_apache_arrow_flatbuf_Type_LargeList: return 1; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return 1; + case org_apache_arrow_flatbuf_Type_BinaryView: return 1; + case org_apache_arrow_flatbuf_Type_Utf8View: return 1; + case org_apache_arrow_flatbuf_Type_ListView: return 1; + case org_apache_arrow_flatbuf_Type_LargeListView: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_KeyValue_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_KeyValue_vec_len(org_apache_arrow_flatbuf_KeyValue_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_KeyValue_table_t org_apache_arrow_flatbuf_KeyValue_vec_at(org_apache_arrow_flatbuf_KeyValue_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_KeyValue_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_KeyValue) + +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_KeyValue, key, 0) +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_KeyValue, value, 0) + +struct org_apache_arrow_flatbuf_DictionaryEncoding_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_len(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryEncoding_table_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryEncoding) + +/** The known dictionary id in the application where this data is used. In + * the file or streaming formats, the dictionary ids are found in the + * DictionaryBatch messages */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryEncoding, id, flatbuffers_int64, int64_t, INT64_C(0)) +/** The dictionary indices are constrained to be non-negative integers. If + * this field is null, the indices must be signed int32. To maximize + * cross-language compatibility and performance, implementations are + * recommended to prefer signed integer types over unsigned integer types + * and to avoid uint64 indices unless they are required by an application. */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryEncoding, indexType, org_apache_arrow_flatbuf_Int_table_t, 0) +/** By default, dictionaries are not ordered, or the order does not have + * semantic meaning. In some statistical, applications, dictionary-encoding + * is used to represent ordered categorical data, and we provide a way to + * preserve that metadata here */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryEncoding, isOrdered, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_DictionaryEncoding, dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, INT16_C(0)) + +/** ---------------------------------------------------------------------- + * A field represents a named column in a record / row batch or child of a + * nested type. */ +struct org_apache_arrow_flatbuf_Field_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Field_vec_len(org_apache_arrow_flatbuf_Field_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Field_table_t org_apache_arrow_flatbuf_Field_vec_at(org_apache_arrow_flatbuf_Field_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Field_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Field) + +/** Name is not required, in i.e. a List */ +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_Field, name, 0) +/** Whether or not this field can contain nulls. Should be true in general. */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Field, nullable, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** This is the type of the decoded value if the field is dictionary encoded. */ +__flatbuffers_define_union_field(flatbuffers_, 3, org_apache_arrow_flatbuf_Field, type, org_apache_arrow_flatbuf_Type, 0) +/** Present only if the field is dictionary encoded. */ +__flatbuffers_define_table_field(4, org_apache_arrow_flatbuf_Field, dictionary, org_apache_arrow_flatbuf_DictionaryEncoding_table_t, 0) +/** children apply only to nested data types like Struct, List and Union. For + * primitive types children will have length 0. */ +__flatbuffers_define_vector_field(5, org_apache_arrow_flatbuf_Field, children, org_apache_arrow_flatbuf_Field_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(6, org_apache_arrow_flatbuf_Field, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + +/** ---------------------------------------------------------------------- + * A Schema describes the columns in a row batch */ +struct org_apache_arrow_flatbuf_Schema_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Schema_vec_len(org_apache_arrow_flatbuf_Schema_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Schema_table_t org_apache_arrow_flatbuf_Schema_vec_at(org_apache_arrow_flatbuf_Schema_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Schema_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Schema) + +/** endianness of the buffer + * it is Little Endian by default + * if endianness doesn't match the underlying system then the vectors need to be converted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Schema, endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Schema, fields, org_apache_arrow_flatbuf_Field_vec_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Schema, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) +/** Features used in the stream/file. */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Schema, features, org_apache_arrow_flatbuf_Feature_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_READER_H */ +#ifndef SCHEMA_BUILDER_H +#define SCHEMA_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_MetadataVersion_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0 +#define __org_apache_arrow_flatbuf_MetadataVersion_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t) +#define __org_apache_arrow_flatbuf_Feature_formal_args , org_apache_arrow_flatbuf_Feature_enum_t v0 +#define __org_apache_arrow_flatbuf_Feature_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t) +#define __org_apache_arrow_flatbuf_UnionMode_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0 +#define __org_apache_arrow_flatbuf_UnionMode_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t) +#define __org_apache_arrow_flatbuf_Precision_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_Precision_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t) +#define __org_apache_arrow_flatbuf_DateUnit_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_DateUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t) +#define __org_apache_arrow_flatbuf_TimeUnit_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_TimeUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t) +#define __org_apache_arrow_flatbuf_IntervalUnit_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_IntervalUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t) +#define __org_apache_arrow_flatbuf_DictionaryKind_formal_args , org_apache_arrow_flatbuf_DictionaryKind_enum_t v0 +#define __org_apache_arrow_flatbuf_DictionaryKind_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t) +#define __org_apache_arrow_flatbuf_Endianness_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0 +#define __org_apache_arrow_flatbuf_Endianness_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t) + +#define __org_apache_arrow_flatbuf_Buffer_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_Buffer_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ p->offset = v0; p->length = v1; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ p->offset = p2->offset; p->length = p2->length; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int64_assign_to_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_to_pe(&p->length, &p2->length); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int64_assign_from_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_from_pe(&p->length, &p2->length); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Buffer_file_identifier, org_apache_arrow_flatbuf_Buffer_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_Type_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_Type_union_vec_ref_t; +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Null_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Null_ref_t; +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Null, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Struct__required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Struct__ref_t; +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Struct_, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_List_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_List_ref_t; +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_List, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeList_ref_t; +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeList, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_ListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_ListView_ref_t; +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_ListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeListView_ref_t; +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeList_ref_t; +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Map_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Map_ref_t; +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Map, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Union_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Union_ref_t; +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Union, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Int_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Int_ref_t; +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Int, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FloatingPoint_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FloatingPoint_ref_t; +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8_ref_t; +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Binary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Binary_ref_t; +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Binary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeUtf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeUtf8_ref_t; +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeBinary_ref_t; +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8View_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8View_ref_t; +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BinaryView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BinaryView_ref_t; +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_ref_t; +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Bool_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Bool_ref_t; +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Bool, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RunEndEncoded_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RunEndEncoded_ref_t; +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Decimal_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Decimal_ref_t; +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Decimal, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Date_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Date_ref_t; +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Date, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Time_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Time_ref_t; +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Time, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Timestamp_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Timestamp_ref_t; +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Interval_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Interval_ref_t; +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Interval, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Duration_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Duration_ref_t; +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Duration, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_KeyValue_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_KeyValue_ref_t; +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryEncoding_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_ref_t; +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Field_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Field_ref_t; +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Field, 7) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Schema_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Schema_ref_t; +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Schema, 4) + +#define __org_apache_arrow_flatbuf_Null_formal_args +#define __org_apache_arrow_flatbuf_Null_call_args +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Null, org_apache_arrow_flatbuf_Null_file_identifier, org_apache_arrow_flatbuf_Null_type_identifier) + +#define __org_apache_arrow_flatbuf_Struct__formal_args +#define __org_apache_arrow_flatbuf_Struct__call_args +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Struct_, org_apache_arrow_flatbuf_Struct__file_identifier, org_apache_arrow_flatbuf_Struct__type_identifier) + +#define __org_apache_arrow_flatbuf_List_formal_args +#define __org_apache_arrow_flatbuf_List_call_args +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_List, org_apache_arrow_flatbuf_List_file_identifier, org_apache_arrow_flatbuf_List_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeList_formal_args +#define __org_apache_arrow_flatbuf_LargeList_call_args +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeList, org_apache_arrow_flatbuf_LargeList_file_identifier, org_apache_arrow_flatbuf_LargeList_type_identifier) + +#define __org_apache_arrow_flatbuf_ListView_formal_args +#define __org_apache_arrow_flatbuf_ListView_call_args +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_ListView, org_apache_arrow_flatbuf_ListView_file_identifier, org_apache_arrow_flatbuf_ListView_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeListView_formal_args +#define __org_apache_arrow_flatbuf_LargeListView_call_args +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, org_apache_arrow_flatbuf_LargeListView_file_identifier, org_apache_arrow_flatbuf_LargeListView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeList_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeList_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList_file_identifier, org_apache_arrow_flatbuf_FixedSizeList_type_identifier) + +#define __org_apache_arrow_flatbuf_Map_formal_args , flatbuffers_bool_t v0 +#define __org_apache_arrow_flatbuf_Map_call_args , v0 +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Map, org_apache_arrow_flatbuf_Map_file_identifier, org_apache_arrow_flatbuf_Map_type_identifier) + +#define __org_apache_arrow_flatbuf_Union_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0, flatbuffers_int32_vec_ref_t v1 +#define __org_apache_arrow_flatbuf_Union_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Union, org_apache_arrow_flatbuf_Union_file_identifier, org_apache_arrow_flatbuf_Union_type_identifier) + +#define __org_apache_arrow_flatbuf_Int_formal_args , int32_t v0, flatbuffers_bool_t v1 +#define __org_apache_arrow_flatbuf_Int_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_Int_file_identifier, org_apache_arrow_flatbuf_Int_type_identifier) + +#define __org_apache_arrow_flatbuf_FloatingPoint_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_FloatingPoint_call_args , v0 +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint_file_identifier, org_apache_arrow_flatbuf_FloatingPoint_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8_formal_args +#define __org_apache_arrow_flatbuf_Utf8_call_args +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8, org_apache_arrow_flatbuf_Utf8_file_identifier, org_apache_arrow_flatbuf_Utf8_type_identifier) + +#define __org_apache_arrow_flatbuf_Binary_formal_args +#define __org_apache_arrow_flatbuf_Binary_call_args +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Binary, org_apache_arrow_flatbuf_Binary_file_identifier, org_apache_arrow_flatbuf_Binary_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeUtf8_formal_args +#define __org_apache_arrow_flatbuf_LargeUtf8_call_args +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8_file_identifier, org_apache_arrow_flatbuf_LargeUtf8_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeBinary_formal_args +#define __org_apache_arrow_flatbuf_LargeBinary_call_args +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, org_apache_arrow_flatbuf_LargeBinary_file_identifier, org_apache_arrow_flatbuf_LargeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8View_formal_args +#define __org_apache_arrow_flatbuf_Utf8View_call_args +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, org_apache_arrow_flatbuf_Utf8View_file_identifier, org_apache_arrow_flatbuf_Utf8View_type_identifier) + +#define __org_apache_arrow_flatbuf_BinaryView_formal_args +#define __org_apache_arrow_flatbuf_BinaryView_call_args +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, org_apache_arrow_flatbuf_BinaryView_file_identifier, org_apache_arrow_flatbuf_BinaryView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeBinary_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Bool_formal_args +#define __org_apache_arrow_flatbuf_Bool_call_args +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Bool, org_apache_arrow_flatbuf_Bool_file_identifier, org_apache_arrow_flatbuf_Bool_type_identifier) + +#define __org_apache_arrow_flatbuf_RunEndEncoded_formal_args +#define __org_apache_arrow_flatbuf_RunEndEncoded_call_args +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded_file_identifier, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier) + +#define __org_apache_arrow_flatbuf_Decimal_formal_args , int32_t v0, int32_t v1, int32_t v2 +#define __org_apache_arrow_flatbuf_Decimal_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Decimal, org_apache_arrow_flatbuf_Decimal_file_identifier, org_apache_arrow_flatbuf_Decimal_type_identifier) + +#define __org_apache_arrow_flatbuf_Date_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Date_call_args , v0 +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Date, org_apache_arrow_flatbuf_Date_file_identifier, org_apache_arrow_flatbuf_Date_type_identifier) + +#define __org_apache_arrow_flatbuf_Time_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, int32_t v1 +#define __org_apache_arrow_flatbuf_Time_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Time, org_apache_arrow_flatbuf_Time_file_identifier, org_apache_arrow_flatbuf_Time_type_identifier) + +#define __org_apache_arrow_flatbuf_Timestamp_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_Timestamp_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, org_apache_arrow_flatbuf_Timestamp_file_identifier, org_apache_arrow_flatbuf_Timestamp_type_identifier) + +#define __org_apache_arrow_flatbuf_Interval_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Interval_call_args , v0 +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Interval, org_apache_arrow_flatbuf_Interval_file_identifier, org_apache_arrow_flatbuf_Interval_type_identifier) + +#define __org_apache_arrow_flatbuf_Duration_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Duration_call_args , v0 +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Duration, org_apache_arrow_flatbuf_Duration_file_identifier, org_apache_arrow_flatbuf_Duration_type_identifier) + +#define __org_apache_arrow_flatbuf_KeyValue_formal_args , flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_KeyValue_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_KeyValue_file_identifier, org_apache_arrow_flatbuf_KeyValue_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args , int64_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, flatbuffers_bool_t v2, org_apache_arrow_flatbuf_DictionaryKind_enum_t v3 +#define __org_apache_arrow_flatbuf_DictionaryEncoding_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier) + +#define __org_apache_arrow_flatbuf_Field_formal_args ,\ + flatbuffers_string_ref_t v0, flatbuffers_bool_t v1, org_apache_arrow_flatbuf_Type_union_ref_t v3, org_apache_arrow_flatbuf_DictionaryEncoding_ref_t v4, org_apache_arrow_flatbuf_Field_vec_ref_t v5, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v6 +#define __org_apache_arrow_flatbuf_Field_call_args ,\ + v0, v1, v3, v4, v5, v6 +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field_file_identifier, org_apache_arrow_flatbuf_Field_type_identifier) + +#define __org_apache_arrow_flatbuf_Schema_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0, org_apache_arrow_flatbuf_Field_vec_ref_t v1, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v2, org_apache_arrow_flatbuf_Feature_vec_ref_t v3 +#define __org_apache_arrow_flatbuf_Schema_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Schema_file_identifier, org_apache_arrow_flatbuf_Schema_type_identifier) + +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_NONE(void) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Null; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Int; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FloatingPoint; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Binary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Bool; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Decimal; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Date; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Time; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Timestamp; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Interval; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_List; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Struct_; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Union; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Map; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Duration; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeUtf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_RunEndEncoded; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_BinaryView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8View; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_ListView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeListView; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_Type) + +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_clone(B, (org_apache_arrow_flatbuf_Null_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_clone(B, (org_apache_arrow_flatbuf_Int_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_clone(B, (org_apache_arrow_flatbuf_FloatingPoint_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_clone(B, (org_apache_arrow_flatbuf_Binary_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_clone(B, (org_apache_arrow_flatbuf_Utf8_table_t)u.value)); + case 6: return org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_clone(B, (org_apache_arrow_flatbuf_Bool_table_t)u.value)); + case 7: return org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_clone(B, (org_apache_arrow_flatbuf_Decimal_table_t)u.value)); + case 8: return org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_clone(B, (org_apache_arrow_flatbuf_Date_table_t)u.value)); + case 9: return org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_clone(B, (org_apache_arrow_flatbuf_Time_table_t)u.value)); + case 10: return org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_clone(B, (org_apache_arrow_flatbuf_Timestamp_table_t)u.value)); + case 11: return org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_clone(B, (org_apache_arrow_flatbuf_Interval_table_t)u.value)); + case 12: return org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_clone(B, (org_apache_arrow_flatbuf_List_table_t)u.value)); + case 13: return org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__clone(B, (org_apache_arrow_flatbuf_Struct__table_t)u.value)); + case 14: return org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_clone(B, (org_apache_arrow_flatbuf_Union_table_t)u.value)); + case 15: return org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_clone(B, (org_apache_arrow_flatbuf_FixedSizeBinary_table_t)u.value)); + case 16: return org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_clone(B, (org_apache_arrow_flatbuf_FixedSizeList_table_t)u.value)); + case 17: return org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_clone(B, (org_apache_arrow_flatbuf_Map_table_t)u.value)); + case 18: return org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_clone(B, (org_apache_arrow_flatbuf_Duration_table_t)u.value)); + case 19: return org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_clone(B, (org_apache_arrow_flatbuf_LargeBinary_table_t)u.value)); + case 20: return org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_clone(B, (org_apache_arrow_flatbuf_LargeUtf8_table_t)u.value)); + case 21: return org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_clone(B, (org_apache_arrow_flatbuf_LargeList_table_t)u.value)); + case 22: return org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_clone(B, (org_apache_arrow_flatbuf_RunEndEncoded_table_t)u.value)); + case 23: return org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_clone(B, (org_apache_arrow_flatbuf_BinaryView_table_t)u.value)); + case 24: return org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_clone(B, (org_apache_arrow_flatbuf_Utf8View_table_t)u.value)); + case 25: return org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_clone(B, (org_apache_arrow_flatbuf_ListView_table_t)u.value)); + case 26: return org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_clone(B, (org_apache_arrow_flatbuf_LargeListView_table_t)u.value)); + default: return org_apache_arrow_flatbuf_Type_as_NONE(); + } +} + + +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args) +{ + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Null_end(B); +} + +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Null_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args) +{ + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Struct__end(B); +} + +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Struct__end(B)); +} + + +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args) +{ + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_List_end(B); +} + +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_List_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeList_end(B); +} + +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeList_end(B)); +} + + +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args) +{ + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_ListView_end(B); +} + +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_ListView_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeListView_end(B); +} + +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeListView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList_listSize, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeList) + +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeList_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeList_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Map_keysSorted, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Map) + +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args) +{ + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Map_end(B); +} + +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Map_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Union_mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Union) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Union_typeIds, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_Union) + +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args) +{ + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_add(B, v1) + || org_apache_arrow_flatbuf_Union_mode_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Union_end(B); +} + +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_pick(B, t) + || org_apache_arrow_flatbuf_Union_mode_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Union_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Int_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Int) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Int_is_signed, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Int) + +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args) +{ + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_add(B, v0) + || org_apache_arrow_flatbuf_Int_is_signed_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_Int_end(B); +} + +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Int_is_signed_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Int_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint_precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_FloatingPoint) + +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args) +{ + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FloatingPoint_end(B); +} + +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FloatingPoint_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8_end(B); +} + +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args) +{ + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Binary_end(B); +} + +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Binary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeUtf8_end(B); +} + +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeUtf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeBinary_end(B); +} + +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8View_end(B); +} + +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8View_end(B)); +} + + +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args) +{ + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_BinaryView_end(B); +} + +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BinaryView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeBinary) + +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeBinary_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args) +{ + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Bool_end(B); +} + +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Bool_end(B)); +} + + +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args) +{ + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_RunEndEncoded_end(B); +} + +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RunEndEncoded_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Decimal_precision, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Decimal_scale, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_Decimal_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(128), org_apache_arrow_flatbuf_Decimal) + +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args) +{ + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_add(B, v0) + || org_apache_arrow_flatbuf_Decimal_scale_add(B, v1) + || org_apache_arrow_flatbuf_Decimal_bitWidth_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_Decimal_end(B); +} + +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_scale_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_bitWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Decimal_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Date_unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Date) + +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args) +{ + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Date_end(B); +} + +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Date_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Time_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Time) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Time_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(32), org_apache_arrow_flatbuf_Time) + +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args) +{ + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_add(B, v1) + || org_apache_arrow_flatbuf_Time_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Time_end(B); +} + +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Time_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Time_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_timezone, org_apache_arrow_flatbuf_Timestamp) + +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args) +{ + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_add(B, v1) + || org_apache_arrow_flatbuf_Timestamp_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Timestamp_end(B); +} + +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_pick(B, t) + || org_apache_arrow_flatbuf_Timestamp_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Timestamp_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Interval_unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Interval) + +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args) +{ + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Interval_end(B); +} + +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Interval_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Duration_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Duration) + +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args) +{ + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Duration_end(B); +} + +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Duration_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_key, org_apache_arrow_flatbuf_KeyValue) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_value, org_apache_arrow_flatbuf_KeyValue) + +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args) +{ + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_add(B, v0) + || org_apache_arrow_flatbuf_KeyValue_value_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_KeyValue_end(B); +} + +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_pick(B, t) + || org_apache_arrow_flatbuf_KeyValue_value_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_KeyValue_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_indexType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) + +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_add(B, v3) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryEncoding_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryEncoding_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_Field_name, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Field_nullable, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_field(3, flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_field(4, flatbuffers_, org_apache_arrow_flatbuf_Field_dictionary, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(5, flatbuffers_, org_apache_arrow_flatbuf_Field_children, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(6, flatbuffers_, org_apache_arrow_flatbuf_Field_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Field) + +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args) +{ + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_add(B, v0) + || org_apache_arrow_flatbuf_Field_type_add_value(B, v3) + || org_apache_arrow_flatbuf_Field_dictionary_add(B, v4) + || org_apache_arrow_flatbuf_Field_children_add(B, v5) + || org_apache_arrow_flatbuf_Field_custom_metadata_add(B, v6) + || org_apache_arrow_flatbuf_Field_nullable_add(B, v1) + || org_apache_arrow_flatbuf_Field_type_add_type(B, v3.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Field_end(B); +} + +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_pick(B, t) + || org_apache_arrow_flatbuf_Field_type_pick(B, t) + || org_apache_arrow_flatbuf_Field_dictionary_pick(B, t) + || org_apache_arrow_flatbuf_Field_children_pick(B, t) + || org_apache_arrow_flatbuf_Field_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Field_nullable_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Field_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Schema_endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Schema_fields, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Schema_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Schema_features, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, org_apache_arrow_flatbuf_Schema) + +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args) +{ + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_add(B, v1) + || org_apache_arrow_flatbuf_Schema_custom_metadata_add(B, v2) + || org_apache_arrow_flatbuf_Schema_features_add(B, v3) + || org_apache_arrow_flatbuf_Schema_endianness_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Schema_end(B); +} + +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_pick(B, t) + || org_apache_arrow_flatbuf_Schema_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Schema_features_pick(B, t) + || org_apache_arrow_flatbuf_Schema_endianness_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Schema_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_BUILDER_H */ +#ifndef SCHEMA_VERIFIER_H +#define SCHEMA_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_Type_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Null_verify_table); /* Null */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Int_verify_table); /* Int */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FloatingPoint_verify_table); /* FloatingPoint */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Binary_verify_table); /* Binary */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8_verify_table); /* Utf8 */ + case 6: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Bool_verify_table); /* Bool */ + case 7: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Decimal_verify_table); /* Decimal */ + case 8: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Date_verify_table); /* Date */ + case 9: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Time_verify_table); /* Time */ + case 10: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Timestamp_verify_table); /* Timestamp */ + case 11: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Interval_verify_table); /* Interval */ + case 12: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_List_verify_table); /* List */ + case 13: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Struct__verify_table); /* Struct_ */ + case 14: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Union_verify_table); /* Union */ + case 15: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); /* FixedSizeBinary */ + case 16: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeList_verify_table); /* FixedSizeList */ + case 17: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Map_verify_table); /* Map */ + case 18: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Duration_verify_table); /* Duration */ + case 19: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeBinary_verify_table); /* LargeBinary */ + case 20: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeUtf8_verify_table); /* LargeUtf8 */ + case 21: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeList_verify_table); /* LargeList */ + case 22: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RunEndEncoded_verify_table); /* RunEndEncoded */ + case 23: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_BinaryView_verify_table); /* BinaryView */ + case 24: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8View_verify_table); /* Utf8View */ + case 25: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_ListView_verify_table); /* ListView */ + case 26: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeListView_verify_table); /* LargeListView */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* listSize */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* keysSorted */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* mode */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 4, 4, INT64_C(1073741823)) /* typeIds */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* bitWidth */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* is_signed */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* precision */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* byteWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* precision */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* scale */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* timezone */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* value */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Int_verify_table) /* indexType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isOrdered */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 2, 2) /* dictionaryKind */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* name */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* nullable */)) return ret; + if ((ret = flatcc_verify_union_field(td, 3, 0, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_field(td, 4, 0, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table) /* dictionary */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 5, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* children */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 6, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* endianness */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 1, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* fields */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* features */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_VERIFIER_H */ +#ifndef TENSOR_READER_H +#define TENSOR_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_table_t; +typedef struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_table_t; +typedef struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_TensorDim_file_identifier +#define org_apache_arrow_flatbuf_TensorDim_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_TensorDim_file_identifier */ +#ifndef org_apache_arrow_flatbuf_TensorDim_identifier +#define org_apache_arrow_flatbuf_TensorDim_identifier 0 +#endif +#define org_apache_arrow_flatbuf_TensorDim_type_hash ((flatbuffers_thash_t)0xbc6d7b25) +#define org_apache_arrow_flatbuf_TensorDim_type_identifier "\x25\x7b\x6d\xbc" +#ifndef org_apache_arrow_flatbuf_TensorDim_file_extension +#define org_apache_arrow_flatbuf_TensorDim_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Tensor_file_identifier +#define org_apache_arrow_flatbuf_Tensor_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Tensor_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Tensor_identifier +#define org_apache_arrow_flatbuf_Tensor_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Tensor_type_hash ((flatbuffers_thash_t)0x1764df19) +#define org_apache_arrow_flatbuf_Tensor_type_identifier "\x19\xdf\x64\x17" +#ifndef org_apache_arrow_flatbuf_Tensor_file_extension +#define org_apache_arrow_flatbuf_Tensor_file_extension "bin" +#endif + + + +/** ---------------------------------------------------------------------- + * Data structures for dense tensors + * Shape data for a single axis in a tensor */ +struct org_apache_arrow_flatbuf_TensorDim_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_TensorDim_vec_len(org_apache_arrow_flatbuf_TensorDim_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_TensorDim_table_t org_apache_arrow_flatbuf_TensorDim_vec_at(org_apache_arrow_flatbuf_TensorDim_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_TensorDim_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_TensorDim) + +/** Length of dimension */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_TensorDim, size, flatbuffers_int64, int64_t, INT64_C(0)) +/** Name of the dimension, optional */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_TensorDim, name, 0) + +struct org_apache_arrow_flatbuf_Tensor_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Tensor_vec_len(org_apache_arrow_flatbuf_Tensor_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Tensor_table_t org_apache_arrow_flatbuf_Tensor_vec_at(org_apache_arrow_flatbuf_Tensor_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Tensor_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Tensor) + +/** The type of data contained in a value cell. Currently only fixed-width + * value types are supported, no strings or nested types */ +__flatbuffers_define_union_field(flatbuffers_, 1, org_apache_arrow_flatbuf_Tensor, type, org_apache_arrow_flatbuf_Type, 1) +/** The dimensions of the tensor, optionally named */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Tensor, shape, org_apache_arrow_flatbuf_TensorDim_vec_t, 1) +/** Non-negative byte offsets to advance one value cell along each dimension + * If omitted, default to row-major order (C-like). */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Tensor, strides, flatbuffers_int64_vec_t, 0) +/** The location and size of the tensor's data */ +__flatbuffers_define_struct_field(4, org_apache_arrow_flatbuf_Tensor, data, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_READER_H */ +#ifndef TENSOR_BUILDER_H +#define TENSOR_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef SCHEMA_BUILDER_H +#include "Schema_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_TensorDim_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_TensorDim_ref_t; +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Tensor_required[] = { 1, 2, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Tensor_ref_t; +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Tensor, 5) + +#define __org_apache_arrow_flatbuf_TensorDim_formal_args , int64_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_TensorDim_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_TensorDim_file_identifier, org_apache_arrow_flatbuf_TensorDim_type_identifier) + +#define __org_apache_arrow_flatbuf_Tensor_formal_args , org_apache_arrow_flatbuf_Type_union_ref_t v1, org_apache_arrow_flatbuf_TensorDim_vec_ref_t v2, flatbuffers_int64_vec_ref_t v3, org_apache_arrow_flatbuf_Buffer_t *v4 +#define __org_apache_arrow_flatbuf_Tensor_call_args , v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Tensor, org_apache_arrow_flatbuf_Tensor_file_identifier, org_apache_arrow_flatbuf_Tensor_type_identifier) + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_size, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_TensorDim) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_name, org_apache_arrow_flatbuf_TensorDim) + +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args) +{ + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_add(B, v0) + || org_apache_arrow_flatbuf_TensorDim_name_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_TensorDim_end(B); +} + +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_pick(B, t) + || org_apache_arrow_flatbuf_TensorDim_name_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_TensorDim_end(B)); +} + +__flatbuffers_build_union_field(1, flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Tensor_shape, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Tensor_strides, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_struct_field(4, flatbuffers_, org_apache_arrow_flatbuf_Tensor_data, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Tensor) + +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args) +{ + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_add(B, v4) + || org_apache_arrow_flatbuf_Tensor_type_add_value(B, v1) + || org_apache_arrow_flatbuf_Tensor_shape_add(B, v2) + || org_apache_arrow_flatbuf_Tensor_strides_add(B, v3) + || org_apache_arrow_flatbuf_Tensor_type_add_type(B, v1.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Tensor_end(B); +} + +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_type_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_shape_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_strides_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Tensor_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_BUILDER_H */ +#ifndef TENSOR_VERIFIER_H +#define TENSOR_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef SCHEMA_VERIFIER_H +#include "Schema_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* size */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* name */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_union_field(td, 1, 1, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 1, &org_apache_arrow_flatbuf_TensorDim_verify_table) /* shape */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* strides */)) return ret; + if ((ret = flatcc_verify_field(td, 4, 16, 8) /* data */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_VERIFIER_H */ +#ifndef SPARSETENSOR_READER_H +#define SPARSETENSOR_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table *org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table *org_apache_arrow_flatbuf_SparseTensorIndexCOO_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCOO_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t; +typedef struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseMatrixIndexCSX_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table *org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table *org_apache_arrow_flatbuf_SparseTensorIndexCSF_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensorIndexCSF_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_SparseTensor_table *org_apache_arrow_flatbuf_SparseTensor_table_t; +typedef struct org_apache_arrow_flatbuf_SparseTensor_table *org_apache_arrow_flatbuf_SparseTensor_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensor_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_SparseTensor_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_hash ((flatbuffers_thash_t)0x3b31385a) +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier "\x5a\x38\x31\x3b" +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_extension +#define org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_hash ((flatbuffers_thash_t)0xec57ea87) +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier "\x87\xea\x57\xec" +#ifndef org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_extension +#define org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_hash ((flatbuffers_thash_t)0xf44edda9) +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier "\xa9\xdd\x4e\xf4" +#ifndef org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_extension +#define org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_SparseTensor_file_identifier +#define org_apache_arrow_flatbuf_SparseTensor_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_SparseTensor_file_identifier */ +#ifndef org_apache_arrow_flatbuf_SparseTensor_identifier +#define org_apache_arrow_flatbuf_SparseTensor_identifier 0 +#endif +#define org_apache_arrow_flatbuf_SparseTensor_type_hash ((flatbuffers_thash_t)0xae6f7239) +#define org_apache_arrow_flatbuf_SparseTensor_type_identifier "\x39\x72\x6f\xae" +#ifndef org_apache_arrow_flatbuf_SparseTensor_file_extension +#define org_apache_arrow_flatbuf_SparseTensor_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, 16) +#define org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row ((org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column ((org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_name(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row: return "Row"; + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column: return "Column"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_is_known_value(org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Row: return 1; + case org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_Column: return 1; + default: return 0; + } +} + + + +/** ---------------------------------------------------------------------- + * EXPERIMENTAL: Data structures for sparse tensors + * Coordinate (COO) format of sparse tensor index. + * + * COO's index list are represented as a NxM matrix, + * where N is the number of non-zero values, + * and M is the number of dimensions of a sparse tensor. + * + * indicesBuffer stores the location and size of the data of this indices + * matrix. The value type and the stride of the indices matrix is + * specified in indicesType and indicesStrides fields. + * + * For example, let X be a 2x3x4x5 tensor, and it has the following + * 6 non-zero values: + * ```text + * X[0, 1, 2, 0] := 1 + * X[1, 1, 2, 3] := 2 + * X[0, 2, 1, 0] := 3 + * X[0, 1, 3, 0] := 4 + * X[0, 1, 2, 1] := 5 + * X[1, 2, 0, 4] := 6 + * ``` + * In COO format, the index matrix of X is the following 4x6 matrix: + * ```text + * [[0, 0, 0, 0, 1, 1], + * [1, 1, 1, 2, 1, 2], + * [2, 2, 3, 1, 2, 0], + * [0, 1, 0, 0, 3, 4]] + * ``` + * When isCanonical is true, the indices is sorted in lexicographical order + * (row-major order), and it does not have duplicated entries. Otherwise, + * the indices may not be sorted, or may have duplicated entries. */ +struct org_apache_arrow_flatbuf_SparseTensorIndexCOO_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_len(org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCOO_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensorIndexCOO) + +/** The type of values in indicesBuffer */ +__flatbuffers_define_table_field(0, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** Non-negative byte offsets to advance one value cell along each dimension + * If omitted, default to row-major order (C-like). */ +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesStrides, flatbuffers_int64_vec_t, 0) +/** The location and size of the indices matrix's data */ +__flatbuffers_define_struct_field(2, org_apache_arrow_flatbuf_SparseTensorIndexCOO, indicesBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) +/** This flag is true if and only if the indices matrix is sorted in + * row-major order, and does not have duplicated entries. + * This sort order is the same as of Tensorflow's SparseTensor, + * but it is inverse order of SciPy's canonical coo_matrix + * (SciPy employs column-major order for its coo_matrix). */ +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_SparseTensorIndexCOO, isCanonical, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** Compressed Sparse format, that is matrix-specific. */ +struct org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_len(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_at(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseMatrixIndexCSX) + +/** Which axis, row or column, is compressed */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, compressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, INT16_C(0)) +/** The type of values in indptrBuffer */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indptrType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indptrBuffer stores the location and size of indptr array that + * represents the range of the rows. + * The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. + * The length of this array is 1 + (the number of rows), and the type + * of index value is long. + * + * For example, let X be the following 6x4 matrix: + * ```text + * X := [[0, 1, 2, 0], + * [0, 0, 3, 0], + * [0, 4, 0, 5], + * [0, 0, 0, 0], + * [6, 0, 7, 8], + * [0, 9, 0, 0]]. + * ``` + * The array of non-zero values in X is: + * ```text + * values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. + * ``` + * And the indptr of X is: + * ```text + * indptr(X) = [0, 2, 3, 5, 5, 8, 10]. + * ``` */ +__flatbuffers_define_struct_field(2, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indptrBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) +/** The type of values in indicesBuffer */ +__flatbuffers_define_table_field(3, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indicesBuffer stores the location and size of the array that + * contains the column indices of the corresponding non-zero values. + * The type of index value is long. + * + * For example, the indices of the above X is: + * ```text + * indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. + * ``` + * Note that the indices are sorted in lexicographical order for each row. */ +__flatbuffers_define_struct_field(4, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, indicesBuffer, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + +/** Compressed Sparse Fiber (CSF) sparse tensor index. */ +struct org_apache_arrow_flatbuf_SparseTensorIndexCSF_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_len(org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCSF_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensorIndexCSF) + +/** CSF is a generalization of compressed sparse row (CSR) index. + * See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) + * + * CSF index recursively compresses each dimension of a tensor into a set + * of prefix trees. Each path from a root to leaf forms one tensor + * non-zero index. CSF is implemented with two arrays of buffers and one + * arrays of integers. + * + * For example, let X be a 2x3x4x5 tensor and let it have the following + * 8 non-zero values: + * ```text + * X[0, 0, 0, 1] := 1 + * X[0, 0, 0, 2] := 2 + * X[0, 1, 0, 0] := 3 + * X[0, 1, 0, 2] := 4 + * X[0, 1, 1, 0] := 5 + * X[1, 1, 1, 0] := 6 + * X[1, 1, 1, 1] := 7 + * X[1, 1, 1, 2] := 8 + * ``` + * As a prefix tree this would be represented as: + * ```text + * 0 1 + * / \ | + * 0 1 1 + * / / \ | + * 0 0 1 1 + * /| /| | /| | + * 1 2 0 2 0 0 1 2 + * ``` + * The type of values in indptrBuffers */ +__flatbuffers_define_table_field(0, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indptrType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indptrBuffers stores the sparsity structure. + * Each two consecutive dimensions in a tensor correspond to a buffer in + * indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` + * and `indptrBuffers[dim][i + 1]` signify a range of nodes in + * `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. + * + * For example, the indptrBuffers for the above X is: + * ```text + * indptrBuffer(X) = [ + * [0, 2, 3], + * [0, 1, 3, 4], + * [0, 2, 4, 5, 8] + * ]. + * ``` */ +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indptrBuffers, org_apache_arrow_flatbuf_Buffer_vec_t, 1) +/** The type of values in indicesBuffers */ +__flatbuffers_define_table_field(2, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indicesType, org_apache_arrow_flatbuf_Int_table_t, 1) +/** indicesBuffers stores values of nodes. + * Each tensor dimension corresponds to a buffer in indicesBuffers. + * For example, the indicesBuffers for the above X is: + * ```text + * indicesBuffer(X) = [ + * [0, 1], + * [0, 1, 1], + * [0, 0, 1, 1], + * [1, 2, 0, 2, 0, 0, 1, 2] + * ]. + * ``` */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_SparseTensorIndexCSF, indicesBuffers, org_apache_arrow_flatbuf_Buffer_vec_t, 1) +/** axisOrder stores the sequence in which dimensions were traversed to + * produce the prefix tree. + * For example, the axisOrder for the above X is: + * ```text + * axisOrder(X) = [0, 1, 2, 3]. + * ``` */ +__flatbuffers_define_vector_field(4, org_apache_arrow_flatbuf_SparseTensorIndexCSF, axisOrder, flatbuffers_int32_vec_t, 1) +typedef uint8_t org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_SparseTensorIndex, org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndex) +#define org_apache_arrow_flatbuf_SparseTensorIndex_NONE ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF ((org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t)UINT8_C(3)) + +static inline const char *org_apache_arrow_flatbuf_SparseTensorIndex_type_name(org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_SparseTensorIndex_NONE: return "NONE"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO: return "SparseTensorIndexCOO"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX: return "SparseMatrixIndexCSX"; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF: return "SparseTensorIndexCSF"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndex_is_known_type(org_apache_arrow_flatbuf_SparseTensorIndex_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_SparseTensorIndex_NONE: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX: return 1; + case org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_SparseTensor_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_SparseTensor_vec_len(org_apache_arrow_flatbuf_SparseTensor_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_SparseTensor_table_t org_apache_arrow_flatbuf_SparseTensor_vec_at(org_apache_arrow_flatbuf_SparseTensor_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_SparseTensor_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_SparseTensor) + +/** The type of data contained in a value cell. + * Currently only fixed-width value types are supported, + * no strings or nested types. */ +__flatbuffers_define_union_field(flatbuffers_, 1, org_apache_arrow_flatbuf_SparseTensor, type, org_apache_arrow_flatbuf_Type, 1) +/** The dimensions of the tensor, optionally named. */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_SparseTensor, shape, org_apache_arrow_flatbuf_TensorDim_vec_t, 1) +/** The number of non-zero values in a sparse tensor. */ +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_SparseTensor, non_zero_length, flatbuffers_int64, int64_t, INT64_C(0)) +/** Sparse tensor index */ +__flatbuffers_define_union_field(flatbuffers_, 5, org_apache_arrow_flatbuf_SparseTensor, sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, 1) +/** The location and size of the tensor's data */ +__flatbuffers_define_struct_field(6, org_apache_arrow_flatbuf_SparseTensor, data, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_READER_H */ +#ifndef SPARSETENSOR_BUILDER_H +#define SPARSETENSOR_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SPARSETENSOR_READER_H +#include "SparseTensor_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef TENSOR_BUILDER_H +#include "Tensor_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_formal_args , org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t v0 +#define __org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_union_vec_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndex_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensorIndexCOO_required[] = { 0, 2, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_required[] = { 1, 2, 3, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t; +static org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, 5) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensorIndexCSF_required[] = { 0, 1, 2, 3, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t; +static org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF, 5) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_SparseTensor_required[] = { 1, 2, 5, 6, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_SparseTensor_ref_t; +static org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensor_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor, 7) + +#define __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args , org_apache_arrow_flatbuf_Int_ref_t v0, flatbuffers_int64_vec_ref_t v1, org_apache_arrow_flatbuf_Buffer_t *v2, flatbuffers_bool_t v3 +#define __org_apache_arrow_flatbuf_SparseTensorIndexCOO_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO, org_apache_arrow_flatbuf_SparseTensorIndexCOO_file_identifier, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args ,\ + org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, org_apache_arrow_flatbuf_Buffer_t *v2, org_apache_arrow_flatbuf_Int_ref_t v3, org_apache_arrow_flatbuf_Buffer_t *v4 +#define __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_file_identifier, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args ,\ + org_apache_arrow_flatbuf_Int_ref_t v0, org_apache_arrow_flatbuf_Buffer_vec_ref_t v1, org_apache_arrow_flatbuf_Int_ref_t v2, org_apache_arrow_flatbuf_Buffer_vec_ref_t v3, flatbuffers_int32_vec_ref_t v4 +#define __org_apache_arrow_flatbuf_SparseTensorIndexCSF_call_args ,\ + v0, v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF, org_apache_arrow_flatbuf_SparseTensorIndexCSF_file_identifier, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier) + +#define __org_apache_arrow_flatbuf_SparseTensor_formal_args ,\ + org_apache_arrow_flatbuf_Type_union_ref_t v1, org_apache_arrow_flatbuf_TensorDim_vec_ref_t v2, int64_t v3, org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t v5, org_apache_arrow_flatbuf_Buffer_t *v6 +#define __org_apache_arrow_flatbuf_SparseTensor_call_args ,\ + v1, v2, v3, v5, v6 +static inline org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensor_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor, org_apache_arrow_flatbuf_SparseTensor_file_identifier, org_apache_arrow_flatbuf_SparseTensor_type_identifier) + +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_NONE(void) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCOO(org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCOO; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseMatrixIndexCSX(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseMatrixIndexCSX; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCSF(org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t ref) +{ org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_SparseTensorIndex_SparseTensorIndexCSF; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndex) + +static org_apache_arrow_flatbuf_SparseTensorIndex_union_ref_t org_apache_arrow_flatbuf_SparseTensorIndex_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndex_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCOO(org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(B, (org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseMatrixIndexCSX(org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(B, (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_SparseTensorIndex_as_SparseTensorIndexCSF(org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(B, (org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t)u.value)); + default: return org_apache_arrow_flatbuf_SparseTensorIndex_as_NONE(); + } +} + +__flatbuffers_build_table_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_struct_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_SparseTensorIndexCOO) + +static inline org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCOO_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensorIndexCOO_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType_add(B, v0) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides_add(B, v1) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical_add(B, v3)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensorIndexCOO_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensorIndexCOO_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCOO_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCOO_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensorIndexCOO_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_indicesStrides_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCOO_isCanonical_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensorIndexCOO_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis, org_apache_arrow_flatbuf_SparseMatrixCompressedAxis_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_struct_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_table_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_struct_field(4, flatbuffers_, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) + +static inline org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseMatrixIndexCSX_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_start(B) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer_add(B, v2) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer_add(B, v4) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType_add(B, v1) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType_add(B, v3) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseMatrixIndexCSX_end(B); +} + +static org_apache_arrow_flatbuf_SparseMatrixIndexCSX_ref_t org_apache_arrow_flatbuf_SparseMatrixIndexCSX_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseMatrixIndexCSX_start(B) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesBuffer_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indptrType_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseMatrixIndexCSX_compressedAxis_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_end(B)); +} + +__flatbuffers_build_table_field(0, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_table_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_vector_field(4, flatbuffers_, org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_SparseTensorIndexCSF) + +static inline org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensorIndexCSF_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensorIndexCSF_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType_add(B, v0) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers_add(B, v1) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers_add(B, v3) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder_add(B, v4)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensorIndexCSF_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensorIndexCSF_ref_t org_apache_arrow_flatbuf_SparseTensorIndexCSF_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensorIndexCSF_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensorIndexCSF_start(B) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indptrBuffers_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesType_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_indicesBuffers_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensorIndexCSF_axisOrder_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensorIndexCSF_end(B)); +} + +__flatbuffers_build_union_field(1, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_shape, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_non_zero_length, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_field(5, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, org_apache_arrow_flatbuf_SparseTensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseTensorIndexCOO, org_apache_arrow_flatbuf_SparseTensorIndexCOO) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseMatrixIndexCSX, org_apache_arrow_flatbuf_SparseMatrixIndexCSX) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_sparseIndex, org_apache_arrow_flatbuf_SparseTensorIndex, SparseTensorIndexCSF, org_apache_arrow_flatbuf_SparseTensorIndexCSF) +__flatbuffers_build_struct_field(6, flatbuffers_, org_apache_arrow_flatbuf_SparseTensor_data, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_SparseTensor) + +static inline org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_SparseTensor_formal_args) +{ + if (org_apache_arrow_flatbuf_SparseTensor_start(B) + || org_apache_arrow_flatbuf_SparseTensor_non_zero_length_add(B, v3) + || org_apache_arrow_flatbuf_SparseTensor_data_add(B, v6) + || org_apache_arrow_flatbuf_SparseTensor_type_add_value(B, v1) + || org_apache_arrow_flatbuf_SparseTensor_shape_add(B, v2) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_add_value(B, v5) + || org_apache_arrow_flatbuf_SparseTensor_type_add_type(B, v1.type) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_add_type(B, v5.type)) { + return 0; + } + return org_apache_arrow_flatbuf_SparseTensor_end(B); +} + +static org_apache_arrow_flatbuf_SparseTensor_ref_t org_apache_arrow_flatbuf_SparseTensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_SparseTensor_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_SparseTensor_start(B) + || org_apache_arrow_flatbuf_SparseTensor_non_zero_length_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_data_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_type_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_shape_pick(B, t) + || org_apache_arrow_flatbuf_SparseTensor_sparseIndex_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_SparseTensor_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_BUILDER_H */ +#ifndef SPARSETENSOR_VERIFIER_H +#define SPARSETENSOR_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SPARSETENSOR_READER_H +#include "SparseTensor_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef TENSOR_VERIFIER_H +#include "Tensor_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_SparseTensor_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_SparseTensorIndex_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); /* SparseTensorIndexCOO */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); /* SparseMatrixIndexCSX */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); /* SparseTensorIndexCSF */ + default: return flatcc_verify_ok; + } +} + +static int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_table_field(td, 0, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 8, 8, INT64_C(536870911)) /* indicesStrides */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 16, 8) /* indicesBuffer */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 1, 1) /* isCanonical */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCOO_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCOO_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* compressedAxis */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indptrType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 16, 8) /* indptrBuffer */)) return ret; + if ((ret = flatcc_verify_table_field(td, 3, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_field(td, 4, 16, 8) /* indicesBuffer */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseMatrixIndexCSX_type_identifier, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseMatrixIndexCSX_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_table_field(td, 0, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indptrType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 1, 16, 8, INT64_C(268435455)) /* indptrBuffers */)) return ret; + if ((ret = flatcc_verify_table_field(td, 2, 1, &org_apache_arrow_flatbuf_Int_verify_table) /* indicesType */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 1, 16, 8, INT64_C(268435455)) /* indicesBuffers */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 4, 1, 4, 4, INT64_C(1073741823)) /* axisOrder */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensorIndexCSF_type_identifier, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensorIndexCSF_verify_table); +} + +static int org_apache_arrow_flatbuf_SparseTensor_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_union_field(td, 1, 1, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 1, &org_apache_arrow_flatbuf_TensorDim_verify_table) /* shape */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 8, 8) /* non_zero_length */)) return ret; + if ((ret = flatcc_verify_union_field(td, 5, 1, &org_apache_arrow_flatbuf_SparseTensorIndex_union_verifier) /* sparseIndex */)) return ret; + if ((ret = flatcc_verify_field(td, 6, 16, 8) /* data */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_type_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_SparseTensor_type_identifier, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_SparseTensor_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_SparseTensor_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SPARSETENSOR_VERIFIER_H */ +#ifndef SCHEMA_READER_H +#define SCHEMA_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +typedef struct org_apache_arrow_flatbuf_Buffer org_apache_arrow_flatbuf_Buffer_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_struct_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_struct_t; +typedef const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_vec_t; +typedef org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_mutable_vec_t; + +typedef const struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_table_t; +typedef struct org_apache_arrow_flatbuf_Null_table *org_apache_arrow_flatbuf_Null_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Null_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__table_t; +typedef struct org_apache_arrow_flatbuf_Struct__table *org_apache_arrow_flatbuf_Struct__mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Struct__mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_table_t; +typedef struct org_apache_arrow_flatbuf_List_table *org_apache_arrow_flatbuf_List_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_List_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_table_t; +typedef struct org_apache_arrow_flatbuf_LargeList_table *org_apache_arrow_flatbuf_LargeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_table_t; +typedef struct org_apache_arrow_flatbuf_ListView_table *org_apache_arrow_flatbuf_ListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_ListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_table_t; +typedef struct org_apache_arrow_flatbuf_LargeListView_table *org_apache_arrow_flatbuf_LargeListView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeListView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeList_table *org_apache_arrow_flatbuf_FixedSizeList_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeList_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_table_t; +typedef struct org_apache_arrow_flatbuf_Map_table *org_apache_arrow_flatbuf_Map_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Map_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_table_t; +typedef struct org_apache_arrow_flatbuf_Union_table *org_apache_arrow_flatbuf_Union_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Union_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_table_t; +typedef struct org_apache_arrow_flatbuf_Int_table *org_apache_arrow_flatbuf_Int_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Int_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_table_t; +typedef struct org_apache_arrow_flatbuf_FloatingPoint_table *org_apache_arrow_flatbuf_FloatingPoint_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FloatingPoint_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8_table *org_apache_arrow_flatbuf_Utf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_table_t; +typedef struct org_apache_arrow_flatbuf_Binary_table *org_apache_arrow_flatbuf_Binary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Binary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_table_t; +typedef struct org_apache_arrow_flatbuf_LargeUtf8_table *org_apache_arrow_flatbuf_LargeUtf8_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeUtf8_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_LargeBinary_table *org_apache_arrow_flatbuf_LargeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_LargeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_table_t; +typedef struct org_apache_arrow_flatbuf_Utf8View_table *org_apache_arrow_flatbuf_Utf8View_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Utf8View_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_table_t; +typedef struct org_apache_arrow_flatbuf_BinaryView_table *org_apache_arrow_flatbuf_BinaryView_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_BinaryView_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_table_t; +typedef struct org_apache_arrow_flatbuf_FixedSizeBinary_table *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_FixedSizeBinary_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_table_t; +typedef struct org_apache_arrow_flatbuf_Bool_table *org_apache_arrow_flatbuf_Bool_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Bool_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_table_t; +typedef struct org_apache_arrow_flatbuf_RunEndEncoded_table *org_apache_arrow_flatbuf_RunEndEncoded_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_RunEndEncoded_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_table_t; +typedef struct org_apache_arrow_flatbuf_Decimal_table *org_apache_arrow_flatbuf_Decimal_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Decimal_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_table_t; +typedef struct org_apache_arrow_flatbuf_Date_table *org_apache_arrow_flatbuf_Date_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Date_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_table_t; +typedef struct org_apache_arrow_flatbuf_Time_table *org_apache_arrow_flatbuf_Time_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Time_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_table_t; +typedef struct org_apache_arrow_flatbuf_Timestamp_table *org_apache_arrow_flatbuf_Timestamp_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Timestamp_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_table_t; +typedef struct org_apache_arrow_flatbuf_Interval_table *org_apache_arrow_flatbuf_Interval_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Interval_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_table_t; +typedef struct org_apache_arrow_flatbuf_Duration_table *org_apache_arrow_flatbuf_Duration_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Duration_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_table_t; +typedef struct org_apache_arrow_flatbuf_KeyValue_table *org_apache_arrow_flatbuf_KeyValue_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_KeyValue_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_table_t; +typedef struct org_apache_arrow_flatbuf_DictionaryEncoding_table *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_DictionaryEncoding_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_table_t; +typedef struct org_apache_arrow_flatbuf_Field_table *org_apache_arrow_flatbuf_Field_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Field_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_table_t; +typedef struct org_apache_arrow_flatbuf_Schema_table *org_apache_arrow_flatbuf_Schema_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Schema_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_Null_file_identifier +#define org_apache_arrow_flatbuf_Null_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Null_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Null_identifier +#define org_apache_arrow_flatbuf_Null_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Null_type_hash ((flatbuffers_thash_t)0x7b36a4dd) +#define org_apache_arrow_flatbuf_Null_type_identifier "\xdd\xa4\x36\x7b" +#ifndef org_apache_arrow_flatbuf_Null_file_extension +#define org_apache_arrow_flatbuf_Null_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Struct__file_identifier +#define org_apache_arrow_flatbuf_Struct__file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Struct__file_identifier */ +#ifndef org_apache_arrow_flatbuf_Struct__identifier +#define org_apache_arrow_flatbuf_Struct__identifier 0 +#endif +#define org_apache_arrow_flatbuf_Struct__type_hash ((flatbuffers_thash_t)0x6310f362) +#define org_apache_arrow_flatbuf_Struct__type_identifier "\x62\xf3\x10\x63" +#ifndef org_apache_arrow_flatbuf_Struct__file_extension +#define org_apache_arrow_flatbuf_Struct__file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_List_file_identifier +#define org_apache_arrow_flatbuf_List_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_List_file_identifier */ +#ifndef org_apache_arrow_flatbuf_List_identifier +#define org_apache_arrow_flatbuf_List_identifier 0 +#endif +#define org_apache_arrow_flatbuf_List_type_hash ((flatbuffers_thash_t)0xd4ce5878) +#define org_apache_arrow_flatbuf_List_type_identifier "\x78\x58\xce\xd4" +#ifndef org_apache_arrow_flatbuf_List_file_extension +#define org_apache_arrow_flatbuf_List_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeList_file_identifier +#define org_apache_arrow_flatbuf_LargeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeList_identifier +#define org_apache_arrow_flatbuf_LargeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeList_type_hash ((flatbuffers_thash_t)0x38aa7e27) +#define org_apache_arrow_flatbuf_LargeList_type_identifier "\x27\x7e\xaa\x38" +#ifndef org_apache_arrow_flatbuf_LargeList_file_extension +#define org_apache_arrow_flatbuf_LargeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_ListView_file_identifier +#define org_apache_arrow_flatbuf_ListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_ListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_ListView_identifier +#define org_apache_arrow_flatbuf_ListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_ListView_type_hash ((flatbuffers_thash_t)0x23d37919) +#define org_apache_arrow_flatbuf_ListView_type_identifier "\x19\x79\xd3\x23" +#ifndef org_apache_arrow_flatbuf_ListView_file_extension +#define org_apache_arrow_flatbuf_ListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeListView_file_identifier +#define org_apache_arrow_flatbuf_LargeListView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeListView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeListView_identifier +#define org_apache_arrow_flatbuf_LargeListView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeListView_type_hash ((flatbuffers_thash_t)0x28efac02) +#define org_apache_arrow_flatbuf_LargeListView_type_identifier "\x02\xac\xef\x28" +#ifndef org_apache_arrow_flatbuf_LargeListView_file_extension +#define org_apache_arrow_flatbuf_LargeListView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeList_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeList_identifier +#define org_apache_arrow_flatbuf_FixedSizeList_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeList_type_hash ((flatbuffers_thash_t)0xcef245bb) +#define org_apache_arrow_flatbuf_FixedSizeList_type_identifier "\xbb\x45\xf2\xce" +#ifndef org_apache_arrow_flatbuf_FixedSizeList_file_extension +#define org_apache_arrow_flatbuf_FixedSizeList_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Map_file_identifier +#define org_apache_arrow_flatbuf_Map_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Map_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Map_identifier +#define org_apache_arrow_flatbuf_Map_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Map_type_hash ((flatbuffers_thash_t)0xcebef8e6) +#define org_apache_arrow_flatbuf_Map_type_identifier "\xe6\xf8\xbe\xce" +#ifndef org_apache_arrow_flatbuf_Map_file_extension +#define org_apache_arrow_flatbuf_Map_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Union_file_identifier +#define org_apache_arrow_flatbuf_Union_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Union_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Union_identifier +#define org_apache_arrow_flatbuf_Union_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Union_type_hash ((flatbuffers_thash_t)0x896bda57) +#define org_apache_arrow_flatbuf_Union_type_identifier "\x57\xda\x6b\x89" +#ifndef org_apache_arrow_flatbuf_Union_file_extension +#define org_apache_arrow_flatbuf_Union_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Int_file_identifier +#define org_apache_arrow_flatbuf_Int_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Int_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Int_identifier +#define org_apache_arrow_flatbuf_Int_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Int_type_hash ((flatbuffers_thash_t)0x30789001) +#define org_apache_arrow_flatbuf_Int_type_identifier "\x01\x90\x78\x30" +#ifndef org_apache_arrow_flatbuf_Int_file_extension +#define org_apache_arrow_flatbuf_Int_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FloatingPoint_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FloatingPoint_identifier +#define org_apache_arrow_flatbuf_FloatingPoint_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FloatingPoint_type_hash ((flatbuffers_thash_t)0xf7d06268) +#define org_apache_arrow_flatbuf_FloatingPoint_type_identifier "\x68\x62\xd0\xf7" +#ifndef org_apache_arrow_flatbuf_FloatingPoint_file_extension +#define org_apache_arrow_flatbuf_FloatingPoint_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8_file_identifier +#define org_apache_arrow_flatbuf_Utf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8_identifier +#define org_apache_arrow_flatbuf_Utf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8_type_hash ((flatbuffers_thash_t)0x8fe60d37) +#define org_apache_arrow_flatbuf_Utf8_type_identifier "\x37\x0d\xe6\x8f" +#ifndef org_apache_arrow_flatbuf_Utf8_file_extension +#define org_apache_arrow_flatbuf_Utf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Binary_file_identifier +#define org_apache_arrow_flatbuf_Binary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Binary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Binary_identifier +#define org_apache_arrow_flatbuf_Binary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Binary_type_hash ((flatbuffers_thash_t)0x8e21a795) +#define org_apache_arrow_flatbuf_Binary_type_identifier "\x95\xa7\x21\x8e" +#ifndef org_apache_arrow_flatbuf_Binary_file_extension +#define org_apache_arrow_flatbuf_Binary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeUtf8_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeUtf8_identifier +#define org_apache_arrow_flatbuf_LargeUtf8_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeUtf8_type_hash ((flatbuffers_thash_t)0x24ed2fb0) +#define org_apache_arrow_flatbuf_LargeUtf8_type_identifier "\xb0\x2f\xed\x24" +#ifndef org_apache_arrow_flatbuf_LargeUtf8_file_extension +#define org_apache_arrow_flatbuf_LargeUtf8_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_identifier +#define org_apache_arrow_flatbuf_LargeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_LargeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_LargeBinary_identifier +#define org_apache_arrow_flatbuf_LargeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_LargeBinary_type_hash ((flatbuffers_thash_t)0xbd437872) +#define org_apache_arrow_flatbuf_LargeBinary_type_identifier "\x72\x78\x43\xbd" +#ifndef org_apache_arrow_flatbuf_LargeBinary_file_extension +#define org_apache_arrow_flatbuf_LargeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Utf8View_file_identifier +#define org_apache_arrow_flatbuf_Utf8View_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Utf8View_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Utf8View_identifier +#define org_apache_arrow_flatbuf_Utf8View_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Utf8View_type_hash ((flatbuffers_thash_t)0xab7692) +#define org_apache_arrow_flatbuf_Utf8View_type_identifier "\x92\x76\xab\x00" +#ifndef org_apache_arrow_flatbuf_Utf8View_file_extension +#define org_apache_arrow_flatbuf_Utf8View_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_BinaryView_file_identifier +#define org_apache_arrow_flatbuf_BinaryView_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_BinaryView_file_identifier */ +#ifndef org_apache_arrow_flatbuf_BinaryView_identifier +#define org_apache_arrow_flatbuf_BinaryView_identifier 0 +#endif +#define org_apache_arrow_flatbuf_BinaryView_type_hash ((flatbuffers_thash_t)0x18c52428) +#define org_apache_arrow_flatbuf_BinaryView_type_identifier "\x28\x24\xc5\x18" +#ifndef org_apache_arrow_flatbuf_BinaryView_file_extension +#define org_apache_arrow_flatbuf_BinaryView_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier */ +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_identifier +#define org_apache_arrow_flatbuf_FixedSizeBinary_identifier 0 +#endif +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_hash ((flatbuffers_thash_t)0x80d0f4ce) +#define org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier "\xce\xf4\xd0\x80" +#ifndef org_apache_arrow_flatbuf_FixedSizeBinary_file_extension +#define org_apache_arrow_flatbuf_FixedSizeBinary_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Bool_file_identifier +#define org_apache_arrow_flatbuf_Bool_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Bool_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Bool_identifier +#define org_apache_arrow_flatbuf_Bool_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Bool_type_hash ((flatbuffers_thash_t)0x96bf83f0) +#define org_apache_arrow_flatbuf_Bool_type_identifier "\xf0\x83\xbf\x96" +#ifndef org_apache_arrow_flatbuf_Bool_file_extension +#define org_apache_arrow_flatbuf_Bool_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_RunEndEncoded_file_identifier */ +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_identifier +#define org_apache_arrow_flatbuf_RunEndEncoded_identifier 0 +#endif +#define org_apache_arrow_flatbuf_RunEndEncoded_type_hash ((flatbuffers_thash_t)0x5a98bcc) +#define org_apache_arrow_flatbuf_RunEndEncoded_type_identifier "\xcc\x8b\xa9\x05" +#ifndef org_apache_arrow_flatbuf_RunEndEncoded_file_extension +#define org_apache_arrow_flatbuf_RunEndEncoded_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Decimal_file_identifier +#define org_apache_arrow_flatbuf_Decimal_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Decimal_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Decimal_identifier +#define org_apache_arrow_flatbuf_Decimal_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Decimal_type_hash ((flatbuffers_thash_t)0x91d1beb7) +#define org_apache_arrow_flatbuf_Decimal_type_identifier "\xb7\xbe\xd1\x91" +#ifndef org_apache_arrow_flatbuf_Decimal_file_extension +#define org_apache_arrow_flatbuf_Decimal_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Date_file_identifier +#define org_apache_arrow_flatbuf_Date_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Date_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Date_identifier +#define org_apache_arrow_flatbuf_Date_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Date_type_hash ((flatbuffers_thash_t)0xe0ccf624) +#define org_apache_arrow_flatbuf_Date_type_identifier "\x24\xf6\xcc\xe0" +#ifndef org_apache_arrow_flatbuf_Date_file_extension +#define org_apache_arrow_flatbuf_Date_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Time_file_identifier +#define org_apache_arrow_flatbuf_Time_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Time_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Time_identifier +#define org_apache_arrow_flatbuf_Time_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Time_type_hash ((flatbuffers_thash_t)0x2442a489) +#define org_apache_arrow_flatbuf_Time_type_identifier "\x89\xa4\x42\x24" +#ifndef org_apache_arrow_flatbuf_Time_file_extension +#define org_apache_arrow_flatbuf_Time_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Timestamp_file_identifier +#define org_apache_arrow_flatbuf_Timestamp_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Timestamp_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Timestamp_identifier +#define org_apache_arrow_flatbuf_Timestamp_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Timestamp_type_hash ((flatbuffers_thash_t)0x1fddf080) +#define org_apache_arrow_flatbuf_Timestamp_type_identifier "\x80\xf0\xdd\x1f" +#ifndef org_apache_arrow_flatbuf_Timestamp_file_extension +#define org_apache_arrow_flatbuf_Timestamp_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Interval_file_identifier +#define org_apache_arrow_flatbuf_Interval_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Interval_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Interval_identifier +#define org_apache_arrow_flatbuf_Interval_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Interval_type_hash ((flatbuffers_thash_t)0x1e2d6809) +#define org_apache_arrow_flatbuf_Interval_type_identifier "\x09\x68\x2d\x1e" +#ifndef org_apache_arrow_flatbuf_Interval_file_extension +#define org_apache_arrow_flatbuf_Interval_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Duration_file_identifier +#define org_apache_arrow_flatbuf_Duration_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Duration_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Duration_identifier +#define org_apache_arrow_flatbuf_Duration_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Duration_type_hash ((flatbuffers_thash_t)0x1ecea6b0) +#define org_apache_arrow_flatbuf_Duration_type_identifier "\xb0\xa6\xce\x1e" +#ifndef org_apache_arrow_flatbuf_Duration_file_extension +#define org_apache_arrow_flatbuf_Duration_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_KeyValue_file_identifier +#define org_apache_arrow_flatbuf_KeyValue_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_KeyValue_file_identifier */ +#ifndef org_apache_arrow_flatbuf_KeyValue_identifier +#define org_apache_arrow_flatbuf_KeyValue_identifier 0 +#endif +#define org_apache_arrow_flatbuf_KeyValue_type_hash ((flatbuffers_thash_t)0x3b264744) +#define org_apache_arrow_flatbuf_KeyValue_type_identifier "\x44\x47\x26\x3b" +#ifndef org_apache_arrow_flatbuf_KeyValue_file_extension +#define org_apache_arrow_flatbuf_KeyValue_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier */ +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_identifier +#define org_apache_arrow_flatbuf_DictionaryEncoding_identifier 0 +#endif +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_hash ((flatbuffers_thash_t)0x8c703261) +#define org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier "\x61\x32\x70\x8c" +#ifndef org_apache_arrow_flatbuf_DictionaryEncoding_file_extension +#define org_apache_arrow_flatbuf_DictionaryEncoding_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Field_file_identifier +#define org_apache_arrow_flatbuf_Field_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Field_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Field_identifier +#define org_apache_arrow_flatbuf_Field_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Field_type_hash ((flatbuffers_thash_t)0xd981525c) +#define org_apache_arrow_flatbuf_Field_type_identifier "\x5c\x52\x81\xd9" +#ifndef org_apache_arrow_flatbuf_Field_file_extension +#define org_apache_arrow_flatbuf_Field_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Buffer_file_identifier +#define org_apache_arrow_flatbuf_Buffer_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Buffer_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Buffer_identifier +#define org_apache_arrow_flatbuf_Buffer_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Buffer_type_hash ((flatbuffers_thash_t)0x519d7fea) +#define org_apache_arrow_flatbuf_Buffer_type_identifier "\xea\x7f\x9d\x51" +#ifndef org_apache_arrow_flatbuf_Buffer_file_extension +#define org_apache_arrow_flatbuf_Buffer_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Schema_file_identifier +#define org_apache_arrow_flatbuf_Schema_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Schema_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Schema_identifier +#define org_apache_arrow_flatbuf_Schema_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Schema_type_hash ((flatbuffers_thash_t)0x406570b) +#define org_apache_arrow_flatbuf_Schema_type_identifier "\x0b\x57\x06\x04" +#ifndef org_apache_arrow_flatbuf_Schema_file_extension +#define org_apache_arrow_flatbuf_Schema_file_extension "bin" +#endif + +typedef int16_t org_apache_arrow_flatbuf_MetadataVersion_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t, 16) +/** 0.1.0 (October 2016). */ +#define org_apache_arrow_flatbuf_MetadataVersion_V1 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_MetadataVersion_V2 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_MetadataVersion_V3 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_MetadataVersion_V4 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(3)) +#define org_apache_arrow_flatbuf_MetadataVersion_V5 ((org_apache_arrow_flatbuf_MetadataVersion_enum_t)INT16_C(4)) + +static inline const char *org_apache_arrow_flatbuf_MetadataVersion_name(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return "V1"; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return "V2"; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return "V3"; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return "V4"; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return "V5"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_MetadataVersion_is_known_value(org_apache_arrow_flatbuf_MetadataVersion_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_MetadataVersion_V1: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V2: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V3: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V4: return 1; + case org_apache_arrow_flatbuf_MetadataVersion_V5: return 1; + default: return 0; + } +} + +/** Represents Arrow Features that might not have full support + * within implementations. This is intended to be used in + * two scenarios: + * 1. A mechanism for readers of Arrow Streams + * and files to understand that the stream or file makes + * use of a feature that isn't supported or unknown to + * the implementation (and therefore can meet the Arrow + * forward compatibility guarantees). + * 2. A means of negotiating between a client and server + * what features a stream is allowed to use. The enums + * values here are intented to represent higher level + * features, additional details maybe negotiated + * with key-value pairs specific to the protocol. + * + * Enums added to this list should be assigned power-of-two values + * to facilitate exchanging and comparing bitmaps for supported + * features. */ +typedef int64_t org_apache_arrow_flatbuf_Feature_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, 64) +/** Needed to make flatbuffers happy. */ +#define org_apache_arrow_flatbuf_Feature_UNUSED ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(0)) +#define org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(1)) +#define org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY ((org_apache_arrow_flatbuf_Feature_enum_t)INT64_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Feature_name(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return "UNUSED"; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return "DICTIONARY_REPLACEMENT"; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return "COMPRESSED_BODY"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Feature_is_known_value(org_apache_arrow_flatbuf_Feature_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Feature_UNUSED: return 1; + case org_apache_arrow_flatbuf_Feature_DICTIONARY_REPLACEMENT: return 1; + case org_apache_arrow_flatbuf_Feature_COMPRESSED_BODY: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_UnionMode_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 16) +#define org_apache_arrow_flatbuf_UnionMode_Sparse ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_UnionMode_Dense ((org_apache_arrow_flatbuf_UnionMode_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_UnionMode_name(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return "Sparse"; + case org_apache_arrow_flatbuf_UnionMode_Dense: return "Dense"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_UnionMode_is_known_value(org_apache_arrow_flatbuf_UnionMode_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_UnionMode_Sparse: return 1; + case org_apache_arrow_flatbuf_UnionMode_Dense: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_Precision_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 16) +#define org_apache_arrow_flatbuf_Precision_HALF ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Precision_SINGLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_Precision_DOUBLE ((org_apache_arrow_flatbuf_Precision_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_Precision_name(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return "HALF"; + case org_apache_arrow_flatbuf_Precision_SINGLE: return "SINGLE"; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return "DOUBLE"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Precision_is_known_value(org_apache_arrow_flatbuf_Precision_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Precision_HALF: return 1; + case org_apache_arrow_flatbuf_Precision_SINGLE: return 1; + case org_apache_arrow_flatbuf_Precision_DOUBLE: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_DateUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_DateUnit_DAY ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_DateUnit_MILLISECOND ((org_apache_arrow_flatbuf_DateUnit_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_DateUnit_name(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return "DAY"; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return "MILLISECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DateUnit_is_known_value(org_apache_arrow_flatbuf_DateUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DateUnit_DAY: return 1; + case org_apache_arrow_flatbuf_DateUnit_MILLISECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_TimeUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_TimeUnit_SECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_TimeUnit_MILLISECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_TimeUnit_MICROSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(2)) +#define org_apache_arrow_flatbuf_TimeUnit_NANOSECOND ((org_apache_arrow_flatbuf_TimeUnit_enum_t)INT16_C(3)) + +static inline const char *org_apache_arrow_flatbuf_TimeUnit_name(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return "SECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return "MILLISECOND"; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return "MICROSECOND"; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return "NANOSECOND"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_TimeUnit_is_known_value(org_apache_arrow_flatbuf_TimeUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_TimeUnit_SECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MILLISECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_MICROSECOND: return 1; + case org_apache_arrow_flatbuf_TimeUnit_NANOSECOND: return 1; + default: return 0; + } +} + +typedef int16_t org_apache_arrow_flatbuf_IntervalUnit_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 16) +#define org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(1)) +#define org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO ((org_apache_arrow_flatbuf_IntervalUnit_enum_t)INT16_C(2)) + +static inline const char *org_apache_arrow_flatbuf_IntervalUnit_name(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return "YEAR_MONTH"; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return "DAY_TIME"; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return "MONTH_DAY_NANO"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_IntervalUnit_is_known_value(org_apache_arrow_flatbuf_IntervalUnit_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_IntervalUnit_YEAR_MONTH: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_DAY_TIME: return 1; + case org_apache_arrow_flatbuf_IntervalUnit_MONTH_DAY_NANO: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Dictionary encoding metadata + * Maintained for forwards compatibility, in the future + * Dictionaries might be explicit maps between integers and values + * allowing for non-contiguous index values */ +typedef int16_t org_apache_arrow_flatbuf_DictionaryKind_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 16) +#define org_apache_arrow_flatbuf_DictionaryKind_DenseArray ((org_apache_arrow_flatbuf_DictionaryKind_enum_t)INT16_C(0)) + +static inline const char *org_apache_arrow_flatbuf_DictionaryKind_name(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return "DenseArray"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_DictionaryKind_is_known_value(org_apache_arrow_flatbuf_DictionaryKind_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_DictionaryKind_DenseArray: return 1; + default: return 0; + } +} + +/** ---------------------------------------------------------------------- + * Endianness of the platform producing the data */ +typedef int16_t org_apache_arrow_flatbuf_Endianness_enum_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 16) +#define org_apache_arrow_flatbuf_Endianness_Little ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(0)) +#define org_apache_arrow_flatbuf_Endianness_Big ((org_apache_arrow_flatbuf_Endianness_enum_t)INT16_C(1)) + +static inline const char *org_apache_arrow_flatbuf_Endianness_name(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return "Little"; + case org_apache_arrow_flatbuf_Endianness_Big: return "Big"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Endianness_is_known_value(org_apache_arrow_flatbuf_Endianness_enum_t value) +{ + switch (value) { + case org_apache_arrow_flatbuf_Endianness_Little: return 1; + case org_apache_arrow_flatbuf_Endianness_Big: return 1; + default: return 0; + } +} + + +/** ---------------------------------------------------------------------- + * A Buffer represents a single contiguous memory segment */ +struct org_apache_arrow_flatbuf_Buffer { + /** The relative offset into the shared memory page where the bytes for this + * buffer starts */ + alignas(8) int64_t offset; + /** The absolute length (in bytes) of the memory buffer. The memory is found + * from offset (inclusive) to offset + length (non-inclusive). When building + * messages using the encapsulated IPC message, padding bytes may be written + * after a buffer, but such padding bytes do not need to be accounted for in + * the size here. */ + alignas(8) int64_t length; +}; +static_assert(sizeof(org_apache_arrow_flatbuf_Buffer_t) == 16, "struct size mismatch"); + +static inline const org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__const_ptr_add(const org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer__ptr_add(org_apache_arrow_flatbuf_Buffer_t *p, size_t i) { return p + i; } +static inline org_apache_arrow_flatbuf_Buffer_struct_t org_apache_arrow_flatbuf_Buffer_vec_at(org_apache_arrow_flatbuf_Buffer_vec_t vec, size_t i) +__flatbuffers_struct_vec_at(vec, i) +static inline size_t org_apache_arrow_flatbuf_Buffer__size(void) { return 16; } +static inline size_t org_apache_arrow_flatbuf_Buffer_vec_len(org_apache_arrow_flatbuf_Buffer_vec_t vec) +__flatbuffers_vec_len(vec) +__flatbuffers_struct_as_root(org_apache_arrow_flatbuf_Buffer) + +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, offset, flatbuffers_int64, int64_t) +__flatbuffers_define_struct_scalar_field(org_apache_arrow_flatbuf_Buffer, length, flatbuffers_int64, int64_t) + + +/** These are stored in the flatbuffer in the Type union below */ +struct org_apache_arrow_flatbuf_Null_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Null_vec_len(org_apache_arrow_flatbuf_Null_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Null_table_t org_apache_arrow_flatbuf_Null_vec_at(org_apache_arrow_flatbuf_Null_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Null_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Null) + + +/** A Struct_ in the flatbuffer metadata is the same as an Arrow Struct + * (according to the physical memory layout). We used Struct_ here as + * Struct is a reserved word in Flatbuffers */ +struct org_apache_arrow_flatbuf_Struct__table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Struct__vec_len(org_apache_arrow_flatbuf_Struct__vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Struct__table_t org_apache_arrow_flatbuf_Struct__vec_at(org_apache_arrow_flatbuf_Struct__vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Struct__table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Struct_) + + +struct org_apache_arrow_flatbuf_List_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_List_vec_len(org_apache_arrow_flatbuf_List_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_List_table_t org_apache_arrow_flatbuf_List_vec_at(org_apache_arrow_flatbuf_List_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_List_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_List) + + +/** Same as List, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeList_vec_len(org_apache_arrow_flatbuf_LargeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeList_table_t org_apache_arrow_flatbuf_LargeList_vec_at(org_apache_arrow_flatbuf_LargeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeList) + + +/** Represents the same logical types that List can, but contains offsets and + * sizes allowing for writes in any order and sharing of child values among + * list values. */ +struct org_apache_arrow_flatbuf_ListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_ListView_vec_len(org_apache_arrow_flatbuf_ListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_ListView_table_t org_apache_arrow_flatbuf_ListView_vec_at(org_apache_arrow_flatbuf_ListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_ListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_ListView) + + +/** Same as ListView, but with 64-bit offsets and sizes, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeListView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeListView_vec_len(org_apache_arrow_flatbuf_LargeListView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeListView_table_t org_apache_arrow_flatbuf_LargeListView_vec_at(org_apache_arrow_flatbuf_LargeListView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeListView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeListView) + + +struct org_apache_arrow_flatbuf_FixedSizeList_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeList_vec_len(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeList_table_t org_apache_arrow_flatbuf_FixedSizeList_vec_at(org_apache_arrow_flatbuf_FixedSizeList_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeList_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeList) + +/** Number of list items per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeList, listSize, flatbuffers_int32, int32_t, INT32_C(0)) + +/** A Map is a logical nested type that is represented as + * + * List> + * + * In this layout, the keys and values are each respectively contiguous. We do + * not constrain the key and value types, so the application is responsible + * for ensuring that the keys are hashable and unique. Whether the keys are sorted + * may be set in the metadata for this field. + * + * In a field with Map type, the field has a child Struct field, which then + * has two children: key type and the second the value type. The names of the + * child fields may be respectively "entries", "key", and "value", but this is + * not enforced. + * + * Map + * ```text + * - child[0] entries: Struct + * - child[0] key: K + * - child[1] value: V + * ``` + * Neither the "entries" field nor the "key" field may be nullable. + * + * The metadata is structured so that Arrow systems without special handling + * for Map can make Map an alias for List. The "layout" attribute for the Map + * field must have the same contents as a List. */ +struct org_apache_arrow_flatbuf_Map_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Map_vec_len(org_apache_arrow_flatbuf_Map_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Map_table_t org_apache_arrow_flatbuf_Map_vec_at(org_apache_arrow_flatbuf_Map_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Map_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Map) + +/** Set to true if the keys within each value are sorted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Map, keysSorted, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +/** A union is a complex type with children in Field + * By default ids in the type vector refer to the offsets in the children + * optionally typeIds provides an indirection between the child offset and the type id + * for each child `typeIds[offset]` is the id used in the type vector */ +struct org_apache_arrow_flatbuf_Union_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Union_vec_len(org_apache_arrow_flatbuf_Union_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Union_table_t org_apache_arrow_flatbuf_Union_vec_at(org_apache_arrow_flatbuf_Union_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Union_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Union) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Union, mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Union, typeIds, flatbuffers_int32_vec_t, 0) + +struct org_apache_arrow_flatbuf_Int_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Int_vec_len(org_apache_arrow_flatbuf_Int_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Int_table_t org_apache_arrow_flatbuf_Int_vec_at(org_apache_arrow_flatbuf_Int_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Int_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Int) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Int, bitWidth, flatbuffers_int32, int32_t, INT32_C(0)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Int, is_signed, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) + +struct org_apache_arrow_flatbuf_FloatingPoint_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FloatingPoint_vec_len(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FloatingPoint_table_t org_apache_arrow_flatbuf_FloatingPoint_vec_at(org_apache_arrow_flatbuf_FloatingPoint_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FloatingPoint_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FloatingPoint) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FloatingPoint, precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, INT16_C(0)) + +/** Unicode with UTF-8 encoding */ +struct org_apache_arrow_flatbuf_Utf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8_vec_len(org_apache_arrow_flatbuf_Utf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8_table_t org_apache_arrow_flatbuf_Utf8_vec_at(org_apache_arrow_flatbuf_Utf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8) + + +/** Opaque binary data */ +struct org_apache_arrow_flatbuf_Binary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Binary_vec_len(org_apache_arrow_flatbuf_Binary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Binary_table_t org_apache_arrow_flatbuf_Binary_vec_at(org_apache_arrow_flatbuf_Binary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Binary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Binary) + + +/** Same as Utf8, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeUtf8_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeUtf8_vec_len(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeUtf8_table_t org_apache_arrow_flatbuf_LargeUtf8_vec_at(org_apache_arrow_flatbuf_LargeUtf8_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeUtf8_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeUtf8) + + +/** Same as Binary, but with 64-bit offsets, allowing to represent + * extremely large data values. */ +struct org_apache_arrow_flatbuf_LargeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_LargeBinary_vec_len(org_apache_arrow_flatbuf_LargeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_LargeBinary_table_t org_apache_arrow_flatbuf_LargeBinary_vec_at(org_apache_arrow_flatbuf_LargeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_LargeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_LargeBinary) + + +/** Logically the same as Utf8, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_Utf8View_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Utf8View_vec_len(org_apache_arrow_flatbuf_Utf8View_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Utf8View_table_t org_apache_arrow_flatbuf_Utf8View_vec_at(org_apache_arrow_flatbuf_Utf8View_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Utf8View_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Utf8View) + + +/** Logically the same as Binary, but the internal representation uses a view + * struct that contains the string length and either the string's entire data + * inline (for small strings) or an inlined prefix, an index of another buffer, + * and an offset pointing to a slice in that buffer (for non-small strings). + * + * Since it uses a variable number of data buffers, each Field with this type + * must have a corresponding entry in `variadicBufferCounts`. */ +struct org_apache_arrow_flatbuf_BinaryView_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_BinaryView_vec_len(org_apache_arrow_flatbuf_BinaryView_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_BinaryView_table_t org_apache_arrow_flatbuf_BinaryView_vec_at(org_apache_arrow_flatbuf_BinaryView_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_BinaryView_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_BinaryView) + + +struct org_apache_arrow_flatbuf_FixedSizeBinary_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_len(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_FixedSizeBinary_table_t org_apache_arrow_flatbuf_FixedSizeBinary_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_FixedSizeBinary_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_FixedSizeBinary) + +/** Number of bytes per value */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_FixedSizeBinary, byteWidth, flatbuffers_int32, int32_t, INT32_C(0)) + +struct org_apache_arrow_flatbuf_Bool_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Bool_vec_len(org_apache_arrow_flatbuf_Bool_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Bool_table_t org_apache_arrow_flatbuf_Bool_vec_at(org_apache_arrow_flatbuf_Bool_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Bool_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Bool) + + +/** Contains two child arrays, run_ends and values. + * The run_ends child array must be a 16/32/64-bit integer array + * which encodes the indices at which the run with the value in + * each corresponding index in the values child array ends. + * Like list/struct types, the value array can be of any type. */ +struct org_apache_arrow_flatbuf_RunEndEncoded_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_RunEndEncoded_vec_len(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_RunEndEncoded_table_t org_apache_arrow_flatbuf_RunEndEncoded_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_RunEndEncoded_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_RunEndEncoded) + + +/** Exact decimal value represented as an integer value in two's + * complement. Currently only 128-bit (16-byte) and 256-bit (32-byte) integers + * are used. The representation uses the endianness indicated + * in the Schema. */ +struct org_apache_arrow_flatbuf_Decimal_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Decimal_vec_len(org_apache_arrow_flatbuf_Decimal_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Decimal_table_t org_apache_arrow_flatbuf_Decimal_vec_at(org_apache_arrow_flatbuf_Decimal_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Decimal_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Decimal) + +/** Total number of decimal digits */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Decimal, precision, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of digits after the decimal point "." */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Decimal, scale, flatbuffers_int32, int32_t, INT32_C(0)) +/** Number of bits per value. The only accepted widths are 128 and 256. + * We use bitWidth for consistency with Int::bitWidth. */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_Decimal, bitWidth, flatbuffers_int32, int32_t, INT32_C(128)) + +/** Date is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since UNIX epoch (1970-01-01), stored in either of two units: + * + * * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no + * leap seconds), where the values are evenly divisible by 86400000 + * * Days (32 bits) since the UNIX epoch */ +struct org_apache_arrow_flatbuf_Date_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Date_vec_len(org_apache_arrow_flatbuf_Date_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Date_table_t org_apache_arrow_flatbuf_Date_vec_at(org_apache_arrow_flatbuf_Date_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Date_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Date) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Date, unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, INT16_C(1)) + +/** Time is either a 32-bit or 64-bit signed integer type representing an + * elapsed time since midnight, stored in either of four units: seconds, + * milliseconds, microseconds or nanoseconds. + * + * The integer `bitWidth` depends on the `unit` and must be one of the following: + * * SECOND and MILLISECOND: 32 bits + * * MICROSECOND and NANOSECOND: 64 bits + * + * The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds + * (exclusive), adjusted for the time unit (for example, up to 86400000 + * exclusive for the MILLISECOND unit). + * This definition doesn't allow for leap seconds. Time values from + * measurements with leap seconds will need to be corrected when ingesting + * into Arrow (for example by replacing the value 86400 with 86399). */ +struct org_apache_arrow_flatbuf_Time_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Time_vec_len(org_apache_arrow_flatbuf_Time_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Time_table_t org_apache_arrow_flatbuf_Time_vec_at(org_apache_arrow_flatbuf_Time_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Time_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Time) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Time, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Time, bitWidth, flatbuffers_int32, int32_t, INT32_C(32)) + +/** Timestamp is a 64-bit signed integer representing an elapsed time since a + * fixed epoch, stored in either of four units: seconds, milliseconds, + * microseconds or nanoseconds, and is optionally annotated with a timezone. + * + * Timestamp values do not include any leap seconds (in other words, all + * days are considered 86400 seconds long). + * + * Timestamps with a non-empty timezone + * ------------------------------------ + * + * If a Timestamp column has a non-empty timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone + * (the Unix epoch), regardless of the Timestamp's own timezone. + * + * Therefore, timestamp values with a non-empty timezone correspond to + * physical points in time together with some additional information about + * how the data was obtained and/or how to display it (the timezone). + * + * For example, the timestamp value 0 with the timezone string "Europe/Paris" + * corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the + * application may prefer to display it as "January 1st 1970, 01h00" in + * the Europe/Paris timezone (which is the same physical point in time). + * + * One consequence is that timestamp values with a non-empty timezone + * can be compared and ordered directly, since they all share the same + * well-known point of reference (the Unix epoch). + * + * Timestamps with an unset / empty timezone + * ----------------------------------------- + * + * If a Timestamp column has no timezone value, its epoch is + * 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. + * + * Therefore, timestamp values without a timezone cannot be meaningfully + * interpreted as physical points in time, but only as calendar / clock + * indications ("wall clock time") in an unspecified timezone. + * + * For example, the timestamp value 0 with an empty timezone string + * corresponds to "January 1st 1970, 00h00" in an unknown timezone: there + * is not enough information to interpret it as a well-defined physical + * point in time. + * + * One consequence is that timestamp values without a timezone cannot + * be reliably compared or ordered, since they may have different points of + * reference. In particular, it is *not* possible to interpret an unset + * or empty timezone as the same as "UTC". + * + * Conversion between timezones + * ---------------------------- + * + * If a Timestamp column has a non-empty timezone, changing the timezone + * to a different non-empty value is a metadata-only operation: + * the timestamp values need not change as their point of reference remains + * the same (the Unix epoch). + * + * However, if a Timestamp column has no timezone value, changing it to a + * non-empty value requires to think about the desired semantics. + * One possibility is to assume that the original timestamp values are + * relative to the epoch of the timezone being set; timestamp values should + * then adjusted to the Unix epoch (for example, changing the timezone from + * empty to "Europe/Paris" would require converting the timestamp values + * from "Europe/Paris" to "UTC", which seems counter-intuitive but is + * nevertheless correct). + * + * Guidelines for encoding data from external libraries + * ---------------------------------------------------- + * + * Date & time libraries often have multiple different data types for temporal + * data. In order to ease interoperability between different implementations the + * Arrow project has some recommendations for encoding these types into a Timestamp + * column. + * + * An "instant" represents a physical point in time that has no relevant timezone + * (for example, astronomical data). To encode an instant, use a Timestamp with + * the timezone string set to "UTC", and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * A "zoned date-time" represents a physical point in time annotated with an + * informative timezone (for example, the timezone in which the data was + * recorded). To encode a zoned date-time, use a Timestamp with the timezone + * string set to the name of the timezone, and make sure the Timestamp values + * are relative to the UTC epoch (January 1st 1970, midnight). + * + * (There is some ambiguity between an instant and a zoned date-time with the + * UTC timezone. Both of these are stored the same in Arrow. Typically, + * this distinction does not matter. If it does, then an application should + * use custom metadata or an extension type to distinguish between the two cases.) + * + * An "offset date-time" represents a physical point in time combined with an + * explicit offset from UTC. To encode an offset date-time, use a Timestamp + * with the timezone string set to the numeric timezone offset string + * (e.g. "+03:00"), and make sure the Timestamp values are relative to + * the UTC epoch (January 1st 1970, midnight). + * + * A "naive date-time" (also called "local date-time" in some libraries) + * represents a wall clock time combined with a calendar date, but with + * no indication of how to map this information to a physical point in time. + * Naive date-times must be handled with care because of this missing + * information, and also because daylight saving time (DST) may make + * some values ambiguous or nonexistent. A naive date-time may be + * stored as a struct with Date and Time fields. However, it may also be + * encoded into a Timestamp column with an empty timezone. The timestamp + * values should be computed "as if" the timezone of the date-time values + * was UTC; for example, the naive date-time "January 1st 1970, 00h00" would + * be encoded as timestamp value 0. */ +struct org_apache_arrow_flatbuf_Timestamp_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Timestamp_vec_len(org_apache_arrow_flatbuf_Timestamp_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Timestamp_table_t org_apache_arrow_flatbuf_Timestamp_vec_at(org_apache_arrow_flatbuf_Timestamp_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Timestamp_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Timestamp) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Timestamp, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(0)) +/** The timezone is an optional string indicating the name of a timezone, + * one of: + * + * * As used in the Olson timezone database (the "tz database" or + * "tzdata"), such as "America/New_York". + * * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + * such as "+07:30". + * + * Whether a timezone string is present indicates different semantics about + * the data (see above). */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_Timestamp, timezone, 0) + +struct org_apache_arrow_flatbuf_Interval_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Interval_vec_len(org_apache_arrow_flatbuf_Interval_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Interval_table_t org_apache_arrow_flatbuf_Interval_vec_at(org_apache_arrow_flatbuf_Interval_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Interval_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Interval) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Interval, unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, INT16_C(0)) + +struct org_apache_arrow_flatbuf_Duration_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Duration_vec_len(org_apache_arrow_flatbuf_Duration_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Duration_table_t org_apache_arrow_flatbuf_Duration_vec_at(org_apache_arrow_flatbuf_Duration_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Duration_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Duration) + +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Duration, unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, INT16_C(1)) +/** ---------------------------------------------------------------------- + * Top-level Type value, enabling extensible type-specific metadata. We can + * add new logical types to Type without breaking backwards compatibility */ +typedef uint8_t org_apache_arrow_flatbuf_Type_union_type_t; +__flatbuffers_define_integer_type(org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Type_union_type_t, 8) +__flatbuffers_define_union(flatbuffers_, org_apache_arrow_flatbuf_Type) +/** ---------------------------------------------------------------------- + * user defined key value pairs to add custom metadata to arrow + * key namespacing is the responsibility of the user */ +#define org_apache_arrow_flatbuf_Type_NONE ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(0)) +#define org_apache_arrow_flatbuf_Type_Null ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(1)) +#define org_apache_arrow_flatbuf_Type_Int ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(2)) +#define org_apache_arrow_flatbuf_Type_FloatingPoint ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(3)) +#define org_apache_arrow_flatbuf_Type_Binary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(4)) +#define org_apache_arrow_flatbuf_Type_Utf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(5)) +#define org_apache_arrow_flatbuf_Type_Bool ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(6)) +#define org_apache_arrow_flatbuf_Type_Decimal ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(7)) +#define org_apache_arrow_flatbuf_Type_Date ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(8)) +#define org_apache_arrow_flatbuf_Type_Time ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(9)) +#define org_apache_arrow_flatbuf_Type_Timestamp ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(10)) +#define org_apache_arrow_flatbuf_Type_Interval ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(11)) +#define org_apache_arrow_flatbuf_Type_List ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(12)) +#define org_apache_arrow_flatbuf_Type_Struct_ ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(13)) +#define org_apache_arrow_flatbuf_Type_Union ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(14)) +#define org_apache_arrow_flatbuf_Type_FixedSizeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(15)) +#define org_apache_arrow_flatbuf_Type_FixedSizeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(16)) +#define org_apache_arrow_flatbuf_Type_Map ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(17)) +#define org_apache_arrow_flatbuf_Type_Duration ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(18)) +#define org_apache_arrow_flatbuf_Type_LargeBinary ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(19)) +#define org_apache_arrow_flatbuf_Type_LargeUtf8 ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(20)) +#define org_apache_arrow_flatbuf_Type_LargeList ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(21)) +#define org_apache_arrow_flatbuf_Type_RunEndEncoded ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(22)) +#define org_apache_arrow_flatbuf_Type_BinaryView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(23)) +#define org_apache_arrow_flatbuf_Type_Utf8View ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(24)) +#define org_apache_arrow_flatbuf_Type_ListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(25)) +#define org_apache_arrow_flatbuf_Type_LargeListView ((org_apache_arrow_flatbuf_Type_union_type_t)UINT8_C(26)) + +static inline const char *org_apache_arrow_flatbuf_Type_type_name(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return "NONE"; + case org_apache_arrow_flatbuf_Type_Null: return "Null"; + case org_apache_arrow_flatbuf_Type_Int: return "Int"; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return "FloatingPoint"; + case org_apache_arrow_flatbuf_Type_Binary: return "Binary"; + case org_apache_arrow_flatbuf_Type_Utf8: return "Utf8"; + case org_apache_arrow_flatbuf_Type_Bool: return "Bool"; + case org_apache_arrow_flatbuf_Type_Decimal: return "Decimal"; + case org_apache_arrow_flatbuf_Type_Date: return "Date"; + case org_apache_arrow_flatbuf_Type_Time: return "Time"; + case org_apache_arrow_flatbuf_Type_Timestamp: return "Timestamp"; + case org_apache_arrow_flatbuf_Type_Interval: return "Interval"; + case org_apache_arrow_flatbuf_Type_List: return "List"; + case org_apache_arrow_flatbuf_Type_Struct_: return "Struct_"; + case org_apache_arrow_flatbuf_Type_Union: return "Union"; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return "FixedSizeBinary"; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return "FixedSizeList"; + case org_apache_arrow_flatbuf_Type_Map: return "Map"; + case org_apache_arrow_flatbuf_Type_Duration: return "Duration"; + case org_apache_arrow_flatbuf_Type_LargeBinary: return "LargeBinary"; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return "LargeUtf8"; + case org_apache_arrow_flatbuf_Type_LargeList: return "LargeList"; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return "RunEndEncoded"; + case org_apache_arrow_flatbuf_Type_BinaryView: return "BinaryView"; + case org_apache_arrow_flatbuf_Type_Utf8View: return "Utf8View"; + case org_apache_arrow_flatbuf_Type_ListView: return "ListView"; + case org_apache_arrow_flatbuf_Type_LargeListView: return "LargeListView"; + default: return ""; + } +} + +static inline int org_apache_arrow_flatbuf_Type_is_known_type(org_apache_arrow_flatbuf_Type_union_type_t type) +{ + switch (type) { + case org_apache_arrow_flatbuf_Type_NONE: return 1; + case org_apache_arrow_flatbuf_Type_Null: return 1; + case org_apache_arrow_flatbuf_Type_Int: return 1; + case org_apache_arrow_flatbuf_Type_FloatingPoint: return 1; + case org_apache_arrow_flatbuf_Type_Binary: return 1; + case org_apache_arrow_flatbuf_Type_Utf8: return 1; + case org_apache_arrow_flatbuf_Type_Bool: return 1; + case org_apache_arrow_flatbuf_Type_Decimal: return 1; + case org_apache_arrow_flatbuf_Type_Date: return 1; + case org_apache_arrow_flatbuf_Type_Time: return 1; + case org_apache_arrow_flatbuf_Type_Timestamp: return 1; + case org_apache_arrow_flatbuf_Type_Interval: return 1; + case org_apache_arrow_flatbuf_Type_List: return 1; + case org_apache_arrow_flatbuf_Type_Struct_: return 1; + case org_apache_arrow_flatbuf_Type_Union: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeBinary: return 1; + case org_apache_arrow_flatbuf_Type_FixedSizeList: return 1; + case org_apache_arrow_flatbuf_Type_Map: return 1; + case org_apache_arrow_flatbuf_Type_Duration: return 1; + case org_apache_arrow_flatbuf_Type_LargeBinary: return 1; + case org_apache_arrow_flatbuf_Type_LargeUtf8: return 1; + case org_apache_arrow_flatbuf_Type_LargeList: return 1; + case org_apache_arrow_flatbuf_Type_RunEndEncoded: return 1; + case org_apache_arrow_flatbuf_Type_BinaryView: return 1; + case org_apache_arrow_flatbuf_Type_Utf8View: return 1; + case org_apache_arrow_flatbuf_Type_ListView: return 1; + case org_apache_arrow_flatbuf_Type_LargeListView: return 1; + default: return 0; + } +} + + +struct org_apache_arrow_flatbuf_KeyValue_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_KeyValue_vec_len(org_apache_arrow_flatbuf_KeyValue_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_KeyValue_table_t org_apache_arrow_flatbuf_KeyValue_vec_at(org_apache_arrow_flatbuf_KeyValue_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_KeyValue_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_KeyValue) + +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_KeyValue, key, 0) +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_KeyValue, value, 0) + +struct org_apache_arrow_flatbuf_DictionaryEncoding_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_len(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_DictionaryEncoding_table_t org_apache_arrow_flatbuf_DictionaryEncoding_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_DictionaryEncoding_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_DictionaryEncoding) + +/** The known dictionary id in the application where this data is used. In + * the file or streaming formats, the dictionary ids are found in the + * DictionaryBatch messages */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_DictionaryEncoding, id, flatbuffers_int64, int64_t, INT64_C(0)) +/** The dictionary indices are constrained to be non-negative integers. If + * this field is null, the indices must be signed int32. To maximize + * cross-language compatibility and performance, implementations are + * recommended to prefer signed integer types over unsigned integer types + * and to avoid uint64 indices unless they are required by an application. */ +__flatbuffers_define_table_field(1, org_apache_arrow_flatbuf_DictionaryEncoding, indexType, org_apache_arrow_flatbuf_Int_table_t, 0) +/** By default, dictionaries are not ordered, or the order does not have + * semantic meaning. In some statistical, applications, dictionary-encoding + * is used to represent ordered categorical data, and we provide a way to + * preserve that metadata here */ +__flatbuffers_define_scalar_field(2, org_apache_arrow_flatbuf_DictionaryEncoding, isOrdered, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +__flatbuffers_define_scalar_field(3, org_apache_arrow_flatbuf_DictionaryEncoding, dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, INT16_C(0)) + +/** ---------------------------------------------------------------------- + * A field represents a named column in a record / row batch or child of a + * nested type. */ +struct org_apache_arrow_flatbuf_Field_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Field_vec_len(org_apache_arrow_flatbuf_Field_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Field_table_t org_apache_arrow_flatbuf_Field_vec_at(org_apache_arrow_flatbuf_Field_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Field_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Field) + +/** Name is not required, in i.e. a List */ +__flatbuffers_define_string_field(0, org_apache_arrow_flatbuf_Field, name, 0) +/** Whether or not this field can contain nulls. Should be true in general. */ +__flatbuffers_define_scalar_field(1, org_apache_arrow_flatbuf_Field, nullable, flatbuffers_bool, flatbuffers_bool_t, UINT8_C(0)) +/** This is the type of the decoded value if the field is dictionary encoded. */ +__flatbuffers_define_union_field(flatbuffers_, 3, org_apache_arrow_flatbuf_Field, type, org_apache_arrow_flatbuf_Type, 0) +/** Present only if the field is dictionary encoded. */ +__flatbuffers_define_table_field(4, org_apache_arrow_flatbuf_Field, dictionary, org_apache_arrow_flatbuf_DictionaryEncoding_table_t, 0) +/** children apply only to nested data types like Struct, List and Union. For + * primitive types children will have length 0. */ +__flatbuffers_define_vector_field(5, org_apache_arrow_flatbuf_Field, children, org_apache_arrow_flatbuf_Field_vec_t, 0) +/** User-defined metadata */ +__flatbuffers_define_vector_field(6, org_apache_arrow_flatbuf_Field, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) + +/** ---------------------------------------------------------------------- + * A Schema describes the columns in a row batch */ +struct org_apache_arrow_flatbuf_Schema_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Schema_vec_len(org_apache_arrow_flatbuf_Schema_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Schema_table_t org_apache_arrow_flatbuf_Schema_vec_at(org_apache_arrow_flatbuf_Schema_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Schema_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Schema) + +/** endianness of the buffer + * it is Little Endian by default + * if endianness doesn't match the underlying system then the vectors need to be converted */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_Schema, endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, INT16_C(0)) +__flatbuffers_define_vector_field(1, org_apache_arrow_flatbuf_Schema, fields, org_apache_arrow_flatbuf_Field_vec_t, 0) +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Schema, custom_metadata, org_apache_arrow_flatbuf_KeyValue_vec_t, 0) +/** Features used in the stream/file. */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Schema, features, org_apache_arrow_flatbuf_Feature_vec_t, 0) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_READER_H */ +#ifndef SCHEMA_BUILDER_H +#define SCHEMA_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +#define __org_apache_arrow_flatbuf_MetadataVersion_formal_args , org_apache_arrow_flatbuf_MetadataVersion_enum_t v0 +#define __org_apache_arrow_flatbuf_MetadataVersion_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_MetadataVersion, org_apache_arrow_flatbuf_MetadataVersion_enum_t) +#define __org_apache_arrow_flatbuf_Feature_formal_args , org_apache_arrow_flatbuf_Feature_enum_t v0 +#define __org_apache_arrow_flatbuf_Feature_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t) +#define __org_apache_arrow_flatbuf_UnionMode_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0 +#define __org_apache_arrow_flatbuf_UnionMode_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t) +#define __org_apache_arrow_flatbuf_Precision_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_Precision_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t) +#define __org_apache_arrow_flatbuf_DateUnit_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_DateUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t) +#define __org_apache_arrow_flatbuf_TimeUnit_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_TimeUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t) +#define __org_apache_arrow_flatbuf_IntervalUnit_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_IntervalUnit_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t) +#define __org_apache_arrow_flatbuf_DictionaryKind_formal_args , org_apache_arrow_flatbuf_DictionaryKind_enum_t v0 +#define __org_apache_arrow_flatbuf_DictionaryKind_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t) +#define __org_apache_arrow_flatbuf_Endianness_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0 +#define __org_apache_arrow_flatbuf_Endianness_call_args , v0 +__flatbuffers_build_scalar(flatbuffers_, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t) + +#define __org_apache_arrow_flatbuf_Buffer_formal_args , int64_t v0, int64_t v1 +#define __org_apache_arrow_flatbuf_Buffer_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ p->offset = v0; p->length = v1; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ p->offset = p2->offset; p->length = p2->length; + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_to_pe(&p->offset, v0); flatbuffers_int64_assign_to_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_to_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_to_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_to_pe(&p->length, &p2->length); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_assign_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, int64_t v0, int64_t v1) +{ flatbuffers_int64_assign_from_pe(&p->offset, v0); flatbuffers_int64_assign_from_pe(&p->length, v1); + return p; } +static inline org_apache_arrow_flatbuf_Buffer_t *org_apache_arrow_flatbuf_Buffer_copy_from_pe(org_apache_arrow_flatbuf_Buffer_t *p, const org_apache_arrow_flatbuf_Buffer_t *p2) +{ flatbuffers_int64_copy_from_pe(&p->offset, &p2->offset); flatbuffers_int64_copy_from_pe(&p->length, &p2->length); + return p; } +__flatbuffers_build_struct(flatbuffers_, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Buffer_file_identifier, org_apache_arrow_flatbuf_Buffer_type_identifier) +__flatbuffers_define_fixed_array_primitives(flatbuffers_, org_apache_arrow_flatbuf_Buffer, org_apache_arrow_flatbuf_Buffer_t) + +typedef flatbuffers_union_ref_t org_apache_arrow_flatbuf_Type_union_ref_t; +typedef flatbuffers_union_vec_ref_t org_apache_arrow_flatbuf_Type_union_vec_ref_t; +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t t); + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Null_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Null_ref_t; +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Null, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Struct__required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Struct__ref_t; +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Struct_, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_List_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_List_ref_t; +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_List, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeList_ref_t; +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeList, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_ListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_ListView_ref_t; +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_ListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeListView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeListView_ref_t; +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeList_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeList_ref_t; +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Map_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Map_ref_t; +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Map, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Union_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Union_ref_t; +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Union, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Int_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Int_ref_t; +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Int, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FloatingPoint_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FloatingPoint_ref_t; +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8_ref_t; +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Binary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Binary_ref_t; +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Binary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeUtf8_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeUtf8_ref_t; +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_LargeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_LargeBinary_ref_t; +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Utf8View_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Utf8View_ref_t; +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_BinaryView_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_BinaryView_ref_t; +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_FixedSizeBinary_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_ref_t; +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Bool_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Bool_ref_t; +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Bool, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_RunEndEncoded_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_RunEndEncoded_ref_t; +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, 0) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Decimal_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Decimal_ref_t; +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Decimal, 3) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Date_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Date_ref_t; +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Date, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Time_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Time_ref_t; +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Time, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Timestamp_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Timestamp_ref_t; +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Interval_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Interval_ref_t; +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Interval, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Duration_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Duration_ref_t; +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Duration, 1) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_KeyValue_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_KeyValue_ref_t; +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_DictionaryEncoding_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_ref_t; +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, 4) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Field_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Field_ref_t; +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Field, 7) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Schema_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Schema_ref_t; +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Schema, 4) + +#define __org_apache_arrow_flatbuf_Null_formal_args +#define __org_apache_arrow_flatbuf_Null_call_args +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Null, org_apache_arrow_flatbuf_Null_file_identifier, org_apache_arrow_flatbuf_Null_type_identifier) + +#define __org_apache_arrow_flatbuf_Struct__formal_args +#define __org_apache_arrow_flatbuf_Struct__call_args +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Struct_, org_apache_arrow_flatbuf_Struct__file_identifier, org_apache_arrow_flatbuf_Struct__type_identifier) + +#define __org_apache_arrow_flatbuf_List_formal_args +#define __org_apache_arrow_flatbuf_List_call_args +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_List, org_apache_arrow_flatbuf_List_file_identifier, org_apache_arrow_flatbuf_List_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeList_formal_args +#define __org_apache_arrow_flatbuf_LargeList_call_args +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeList, org_apache_arrow_flatbuf_LargeList_file_identifier, org_apache_arrow_flatbuf_LargeList_type_identifier) + +#define __org_apache_arrow_flatbuf_ListView_formal_args +#define __org_apache_arrow_flatbuf_ListView_call_args +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_ListView, org_apache_arrow_flatbuf_ListView_file_identifier, org_apache_arrow_flatbuf_ListView_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeListView_formal_args +#define __org_apache_arrow_flatbuf_LargeListView_call_args +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeListView, org_apache_arrow_flatbuf_LargeListView_file_identifier, org_apache_arrow_flatbuf_LargeListView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeList_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeList_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList_file_identifier, org_apache_arrow_flatbuf_FixedSizeList_type_identifier) + +#define __org_apache_arrow_flatbuf_Map_formal_args , flatbuffers_bool_t v0 +#define __org_apache_arrow_flatbuf_Map_call_args , v0 +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Map, org_apache_arrow_flatbuf_Map_file_identifier, org_apache_arrow_flatbuf_Map_type_identifier) + +#define __org_apache_arrow_flatbuf_Union_formal_args , org_apache_arrow_flatbuf_UnionMode_enum_t v0, flatbuffers_int32_vec_ref_t v1 +#define __org_apache_arrow_flatbuf_Union_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Union, org_apache_arrow_flatbuf_Union_file_identifier, org_apache_arrow_flatbuf_Union_type_identifier) + +#define __org_apache_arrow_flatbuf_Int_formal_args , int32_t v0, flatbuffers_bool_t v1 +#define __org_apache_arrow_flatbuf_Int_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_Int_file_identifier, org_apache_arrow_flatbuf_Int_type_identifier) + +#define __org_apache_arrow_flatbuf_FloatingPoint_formal_args , org_apache_arrow_flatbuf_Precision_enum_t v0 +#define __org_apache_arrow_flatbuf_FloatingPoint_call_args , v0 +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint_file_identifier, org_apache_arrow_flatbuf_FloatingPoint_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8_formal_args +#define __org_apache_arrow_flatbuf_Utf8_call_args +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8, org_apache_arrow_flatbuf_Utf8_file_identifier, org_apache_arrow_flatbuf_Utf8_type_identifier) + +#define __org_apache_arrow_flatbuf_Binary_formal_args +#define __org_apache_arrow_flatbuf_Binary_call_args +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Binary, org_apache_arrow_flatbuf_Binary_file_identifier, org_apache_arrow_flatbuf_Binary_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeUtf8_formal_args +#define __org_apache_arrow_flatbuf_LargeUtf8_call_args +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8_file_identifier, org_apache_arrow_flatbuf_LargeUtf8_type_identifier) + +#define __org_apache_arrow_flatbuf_LargeBinary_formal_args +#define __org_apache_arrow_flatbuf_LargeBinary_call_args +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_LargeBinary, org_apache_arrow_flatbuf_LargeBinary_file_identifier, org_apache_arrow_flatbuf_LargeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Utf8View_formal_args +#define __org_apache_arrow_flatbuf_Utf8View_call_args +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Utf8View, org_apache_arrow_flatbuf_Utf8View_file_identifier, org_apache_arrow_flatbuf_Utf8View_type_identifier) + +#define __org_apache_arrow_flatbuf_BinaryView_formal_args +#define __org_apache_arrow_flatbuf_BinaryView_call_args +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_BinaryView, org_apache_arrow_flatbuf_BinaryView_file_identifier, org_apache_arrow_flatbuf_BinaryView_type_identifier) + +#define __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args , int32_t v0 +#define __org_apache_arrow_flatbuf_FixedSizeBinary_call_args , v0 +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary_file_identifier, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier) + +#define __org_apache_arrow_flatbuf_Bool_formal_args +#define __org_apache_arrow_flatbuf_Bool_call_args +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Bool, org_apache_arrow_flatbuf_Bool_file_identifier, org_apache_arrow_flatbuf_Bool_type_identifier) + +#define __org_apache_arrow_flatbuf_RunEndEncoded_formal_args +#define __org_apache_arrow_flatbuf_RunEndEncoded_call_args +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded_file_identifier, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier) + +#define __org_apache_arrow_flatbuf_Decimal_formal_args , int32_t v0, int32_t v1, int32_t v2 +#define __org_apache_arrow_flatbuf_Decimal_call_args , v0, v1, v2 +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Decimal, org_apache_arrow_flatbuf_Decimal_file_identifier, org_apache_arrow_flatbuf_Decimal_type_identifier) + +#define __org_apache_arrow_flatbuf_Date_formal_args , org_apache_arrow_flatbuf_DateUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Date_call_args , v0 +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Date, org_apache_arrow_flatbuf_Date_file_identifier, org_apache_arrow_flatbuf_Date_type_identifier) + +#define __org_apache_arrow_flatbuf_Time_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, int32_t v1 +#define __org_apache_arrow_flatbuf_Time_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Time, org_apache_arrow_flatbuf_Time_file_identifier, org_apache_arrow_flatbuf_Time_type_identifier) + +#define __org_apache_arrow_flatbuf_Timestamp_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_Timestamp_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Timestamp, org_apache_arrow_flatbuf_Timestamp_file_identifier, org_apache_arrow_flatbuf_Timestamp_type_identifier) + +#define __org_apache_arrow_flatbuf_Interval_formal_args , org_apache_arrow_flatbuf_IntervalUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Interval_call_args , v0 +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Interval, org_apache_arrow_flatbuf_Interval_file_identifier, org_apache_arrow_flatbuf_Interval_type_identifier) + +#define __org_apache_arrow_flatbuf_Duration_formal_args , org_apache_arrow_flatbuf_TimeUnit_enum_t v0 +#define __org_apache_arrow_flatbuf_Duration_call_args , v0 +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Duration, org_apache_arrow_flatbuf_Duration_file_identifier, org_apache_arrow_flatbuf_Duration_type_identifier) + +#define __org_apache_arrow_flatbuf_KeyValue_formal_args , flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_KeyValue_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_KeyValue_file_identifier, org_apache_arrow_flatbuf_KeyValue_type_identifier) + +#define __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args , int64_t v0, org_apache_arrow_flatbuf_Int_ref_t v1, flatbuffers_bool_t v2, org_apache_arrow_flatbuf_DictionaryKind_enum_t v3 +#define __org_apache_arrow_flatbuf_DictionaryEncoding_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_DictionaryEncoding_file_identifier, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier) + +#define __org_apache_arrow_flatbuf_Field_formal_args ,\ + flatbuffers_string_ref_t v0, flatbuffers_bool_t v1, org_apache_arrow_flatbuf_Type_union_ref_t v3, org_apache_arrow_flatbuf_DictionaryEncoding_ref_t v4, org_apache_arrow_flatbuf_Field_vec_ref_t v5, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v6 +#define __org_apache_arrow_flatbuf_Field_call_args ,\ + v0, v1, v3, v4, v5, v6 +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field_file_identifier, org_apache_arrow_flatbuf_Field_type_identifier) + +#define __org_apache_arrow_flatbuf_Schema_formal_args , org_apache_arrow_flatbuf_Endianness_enum_t v0, org_apache_arrow_flatbuf_Field_vec_ref_t v1, org_apache_arrow_flatbuf_KeyValue_vec_ref_t v2, org_apache_arrow_flatbuf_Feature_vec_ref_t v3 +#define __org_apache_arrow_flatbuf_Schema_call_args , v0, v1, v2, v3 +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Schema, org_apache_arrow_flatbuf_Schema_file_identifier, org_apache_arrow_flatbuf_Schema_type_identifier) + +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_NONE(void) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_NONE; uref.value = 0; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Null; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Int; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FloatingPoint; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Binary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Bool; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Decimal; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Date; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Time; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Timestamp; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Interval; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_List; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Struct_; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Union; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_FixedSizeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Map; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Duration; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeBinary; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeUtf8; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeList; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_RunEndEncoded; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_BinaryView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_Utf8View; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_ListView; uref.value = ref; return uref; } +static inline org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_ref_t ref) +{ org_apache_arrow_flatbuf_Type_union_ref_t uref; uref.type = org_apache_arrow_flatbuf_Type_LargeListView; uref.value = ref; return uref; } +__flatbuffers_build_union_vector(flatbuffers_, org_apache_arrow_flatbuf_Type) + +static org_apache_arrow_flatbuf_Type_union_ref_t org_apache_arrow_flatbuf_Type_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Type_union_t u) +{ + switch (u.type) { + case 1: return org_apache_arrow_flatbuf_Type_as_Null(org_apache_arrow_flatbuf_Null_clone(B, (org_apache_arrow_flatbuf_Null_table_t)u.value)); + case 2: return org_apache_arrow_flatbuf_Type_as_Int(org_apache_arrow_flatbuf_Int_clone(B, (org_apache_arrow_flatbuf_Int_table_t)u.value)); + case 3: return org_apache_arrow_flatbuf_Type_as_FloatingPoint(org_apache_arrow_flatbuf_FloatingPoint_clone(B, (org_apache_arrow_flatbuf_FloatingPoint_table_t)u.value)); + case 4: return org_apache_arrow_flatbuf_Type_as_Binary(org_apache_arrow_flatbuf_Binary_clone(B, (org_apache_arrow_flatbuf_Binary_table_t)u.value)); + case 5: return org_apache_arrow_flatbuf_Type_as_Utf8(org_apache_arrow_flatbuf_Utf8_clone(B, (org_apache_arrow_flatbuf_Utf8_table_t)u.value)); + case 6: return org_apache_arrow_flatbuf_Type_as_Bool(org_apache_arrow_flatbuf_Bool_clone(B, (org_apache_arrow_flatbuf_Bool_table_t)u.value)); + case 7: return org_apache_arrow_flatbuf_Type_as_Decimal(org_apache_arrow_flatbuf_Decimal_clone(B, (org_apache_arrow_flatbuf_Decimal_table_t)u.value)); + case 8: return org_apache_arrow_flatbuf_Type_as_Date(org_apache_arrow_flatbuf_Date_clone(B, (org_apache_arrow_flatbuf_Date_table_t)u.value)); + case 9: return org_apache_arrow_flatbuf_Type_as_Time(org_apache_arrow_flatbuf_Time_clone(B, (org_apache_arrow_flatbuf_Time_table_t)u.value)); + case 10: return org_apache_arrow_flatbuf_Type_as_Timestamp(org_apache_arrow_flatbuf_Timestamp_clone(B, (org_apache_arrow_flatbuf_Timestamp_table_t)u.value)); + case 11: return org_apache_arrow_flatbuf_Type_as_Interval(org_apache_arrow_flatbuf_Interval_clone(B, (org_apache_arrow_flatbuf_Interval_table_t)u.value)); + case 12: return org_apache_arrow_flatbuf_Type_as_List(org_apache_arrow_flatbuf_List_clone(B, (org_apache_arrow_flatbuf_List_table_t)u.value)); + case 13: return org_apache_arrow_flatbuf_Type_as_Struct_(org_apache_arrow_flatbuf_Struct__clone(B, (org_apache_arrow_flatbuf_Struct__table_t)u.value)); + case 14: return org_apache_arrow_flatbuf_Type_as_Union(org_apache_arrow_flatbuf_Union_clone(B, (org_apache_arrow_flatbuf_Union_table_t)u.value)); + case 15: return org_apache_arrow_flatbuf_Type_as_FixedSizeBinary(org_apache_arrow_flatbuf_FixedSizeBinary_clone(B, (org_apache_arrow_flatbuf_FixedSizeBinary_table_t)u.value)); + case 16: return org_apache_arrow_flatbuf_Type_as_FixedSizeList(org_apache_arrow_flatbuf_FixedSizeList_clone(B, (org_apache_arrow_flatbuf_FixedSizeList_table_t)u.value)); + case 17: return org_apache_arrow_flatbuf_Type_as_Map(org_apache_arrow_flatbuf_Map_clone(B, (org_apache_arrow_flatbuf_Map_table_t)u.value)); + case 18: return org_apache_arrow_flatbuf_Type_as_Duration(org_apache_arrow_flatbuf_Duration_clone(B, (org_apache_arrow_flatbuf_Duration_table_t)u.value)); + case 19: return org_apache_arrow_flatbuf_Type_as_LargeBinary(org_apache_arrow_flatbuf_LargeBinary_clone(B, (org_apache_arrow_flatbuf_LargeBinary_table_t)u.value)); + case 20: return org_apache_arrow_flatbuf_Type_as_LargeUtf8(org_apache_arrow_flatbuf_LargeUtf8_clone(B, (org_apache_arrow_flatbuf_LargeUtf8_table_t)u.value)); + case 21: return org_apache_arrow_flatbuf_Type_as_LargeList(org_apache_arrow_flatbuf_LargeList_clone(B, (org_apache_arrow_flatbuf_LargeList_table_t)u.value)); + case 22: return org_apache_arrow_flatbuf_Type_as_RunEndEncoded(org_apache_arrow_flatbuf_RunEndEncoded_clone(B, (org_apache_arrow_flatbuf_RunEndEncoded_table_t)u.value)); + case 23: return org_apache_arrow_flatbuf_Type_as_BinaryView(org_apache_arrow_flatbuf_BinaryView_clone(B, (org_apache_arrow_flatbuf_BinaryView_table_t)u.value)); + case 24: return org_apache_arrow_flatbuf_Type_as_Utf8View(org_apache_arrow_flatbuf_Utf8View_clone(B, (org_apache_arrow_flatbuf_Utf8View_table_t)u.value)); + case 25: return org_apache_arrow_flatbuf_Type_as_ListView(org_apache_arrow_flatbuf_ListView_clone(B, (org_apache_arrow_flatbuf_ListView_table_t)u.value)); + case 26: return org_apache_arrow_flatbuf_Type_as_LargeListView(org_apache_arrow_flatbuf_LargeListView_clone(B, (org_apache_arrow_flatbuf_LargeListView_table_t)u.value)); + default: return org_apache_arrow_flatbuf_Type_as_NONE(); + } +} + + +static inline org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Null_formal_args) +{ + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Null_end(B); +} + +static org_apache_arrow_flatbuf_Null_ref_t org_apache_arrow_flatbuf_Null_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Null_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Null_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Null_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Struct__formal_args) +{ + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Struct__end(B); +} + +static org_apache_arrow_flatbuf_Struct__ref_t org_apache_arrow_flatbuf_Struct__clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Struct__table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Struct__start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Struct__end(B)); +} + + +static inline org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_List_formal_args) +{ + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_List_end(B); +} + +static org_apache_arrow_flatbuf_List_ref_t org_apache_arrow_flatbuf_List_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_List_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_List_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_List_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeList_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeList_end(B); +} + +static org_apache_arrow_flatbuf_LargeList_ref_t org_apache_arrow_flatbuf_LargeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeList_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeList_end(B)); +} + + +static inline org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_ListView_formal_args) +{ + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_ListView_end(B); +} + +static org_apache_arrow_flatbuf_ListView_ref_t org_apache_arrow_flatbuf_ListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_ListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_ListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_ListView_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeListView_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeListView_end(B); +} + +static org_apache_arrow_flatbuf_LargeListView_ref_t org_apache_arrow_flatbuf_LargeListView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeListView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeListView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeListView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeList_listSize, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeList) + +static inline org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeList_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeList_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeList_ref_t org_apache_arrow_flatbuf_FixedSizeList_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeList_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeList_start(B) + || org_apache_arrow_flatbuf_FixedSizeList_listSize_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeList_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Map_keysSorted, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Map) + +static inline org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Map_formal_args) +{ + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Map_end(B); +} + +static org_apache_arrow_flatbuf_Map_ref_t org_apache_arrow_flatbuf_Map_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Map_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Map_start(B) + || org_apache_arrow_flatbuf_Map_keysSorted_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Map_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Union_mode, org_apache_arrow_flatbuf_UnionMode, org_apache_arrow_flatbuf_UnionMode_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Union) +__flatbuffers_build_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Union_typeIds, flatbuffers_int32, int32_t, org_apache_arrow_flatbuf_Union) + +static inline org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Union_formal_args) +{ + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_add(B, v1) + || org_apache_arrow_flatbuf_Union_mode_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Union_end(B); +} + +static org_apache_arrow_flatbuf_Union_ref_t org_apache_arrow_flatbuf_Union_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Union_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Union_start(B) + || org_apache_arrow_flatbuf_Union_typeIds_pick(B, t) + || org_apache_arrow_flatbuf_Union_mode_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Union_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Int_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Int) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Int_is_signed, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Int) + +static inline org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Int_formal_args) +{ + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_add(B, v0) + || org_apache_arrow_flatbuf_Int_is_signed_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_Int_end(B); +} + +static org_apache_arrow_flatbuf_Int_ref_t org_apache_arrow_flatbuf_Int_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Int_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Int_start(B) + || org_apache_arrow_flatbuf_Int_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Int_is_signed_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Int_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FloatingPoint_precision, org_apache_arrow_flatbuf_Precision, org_apache_arrow_flatbuf_Precision_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_FloatingPoint) + +static inline org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FloatingPoint_formal_args) +{ + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FloatingPoint_end(B); +} + +static org_apache_arrow_flatbuf_FloatingPoint_ref_t org_apache_arrow_flatbuf_FloatingPoint_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FloatingPoint_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FloatingPoint_start(B) + || org_apache_arrow_flatbuf_FloatingPoint_precision_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FloatingPoint_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8_end(B); +} + +static org_apache_arrow_flatbuf_Utf8_ref_t org_apache_arrow_flatbuf_Utf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Binary_formal_args) +{ + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Binary_end(B); +} + +static org_apache_arrow_flatbuf_Binary_ref_t org_apache_arrow_flatbuf_Binary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Binary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Binary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Binary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeUtf8_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeUtf8_end(B); +} + +static org_apache_arrow_flatbuf_LargeUtf8_ref_t org_apache_arrow_flatbuf_LargeUtf8_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeUtf8_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeUtf8_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeUtf8_end(B)); +} + + +static inline org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_LargeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_LargeBinary_end(B); +} + +static org_apache_arrow_flatbuf_LargeBinary_ref_t org_apache_arrow_flatbuf_LargeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_LargeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_LargeBinary_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_LargeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Utf8View_formal_args) +{ + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Utf8View_end(B); +} + +static org_apache_arrow_flatbuf_Utf8View_ref_t org_apache_arrow_flatbuf_Utf8View_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Utf8View_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Utf8View_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Utf8View_end(B)); +} + + +static inline org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_BinaryView_formal_args) +{ + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_BinaryView_end(B); +} + +static org_apache_arrow_flatbuf_BinaryView_ref_t org_apache_arrow_flatbuf_BinaryView_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_BinaryView_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_BinaryView_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_BinaryView_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_FixedSizeBinary) + +static inline org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_FixedSizeBinary_formal_args) +{ + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_FixedSizeBinary_end(B); +} + +static org_apache_arrow_flatbuf_FixedSizeBinary_ref_t org_apache_arrow_flatbuf_FixedSizeBinary_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_FixedSizeBinary_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_FixedSizeBinary_start(B) + || org_apache_arrow_flatbuf_FixedSizeBinary_byteWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_FixedSizeBinary_end(B)); +} + + +static inline org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Bool_formal_args) +{ + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_Bool_end(B); +} + +static org_apache_arrow_flatbuf_Bool_ref_t org_apache_arrow_flatbuf_Bool_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Bool_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Bool_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Bool_end(B)); +} + + +static inline org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_RunEndEncoded_formal_args) +{ + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + return org_apache_arrow_flatbuf_RunEndEncoded_end(B); +} + +static org_apache_arrow_flatbuf_RunEndEncoded_ref_t org_apache_arrow_flatbuf_RunEndEncoded_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_RunEndEncoded_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_RunEndEncoded_start(B)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_RunEndEncoded_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Decimal_precision, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Decimal_scale, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_Decimal_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(128), org_apache_arrow_flatbuf_Decimal) + +static inline org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Decimal_formal_args) +{ + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_add(B, v0) + || org_apache_arrow_flatbuf_Decimal_scale_add(B, v1) + || org_apache_arrow_flatbuf_Decimal_bitWidth_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_Decimal_end(B); +} + +static org_apache_arrow_flatbuf_Decimal_ref_t org_apache_arrow_flatbuf_Decimal_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Decimal_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Decimal_start(B) + || org_apache_arrow_flatbuf_Decimal_precision_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_scale_pick(B, t) + || org_apache_arrow_flatbuf_Decimal_bitWidth_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Decimal_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Date_unit, org_apache_arrow_flatbuf_DateUnit, org_apache_arrow_flatbuf_DateUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Date) + +static inline org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Date_formal_args) +{ + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Date_end(B); +} + +static org_apache_arrow_flatbuf_Date_ref_t org_apache_arrow_flatbuf_Date_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Date_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Date_start(B) + || org_apache_arrow_flatbuf_Date_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Date_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Time_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Time) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Time_bitWidth, flatbuffers_int32, int32_t, 4, 4, INT32_C(32), org_apache_arrow_flatbuf_Time) + +static inline org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Time_formal_args) +{ + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_add(B, v1) + || org_apache_arrow_flatbuf_Time_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Time_end(B); +} + +static org_apache_arrow_flatbuf_Time_ref_t org_apache_arrow_flatbuf_Time_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Time_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Time_start(B) + || org_apache_arrow_flatbuf_Time_bitWidth_pick(B, t) + || org_apache_arrow_flatbuf_Time_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Time_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_Timestamp_timezone, org_apache_arrow_flatbuf_Timestamp) + +static inline org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Timestamp_formal_args) +{ + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_add(B, v1) + || org_apache_arrow_flatbuf_Timestamp_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Timestamp_end(B); +} + +static org_apache_arrow_flatbuf_Timestamp_ref_t org_apache_arrow_flatbuf_Timestamp_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Timestamp_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Timestamp_start(B) + || org_apache_arrow_flatbuf_Timestamp_timezone_pick(B, t) + || org_apache_arrow_flatbuf_Timestamp_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Timestamp_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Interval_unit, org_apache_arrow_flatbuf_IntervalUnit, org_apache_arrow_flatbuf_IntervalUnit_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Interval) + +static inline org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Interval_formal_args) +{ + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Interval_end(B); +} + +static org_apache_arrow_flatbuf_Interval_ref_t org_apache_arrow_flatbuf_Interval_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Interval_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Interval_start(B) + || org_apache_arrow_flatbuf_Interval_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Interval_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Duration_unit, org_apache_arrow_flatbuf_TimeUnit, org_apache_arrow_flatbuf_TimeUnit_enum_t, 2, 2, INT16_C(1), org_apache_arrow_flatbuf_Duration) + +static inline org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Duration_formal_args) +{ + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Duration_end(B); +} + +static org_apache_arrow_flatbuf_Duration_ref_t org_apache_arrow_flatbuf_Duration_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Duration_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Duration_start(B) + || org_apache_arrow_flatbuf_Duration_unit_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Duration_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_key, org_apache_arrow_flatbuf_KeyValue) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_KeyValue_value, org_apache_arrow_flatbuf_KeyValue) + +static inline org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_KeyValue_formal_args) +{ + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_add(B, v0) + || org_apache_arrow_flatbuf_KeyValue_value_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_KeyValue_end(B); +} + +static org_apache_arrow_flatbuf_KeyValue_ref_t org_apache_arrow_flatbuf_KeyValue_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_KeyValue_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_KeyValue_start(B) + || org_apache_arrow_flatbuf_KeyValue_key_pick(B, t) + || org_apache_arrow_flatbuf_KeyValue_value_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_KeyValue_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_id, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_table_field(1, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_indexType, org_apache_arrow_flatbuf_Int, org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(2, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) +__flatbuffers_build_scalar_field(3, flatbuffers_, org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind, org_apache_arrow_flatbuf_DictionaryKind, org_apache_arrow_flatbuf_DictionaryKind_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_DictionaryEncoding) + +static inline org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_DictionaryEncoding_formal_args) +{ + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_add(B, v0) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_add(B, v1) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_add(B, v3) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_add(B, v2)) { + return 0; + } + return org_apache_arrow_flatbuf_DictionaryEncoding_end(B); +} + +static org_apache_arrow_flatbuf_DictionaryEncoding_ref_t org_apache_arrow_flatbuf_DictionaryEncoding_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_DictionaryEncoding_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_DictionaryEncoding_start(B) + || org_apache_arrow_flatbuf_DictionaryEncoding_id_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_indexType_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_dictionaryKind_pick(B, t) + || org_apache_arrow_flatbuf_DictionaryEncoding_isOrdered_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_DictionaryEncoding_end(B)); +} + +__flatbuffers_build_string_field(0, flatbuffers_, org_apache_arrow_flatbuf_Field_name, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_scalar_field(1, flatbuffers_, org_apache_arrow_flatbuf_Field_nullable, flatbuffers_bool, flatbuffers_bool_t, 1, 1, UINT8_C(0), org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_field(3, flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Field_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_field(4, flatbuffers_, org_apache_arrow_flatbuf_Field_dictionary, org_apache_arrow_flatbuf_DictionaryEncoding, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(5, flatbuffers_, org_apache_arrow_flatbuf_Field_children, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Field) +__flatbuffers_build_table_vector_field(6, flatbuffers_, org_apache_arrow_flatbuf_Field_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Field) + +static inline org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Field_formal_args) +{ + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_add(B, v0) + || org_apache_arrow_flatbuf_Field_type_add_value(B, v3) + || org_apache_arrow_flatbuf_Field_dictionary_add(B, v4) + || org_apache_arrow_flatbuf_Field_children_add(B, v5) + || org_apache_arrow_flatbuf_Field_custom_metadata_add(B, v6) + || org_apache_arrow_flatbuf_Field_nullable_add(B, v1) + || org_apache_arrow_flatbuf_Field_type_add_type(B, v3.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Field_end(B); +} + +static org_apache_arrow_flatbuf_Field_ref_t org_apache_arrow_flatbuf_Field_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Field_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Field_start(B) + || org_apache_arrow_flatbuf_Field_name_pick(B, t) + || org_apache_arrow_flatbuf_Field_type_pick(B, t) + || org_apache_arrow_flatbuf_Field_dictionary_pick(B, t) + || org_apache_arrow_flatbuf_Field_children_pick(B, t) + || org_apache_arrow_flatbuf_Field_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Field_nullable_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Field_end(B)); +} + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_Schema_endianness, org_apache_arrow_flatbuf_Endianness, org_apache_arrow_flatbuf_Endianness_enum_t, 2, 2, INT16_C(0), org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(1, flatbuffers_, org_apache_arrow_flatbuf_Schema_fields, org_apache_arrow_flatbuf_Field, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Schema_custom_metadata, org_apache_arrow_flatbuf_KeyValue, org_apache_arrow_flatbuf_Schema) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Schema_features, org_apache_arrow_flatbuf_Feature, org_apache_arrow_flatbuf_Feature_enum_t, org_apache_arrow_flatbuf_Schema) + +static inline org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Schema_formal_args) +{ + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_add(B, v1) + || org_apache_arrow_flatbuf_Schema_custom_metadata_add(B, v2) + || org_apache_arrow_flatbuf_Schema_features_add(B, v3) + || org_apache_arrow_flatbuf_Schema_endianness_add(B, v0)) { + return 0; + } + return org_apache_arrow_flatbuf_Schema_end(B); +} + +static org_apache_arrow_flatbuf_Schema_ref_t org_apache_arrow_flatbuf_Schema_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Schema_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Schema_start(B) + || org_apache_arrow_flatbuf_Schema_fields_pick(B, t) + || org_apache_arrow_flatbuf_Schema_custom_metadata_pick(B, t) + || org_apache_arrow_flatbuf_Schema_features_pick(B, t) + || org_apache_arrow_flatbuf_Schema_endianness_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Schema_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_BUILDER_H */ +#ifndef SCHEMA_VERIFIER_H +#define SCHEMA_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_Type_union_verifier(flatcc_union_verifier_descriptor_t *ud) +{ + switch (ud->type) { + case 1: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Null_verify_table); /* Null */ + case 2: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Int_verify_table); /* Int */ + case 3: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FloatingPoint_verify_table); /* FloatingPoint */ + case 4: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Binary_verify_table); /* Binary */ + case 5: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8_verify_table); /* Utf8 */ + case 6: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Bool_verify_table); /* Bool */ + case 7: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Decimal_verify_table); /* Decimal */ + case 8: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Date_verify_table); /* Date */ + case 9: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Time_verify_table); /* Time */ + case 10: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Timestamp_verify_table); /* Timestamp */ + case 11: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Interval_verify_table); /* Interval */ + case 12: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_List_verify_table); /* List */ + case 13: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Struct__verify_table); /* Struct_ */ + case 14: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Union_verify_table); /* Union */ + case 15: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); /* FixedSizeBinary */ + case 16: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_FixedSizeList_verify_table); /* FixedSizeList */ + case 17: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Map_verify_table); /* Map */ + case 18: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Duration_verify_table); /* Duration */ + case 19: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeBinary_verify_table); /* LargeBinary */ + case 20: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeUtf8_verify_table); /* LargeUtf8 */ + case 21: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeList_verify_table); /* LargeList */ + case 22: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_RunEndEncoded_verify_table); /* RunEndEncoded */ + case 23: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_BinaryView_verify_table); /* BinaryView */ + case 24: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_Utf8View_verify_table); /* Utf8View */ + case 25: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_ListView_verify_table); /* ListView */ + case 26: return flatcc_verify_union_table(ud, org_apache_arrow_flatbuf_LargeListView_verify_table); /* LargeListView */ + default: return flatcc_verify_ok; + } +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_identifier, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Buffer_type_hash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_struct_as_typed_root_with_size(buf, bufsiz, thash, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root(buf, bufsiz, fid, 16, 8); +} + +static inline int org_apache_arrow_flatbuf_Buffer_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_struct_as_root_with_size(buf, bufsiz, fid, 16, 8); +} + +static int org_apache_arrow_flatbuf_Null_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Null_type_identifier, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Null_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Null_verify_table); +} + +static int org_apache_arrow_flatbuf_Struct__verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Struct__type_identifier, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static inline int org_apache_arrow_flatbuf_Struct__verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Struct__verify_table); +} + +static int org_apache_arrow_flatbuf_List_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_List_type_identifier, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static inline int org_apache_arrow_flatbuf_List_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_List_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeList_type_identifier, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeList_verify_table); +} + +static int org_apache_arrow_flatbuf_ListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_ListView_type_identifier, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_ListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_ListView_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeListView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeListView_type_identifier, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeListView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeListView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeList_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* listSize */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeList_type_identifier, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeList_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeList_verify_table); +} + +static int org_apache_arrow_flatbuf_Map_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 1, 1) /* keysSorted */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Map_type_identifier, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Map_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Map_verify_table); +} + +static int org_apache_arrow_flatbuf_Union_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* mode */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 1, 0, 4, 4, INT64_C(1073741823)) /* typeIds */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Union_type_identifier, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Union_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Union_verify_table); +} + +static int org_apache_arrow_flatbuf_Int_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* bitWidth */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* is_signed */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Int_type_identifier, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Int_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Int_verify_table); +} + +static int org_apache_arrow_flatbuf_FloatingPoint_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* precision */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FloatingPoint_type_identifier, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FloatingPoint_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FloatingPoint_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8_type_identifier, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8_verify_table); +} + +static int org_apache_arrow_flatbuf_Binary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Binary_type_identifier, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Binary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Binary_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeUtf8_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeUtf8_type_identifier, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeUtf8_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeUtf8_verify_table); +} + +static int org_apache_arrow_flatbuf_LargeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_LargeBinary_type_identifier, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_LargeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_LargeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Utf8View_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Utf8View_type_identifier, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Utf8View_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Utf8View_verify_table); +} + +static int org_apache_arrow_flatbuf_BinaryView_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_BinaryView_type_identifier, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static inline int org_apache_arrow_flatbuf_BinaryView_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_BinaryView_verify_table); +} + +static int org_apache_arrow_flatbuf_FixedSizeBinary_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* byteWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_FixedSizeBinary_type_identifier, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static inline int org_apache_arrow_flatbuf_FixedSizeBinary_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_FixedSizeBinary_verify_table); +} + +static int org_apache_arrow_flatbuf_Bool_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Bool_type_identifier, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Bool_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Bool_verify_table); +} + +static int org_apache_arrow_flatbuf_RunEndEncoded_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_RunEndEncoded_type_identifier, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static inline int org_apache_arrow_flatbuf_RunEndEncoded_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_RunEndEncoded_verify_table); +} + +static int org_apache_arrow_flatbuf_Decimal_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* precision */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* scale */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Decimal_type_identifier, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Decimal_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Decimal_verify_table); +} + +static int org_apache_arrow_flatbuf_Date_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Date_type_identifier, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Date_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Date_verify_table); +} + +static int org_apache_arrow_flatbuf_Time_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 4, 4) /* bitWidth */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Time_type_identifier, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Time_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Time_verify_table); +} + +static int org_apache_arrow_flatbuf_Timestamp_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* timezone */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Timestamp_type_identifier, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Timestamp_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Timestamp_verify_table); +} + +static int org_apache_arrow_flatbuf_Interval_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Interval_type_identifier, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Interval_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Interval_verify_table); +} + +static int org_apache_arrow_flatbuf_Duration_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* unit */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Duration_type_identifier, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Duration_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Duration_verify_table); +} + +static int org_apache_arrow_flatbuf_KeyValue_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* value */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_KeyValue_type_identifier, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static inline int org_apache_arrow_flatbuf_KeyValue_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_KeyValue_verify_table); +} + +static int org_apache_arrow_flatbuf_DictionaryEncoding_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* id */)) return ret; + if ((ret = flatcc_verify_table_field(td, 1, 0, &org_apache_arrow_flatbuf_Int_verify_table) /* indexType */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 1, 1) /* isOrdered */)) return ret; + if ((ret = flatcc_verify_field(td, 3, 2, 2) /* dictionaryKind */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_DictionaryEncoding_type_identifier, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static inline int org_apache_arrow_flatbuf_DictionaryEncoding_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table); +} + +static int org_apache_arrow_flatbuf_Field_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_string_field(td, 0, 0) /* name */)) return ret; + if ((ret = flatcc_verify_field(td, 1, 1, 1) /* nullable */)) return ret; + if ((ret = flatcc_verify_union_field(td, 3, 0, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_field(td, 4, 0, &org_apache_arrow_flatbuf_DictionaryEncoding_verify_table) /* dictionary */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 5, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* children */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 6, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Field_type_identifier, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Field_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Field_verify_table); +} + +static int org_apache_arrow_flatbuf_Schema_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 2, 2) /* endianness */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 1, 0, &org_apache_arrow_flatbuf_Field_verify_table) /* fields */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 0, &org_apache_arrow_flatbuf_KeyValue_verify_table) /* custom_metadata */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* features */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Schema_type_identifier, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Schema_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Schema_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* SCHEMA_VERIFIER_H */ +#ifndef TENSOR_READER_H +#define TENSOR_READER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#ifndef SCHEMA_READER_H +#include "Schema_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_table_t; +typedef struct org_apache_arrow_flatbuf_TensorDim_table *org_apache_arrow_flatbuf_TensorDim_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_TensorDim_mutable_vec_t; +typedef const struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_table_t; +typedef struct org_apache_arrow_flatbuf_Tensor_table *org_apache_arrow_flatbuf_Tensor_mutable_table_t; +typedef const flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_vec_t; +typedef flatbuffers_uoffset_t *org_apache_arrow_flatbuf_Tensor_mutable_vec_t; +#ifndef org_apache_arrow_flatbuf_TensorDim_file_identifier +#define org_apache_arrow_flatbuf_TensorDim_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_TensorDim_file_identifier */ +#ifndef org_apache_arrow_flatbuf_TensorDim_identifier +#define org_apache_arrow_flatbuf_TensorDim_identifier 0 +#endif +#define org_apache_arrow_flatbuf_TensorDim_type_hash ((flatbuffers_thash_t)0xbc6d7b25) +#define org_apache_arrow_flatbuf_TensorDim_type_identifier "\x25\x7b\x6d\xbc" +#ifndef org_apache_arrow_flatbuf_TensorDim_file_extension +#define org_apache_arrow_flatbuf_TensorDim_file_extension "bin" +#endif +#ifndef org_apache_arrow_flatbuf_Tensor_file_identifier +#define org_apache_arrow_flatbuf_Tensor_file_identifier 0 +#endif +/* deprecated, use org_apache_arrow_flatbuf_Tensor_file_identifier */ +#ifndef org_apache_arrow_flatbuf_Tensor_identifier +#define org_apache_arrow_flatbuf_Tensor_identifier 0 +#endif +#define org_apache_arrow_flatbuf_Tensor_type_hash ((flatbuffers_thash_t)0x1764df19) +#define org_apache_arrow_flatbuf_Tensor_type_identifier "\x19\xdf\x64\x17" +#ifndef org_apache_arrow_flatbuf_Tensor_file_extension +#define org_apache_arrow_flatbuf_Tensor_file_extension "bin" +#endif + + + +/** ---------------------------------------------------------------------- + * Data structures for dense tensors + * Shape data for a single axis in a tensor */ +struct org_apache_arrow_flatbuf_TensorDim_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_TensorDim_vec_len(org_apache_arrow_flatbuf_TensorDim_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_TensorDim_table_t org_apache_arrow_flatbuf_TensorDim_vec_at(org_apache_arrow_flatbuf_TensorDim_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_TensorDim_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_TensorDim) + +/** Length of dimension */ +__flatbuffers_define_scalar_field(0, org_apache_arrow_flatbuf_TensorDim, size, flatbuffers_int64, int64_t, INT64_C(0)) +/** Name of the dimension, optional */ +__flatbuffers_define_string_field(1, org_apache_arrow_flatbuf_TensorDim, name, 0) + +struct org_apache_arrow_flatbuf_Tensor_table { uint8_t unused__; }; + +static inline size_t org_apache_arrow_flatbuf_Tensor_vec_len(org_apache_arrow_flatbuf_Tensor_vec_t vec) +__flatbuffers_vec_len(vec) +static inline org_apache_arrow_flatbuf_Tensor_table_t org_apache_arrow_flatbuf_Tensor_vec_at(org_apache_arrow_flatbuf_Tensor_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(org_apache_arrow_flatbuf_Tensor_table_t, vec, i, 0) +__flatbuffers_table_as_root(org_apache_arrow_flatbuf_Tensor) + +/** The type of data contained in a value cell. Currently only fixed-width + * value types are supported, no strings or nested types */ +__flatbuffers_define_union_field(flatbuffers_, 1, org_apache_arrow_flatbuf_Tensor, type, org_apache_arrow_flatbuf_Type, 1) +/** The dimensions of the tensor, optionally named */ +__flatbuffers_define_vector_field(2, org_apache_arrow_flatbuf_Tensor, shape, org_apache_arrow_flatbuf_TensorDim_vec_t, 1) +/** Non-negative byte offsets to advance one value cell along each dimension + * If omitted, default to row-major order (C-like). */ +__flatbuffers_define_vector_field(3, org_apache_arrow_flatbuf_Tensor, strides, flatbuffers_int64_vec_t, 0) +/** The location and size of the tensor's data */ +__flatbuffers_define_struct_field(4, org_apache_arrow_flatbuf_Tensor, data, org_apache_arrow_flatbuf_Buffer_struct_t, 1) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_READER_H */ +#ifndef TENSOR_BUILDER_H +#define TENSOR_BUILDER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#ifndef SCHEMA_BUILDER_H +#include "Schema_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_TensorDim_required[] = { 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_TensorDim_ref_t; +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, 2) + +static const flatbuffers_voffset_t __org_apache_arrow_flatbuf_Tensor_required[] = { 1, 2, 4, 0 }; +typedef flatbuffers_ref_t org_apache_arrow_flatbuf_Tensor_ref_t; +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t); +__flatbuffers_build_table(flatbuffers_, org_apache_arrow_flatbuf_Tensor, 5) + +#define __org_apache_arrow_flatbuf_TensorDim_formal_args , int64_t v0, flatbuffers_string_ref_t v1 +#define __org_apache_arrow_flatbuf_TensorDim_call_args , v0, v1 +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_TensorDim_file_identifier, org_apache_arrow_flatbuf_TensorDim_type_identifier) + +#define __org_apache_arrow_flatbuf_Tensor_formal_args , org_apache_arrow_flatbuf_Type_union_ref_t v1, org_apache_arrow_flatbuf_TensorDim_vec_ref_t v2, flatbuffers_int64_vec_ref_t v3, org_apache_arrow_flatbuf_Buffer_t *v4 +#define __org_apache_arrow_flatbuf_Tensor_call_args , v1, v2, v3, v4 +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, org_apache_arrow_flatbuf_Tensor, org_apache_arrow_flatbuf_Tensor_file_identifier, org_apache_arrow_flatbuf_Tensor_type_identifier) + +__flatbuffers_build_scalar_field(0, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_size, flatbuffers_int64, int64_t, 8, 8, INT64_C(0), org_apache_arrow_flatbuf_TensorDim) +__flatbuffers_build_string_field(1, flatbuffers_, org_apache_arrow_flatbuf_TensorDim_name, org_apache_arrow_flatbuf_TensorDim) + +static inline org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_TensorDim_formal_args) +{ + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_add(B, v0) + || org_apache_arrow_flatbuf_TensorDim_name_add(B, v1)) { + return 0; + } + return org_apache_arrow_flatbuf_TensorDim_end(B); +} + +static org_apache_arrow_flatbuf_TensorDim_ref_t org_apache_arrow_flatbuf_TensorDim_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_TensorDim_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_TensorDim_start(B) + || org_apache_arrow_flatbuf_TensorDim_size_pick(B, t) + || org_apache_arrow_flatbuf_TensorDim_name_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_TensorDim_end(B)); +} + +__flatbuffers_build_union_field(1, flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Null, org_apache_arrow_flatbuf_Null) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Int, org_apache_arrow_flatbuf_Int) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FloatingPoint, org_apache_arrow_flatbuf_FloatingPoint) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Binary, org_apache_arrow_flatbuf_Binary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8, org_apache_arrow_flatbuf_Utf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Bool, org_apache_arrow_flatbuf_Bool) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Decimal, org_apache_arrow_flatbuf_Decimal) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Date, org_apache_arrow_flatbuf_Date) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Time, org_apache_arrow_flatbuf_Time) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Timestamp, org_apache_arrow_flatbuf_Timestamp) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Interval, org_apache_arrow_flatbuf_Interval) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, List, org_apache_arrow_flatbuf_List) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Struct_, org_apache_arrow_flatbuf_Struct_) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Union, org_apache_arrow_flatbuf_Union) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeBinary, org_apache_arrow_flatbuf_FixedSizeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, FixedSizeList, org_apache_arrow_flatbuf_FixedSizeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Map, org_apache_arrow_flatbuf_Map) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Duration, org_apache_arrow_flatbuf_Duration) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeBinary, org_apache_arrow_flatbuf_LargeBinary) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeUtf8, org_apache_arrow_flatbuf_LargeUtf8) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeList, org_apache_arrow_flatbuf_LargeList) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, RunEndEncoded, org_apache_arrow_flatbuf_RunEndEncoded) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, BinaryView, org_apache_arrow_flatbuf_BinaryView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, Utf8View, org_apache_arrow_flatbuf_Utf8View) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, ListView, org_apache_arrow_flatbuf_ListView) +__flatbuffers_build_union_table_value_field(flatbuffers_, org_apache_arrow_flatbuf_Tensor_type, org_apache_arrow_flatbuf_Type, LargeListView, org_apache_arrow_flatbuf_LargeListView) +__flatbuffers_build_table_vector_field(2, flatbuffers_, org_apache_arrow_flatbuf_Tensor_shape, org_apache_arrow_flatbuf_TensorDim, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_vector_field(3, flatbuffers_, org_apache_arrow_flatbuf_Tensor_strides, flatbuffers_int64, int64_t, org_apache_arrow_flatbuf_Tensor) +__flatbuffers_build_struct_field(4, flatbuffers_, org_apache_arrow_flatbuf_Tensor_data, org_apache_arrow_flatbuf_Buffer, 16, 8, org_apache_arrow_flatbuf_Tensor) + +static inline org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_create(flatbuffers_builder_t *B __org_apache_arrow_flatbuf_Tensor_formal_args) +{ + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_add(B, v4) + || org_apache_arrow_flatbuf_Tensor_type_add_value(B, v1) + || org_apache_arrow_flatbuf_Tensor_shape_add(B, v2) + || org_apache_arrow_flatbuf_Tensor_strides_add(B, v3) + || org_apache_arrow_flatbuf_Tensor_type_add_type(B, v1.type)) { + return 0; + } + return org_apache_arrow_flatbuf_Tensor_end(B); +} + +static org_apache_arrow_flatbuf_Tensor_ref_t org_apache_arrow_flatbuf_Tensor_clone(flatbuffers_builder_t *B, org_apache_arrow_flatbuf_Tensor_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (org_apache_arrow_flatbuf_Tensor_start(B) + || org_apache_arrow_flatbuf_Tensor_data_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_type_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_shape_pick(B, t) + || org_apache_arrow_flatbuf_Tensor_strides_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, org_apache_arrow_flatbuf_Tensor_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_BUILDER_H */ +#ifndef TENSOR_VERIFIER_H +#define TENSOR_VERIFIER_H + +/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef TENSOR_READER_H +#include "Tensor_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#ifndef SCHEMA_VERIFIER_H +#include "Schema_verifier.h" +#endif +#include "flatcc/flatcc_prologue.h" + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td); +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int org_apache_arrow_flatbuf_TensorDim_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 8, 8) /* size */)) return ret; + if ((ret = flatcc_verify_string_field(td, 1, 0) /* name */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_TensorDim_type_identifier, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static inline int org_apache_arrow_flatbuf_TensorDim_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_TensorDim_verify_table); +} + +static int org_apache_arrow_flatbuf_Tensor_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_union_field(td, 1, 1, &org_apache_arrow_flatbuf_Type_union_verifier) /* type */)) return ret; + if ((ret = flatcc_verify_table_vector_field(td, 2, 1, &org_apache_arrow_flatbuf_TensorDim_verify_table) /* shape */)) return ret; + if ((ret = flatcc_verify_vector_field(td, 3, 0, 8, 8, INT64_C(536870911)) /* strides */)) return ret; + if ((ret = flatcc_verify_field(td, 4, 16, 8) /* data */)) return ret; + return flatcc_verify_ok; +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_typed_root_with_size(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, org_apache_arrow_flatbuf_Tensor_type_identifier, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_identifier_and_size(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root_with_size(buf, bufsiz, fid, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +static inline int org_apache_arrow_flatbuf_Tensor_verify_as_root_with_type_hash_and_size(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root_with_size(buf, bufsiz, thash, &org_apache_arrow_flatbuf_Tensor_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* TENSOR_VERIFIER_H */ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "nanoarrow/nanoarrow_ipc.h" + +#if defined(NANOARROW_IPC_WITH_ZSTD) +#include + +static ArrowErrorCode ArrowIpcDecompressZstd(struct ArrowBufferView src, uint8_t* dst, + int64_t dst_size, struct ArrowError* error) { + size_t code = + ZSTD_decompress((void*)dst, (size_t)dst_size, src.data.data, src.size_bytes); + if (ZSTD_isError(code)) { + ArrowErrorSet(error, + "ZSTD_decompress([buffer with %" PRId64 + " bytes] -> [buffer with %" PRId64 " bytes]) failed with error '%s'", + src.size_bytes, dst_size, ZSTD_getErrorName(code)); + return EIO; + } + + if (dst_size != (int64_t)code) { + ArrowErrorSet(error, + "Expected decompressed size of %" PRId64 " bytes but got %" PRId64 + " bytes", + dst_size, (int64_t)code); + return EIO; + } + + return NANOARROW_OK; +} +#endif + +ArrowIpcDecompressFunction ArrowIpcGetZstdDecompressionFunction(void) { +#if defined(NANOARROW_IPC_WITH_ZSTD) + return &ArrowIpcDecompressZstd; +#else + return NULL; +#endif +} + +#if defined(NANOARROW_IPC_WITH_LZ4) +#include +#include + +static ArrowErrorCode ArrowIpcDecompressLZ4(struct ArrowBufferView src, uint8_t* dst, + int64_t dst_size, struct ArrowError* error) { + LZ4F_errorCode_t ret; + LZ4F_decompressionContext_t ctx = NULL; + + ret = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); + if (LZ4F_isError(ret)) { + ArrowErrorSet(error, "LZ4 init failed"); + return EIO; + } + + size_t dst_capacity = dst_size; + size_t src_size = src.size_bytes; + ret = LZ4F_decompress(ctx, dst, &dst_capacity, src.data.data, &src_size, + NULL /* options */); + if (LZ4F_isError(ret)) { + NANOARROW_UNUSED(LZ4F_freeDecompressionContext(ctx)); + ArrowErrorSet(error, + "LZ4F_decompress([buffer with %" PRId64 + " bytes] -> [buffer with %" PRId64 " bytes]) failed", + src.size_bytes, dst_size); + return EIO; + } + + if ((int64_t)dst_capacity != dst_size) { + NANOARROW_UNUSED(LZ4F_freeDecompressionContext(ctx)); + ArrowErrorSet(error, + "Expected decompressed size of %" PRId64 " bytes but got %" PRId64 + " bytes", + dst_size, (int64_t)dst_capacity); + return EIO; + } + + if (ret != 0) { + NANOARROW_UNUSED(LZ4F_freeDecompressionContext(ctx)); + ArrowErrorSet(error, + "Expected complete LZ4 frame but found frame with %" PRId64 + " bytes remaining", + (int64_t)ret); + return EIO; + } + + NANOARROW_UNUSED(LZ4F_freeDecompressionContext(ctx)); + return NANOARROW_OK; +} +#endif + +ArrowIpcDecompressFunction ArrowIpcGetLZ4DecompressionFunction(void) { +#if defined(NANOARROW_IPC_WITH_LZ4) + return &ArrowIpcDecompressLZ4; +#else + return NULL; +#endif +} + +struct ArrowIpcSerialDecompressorPrivate { + ArrowIpcDecompressFunction decompress_functions[3]; +}; + +static ArrowErrorCode ArrowIpcSerialDecompressorAdd( + struct ArrowIpcDecompressor* decompressor, + enum ArrowIpcCompressionType compression_type, struct ArrowBufferView src, + uint8_t* dst, int64_t dst_size, struct ArrowError* error) { + struct ArrowIpcSerialDecompressorPrivate* private_data = + (struct ArrowIpcSerialDecompressorPrivate*)decompressor->private_data; + + ArrowIpcDecompressFunction fn = NULL; + switch (compression_type) { + case NANOARROW_IPC_COMPRESSION_TYPE_ZSTD: + case NANOARROW_IPC_COMPRESSION_TYPE_LZ4_FRAME: + fn = private_data->decompress_functions[compression_type]; + break; + default: + ArrowErrorSet(error, "Unknown decompression type with value %d", + (int)compression_type); + return EINVAL; + } + + if (fn == NULL) { + ArrowErrorSet( + error, "Compression type with value %d not supported by this build of nanoarrow", + (int)compression_type); + return ENOTSUP; + } + + NANOARROW_RETURN_NOT_OK(fn(src, dst, dst_size, error)); + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcSerialDecompressorWait( + struct ArrowIpcDecompressor* decompressor, int64_t timeout_ms, + struct ArrowError* error) { + NANOARROW_UNUSED(decompressor); + NANOARROW_UNUSED(timeout_ms); + NANOARROW_UNUSED(error); + return NANOARROW_OK; +} + +static void ArrowIpcSerialDecompressorRelease(struct ArrowIpcDecompressor* decompressor) { + ArrowFree(decompressor->private_data); + decompressor->release = NULL; +} + +ArrowErrorCode ArrowIpcSerialDecompressor(struct ArrowIpcDecompressor* decompressor) { + decompressor->decompress_add = &ArrowIpcSerialDecompressorAdd; + decompressor->decompress_wait = &ArrowIpcSerialDecompressorWait; + decompressor->release = &ArrowIpcSerialDecompressorRelease; + decompressor->private_data = + ArrowMalloc(sizeof(struct ArrowIpcSerialDecompressorPrivate)); + if (decompressor->private_data == NULL) { + return ENOMEM; + } + + memset(decompressor->private_data, 0, sizeof(struct ArrowIpcSerialDecompressorPrivate)); + ArrowIpcSerialDecompressorSetFunction(decompressor, NANOARROW_IPC_COMPRESSION_TYPE_ZSTD, + ArrowIpcGetZstdDecompressionFunction()); + ArrowIpcSerialDecompressorSetFunction(decompressor, + NANOARROW_IPC_COMPRESSION_TYPE_LZ4_FRAME, + ArrowIpcGetLZ4DecompressionFunction()); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcSerialDecompressorSetFunction( + struct ArrowIpcDecompressor* decompressor, + enum ArrowIpcCompressionType compression_type, + ArrowIpcDecompressFunction decompress_function) { + struct ArrowIpcSerialDecompressorPrivate* private_data = + (struct ArrowIpcSerialDecompressorPrivate*)decompressor->private_data; + + switch (compression_type) { + case NANOARROW_IPC_COMPRESSION_TYPE_ZSTD: + case NANOARROW_IPC_COMPRESSION_TYPE_LZ4_FRAME: + break; + default: + return EINVAL; + } + + private_data->decompress_functions[compression_type] = decompress_function; + return NANOARROW_OK; +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include +#include + +// For thread safe shared buffers we need C11 + stdatomic.h +// Can compile with -DNANOARROW_IPC_USE_STDATOMIC=0 or 1 to override +// automatic detection +#if !defined(NANOARROW_IPC_USE_STDATOMIC) +#define NANOARROW_IPC_USE_STDATOMIC 0 + +// Check for C11 +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + +// Check for GCC 4.8, which doesn't include stdatomic.h but does +// not define __STDC_NO_ATOMICS__ +#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 5 + +#if !defined(__STDC_NO_ATOMICS__) +#include +#undef NANOARROW_IPC_USE_STDATOMIC +#define NANOARROW_IPC_USE_STDATOMIC 1 +#endif +#endif +#endif + +#endif + + +#include "nanoarrow/nanoarrow.h" +#include "nanoarrow/nanoarrow_ipc.h" + +// R 3.6 / Windows builds on a very old toolchain that does not define ENODATA +#if defined(_WIN32) && !defined(_MSC_VER) && !defined(ENODATA) +#define ENODATA 120 +#endif + +#define NANOARROW_IPC_MAGIC "ARROW1" + +// Internal representation of a parsed "Field" from flatbuffers. This +// represents a field in a depth-first walk of column arrays and their +// children. +struct ArrowIpcField { + // Pointer to the ArrowIpcDecoderPrivate::array_view or child for this node + struct ArrowArrayView* array_view; + // Pointer to the ArrowIpcDecoderPrivate::array or child for this node. This + // array is scratch space for any intermediary allocations (i.e., it is never moved + // to the user). + struct ArrowArray* array; + // The cumulative number of buffers preceding this node. + int64_t buffer_offset; +}; + +// Internal data specific to the read/decode process +struct ArrowIpcDecoderPrivate { + // The endianness that will be assumed for decoding future RecordBatch messages + enum ArrowIpcEndianness endianness; + // A cached system endianness value + enum ArrowIpcEndianness system_endianness; + // An ArrowArrayView whose length/null_count/buffers are set directly from the + // deserialized flatbuffer message (i.e., no fully underlying ArrowArray exists, + // although some buffers may be temporarily owned by ArrowIpcDecoderPrivate::array). + struct ArrowArrayView array_view; + // An ArrowArray with the same structure as the ArrowArrayView whose ArrowArrayBuffer() + // values are used to allocate or store memory when this is required. This ArrowArray + // is never moved to the caller; however, its buffers may be moved to the final output + // ArrowArray if the caller requests one. + struct ArrowArray array; + // The number of fields in the flattened depth-first walk of columns and their children + int64_t n_fields; + // Array of cached information such that given a field index it is possible to locate + // the ArrowArrayView/ArrowArray where the depth-first buffer/field walk should start. + struct ArrowIpcField* fields; + // The number of buffers that future RecordBatch messages must have to match the schema + // that has been set. + int64_t n_buffers; + // The number of union fields in the Schema. + int64_t n_union_fields; + // A pointer to the last flatbuffers message. + const void* last_message; + // Storage for a Footer + struct ArrowIpcFooter footer; + // Decompressor for compression support + struct ArrowIpcDecompressor decompressor; +}; + +ArrowErrorCode ArrowIpcCheckRuntime(struct ArrowError* error) { + // Avoids an unused warning when bundling the header into nanoarrow_ipc.c + NANOARROW_UNUSED(flatbuffers_end); + + const char* nanoarrow_runtime_version = ArrowNanoarrowVersion(); + const char* nanoarrow_ipc_build_time_version = NANOARROW_VERSION; + + if (strcmp(nanoarrow_runtime_version, nanoarrow_ipc_build_time_version) != 0) { + ArrowErrorSet(error, "Expected nanoarrow runtime version '%s' but found version '%s'", + nanoarrow_ipc_build_time_version, nanoarrow_runtime_version); + return EINVAL; + } + + return NANOARROW_OK; +} + +#if NANOARROW_IPC_USE_STDATOMIC +struct ArrowIpcSharedBufferPrivate { + struct ArrowBuffer src; + atomic_long reference_count; +}; + +static int64_t ArrowIpcSharedBufferUpdate( + struct ArrowIpcSharedBufferPrivate* private_data, int delta) { + int64_t old_count = atomic_fetch_add(&private_data->reference_count, delta); + return old_count + delta; +} + +static void ArrowIpcSharedBufferSet(struct ArrowIpcSharedBufferPrivate* private_data, + int64_t count) { + atomic_store(&private_data->reference_count, count); +} + +int ArrowIpcSharedBufferIsThreadSafe(void) { return 1; } +#else +struct ArrowIpcSharedBufferPrivate { + struct ArrowBuffer src; + int64_t reference_count; +}; + +static int64_t ArrowIpcSharedBufferUpdate( + struct ArrowIpcSharedBufferPrivate* private_data, int delta) { + private_data->reference_count += delta; + return private_data->reference_count; +} + +static void ArrowIpcSharedBufferSet(struct ArrowIpcSharedBufferPrivate* private_data, + int64_t count) { + private_data->reference_count = count; +} + +int ArrowIpcSharedBufferIsThreadSafe(void) { return 0; } +#endif + +static void ArrowIpcSharedBufferFree(struct ArrowBufferAllocator* allocator, uint8_t* ptr, + int64_t size) { + NANOARROW_UNUSED(allocator); + NANOARROW_UNUSED(ptr); + NANOARROW_UNUSED(size); + + struct ArrowIpcSharedBufferPrivate* private_data = + (struct ArrowIpcSharedBufferPrivate*)allocator->private_data; + + if (ArrowIpcSharedBufferUpdate(private_data, -1) == 0) { + ArrowBufferReset(&private_data->src); + ArrowFree(private_data); + } +} + +ArrowErrorCode ArrowIpcSharedBufferInit(struct ArrowIpcSharedBuffer* shared, + struct ArrowBuffer* src) { + if (src->data == NULL) { + ArrowBufferMove(src, &shared->private_src); + return NANOARROW_OK; + } + + struct ArrowIpcSharedBufferPrivate* private_data = + (struct ArrowIpcSharedBufferPrivate*)ArrowMalloc( + sizeof(struct ArrowIpcSharedBufferPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + ArrowBufferMove(src, &private_data->src); + ArrowIpcSharedBufferSet(private_data, 1); + + ArrowBufferInit(&shared->private_src); + shared->private_src.data = private_data->src.data; + shared->private_src.size_bytes = private_data->src.size_bytes; + // Don't expose any extra capcity from src so that any calls to ArrowBufferAppend + // on this buffer will fail. + shared->private_src.capacity_bytes = private_data->src.size_bytes; + shared->private_src.allocator = + ArrowBufferDeallocator(&ArrowIpcSharedBufferFree, private_data); + return NANOARROW_OK; +} + +static void ArrowIpcSharedBufferClone(struct ArrowIpcSharedBuffer* shared, + struct ArrowBuffer* shared_out) { + if (shared->private_src.size_bytes == 0) { + ArrowBufferInit(shared_out); + return; + } + + struct ArrowIpcSharedBufferPrivate* private_data = + (struct ArrowIpcSharedBufferPrivate*)shared->private_src.allocator.private_data; + ArrowIpcSharedBufferUpdate(private_data, 1); + memcpy(shared_out, shared, sizeof(struct ArrowBuffer)); +} + +void ArrowIpcSharedBufferReset(struct ArrowIpcSharedBuffer* shared) { + ArrowBufferReset(&shared->private_src); +} + +static int ArrowIpcDecoderNeedsSwapEndian(struct ArrowIpcDecoder* decoder) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + switch (private_data->endianness) { + case NANOARROW_IPC_ENDIANNESS_LITTLE: + case NANOARROW_IPC_ENDIANNESS_BIG: + return private_data->endianness != NANOARROW_IPC_ENDIANNESS_UNINITIALIZED && + private_data->endianness != private_data->system_endianness; + default: + return 0; + } +} + +ArrowErrorCode ArrowIpcDecoderInit(struct ArrowIpcDecoder* decoder) { + memset(decoder, 0, sizeof(struct ArrowIpcDecoder)); + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)ArrowMalloc(sizeof(struct ArrowIpcDecoderPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + memset(private_data, 0, sizeof(struct ArrowIpcDecoderPrivate)); + private_data->system_endianness = ArrowIpcSystemEndianness(); + ArrowIpcFooterInit(&private_data->footer); + decoder->private_data = private_data; + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcDecoderInitDecompressor( + struct ArrowIpcDecoderPrivate* private_data) { + if (private_data->decompressor.release == NULL) { + NANOARROW_RETURN_NOT_OK(ArrowIpcSerialDecompressor(&private_data->decompressor)); + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderSetDecompressor(struct ArrowIpcDecoder* decoder, + struct ArrowIpcDecompressor* decompressor) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + if (private_data->decompressor.release != NULL) { + private_data->decompressor.release(&private_data->decompressor); + } + + memcpy(&private_data->decompressor, decompressor, sizeof(struct ArrowIpcDecompressor)); + decompressor->release = NULL; + return NANOARROW_OK; +} + +void ArrowIpcDecoderReset(struct ArrowIpcDecoder* decoder) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + if (private_data != NULL) { + ArrowArrayViewReset(&private_data->array_view); + + if (private_data->array.release != NULL) { + ArrowArrayRelease(&private_data->array); + } + + if (private_data->fields != NULL) { + ArrowFree(private_data->fields); + private_data->n_fields = 0; + } + + private_data->n_union_fields = 0; + + ArrowIpcFooterReset(&private_data->footer); + + if (private_data->decompressor.release != NULL) { + private_data->decompressor.release(&private_data->decompressor); + } + + ArrowFree(private_data); + memset(decoder, 0, sizeof(struct ArrowIpcDecoder)); + } +} + +static inline int32_t ArrowIpcReadInt32LE(struct ArrowBufferView* data, int swap_endian) { + int32_t value; + memcpy(&value, data->data.as_uint8, sizeof(int32_t)); + if (swap_endian) { + value = bswap32(value); + } + + data->data.as_uint8 += sizeof(int32_t); + data->size_bytes -= sizeof(int32_t); + return value; +} + +#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(org_apache_arrow_flatbuf, x) + +static int ArrowIpcDecoderSetMetadata(struct ArrowSchema* schema, + ns(KeyValue_vec_t) kv_vec, + struct ArrowError* error) { + int64_t n_pairs = ns(KeyValue_vec_len(kv_vec)); + if (n_pairs == 0) { + return NANOARROW_OK; + } + + if (n_pairs > 2147483647) { + ArrowErrorSet(error, + "Expected between 0 and 2147483647 key/value pairs but found %" PRId64, + n_pairs); + return EINVAL; + } + + struct ArrowBuffer buf; + struct ArrowStringView key; + struct ArrowStringView value; + ns(KeyValue_table_t) kv; + + int result = ArrowMetadataBuilderInit(&buf, NULL); + if (result != NANOARROW_OK) { + ArrowBufferReset(&buf); + ArrowErrorSet(error, "ArrowMetadataBuilderInit() failed"); + return result; + } + + for (int64_t i = 0; i < n_pairs; i++) { + kv = ns(KeyValue_vec_at(kv_vec, i)); + + key.data = ns(KeyValue_key(kv)); + key.size_bytes = strlen(key.data); + value.data = ns(KeyValue_value(kv)); + value.size_bytes = strlen(value.data); + + result = ArrowMetadataBuilderAppend(&buf, key, value); + if (result != NANOARROW_OK) { + ArrowBufferReset(&buf); + ArrowErrorSet(error, "ArrowMetadataBuilderAppend() failed"); + return result; + } + } + + result = ArrowSchemaSetMetadata(schema, (const char*)buf.data); + ArrowBufferReset(&buf); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetMetadata() failed"); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeSimple(struct ArrowSchema* schema, int nanoarrow_type, + struct ArrowError* error) { + int result = ArrowSchemaSetType(schema, nanoarrow_type); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetType() failed for type %s", + ArrowTypeString(nanoarrow_type)); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeInt(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Int_table_t) type = (ns(Int_table_t))type_generic; + + int is_signed = ns(Int_is_signed_get(type)); + int bitwidth = ns(Int_bitWidth_get(type)); + int nanoarrow_type = NANOARROW_TYPE_UNINITIALIZED; + + if (is_signed) { + switch (bitwidth) { + case 8: + nanoarrow_type = NANOARROW_TYPE_INT8; + break; + case 16: + nanoarrow_type = NANOARROW_TYPE_INT16; + break; + case 32: + nanoarrow_type = NANOARROW_TYPE_INT32; + break; + case 64: + nanoarrow_type = NANOARROW_TYPE_INT64; + break; + default: + ArrowErrorSet(error, + "Expected signed int bitwidth of 8, 16, 32, or 64 but got %d", + bitwidth); + return EINVAL; + } + } else { + switch (bitwidth) { + case 8: + nanoarrow_type = NANOARROW_TYPE_UINT8; + break; + case 16: + nanoarrow_type = NANOARROW_TYPE_UINT16; + break; + case 32: + nanoarrow_type = NANOARROW_TYPE_UINT32; + break; + case 64: + nanoarrow_type = NANOARROW_TYPE_UINT64; + break; + default: + ArrowErrorSet(error, + "Expected unsigned int bitwidth of 8, 16, 32, or 64 but got %d", + bitwidth); + return EINVAL; + } + } + + return ArrowIpcDecoderSetTypeSimple(schema, nanoarrow_type, error); +} + +static int ArrowIpcDecoderSetTypeFloatingPoint(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(FloatingPoint_table_t) type = (ns(FloatingPoint_table_t))type_generic; + int precision = ns(FloatingPoint_precision(type)); + switch (precision) { + case ns(Precision_HALF): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_HALF_FLOAT, error); + case ns(Precision_SINGLE): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_FLOAT, error); + case ns(Precision_DOUBLE): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_DOUBLE, error); + default: + ArrowErrorSet(error, "Unexpected FloatingPoint Precision value: %d", precision); + return EINVAL; + } +} + +static int ArrowIpcDecoderSetTypeDecimal(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Decimal_table_t) type = (ns(Decimal_table_t))type_generic; + int scale = ns(Decimal_scale(type)); + int precision = ns(Decimal_precision(type)); + int bitwidth = ns(Decimal_bitWidth(type)); + + int result; + switch (bitwidth) { + case 32: + result = + ArrowSchemaSetTypeDecimal(schema, NANOARROW_TYPE_DECIMAL32, precision, scale); + break; + case 64: + result = + ArrowSchemaSetTypeDecimal(schema, NANOARROW_TYPE_DECIMAL64, precision, scale); + break; + case 128: + result = + ArrowSchemaSetTypeDecimal(schema, NANOARROW_TYPE_DECIMAL128, precision, scale); + break; + case 256: + result = + ArrowSchemaSetTypeDecimal(schema, NANOARROW_TYPE_DECIMAL256, precision, scale); + break; + default: + ArrowErrorSet(error, "Unexpected Decimal bitwidth value: %d", bitwidth); + return EINVAL; + } + + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetTypeDecimal() failed"); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeFixedSizeBinary(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(FixedSizeBinary_table_t) type = (ns(FixedSizeBinary_table_t))type_generic; + int fixed_size = ns(FixedSizeBinary_byteWidth(type)); + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowSchemaSetTypeFixedSize(schema, NANOARROW_TYPE_FIXED_SIZE_BINARY, fixed_size), + error); + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeDate(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Date_table_t) type = (ns(Date_table_t))type_generic; + int date_unit = ns(Date_unit(type)); + switch (date_unit) { + case ns(DateUnit_DAY): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_DATE32, error); + case ns(DateUnit_MILLISECOND): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_DATE64, error); + default: + ArrowErrorSet(error, "Unexpected Date DateUnit value: %d", (int)date_unit); + return EINVAL; + } +} + +static int ArrowIpcDecoderSetTypeTime(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Time_table_t) type = (ns(Time_table_t))type_generic; + int time_unit = ns(Time_unit(type)); + int bitwidth = ns(Time_bitWidth(type)); + int nanoarrow_type; + + switch (time_unit) { + case ns(TimeUnit_SECOND): + case ns(TimeUnit_MILLISECOND): + if (bitwidth != 32) { + ArrowErrorSet(error, "Expected bitwidth of 32 for Time TimeUnit %s but found %d", + ns(TimeUnit_name(ns(Time_unit(type)))), bitwidth); + return EINVAL; + } + + nanoarrow_type = NANOARROW_TYPE_TIME32; + break; + + case ns(TimeUnit_MICROSECOND): + case ns(TimeUnit_NANOSECOND): + if (bitwidth != 64) { + ArrowErrorSet(error, "Expected bitwidth of 64 for Time TimeUnit %s but found %d", + ns(TimeUnit_name(ns(Time_unit(type)))), bitwidth); + return EINVAL; + } + + nanoarrow_type = NANOARROW_TYPE_TIME64; + break; + + default: + ArrowErrorSet(error, "Unexpected Time TimeUnit value: %d", time_unit); + return EINVAL; + } + + int result = ArrowSchemaSetTypeDateTime(schema, nanoarrow_type, time_unit, NULL); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetTypeDateTime() failed"); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeTimestamp(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Timestamp_table_t) type = (ns(Timestamp_table_t))type_generic; + int time_unit = ns(Timestamp_unit(type)); + + const char* timezone = ""; + if (ns(Timestamp_timezone_is_present(type))) { + timezone = ns(Timestamp_timezone_get(type)); + } + + int result = + ArrowSchemaSetTypeDateTime(schema, NANOARROW_TYPE_TIMESTAMP, time_unit, timezone); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetTypeDateTime() failed"); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeDuration(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Duration_table_t) type = (ns(Duration_table_t))type_generic; + int time_unit = ns(Duration_unit(type)); + + int result = + ArrowSchemaSetTypeDateTime(schema, NANOARROW_TYPE_DURATION, time_unit, NULL); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetTypeDateTime() failed"); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeInterval(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Interval_table_t) type = (ns(Interval_table_t))type_generic; + int interval_unit = ns(Interval_unit(type)); + + switch (interval_unit) { + case ns(IntervalUnit_YEAR_MONTH): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_INTERVAL_MONTHS, error); + case ns(IntervalUnit_DAY_TIME): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_INTERVAL_DAY_TIME, + error); + case ns(IntervalUnit_MONTH_DAY_NANO): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO, + error); + default: + ArrowErrorSet(error, "Unexpected Interval unit value: %d", interval_unit); + return EINVAL; + } +} + +// We can't quite use nanoarrow's built-in SchemaSet functions for nested types +// because the IPC format allows modifying some of the defaults those functions assume. +// In particular, the allocate + initialize children step is handled outside these +// setters. +static int ArrowIpcDecoderSetTypeSimpleNested(struct ArrowSchema* schema, + const char* format, + struct ArrowError* error) { + int result = ArrowSchemaSetFormat(schema, format); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetFormat('%s') failed", format); + return result; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeFixedSizeList(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(FixedSizeList_table_t) type = (ns(FixedSizeList_table_t))type_generic; + int32_t fixed_size = ns(FixedSizeList_listSize(type)); + + char fixed_size_str[128]; + int n_chars = snprintf(fixed_size_str, 128, "+w:%d", fixed_size); + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + + fixed_size_str[n_chars] = '\0'; + return ArrowIpcDecoderSetTypeSimpleNested(schema, fixed_size_str, error); +} + +static int ArrowIpcDecoderSetTypeMap(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + struct ArrowError* error) { + ns(Map_table_t) type = (ns(Map_table_t))type_generic; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderSetTypeSimpleNested(schema, "+m", error)); + + if (ns(Map_keysSorted(type))) { + schema->flags |= ARROW_FLAG_MAP_KEYS_SORTED; + } else { + schema->flags &= ~ARROW_FLAG_MAP_KEYS_SORTED; + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderSetTypeUnion(struct ArrowSchema* schema, + flatbuffers_generic_t type_generic, + int64_t n_children, struct ArrowError* error) { + ns(Union_table_t) type = (ns(Union_table_t))type_generic; + int union_mode = ns(Union_mode(type)); + + if (n_children < 0 || n_children > 127) { + ArrowErrorSet(error, + "Expected between 0 and 127 children for Union type but found %" PRId64, + n_children); + return EINVAL; + } + + // Max valid typeIds size is 127; the longest single ID that could be present here + // is -INT_MIN (11 chars). With commas and the prefix the max size would be + // 1527 characters. (Any ids outside the range 0...127 are unlikely to be valid + // elsewhere but they could in theory be present here). + char union_types_str[2048]; + memset(union_types_str, 0, sizeof(union_types_str)); + char* format_cursor = union_types_str; + int format_out_size = sizeof(union_types_str); + int n_chars = 0; + + switch (union_mode) { + case ns(UnionMode_Sparse): + n_chars = snprintf(format_cursor, format_out_size, "+us:"); + format_cursor += n_chars; + format_out_size -= n_chars; + break; + case ns(UnionMode_Dense): + n_chars = snprintf(format_cursor, format_out_size, "+ud:"); + format_cursor += n_chars; + format_out_size -= n_chars; + break; + default: + ArrowErrorSet(error, "Unexpected Union UnionMode value: %d", union_mode); + return EINVAL; + } + + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + + if (ns(Union_typeIds_is_present(type))) { + flatbuffers_int32_vec_t type_ids = ns(Union_typeIds(type)); + int64_t n_type_ids = flatbuffers_int32_vec_len(type_ids); + + if (n_type_ids != n_children) { + ArrowErrorSet(error, + "Expected between %" PRId64 " children for Union type with %" PRId64 + " typeIds but found %" PRId64, + n_type_ids, n_type_ids, n_children); + return EINVAL; + } + + if (n_type_ids > 0) { + n_chars = snprintf(format_cursor, format_out_size, "%d", + flatbuffers_int32_vec_at(type_ids, 0)); + format_cursor += n_chars; + format_out_size -= n_chars; + + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + + for (int64_t i = 1; i < n_type_ids; i++) { + n_chars = snprintf(format_cursor, format_out_size, ",%" PRId32, + flatbuffers_int32_vec_at(type_ids, i)); + format_cursor += n_chars; + format_out_size -= n_chars; + + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + } + } + } else if (n_children > 0) { + n_chars = snprintf(format_cursor, format_out_size, "0"); + format_cursor += n_chars; + format_out_size -= n_chars; + + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + + for (int64_t i = 1; i < n_children; i++) { + n_chars = snprintf(format_cursor, format_out_size, ",%" PRId64, i); + format_cursor += n_chars; + format_out_size -= n_chars; + + if (n_chars < 0) { + ArrowErrorSet(error, "snprintf() encoding error"); + return ERANGE; + } + } + } + + return ArrowIpcDecoderSetTypeSimpleNested(schema, union_types_str, error); +} + +static int ArrowIpcDecoderSetType(struct ArrowSchema* schema, ns(Field_table_t) field, + int64_t n_children, struct ArrowError* error) { + int type_type = ns(Field_type_type(field)); + switch (type_type) { + case ns(Type_Null): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_NA, error); + case ns(Type_Bool): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_BOOL, error); + case ns(Type_Int): + return ArrowIpcDecoderSetTypeInt(schema, ns(Field_type_get(field)), error); + case ns(Type_FloatingPoint): + return ArrowIpcDecoderSetTypeFloatingPoint(schema, ns(Field_type_get(field)), + error); + case ns(Type_Decimal): + return ArrowIpcDecoderSetTypeDecimal(schema, ns(Field_type_get(field)), error); + case ns(Type_Binary): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_BINARY, error); + case ns(Type_LargeBinary): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_LARGE_BINARY, error); + case ns(Type_FixedSizeBinary): + return ArrowIpcDecoderSetTypeFixedSizeBinary(schema, ns(Field_type_get(field)), + error); + case ns(Type_Utf8): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_STRING, error); + case ns(Type_LargeUtf8): + return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_LARGE_STRING, error); + case ns(Type_Date): + return ArrowIpcDecoderSetTypeDate(schema, ns(Field_type_get(field)), error); + case ns(Type_Time): + return ArrowIpcDecoderSetTypeTime(schema, ns(Field_type_get(field)), error); + case ns(Type_Timestamp): + return ArrowIpcDecoderSetTypeTimestamp(schema, ns(Field_type_get(field)), error); + case ns(Type_Duration): + return ArrowIpcDecoderSetTypeDuration(schema, ns(Field_type_get(field)), error); + case ns(Type_Interval): + return ArrowIpcDecoderSetTypeInterval(schema, ns(Field_type_get(field)), error); + case ns(Type_Struct_): + return ArrowIpcDecoderSetTypeSimpleNested(schema, "+s", error); + case ns(Type_List): + return ArrowIpcDecoderSetTypeSimpleNested(schema, "+l", error); + case ns(Type_LargeList): + return ArrowIpcDecoderSetTypeSimpleNested(schema, "+L", error); + case ns(Type_FixedSizeList): + return ArrowIpcDecoderSetTypeFixedSizeList(schema, ns(Field_type_get(field)), + error); + case ns(Type_Map): + return ArrowIpcDecoderSetTypeMap(schema, ns(Field_type_get(field)), error); + case ns(Type_Union): + return ArrowIpcDecoderSetTypeUnion(schema, ns(Field_type_get(field)), n_children, + error); + default: + ArrowErrorSet(error, "Unrecognized Field type with value %d", type_type); + return EINVAL; + } +} + +static int ArrowIpcDecoderSetChildren(struct ArrowSchema* schema, ns(Field_vec_t) fields, + struct ArrowError* error); + +static int ArrowIpcDecoderSetField(struct ArrowSchema* schema, ns(Field_table_t) field, + struct ArrowError* error) { + // No dictionary support yet + if (ns(Field_dictionary_is_present(field))) { + ArrowErrorSet(error, "Schema message field with DictionaryEncoding not supported"); + return ENOTSUP; + } + + int result; + if (ns(Field_name_is_present(field))) { + result = ArrowSchemaSetName(schema, ns(Field_name_get(field))); + } else { + result = ArrowSchemaSetName(schema, ""); + } + + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaSetName() failed"); + return result; + } + + // Sets the schema->format and validates type-related inconsistencies + // that might exist in the flatbuffer + ns(Field_vec_t) children = ns(Field_children(field)); + int64_t n_children = ns(Field_vec_len(children)); + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderSetType(schema, field, n_children, error)); + + // nanoarrow's type setters set the nullable flag by default, so we might + // have to unset it here. + if (ns(Field_nullable_get(field))) { + schema->flags |= ARROW_FLAG_NULLABLE; + } else { + schema->flags &= ~ARROW_FLAG_NULLABLE; + } + + // Children are defined separately in the flatbuffer, so we allocate, initialize + // and set them separately as well. + result = ArrowSchemaAllocateChildren(schema, n_children); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "ArrowSchemaAllocateChildren() failed"); + return result; + } + + for (int64_t i = 0; i < n_children; i++) { + ArrowSchemaInit(schema->children[i]); + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderSetChildren(schema, children, error)); + return ArrowIpcDecoderSetMetadata(schema, ns(Field_custom_metadata(field)), error); +} + +static int ArrowIpcDecoderSetChildren(struct ArrowSchema* schema, ns(Field_vec_t) fields, + struct ArrowError* error) { + int64_t n_fields = ns(Schema_vec_len(fields)); + + for (int64_t i = 0; i < n_fields; i++) { + ns(Field_table_t) field = ns(Field_vec_at(fields, i)); + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderSetField(schema->children[i], field, error)); + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderDecodeSchemaHeader(struct ArrowIpcDecoder* decoder, + flatbuffers_generic_t message_header, + struct ArrowError* error) { + ns(Schema_table_t) schema = (ns(Schema_table_t))message_header; + int endianness = ns(Schema_endianness(schema)); + switch (endianness) { + case ns(Endianness_Little): + decoder->endianness = NANOARROW_IPC_ENDIANNESS_LITTLE; + break; + case ns(Endianness_Big): + decoder->endianness = NANOARROW_IPC_ENDIANNESS_BIG; + break; + default: + ArrowErrorSet(error, + "Expected Schema endianness of 0 (little) or 1 (big) but got %d", + endianness); + return EINVAL; + } + + ns(Feature_vec_t) features = ns(Schema_features(schema)); + int64_t n_features = ns(Feature_vec_len(features)); + decoder->feature_flags = 0; + + for (int64_t i = 0; i < n_features; i++) { + ns(Feature_enum_t) feature = ns(Feature_vec_at(features, i)); + switch (feature) { + case ns(Feature_COMPRESSED_BODY): + decoder->feature_flags |= NANOARROW_IPC_FEATURE_COMPRESSED_BODY; + break; + case ns(Feature_DICTIONARY_REPLACEMENT): + decoder->feature_flags |= NANOARROW_IPC_FEATURE_DICTIONARY_REPLACEMENT; + break; + default: + ArrowErrorSet(error, "Unrecognized Schema feature with value %d", (int)feature); + return EINVAL; + } + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderDecodeRecordBatchHeader(struct ArrowIpcDecoder* decoder, + flatbuffers_generic_t message_header, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + ns(RecordBatch_table_t) batch = (ns(RecordBatch_table_t))message_header; + + ns(FieldNode_vec_t) fields = ns(RecordBatch_nodes(batch)); + ns(Buffer_vec_t) buffers = ns(RecordBatch_buffers(batch)); + int64_t n_fields = ns(FieldNode_vec_len(fields)); + int64_t n_buffers = ns(Buffer_vec_len(buffers)); + + // Check field node and buffer count. We have one more field and buffer + // because we count the root struct and the flatbuffer message does not. + if ((n_fields + 1) != private_data->n_fields) { + ArrowErrorSet(error, "Expected %" PRId64 " field nodes in message but found %" PRId64, + private_data->n_fields - 1, n_fields); + return EINVAL; + } + + int64_t n_expected_buffers = private_data->n_buffers; + if (decoder->metadata_version < NANOARROW_IPC_METADATA_VERSION_V5) { + // Unions had null buffers before arrow 1.0, so expect one extra buffer per union + // field + n_expected_buffers += private_data->n_union_fields; + } + + if ((n_buffers + 1) != n_expected_buffers) { + ArrowErrorSet(error, "Expected %" PRId64 " buffers in message but found %" PRId64, + n_expected_buffers - 1, n_buffers); + return EINVAL; + } + + if (ns(RecordBatch_compression_is_present(batch))) { + ns(BodyCompression_table_t) compression = ns(RecordBatch_compression(batch)); + ns(CompressionType_enum_t) codec = ns(BodyCompression_codec(compression)); + switch (codec) { + case ns(CompressionType_LZ4_FRAME): + decoder->codec = NANOARROW_IPC_COMPRESSION_TYPE_LZ4_FRAME; + break; + case ns(CompressionType_ZSTD): + decoder->codec = NANOARROW_IPC_COMPRESSION_TYPE_ZSTD; + break; + default: + ArrowErrorSet(error, "Unrecognized RecordBatch BodyCompression codec value: %d", + (int)codec); + return EINVAL; + } + } else { + decoder->codec = NANOARROW_IPC_COMPRESSION_TYPE_NONE; + } + + // Copying field node and buffer information is separate so as only to pay for the + // nodes that are actually accessed. + return NANOARROW_OK; +} + +// Wipes any "current message" fields before moving on to a new message +static inline void ArrowIpcDecoderResetHeaderInfo(struct ArrowIpcDecoder* decoder) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + decoder->message_type = 0; + decoder->metadata_version = 0; + decoder->endianness = 0; + decoder->feature_flags = 0; + decoder->codec = 0; + decoder->header_size_bytes = 0; + decoder->body_size_bytes = 0; + decoder->footer = NULL; + ArrowIpcFooterReset(&private_data->footer); + private_data->last_message = NULL; +} + +// Returns NANOARROW_OK if data is large enough to read the first 8 bytes +// of the message header, ESPIPE if reading more data might help, or EINVAL if the content +// is not valid. Advances the input ArrowBufferView by prefix_size (8 bytes or 4 bytes if +// the message is pre-0.15 and has no continuation). Sets decoder->header_size_bytes +// to the flatbuffers length plus the prefix_size. +static inline int ArrowIpcDecoderReadHeaderPrefix(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView* data_mut, + int32_t* prefix_size_bytes, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + if (data_mut->size_bytes < 8) { + ArrowErrorSet(error, + "Expected data of at least 8 bytes but only %" PRId64 " bytes remain", + data_mut->size_bytes); + return ESPIPE; + } + + int swap_endian = private_data->system_endianness == NANOARROW_IPC_ENDIANNESS_BIG; + int32_t continuation = ArrowIpcReadInt32LE(data_mut, swap_endian); + int32_t length; + if ((uint32_t)continuation != 0xFFFFFFFF) { + if (continuation < 0) { + ArrowErrorSet(error, "Expected 0xFFFFFFFF at start of message but found 0x%08X", + (unsigned int)continuation); + return EINVAL; + } + // Tolerate pre-0.15 encapsulated messages which only had the length prefix + length = continuation; + *prefix_size_bytes = sizeof(length); + } else { + length = ArrowIpcReadInt32LE(data_mut, swap_endian); + *prefix_size_bytes = sizeof(continuation) + sizeof(length); + } + decoder->header_size_bytes = *prefix_size_bytes + length; + + if (length < 0) { + ArrowErrorSet(error, + "Expected message size > 0 but found message size of %" PRId32 " bytes", + length); + return EINVAL; + } + + if (length == 0) { + ArrowErrorSet(error, "End of Arrow stream"); + return ENODATA; + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderPeekHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + int32_t* prefix_size_bytes, + struct ArrowError* error) { + ArrowIpcDecoderResetHeaderInfo(decoder); + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderReadHeaderPrefix(decoder, &data, prefix_size_bytes, error)); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderVerifyHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + ArrowIpcDecoderResetHeaderInfo(decoder); + int32_t prefix_size_bytes; + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderReadHeaderPrefix(decoder, &data, &prefix_size_bytes, error)); + + // Check that data contains at least the entire header (return ESPIPE to signal + // that reading more data may help). + if (data.size_bytes < (int64_t)decoder->header_size_bytes - prefix_size_bytes) { + ArrowErrorSet(error, + "Expected >= %d bytes of remaining data but found %" PRId64 + " bytes in buffer", + decoder->header_size_bytes, data.size_bytes + prefix_size_bytes); + return ESPIPE; + } + + // Run flatbuffers verification + enum flatcc_verify_error_no verify_error = + ns(Message_verify_as_root(data.data.as_uint8, + decoder->header_size_bytes - prefix_size_bytes); + if (verify_error != flatcc_verify_ok)) { + ArrowErrorSet(error, "Message flatbuffer verification failed (%d) %s", + (int)verify_error, flatcc_verify_error_string(verify_error)); + return EINVAL; + } + + // Read some basic information from the message + ns(Message_table_t) message = ns(Message_as_root(data.data.as_uint8)); + decoder->metadata_version = ns(Message_version(message)); + decoder->message_type = ns(Message_header_type(message)); + decoder->body_size_bytes = ns(Message_bodyLength(message)); + + private_data->last_message = ns(Message_header_get(message)); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderPeekFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + ArrowIpcDecoderResetHeaderInfo(decoder); + if (data.size_bytes < (int)strlen(NANOARROW_IPC_MAGIC) + (int)sizeof(int32_t)) { + ArrowErrorSet(error, + "Expected data of at least 10 bytes but only %" PRId64 + " bytes are available", + data.size_bytes); + return ESPIPE; + } + + const char* data_end = data.data.as_char + data.size_bytes; + const char* magic = data_end - strlen(NANOARROW_IPC_MAGIC); + const char* footer_size_data = magic - sizeof(int32_t); + + if (memcmp(magic, NANOARROW_IPC_MAGIC, strlen(NANOARROW_IPC_MAGIC)) != 0) { + ArrowErrorSet(error, "Expected file to end with ARROW1 but got %s", data_end); + return EINVAL; + } + + int32_t footer_size; + memcpy(&footer_size, footer_size_data, sizeof(footer_size)); + if (private_data->system_endianness == NANOARROW_IPC_ENDIANNESS_BIG) { + footer_size = bswap32(footer_size); + } + + if (footer_size < 0) { + ArrowErrorSet(error, "Expected footer size > 0 but found footer size of %d bytes", + footer_size); + return EINVAL; + } + + decoder->header_size_bytes = footer_size; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderVerifyFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderPeekFooter(decoder, data, error)); + + // Check that data contains at least the entire footer (return ESPIPE to signal + // that reading more data may help). + int32_t footer_and_size_and_magic_size = + decoder->header_size_bytes + sizeof(int32_t) + (int)strlen(NANOARROW_IPC_MAGIC); + if (data.size_bytes < footer_and_size_and_magic_size) { + ArrowErrorSet(error, + "Expected >= %d bytes of data but only %" PRId64 + " bytes are in the buffer", + footer_and_size_and_magic_size, data.size_bytes); + return ESPIPE; + } + + const uint8_t* footer_data = + data.data.as_uint8 + data.size_bytes - footer_and_size_and_magic_size; + + // Run flatbuffers verification + enum flatcc_verify_error_no verify_error = + ns(Footer_verify_as_root(footer_data, decoder->header_size_bytes)); + if (verify_error != flatcc_verify_ok) { + ArrowErrorSet(error, "Footer flatbuffer verification failed (%d) %s", + (int)verify_error, flatcc_verify_error_string(verify_error)); + return EINVAL; + } + + // Read some basic information from the message + ns(Footer_table_t) footer = ns(Footer_as_root(footer_data)); + if (ns(Footer_schema(footer)) == NULL) { + ArrowErrorSet(error, "Footer has no schema"); + return EINVAL; + } + + decoder->metadata_version = ns(Footer_version(footer)); + decoder->body_size_bytes = 0; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderDecodeHeader(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + ArrowIpcDecoderResetHeaderInfo(decoder); + int32_t prefix_size_bytes; + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderReadHeaderPrefix(decoder, &data, &prefix_size_bytes, error)); + + // Check that data contains at least the entire header (return ESPIPE to signal + // that reading more data may help). + if (data.size_bytes < (int64_t)decoder->header_size_bytes - prefix_size_bytes) { + ArrowErrorSet(error, + "Expected >= %d bytes of remaining data but found %" PRId64 + " bytes in buffer", + decoder->header_size_bytes, data.size_bytes + prefix_size_bytes); + return ESPIPE; + } + + ns(Message_table_t) message = ns(Message_as_root(data.data.as_uint8)); + if (!message) { + return EINVAL; + } + + // Read some basic information from the message + decoder->metadata_version = ns(Message_version(message)); + decoder->message_type = ns(Message_header_type(message)); + decoder->body_size_bytes = ns(Message_bodyLength(message)); + + switch (decoder->metadata_version) { + case ns(MetadataVersion_V4): + case ns(MetadataVersion_V5): + break; + ArrowErrorSet(error, "Expected metadata version V4 or V5 but found %s", + ns(MetadataVersion_name(ns(Message_version(message))))); + return EINVAL; + case ns(MetadataVersion_V1): + case ns(MetadataVersion_V2): + case ns(MetadataVersion_V3): + default: + ArrowErrorSet(error, "Unexpected value for Message metadata version (%d)", + decoder->metadata_version); + return EINVAL; + } + + flatbuffers_generic_t message_header = ns(Message_header_get(message)); + switch (decoder->message_type) { + case ns(MessageHeader_Schema): + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderDecodeSchemaHeader(decoder, message_header, error)); + break; + case ns(MessageHeader_RecordBatch): + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderDecodeRecordBatchHeader(decoder, message_header, error)); + break; + case ns(MessageHeader_DictionaryBatch): + case ns(MessageHeader_Tensor): + case ns(MessageHeader_SparseTensor): + ArrowErrorSet(error, "Unsupported message type: '%s'", + ns(MessageHeader_type_name(ns(Message_header_type(message))))); + return ENOTSUP; + default: + ArrowErrorSet(error, "Unknown message type: %d", (int)(decoder->message_type)); + return EINVAL; + } + + private_data->last_message = message_header; + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcDecoderDecodeSchemaImpl(ns(Schema_table_t) schema, + struct ArrowSchema* out, + struct ArrowError* error) { + ArrowSchemaInit(out); + // Top-level batch schema is typically non-nullable + out->flags = 0; + + ns(Field_vec_t) fields = ns(Schema_fields(schema)); + int64_t n_fields = ns(Schema_vec_len(fields)); + + ArrowErrorCode result = ArrowSchemaSetTypeStruct(out, n_fields); + if (result != NANOARROW_OK) { + ArrowErrorSet(error, "Failed to allocate struct schema with %" PRId64 " children", + n_fields); + return result; + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderSetChildren(out, fields, error)); + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderSetMetadata(out, ns(Schema_custom_metadata(schema)), error)); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderDecodeSchema(struct ArrowIpcDecoder* decoder, + struct ArrowSchema* out, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + if (private_data->last_message == NULL || + decoder->message_type != NANOARROW_IPC_MESSAGE_TYPE_SCHEMA) { + ArrowErrorSet(error, "decoder did not just decode a Schema message"); + return EINVAL; + } + + struct ArrowSchema tmp; + ArrowErrorCode result = ArrowIpcDecoderDecodeSchemaImpl( + (ns(Schema_table_t))private_data->last_message, &tmp, error); + + if (result != NANOARROW_OK) { + ArrowSchemaRelease(&tmp); + return result; + } + ArrowSchemaMove(&tmp, out); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderDecodeFooter(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView data, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + int32_t footer_and_size_and_magic_size = + decoder->header_size_bytes + sizeof(int32_t) + (int)strlen(NANOARROW_IPC_MAGIC); + const uint8_t* footer_data = + data.data.as_uint8 + data.size_bytes - footer_and_size_and_magic_size; + ns(Footer_table_t) footer = ns(Footer_as_root(footer_data)); + + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderDecodeSchemaHeader(decoder, ns(Footer_schema(footer)), error)); + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeSchemaImpl( + ns(Footer_schema(footer)), &private_data->footer.schema, error)); + + ns(Block_vec_t) blocks = ns(Footer_recordBatches(footer)); + int64_t n = ns(Block_vec_len(blocks)); + NANOARROW_RETURN_NOT_OK(ArrowBufferResize(&private_data->footer.record_batch_blocks, + sizeof(struct ArrowIpcFileBlock) * n, + /*shrink_to_fit=*/0)); + struct ArrowIpcFileBlock* record_batches = + (struct ArrowIpcFileBlock*)private_data->footer.record_batch_blocks.data; + for (int64_t i = 0; i < n; i++) { + record_batches[i].offset = ns(Block_offset(blocks + i)); + record_batches[i].metadata_length = ns(Block_metaDataLength(blocks + i)); + record_batches[i].body_length = ns(Block_bodyLength(blocks + i)); + } + + decoder->footer = &private_data->footer; + return NANOARROW_OK; +} + +static void ArrowIpcDecoderCountFields(struct ArrowSchema* schema, int64_t* n_fields) { + *n_fields += 1; + for (int64_t i = 0; i < schema->n_children; i++) { + ArrowIpcDecoderCountFields(schema->children[i], n_fields); + } +} + +static void ArrowIpcDecoderInitFields(struct ArrowIpcField* fields, + struct ArrowArrayView* array_view, + struct ArrowArray* array, int64_t* n_fields, + int64_t* n_buffers, int64_t* n_union_fields) { + struct ArrowIpcField* field = fields + (*n_fields); + field->array_view = array_view; + field->array = array; + field->buffer_offset = *n_buffers; + + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + *n_buffers += array_view->layout.buffer_type[i] != NANOARROW_BUFFER_TYPE_NONE; + } + *n_union_fields += array_view->storage_type == NANOARROW_TYPE_SPARSE_UNION || + array_view->storage_type == NANOARROW_TYPE_DENSE_UNION; + + *n_fields += 1; + + for (int64_t i = 0; i < array_view->n_children; i++) { + ArrowIpcDecoderInitFields(fields, array_view->children[i], array->children[i], + n_fields, n_buffers, n_union_fields); + } +} + +ArrowErrorCode ArrowIpcDecoderSetSchema(struct ArrowIpcDecoder* decoder, + struct ArrowSchema* schema, + struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + // Reset previously allocated schema-specific resources + private_data->n_buffers = 0; + private_data->n_fields = 0; + private_data->n_union_fields = 0; + ArrowArrayViewReset(&private_data->array_view); + if (private_data->array.release != NULL) { + ArrowArrayRelease(&private_data->array); + } + if (private_data->fields != NULL) { + ArrowFree(private_data->fields); + } + + // Allocate Array and ArrayView based on schema without moving the schema. + // This will fail if the schema is not valid. + NANOARROW_RETURN_NOT_OK( + ArrowArrayViewInitFromSchema(&private_data->array_view, schema, error)); + NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromArrayView(&private_data->array, + &private_data->array_view, error)); + + // Root must be a struct + if (private_data->array_view.storage_type != NANOARROW_TYPE_STRUCT) { + ArrowErrorSet(error, "schema must be a struct type"); + return EINVAL; + } + + // Walk tree and calculate how many fields we need to allocate + ArrowIpcDecoderCountFields(schema, &private_data->n_fields); + private_data->fields = (struct ArrowIpcField*)ArrowMalloc(private_data->n_fields * + sizeof(struct ArrowIpcField)); + if (private_data->fields == NULL) { + ArrowErrorSet(error, "Failed to allocate decoder->fields"); + return ENOMEM; + } + memset(private_data->fields, 0, private_data->n_fields * sizeof(struct ArrowIpcField)); + + // Init field information and calculate starting buffer offset for each + int64_t field_i = 0; + ArrowIpcDecoderInitFields(private_data->fields, &private_data->array_view, + &private_data->array, &field_i, &private_data->n_buffers, + &private_data->n_union_fields); + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderSetEndianness(struct ArrowIpcDecoder* decoder, + enum ArrowIpcEndianness endianness) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + switch (endianness) { + case NANOARROW_IPC_ENDIANNESS_UNINITIALIZED: + case NANOARROW_IPC_ENDIANNESS_LITTLE: + case NANOARROW_IPC_ENDIANNESS_BIG: + private_data->endianness = endianness; + return NANOARROW_OK; + default: + return EINVAL; + } +} + +/// \brief Information required to read and/or decompress a single buffer +/// +/// The RecordBatch message header contains a description of each buffer +/// in the message body. The ArrowIpcBufferSource is the parsed result of +/// a single buffer with compression and endian information such that the +/// original buffer can be reconstructed. +struct ArrowIpcBufferSource { + int64_t body_offset_bytes; + int64_t buffer_length_bytes; + enum ArrowIpcCompressionType codec; + enum ArrowType data_type; + int64_t element_size_bits; + int swap_endian; +}; + +/// \brief Materializing ArrowBuffer objects +/// +/// Given a description of where a buffer is located inside the message body, make +/// the ArrowBuffer that will be placed into the correct ArrowArray. The decoder +/// does not do any IO and does not make any assumptions about how or if the body +/// has been read into memory. This abstraction is currently internal and exists +/// to support the two obvious ways a user might go about this: (1) using a +/// non-owned view of memory that must be copied slice-wise or (2) adding a reference +/// to an ArrowIpcSharedBuffer and returning a slice of that memory. +struct ArrowIpcBufferFactory { + /// \brief User-defined callback to populate a buffer view + /// + /// At the time that this callback is called, the ArrowIpcBufferSource has been checked + /// to ensure that it is within the body size declared by the message header. A + /// possibly preallocated ArrowBuffer (dst) is provided, which implementations must use + /// if an allocation is required (in which case the view must be populated pointing to + /// the contents of the ArrowBuffer) If NANOARROW_OK is not returned, error must contain + /// a null-terminated message. + ArrowErrorCode (*make_buffer)(struct ArrowIpcBufferFactory* factory, + struct ArrowIpcBufferSource* src, + struct ArrowBufferView* dst_view, struct ArrowBuffer* dst, + struct ArrowError* error); + + /// \brief Caller provided decompressor instance to which any decompression requests + /// should be made. + struct ArrowIpcDecompressor* decompressor; + + /// \brief Caller-defined private data to be used in the callback. + /// + /// Usually this would be a description of where the body has been read into memory or + /// information required to do so. + void* private_data; +}; + +static ArrowErrorCode ArrowIpcDecompressBufferFromView( + struct ArrowIpcDecompressor* decompressor, + enum ArrowIpcCompressionType compression_type, struct ArrowBufferView src, + struct ArrowBuffer* dst, int* needs_decompression, struct ArrowError* error) { + if (src.size_bytes < (int64_t)sizeof(int64_t)) { + ArrowErrorSet( + error, + "Buffer size must be >= sizeof(int64_t) when buffer compression is enabled"); + return EINVAL; + } + + // When body compression is enabled, buffers are prefixed with a little endian + // signed 64-bit integer that is the uncompressed body length. + int64_t uncompressed_size; + memcpy(&uncompressed_size, src.data.data, sizeof(int64_t)); + if (ArrowIpcSystemEndianness() != NANOARROW_IPC_ENDIANNESS_LITTLE) { + uncompressed_size = (int64_t)bswap64(uncompressed_size); + } + + // Sentinel for "body compression was enabled but this buffer is not compressed" is -1 + if (uncompressed_size == -1) { + *needs_decompression = 0; + return NANOARROW_OK; + } + + if (uncompressed_size < 0) { + ArrowErrorSet(error, + "Decompressed buffer size must be -1 or >= 0 bytes but was %" PRId64, + uncompressed_size); + return EINVAL; + } + + // Prepare the source and destination + src.data.as_uint8 += sizeof(int64_t); + src.size_bytes -= sizeof(int64_t); + NANOARROW_RETURN_NOT_OK(ArrowBufferResize(dst, uncompressed_size, 0)); + + // Add the task to the decompressor (this may execute synchronously for some + // decompressors) + NANOARROW_RETURN_NOT_OK(decompressor->decompress_add( + decompressor, compression_type, src, dst->data, uncompressed_size, error)); + + // Pass on that we handled the decompression + *needs_decompression = 1; + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcMakeBufferFromView(struct ArrowIpcBufferFactory* factory, + struct ArrowIpcBufferSource* src, + struct ArrowBufferView* dst_view, + struct ArrowBuffer* dst, + struct ArrowError* error) { + struct ArrowBufferView* body = (struct ArrowBufferView*)factory->private_data; + + struct ArrowBufferView src_view; + src_view.data.as_uint8 = body->data.as_uint8 + src->body_offset_bytes; + src_view.size_bytes = src->buffer_length_bytes; + + int needs_decompression = 0; + int uncompressed_data_offset = 0; + if (src->codec != NANOARROW_IPC_COMPRESSION_TYPE_NONE) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecompressBufferFromView( + factory->decompressor, src->codec, src_view, dst, &needs_decompression, error)); + uncompressed_data_offset += sizeof(int64_t); + } + + if (!needs_decompression) { + *dst_view = src_view; + dst_view->data.as_uint8 += uncompressed_data_offset; + dst_view->size_bytes -= uncompressed_data_offset; + } else { + dst_view->data.data = dst->data; + dst_view->size_bytes = dst->size_bytes; + } + + return NANOARROW_OK; +} + +static struct ArrowIpcBufferFactory ArrowIpcBufferFactoryFromView( + struct ArrowBufferView* buffer_view) { + struct ArrowIpcBufferFactory out; + out.make_buffer = &ArrowIpcMakeBufferFromView; + out.decompressor = NULL; + out.private_data = buffer_view; + return out; +} + +static ArrowErrorCode ArrowIpcMakeBufferFromShared(struct ArrowIpcBufferFactory* factory, + struct ArrowIpcBufferSource* src, + struct ArrowBufferView* dst_view, + struct ArrowBuffer* dst, + struct ArrowError* error) { + struct ArrowIpcSharedBuffer* shared = + (struct ArrowIpcSharedBuffer*)factory->private_data; + + int needs_decompression = 0; + int uncompressed_data_offset = 0; + if (src->codec != NANOARROW_IPC_COMPRESSION_TYPE_NONE) { + struct ArrowBufferView src_view; + src_view.data.as_uint8 = shared->private_src.data + src->body_offset_bytes; + src_view.size_bytes = src->buffer_length_bytes; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecompressBufferFromView( + factory->decompressor, src->codec, src_view, dst, &needs_decompression, error)); + uncompressed_data_offset += sizeof(int64_t); + } + + if (!needs_decompression) { + ArrowBufferReset(dst); + ArrowIpcSharedBufferClone(shared, dst); + dst->data += src->body_offset_bytes + uncompressed_data_offset; + dst->size_bytes = src->buffer_length_bytes - uncompressed_data_offset; + } + + dst_view->data.data = dst->data; + dst_view->size_bytes = dst->size_bytes; + return NANOARROW_OK; +} + +static struct ArrowIpcBufferFactory ArrowIpcBufferFactoryFromShared( + struct ArrowIpcSharedBuffer* shared) { + struct ArrowIpcBufferFactory out; + out.make_buffer = &ArrowIpcMakeBufferFromShared; + out.decompressor = NULL; + out.private_data = shared; + return out; +} + +// Just for the purposes of endian-swapping +struct ArrowIpcIntervalMonthDayNano { + uint32_t months; + uint32_t days; + uint64_t ns; +}; + +static int ArrowIpcDecoderSwapEndian(struct ArrowIpcBufferSource* src, + struct ArrowBufferView* out_view, + struct ArrowBuffer* dst, struct ArrowError* error) { + NANOARROW_DCHECK(out_view->size_bytes > 0); + NANOARROW_DCHECK(out_view->data.data != NULL); + + // Some buffer data types don't need any endian swapping + switch (src->data_type) { + case NANOARROW_TYPE_BOOL: + case NANOARROW_TYPE_INT8: + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_STRING: + case NANOARROW_TYPE_BINARY: + return NANOARROW_OK; + default: + break; + } + + // Make sure dst is not a shared buffer that we can't modify + struct ArrowBuffer tmp; + ArrowBufferInit(&tmp); + + if (dst->allocator.private_data != NULL) { + ArrowBufferMove(dst, &tmp); + ArrowBufferInit(dst); + } + + if (dst->size_bytes == 0) { + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(dst, out_view->size_bytes)); + dst->size_bytes = out_view->size_bytes; + } + + switch (src->data_type) { + case NANOARROW_TYPE_DECIMAL32: { + uint32_t* ptr = (uint32_t*)dst->data; + for (int64_t i = 0; i < (dst->size_bytes / 4); i++) { + ptr[i] = bswap32(out_view->data.as_uint32[i]); + } + break; + } + case NANOARROW_TYPE_DECIMAL64: + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_DECIMAL256: { + const uint64_t* ptr_src = out_view->data.as_uint64; + uint64_t* ptr_dst = (uint64_t*)dst->data; + uint64_t words[4]; + int n_words = (int)(src->element_size_bits / 64); + NANOARROW_DCHECK(n_words == 1 || n_words == 2 || n_words == 4); + + for (int64_t i = 0; i < (dst->size_bytes / n_words / 8); i++) { + for (int j = 0; j < n_words; j++) { + words[j] = bswap64(ptr_src[i * n_words + j]); + } + + for (int j = 0; j < n_words; j++) { + ptr_dst[i * n_words + j] = words[n_words - j - 1]; + } + } + break; + } + case NANOARROW_TYPE_INTERVAL_DAY_TIME: { + uint32_t* ptr = (uint32_t*)dst->data; + for (int64_t i = 0; i < (dst->size_bytes / 4); i++) { + ptr[i] = bswap32(out_view->data.as_uint32[i]); + } + break; + } + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: { + const uint8_t* ptr_src = out_view->data.as_uint8; + uint8_t* ptr_dst = dst->data; + int item_size_bytes = 16; + struct ArrowIpcIntervalMonthDayNano item; + for (int64_t i = 0; i < (dst->size_bytes / item_size_bytes); i++) { + memcpy(&item, ptr_src + i * item_size_bytes, item_size_bytes); + item.months = bswap32(item.months); + item.days = bswap32(item.days); + item.ns = bswap64(item.ns); + memcpy(ptr_dst + i * item_size_bytes, &item, item_size_bytes); + } + break; + } + default: + switch (src->element_size_bits) { + case 16: { + uint16_t* ptr = (uint16_t*)dst->data; + for (int64_t i = 0; i < (dst->size_bytes / 2); i++) { + ptr[i] = bswap16(out_view->data.as_uint16[i]); + } + break; + } + case 32: { + uint32_t* ptr = (uint32_t*)dst->data; + for (int64_t i = 0; i < (dst->size_bytes / 4); i++) { + ptr[i] = bswap32(out_view->data.as_uint32[i]); + } + break; + } + case 64: { + uint64_t* ptr = (uint64_t*)dst->data; + for (int64_t i = 0; i < (dst->size_bytes / 8); i++) { + ptr[i] = bswap64(out_view->data.as_uint64[i]); + } + break; + } + default: + ArrowErrorSet( + error, "Endian swapping for element bitwidth %" PRId64 " is not supported", + src->element_size_bits); + return ENOTSUP; + } + break; + } + + ArrowBufferReset(&tmp); + out_view->data.data = dst->data; + return NANOARROW_OK; +} + +struct ArrowIpcArraySetter { + ns(FieldNode_vec_t) fields; + int64_t field_i; + ns(Buffer_vec_t) buffers; + int64_t buffer_i; + int64_t body_size_bytes; + struct ArrowIpcBufferSource src; + struct ArrowIpcBufferFactory factory; + enum ArrowIpcMetadataVersion version; +}; + +static int ArrowIpcDecoderMakeBuffer(struct ArrowIpcArraySetter* setter, int64_t offset, + int64_t length, struct ArrowBufferView* out_view, + struct ArrowBuffer* out, struct ArrowError* error) { + out_view->data.data = NULL; + out_view->size_bytes = 0; + + if (length == 0) { + return NANOARROW_OK; + } + + // Check that this buffer fits within the body + int64_t buffer_start = offset; + int64_t buffer_end = buffer_start + length; + if (buffer_start < 0 || buffer_end > setter->body_size_bytes) { + ArrowErrorSet(error, + "Buffer requires body offsets [%" PRId64 "..%" PRId64 + ") but body has size %" PRId64, + buffer_start, buffer_end, setter->body_size_bytes); + return EINVAL; + } + + setter->src.body_offset_bytes = offset; + setter->src.buffer_length_bytes = length; + NANOARROW_RETURN_NOT_OK( + setter->factory.make_buffer(&setter->factory, &setter->src, out_view, out, error)); + + if (setter->src.swap_endian) { + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderSwapEndian(&setter->src, out_view, out, error)); + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderWalkGetArray(struct ArrowArrayView* array_view, + struct ArrowArray* array, struct ArrowArray* out, + struct ArrowError* error) { + out->length = array_view->length; + out->null_count = array_view->null_count; + + for (int64_t i = 0; i < array->n_buffers; i++) { + struct ArrowBufferView view = array_view->buffer_views[i]; + struct ArrowBuffer* scratch_buffer = ArrowArrayBuffer(array, i); + struct ArrowBuffer* buffer_out = ArrowArrayBuffer(out, i); + + // If the scratch buffer was used, move it to the final array. Otherwise, + // copy the view. + if (scratch_buffer->size_bytes == 0) { + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendBufferView(buffer_out, view)); + } else if (scratch_buffer->data == view.data.as_uint8) { + ArrowBufferMove(scratch_buffer, buffer_out); + } else { + ArrowErrorSet( + error, + "Internal: scratch buffer was used but doesn't point to the same data as view"); + return EINVAL; + } + } + + for (int64_t i = 0; i < array->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderWalkGetArray( + array_view->children[i], array->children[i], out->children[i], error)); + } + + return NANOARROW_OK; +} + +static int ArrowIpcDecoderWalkSetArrayView(struct ArrowIpcArraySetter* setter, + struct ArrowArrayView* array_view, + struct ArrowArray* array, + struct ArrowError* error) { + ns(FieldNode_struct_t) field = + ns(FieldNode_vec_at(setter->fields, (size_t)setter->field_i)); + array_view->length = ns(FieldNode_length(field)); + array_view->null_count = ns(FieldNode_null_count(field)); + setter->field_i += 1; + + if (array_view->storage_type == NANOARROW_TYPE_SPARSE_UNION || + array_view->storage_type == NANOARROW_TYPE_DENSE_UNION) { + if (setter->version < NANOARROW_IPC_METADATA_VERSION_V5) { + ns(Buffer_struct_t) buffer = + ns(Buffer_vec_at(setter->buffers, (size_t)setter->buffer_i)); + if (ns(Buffer_length(buffer)) != 0) { + ArrowErrorSet(error, + "Cannot read pre-1.0.0 Union array with top-level validity bitmap"); + return EINVAL; + } + // skip the empty validity bitmap + setter->buffer_i += 1; + } + } + + for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) { + if (array_view->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_NONE) { + break; + } + + ns(Buffer_struct_t) buffer = + ns(Buffer_vec_at(setter->buffers, (size_t)setter->buffer_i)); + int64_t buffer_offset = ns(Buffer_offset(buffer)); + int64_t buffer_length = ns(Buffer_length(buffer)); + setter->buffer_i += 1; + + // Provide a buffer that will be used if any allocation has to occur + struct ArrowBuffer* buffer_dst = ArrowArrayBuffer(array, i); + + // Attempt to re-use any previous allocation unless this buffer is + // wrapping a custom allocator. + if (buffer_dst->allocator.private_data != NULL) { + ArrowBufferReset(buffer_dst); + } else { + buffer_dst->size_bytes = 0; + } + + setter->src.data_type = array_view->layout.buffer_data_type[i]; + setter->src.element_size_bits = array_view->layout.element_size_bits[i]; + + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderMakeBuffer(setter, buffer_offset, buffer_length, + &array_view->buffer_views[i], buffer_dst, error)); + } + + for (int64_t i = 0; i < array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderWalkSetArrayView( + setter, array_view->children[i], array->children[i], error)); + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcDecoderDecodeArrayInternal( + struct ArrowIpcDecoder* decoder, int64_t field_i, struct ArrowArray* out, + enum ArrowValidationLevel validation_level, struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + struct ArrowIpcField* root = private_data->fields + field_i + 1; + + if (field_i == -1) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayInitFromArrayView(out, &private_data->array_view, error)); + out->length = private_data->array_view.length; + out->null_count = private_data->array_view.null_count; + + for (int64_t i = 0; i < private_data->array_view.n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderWalkGetArray( + private_data->array_view.children[i], private_data->array.children[i], + out->children[i], error)); + } + + } else { + NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromArrayView(out, root->array_view, error)); + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderWalkGetArray(root->array_view, root->array, out, error)); + } + + // If validation is going to happen it has already occurred; however, the part of + // ArrowArrayFinishBuilding() that allocates a data buffer if the data buffer is + // NULL (required for compatibility with Arrow <= 9.0.0) assumes CPU data access + // and thus needs a validation level >= default. + if (validation_level >= NANOARROW_VALIDATION_LEVEL_DEFAULT) { + NANOARROW_RETURN_NOT_OK( + ArrowArrayFinishBuilding(out, NANOARROW_VALIDATION_LEVEL_DEFAULT, error)); + } else { + NANOARROW_RETURN_NOT_OK( + ArrowArrayFinishBuilding(out, NANOARROW_VALIDATION_LEVEL_NONE, error)); + } + + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcDecoderDecodeArrayViewInternal( + struct ArrowIpcDecoder* decoder, struct ArrowIpcBufferFactory factory, + int64_t field_i, struct ArrowArrayView** out_view, struct ArrowError* error) { + struct ArrowIpcDecoderPrivate* private_data = + (struct ArrowIpcDecoderPrivate*)decoder->private_data; + + if (private_data->last_message == NULL || + decoder->message_type != NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH) { + ArrowErrorSet(error, "decoder did not just decode a RecordBatch message"); + return EINVAL; + } + + // RecordBatch messages don't count the root node but decoder->fields does + // (decoder->fields[0] is the root field) + if (field_i + 1 >= private_data->n_fields) { + ArrowErrorSet(error, "cannot decode column %" PRId64 "; there are only %" PRId64, + field_i, private_data->n_fields - 1); + return EINVAL; + } + + ns(RecordBatch_table_t) batch = (ns(RecordBatch_table_t))private_data->last_message; + + struct ArrowIpcField* root = private_data->fields + field_i + 1; + + struct ArrowIpcArraySetter setter; + setter.fields = ns(RecordBatch_nodes(batch)); + setter.field_i = field_i; + setter.buffers = ns(RecordBatch_buffers(batch)); + setter.buffer_i = root->buffer_offset - 1; + setter.body_size_bytes = decoder->body_size_bytes; + setter.factory = factory; + setter.src.codec = decoder->codec; + setter.src.swap_endian = ArrowIpcDecoderNeedsSwapEndian(decoder); + setter.version = decoder->metadata_version; + + // If we are going to need a decompressor here, ensure the default one is + // initialized. + if (setter.src.codec != NANOARROW_IPC_COMPRESSION_TYPE_NONE) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderInitDecompressor(private_data)); + setter.factory.decompressor = &private_data->decompressor; + } + + // The flatbuffers FieldNode doesn't count the root struct so we have to loop over the + // children ourselves + if (field_i == -1) { + root->array_view->length = ns(RecordBatch_length(batch)); + root->array_view->null_count = 0; + setter.field_i++; + setter.buffer_i++; + + for (int64_t i = 0; i < root->array_view->n_children; i++) { + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderWalkSetArrayView( + &setter, root->array_view->children[i], root->array->children[i], error)); + } + } else { + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderWalkSetArrayView(&setter, root->array_view, root->array, error)); + } + + // If we decoded a compressed message, wait for any pending decompression tasks to + // complete. The default compressor already performed the decompression + if (setter.factory.decompressor != NULL) { + NANOARROW_RETURN_NOT_OK(setter.factory.decompressor->decompress_wait( + setter.factory.decompressor, -1, error)); + } + + *out_view = root->array_view; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderDecodeArrayView(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView body, int64_t i, + struct ArrowArrayView** out, + struct ArrowError* error) { + return ArrowIpcDecoderDecodeArrayViewInternal( + decoder, ArrowIpcBufferFactoryFromView(&body), i, out, error); +} + +ArrowErrorCode ArrowIpcDecoderDecodeArray(struct ArrowIpcDecoder* decoder, + struct ArrowBufferView body, int64_t i, + struct ArrowArray* out, + enum ArrowValidationLevel validation_level, + struct ArrowError* error) { + struct ArrowArrayView* array_view; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeArrayViewInternal( + decoder, ArrowIpcBufferFactoryFromView(&body), i, &array_view, error)); + + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidate(array_view, validation_level, error)); + + struct ArrowArray temp; + temp.release = NULL; + int result = + ArrowIpcDecoderDecodeArrayInternal(decoder, i, &temp, validation_level, error); + if (result != NANOARROW_OK && temp.release != NULL) { + ArrowArrayRelease(&temp); + } else if (result != NANOARROW_OK) { + return result; + } + + ArrowArrayMove(&temp, out); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcDecoderDecodeArrayFromShared( + struct ArrowIpcDecoder* decoder, struct ArrowIpcSharedBuffer* body, int64_t i, + struct ArrowArray* out, enum ArrowValidationLevel validation_level, + struct ArrowError* error) { + struct ArrowArrayView* array_view; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeArrayViewInternal( + decoder, ArrowIpcBufferFactoryFromShared(body), i, &array_view, error)); + + NANOARROW_RETURN_NOT_OK(ArrowArrayViewValidate(array_view, validation_level, error)); + + struct ArrowArray temp; + temp.release = NULL; + int result = + ArrowIpcDecoderDecodeArrayInternal(decoder, i, &temp, validation_level, error); + if (result != NANOARROW_OK && temp.release != NULL) { + ArrowArrayRelease(&temp); + } else if (result != NANOARROW_OK) { + return result; + } + + ArrowArrayMove(&temp, out); + return NANOARROW_OK; +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include + +#include "flatcc/flatcc_builder.h" + +#include "nanoarrow/nanoarrow.h" +#include "nanoarrow/nanoarrow_ipc.h" + +#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(org_apache_arrow_flatbuf, x) + +#define FLATCC_RETURN_UNLESS_0_NO_NS(x, error) \ + if ((x) != 0) { \ + ArrowErrorSet(error, "%s:%d: %s failed", __FILE__, __LINE__, #x); \ + return ENOMEM; \ + } + +#define FLATCC_RETURN_UNLESS_0(x, error) FLATCC_RETURN_UNLESS_0_NO_NS(ns(x), error) + +#define FLATCC_RETURN_IF_NULL(x, error) \ + if (!(x)) { \ + ArrowErrorSet(error, "%s:%d: %s was null", __FILE__, __LINE__, #x); \ + return ENOMEM; \ + } + +struct ArrowIpcEncoderPrivate { + flatcc_builder_t builder; + struct ArrowBuffer buffers; + struct ArrowBuffer nodes; + int encoding_footer; +}; + +ArrowErrorCode ArrowIpcEncoderInit(struct ArrowIpcEncoder* encoder) { + NANOARROW_DCHECK(encoder != NULL); + memset(encoder, 0, sizeof(struct ArrowIpcEncoder)); + encoder->private_data = ArrowMalloc(sizeof(struct ArrowIpcEncoderPrivate)); + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + if (private == NULL) { + return ENOMEM; + } + if (flatcc_builder_init(&private->builder) == -1) { + ArrowFree(private); + return ESPIPE; + } + private->encoding_footer = 0; + ArrowBufferInit(&private->buffers); + ArrowBufferInit(&private->nodes); + return NANOARROW_OK; +} + +void ArrowIpcEncoderReset(struct ArrowIpcEncoder* encoder) { + NANOARROW_DCHECK(encoder != NULL); + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + if (private != NULL) { + flatcc_builder_clear(&private->builder); + ArrowBufferReset(&private->nodes); + ArrowBufferReset(&private->buffers); + ArrowFree(private); + } + memset(encoder, 0, sizeof(struct ArrowIpcEncoder)); +} + +static ArrowErrorCode ArrowIpcEncoderWriteContinuationAndSize(struct ArrowBuffer* out, + size_t size) { + _NANOARROW_CHECK_UPPER_LIMIT(size, INT32_MAX); + NANOARROW_RETURN_NOT_OK(ArrowBufferAppendInt32(out, -1)); + + if (ArrowIpcSystemEndianness() == NANOARROW_IPC_ENDIANNESS_BIG) { + return ArrowBufferAppendInt32(out, (int32_t)bswap32((uint32_t)size)); + } else { + return ArrowBufferAppendInt32(out, (int32_t)size); + } +} + +ArrowErrorCode ArrowIpcEncoderFinalizeBuffer(struct ArrowIpcEncoder* encoder, + char encapsulate, struct ArrowBuffer* out) { + NANOARROW_DCHECK(encoder != NULL && encoder->private_data != NULL && out != NULL); + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + + size_t size = flatcc_builder_get_buffer_size(&private->builder); + + if (encapsulate) { + int64_t padded_size = _ArrowRoundUpToMultipleOf8(size); + NANOARROW_RETURN_NOT_OK( + ArrowBufferReserve(out, sizeof(int32_t) + sizeof(int32_t) + padded_size)); + NANOARROW_ASSERT_OK(ArrowIpcEncoderWriteContinuationAndSize(out, padded_size)); + } else { + NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(out, size)); + } + + if (size == 0) { + // Finalizing an empty flatcc_builder_t triggers an assertion + return NANOARROW_OK; + } + + void* data = + flatcc_builder_copy_buffer(&private->builder, out->data + out->size_bytes, size); + NANOARROW_DCHECK(data != NULL); + NANOARROW_UNUSED(data); + out->size_bytes += size; + + while (encapsulate && out->size_bytes % 8 != 0) { + // zero padding bytes, if any + out->data[out->size_bytes++] = 0; + } + + // don't deallocate yet, just wipe the builder's current Message + flatcc_builder_reset(&private->builder); + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncodeFieldType(flatcc_builder_t* builder, + const struct ArrowSchemaView* schema_view, + struct ArrowError* error) { + switch (schema_view->type) { + case NANOARROW_TYPE_NA: + FLATCC_RETURN_UNLESS_0(Field_type_Null_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_BOOL: + FLATCC_RETURN_UNLESS_0(Field_type_Bool_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_UINT8: + case NANOARROW_TYPE_INT8: + FLATCC_RETURN_UNLESS_0( + Field_type_Int_create(builder, 8, schema_view->type == NANOARROW_TYPE_INT8), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_UINT16: + case NANOARROW_TYPE_INT16: + FLATCC_RETURN_UNLESS_0( + Field_type_Int_create(builder, 16, schema_view->type == NANOARROW_TYPE_INT16), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_UINT32: + case NANOARROW_TYPE_INT32: + FLATCC_RETURN_UNLESS_0( + Field_type_Int_create(builder, 32, schema_view->type == NANOARROW_TYPE_INT32), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_UINT64: + case NANOARROW_TYPE_INT64: + FLATCC_RETURN_UNLESS_0( + Field_type_Int_create(builder, 64, schema_view->type == NANOARROW_TYPE_INT64), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_HALF_FLOAT: + FLATCC_RETURN_UNLESS_0(Field_type_FloatingPoint_create(builder, ns(Precision_HALF)), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_FLOAT: + FLATCC_RETURN_UNLESS_0( + Field_type_FloatingPoint_create(builder, ns(Precision_SINGLE)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DOUBLE: + FLATCC_RETURN_UNLESS_0( + Field_type_FloatingPoint_create(builder, ns(Precision_DOUBLE)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DECIMAL32: + case NANOARROW_TYPE_DECIMAL64: + case NANOARROW_TYPE_DECIMAL128: + case NANOARROW_TYPE_DECIMAL256: + FLATCC_RETURN_UNLESS_0( + Field_type_Decimal_create(builder, schema_view->decimal_precision, + schema_view->decimal_scale, + schema_view->decimal_bitwidth), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_STRING: + FLATCC_RETURN_UNLESS_0(Field_type_Utf8_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_LARGE_STRING: + FLATCC_RETURN_UNLESS_0(Field_type_LargeUtf8_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_BINARY: + FLATCC_RETURN_UNLESS_0(Field_type_Binary_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_LARGE_BINARY: + FLATCC_RETURN_UNLESS_0(Field_type_LargeBinary_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DATE32: + FLATCC_RETURN_UNLESS_0(Field_type_Date_create(builder, ns(DateUnit_DAY)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DATE64: + FLATCC_RETURN_UNLESS_0(Field_type_Date_create(builder, ns(DateUnit_MILLISECOND)), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_INTERVAL_MONTHS: + FLATCC_RETURN_UNLESS_0( + Field_type_Interval_create(builder, ns(IntervalUnit_YEAR_MONTH)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_INTERVAL_DAY_TIME: + FLATCC_RETURN_UNLESS_0( + Field_type_Interval_create(builder, ns(IntervalUnit_DAY_TIME)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: + FLATCC_RETURN_UNLESS_0( + Field_type_Interval_create(builder, ns(IntervalUnit_MONTH_DAY_NANO)), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_TIMESTAMP: + FLATCC_RETURN_UNLESS_0(Field_type_Timestamp_start(builder), error); + FLATCC_RETURN_UNLESS_0( + Timestamp_unit_add(builder, (ns(TimeUnit_enum_t))schema_view->time_unit), + error); + if (schema_view->timezone && schema_view->timezone[0] != 0) { + FLATCC_RETURN_UNLESS_0( + Timestamp_timezone_create_str(builder, schema_view->timezone), error); + } + FLATCC_RETURN_UNLESS_0(Field_type_Timestamp_end(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_TIME32: + FLATCC_RETURN_UNLESS_0( + Field_type_Time_create(builder, (ns(TimeUnit_enum_t))schema_view->time_unit, + 32), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_TIME64: + FLATCC_RETURN_UNLESS_0( + Field_type_Time_create(builder, (ns(TimeUnit_enum_t))schema_view->time_unit, + 64), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DURATION: + FLATCC_RETURN_UNLESS_0(Field_type_Duration_create( + builder, (ns(TimeUnit_enum_t))schema_view->time_unit), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_FIXED_SIZE_BINARY: + FLATCC_RETURN_UNLESS_0( + Field_type_FixedSizeBinary_create(builder, schema_view->fixed_size), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_LIST: + FLATCC_RETURN_UNLESS_0(Field_type_List_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_LARGE_LIST: + FLATCC_RETURN_UNLESS_0(Field_type_LargeList_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_FIXED_SIZE_LIST: + FLATCC_RETURN_UNLESS_0( + Field_type_FixedSizeList_create(builder, schema_view->fixed_size), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_RUN_END_ENCODED: + FLATCC_RETURN_UNLESS_0(Field_type_RunEndEncoded_create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_STRUCT: + FLATCC_RETURN_UNLESS_0(Field_type_Struct__create(builder), error); + return NANOARROW_OK; + + case NANOARROW_TYPE_SPARSE_UNION: + case NANOARROW_TYPE_DENSE_UNION: { + FLATCC_RETURN_UNLESS_0(Field_type_Union_start(builder), error); + + FLATCC_RETURN_UNLESS_0( + Union_mode_add(builder, schema_view->type == NANOARROW_TYPE_DENSE_UNION), + error); + if (schema_view->union_type_ids) { + int8_t type_ids[128]; + int n = _ArrowParseUnionTypeIds(schema_view->union_type_ids, type_ids); + if (n != 0) { + FLATCC_RETURN_UNLESS_0(Union_typeIds_start(builder), error); + int32_t* type_ids_32 = (int32_t*)ns(Union_typeIds_extend(builder, n)); + FLATCC_RETURN_IF_NULL(type_ids_32, error); + + for (int i = 0; i < n; i++) { + type_ids_32[i] = type_ids[i]; + } + FLATCC_RETURN_UNLESS_0(Union_typeIds_end(builder), error); + } + } + + FLATCC_RETURN_UNLESS_0(Field_type_Union_end(builder), error); + return NANOARROW_OK; + } + + case NANOARROW_TYPE_MAP: + FLATCC_RETURN_UNLESS_0( + Field_type_Map_create(builder, + schema_view->schema->flags & ARROW_FLAG_MAP_KEYS_SORTED), + error); + return NANOARROW_OK; + + case NANOARROW_TYPE_DICTIONARY: + ArrowErrorSet(error, "IPC encoding of dictionary types unsupported"); + return ENOTSUP; + + default: + ArrowErrorSet(error, "Expected a valid enum ArrowType value but found %d", + schema_view->type); + return EINVAL; + } +} + +static ArrowErrorCode ArrowIpcEncodeField(flatcc_builder_t* builder, + const struct ArrowSchema* schema, + struct ArrowError* error); + +static ArrowErrorCode ArrowIpcEncodeMetadata(flatcc_builder_t* builder, + const struct ArrowSchema* schema, + int (*push_start)(flatcc_builder_t*), + ns(KeyValue_ref_t) * + (*push_end)(flatcc_builder_t*), + struct ArrowError* error) { + struct ArrowMetadataReader metadata; + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowMetadataReaderInit(&metadata, schema->metadata), + error); + while (metadata.remaining_keys > 0) { + struct ArrowStringView key, value; + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowMetadataReaderRead(&metadata, &key, &value), + error); + FLATCC_RETURN_UNLESS_0_NO_NS(push_start(builder), error); + FLATCC_RETURN_UNLESS_0(KeyValue_key_create_strn(builder, key.data, key.size_bytes), + error); + FLATCC_RETURN_UNLESS_0( + KeyValue_value_create_strn(builder, value.data, value.size_bytes), error); + FLATCC_RETURN_IF_NULL(push_end(builder), error); + } + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncodeFields(flatcc_builder_t* builder, + const struct ArrowSchema* schema, + int (*push_start)(flatcc_builder_t*), + ns(Field_ref_t) * + (*push_end)(flatcc_builder_t*), + struct ArrowError* error) { + for (int i = 0; i < schema->n_children; i++) { + FLATCC_RETURN_UNLESS_0_NO_NS(push_start(builder), error); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeField(builder, schema->children[i], error)); + FLATCC_RETURN_IF_NULL(push_end(builder), error); + } + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncodeField(flatcc_builder_t* builder, + const struct ArrowSchema* schema, + struct ArrowError* error) { + FLATCC_RETURN_UNLESS_0(Field_name_create_str(builder, schema->name), error); + FLATCC_RETURN_UNLESS_0( + Field_nullable_add(builder, (schema->flags & ARROW_FLAG_NULLABLE) != 0), error); + + struct ArrowSchemaView schema_view; + NANOARROW_RETURN_NOT_OK(ArrowSchemaViewInit(&schema_view, schema, error)); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeFieldType(builder, &schema_view, error)); + + if (schema->n_children != 0) { + FLATCC_RETURN_UNLESS_0(Field_children_start(builder), error); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeFields(builder, schema, + &ns(Field_children_push_start), + &ns(Field_children_push_end), error)); + FLATCC_RETURN_UNLESS_0(Field_children_end(builder), error); + } + + if (schema->metadata) { + FLATCC_RETURN_UNLESS_0(Field_custom_metadata_start(builder), error); + NANOARROW_RETURN_NOT_OK( + ArrowIpcEncodeMetadata(builder, schema, &ns(Field_custom_metadata_push_start), + &ns(Field_custom_metadata_push_end), error)); + FLATCC_RETURN_UNLESS_0(Field_custom_metadata_end(builder), error); + } + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncodeSchema(flatcc_builder_t* builder, + const struct ArrowSchema* schema, + struct ArrowError* error) { + NANOARROW_DCHECK(schema->release != NULL); + + if (strcmp(schema->format, "+s") != 0) { + ArrowErrorSet( + error, + "Cannot encode schema with format '%s'; top level schema must have struct type", + schema->format); + return EINVAL; + } + + if (ArrowIpcSystemEndianness() == NANOARROW_IPC_ENDIANNESS_LITTLE) { + FLATCC_RETURN_UNLESS_0(Schema_endianness_add(builder, ns(Endianness_Little)), error); + } else { + FLATCC_RETURN_UNLESS_0(Schema_endianness_add(builder, ns(Endianness_Big)), error); + } + + FLATCC_RETURN_UNLESS_0(Schema_fields_start(builder), error); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeFields(builder, schema, + &ns(Schema_fields_push_start), + &ns(Schema_fields_push_end), error)); + FLATCC_RETURN_UNLESS_0(Schema_fields_end(builder), error); + + FLATCC_RETURN_UNLESS_0(Schema_custom_metadata_start(builder), error); + if (schema->metadata) { + NANOARROW_RETURN_NOT_OK( + ArrowIpcEncodeMetadata(builder, schema, &ns(Schema_custom_metadata_push_start), + &ns(Schema_custom_metadata_push_end), error)); + } + FLATCC_RETURN_UNLESS_0(Schema_custom_metadata_end(builder), error); + + FLATCC_RETURN_UNLESS_0(Schema_features_start(builder), error); + FLATCC_RETURN_UNLESS_0(Schema_features_end(builder), error); + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcEncoderEncodeSchema(struct ArrowIpcEncoder* encoder, + const struct ArrowSchema* schema, + struct ArrowError* error) { + NANOARROW_DCHECK(encoder != NULL && encoder->private_data != NULL && schema != NULL); + + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + + flatcc_builder_t* builder = &private->builder; + + FLATCC_RETURN_UNLESS_0(Message_start_as_root(builder), error); + + FLATCC_RETURN_UNLESS_0(Message_version_add(builder, ns(MetadataVersion_V5)), error); + + FLATCC_RETURN_UNLESS_0(Message_header_Schema_start(builder), error); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeSchema(builder, schema, error)); + FLATCC_RETURN_UNLESS_0(Message_header_Schema_end(builder), error); + + FLATCC_RETURN_UNLESS_0(Message_bodyLength_add(builder, 0), error); + + FLATCC_RETURN_IF_NULL(ns(Message_end_as_root(builder)), error); + return NANOARROW_OK; +} + +struct ArrowIpcBufferEncoder { + /// \brief Callback invoked against each buffer to be encoded + /// + /// Encoding of buffers is left as a callback to accommodate dissociated data storage. + /// One implementation of this callback might copy all buffers into a contiguous body + /// for use in an arrow IPC stream, another implementation might store offsets and + /// lengths relative to a known arena. + ArrowErrorCode (*encode_buffer)(struct ArrowBufferView buffer_view, + struct ArrowIpcEncoder* encoder, + struct ArrowIpcBufferEncoder* buffer_encoder, + int64_t* offset, int64_t* length, + struct ArrowError* error); + + /// \brief Pointer to arbitrary data used by encode_buffer() + void* encode_buffer_state; + + /// \brief Finalized body length of the most recently encoded RecordBatch message + /// + /// encode_buffer() is expected to update this while encoding each buffer. After all + /// buffers are encoded, this will be written to the RecordBatch's .bodyLength + int64_t body_length; +}; + +static ArrowErrorCode ArrowIpcEncoderBuildContiguousBodyBufferCallback( + struct ArrowBufferView buffer_view, struct ArrowIpcEncoder* encoder, + struct ArrowIpcBufferEncoder* buffer_encoder, int64_t* offset, int64_t* length, + struct ArrowError* error) { + NANOARROW_UNUSED(encoder); + + struct ArrowBuffer* body_buffer = + (struct ArrowBuffer*)buffer_encoder->encode_buffer_state; + + int64_t old_size = body_buffer->size_bytes; + int64_t buffer_begin = _ArrowRoundUpToMultipleOf8(old_size); + int64_t buffer_end = buffer_begin + buffer_view.size_bytes; + int64_t new_size = _ArrowRoundUpToMultipleOf8(buffer_end); + + // reserve all the memory we'll need now + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBufferReserve(body_buffer, new_size - old_size), + error); + + // zero padding up to the start of the buffer + NANOARROW_ASSERT_OK(ArrowBufferAppendFill(body_buffer, 0, buffer_begin - old_size)); + + // store offset and length of the buffer + *offset = buffer_begin; + *length = buffer_view.size_bytes; + + NANOARROW_ASSERT_OK( + ArrowBufferAppend(body_buffer, buffer_view.data.data, buffer_view.size_bytes)); + + // zero padding after writing the buffer + NANOARROW_DCHECK(body_buffer->size_bytes == buffer_end); + NANOARROW_ASSERT_OK(ArrowBufferAppendFill(body_buffer, 0, new_size - buffer_end)); + + buffer_encoder->body_length = body_buffer->size_bytes; + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncoderEncodeRecordBatchImpl( + struct ArrowIpcEncoder* encoder, struct ArrowIpcBufferEncoder* buffer_encoder, + const struct ArrowArrayView* array_view, struct ArrowBuffer* buffers, + struct ArrowBuffer* nodes, struct ArrowError* error) { + if (array_view->offset != 0) { + ArrowErrorSet(error, "Cannot encode arrays with nonzero offset"); + return ENOTSUP; + } + + for (int64_t c = 0; c < array_view->n_children; ++c) { + const struct ArrowArrayView* child = array_view->children[c]; + + struct ns(FieldNode) node = {child->length, child->null_count}; + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBufferAppend(nodes, &node, sizeof(node)), + error); + + for (int64_t b = 0; b < child->array->n_buffers; ++b) { + struct ns(Buffer) buffer; + NANOARROW_RETURN_NOT_OK( + buffer_encoder->encode_buffer(child->buffer_views[b], encoder, buffer_encoder, + &buffer.offset, &buffer.length, error)); + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferAppend(buffers, &buffer, sizeof(buffer)), error); + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderEncodeRecordBatchImpl( + encoder, buffer_encoder, child, buffers, nodes, error)); + } + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcEncoderEncodeRecordBatch( + struct ArrowIpcEncoder* encoder, struct ArrowIpcBufferEncoder* buffer_encoder, + const struct ArrowArrayView* array_view, struct ArrowError* error) { + NANOARROW_DCHECK(encoder != NULL && encoder->private_data != NULL && + buffer_encoder != NULL && buffer_encoder->encode_buffer != NULL); + if (array_view->null_count != 0 && ArrowArrayViewComputeNullCount(array_view) != 0) { + ArrowErrorSet(error, + "RecordBatches cannot be constructed from arrays with top level nulls"); + return EINVAL; + } + + if (array_view->storage_type != NANOARROW_TYPE_STRUCT) { + ArrowErrorSet( + error, + "RecordBatches cannot be constructed from arrays of type other than struct"); + return EINVAL; + } + + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + + flatcc_builder_t* builder = &private->builder; + + FLATCC_RETURN_UNLESS_0(Message_start_as_root(builder), error); + FLATCC_RETURN_UNLESS_0(Message_version_add(builder, ns(MetadataVersion_V5)), error); + + FLATCC_RETURN_UNLESS_0(Message_header_RecordBatch_start(builder), error); + FLATCC_RETURN_UNLESS_0(RecordBatch_length_add(builder, array_view->length), error); + + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffers, 0, 0)); + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->nodes, 0, 0)); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderEncodeRecordBatchImpl( + encoder, buffer_encoder, array_view, &private->buffers, &private->nodes, error)); + + FLATCC_RETURN_UNLESS_0(RecordBatch_nodes_create( // + builder, (struct ns(FieldNode)*)private->nodes.data, + private->nodes.size_bytes / sizeof(struct ns(FieldNode))), + error); + FLATCC_RETURN_UNLESS_0(RecordBatch_buffers_create( // + builder, (struct ns(Buffer)*)private->buffers.data, + private->buffers.size_bytes / sizeof(struct ns(Buffer))), + error); + + FLATCC_RETURN_UNLESS_0(Message_header_RecordBatch_end(builder), error); + + FLATCC_RETURN_UNLESS_0(Message_bodyLength_add(builder, buffer_encoder->body_length), + error); + FLATCC_RETURN_IF_NULL(ns(Message_end_as_root(builder)), error); + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcEncoderEncodeSimpleRecordBatch( + struct ArrowIpcEncoder* encoder, const struct ArrowArrayView* array_view, + struct ArrowBuffer* body_buffer, struct ArrowError* error) { + NANOARROW_DCHECK(encoder != NULL && encoder->private_data != NULL && + body_buffer != NULL); + + struct ArrowIpcBufferEncoder buffer_encoder = { + .encode_buffer = &ArrowIpcEncoderBuildContiguousBodyBufferCallback, + .encode_buffer_state = body_buffer, + .body_length = 0, + }; + + return ArrowIpcEncoderEncodeRecordBatch(encoder, &buffer_encoder, array_view, error); +} + +void ArrowIpcFooterInit(struct ArrowIpcFooter* footer) { + footer->schema.release = NULL; + ArrowBufferInit(&footer->record_batch_blocks); +} + +void ArrowIpcFooterReset(struct ArrowIpcFooter* footer) { + if (footer->schema.release != NULL) { + ArrowSchemaRelease(&footer->schema); + } + ArrowBufferReset(&footer->record_batch_blocks); +} + +ArrowErrorCode ArrowIpcEncoderEncodeFooter(struct ArrowIpcEncoder* encoder, + const struct ArrowIpcFooter* footer, + struct ArrowError* error) { + NANOARROW_DCHECK(encoder != NULL && encoder->private_data != NULL && footer != NULL); + + struct ArrowIpcEncoderPrivate* private = + (struct ArrowIpcEncoderPrivate*)encoder->private_data; + + flatcc_builder_t* builder = &private->builder; + + FLATCC_RETURN_UNLESS_0(Footer_start_as_root(builder), error); + + FLATCC_RETURN_UNLESS_0(Footer_version_add(builder, ns(MetadataVersion_V5)), error); + + FLATCC_RETURN_UNLESS_0(Footer_schema_start(builder), error); + NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeSchema(builder, &footer->schema, error)); + FLATCC_RETURN_UNLESS_0(Footer_schema_end(builder), error); + + const struct ArrowIpcFileBlock* blocks = + (struct ArrowIpcFileBlock*)footer->record_batch_blocks.data; + int64_t n_blocks = + footer->record_batch_blocks.size_bytes / sizeof(struct ArrowIpcFileBlock); + + FLATCC_RETURN_UNLESS_0(Footer_recordBatches_start(builder), error); + struct ns(Block)* flatcc_RecordBatch_blocks = + ns(Footer_recordBatches_extend(builder, n_blocks)); + FLATCC_RETURN_IF_NULL(flatcc_RecordBatch_blocks, error); + for (int64_t i = 0; i < n_blocks; i++) { + struct ns(Block) block = { + blocks[i].offset, + blocks[i].metadata_length, + blocks[i].body_length, + }; + flatcc_RecordBatch_blocks[i] = block; + } + FLATCC_RETURN_UNLESS_0(Footer_recordBatches_end(builder), error); + + FLATCC_RETURN_IF_NULL(ns(Footer_end_as_root(builder)), error); + return NANOARROW_OK; +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include +#include + +#include "nanoarrow/nanoarrow.h" +#include "nanoarrow/nanoarrow_ipc.h" + +// R 3.6 / Windows builds on a very old toolchain that does not define ENODATA +#if defined(_WIN32) && !defined(_MSC_VER) && !defined(ENODATA) +#define ENODATA 120 +#endif + +// Sentinel value to indicate that we haven't read a message yet +// and don't know the number of header prefix bytes to expect. +static const int32_t kExpectedHeaderPrefixSizeNotSet = -1; + +void ArrowIpcInputStreamMove(struct ArrowIpcInputStream* src, + struct ArrowIpcInputStream* dst) { + memcpy(dst, src, sizeof(struct ArrowIpcInputStream)); + src->release = NULL; +} + +struct ArrowIpcInputStreamBufferPrivate { + struct ArrowBuffer input; + int64_t cursor_bytes; +}; + +static ArrowErrorCode ArrowIpcInputStreamBufferRead(struct ArrowIpcInputStream* stream, + uint8_t* buf, int64_t buf_size_bytes, + int64_t* size_read_out, + struct ArrowError* error) { + NANOARROW_UNUSED(error); + + if (buf_size_bytes == 0) { + *size_read_out = 0; + return NANOARROW_OK; + } + + struct ArrowIpcInputStreamBufferPrivate* private_data = + (struct ArrowIpcInputStreamBufferPrivate*)stream->private_data; + int64_t bytes_remaining = private_data->input.size_bytes - private_data->cursor_bytes; + int64_t bytes_to_read; + if (bytes_remaining > buf_size_bytes) { + bytes_to_read = buf_size_bytes; + } else { + bytes_to_read = bytes_remaining; + } + + if (bytes_to_read > 0) { + memcpy(buf, private_data->input.data + private_data->cursor_bytes, bytes_to_read); + } + + *size_read_out = bytes_to_read; + private_data->cursor_bytes += bytes_to_read; + return NANOARROW_OK; +} + +static void ArrowIpcInputStreamBufferRelease(struct ArrowIpcInputStream* stream) { + struct ArrowIpcInputStreamBufferPrivate* private_data = + (struct ArrowIpcInputStreamBufferPrivate*)stream->private_data; + ArrowBufferReset(&private_data->input); + ArrowFree(private_data); + stream->release = NULL; +} + +ArrowErrorCode ArrowIpcInputStreamInitBuffer(struct ArrowIpcInputStream* stream, + struct ArrowBuffer* input) { + NANOARROW_DCHECK(stream != NULL); + + struct ArrowIpcInputStreamBufferPrivate* private_data = + (struct ArrowIpcInputStreamBufferPrivate*)ArrowMalloc( + sizeof(struct ArrowIpcInputStreamBufferPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + ArrowBufferMove(input, &private_data->input); + private_data->cursor_bytes = 0; + stream->read = &ArrowIpcInputStreamBufferRead; + stream->release = &ArrowIpcInputStreamBufferRelease; + stream->private_data = private_data; + + return NANOARROW_OK; +} + +struct ArrowIpcInputStreamFilePrivate { + FILE* file_ptr; + int stream_finished; + int close_on_release; +}; + +static void ArrowIpcInputStreamFileRelease(struct ArrowIpcInputStream* stream) { + struct ArrowIpcInputStreamFilePrivate* private_data = + (struct ArrowIpcInputStreamFilePrivate*)stream->private_data; + + if (private_data->file_ptr != NULL && private_data->close_on_release) { + fclose(private_data->file_ptr); + } + + ArrowFree(private_data); + stream->release = NULL; +} + +static ArrowErrorCode ArrowIpcInputStreamFileRead(struct ArrowIpcInputStream* stream, + uint8_t* buf, int64_t buf_size_bytes, + int64_t* size_read_out, + struct ArrowError* error) { + struct ArrowIpcInputStreamFilePrivate* private_data = + (struct ArrowIpcInputStreamFilePrivate*)stream->private_data; + + if (private_data->stream_finished) { + *size_read_out = 0; + return NANOARROW_OK; + } + + // Do the read + int64_t bytes_read = (int64_t)fread(buf, 1, buf_size_bytes, private_data->file_ptr); + *size_read_out = bytes_read; + + if (bytes_read != buf_size_bytes) { + private_data->stream_finished = 1; + + // Inspect error + int has_error = !feof(private_data->file_ptr) && ferror(private_data->file_ptr); + + // Try to close the file now + if (private_data->close_on_release) { + if (fclose(private_data->file_ptr) == 0) { + private_data->file_ptr = NULL; + } + } + + // Maybe return error + if (has_error) { + ArrowErrorSet(error, "ArrowIpcInputStreamFile IO error"); + return EIO; + } + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcInputStreamInitFile(struct ArrowIpcInputStream* stream, + void* file_ptr, int close_on_release) { + NANOARROW_DCHECK(stream != NULL); + if (file_ptr == NULL) { + return errno ? errno : EINVAL; + } + + struct ArrowIpcInputStreamFilePrivate* private_data = + (struct ArrowIpcInputStreamFilePrivate*)ArrowMalloc( + sizeof(struct ArrowIpcInputStreamFilePrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + private_data->file_ptr = (FILE*)file_ptr; + private_data->close_on_release = close_on_release; + private_data->stream_finished = 0; + + stream->read = &ArrowIpcInputStreamFileRead; + stream->release = &ArrowIpcInputStreamFileRelease; + stream->private_data = private_data; + return NANOARROW_OK; +} + +struct ArrowIpcArrayStreamReaderPrivate { + struct ArrowIpcInputStream input; + struct ArrowIpcDecoder decoder; + int use_shared_buffers; + struct ArrowSchema out_schema; + int64_t field_index; + struct ArrowBuffer header; + struct ArrowBuffer body; + int32_t expected_header_prefix_size; + struct ArrowError error; +}; + +static void ArrowIpcArrayStreamReaderRelease(struct ArrowArrayStream* stream) { + struct ArrowIpcArrayStreamReaderPrivate* private_data = + (struct ArrowIpcArrayStreamReaderPrivate*)stream->private_data; + + if (private_data->input.release != NULL) { + private_data->input.release(&private_data->input); + } + + ArrowIpcDecoderReset(&private_data->decoder); + + if (private_data->out_schema.release != NULL) { + ArrowSchemaRelease(&private_data->out_schema); + } + + ArrowBufferReset(&private_data->header); + ArrowBufferReset(&private_data->body); + + ArrowFree(private_data); + stream->release = NULL; +} + +static int ArrowIpcArrayStreamReaderNextHeader( + struct ArrowIpcArrayStreamReaderPrivate* private_data, + enum ArrowIpcMessageType message_type) { + private_data->header.size_bytes = 0; + int64_t bytes_read = 0; + + // Read 8 bytes (continuation + header size in bytes) + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBufferReserve(&private_data->header, 8), + &private_data->error); + NANOARROW_RETURN_NOT_OK(private_data->input.read(&private_data->input, + private_data->header.data, 8, + &bytes_read, &private_data->error)); + private_data->header.size_bytes += bytes_read; + + if (bytes_read == 0) { + // The caller might not use this error message (e.g., if the end of the stream + // is one of the valid outcomes) but we set the error anyway in case it gets + // propagated higher (e.g., if the stream is empty and there's no schema message) + ArrowErrorSet(&private_data->error, "No data available on stream"); + return ENODATA; + } else if (bytes_read == 4 && private_data->expected_header_prefix_size == 4) { + // Special case very, very old IPC streams that used 0x00000000 as the + // end-of-stream indicator. We may want to remove this case at some point: + // https://github.com/apache/arrow-nanoarrow/issues/648 + uint32_t last_four_bytes = 0; + memcpy(&last_four_bytes, private_data->header.data, sizeof(uint32_t)); + if (last_four_bytes == 0) { + ArrowErrorSet(&private_data->error, "No data available on stream"); + return ENODATA; + } else { + ArrowErrorSet(&private_data->error, + "Expected 0x00000000 if exactly four bytes are available at the end " + "of a stream"); + return EINVAL; + } + } else if (bytes_read != 8) { + ArrowErrorSet(&private_data->error, + "Expected at least 8 bytes in remainder of stream"); + return EINVAL; + } + + struct ArrowBufferView input_view; + input_view.data.data = private_data->header.data; + input_view.size_bytes = private_data->header.size_bytes; + + // Use PeekHeader to fill in decoder.header_size_bytes + int32_t prefix_size_bytes = 0; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderPeekHeader( + &private_data->decoder, input_view, &prefix_size_bytes, &private_data->error)); + + // Check for a consistent header prefix size + if (private_data->expected_header_prefix_size != kExpectedHeaderPrefixSizeNotSet && + prefix_size_bytes != private_data->expected_header_prefix_size) { + ArrowErrorSet(&private_data->error, + "Expected prefix %d prefix header bytes but found %d", + (int)private_data->expected_header_prefix_size, (int)prefix_size_bytes); + return EINVAL; + } else { + private_data->expected_header_prefix_size = prefix_size_bytes; + } + + // Legacy streams are missing the 0xFFFFFFFF at the start of the message. The + // decoder can handle this; however, verification will fail because flatbuffers + // must be 8-byte aligned. To handle this case, we prepend the continuation + // token to the start of the stream and ensure that we read four fewer bytes + // the next time we issue a read. We may be able to remove this case in the future: + // https://github.com/apache/arrow-nanoarrow/issues/648 + int64_t extra_bytes_already_read = 0; + if (prefix_size_bytes == 4) { + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBufferReserve(&private_data->header, 4), + &private_data->error); + memmove(private_data->header.data + 4, private_data->header.data, + private_data->header.size_bytes); + uint32_t continuation = 0xFFFFFFFFU; + memcpy(private_data->header.data, &continuation, sizeof(uint32_t)); + private_data->header.size_bytes += 4; + extra_bytes_already_read = 4; + + input_view.data.data = private_data->header.data; + input_view.size_bytes = private_data->header.size_bytes; + + int32_t new_prefix_size_bytes; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderPeekHeader(&private_data->decoder, input_view, + &new_prefix_size_bytes, + &private_data->error)); + NANOARROW_DCHECK(new_prefix_size_bytes == 8); + } + + // Read the header bytes + int64_t expected_header_bytes = private_data->decoder.header_size_bytes - 8; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferReserve(&private_data->header, + expected_header_bytes - extra_bytes_already_read), + &private_data->error); + NANOARROW_RETURN_NOT_OK(private_data->input.read( + &private_data->input, private_data->header.data + private_data->header.size_bytes, + expected_header_bytes - extra_bytes_already_read, &bytes_read, + &private_data->error)); + private_data->header.size_bytes += bytes_read; + + // Verify + decode the header + input_view.data.data = private_data->header.data; + input_view.size_bytes = private_data->header.size_bytes; + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderVerifyHeader(&private_data->decoder, input_view, + &private_data->error)); + + // If we have a 4-byte header prefix, make sure the metadata version is V4 + // (Note that some V4 IPC files have an 8 byte header prefix). + if (prefix_size_bytes == 4 && + private_data->decoder.metadata_version != NANOARROW_IPC_METADATA_VERSION_V4) { + ArrowErrorSet(&private_data->error, + "Header prefix size of four bytes is only allowed for V4 metadata"); + return EINVAL; + } + + // Don't decode the message if it's of the wrong type (because the error message + // is better communicated by the caller) + if (private_data->decoder.message_type != message_type) { + return NANOARROW_OK; + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeHeader(&private_data->decoder, input_view, + &private_data->error)); + return NANOARROW_OK; +} + +static int ArrowIpcArrayStreamReaderNextBody( + struct ArrowIpcArrayStreamReaderPrivate* private_data) { + int64_t bytes_read; + int64_t bytes_to_read = private_data->decoder.body_size_bytes; + + // Read the body bytes + private_data->body.size_bytes = 0; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferReserve(&private_data->body, bytes_to_read), &private_data->error); + NANOARROW_RETURN_NOT_OK(private_data->input.read(&private_data->input, + private_data->body.data, bytes_to_read, + &bytes_read, &private_data->error)); + private_data->body.size_bytes += bytes_read; + + if (bytes_read != bytes_to_read) { + ArrowErrorSet(&private_data->error, + "Expected to be able to read %" PRId64 + " bytes for message body but got %" PRId64, + bytes_to_read, bytes_read); + return ESPIPE; + } else { + return NANOARROW_OK; + } +} + +static int ArrowIpcArrayStreamReaderReadSchemaIfNeeded( + struct ArrowIpcArrayStreamReaderPrivate* private_data) { + if (private_data->out_schema.release != NULL) { + return NANOARROW_OK; + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcArrayStreamReaderNextHeader( + private_data, NANOARROW_IPC_MESSAGE_TYPE_SCHEMA)); + + // Error if this isn't a schema message + if (private_data->decoder.message_type != NANOARROW_IPC_MESSAGE_TYPE_SCHEMA) { + ArrowErrorSet(&private_data->error, + "Unexpected message type at start of input (expected Schema)"); + return EINVAL; + } + + // ...or if it uses features we don't support + if (private_data->decoder.feature_flags & NANOARROW_IPC_FEATURE_COMPRESSED_BODY) { + ArrowErrorSet(&private_data->error, + "This stream uses unsupported feature COMPRESSED_BODY"); + return EINVAL; + } + + if (private_data->decoder.feature_flags & + NANOARROW_IPC_FEATURE_DICTIONARY_REPLACEMENT) { + ArrowErrorSet(&private_data->error, + "This stream uses unsupported feature DICTIONARY_REPLACEMENT"); + return EINVAL; + } + + // Notify the decoder of buffer endianness + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowIpcDecoderSetEndianness(&private_data->decoder, + private_data->decoder.endianness), + &private_data->error); + + struct ArrowSchema tmp; + NANOARROW_RETURN_NOT_OK( + ArrowIpcDecoderDecodeSchema(&private_data->decoder, &tmp, &private_data->error)); + + // Only support "read the whole thing" for now + if (private_data->field_index != -1) { + ArrowSchemaRelease(&tmp); + ArrowErrorSet(&private_data->error, "Field index != -1 is not yet supported"); + return ENOTSUP; + } + + // Notify the decoder of the schema for forthcoming messages + int result = + ArrowIpcDecoderSetSchema(&private_data->decoder, &tmp, &private_data->error); + if (result != NANOARROW_OK) { + ArrowSchemaRelease(&tmp); + return result; + } + + ArrowSchemaMove(&tmp, &private_data->out_schema); + return NANOARROW_OK; +} + +static int ArrowIpcArrayStreamReaderGetSchema(struct ArrowArrayStream* stream, + struct ArrowSchema* out) { + struct ArrowIpcArrayStreamReaderPrivate* private_data = + (struct ArrowIpcArrayStreamReaderPrivate*)stream->private_data; + private_data->error.message[0] = '\0'; + NANOARROW_RETURN_NOT_OK(ArrowIpcArrayStreamReaderReadSchemaIfNeeded(private_data)); + return ArrowSchemaDeepCopy(&private_data->out_schema, out); +} + +static int ArrowIpcArrayStreamReaderGetNext(struct ArrowArrayStream* stream, + struct ArrowArray* out) { + struct ArrowIpcArrayStreamReaderPrivate* private_data = + (struct ArrowIpcArrayStreamReaderPrivate*)stream->private_data; + ArrowErrorInit(&private_data->error); + NANOARROW_RETURN_NOT_OK(ArrowIpcArrayStreamReaderReadSchemaIfNeeded(private_data)); + + // Read + decode the next header + int result = ArrowIpcArrayStreamReaderNextHeader( + private_data, NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH); + if (result == ENODATA) { + // Stream is finished either because there is no input or because + // end of stream bytes were read. + out->release = NULL; + return NANOARROW_OK; + } else if (result != NANOARROW_OK) { + // Other error + return result; + } + + // Make sure we have a RecordBatch message + if (private_data->decoder.message_type != NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH) { + ArrowErrorSet(&private_data->error, "Unexpected message type (expected RecordBatch)"); + return EINVAL; + } + + // Read in the body + NANOARROW_RETURN_NOT_OK(ArrowIpcArrayStreamReaderNextBody(private_data)); + + struct ArrowArray tmp; + + if (private_data->use_shared_buffers) { + struct ArrowIpcSharedBuffer shared; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowIpcSharedBufferInit(&shared, &private_data->body), &private_data->error); + result = ArrowIpcDecoderDecodeArrayFromShared( + &private_data->decoder, &shared, private_data->field_index, &tmp, + NANOARROW_VALIDATION_LEVEL_FULL, &private_data->error); + ArrowIpcSharedBufferReset(&shared); + NANOARROW_RETURN_NOT_OK(result); + } else { + struct ArrowBufferView body_view; + body_view.data.data = private_data->body.data; + body_view.size_bytes = private_data->body.size_bytes; + + NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeArray( + &private_data->decoder, body_view, private_data->field_index, &tmp, + NANOARROW_VALIDATION_LEVEL_FULL, &private_data->error)); + } + + ArrowArrayMove(&tmp, out); + return NANOARROW_OK; +} + +static const char* ArrowIpcArrayStreamReaderGetLastError( + struct ArrowArrayStream* stream) { + struct ArrowIpcArrayStreamReaderPrivate* private_data = + (struct ArrowIpcArrayStreamReaderPrivate*)stream->private_data; + return private_data->error.message; +} + +ArrowErrorCode ArrowIpcArrayStreamReaderInit( + struct ArrowArrayStream* out, struct ArrowIpcInputStream* input_stream, + struct ArrowIpcArrayStreamReaderOptions* options) { + struct ArrowIpcArrayStreamReaderPrivate* private_data = + (struct ArrowIpcArrayStreamReaderPrivate*)ArrowMalloc( + sizeof(struct ArrowIpcArrayStreamReaderPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + int result = ArrowIpcDecoderInit(&private_data->decoder); + if (result != NANOARROW_OK) { + ArrowFree(private_data); + return result; + } + + ArrowBufferInit(&private_data->header); + ArrowBufferInit(&private_data->body); + private_data->out_schema.release = NULL; + ArrowIpcInputStreamMove(input_stream, &private_data->input); + private_data->expected_header_prefix_size = kExpectedHeaderPrefixSizeNotSet; + + if (options != NULL) { + private_data->field_index = options->field_index; + private_data->use_shared_buffers = options->use_shared_buffers; + } else { + private_data->field_index = -1; + private_data->use_shared_buffers = ArrowIpcSharedBufferIsThreadSafe(); + } + + out->private_data = private_data; + out->get_schema = &ArrowIpcArrayStreamReaderGetSchema; + out->get_next = &ArrowIpcArrayStreamReaderGetNext; + out->get_last_error = &ArrowIpcArrayStreamReaderGetLastError; + out->release = &ArrowIpcArrayStreamReaderRelease; + + return NANOARROW_OK; +} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include +#include + +#include "flatcc/flatcc_builder.h" + +#include "nanoarrow/nanoarrow.h" +#include "nanoarrow/nanoarrow_ipc.h" + +#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(org_apache_arrow_flatbuf, x) + +void ArrowIpcOutputStreamMove(struct ArrowIpcOutputStream* src, + struct ArrowIpcOutputStream* dst) { + NANOARROW_DCHECK(src != NULL && dst != NULL); + + memcpy(dst, src, sizeof(struct ArrowIpcOutputStream)); + src->release = NULL; +} + +ArrowErrorCode ArrowIpcOutputStreamWrite(struct ArrowIpcOutputStream* stream, + struct ArrowBufferView data, + struct ArrowError* error) { + while (data.size_bytes != 0) { + int64_t bytes_written = 0; + NANOARROW_RETURN_NOT_OK(stream->write(stream, data.data.as_uint8, data.size_bytes, + &bytes_written, error)); + data.size_bytes -= bytes_written; + data.data.as_uint8 += bytes_written; + } + return NANOARROW_OK; +} + +struct ArrowIpcOutputStreamBufferPrivate { + struct ArrowBuffer* output; +}; + +static ArrowErrorCode ArrowIpcOutputStreamBufferWrite(struct ArrowIpcOutputStream* stream, + const void* buf, + int64_t buf_size_bytes, + int64_t* size_written_out, + struct ArrowError* error) { + struct ArrowIpcOutputStreamBufferPrivate* private_data = + (struct ArrowIpcOutputStreamBufferPrivate*)stream->private_data; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferAppend(private_data->output, buf, buf_size_bytes), error); + *size_written_out = buf_size_bytes; + return NANOARROW_OK; +} + +static void ArrowIpcOutputStreamBufferRelease(struct ArrowIpcOutputStream* stream) { + struct ArrowIpcOutputStreamBufferPrivate* private_data = + (struct ArrowIpcOutputStreamBufferPrivate*)stream->private_data; + ArrowFree(private_data); + stream->release = NULL; +} + +ArrowErrorCode ArrowIpcOutputStreamInitBuffer(struct ArrowIpcOutputStream* stream, + struct ArrowBuffer* output) { + NANOARROW_DCHECK(stream != NULL && output != NULL); + + struct ArrowIpcOutputStreamBufferPrivate* private_data = + (struct ArrowIpcOutputStreamBufferPrivate*)ArrowMalloc( + sizeof(struct ArrowIpcOutputStreamBufferPrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + private_data->output = output; + stream->write = &ArrowIpcOutputStreamBufferWrite; + stream->release = &ArrowIpcOutputStreamBufferRelease; + stream->private_data = private_data; + + return NANOARROW_OK; +} + +struct ArrowIpcOutputStreamFilePrivate { + FILE* file_ptr; + int stream_finished; + int close_on_release; +}; + +static void ArrowIpcOutputStreamFileRelease(struct ArrowIpcOutputStream* stream) { + struct ArrowIpcOutputStreamFilePrivate* private_data = + (struct ArrowIpcOutputStreamFilePrivate*)stream->private_data; + + if (private_data->file_ptr != NULL && private_data->close_on_release) { + fclose(private_data->file_ptr); + } + + ArrowFree(private_data); + stream->release = NULL; +} + +static ArrowErrorCode ArrowIpcOutputStreamFileWrite(struct ArrowIpcOutputStream* stream, + const void* buf, + int64_t buf_size_bytes, + int64_t* size_written_out, + struct ArrowError* error) { + struct ArrowIpcOutputStreamFilePrivate* private_data = + (struct ArrowIpcOutputStreamFilePrivate*)stream->private_data; + + if (private_data->stream_finished) { + *size_written_out = 0; + return NANOARROW_OK; + } + + // Do the write + int64_t bytes_written = (int64_t)fwrite(buf, 1, buf_size_bytes, private_data->file_ptr); + *size_written_out = bytes_written; + + if (bytes_written != buf_size_bytes) { + private_data->stream_finished = 1; + + // Inspect error + int has_error = !feof(private_data->file_ptr) && ferror(private_data->file_ptr); + + // Try to close the file now + if (private_data->close_on_release) { + if (fclose(private_data->file_ptr) == 0) { + private_data->file_ptr = NULL; + } + } + + // Maybe return error + if (has_error) { + ArrowErrorSet(error, "ArrowIpcOutputStreamFile IO error"); + return EIO; + } + } + + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcOutputStreamInitFile(struct ArrowIpcOutputStream* stream, + void* file_ptr, int close_on_release) { + NANOARROW_DCHECK(stream != NULL); + if (file_ptr == NULL) { + return errno ? errno : EINVAL; + } + + struct ArrowIpcOutputStreamFilePrivate* private_data = + (struct ArrowIpcOutputStreamFilePrivate*)ArrowMalloc( + sizeof(struct ArrowIpcOutputStreamFilePrivate)); + if (private_data == NULL) { + return ENOMEM; + } + + private_data->file_ptr = (FILE*)file_ptr; + private_data->close_on_release = close_on_release; + private_data->stream_finished = 0; + + stream->write = &ArrowIpcOutputStreamFileWrite; + stream->release = &ArrowIpcOutputStreamFileRelease; + stream->private_data = private_data; + return NANOARROW_OK; +} + +struct ArrowIpcWriterPrivate { + struct ArrowIpcEncoder encoder; + struct ArrowIpcOutputStream output_stream; + struct ArrowBuffer buffer; + struct ArrowBuffer body_buffer; + + int writing_file; + int64_t bytes_written; + struct ArrowIpcFooter footer; +}; + +ArrowErrorCode ArrowIpcWriterInit(struct ArrowIpcWriter* writer, + struct ArrowIpcOutputStream* output_stream) { + NANOARROW_DCHECK(writer != NULL && output_stream != NULL); + + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)ArrowMalloc(sizeof(struct ArrowIpcWriterPrivate)); + + if (private == NULL) { + return ENOMEM; + } + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderInit(&private->encoder)); + ArrowIpcOutputStreamMove(output_stream, &private->output_stream); + + ArrowBufferInit(&private->buffer); + ArrowBufferInit(&private->body_buffer); + + private->writing_file = 0; + private->bytes_written = 0; + ArrowIpcFooterInit(&private->footer); + + writer->private_data = private; + return NANOARROW_OK; +} + +void ArrowIpcWriterReset(struct ArrowIpcWriter* writer) { + NANOARROW_DCHECK(writer != NULL); + + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)writer->private_data; + + if (private != NULL) { + ArrowIpcEncoderReset(&private->encoder); + private->output_stream.release(&private->output_stream); + ArrowBufferReset(&private->buffer); + ArrowBufferReset(&private->body_buffer); + + ArrowIpcFooterReset(&private->footer); + + ArrowFree(private); + } + memset(writer, 0, sizeof(struct ArrowIpcWriter)); +} + +static struct ArrowBufferView ArrowBufferToBufferView(const struct ArrowBuffer* buffer) { + struct ArrowBufferView buffer_view = { + .data.as_uint8 = buffer->data, + .size_bytes = buffer->size_bytes, + }; + return buffer_view; +} + +// Eventually, it may be necessary to construct an ArrowIpcWriter which doesn't rely on +// blocking writes (ArrowIpcOutputStreamWrite). For example an ArrowIpcOutputStream +// might wrap a socket which is not always able to transmit all bytes of a Message. In +// that case users of ArrowIpcWriter might prefer to do other work until a socket is +// ready rather than blocking, or timeout, or otherwise respond to partial transmission. +// +// This could be handled by: +// - keeping partially sent buffers internal and signalling incomplete transmission by +// raising EAGAIN, returning "bytes actually written", ... +// - when the caller is ready to try again, call ArrowIpcWriterWriteSome() +// - exposing internal buffers which have not been completely sent, deferring +// follow-up transmission to the caller + +ArrowErrorCode ArrowIpcWriterWriteSchema(struct ArrowIpcWriter* writer, + const struct ArrowSchema* in, + struct ArrowError* error) { + NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL && in != NULL); + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)writer->private_data; + + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffer, 0, 0)); + + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderEncodeSchema(&private->encoder, in, error)); + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowIpcEncoderFinalizeBuffer(&private->encoder, /*encapsulate=*/1, + &private->buffer), + error); + + if (private->writing_file) { + NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowSchemaDeepCopy(in, &private->footer.schema), + error); + } + private->bytes_written += private->buffer.size_bytes; + + return ArrowIpcOutputStreamWrite(&private->output_stream, + ArrowBufferToBufferView(&private->buffer), error); +} + +ArrowErrorCode ArrowIpcWriterWriteArrayView(struct ArrowIpcWriter* writer, + const struct ArrowArrayView* in, + struct ArrowError* error) { + NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL); + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)writer->private_data; + + if (in == NULL) { + int32_t eos[] = {-1, 0}; + private->bytes_written += sizeof(eos); + struct ArrowBufferView eos_view = {.data.as_int32 = eos, .size_bytes = sizeof(eos)}; + return ArrowIpcOutputStreamWrite(&private->output_stream, eos_view, error); + } + + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffer, 0, 0)); + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->body_buffer, 0, 0)); + + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderEncodeSimpleRecordBatch( + &private->encoder, in, &private->body_buffer, error)); + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowIpcEncoderFinalizeBuffer(&private->encoder, /*encapsulate=*/1, + &private->buffer), + error); + + if (private->writing_file) { + _NANOARROW_CHECK_RANGE(private->buffer.size_bytes, 0, INT32_MAX); + struct ArrowIpcFileBlock block = { + .offset = private->bytes_written, + .metadata_length = (int32_t) private->buffer.size_bytes, + .body_length = private->body_buffer.size_bytes, + }; + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferAppend(&private->footer.record_batch_blocks, &block, sizeof(block)), + error); + } + private->bytes_written += private->buffer.size_bytes; + private->bytes_written += private->body_buffer.size_bytes; + + NANOARROW_RETURN_NOT_OK(ArrowIpcOutputStreamWrite( + &private->output_stream, ArrowBufferToBufferView(&private->buffer), error)); + NANOARROW_RETURN_NOT_OK(ArrowIpcOutputStreamWrite( + &private->output_stream, ArrowBufferToBufferView(&private->body_buffer), error)); + return NANOARROW_OK; +} + +static ArrowErrorCode ArrowIpcWriterWriteArrayStreamImpl( + struct ArrowIpcWriter* writer, struct ArrowArrayStream* in, + struct ArrowSchema* schema, struct ArrowArray* array, + struct ArrowArrayView* array_view, struct ArrowError* error) { + NANOARROW_RETURN_NOT_OK(ArrowArrayStreamGetSchema(in, schema, error)); + NANOARROW_RETURN_NOT_OK(ArrowIpcWriterWriteSchema(writer, schema, error)); + + NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromSchema(array_view, schema, error)); + while (1) { + NANOARROW_RETURN_NOT_OK(ArrowArrayStreamGetNext(in, array, error)); + if (array->release == NULL) { + break; + } + + NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArray(array_view, array, error)); + NANOARROW_RETURN_NOT_OK(ArrowIpcWriterWriteArrayView(writer, array_view, error)); + ArrowArrayRelease(array); + } + + // The stream is complete, signal the end to the caller + return ArrowIpcWriterWriteArrayView(writer, NULL, error); +} + +ArrowErrorCode ArrowIpcWriterWriteArrayStream(struct ArrowIpcWriter* writer, + struct ArrowArrayStream* in, + struct ArrowError* error) { + NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL && in != NULL); + + struct ArrowSchema schema = {.release = NULL}; + struct ArrowArray array = {.release = NULL}; + struct ArrowArrayView array_view; + ArrowArrayViewInitFromType(&array_view, NANOARROW_TYPE_UNINITIALIZED); + + ArrowErrorCode result = + ArrowIpcWriterWriteArrayStreamImpl(writer, in, &schema, &array, &array_view, error); + + if (schema.release != NULL) { + ArrowSchemaRelease(&schema); + } + + if (array.release != NULL) { + ArrowArrayRelease(&array); + } + + ArrowArrayViewReset(&array_view); + + return result; +} + +#define NANOARROW_IPC_FILE_PADDED_MAGIC "ARROW1\0" + +ArrowErrorCode ArrowIpcWriterStartFile(struct ArrowIpcWriter* writer, + struct ArrowError* error) { + NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL); + + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)writer->private_data; + + NANOARROW_DCHECK(!private->writing_file && private->bytes_written == 0); + + struct ArrowBufferView magic = { + .data.data = NANOARROW_IPC_FILE_PADDED_MAGIC, + .size_bytes = sizeof(NANOARROW_IPC_FILE_PADDED_MAGIC), + }; + NANOARROW_RETURN_NOT_OK( + ArrowIpcOutputStreamWrite(&private->output_stream, magic, error)); + + private->writing_file = 1; + private->bytes_written = magic.size_bytes; + return NANOARROW_OK; +} + +ArrowErrorCode ArrowIpcWriterFinalizeFile(struct ArrowIpcWriter* writer, + struct ArrowError* error) { + NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL); + + struct ArrowIpcWriterPrivate* private = + (struct ArrowIpcWriterPrivate*)writer->private_data; + + NANOARROW_DCHECK(private->writing_file); + + NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffer, 0, 0)); + NANOARROW_RETURN_NOT_OK( + ArrowIpcEncoderEncodeFooter(&private->encoder, &private->footer, error)); + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowIpcEncoderFinalizeBuffer(&private->encoder, /*encapsulate=*/0, + &private->buffer), + error); + + _NANOARROW_CHECK_RANGE(private->buffer.size_bytes, 0, INT32_MAX); + int32_t size = (int32_t) private->buffer.size_bytes; + // we don't pad the magic at the end of the file + struct ArrowStringView unpadded_magic = ArrowCharView(NANOARROW_IPC_FILE_PADDED_MAGIC); + NANOARROW_DCHECK(unpadded_magic.size_bytes == 6); + + // just append to private->buffer instead of queueing two more tiny writes + NANOARROW_RETURN_NOT_OK_WITH_ERROR( + ArrowBufferReserve(&private->buffer, sizeof(size) + unpadded_magic.size_bytes), + error); + + if (ArrowIpcSystemEndianness() == NANOARROW_IPC_ENDIANNESS_BIG) { + size = (int32_t)bswap32((uint32_t)size); + } + NANOARROW_ASSERT_OK(ArrowBufferAppendInt32(&private->buffer, size)); + NANOARROW_ASSERT_OK(ArrowBufferAppendStringView(&private->buffer, unpadded_magic)); + + NANOARROW_RETURN_NOT_OK(ArrowIpcOutputStreamWrite( + &private->output_stream, ArrowBufferToBufferView(&private->buffer), error)); + private->bytes_written += private->buffer.size_bytes; + return NANOARROW_OK; +} From 8e0eaf8dcb51bdd340ca6e5229e7c3c2de4248d7 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:25:41 -0500 Subject: [PATCH 03/11] style: reformat existing C sources with project clang-format Pure clang-format reflow (K&R/PostgreSQL brace and wrapping style -> the project's Google-derived .clang-format). No logic changes. These files were never format-enforced before because the mise/CI globs only matched .cc. --- src/hooks/hooks.c | 43 +++++------- src/hooks/query_normalize_state.c | 107 +++++++++++------------------- src/queue/psch_dsa.c | 3 +- 3 files changed, 56 insertions(+), 97 deletions(-) diff --git a/src/hooks/hooks.c b/src/hooks/hooks.c index 6d99d3a..214163d 100644 --- a/src/hooks/hooks.c +++ b/src/hooks/hooks.c @@ -123,8 +123,8 @@ static void EnsureBackendCache(void) { datname != NULL ? datname : ""); // Client address (session-stable) - backend_state.client_addr_len = (uint8)( - GetClientAddress(backend_state.client_addr, sizeof(backend_state.client_addr))); + backend_state.client_addr_len = + (uint8)(GetClientAddress(backend_state.client_addr, sizeof(backend_state.client_addr))); // Username (may change via SET ROLE) CacheUsername(userid, true); @@ -165,8 +165,7 @@ static PschCmdType ConvertCmdType(CmdType cmd) { } static int64 TimeDiffMicrosec(struct timeval end, struct timeval start) { - return ((int64)(end.tv_sec - start.tv_sec) * 1000000LL) + - (int64)(end.tv_usec - start.tv_usec); + return ((int64)(end.tv_sec - start.tv_sec) * 1000000LL) + (int64)(end.tv_usec - start.tv_usec); } // Unpack SQLSTATE code from PostgreSQL's packed format to string @@ -225,9 +224,9 @@ static int GetClientAddress(char* buf, int buf_size) { char remote_host[NI_MAXHOST] = {0}; - int ret = pg_getnameinfo_all(&beentry->st_clientaddr.addr, beentry->st_clientaddr.salen, - remote_host, sizeof(remote_host), NULL, 0, - NI_NUMERICHOST | NI_NUMERICSERV); + int ret = + pg_getnameinfo_all(&beentry->st_clientaddr.addr, beentry->st_clientaddr.salen, remote_host, + sizeof(remote_host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); if (ret != 0 || remote_host[0] == '\0') { return 0; @@ -324,8 +323,8 @@ static void InitBaseEvent(PschEvent* event, TimestampTz ts_start, bool top_level } static void CopyClientContext(PschEvent* event) { - event->application_name_len = (uint8)( - GetApplicationName(event->application_name, sizeof(event->application_name))); + event->application_name_len = + (uint8)(GetApplicationName(event->application_name, sizeof(event->application_name))); EnsureBackendCache(); if (backend_state.initialized) { @@ -371,8 +370,8 @@ static void ResolveNames(PschEvent* event) { username = GetUserNameFromId(event->userid, true); } - event->datname_len = PschCopyName(event->datname, sizeof(event->datname), - datname != NULL ? datname : ""); + event->datname_len = + PschCopyName(event->datname, sizeof(event->datname), datname != NULL ? datname : ""); event->username_len = PschCopyName(event->username, sizeof(event->username), username != NULL ? username : ""); } @@ -384,14 +383,10 @@ static void CopyJitInstrumentation(PschEvent* event pg_attribute_unused(), if (query_desc->estate->es_jit != NULL) { JitInstrumentation* jit = &query_desc->estate->es_jit->instr; event->jit_functions = (int32)(jit->created_functions); - event->jit_generation_time_us = - (int32)(INSTR_TIME_GET_MICROSEC(jit->generation_counter)); - event->jit_inlining_time_us = - (int32)(INSTR_TIME_GET_MICROSEC(jit->inlining_counter)); - event->jit_optimization_time_us = - (int32)(INSTR_TIME_GET_MICROSEC(jit->optimization_counter)); - event->jit_emission_time_us = - (int32)(INSTR_TIME_GET_MICROSEC(jit->emission_counter)); + event->jit_generation_time_us = (int32)(INSTR_TIME_GET_MICROSEC(jit->generation_counter)); + event->jit_inlining_time_us = (int32)(INSTR_TIME_GET_MICROSEC(jit->inlining_counter)); + event->jit_optimization_time_us = (int32)(INSTR_TIME_GET_MICROSEC(jit->optimization_counter)); + event->jit_emission_time_us = (int32)(INSTR_TIME_GET_MICROSEC(jit->emission_counter)); #if PG_VERSION_NUM >= 170000 event->jit_deform_time_us = (int32)(INSTR_TIME_GET_MICROSEC(jit->deform_counter)); #endif @@ -404,10 +399,8 @@ static void CopyParallelWorkerInfo(PschEvent* event pg_attribute_unused(), QueryDesc* query_desc pg_attribute_unused()) { #if PG_VERSION_NUM >= 180000 if (query_desc->estate != NULL) { - event->parallel_workers_planned = - (int16)(query_desc->estate->es_parallel_workers_to_launch); - event->parallel_workers_launched = - (int16)(query_desc->estate->es_parallel_workers_launched); + event->parallel_workers_planned = (int16)(query_desc->estate->es_parallel_workers_to_launch); + event->parallel_workers_launched = (int16)(query_desc->estate->es_parallel_workers_launched); } #endif } @@ -856,8 +849,8 @@ static void CaptureLogEvent(ErrorData* edata) { event.err_elevel = (uint8)(edata->elevel); if (edata->message != NULL) { - event.err_message_len = (uint16)( - PschCopyTrimmed(event.err_message, PSCH_MAX_ERR_MSG_LEN, edata->message)); + event.err_message_len = + (uint16)(PschCopyTrimmed(event.err_message, PSCH_MAX_ERR_MSG_LEN, edata->message)); } CopyClientContext(&event); diff --git a/src/hooks/query_normalize_state.c b/src/hooks/query_normalize_state.c index d04d761..4b41cab 100644 --- a/src/hooks/query_normalize_state.c +++ b/src/hooks/query_normalize_state.c @@ -19,117 +19,94 @@ #define PSCH_MAX_CACHED_QUERY_LEN 2048 // HTAB key — just the queryId. -typedef struct PschNormalizeCacheKey -{ +typedef struct PschNormalizeCacheKey { uint64 query_id; } PschNormalizeCacheKey; // Entry stored in HTAB. key must be the first member so hash_search can // cast between key pointer and entry pointer. -typedef struct PschNormalizeCacheEntry -{ +typedef struct PschNormalizeCacheEntry { PschNormalizeCacheKey key; dlist_node lru_node; - char *normalized_query; // palloc'd in cache->mcxt + char* normalized_query; // palloc'd in cache->mcxt int normalized_len; } PschNormalizeCacheEntry; -static PschNormalizeCacheKey -MakeCacheKey(uint64 query_id) -{ +static PschNormalizeCacheKey MakeCacheKey(uint64 query_id) { PschNormalizeCacheKey key; key.query_id = query_id; return key; } -static void -EnsureCacheInitialized(PschNormalizedQueryCache *cache) -{ +static void EnsureCacheInitialized(PschNormalizedQueryCache* cache) { int max_entries; if (cache->htab != NULL) return; - max_entries = cache->max_entries > 0 ? cache->max_entries - : psch_normalize_cache_max; + max_entries = cache->max_entries > 0 ? cache->max_entries : psch_normalize_cache_max; PschInitNormalizedQueryCache(cache, max_entries); } -static int -ClampCachedQueryLen(int normalized_len) -{ +static int ClampCachedQueryLen(int normalized_len) { if (normalized_len >= PSCH_MAX_CACHED_QUERY_LEN) return PSCH_MAX_CACHED_QUERY_LEN - 1; return normalized_len; } -static void -PushEntryToMru(PschNormalizedQueryCache *cache, PschNormalizeCacheEntry *entry) -{ +static void PushEntryToMru(PschNormalizedQueryCache* cache, PschNormalizeCacheEntry* entry) { dclist_push_head(&cache->lru, &entry->lru_node); } -static void -PromoteEntryToMru(PschNormalizedQueryCache *cache, PschNormalizeCacheEntry *entry) -{ +static void PromoteEntryToMru(PschNormalizedQueryCache* cache, PschNormalizeCacheEntry* entry) { dclist_delete_from(&cache->lru, &entry->lru_node); PushEntryToMru(cache, entry); } -static char * -CopyQueryText(PschNormalizedQueryCache *cache, const char *normalized_query, - int normalized_len) -{ - char *copy; +static char* CopyQueryText(PschNormalizedQueryCache* cache, const char* normalized_query, + int normalized_len) { + char* copy; - copy = (char *) MemoryContextAlloc(cache->mcxt, normalized_len + 1); + copy = (char*)MemoryContextAlloc(cache->mcxt, normalized_len + 1); memcpy(copy, normalized_query, normalized_len); copy[normalized_len] = '\0'; return copy; } -static uint16 -CopyEntryText(const PschNormalizeCacheEntry *entry, char *dst, Size dst_size) -{ +static uint16 CopyEntryText(const PschNormalizeCacheEntry* entry, char* dst, Size dst_size) { Size len; - len = Min((Size) entry->normalized_len, dst_size - 1); + len = Min((Size)entry->normalized_len, dst_size - 1); memcpy(dst, entry->normalized_query, len); dst[len] = '\0'; - return (uint16) len; + return (uint16)len; } -void -PschInitNormalizedQueryCache(PschNormalizedQueryCache *cache, int max_entries) -{ +void PschInitNormalizedQueryCache(PschNormalizedQueryCache* cache, int max_entries) { HASHCTL info; Assert(cache != NULL); Assert(max_entries >= PSCH_NORMALIZE_CACHE_MIN_MAX); - cache->mcxt = AllocSetContextCreate(TopMemoryContext, - "pg_stat_ch normalize cache", - ALLOCSET_DEFAULT_SIZES); + cache->mcxt = + AllocSetContextCreate(TopMemoryContext, "pg_stat_ch normalize cache", ALLOCSET_DEFAULT_SIZES); MemSet(&info, 0, sizeof(info)); info.keysize = sizeof(PschNormalizeCacheKey); info.entrysize = sizeof(PschNormalizeCacheEntry); info.hcxt = cache->mcxt; - cache->htab = hash_create("pg_stat_ch normalize cache", - Min(max_entries, 256), &info, + cache->htab = hash_create("pg_stat_ch normalize cache", Min(max_entries, 256), &info, HASH_ELEM | HASH_BLOBS | HASH_CONTEXT); dclist_init(&cache->lru); cache->max_entries = max_entries; } // Evict the least-recently-used entry (tail of LRU list). -static void -EvictLru(PschNormalizedQueryCache *cache) -{ - dlist_node *tail; - PschNormalizeCacheEntry *victim; +static void EvictLru(PschNormalizedQueryCache* cache) { + dlist_node* tail; + PschNormalizeCacheEntry* victim; PschNormalizeCacheKey victim_key; Assert(!dclist_is_empty(&cache->lru)); @@ -144,12 +121,10 @@ EvictLru(PschNormalizedQueryCache *cache) hash_search(cache->htab, &victim_key, HASH_REMOVE, NULL); } -void -PschRememberNormalizedQuery(PschNormalizedQueryCache *cache, uint64 query_id, - const char *normalized_query, int normalized_len) -{ +void PschRememberNormalizedQuery(PschNormalizedQueryCache* cache, uint64 query_id, + const char* normalized_query, int normalized_len) { PschNormalizeCacheKey hkey; - PschNormalizeCacheEntry *entry; + PschNormalizeCacheEntry* entry; bool found; if (cache == NULL || normalized_query == NULL || query_id == UINT64CONST(0)) @@ -158,19 +133,15 @@ PschRememberNormalizedQuery(PschNormalizedQueryCache *cache, uint64 query_id, EnsureCacheInitialized(cache); hkey = MakeCacheKey(query_id); - entry = (PschNormalizeCacheEntry *) hash_search(cache->htab, &hkey, - HASH_ENTER, &found); + entry = (PschNormalizeCacheEntry*)hash_search(cache->htab, &hkey, HASH_ENTER, &found); - if (found) - { + if (found) { // Update existing entry — free old text and requeue it as MRU below. pfree(entry->normalized_query); dclist_delete_from(&cache->lru, &entry->lru_node); - } - else - { + } else { // New entry — evict LRU if at capacity. - if ((int) dclist_count(&cache->lru) >= cache->max_entries) + if ((int)dclist_count(&cache->lru) >= cache->max_entries) EvictLru(cache); } @@ -179,26 +150,22 @@ PschRememberNormalizedQuery(PschNormalizedQueryCache *cache, uint64 query_id, normalized_len = ClampCachedQueryLen(normalized_len); // Copy text into the cache's own memory context. - entry->normalized_query = CopyQueryText(cache, normalized_query, - normalized_len); + entry->normalized_query = CopyQueryText(cache, normalized_query, normalized_len); entry->normalized_len = normalized_len; PushEntryToMru(cache, entry); } -bool -PschLookupNormalizedQuery(PschNormalizedQueryCache *cache, uint64 query_id, - char *dst, Size dst_size, uint16 *out_len) -{ +bool PschLookupNormalizedQuery(PschNormalizedQueryCache* cache, uint64 query_id, char* dst, + Size dst_size, uint16* out_len) { PschNormalizeCacheKey hkey; - PschNormalizeCacheEntry *entry; + PschNormalizeCacheEntry* entry; - if (cache == NULL || cache->htab == NULL || dst == NULL || dst_size == 0 || - out_len == NULL || query_id == UINT64CONST(0)) + if (cache == NULL || cache->htab == NULL || dst == NULL || dst_size == 0 || out_len == NULL || + query_id == UINT64CONST(0)) return false; hkey = MakeCacheKey(query_id); - entry = (PschNormalizeCacheEntry *) hash_search(cache->htab, &hkey, - HASH_FIND, NULL); + entry = (PschNormalizeCacheEntry*)hash_search(cache->htab, &hkey, HASH_FIND, NULL); if (entry == NULL) return false; diff --git a/src/queue/psch_dsa.c b/src/queue/psch_dsa.c index dc45031..612cdb0 100644 --- a/src/queue/psch_dsa.c +++ b/src/queue/psch_dsa.c @@ -23,8 +23,7 @@ static bool psch_dsa_exit_hook_registered = false; // but because there is no containing DSM segment, PostgreSQL won't release it // automatically. We must detach the backend-local handle and drop the shared // reference explicitly on backend/bgworker exit (see pgstat_detach_shmem()). -static void PschDsaDetachOnExit(int code pg_attribute_unused(), - Datum arg pg_attribute_unused()) { +static void PschDsaDetachOnExit(int code pg_attribute_unused(), Datum arg pg_attribute_unused()) { if (psch_dsa != NULL) { dsa_detach(psch_dsa); psch_dsa = NULL; From cb92469124dc90e9026cb6120a7971ac58f23191 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:06 -0500 Subject: [PATCH 04/11] feat(export): C exporter interface and OTLP protobuf encoder Replace the C++ virtual exporter_interface.h with exporter.h: a function-pointer ops table (connect/export_events/send_arrow/...), the PschExportStatus contract, and the preallocated export-arena split shared by driver and backends. Add otlp_encode.{h,c}: a hand-rolled, zero-allocation protobuf wire encoder for OTLP logs pinned to opentelemetry-proto v1.9.0. Single-pass nested messages via fixed-width overlong varint length slots; overflow-safe (sticky flag, no partial out-of-bounds writes); bounds-checked response/Status parsers. PschPbMsgEnd flags overflow rather than Assert()ing on an unbalanced slot, so an encoder bug cannot SIGABRT the bgworker. --- src/export/exporter.h | 113 +++++++++ src/export/exporter_interface.h | 111 --------- src/export/otlp_encode.c | 430 ++++++++++++++++++++++++++++++++ src/export/otlp_encode.h | 99 ++++++++ 4 files changed, 642 insertions(+), 111 deletions(-) create mode 100644 src/export/exporter.h delete mode 100644 src/export/exporter_interface.h create mode 100644 src/export/otlp_encode.c create mode 100644 src/export/otlp_encode.h diff --git a/src/export/exporter.h b/src/export/exporter.h new file mode 100644 index 0000000..d22257d --- /dev/null +++ b/src/export/exporter.h @@ -0,0 +1,113 @@ +// pg_stat_ch C exporter interface — replaces the C++ exporter_interface.h. +// +// Contract highlights (see OTEL_REWRITE_DESIGN.md §3, §5a): +// * Backends consume PschEvent arrays directly; there is no column-handle +// abstraction and no per-row heap allocation. +// * All buffers a backend needs are preallocated in its create function; +// steady-state export performs zero heap allocation. Allocation failure +// at create time returns NULL (caller decides FATAL); after create, OOM +// is impossible by construction on the hot path. +// * No function in this interface may ereport(ERROR) or longjmp. WARNING/ +// LOG/DEBUG elevels only. Backends must tolerate a longjmp having +// interrupted the previous call (reset batch state on entry; force +// reconnect if a wire protocol exchange was in flight). +// * Every failed connect/export_events/send_arrow MUST increment the +// backend's consecutive-failure counter (drives bgworker backoff); every +// success resets it. This is what prevents the 2/sec retry flood. +#ifndef PG_STAT_CH_EXPORTER_H +#define PG_STAT_CH_EXPORTER_H + +#include "queue/event.h" + +typedef enum PschExportStatus { + PSCH_EXPORT_OK = 0, + PSCH_EXPORT_ERR_NOMEM, // checked allocation failed (should be init-only; poison-drop if hot) + PSCH_EXPORT_ERR_CONN, // could not (re)connect — events must NOT be consumed + PSCH_EXPORT_ERR_SEND, // wire send/response failure — events must NOT be consumed + PSCH_EXPORT_ERR_INTERNAL, // encode/build failure — poison batch, consume + count as export-drop +} PschExportStatus; + +typedef struct PschExporter PschExporter; + +typedef struct PschExporterOps { + // (Re)establish the connection. Bounded by psch_export_timeout_ms. + // On failure: write a NUL-terminated reason into errbuf, return false. + bool (*connect)(PschExporter* self, char* errbuf, size_t errlen); + bool (*is_connected)(const PschExporter* self); + + // Export a batch of events (per-record path). Sets *exported_out to the + // number of events confirmed sent (0 on failure). Must be all-or-nothing + // per call from the caller's consume perspective: the driver consumes the + // staged chunk iff PSCH_EXPORT_OK (or poison-drops on INTERNAL/NOMEM). + PschExportStatus (*export_events)(PschExporter* self, const PschEvent* events, int nevents, + int* exported_out); + + // Send a finished Arrow IPC payload (arrow passthrough path). + // NULL when the backend does not support it (ClickHouse backend). + PschExportStatus (*send_arrow)(PschExporter* self, const uint8* ipc_data, size_t ipc_len, + int num_rows); + + int (*consecutive_failures)(const PschExporter* self); + void (*reset_failures)(PschExporter* self); + + // Total bytes this backend preallocated (observability; pg_stat_ch_memory). + uint64 (*mem_used)(const PschExporter* self); + + // Idempotent; must tolerate half-initialized state (on_proc_exit may run + // it during FATAL-from-init). Must not ereport(ERROR). + void (*destroy)(PschExporter* self); +} PschExporterOps; + +// Backends embed this as their first member and downcast. +struct PschExporter { + const PschExporterOps* ops; +}; + +// Backend factories. Preallocate everything per the arena plan; on failure +// write a reason into errbuf and return NULL (caller ereport(FATAL)s — a +// worker that cannot preallocate is useless and a clean restart is correct). +extern PschExporter* PschClickHouseExporterCreate(char* errbuf, size_t errlen); +extern PschExporter* PschOtelExporterCreate(char* errbuf, size_t errlen); + +// --------------------------------------------------------------------------- +// Export arena split. The GUC layer resolves a single export_arena_bytes +// budget (src/config/memory_budget.h); this is the one place its internal +// split is defined so the driver (staging) and the OTel backend (encode/net/ +// arrow scratch) cannot disagree. Both export paths are preallocated +// simultaneously because otel_arrow_passthrough is SIGHUP-switchable. +// --------------------------------------------------------------------------- +typedef struct PschExportArenaPlan { + int staging_events; // PschEvent staging chunk (driver-owned) + size_t staging_bytes; // == staging_events * sizeof(PschEvent) + size_t encode_buf_bytes; // OTLP request encode buffer, UNCOMPRESSED payload cap + size_t net_buf_bytes; // HTTP response / scratch buffer + size_t arrow_scratch_bytes; // nanoarrow build buffers + IPC emit + ZSTD workspace +} PschExportArenaPlan; + +// Encode ceiling: otelcol max_request_body_size defaults to 20 MiB and is +// enforced on the DECOMPRESSED body — the cap must bound uncompressed bytes. +#define PSCH_EXPORT_ENCODE_CEILING ((size_t)16 * 1024 * 1024) + +static inline void PschExportArenaSplit(uint64 arena_bytes, PschExportArenaPlan* plan) { + uint64 staging = arena_bytes * 45 / 100; + uint64 arrow = arena_bytes * 30 / 100; + uint64 encode = arena_bytes * 20 / 100; + uint64 net = arena_bytes - staging - arrow - encode; + + if (staging < 256 * sizeof(PschEvent)) + staging = 256 * sizeof(PschEvent); + if (encode < 256 * 1024) + encode = 256 * 1024; + if (encode > PSCH_EXPORT_ENCODE_CEILING) + encode = PSCH_EXPORT_ENCODE_CEILING; + if (net < 64 * 1024) + net = 64 * 1024; + + plan->staging_events = (int)(staging / sizeof(PschEvent)); + plan->staging_bytes = (size_t)plan->staging_events * sizeof(PschEvent); + plan->encode_buf_bytes = (size_t)encode; + plan->net_buf_bytes = (size_t)net; + plan->arrow_scratch_bytes = (size_t)arrow; +} + +#endif // PG_STAT_CH_EXPORTER_H diff --git a/src/export/exporter_interface.h b/src/export/exporter_interface.h deleted file mode 100644 index 1dad609..0000000 --- a/src/export/exporter_interface.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef PG_STAT_CH_SRC_EXPORT_EXPORTER_INTERFACE_H_ -#define PG_STAT_CH_SRC_EXPORT_EXPORTER_INTERFACE_H_ - -#include -#include -#include -#include -#include - -class StatsExporter { - protected: - using string = std::string; - using string_view = std::string_view; - template - using shared_ptr = std::shared_ptr; - - class BasicColumn { - public: - virtual void Crunch() = 0; // Implementation-defined processing helper. - virtual void Clear() {} - virtual ~BasicColumn() = default; - }; - template - class Column : public BasicColumn { - public: - virtual void Append(const T& t) = 0; - virtual ~Column() = default; - }; - - public: - // Tags: Columns that serve as narrowing criteria for metrics. - virtual shared_ptr> TagString(string_view name) = 0; - - // Metrics: Columns that are generally bucketed into histograms. - virtual shared_ptr> MetricInt16(string_view name) = 0; - virtual shared_ptr> MetricInt32(string_view name) = 0; - virtual shared_ptr> MetricInt64(string_view name) = 0; - virtual shared_ptr> MetricUInt8(string_view name) = 0; - virtual shared_ptr> MetricUInt64(string_view name) = 0; - virtual shared_ptr> MetricFixedString(int len, string_view name) = 0; - - // Records: Data columns you wouldn't want to filter by. - virtual shared_ptr> RecordInt16(string_view name) = 0; - virtual shared_ptr> RecordInt32(string_view name) = 0; - virtual shared_ptr> RecordInt64(string_view name) = 0; - virtual shared_ptr> RecordUInt8(string_view name) = 0; - virtual shared_ptr> RecordUInt64(string_view name) = 0; - virtual shared_ptr> RecordDateTime(string_view name) = 0; - virtual shared_ptr> RecordString(string_view name) = 0; - - // =========================================================================== - // Semantic columns: name, unit, and instrument type may vary by backend. - // Add a column here only when its behavior meaningfully differs across - // exporters (e.g. OTel semconv requires a different name, unit, or - // instrument). Pure virtuals enforce explicit handling in every exporter. - // =========================================================================== - - // Database name. CH: TagString "db"; OTel semconv: "db.name" tag. - virtual shared_ptr> DbNameColumn() = 0; - // Authenticated user. CH: TagString "username"; OTel semconv: "db.user" tag. - virtual shared_ptr> DbUserColumn() = 0; - // Query duration. Caller appends microseconds. CH: MetricUInt64 "duration_us"; - // OTel: converts to seconds, records as Histogram "db.client.operation.duration". - virtual shared_ptr> DbDurationColumn() = 0; - // SQL command type. CH: RecordString "cmd_type"; OTel: TagString "db.operation.name" - // (used as a dimension on the duration histogram). - virtual shared_ptr> DbOperationColumn() = 0; - // Query text. CH: RecordString "query"; OTel semconv: "db.query.text". - virtual shared_ptr> DbQueryTextColumn() = 0; - - virtual void BeginBatch() = 0; - virtual void BeginRow() = 0; - virtual bool CommitBatch() = 0; - - virtual bool EstablishNewConnection() = 0; - virtual bool IsConnected() const = 0; - virtual int NumConsecutiveFailures() const = 0; - virtual void ResetFailures() = 0; - virtual int NumExported() const = 0; - virtual bool SendArrowBatch(const uint8_t* ipc_data, size_t ipc_len, int num_rows) { - (void)ipc_data; - (void)ipc_len; - (void)num_rows; - return false; - } - - virtual ~StatsExporter() = default; -}; - -// Bridge functions for PG logging from files that cannot include postgres.h -// (e.g. otel_exporter.cc conflicts with libintl.h via gRPC headers). -void LogNegativeValue(const std::string& column_name, int64_t value); -void LogExporterWarning(const char* context, const char* message); -void RecordExporterFailure(const char* message); - -// Expected usage: -// void ProcessBatch(StatsExporter *exporter) { -// exporter->BeginBatch(); // no op or ClickHouse column reset -// auto col_user = exporter->TagString("username"); -// auto col_rows = exporter->MetricUInt64("rows"); -// -// for (const auto &ev : events) { -// exporter->BeginRow(); // no-op or initialize tag map -// col_user->Append(ev.username); -// col_rows->Append(ev.rows); -// } -// -// exporter->CommitBatch(); // Inserts or collects stats -// } - -#endif // PG_STAT_CH_SRC_EXPORT_EXPORTER_INTERFACE_H_ diff --git a/src/export/otlp_encode.c b/src/export/otlp_encode.c new file mode 100644 index 0000000..7e6d5a6 --- /dev/null +++ b/src/export/otlp_encode.c @@ -0,0 +1,430 @@ +// Protobuf wire encoder/decoder backing the OTLP/HTTP exporter (otlp_encode.h). +// +// Writer discipline: every emit computes its full byte cost before touching +// the buffer, so an overflowing write leaves the buffer byte-for-byte +// untouched and sets `overflow` exactly once; after that every write +// (including PschPbMsgEnd's slot patch) is a no-op. Nothing here allocates, +// ereports, or longjmps — safe on the export hot path. +// +// Host-test escape hatch: test/unit/otlp_encode_test.c defines +// PSCH_OTLP_ENCODE_HOST_TEST, supplies the minimal PG type surface +// (uint8/uint32/uint64/int32/int64/bool/Assert), and #includes this file +// directly so the encoder is unit-testable without a server build. In +// extension builds postgres.h stays the first include. +#ifndef PSCH_OTLP_ENCODE_HOST_TEST +#include "postgres.h" +#endif + +#include + +#include "otlp_encode.h" + +enum { + kPbWireVarint = 0, + kPbWireFixed64 = 1, + kPbWireLen = 2, + kPbWireFixed32 = 5, + // 3/4 are the deprecated group markers (illegal in proto3), 6/7 are unassigned. +}; + +// Largest message length representable in the 4-byte padded varint slot +// (2^28 - 1). PSCH_EXPORT_ENCODE_CEILING is 16 MiB, so a real encode can +// never get close; the check in PschPbMsgEnd is pure defense. +static const size_t kPbSlotMaxLen = 0x0FFFFFFF; + +// --------------------------------------------------------------------------- +// Debug-only Begin/End balance + depth guard. +// +// PschPbBuf carries no depth state (single-pass encoding needs none), so the +// guard keys file-local state to the buffer pointer. Marks from an encode +// abandoned by a longjmp self-heal: live ancestor slots are strictly +// increasing, so any recorded slot >= the new slot must be stale and is +// popped before the depth Assert. All bookkeeping is skipped once +// b->overflow is set — Begin/End are no-ops then, and tracking them would +// desynchronize the mark stack. +// --------------------------------------------------------------------------- +#ifdef USE_ASSERT_CHECKING + +static const PschPbBuf* pb_guard_buf = NULL; +static int pb_guard_depth = 0; +static size_t pb_guard_slots[PSCH_PB_MAX_DEPTH]; + +static void PbGuardBegin(const PschPbBuf* b, size_t slot) { + if (b != pb_guard_buf) { + pb_guard_buf = b; + pb_guard_depth = 0; + } + while (pb_guard_depth > 0 && pb_guard_slots[pb_guard_depth - 1] >= slot) + pb_guard_depth--; + Assert(pb_guard_depth < PSCH_PB_MAX_DEPTH); + if (pb_guard_depth < PSCH_PB_MAX_DEPTH) + pb_guard_slots[pb_guard_depth++] = slot; +} + +static void PbGuardEnd(const PschPbBuf* b, size_t slot) { + if (b != pb_guard_buf) + return; + Assert(pb_guard_depth > 0); + if (pb_guard_depth > 0) { + Assert(pb_guard_slots[pb_guard_depth - 1] == slot); + pb_guard_depth--; + } +} + +#else + +#define PbGuardBegin(b, slot) ((void)0) +#define PbGuardEnd(b, slot) ((void)0) + +#endif // USE_ASSERT_CHECKING + +// --------------------------------------------------------------------------- +// Writer primitives +// --------------------------------------------------------------------------- + +static inline size_t PbVarintLen(uint64 value) { + size_t n = 1; + while (value >= 0x80) { + value >>= 7; + n++; + } + return n; +} + +// Sets the sticky overflow flag when `need` bytes do not fit; the caller +// must not have written anything yet (all-or-nothing per emit). +static inline bool PbEnsure(PschPbBuf* b, size_t need) { + if (b->overflow) + return false; + if (b->cap - b->len < need) { + b->overflow = true; + return false; + } + return true; +} + +// Space must have been ensured by the caller. +static inline void PbPutVarint(PschPbBuf* b, uint64 value) { + while (value >= 0x80) { + b->data[b->len++] = (uint8)(value | 0x80); + value >>= 7; + } + b->data[b->len++] = (uint8)value; +} + +static inline uint64 PbTag(uint32 field, uint32 wire_type) { + return ((uint64)field << 3) | wire_type; +} + +void PschPbVarint(PschPbBuf* b, uint32 field, uint64 value) { + uint64 tag = PbTag(field, kPbWireVarint); + + if (!PbEnsure(b, PbVarintLen(tag) + PbVarintLen(value))) + return; + PbPutVarint(b, tag); + PbPutVarint(b, value); +} + +void PschPbFixed64(PschPbBuf* b, uint32 field, uint64 value) { + uint64 tag = PbTag(field, kPbWireFixed64); + + if (!PbEnsure(b, PbVarintLen(tag) + 8)) + return; + PbPutVarint(b, tag); + for (int i = 0; i < 8; i++) + b->data[b->len++] = (uint8)(value >> (8 * i)); +} + +void PschPbFixed32(PschPbBuf* b, uint32 field, uint32 value) { + uint64 tag = PbTag(field, kPbWireFixed32); + + if (!PbEnsure(b, PbVarintLen(tag) + 4)) + return; + PbPutVarint(b, tag); + for (int i = 0; i < 4; i++) + b->data[b->len++] = (uint8)(value >> (8 * i)); +} + +void PschPbDouble(PschPbBuf* b, uint32 field, double value) { + // IEEE-754 bit image, emitted little-endian (protobuf wire type 1). + uint64 bits; + + memcpy(&bits, &value, sizeof(bits)); + PschPbFixed64(b, field, bits); +} + +void PschPbBytes(PschPbBuf* b, uint32 field, const void* data, size_t len) { + uint64 tag = PbTag(field, kPbWireLen); + + if (!PbEnsure(b, PbVarintLen(tag) + PbVarintLen(len) + len)) + return; + PbPutVarint(b, tag); + PbPutVarint(b, len); + if (len > 0) { + memcpy(b->data + b->len, data, len); + b->len += len; + } +} + +void PschPbString(PschPbBuf* b, uint32 field, const char* s, size_t len) { + PschPbBytes(b, field, s, len); +} + +size_t PschPbMsgBegin(PschPbBuf* b, uint32 field) { + uint64 tag = PbTag(field, kPbWireLen); + size_t slot; + + // On overflow the returned slot is degenerate; the matching MsgEnd is a + // no-op, so it never gets dereferenced. + if (!PbEnsure(b, PbVarintLen(tag) + 4)) + return b->len; + PbPutVarint(b, tag); + slot = b->len; + memset(b->data + slot, 0, 4); + b->len += 4; + PbGuardBegin(b, slot); + return slot; +} + +void PschPbMsgEnd(PschPbBuf* b, size_t slot) { + size_t msg_len; + + if (b->overflow) + return; + PbGuardEnd(b, slot); + if (slot + 4 > b->len) { + // Garbage/unbalanced slot: programmer error. Refuse to scribble and flag + // overflow so the caller drops the batch. Deliberately NOT Assert(false): + // this runs on the bgworker, where a cassert/regression build would turn an + // encoder bug into SIGABRT -> database-wide crash recovery (the exact blast + // radius this rewrite exists to eliminate). + b->overflow = true; + return; + } + msg_len = b->len - slot - 4; + if (msg_len > kPbSlotMaxLen) { + b->overflow = true; + return; + } + // Overlong 4-byte varint: zero-padded with continuation bits, final byte + // clear. Legal protobuf; accepted by all conformant parsers. + b->data[slot] = (uint8)(msg_len & 0x7F) | 0x80; + b->data[slot + 1] = (uint8)((msg_len >> 7) & 0x7F) | 0x80; + b->data[slot + 2] = (uint8)((msg_len >> 14) & 0x7F) | 0x80; + b->data[slot + 3] = (uint8)((msg_len >> 21) & 0x7F); +} + +// --------------------------------------------------------------------------- +// OTLP common.v1 helpers +// --------------------------------------------------------------------------- + +void PschPbKvString(PschPbBuf* b, uint32 field, const char* key, const char* val, size_t val_len) { + size_t kv = PschPbMsgBegin(b, field); + size_t any; + + PschPbString(b, PSCH_OTLP_KV_KEY, key, strlen(key)); + any = PschPbMsgBegin(b, PSCH_OTLP_KV_VALUE); + PschPbString(b, PSCH_OTLP_ANY_STRING, val, val_len); + PschPbMsgEnd(b, any); + PschPbMsgEnd(b, kv); +} + +void PschPbKvInt(PschPbBuf* b, uint32 field, const char* key, int64 value) { + size_t kv = PschPbMsgBegin(b, field); + size_t any; + + PschPbString(b, PSCH_OTLP_KV_KEY, key, strlen(key)); + any = PschPbMsgBegin(b, PSCH_OTLP_KV_VALUE); + // proto3 int64: two's complement varint (10 bytes when negative), not zigzag. + PschPbVarint(b, PSCH_OTLP_ANY_INT, (uint64)value); + PschPbMsgEnd(b, any); + PschPbMsgEnd(b, kv); +} + +void PschPbKvDouble(PschPbBuf* b, uint32 field, const char* key, double value) { + size_t kv = PschPbMsgBegin(b, field); + size_t any; + + PschPbString(b, PSCH_OTLP_KV_KEY, key, strlen(key)); + any = PschPbMsgBegin(b, PSCH_OTLP_KV_VALUE); + PschPbDouble(b, PSCH_OTLP_ANY_DOUBLE, value); + PschPbMsgEnd(b, any); + PschPbMsgEnd(b, kv); +} + +// --------------------------------------------------------------------------- +// Response parsing. Bounds discipline: every read checks remaining bytes +// first; a parse that would over-read returns false instead. Unknown fields +// of all four live wire types are skipped; group markers (3/4) and invalid +// wire types (6/7) reject the input, as does field number 0. +// --------------------------------------------------------------------------- + +typedef struct PbReader { + const uint8* p; + const uint8* end; +} PbReader; + +static bool PbReadVarint(PbReader* r, uint64* value_out) { + uint64 value = 0; + + for (int i = 0; i < 10; i++) { + uint8 byte; + + if (r->p >= r->end) + return false; + byte = *r->p++; + value |= (uint64)(byte & 0x7F) << (7 * i); + if ((byte & 0x80) == 0) { + *value_out = value; + return true; + } + } + return false; // continuation bit set past 10 bytes: malformed +} + +static bool PbSkipField(PbReader* r, uint32 wire_type) { + uint64 skip; + + switch (wire_type) { + case kPbWireVarint: + return PbReadVarint(r, &skip); + case kPbWireFixed64: + if ((size_t)(r->end - r->p) < 8) + return false; + r->p += 8; + return true; + case kPbWireLen: + if (!PbReadVarint(r, &skip)) + return false; + if (skip > (uint64)(r->end - r->p)) + return false; + r->p += skip; + return true; + case kPbWireFixed32: + if ((size_t)(r->end - r->p) < 4) + return false; + r->p += 4; + return true; + default: + return false; + } +} + +// Truncating copy into the caller's fixed message buffer; always +// NUL-terminates when there is room for anything at all. +static void PbCopyMsg(char* msgbuf, size_t msglen, const uint8* src, size_t n) { + size_t ncopy; + + if (msgbuf == NULL || msglen == 0) + return; + ncopy = n < msglen - 1 ? n : msglen - 1; + if (ncopy > 0) + memcpy(msgbuf, src, ncopy); + msgbuf[ncopy] = '\0'; +} + +// ExportLogsPartialSuccess{ int64=1, string=2 } and google.rpc.Status +// { int32=1, string=2 } share this wire shape; proto3 last-one-wins applies +// to repeated occurrences of a scalar field. +static bool PbParseNumStrMsg(const uint8* data, size_t len, uint64* num_out, char* msgbuf, + size_t msglen) { + PbReader r; + + r.p = data; + r.end = data + len; + while (r.p < r.end) { + uint64 tag; + uint64 field; + uint32 wire_type; + + if (!PbReadVarint(&r, &tag)) + return false; + field = tag >> 3; + wire_type = (uint32)(tag & 7); + if (field == 0) + return false; + if (field == 1 && wire_type == kPbWireVarint) { + if (!PbReadVarint(&r, num_out)) + return false; + } else if (field == 2 && wire_type == kPbWireLen) { + uint64 n; + + if (!PbReadVarint(&r, &n)) + return false; + if (n > (uint64)(r.end - r.p)) + return false; + PbCopyMsg(msgbuf, msglen, r.p, (size_t)n); + r.p += n; + } else if (!PbSkipField(&r, wire_type)) { + return false; + } + } + return true; +} + +bool PschOtlpParseLogsResponse(const uint8* data, size_t len, int64* rejected_out, char* msgbuf, + size_t msglen) { + uint64 rejected = 0; + PbReader r; + + if (rejected_out != NULL) + *rejected_out = 0; + if (msgbuf != NULL && msglen > 0) + msgbuf[0] = '\0'; + if (len == 0) + return true; // empty body == full success (partial_success unset) + if (data == NULL) + return false; + + r.p = data; + r.end = data + len; + while (r.p < r.end) { + uint64 tag; + uint64 field; + uint32 wire_type; + + if (!PbReadVarint(&r, &tag)) + return false; + field = tag >> 3; + wire_type = (uint32)(tag & 7); + if (field == 0) + return false; + if (field == 1 && wire_type == kPbWireLen) { + uint64 n; + + if (!PbReadVarint(&r, &n)) + return false; + if (n > (uint64)(r.end - r.p)) + return false; + if (!PbParseNumStrMsg(r.p, (size_t)n, &rejected, msgbuf, msglen)) + return false; + r.p += n; + } else if (!PbSkipField(&r, wire_type)) { + return false; + } + } + if (rejected_out != NULL) + *rejected_out = (int64)rejected; + return true; +} + +bool PschRpcStatusParse(const uint8* data, size_t len, int32* code_out, char* msgbuf, + size_t msglen) { + uint64 code = 0; + + if (code_out != NULL) + *code_out = 0; + if (msgbuf != NULL && msglen > 0) + msgbuf[0] = '\0'; + if (len == 0) + return true; // empty Status: code 0, no message + if (data == NULL) + return false; + + if (!PbParseNumStrMsg(data, len, &code, msgbuf, msglen)) + return false; + // proto3 int32 arrives as the sign-extended 64-bit varint; truncate back. + if (code_out != NULL) + *code_out = (int32)code; + return true; +} diff --git a/src/export/otlp_encode.h b/src/export/otlp_encode.h new file mode 100644 index 0000000..548c661 --- /dev/null +++ b/src/export/otlp_encode.h @@ -0,0 +1,99 @@ +// Hand-rolled protobuf wire encoder for OTLP logs (opentelemetry-proto +// v1.9.0 field surface — see OTEL_REWRITE_DESIGN.md §2/§5). +// +// Properties: +// * Zero heap allocation: encodes into a caller-provided fixed buffer. +// * Overflow-safe: once the buffer would overflow, the `overflow` flag is +// set and all further writes become no-ops; the caller checks once after +// encoding. No partial out-of-bounds writes, ever. +// * Nested messages use fixed-width (4-byte, zero-padded "overlong") +// varint length slots so encoding is single-pass. Overlong varints are +// legal protobuf; all conformant parsers accept them. +// * Never emits post-v1.9.0 fields (AnyValue.string_value_strindex=8, +// KeyValue.key_strindex=3, Resource.entity_refs=3), reserved LogRecord +// field 4, or ResourceLogs field 1000. +#ifndef PG_STAT_CH_OTLP_ENCODE_H +#define PG_STAT_CH_OTLP_ENCODE_H + +typedef struct PschPbBuf { + uint8* data; + size_t cap; + size_t len; + bool overflow; +} PschPbBuf; + +#define PSCH_PB_MAX_DEPTH 16 // ExportLogsServiceRequest nests 7 deep; margin + +static inline void PschPbInit(PschPbBuf* b, uint8* storage, size_t cap) { + b->data = storage; + b->cap = cap; + b->len = 0; + b->overflow = false; +} + +// --- primitives (field = protobuf field number) --- +extern void PschPbVarint(PschPbBuf* b, uint32 field, uint64 value); // wire type 0 +extern void PschPbFixed64(PschPbBuf* b, uint32 field, uint64 value); // wire type 1 +extern void PschPbFixed32(PschPbBuf* b, uint32 field, uint32 value); // wire type 5 +extern void PschPbDouble(PschPbBuf* b, uint32 field, double value); // wire type 1 +extern void PschPbBytes(PschPbBuf* b, uint32 field, const void* data, size_t len); +extern void PschPbString(PschPbBuf* b, uint32 field, const char* s, size_t len); + +// --- single-pass nested messages --- +// Begin returns the position of a 4-byte padded varint length slot; +// End patches it. Unbalanced Begin/End is a programming error (Assert). +extern size_t PschPbMsgBegin(PschPbBuf* b, uint32 field); +extern void PschPbMsgEnd(PschPbBuf* b, size_t slot); + +// --- OTLP common.v1 helpers (KeyValue{key=1, value=2}, AnyValue oneof: +// string=1 bool=2 int=3 double=4 array=5 kvlist=6 bytes=7) --- +// `field` is the repeated-KeyValue field number in the enclosing message +// (Resource.attributes=1, LogRecord.attributes=6). +extern void PschPbKvString(PschPbBuf* b, uint32 field, const char* key, const char* val, + size_t val_len); +extern void PschPbKvInt(PschPbBuf* b, uint32 field, const char* key, int64 value); +extern void PschPbKvDouble(PschPbBuf* b, uint32 field, const char* key, double value); + +// --- response parsing (no allocation; messages truncated into msgbuf) --- +// ExportLogsServiceResponse{ partial_success=1 { rejected_log_records=1, +// error_message=2 } }. Returns false on malformed input. +extern bool PschOtlpParseLogsResponse(const uint8* data, size_t len, int64* rejected_out, + char* msgbuf, size_t msglen); +// google.rpc.Status{ code=1, message=2 } — for 4xx/5xx diagnostics. +extern bool PschRpcStatusParse(const uint8* data, size_t len, int32* code_out, char* msgbuf, + size_t msglen); + +// --------------------------------------------------------------------------- +// Field-number constants (verified against opentelemetry-proto v1.9.0). +// --------------------------------------------------------------------------- +// ExportLogsServiceRequest +#define PSCH_OTLP_REQ_RESOURCE_LOGS 1 +// ResourceLogs +#define PSCH_OTLP_RL_RESOURCE 1 +#define PSCH_OTLP_RL_SCOPE_LOGS 2 +// Resource +#define PSCH_OTLP_RES_ATTRIBUTES 1 +// ScopeLogs +#define PSCH_OTLP_SL_SCOPE 1 +#define PSCH_OTLP_SL_LOG_RECORDS 2 +// InstrumentationScope +#define PSCH_OTLP_SCOPE_NAME 1 +#define PSCH_OTLP_SCOPE_VERSION 2 +// LogRecord +#define PSCH_OTLP_LR_TIME_UNIX_NANO 1 // fixed64 +#define PSCH_OTLP_LR_SEVERITY_NUMBER 2 // varint enum +#define PSCH_OTLP_LR_SEVERITY_TEXT 3 // string +#define PSCH_OTLP_LR_BODY 5 // AnyValue +#define PSCH_OTLP_LR_ATTRIBUTES 6 // repeated KeyValue +#define PSCH_OTLP_LR_OBSERVED_TIME_UNIX_NANO 11 // fixed64 +// AnyValue oneof +#define PSCH_OTLP_ANY_STRING 1 +#define PSCH_OTLP_ANY_BOOL 2 +#define PSCH_OTLP_ANY_INT 3 +#define PSCH_OTLP_ANY_DOUBLE 4 +#define PSCH_OTLP_ANY_BYTES 7 +// KeyValue +#define PSCH_OTLP_KV_KEY 1 +#define PSCH_OTLP_KV_VALUE 2 + +#endif // PG_STAT_CH_OTLP_ENCODE_H From 8f4677f5a980a248412302263edddc2f98b2d38d Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:06 -0500 Subject: [PATCH 05/11] feat(export): Arrow IPC batch builder on nanoarrow Replace the Arrow C++ ArrowBatchBuilder with a C builder producing byte-compatible Arrow IPC streaming payloads (56-field schema, 13 dictionary batches, ZSTD BUFFER compression, validated against pyarrow). nanoarrow's encoder cannot emit dictionary batches or compressed buffers, so arrow_ipc_emit.c hand-builds the Message/Schema/RecordBatch/DictionaryBatch/BodyCompression flatbuffers via the flatcc runtime. All buffers, the ZSTD context, and dictionary memo tables are preallocated; steady-state Append/Finish/Reset perform zero heap allocation. flatcc_emitter_alloc routes flatcc's emitter pages through a fixed pre-reserved pool so flatcc's page-shrink heuristic cannot malloc/free on the hot path (force-included into flatcc.c via CMake). Length-clamp WARNINGs are rate-limited to 1/sec. --- src/export/arrow_batch.c | 911 ++++++++++++++++++++++++++++++ src/export/arrow_batch.cc | 705 ----------------------- src/export/arrow_batch.h | 100 ++-- src/export/arrow_ipc_emit.c | 849 ++++++++++++++++++++++++++++ src/export/arrow_ipc_emit.h | 79 +++ src/export/flatcc_emitter_alloc.c | 72 +++ src/export/flatcc_emitter_alloc.h | 37 ++ 7 files changed, 2007 insertions(+), 746 deletions(-) create mode 100644 src/export/arrow_batch.c delete mode 100644 src/export/arrow_batch.cc create mode 100644 src/export/arrow_ipc_emit.c create mode 100644 src/export/arrow_ipc_emit.h create mode 100644 src/export/flatcc_emitter_alloc.c create mode 100644 src/export/flatcc_emitter_alloc.h diff --git a/src/export/arrow_batch.c b/src/export/arrow_batch.c new file mode 100644 index 0000000..0ff8268 --- /dev/null +++ b/src/export/arrow_batch.c @@ -0,0 +1,911 @@ +// Arrow IPC batch builder — C replacement for the Arrow C++ ArrowBatchBuilder. +// +// Behavior oracle: the previous arrow_batch.cc (see /tmp/orig-export/) and +// /tmp/wf1-code-arrow-batch.md. The 56-column schema (order traps: +// shared_blks_written BEFORE shared_blks_dirtied; jit_deform_time_us last +// among jit), all value transforms (epoch shift, decimal query_id/pid, +// PschCmdTypeToString, length clamps, negative->0 with rate-limited +// WARNING, extra_attributes parsing with trim + first-wins), and the +// estimated-bytes formula are preserved exactly. +// +// Storage: one malloc'd slab carved into per-column fixed-capacity arrays; +// dictionary columns use fixed-capacity open-addressing memo tables. All +// sizing happens in Create() against cfg->scratch_budget_bytes, degrading +// rows-per-batch (with a LOG) until the plan fits. Append/Finish/Reset +// never allocate; Append reports FULL instead of growing. +#include "postgres.h" + +#include +#include +#include +#include +#include + +#include "export/arrow_batch.h" +#include "export/arrow_ipc_emit.h" +#include "queue/event.h" + +#define PSCH_ARROW_ATTR_MAX 128 + +static const int64 kPostgresEpochOffsetUs = INT64CONST(946684800000000); +static const size_t kFixedBytesPerRow = 512; // estimate term, matches old impl +static const size_t kIpcEnvelopeBytes = 1024; // estimate seed, matches old impl +static const size_t kDefaultIpcBudgetBytes = 3 * 1024 * 1024; +static const size_t kMinIpcBudgetBytes = 65536; +static const size_t kMaxIpcBudgetBytes = 16 * 1024 * 1024; +static const int kMinDegradeRows = 16; +static const int kMaxRowsCap = 65536; + +// --------------------------------------------------------------------------- +// The schema, single-sourced. Expansion order == wire column order. +// PSCH_COL_(name) macros are (re)defined at each expansion site. +// --------------------------------------------------------------------------- +#define PSCH_ARROW_COLUMNS(X) \ + X(TS, ts) \ + X(DICT, severity) \ + X(UTF8, body) \ + X(UTF8, trace_id) \ + X(UTF8, span_id) \ + X(DICT, query_id) \ + X(DICT, db_name) \ + X(DICT, db_user) \ + X(DICT, db_operation) \ + X(DICT, app) \ + X(DICT, client_addr) \ + X(UTF8, query_text) \ + X(UTF8, pid) \ + X(UTF8, err_message) \ + X(DICT, err_sqlstate) \ + X(I32, err_elevel) \ + X(U64, duration_us) \ + X(U64, rows) \ + X(U64, shared_blks_hit) \ + X(U64, shared_blks_read) \ + X(U64, shared_blks_written) \ + X(U64, shared_blks_dirtied) \ + X(U64, shared_blk_read_time_us) \ + X(U64, shared_blk_write_time_us) \ + X(U64, local_blks_hit) \ + X(U64, local_blks_read) \ + X(U64, local_blks_written) \ + X(U64, local_blks_dirtied) \ + X(U64, local_blk_read_time_us) \ + X(U64, local_blk_write_time_us) \ + X(U64, temp_blks_read) \ + X(U64, temp_blks_written) \ + X(U64, temp_blk_read_time_us) \ + X(U64, temp_blk_write_time_us) \ + X(U64, wal_records) \ + X(U64, wal_bytes) \ + X(U64, wal_fpi) \ + X(U64, cpu_user_time_us) \ + X(U64, cpu_sys_time_us) \ + X(U64, jit_functions) \ + X(U64, jit_generation_time_us) \ + X(U64, jit_inlining_time_us) \ + X(U64, jit_optimization_time_us) \ + X(U64, jit_emission_time_us) \ + X(U64, jit_deform_time_us) \ + X(U32, parallel_workers_planned) \ + X(U32, parallel_workers_launched) \ + X(UTF8, instance_ubid) \ + X(UTF8, server_ubid) \ + X(DICT, server_role) \ + X(DICT, read_replica_type) \ + X(DICT, region) \ + X(DICT, cell) \ + X(DICT, service_version) \ + X(UTF8, host_id) \ + X(UTF8, pod_name) + +#define PSCH_COL(K, n) PSCH_COL_##K(n) + +// Slot enums per storage kind, derived from the same list. +#define PSCH_COL_TS(n) +#define PSCH_COL_I32(n) +#define PSCH_COL_U32(n) +#define PSCH_COL_U64(n) PSCH_U64_##n, +#define PSCH_COL_UTF8(n) +#define PSCH_COL_DICT(n) +typedef enum PschU64Slot { PSCH_ARROW_COLUMNS(PSCH_COL) PSCH_U64_NUM } PschU64Slot; +#undef PSCH_COL_U64 +#undef PSCH_COL_U32 +#define PSCH_COL_U64(n) +#define PSCH_COL_U32(n) PSCH_U32_##n, +typedef enum PschU32Slot { PSCH_ARROW_COLUMNS(PSCH_COL) PSCH_U32_NUM } PschU32Slot; +#undef PSCH_COL_U32 +#undef PSCH_COL_UTF8 +#define PSCH_COL_U32(n) +#define PSCH_COL_UTF8(n) PSCH_U8_##n, +typedef enum PschUtf8Slot { PSCH_ARROW_COLUMNS(PSCH_COL) PSCH_U8_NUM } PschUtf8Slot; +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT +#define PSCH_COL_UTF8(n) +#define PSCH_COL_DICT(n) PSCH_DICT_##n, +typedef enum PschDictSlot { PSCH_ARROW_COLUMNS(PSCH_COL) PSCH_DICT_NUM } PschDictSlot; +#undef PSCH_COL_TS +#undef PSCH_COL_I32 +#undef PSCH_COL_U32 +#undef PSCH_COL_U64 +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT + +#define PSCH_COL_TS(n) +1 +#define PSCH_COL_I32(n) +1 +#define PSCH_COL_U32(n) +1 +#define PSCH_COL_U64(n) +1 +#define PSCH_COL_UTF8(n) +1 +#define PSCH_COL_DICT(n) +1 +enum { PSCH_ARROW_NUM_COLS = 0 PSCH_ARROW_COLUMNS(PSCH_COL) }; +#undef PSCH_COL_TS +#undef PSCH_COL_I32 +#undef PSCH_COL_U32 +#undef PSCH_COL_U64 +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT + +StaticAssertDecl(PSCH_ARROW_NUM_COLS == 56, "wire schema must have exactly 56 columns"); + +// Resource attributes replicated into every row (extra_attributes GUC keys). +typedef enum PschAttrSlot { + PSCH_ATTR_INSTANCE_UBID = 0, + PSCH_ATTR_SERVER_UBID, + PSCH_ATTR_SERVER_ROLE, + PSCH_ATTR_READ_REPLICA_TYPE, + PSCH_ATTR_REGION, + PSCH_ATTR_CELL, + PSCH_ATTR_HOST_ID, + PSCH_ATTR_POD_NAME, + PSCH_ATTR_NUM, +} PschAttrSlot; + +static const char* const kAttrKeys[PSCH_ATTR_NUM] = { + "instance_ubid", "server_ubid", "server_role", "read_replica_type", + "region", "cell", "host_id", "pod_name", +}; + +typedef struct PschUtf8Col { + int32* offsets; // max_rows + 1 entries; offsets[0] == 0 + char* data; + size_t data_cap; +} PschUtf8Col; + +typedef struct PschDictCol { + int32* indices; // max_rows entries + int32* val_offsets; // max_distinct + 1 entries; val_offsets[0] == 0 + char* val_data; + size_t val_cap; + int32* memo; // memo_cap slots; value = dict index + 1; 0 = empty + uint32 memo_cap; + int32 max_distinct; + int32 count; +} PschDictCol; + +struct PschArrowBuilder { + int max_rows; + size_t ipc_budget_bytes; + int num_rows; + size_t estimated_bytes; + + int64* ts; + int32* err_elevel; + uint32* u32[PSCH_U32_NUM]; + uint64* u64[PSCH_U64_NUM]; + PschUtf8Col utf8[PSCH_U8_NUM]; + PschDictCol dict[PSCH_DICT_NUM]; + + char attr_val[PSCH_ATTR_NUM][PSCH_ARROW_ATTR_MAX + 1]; + int attr_len[PSCH_ATTR_NUM]; + char service_version[PSCH_ARROW_ATTR_MAX + 1]; + int service_version_len; + + uint8* slab; + size_t slab_bytes; + PschIpcEmitter* emitter; + uint64 mem_used; +}; + +// --------------------------------------------------------------------------- +// Small helpers +// --------------------------------------------------------------------------- + +static size_t AlignUp8(size_t n) { + return (n + 7) & ~(size_t)7; +} + +static void SetErr(char* errbuf, size_t errlen, const char* msg) { + if (errbuf != NULL && errlen > 0) + snprintf(errbuf, errlen, "%s", msg); +} + +// Matches the old LogNegativeValue (stats_exporter.cc): at most one WARNING +// per second across all columns. +static void LogNegativeValue(const char* column_name, int64 value) { + static time_t last_log = 0; + time_t now = time(NULL); + + if (now - last_log >= 1) { + elog(WARNING, "pg_stat_ch: Negative value " INT64_FORMAT " clamped to 0 for column `%s`", value, + column_name); + last_log = now; + } +} + +static uint64 ClampSignedToUint64(int64 value, const char* column_name) { + if (value < 0) { + LogNegativeValue(column_name, value); + return 0; + } + return (uint64)value; +} + +static uint32 ClampSignedToUint32(int32 value, const char* column_name) { + if (value < 0) { + LogNegativeValue(column_name, value); + return 0; + } + return (uint32)value; +} + +static int ClampFieldLen(unsigned len, unsigned max, const char* field_name) { + if (len <= max) + return (int)len; + // Rate-limit to at most one WARNING/sec (like LogNegativeValue): a corrupt or + // oversized field could otherwise flood the log at the event rate. + static time_t last_log = 0; + time_t now = time(NULL); + if (now - last_log >= 1) { + elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, len); + last_log = now; + } + return (int)max; +} + +static uint32 HashBytes(const char* s, int len) { + uint32 h = 2166136261u; // FNV-1a + + for (int i = 0; i < len; i++) { + h ^= (uint8)s[i]; + h *= 16777619u; + } + return h; +} + +// Returns the dictionary index if present, else -1 with *ins_slot set to the +// free memo slot. Load factor <= 0.5 guarantees termination. +static int32 DictLookup(const PschDictCol* d, const char* s, int len, uint32* ins_slot) { + uint32 mask = d->memo_cap - 1; + uint32 idx = HashBytes(s, len) & mask; + + for (;;) { + int32 v = d->memo[idx]; + + if (v == 0) { + *ins_slot = idx; + return -1; + } + { + int32 cand = v - 1; + int32 off = d->val_offsets[cand]; + int32 clen = d->val_offsets[cand + 1] - off; + + if (clen == len && memcmp(d->val_data + off, s, (size_t)len) == 0) + return cand; + } + idx = (idx + 1) & mask; + } +} + +static int32 DictInsert(PschDictCol* d, uint32 slot, const char* s, int len) { + int32 idx = d->count; + int32 off = d->val_offsets[idx]; + + memcpy(d->val_data + off, s, (size_t)len); + d->val_offsets[idx + 1] = off + len; + d->memo[slot] = idx + 1; + d->count++; + return idx; +} + +static void Utf8Append(PschUtf8Col* c, int row, const char* s, int len) { + int32 off = c->offsets[row]; + + memcpy(c->data + off, s, (size_t)len); + c->offsets[row + 1] = off + len; +} + +// --------------------------------------------------------------------------- +// Capacity policy (single source for specs + slab carving) +// --------------------------------------------------------------------------- + +static size_t Utf8DataCapFor(int slot, int rows, size_t ipc_budget) { + size_t per_row; + + switch (slot) { + case PSCH_U8_body: + case PSCH_U8_trace_id: + case PSCH_U8_span_id: + return 8; // always "" + case PSCH_U8_query_text: + per_row = PSCH_MAX_QUERY_LEN; + break; + case PSCH_U8_err_message: + per_row = PSCH_MAX_ERR_MSG_LEN; + break; + case PSCH_U8_pid: + return (size_t)12 * (size_t)rows; + default: // attr-backed: instance_ubid, server_ubid, host_id, pod_name + per_row = PSCH_ARROW_ATTR_MAX; + break; + } + // The estimate-driven flush bounds total var bytes near ipc_budget; one + // max-size row of overshoot is possible (flush check is post-append). + return Min(per_row * (size_t)rows, ipc_budget + per_row); +} + +static int32 DictMaxDistinctFor(int slot, int rows) { + switch (slot) { + case PSCH_DICT_severity: // always "" + case PSCH_DICT_server_role: // constant per batch (extra_attributes) + case PSCH_DICT_read_replica_type: + case PSCH_DICT_region: + case PSCH_DICT_cell: + case PSCH_DICT_service_version: + return 2; + case PSCH_DICT_db_operation: + return 8; // PschCmdType domain + default: // query_id, db_name, db_user, app, client_addr, err_sqlstate + return rows; + } +} + +static size_t DictValMaxLenFor(int slot) { + switch (slot) { + case PSCH_DICT_severity: + return 1; + case PSCH_DICT_query_id: + return 21; // uint64 decimal + case PSCH_DICT_db_operation: + return 8; // "UNKNOWN" + case PSCH_DICT_client_addr: + return PSCH_MAX_CLIENT_ADDR_LEN; + case PSCH_DICT_err_sqlstate: + return 5; + case PSCH_DICT_db_name: + case PSCH_DICT_db_user: + case PSCH_DICT_app: + return 63; + default: // attr-backed + service_version + return PSCH_ARROW_ATTR_MAX; + } +} + +static uint32 MemoCapFor(int32 max_distinct) { + uint32 cap = 8; + + while (cap < 2u * (uint32)max_distinct) + cap <<= 1; + return cap; +} + +static void SpecFixed(PschIpcColSpec* specs, int* i, const char* name, PschIpcFixedType type, + size_t width, int rows) { + specs[*i] = (PschIpcColSpec){.name = name, + .kind = PSCH_IPC_COL_FIXED, + .fixed_type = type, + .data_cap = width * (size_t)rows}; + (*i)++; +} + +static void SpecUtf8(PschIpcColSpec* specs, int* i, const char* name, int slot, int rows, + size_t ipc_budget) { + specs[*i] = (PschIpcColSpec){.name = name, + .kind = PSCH_IPC_COL_UTF8, + .offsets_cap = ((size_t)rows + 1) * 4, + .var_cap = Utf8DataCapFor(slot, rows, ipc_budget)}; + (*i)++; +} + +static void SpecDict(PschIpcColSpec* specs, int* i, const char* name, int slot, int rows) { + int32 md = DictMaxDistinctFor(slot, rows); + + specs[*i] = (PschIpcColSpec){.name = name, + .kind = PSCH_IPC_COL_DICT, + .data_cap = (size_t)rows * 4, + .offsets_cap = ((size_t)md + 1) * 4, + .var_cap = Max(8, (size_t)md * DictValMaxLenFor(slot))}; + (*i)++; +} + +static void BuildSpecs(PschIpcColSpec* specs, int rows, size_t ipc_budget) { + int i = 0; + +#define PSCH_COL_TS(n) SpecFixed(specs, &i, #n, PSCH_IPC_TS_NS_UTC, 8, rows); +#define PSCH_COL_I32(n) SpecFixed(specs, &i, #n, PSCH_IPC_INT32, 4, rows); +#define PSCH_COL_U32(n) SpecFixed(specs, &i, #n, PSCH_IPC_UINT32, 4, rows); +#define PSCH_COL_U64(n) SpecFixed(specs, &i, #n, PSCH_IPC_UINT64, 8, rows); +#define PSCH_COL_UTF8(n) SpecUtf8(specs, &i, #n, PSCH_U8_##n, rows, ipc_budget); +#define PSCH_COL_DICT(n) SpecDict(specs, &i, #n, PSCH_DICT_##n, rows); + PSCH_ARROW_COLUMNS(PSCH_COL) +#undef PSCH_COL_TS +#undef PSCH_COL_I32 +#undef PSCH_COL_U32 +#undef PSCH_COL_U64 +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT +} + +static uint8* CarvePtr(uint8* base, size_t* off, size_t nbytes) { + uint8* p = base != NULL ? base + *off : NULL; + + *off += AlignUp8(nbytes); + return p; +} + +static void CarveUtf8(PschUtf8Col* c, int slot, uint8* base, size_t* off, int rows, + size_t ipc_budget) { + c->offsets = (int32*)CarvePtr(base, off, ((size_t)rows + 1) * 4); + c->data_cap = Utf8DataCapFor(slot, rows, ipc_budget); + c->data = (char*)CarvePtr(base, off, c->data_cap); +} + +static void CarveDict(PschDictCol* d, int slot, uint8* base, size_t* off, int rows) { + d->max_distinct = DictMaxDistinctFor(slot, rows); + d->memo_cap = MemoCapFor(d->max_distinct); + d->val_cap = Max(8, (size_t)d->max_distinct * DictValMaxLenFor(slot)); + d->indices = (int32*)CarvePtr(base, off, (size_t)rows * 4); + d->val_offsets = (int32*)CarvePtr(base, off, ((size_t)d->max_distinct + 1) * 4); + d->val_data = (char*)CarvePtr(base, off, d->val_cap); + d->memo = (int32*)CarvePtr(base, off, (size_t)d->memo_cap * 4); +} + +// One pass assigns all column pointers and returns the slab size; called +// with base=NULL for sizing, then with the real slab. +static size_t CarveAll(PschArrowBuilder* b, uint8* base, int rows, size_t ipc_budget) { + size_t off = 0; + +#define PSCH_COL_TS(n) b->ts = (int64*)CarvePtr(base, &off, (size_t)rows * 8); +#define PSCH_COL_I32(n) b->err_elevel = (int32*)CarvePtr(base, &off, (size_t)rows * 4); +#define PSCH_COL_U32(n) b->u32[PSCH_U32_##n] = (uint32*)CarvePtr(base, &off, (size_t)rows * 4); +#define PSCH_COL_U64(n) b->u64[PSCH_U64_##n] = (uint64*)CarvePtr(base, &off, (size_t)rows * 8); +#define PSCH_COL_UTF8(n) \ + CarveUtf8(&b->utf8[PSCH_U8_##n], PSCH_U8_##n, base, &off, rows, ipc_budget); +#define PSCH_COL_DICT(n) CarveDict(&b->dict[PSCH_DICT_##n], PSCH_DICT_##n, base, &off, rows); + PSCH_ARROW_COLUMNS(PSCH_COL) +#undef PSCH_COL_TS +#undef PSCH_COL_I32 +#undef PSCH_COL_U32 +#undef PSCH_COL_U64 +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT + return off; +} + +static void DataFixed(PschIpcColData* cols, int* i, const void* p, size_t len) { + cols[*i] = (PschIpcColData){.data = p, .data_len = len}; + (*i)++; +} + +static void DataUtf8(PschIpcColData* cols, int* i, const PschUtf8Col* c, int rows) { + cols[*i] = (PschIpcColData){ + .offsets = c->offsets, .var_data = c->data, .var_len = (size_t)c->offsets[rows]}; + (*i)++; +} + +static void DataDict(PschIpcColData* cols, int* i, const PschDictCol* d, int rows) { + cols[*i] = (PschIpcColData){.data = d->indices, + .data_len = (size_t)rows * 4, + .offsets = d->val_offsets, + .var_data = d->val_data, + .var_len = (size_t)d->val_offsets[d->count], + .dict_count = d->count}; + (*i)++; +} + +static void FillColData(PschArrowBuilder* b, PschIpcColData* cols) { + int i = 0; + int rows = b->num_rows; + +#define PSCH_COL_TS(n) DataFixed(cols, &i, b->ts, (size_t)rows * 8); +#define PSCH_COL_I32(n) DataFixed(cols, &i, b->err_elevel, (size_t)rows * 4); +#define PSCH_COL_U32(n) DataFixed(cols, &i, b->u32[PSCH_U32_##n], (size_t)rows * 4); +#define PSCH_COL_U64(n) DataFixed(cols, &i, b->u64[PSCH_U64_##n], (size_t)rows * 8); +#define PSCH_COL_UTF8(n) DataUtf8(cols, &i, &b->utf8[PSCH_U8_##n], rows); +#define PSCH_COL_DICT(n) DataDict(cols, &i, &b->dict[PSCH_DICT_##n], rows); + PSCH_ARROW_COLUMNS(PSCH_COL) +#undef PSCH_COL_TS +#undef PSCH_COL_I32 +#undef PSCH_COL_U32 +#undef PSCH_COL_U64 +#undef PSCH_COL_UTF8 +#undef PSCH_COL_DICT +} + +// --------------------------------------------------------------------------- +// Public API +// --------------------------------------------------------------------------- + +PschArrowBuilder* PschArrowBuilderCreate(const PschArrowBuilderConfig* cfg, char* errbuf, + size_t errlen) { + PschIpcColSpec specs[PSCH_ARROW_NUM_COLS]; + PschArrowBuilder* b; + size_t ipc_budget; + size_t budget; + int rows, r0; + + if (cfg == NULL) { + SetErr(errbuf, errlen, "arrow builder: NULL config"); + return NULL; + } + b = calloc(1, sizeof(PschArrowBuilder)); + if (b == NULL) { + SetErr(errbuf, errlen, "arrow builder: out of memory"); + return NULL; + } + + ipc_budget = cfg->ipc_budget_bytes != 0 ? cfg->ipc_budget_bytes : kDefaultIpcBudgetBytes; + if (ipc_budget < kMinIpcBudgetBytes) + ipc_budget = kMinIpcBudgetBytes; + if (ipc_budget > kMaxIpcBudgetBytes) + ipc_budget = kMaxIpcBudgetBytes; + b->ipc_budget_bytes = ipc_budget; + + // Rows are additionally bounded by the estimate-driven flush: each row + // contributes at least kFixedBytesPerRow to the estimate. + r0 = cfg->max_rows > 0 ? cfg->max_rows : kMaxRowsCap; + if ((size_t)r0 > ipc_budget / kFixedBytesPerRow + 1) + r0 = (int)(ipc_budget / kFixedBytesPerRow + 1); + if (r0 > kMaxRowsCap) + r0 = kMaxRowsCap; + if (r0 < 1) + r0 = 1; + + budget = cfg->scratch_budget_bytes; // 0 = no budget check + rows = r0; + for (;;) { + size_t slab_bytes, need; + + BuildSpecs(specs, rows, ipc_budget); + slab_bytes = CarveAll(b, NULL, rows, ipc_budget); + need = slab_bytes + PschIpcEmitterEstimateBytes(specs, PSCH_ARROW_NUM_COLS) + + sizeof(PschArrowBuilder); + if (budget == 0 || need <= budget) { + b->slab_bytes = slab_bytes; + break; + } + if (rows <= kMinDegradeRows) { + if (errbuf != NULL && errlen > 0) + snprintf(errbuf, errlen, + "arrow builder: scratch budget %zu too small (need %zu even at %d rows/batch)", + budget, need, rows); + free(b); + return NULL; + } + rows = rows / 2 > kMinDegradeRows ? rows / 2 : kMinDegradeRows; + } + if (rows < r0) + elog(LOG, "pg_stat_ch: arrow builder degraded to %d rows/batch to fit %zu-byte budget", rows, + budget); + b->max_rows = rows; + + b->slab = malloc(b->slab_bytes); + if (b->slab == NULL) { + SetErr(errbuf, errlen, "arrow builder: out of memory (column slab)"); + free(b); + return NULL; + } + CarveAll(b, b->slab, rows, ipc_budget); + + b->emitter = PschIpcEmitterCreate(specs, PSCH_ARROW_NUM_COLS, errbuf, errlen); + if (b->emitter == NULL) { + free(b->slab); + free(b); + return NULL; + } + + if (cfg->service_version != NULL) { + size_t len = strlen(cfg->service_version); + + if (len > PSCH_ARROW_ATTR_MAX) { + elog(WARNING, "pg_stat_ch: service_version truncated to %d bytes", PSCH_ARROW_ATTR_MAX); + len = PSCH_ARROW_ATTR_MAX; + } + memcpy(b->service_version, cfg->service_version, len); + b->service_version[len] = '\0'; + b->service_version_len = (int)len; + } + (void)PschArrowBuilderSetAttributes(b, cfg->extra_attributes); + + b->mem_used = sizeof(PschArrowBuilder) + b->slab_bytes + PschIpcEmitterMemUsed(b->emitter); + PschArrowBuilderReset(b); + return b; +} + +void PschArrowBuilderDestroy(PschArrowBuilder* b) { + if (b == NULL) + return; + PschIpcEmitterDestroy(b->emitter); + free(b->slab); + free(b); +} + +bool PschArrowBuilderSetAttributes(PschArrowBuilder* b, const char* extra_attributes) { + bool seen[PSCH_ATTR_NUM] = {false}; + const char* p; + + if (b == NULL) + return false; + for (int k = 0; k < PSCH_ATTR_NUM; k++) { + b->attr_val[k][0] = '\0'; + b->attr_len[k] = 0; + } + + p = extra_attributes != NULL ? extra_attributes : ""; + while (*p != '\0') { + const char* end = strchr(p, ';'); + size_t tok_len = end != NULL ? (size_t)(end - p) : strlen(p); + const char* colon = memchr(p, ':', tok_len); + + if (colon != NULL) { + const char* key = p; + size_t key_len = (size_t)(colon - p); + const char* val = colon + 1; + size_t val_len = tok_len - key_len - 1; + + while (key_len > 0 && isspace((unsigned char)key[0])) + key++, key_len--; + while (key_len > 0 && isspace((unsigned char)key[key_len - 1])) + key_len--; + while (val_len > 0 && isspace((unsigned char)val[0])) + val++, val_len--; + while (val_len > 0 && isspace((unsigned char)val[val_len - 1])) + val_len--; + + if (key_len > 0) { + for (int k = 0; k < PSCH_ATTR_NUM; k++) { + if (seen[k] || strlen(kAttrKeys[k]) != key_len || memcmp(kAttrKeys[k], key, key_len) != 0) + continue; + if (val_len > PSCH_ARROW_ATTR_MAX) { + elog(WARNING, "pg_stat_ch: extra_attributes value for \"%s\" truncated to %d bytes", + kAttrKeys[k], PSCH_ARROW_ATTR_MAX); + val_len = PSCH_ARROW_ATTR_MAX; + } + memcpy(b->attr_val[k], val, val_len); + b->attr_val[k][val_len] = '\0'; + b->attr_len[k] = (int)val_len; + seen[k] = true; // first occurrence wins, like the old map emplace + break; + } + } + } + p = end != NULL ? end + 1 : p + tok_len; + } + return true; +} + +PschArrowAppendResult PschArrowBuilderAppend(PschArrowBuilder* b, const PschEvent* ev) { + const char* dval[PSCH_DICT_NUM]; + const char* uval[PSCH_U8_NUM]; + int dlen[PSCH_DICT_NUM]; + int ulen[PSCH_U8_NUM]; + int32 dfound[PSCH_DICT_NUM]; + uint32 dins[PSCH_DICT_NUM]; + char queryid_buf[24]; + char pid_buf[16]; + int row; + + if (b == NULL || ev == NULL) + return PSCH_ARROW_APPEND_ERR; + if (b->num_rows >= b->max_rows) + return PSCH_ARROW_APPEND_FULL; + // Post-append flush semantics of the old implementation: the row that + // crosses the budget stays in the batch; the next append flushes. + if (b->num_rows > 0 && b->estimated_bytes >= b->ipc_budget_bytes) + return PSCH_ARROW_APPEND_FULL; + + { + int datname_len = + ClampFieldLen(ev->datname_len, (unsigned)sizeof(ev->datname) - 1, "datname_len"); + int username_len = + ClampFieldLen(ev->username_len, (unsigned)sizeof(ev->username) - 1, "username_len"); + int app_len = + ClampFieldLen(ev->application_name_len, PSCH_MAX_APP_NAME_LEN, "application_name_len"); + int client_addr_len = + ClampFieldLen(ev->client_addr_len, PSCH_MAX_CLIENT_ADDR_LEN, "client_addr_len"); + int query_len = ClampFieldLen(ev->query_len, PSCH_MAX_QUERY_LEN, "query_len"); + int err_message_len = + ClampFieldLen(ev->err_message_len, PSCH_MAX_ERR_MSG_LEN, "err_message_len"); + int sqlstate_len = (int)strnlen(ev->err_sqlstate, sizeof(ev->err_sqlstate) - 1); + + snprintf(queryid_buf, sizeof(queryid_buf), UINT64_FORMAT, ev->queryid); + snprintf(pid_buf, sizeof(pid_buf), "%d", ev->pid); + + dval[PSCH_DICT_severity] = ""; + dlen[PSCH_DICT_severity] = 0; + dval[PSCH_DICT_query_id] = queryid_buf; + dlen[PSCH_DICT_query_id] = (int)strlen(queryid_buf); + dval[PSCH_DICT_db_name] = ev->datname; + dlen[PSCH_DICT_db_name] = datname_len; + dval[PSCH_DICT_db_user] = ev->username; + dlen[PSCH_DICT_db_user] = username_len; + dval[PSCH_DICT_db_operation] = PschCmdTypeToString(ev->cmd_type); + dlen[PSCH_DICT_db_operation] = (int)strlen(dval[PSCH_DICT_db_operation]); + dval[PSCH_DICT_app] = ev->application_name; + dlen[PSCH_DICT_app] = app_len; + dval[PSCH_DICT_client_addr] = ev->client_addr; + dlen[PSCH_DICT_client_addr] = client_addr_len; + dval[PSCH_DICT_err_sqlstate] = ev->err_sqlstate; + dlen[PSCH_DICT_err_sqlstate] = sqlstate_len; + dval[PSCH_DICT_server_role] = b->attr_val[PSCH_ATTR_SERVER_ROLE]; + dlen[PSCH_DICT_server_role] = b->attr_len[PSCH_ATTR_SERVER_ROLE]; + dval[PSCH_DICT_read_replica_type] = b->attr_val[PSCH_ATTR_READ_REPLICA_TYPE]; + dlen[PSCH_DICT_read_replica_type] = b->attr_len[PSCH_ATTR_READ_REPLICA_TYPE]; + dval[PSCH_DICT_region] = b->attr_val[PSCH_ATTR_REGION]; + dlen[PSCH_DICT_region] = b->attr_len[PSCH_ATTR_REGION]; + dval[PSCH_DICT_cell] = b->attr_val[PSCH_ATTR_CELL]; + dlen[PSCH_DICT_cell] = b->attr_len[PSCH_ATTR_CELL]; + dval[PSCH_DICT_service_version] = b->service_version; + dlen[PSCH_DICT_service_version] = b->service_version_len; + + uval[PSCH_U8_body] = ""; + ulen[PSCH_U8_body] = 0; + uval[PSCH_U8_trace_id] = ""; + ulen[PSCH_U8_trace_id] = 0; + uval[PSCH_U8_span_id] = ""; + ulen[PSCH_U8_span_id] = 0; + uval[PSCH_U8_query_text] = ev->query; + ulen[PSCH_U8_query_text] = query_len; + uval[PSCH_U8_pid] = pid_buf; + ulen[PSCH_U8_pid] = (int)strlen(pid_buf); + uval[PSCH_U8_err_message] = ev->err_message; + ulen[PSCH_U8_err_message] = err_message_len; + uval[PSCH_U8_instance_ubid] = b->attr_val[PSCH_ATTR_INSTANCE_UBID]; + ulen[PSCH_U8_instance_ubid] = b->attr_len[PSCH_ATTR_INSTANCE_UBID]; + uval[PSCH_U8_server_ubid] = b->attr_val[PSCH_ATTR_SERVER_UBID]; + ulen[PSCH_U8_server_ubid] = b->attr_len[PSCH_ATTR_SERVER_UBID]; + uval[PSCH_U8_host_id] = b->attr_val[PSCH_ATTR_HOST_ID]; + ulen[PSCH_U8_host_id] = b->attr_len[PSCH_ATTR_HOST_ID]; + uval[PSCH_U8_pod_name] = b->attr_val[PSCH_ATTR_POD_NAME]; + ulen[PSCH_U8_pod_name] = b->attr_len[PSCH_ATTR_POD_NAME]; + + // Capacity checks before any mutation: a row is appended atomically or + // not at all (the old builder could leave ragged columns on failure). + for (int u = 0; u < PSCH_U8_NUM; u++) { + const PschUtf8Col* c = &b->utf8[u]; + + if ((size_t)c->offsets[b->num_rows] + (size_t)ulen[u] > c->data_cap) + goto full; + } + for (int k = 0; k < PSCH_DICT_NUM; k++) { + const PschDictCol* d = &b->dict[k]; + + dfound[k] = DictLookup(d, dval[k], dlen[k], &dins[k]); + if (dfound[k] < 0) { + if (d->count >= d->max_distinct) + goto full; + if ((size_t)d->val_offsets[d->count] + (size_t)dlen[k] > d->val_cap) + goto full; + } + } + + row = b->num_rows; + b->ts[row] = (ev->ts_start + kPostgresEpochOffsetUs) * 1000; + b->err_elevel[row] = (int32)ev->err_elevel; + + b->u64[PSCH_U64_duration_us][row] = ev->duration_us; + b->u64[PSCH_U64_rows][row] = ev->rows; + b->u64[PSCH_U64_wal_bytes][row] = ev->wal_bytes; +#define PSCH_APPEND_C64(f) b->u64[PSCH_U64_##f][row] = ClampSignedToUint64(ev->f, #f) + PSCH_APPEND_C64(shared_blks_hit); + PSCH_APPEND_C64(shared_blks_read); + PSCH_APPEND_C64(shared_blks_written); + PSCH_APPEND_C64(shared_blks_dirtied); + PSCH_APPEND_C64(shared_blk_read_time_us); + PSCH_APPEND_C64(shared_blk_write_time_us); + PSCH_APPEND_C64(local_blks_hit); + PSCH_APPEND_C64(local_blks_read); + PSCH_APPEND_C64(local_blks_written); + PSCH_APPEND_C64(local_blks_dirtied); + PSCH_APPEND_C64(local_blk_read_time_us); + PSCH_APPEND_C64(local_blk_write_time_us); + PSCH_APPEND_C64(temp_blks_read); + PSCH_APPEND_C64(temp_blks_written); + PSCH_APPEND_C64(temp_blk_read_time_us); + PSCH_APPEND_C64(temp_blk_write_time_us); + PSCH_APPEND_C64(wal_records); + PSCH_APPEND_C64(wal_fpi); + PSCH_APPEND_C64(cpu_user_time_us); + PSCH_APPEND_C64(cpu_sys_time_us); + PSCH_APPEND_C64(jit_functions); + PSCH_APPEND_C64(jit_generation_time_us); + PSCH_APPEND_C64(jit_inlining_time_us); + PSCH_APPEND_C64(jit_optimization_time_us); + PSCH_APPEND_C64(jit_emission_time_us); + PSCH_APPEND_C64(jit_deform_time_us); +#undef PSCH_APPEND_C64 + b->u32[PSCH_U32_parallel_workers_planned][row] = + ClampSignedToUint32(ev->parallel_workers_planned, "parallel_workers_planned"); + b->u32[PSCH_U32_parallel_workers_launched][row] = + ClampSignedToUint32(ev->parallel_workers_launched, "parallel_workers_launched"); + + for (int u = 0; u < PSCH_U8_NUM; u++) + Utf8Append(&b->utf8[u], row, uval[u], ulen[u]); + for (int k = 0; k < PSCH_DICT_NUM; k++) { + PschDictCol* d = &b->dict[k]; + int32 idx = dfound[k] >= 0 ? dfound[k] : DictInsert(d, dins[k], dval[k], dlen[k]); + + d->indices[row] = idx; + } + + // Exact estimate formula of the old implementation. + b->estimated_bytes += kFixedBytesPerRow + (size_t)datname_len + (size_t)username_len + + (size_t)app_len + (size_t)client_addr_len + (size_t)query_len + + (size_t)err_message_len + (size_t)sqlstate_len + + (size_t)b->service_version_len; + for (int k = 0; k < PSCH_ATTR_NUM; k++) + b->estimated_bytes += (size_t)b->attr_len[k]; + b->num_rows++; + return PSCH_ARROW_APPEND_OK; + } + +full: + if (b->num_rows == 0) { + // Cannot happen with capacities >= one max-size row; guard anyway so a + // single oversized event cannot wedge the flush loop. + elog(WARNING, "pg_stat_ch: event exceeds arrow batch capacity, dropping"); + return PSCH_ARROW_APPEND_ERR; + } + return PSCH_ARROW_APPEND_FULL; +} + +bool PschArrowBuilderFinish(PschArrowBuilder* b, const uint8** data_out, size_t* len_out, + int* rows_out) { + PschIpcColData cols[PSCH_ARROW_NUM_COLS]; + + if (data_out != NULL) + *data_out = NULL; + if (len_out != NULL) + *len_out = 0; + if (rows_out != NULL) + *rows_out = 0; + if (b == NULL || data_out == NULL || len_out == NULL || rows_out == NULL) + return false; + if (b->num_rows == 0) + return false; // nothing to serialize + + FillColData(b, cols); + if (!PschIpcEmitterEmit(b->emitter, cols, PSCH_ARROW_NUM_COLS, b->num_rows, data_out, len_out)) + return false; + *rows_out = b->num_rows; + return true; +} + +void PschArrowBuilderReset(PschArrowBuilder* b) { + if (b == NULL) + return; + b->num_rows = 0; + b->estimated_bytes = kIpcEnvelopeBytes; + for (int u = 0; u < PSCH_U8_NUM; u++) + b->utf8[u].offsets[0] = 0; + for (int k = 0; k < PSCH_DICT_NUM; k++) { + PschDictCol* d = &b->dict[k]; + + // Full reset: every payload carries fresh, self-contained dictionaries + // (the old builders called ResetFull()). + d->count = 0; + d->val_offsets[0] = 0; + memset(d->memo, 0, (size_t)d->memo_cap * 4); + } +} + +int PschArrowBuilderNumRows(const PschArrowBuilder* b) { + return b != NULL ? b->num_rows : 0; +} + +size_t PschArrowBuilderEstimatedBytes(const PschArrowBuilder* b) { + return b != NULL ? b->estimated_bytes : 0; +} + +uint64 PschArrowBuilderMemUsed(const PschArrowBuilder* b) { + return b != NULL ? b->mem_used : 0; +} diff --git a/src/export/arrow_batch.cc b/src/export/arrow_batch.cc deleted file mode 100644 index 63bb650..0000000 --- a/src/export/arrow_batch.cc +++ /dev/null @@ -1,705 +0,0 @@ -extern "C" { -#include "postgres.h" -} - -#include "queue/event.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "export/arrow_batch.h" -#include "export/exporter_interface.h" - -namespace { - -using DictBuilder = arrow::StringDictionary32Builder; - -constexpr int64_t kPostgresEpochOffsetUs = 946684800000000LL; -constexpr size_t kFixedBytesPerRow = 512; -constexpr size_t kIpcEnvelopeBytes = 1024; - -std::shared_ptr TimestampType() { - static const auto kType = arrow::timestamp(arrow::TimeUnit::NANO, "UTC"); - return kType; -} - -std::shared_ptr DictionaryUtf8Type() { - static const auto kType = arrow::dictionary(arrow::int32(), arrow::utf8()); - return kType; -} - -void LogArrowFailure(const char* context, const arrow::Status& status) { - elog(WARNING, "pg_stat_ch: %s: %s", context, status.ToString().c_str()); -} - -template -LenT ClampFieldLen(LenT len, LenT max, const char* field_name) { - if (len <= max) { - return len; - } - elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, static_cast(len)); - return max; -} - -template -bool AppendScalar(BuilderT* builder, ValueT value, const char* context) { - const arrow::Status status = builder->Append(value); - if (!status.ok()) { - LogArrowFailure(context, status); - return false; - } - return true; -} - -bool AppendString(arrow::StringBuilder* builder, std::string_view value, const char* context) { - const char* data = value.empty() ? "" : value.data(); - const arrow::Status status = builder->Append(data, static_cast(value.size())); - if (!status.ok()) { - LogArrowFailure(context, status); - return false; - } - return true; -} - -bool AppendString(DictBuilder* builder, std::string_view value, const char* context) { - const char* data = value.empty() ? "" : value.data(); - const arrow::Status status = builder->Append(data, static_cast(value.size())); - if (!status.ok()) { - LogArrowFailure(context, status); - return false; - } - return true; -} - -uint64_t ClampSignedToUint64(int64_t value, const char* column_name) { - if (value < 0) { - LogNegativeValue(column_name, value); - return 0; - } - return static_cast(value); -} - -uint32_t ClampSignedToUint32(int32_t value, const char* column_name) { - if (value < 0) { - LogNegativeValue(column_name, value); - return 0; - } - return static_cast(value); -} - -std::string_view TrimAsciiWhitespace(std::string_view input) { - while (!input.empty() && std::isspace(static_cast(input.front())) != 0) { - input.remove_prefix(1); - } - while (!input.empty() && std::isspace(static_cast(input.back())) != 0) { - input.remove_suffix(1); - } - return input; -} - -bool FinishArray(arrow::ArrayBuilder* builder, const char* context, - std::shared_ptr* out) { - const arrow::Status status = builder->Finish(out); - if (!status.ok()) { - LogArrowFailure(context, status); - return false; - } - return true; -} - -bool FinishDictionaryArray(DictBuilder* builder, const char* context, - std::shared_ptr* out) { - std::shared_ptr dict_array; - const arrow::Status status = builder->Finish(&dict_array); - if (!status.ok()) { - LogArrowFailure(context, status); - return false; - } - *out = std::static_pointer_cast(std::move(dict_array)); - return true; -} - -} // namespace - -struct ArrowBatchBuilder::Impl { - std::shared_ptr schema; - - arrow::TimestampBuilder ts_builder; - DictBuilder severity_builder; - arrow::StringBuilder body_builder; - arrow::StringBuilder trace_id_builder; - arrow::StringBuilder span_id_builder; - DictBuilder query_id_builder; - DictBuilder db_name_builder; - DictBuilder db_user_builder; - DictBuilder db_operation_builder; - DictBuilder app_builder; - DictBuilder client_addr_builder; - arrow::StringBuilder query_text_builder; - arrow::StringBuilder pid_builder; - arrow::StringBuilder err_message_builder; - DictBuilder err_sqlstate_builder; - arrow::Int32Builder err_elevel_builder; - arrow::UInt64Builder duration_us_builder; - arrow::UInt64Builder rows_builder; - arrow::UInt64Builder shared_blks_hit_builder; - arrow::UInt64Builder shared_blks_read_builder; - arrow::UInt64Builder shared_blks_written_builder; - arrow::UInt64Builder shared_blks_dirtied_builder; - arrow::UInt64Builder shared_blk_read_time_us_builder; - arrow::UInt64Builder shared_blk_write_time_us_builder; - arrow::UInt64Builder local_blks_hit_builder; - arrow::UInt64Builder local_blks_read_builder; - arrow::UInt64Builder local_blks_written_builder; - arrow::UInt64Builder local_blks_dirtied_builder; - arrow::UInt64Builder local_blk_read_time_us_builder; - arrow::UInt64Builder local_blk_write_time_us_builder; - arrow::UInt64Builder temp_blks_read_builder; - arrow::UInt64Builder temp_blks_written_builder; - arrow::UInt64Builder temp_blk_read_time_us_builder; - arrow::UInt64Builder temp_blk_write_time_us_builder; - arrow::UInt64Builder wal_records_builder; - arrow::UInt64Builder wal_bytes_builder; - arrow::UInt64Builder wal_fpi_builder; - arrow::UInt64Builder cpu_user_time_us_builder; - arrow::UInt64Builder cpu_sys_time_us_builder; - arrow::UInt64Builder jit_functions_builder; - arrow::UInt64Builder jit_generation_time_us_builder; - arrow::UInt64Builder jit_inlining_time_us_builder; - arrow::UInt64Builder jit_optimization_time_us_builder; - arrow::UInt64Builder jit_emission_time_us_builder; - arrow::UInt64Builder jit_deform_time_us_builder; - arrow::UInt32Builder parallel_workers_planned_builder; - arrow::UInt32Builder parallel_workers_launched_builder; - arrow::StringBuilder instance_ubid_builder; - arrow::StringBuilder server_ubid_builder; - DictBuilder server_role_builder; - DictBuilder read_replica_type_builder; - DictBuilder region_builder; - DictBuilder cell_builder; - DictBuilder service_version_builder; - arrow::StringBuilder host_id_builder; - arrow::StringBuilder pod_name_builder; - - std::unordered_map extra_attrs; - std::string service_version; - int num_rows = 0; - size_t estimated_bytes = 0; - - Impl() : ts_builder(TimestampType(), arrow::default_memory_pool()) {} - - bool Init(const char* extra_attrs_input, const char* service_version_input) { - service_version = service_version_input != nullptr ? service_version_input : ""; - ParseExtraAttributes(extra_attrs_input != nullptr ? extra_attrs_input : ""); - schema = arrow::schema({ - arrow::field("ts", TimestampType()), - arrow::field("severity", DictionaryUtf8Type()), - arrow::field("body", arrow::utf8()), - arrow::field("trace_id", arrow::utf8()), - arrow::field("span_id", arrow::utf8()), - arrow::field("query_id", DictionaryUtf8Type()), - arrow::field("db_name", DictionaryUtf8Type()), - arrow::field("db_user", DictionaryUtf8Type()), - arrow::field("db_operation", DictionaryUtf8Type()), - arrow::field("app", DictionaryUtf8Type()), - arrow::field("client_addr", DictionaryUtf8Type()), - arrow::field("query_text", arrow::utf8()), - arrow::field("pid", arrow::utf8()), - arrow::field("err_message", arrow::utf8()), - arrow::field("err_sqlstate", DictionaryUtf8Type()), - arrow::field("err_elevel", arrow::int32()), - arrow::field("duration_us", arrow::uint64()), - arrow::field("rows", arrow::uint64()), - arrow::field("shared_blks_hit", arrow::uint64()), - arrow::field("shared_blks_read", arrow::uint64()), - arrow::field("shared_blks_written", arrow::uint64()), - arrow::field("shared_blks_dirtied", arrow::uint64()), - arrow::field("shared_blk_read_time_us", arrow::uint64()), - arrow::field("shared_blk_write_time_us", arrow::uint64()), - arrow::field("local_blks_hit", arrow::uint64()), - arrow::field("local_blks_read", arrow::uint64()), - arrow::field("local_blks_written", arrow::uint64()), - arrow::field("local_blks_dirtied", arrow::uint64()), - arrow::field("local_blk_read_time_us", arrow::uint64()), - arrow::field("local_blk_write_time_us", arrow::uint64()), - arrow::field("temp_blks_read", arrow::uint64()), - arrow::field("temp_blks_written", arrow::uint64()), - arrow::field("temp_blk_read_time_us", arrow::uint64()), - arrow::field("temp_blk_write_time_us", arrow::uint64()), - arrow::field("wal_records", arrow::uint64()), - arrow::field("wal_bytes", arrow::uint64()), - arrow::field("wal_fpi", arrow::uint64()), - arrow::field("cpu_user_time_us", arrow::uint64()), - arrow::field("cpu_sys_time_us", arrow::uint64()), - arrow::field("jit_functions", arrow::uint64()), - arrow::field("jit_generation_time_us", arrow::uint64()), - arrow::field("jit_inlining_time_us", arrow::uint64()), - arrow::field("jit_optimization_time_us", arrow::uint64()), - arrow::field("jit_emission_time_us", arrow::uint64()), - arrow::field("jit_deform_time_us", arrow::uint64()), - arrow::field("parallel_workers_planned", arrow::uint32()), - arrow::field("parallel_workers_launched", arrow::uint32()), - arrow::field("instance_ubid", arrow::utf8()), - arrow::field("server_ubid", arrow::utf8()), - arrow::field("server_role", DictionaryUtf8Type()), - arrow::field("read_replica_type", DictionaryUtf8Type()), - arrow::field("region", DictionaryUtf8Type()), - arrow::field("cell", DictionaryUtf8Type()), - arrow::field("service_version", DictionaryUtf8Type()), - arrow::field("host_id", arrow::utf8()), - arrow::field("pod_name", arrow::utf8()), - }); - Reset(); - return true; - } - - bool Append(const PschEvent& event) { - if (!AppendScalar(&ts_builder, - static_cast((event.ts_start + kPostgresEpochOffsetUs) * 1000LL), - "Arrow ts append")) { - return false; - } - if (!AppendString(&severity_builder, "", "Arrow severity append") || - !AppendString(&body_builder, "", "Arrow body append") || - !AppendString(&trace_id_builder, "", "Arrow trace_id append") || - !AppendString(&span_id_builder, "", "Arrow span_id append")) { - return false; - } - - const auto datname_len = ClampFieldLen( - event.datname_len, static_cast(sizeof(event.datname) - 1), "datname_len"); - const auto username_len = ClampFieldLen( - event.username_len, static_cast(sizeof(event.username) - 1), "username_len"); - const auto app_len = - ClampFieldLen(event.application_name_len, static_cast(PSCH_MAX_APP_NAME_LEN), - "application_name_len"); - const auto client_addr_len = ClampFieldLen( - event.client_addr_len, static_cast(PSCH_MAX_CLIENT_ADDR_LEN), "client_addr_len"); - const auto query_len = - ClampFieldLen(event.query_len, static_cast(PSCH_MAX_QUERY_LEN), "query_len"); - const auto err_message_len = ClampFieldLen( - event.err_message_len, static_cast(PSCH_MAX_ERR_MSG_LEN), "err_message_len"); - const auto err_sqlstate_len = - static_cast(strnlen(event.err_sqlstate, sizeof(event.err_sqlstate) - 1)); - - const std::string_view db_name(event.datname, datname_len); - const std::string_view db_user(event.username, username_len); - const std::string_view app(event.application_name, app_len); - const std::string_view client_addr(event.client_addr, client_addr_len); - const std::string_view query_text(event.query, query_len); - const std::string_view err_message(event.err_message, err_message_len); - const std::string_view err_sqlstate(event.err_sqlstate, err_sqlstate_len); - - char queryid_buf[24]; - snprintf(queryid_buf, sizeof(queryid_buf), "%" PRIu64, static_cast(event.queryid)); - char pid_buf[12]; - snprintf(pid_buf, sizeof(pid_buf), "%d", event.pid); - - if (!AppendString(&query_id_builder, queryid_buf, "Arrow query_id append") || - !AppendString(&db_name_builder, db_name, "Arrow db_name append") || - !AppendString(&db_user_builder, db_user, "Arrow db_user append") || - !AppendString(&db_operation_builder, PschCmdTypeToString(event.cmd_type), - "Arrow db_operation append") || - !AppendString(&app_builder, app, "Arrow app append") || - !AppendString(&client_addr_builder, client_addr, "Arrow client_addr append") || - !AppendString(&query_text_builder, query_text, "Arrow query_text append") || - !AppendString(&pid_builder, pid_buf, "Arrow pid append") || - !AppendString(&err_message_builder, err_message, "Arrow err_message append") || - !AppendString(&err_sqlstate_builder, err_sqlstate, "Arrow err_sqlstate append")) { - return false; - } - - if (!AppendScalar(&err_elevel_builder, static_cast(event.err_elevel), - "Arrow err_elevel append") || - !AppendScalar(&duration_us_builder, event.duration_us, "Arrow duration_us append") || - !AppendScalar(&rows_builder, event.rows, "Arrow rows append") || - !AppendScalar(&shared_blks_hit_builder, - ClampSignedToUint64(event.shared_blks_hit, "shared_blks_hit"), - "Arrow shared_blks_hit append") || - !AppendScalar(&shared_blks_read_builder, - ClampSignedToUint64(event.shared_blks_read, "shared_blks_read"), - "Arrow shared_blks_read append") || - !AppendScalar(&shared_blks_written_builder, - ClampSignedToUint64(event.shared_blks_written, "shared_blks_written"), - "Arrow shared_blks_written append") || - !AppendScalar(&shared_blks_dirtied_builder, - ClampSignedToUint64(event.shared_blks_dirtied, "shared_blks_dirtied"), - "Arrow shared_blks_dirtied append") || - !AppendScalar(&shared_blk_read_time_us_builder, - ClampSignedToUint64(event.shared_blk_read_time_us, "shared_blk_read_time_us"), - "Arrow shared_blk_read_time_us append") || - !AppendScalar( - &shared_blk_write_time_us_builder, - ClampSignedToUint64(event.shared_blk_write_time_us, "shared_blk_write_time_us"), - "Arrow shared_blk_write_time_us append") || - !AppendScalar(&local_blks_hit_builder, - ClampSignedToUint64(event.local_blks_hit, "local_blks_hit"), - "Arrow local_blks_hit append") || - !AppendScalar(&local_blks_read_builder, - ClampSignedToUint64(event.local_blks_read, "local_blks_read"), - "Arrow local_blks_read append") || - !AppendScalar(&local_blks_written_builder, - ClampSignedToUint64(event.local_blks_written, "local_blks_written"), - "Arrow local_blks_written append") || - !AppendScalar(&local_blks_dirtied_builder, - ClampSignedToUint64(event.local_blks_dirtied, "local_blks_dirtied"), - "Arrow local_blks_dirtied append") || - !AppendScalar(&local_blk_read_time_us_builder, - ClampSignedToUint64(event.local_blk_read_time_us, "local_blk_read_time_us"), - "Arrow local_blk_read_time_us append") || - !AppendScalar(&local_blk_write_time_us_builder, - ClampSignedToUint64(event.local_blk_write_time_us, "local_blk_write_time_us"), - "Arrow local_blk_write_time_us append") || - !AppendScalar(&temp_blks_read_builder, - ClampSignedToUint64(event.temp_blks_read, "temp_blks_read"), - "Arrow temp_blks_read append") || - !AppendScalar(&temp_blks_written_builder, - ClampSignedToUint64(event.temp_blks_written, "temp_blks_written"), - "Arrow temp_blks_written append") || - !AppendScalar(&temp_blk_read_time_us_builder, - ClampSignedToUint64(event.temp_blk_read_time_us, "temp_blk_read_time_us"), - "Arrow temp_blk_read_time_us append") || - !AppendScalar(&temp_blk_write_time_us_builder, - ClampSignedToUint64(event.temp_blk_write_time_us, "temp_blk_write_time_us"), - "Arrow temp_blk_write_time_us append") || - !AppendScalar(&wal_records_builder, ClampSignedToUint64(event.wal_records, "wal_records"), - "Arrow wal_records append") || - !AppendScalar(&wal_bytes_builder, event.wal_bytes, "Arrow wal_bytes append") || - !AppendScalar(&wal_fpi_builder, ClampSignedToUint64(event.wal_fpi, "wal_fpi"), - "Arrow wal_fpi append") || - !AppendScalar(&cpu_user_time_us_builder, - ClampSignedToUint64(event.cpu_user_time_us, "cpu_user_time_us"), - "Arrow cpu_user_time_us append") || - !AppendScalar(&cpu_sys_time_us_builder, - ClampSignedToUint64(event.cpu_sys_time_us, "cpu_sys_time_us"), - "Arrow cpu_sys_time_us append") || - !AppendScalar(&jit_functions_builder, - ClampSignedToUint64(event.jit_functions, "jit_functions"), - "Arrow jit_functions append") || - !AppendScalar(&jit_generation_time_us_builder, - ClampSignedToUint64(event.jit_generation_time_us, "jit_generation_time_us"), - "Arrow jit_generation_time_us append") || - !AppendScalar(&jit_inlining_time_us_builder, - ClampSignedToUint64(event.jit_inlining_time_us, "jit_inlining_time_us"), - "Arrow jit_inlining_time_us append") || - !AppendScalar( - &jit_optimization_time_us_builder, - ClampSignedToUint64(event.jit_optimization_time_us, "jit_optimization_time_us"), - "Arrow jit_optimization_time_us append") || - !AppendScalar(&jit_emission_time_us_builder, - ClampSignedToUint64(event.jit_emission_time_us, "jit_emission_time_us"), - "Arrow jit_emission_time_us append") || - !AppendScalar(&jit_deform_time_us_builder, - ClampSignedToUint64(event.jit_deform_time_us, "jit_deform_time_us"), - "Arrow jit_deform_time_us append") || - !AppendScalar( - ¶llel_workers_planned_builder, - ClampSignedToUint32(event.parallel_workers_planned, "parallel_workers_planned"), - "Arrow parallel_workers_planned append") || - !AppendScalar( - ¶llel_workers_launched_builder, - ClampSignedToUint32(event.parallel_workers_launched, "parallel_workers_launched"), - "Arrow parallel_workers_launched append")) { - return false; - } - - if (!AppendString(&instance_ubid_builder, ExtraAttr("instance_ubid"), - "Arrow instance_ubid append") || - !AppendString(&server_ubid_builder, ExtraAttr("server_ubid"), "Arrow server_ubid append") || - !AppendString(&server_role_builder, ExtraAttr("server_role"), "Arrow server_role append") || - !AppendString(&read_replica_type_builder, ExtraAttr("read_replica_type"), - "Arrow read_replica_type append") || - !AppendString(®ion_builder, ExtraAttr("region"), "Arrow region append") || - !AppendString(&cell_builder, ExtraAttr("cell"), "Arrow cell append") || - !AppendString(&service_version_builder, service_version, "Arrow service_version append") || - !AppendString(&host_id_builder, ExtraAttr("host_id"), "Arrow host_id append") || - !AppendString(&pod_name_builder, ExtraAttr("pod_name"), "Arrow pod_name append")) { - return false; - } - - estimated_bytes += kFixedBytesPerRow + db_name.size() + db_user.size() + app.size() + - client_addr.size() + query_text.size() + err_message.size() + - err_sqlstate.size() + service_version.size() + - ExtraAttr("instance_ubid").size() + ExtraAttr("server_ubid").size() + - ExtraAttr("server_role").size() + ExtraAttr("read_replica_type").size() + - ExtraAttr("region").size() + ExtraAttr("cell").size() + - ExtraAttr("host_id").size() + ExtraAttr("pod_name").size(); - ++num_rows; - return true; - } - - ArrowBatchBuilder::FinishResult Finish() { - ArrowBatchBuilder::FinishResult result; - result.num_rows = num_rows; - if (num_rows == 0 || schema == nullptr) { - return result; - } - - std::vector> columns; - columns.reserve(schema->num_fields()); - - auto add_array = [&](arrow::ArrayBuilder* builder, const char* context) -> bool { - std::shared_ptr array; - if (!FinishArray(builder, context, &array)) { - return false; - } - columns.push_back(std::move(array)); - return true; - }; - auto add_dict_array = [&](DictBuilder* builder, const char* context) -> bool { - std::shared_ptr array; - if (!FinishDictionaryArray(builder, context, &array)) { - return false; - } - columns.push_back(std::move(array)); - return true; - }; - - if (!add_array(&ts_builder, "Arrow ts finish") || - !add_dict_array(&severity_builder, "Arrow severity finish") || - !add_array(&body_builder, "Arrow body finish") || - !add_array(&trace_id_builder, "Arrow trace_id finish") || - !add_array(&span_id_builder, "Arrow span_id finish") || - !add_dict_array(&query_id_builder, "Arrow query_id finish") || - !add_dict_array(&db_name_builder, "Arrow db_name finish") || - !add_dict_array(&db_user_builder, "Arrow db_user finish") || - !add_dict_array(&db_operation_builder, "Arrow db_operation finish") || - !add_dict_array(&app_builder, "Arrow app finish") || - !add_dict_array(&client_addr_builder, "Arrow client_addr finish") || - !add_array(&query_text_builder, "Arrow query_text finish") || - !add_array(&pid_builder, "Arrow pid finish") || - !add_array(&err_message_builder, "Arrow err_message finish") || - !add_dict_array(&err_sqlstate_builder, "Arrow err_sqlstate finish") || - !add_array(&err_elevel_builder, "Arrow err_elevel finish") || - !add_array(&duration_us_builder, "Arrow duration_us finish") || - !add_array(&rows_builder, "Arrow rows finish") || - !add_array(&shared_blks_hit_builder, "Arrow shared_blks_hit finish") || - !add_array(&shared_blks_read_builder, "Arrow shared_blks_read finish") || - !add_array(&shared_blks_written_builder, "Arrow shared_blks_written finish") || - !add_array(&shared_blks_dirtied_builder, "Arrow shared_blks_dirtied finish") || - !add_array(&shared_blk_read_time_us_builder, "Arrow shared_blk_read_time_us finish") || - !add_array(&shared_blk_write_time_us_builder, "Arrow shared_blk_write_time_us finish") || - !add_array(&local_blks_hit_builder, "Arrow local_blks_hit finish") || - !add_array(&local_blks_read_builder, "Arrow local_blks_read finish") || - !add_array(&local_blks_written_builder, "Arrow local_blks_written finish") || - !add_array(&local_blks_dirtied_builder, "Arrow local_blks_dirtied finish") || - !add_array(&local_blk_read_time_us_builder, "Arrow local_blk_read_time_us finish") || - !add_array(&local_blk_write_time_us_builder, "Arrow local_blk_write_time_us finish") || - !add_array(&temp_blks_read_builder, "Arrow temp_blks_read finish") || - !add_array(&temp_blks_written_builder, "Arrow temp_blks_written finish") || - !add_array(&temp_blk_read_time_us_builder, "Arrow temp_blk_read_time_us finish") || - !add_array(&temp_blk_write_time_us_builder, "Arrow temp_blk_write_time_us finish") || - !add_array(&wal_records_builder, "Arrow wal_records finish") || - !add_array(&wal_bytes_builder, "Arrow wal_bytes finish") || - !add_array(&wal_fpi_builder, "Arrow wal_fpi finish") || - !add_array(&cpu_user_time_us_builder, "Arrow cpu_user_time_us finish") || - !add_array(&cpu_sys_time_us_builder, "Arrow cpu_sys_time_us finish") || - !add_array(&jit_functions_builder, "Arrow jit_functions finish") || - !add_array(&jit_generation_time_us_builder, "Arrow jit_generation_time_us finish") || - !add_array(&jit_inlining_time_us_builder, "Arrow jit_inlining_time_us finish") || - !add_array(&jit_optimization_time_us_builder, "Arrow jit_optimization_time_us finish") || - !add_array(&jit_emission_time_us_builder, "Arrow jit_emission_time_us finish") || - !add_array(&jit_deform_time_us_builder, "Arrow jit_deform_time_us finish") || - !add_array(¶llel_workers_planned_builder, "Arrow parallel_workers_planned finish") || - !add_array(¶llel_workers_launched_builder, "Arrow parallel_workers_launched finish") || - !add_array(&instance_ubid_builder, "Arrow instance_ubid finish") || - !add_array(&server_ubid_builder, "Arrow server_ubid finish") || - !add_dict_array(&server_role_builder, "Arrow server_role finish") || - !add_dict_array(&read_replica_type_builder, "Arrow read_replica_type finish") || - !add_dict_array(®ion_builder, "Arrow region finish") || - !add_dict_array(&cell_builder, "Arrow cell finish") || - !add_dict_array(&service_version_builder, "Arrow service_version finish") || - !add_array(&host_id_builder, "Arrow host_id finish") || - !add_array(&pod_name_builder, "Arrow pod_name finish")) { - return {}; - } - - const auto batch = arrow::RecordBatch::Make(schema, num_rows, std::move(columns)); - - auto sink_result = arrow::io::BufferOutputStream::Create(kIpcEnvelopeBytes); - if (!sink_result.ok()) { - LogArrowFailure("Arrow buffer sink create", sink_result.status()); - return {}; - } - auto sink = std::move(sink_result).ValueOrDie(); - - auto codec_result = arrow::util::Codec::Create(arrow::Compression::ZSTD); - if (!codec_result.ok()) { - LogArrowFailure("Arrow codec create", codec_result.status()); - return {}; - } - - auto options = arrow::ipc::IpcWriteOptions::Defaults(); - auto codec = std::move(codec_result).ValueOrDie(); - options.codec = std::shared_ptr(std::move(codec)); - - auto writer_result = arrow::ipc::MakeStreamWriter(sink, schema, options); - if (!writer_result.ok()) { - LogArrowFailure("Arrow stream writer create", writer_result.status()); - return {}; - } - auto writer = std::move(writer_result).ValueOrDie(); - - arrow::Status status = writer->WriteRecordBatch(*batch); - if (!status.ok()) { - LogArrowFailure("Arrow write record batch", status); - return {}; - } - status = writer->Close(); - if (!status.ok()) { - LogArrowFailure("Arrow close writer", status); - return {}; - } - - auto buffer_result = sink->Finish(); - if (!buffer_result.ok()) { - LogArrowFailure("Arrow finish buffer", buffer_result.status()); - return {}; - } - - result.ipc_buffer = std::move(buffer_result).ValueOrDie(); - return result; - } - - void Reset() { - ts_builder.Reset(); - severity_builder.ResetFull(); - body_builder.Reset(); - trace_id_builder.Reset(); - span_id_builder.Reset(); - query_id_builder.ResetFull(); - db_name_builder.ResetFull(); - db_user_builder.ResetFull(); - db_operation_builder.ResetFull(); - app_builder.ResetFull(); - client_addr_builder.ResetFull(); - query_text_builder.Reset(); - pid_builder.Reset(); - err_message_builder.Reset(); - err_sqlstate_builder.ResetFull(); - err_elevel_builder.Reset(); - duration_us_builder.Reset(); - rows_builder.Reset(); - shared_blks_hit_builder.Reset(); - shared_blks_read_builder.Reset(); - shared_blks_written_builder.Reset(); - shared_blks_dirtied_builder.Reset(); - shared_blk_read_time_us_builder.Reset(); - shared_blk_write_time_us_builder.Reset(); - local_blks_hit_builder.Reset(); - local_blks_read_builder.Reset(); - local_blks_written_builder.Reset(); - local_blks_dirtied_builder.Reset(); - local_blk_read_time_us_builder.Reset(); - local_blk_write_time_us_builder.Reset(); - temp_blks_read_builder.Reset(); - temp_blks_written_builder.Reset(); - temp_blk_read_time_us_builder.Reset(); - temp_blk_write_time_us_builder.Reset(); - wal_records_builder.Reset(); - wal_bytes_builder.Reset(); - wal_fpi_builder.Reset(); - cpu_user_time_us_builder.Reset(); - cpu_sys_time_us_builder.Reset(); - jit_functions_builder.Reset(); - jit_generation_time_us_builder.Reset(); - jit_inlining_time_us_builder.Reset(); - jit_optimization_time_us_builder.Reset(); - jit_emission_time_us_builder.Reset(); - jit_deform_time_us_builder.Reset(); - parallel_workers_planned_builder.Reset(); - parallel_workers_launched_builder.Reset(); - instance_ubid_builder.Reset(); - server_ubid_builder.Reset(); - server_role_builder.ResetFull(); - read_replica_type_builder.ResetFull(); - region_builder.ResetFull(); - cell_builder.ResetFull(); - service_version_builder.ResetFull(); - host_id_builder.Reset(); - pod_name_builder.Reset(); - num_rows = 0; - estimated_bytes = kIpcEnvelopeBytes; - } - - std::string_view ExtraAttr(const char* key) const { - const auto it = extra_attrs.find(key); - if (it == extra_attrs.end()) { - return {}; - } - return it->second; - } - - void ParseExtraAttributes(const char* raw_attrs) { - extra_attrs.clear(); - std::string_view input = raw_attrs != nullptr ? raw_attrs : ""; - while (!input.empty()) { - const size_t next_delim = input.find(';'); - const std::string_view token = - next_delim == std::string_view::npos ? input : input.substr(0, next_delim); - const size_t sep = token.find(':'); - if (sep != std::string_view::npos) { - const std::string_view key = TrimAsciiWhitespace(token.substr(0, sep)); - const std::string_view value = TrimAsciiWhitespace(token.substr(sep + 1)); - if (!key.empty()) { - extra_attrs.emplace(std::string(key), std::string(value)); - } - } - if (next_delim == std::string_view::npos) { - break; - } - input.remove_prefix(next_delim + 1); - } - } -}; - -ArrowBatchBuilder::ArrowBatchBuilder() : impl_(std::make_unique()) {} - -ArrowBatchBuilder::~ArrowBatchBuilder() = default; - -ArrowBatchBuilder::ArrowBatchBuilder(ArrowBatchBuilder&&) noexcept = default; - -ArrowBatchBuilder& ArrowBatchBuilder::operator=(ArrowBatchBuilder&&) noexcept = default; - -bool ArrowBatchBuilder::Init(const char* extra_attrs, const char* service_version) { - return impl_->Init(extra_attrs, service_version); -} - -bool ArrowBatchBuilder::Append(const PschEvent& event) { - return impl_->Append(event); -} - -ArrowBatchBuilder::FinishResult ArrowBatchBuilder::Finish() { - return impl_->Finish(); -} - -void ArrowBatchBuilder::Reset() { - impl_->Reset(); -} - -int ArrowBatchBuilder::NumRows() const { - return impl_->num_rows; -} - -size_t ArrowBatchBuilder::EstimatedBytes() const { - return impl_->estimated_bytes; -} diff --git a/src/export/arrow_batch.h b/src/export/arrow_batch.h index 7d484ee..12f962f 100644 --- a/src/export/arrow_batch.h +++ b/src/export/arrow_batch.h @@ -1,41 +1,59 @@ -#ifndef PG_STAT_CH_SRC_EXPORT_ARROW_BATCH_H_ -#define PG_STAT_CH_SRC_EXPORT_ARROW_BATCH_H_ - -#include -#include - -#include - -struct PschEvent; - -class ArrowBatchBuilder { - public: - ArrowBatchBuilder(); - ~ArrowBatchBuilder(); - - ArrowBatchBuilder(ArrowBatchBuilder&&) noexcept; - ArrowBatchBuilder& operator=(ArrowBatchBuilder&&) noexcept; - - ArrowBatchBuilder(const ArrowBatchBuilder&) = delete; - ArrowBatchBuilder& operator=(const ArrowBatchBuilder&) = delete; - - bool Init(const char* extra_attrs, const char* service_version); - bool Append(const PschEvent& event); - - struct FinishResult { - std::shared_ptr ipc_buffer; - int num_rows = 0; - }; - - FinishResult Finish(); - void Reset(); - - int NumRows() const; - size_t EstimatedBytes() const; - - private: - struct Impl; - std::unique_ptr impl_; -}; - -#endif // PG_STAT_CH_SRC_EXPORT_ARROW_BATCH_H_ +// Arrow IPC batch builder — C replacement for the Arrow C++ ArrowBatchBuilder. +// +// Produces byte-equivalent Arrow IPC *streaming* payloads to the previous +// implementation (see OTEL_REWRITE_DESIGN.md §2/§4 and /tmp/wf1-code-arrow-batch.md +// for the exact 56-field schema): V5 little-endian, schema message, 13 +// dictionary batches (ids 0-12, isDelta=false, fresh per flush), one record +// batch with BodyCompression{ZSTD, BUFFER} (every buffer compressed, int64-LE +// uncompressed-length prefix, no -1 raw escape), 8-byte EOS. +// +// Memory model: ALL buffers (column builders, dictionary memo tables, flatcc +// builder pages, ZSTD CCtx via static-alloc, IPC output) are preallocated in +// Create() against cfg->scratch_budget_bytes; Append/Finish/Reset perform +// zero heap allocation. Allocation failure is only possible in Create()/ +// SetAttributes(), which return an error. +#ifndef PG_STAT_CH_ARROW_BATCH_H +#define PG_STAT_CH_ARROW_BATCH_H + +#include "queue/event.h" + +typedef struct PschArrowBuilder PschArrowBuilder; + +typedef struct PschArrowBuilderConfig { + size_t scratch_budget_bytes; // PschExportArenaPlan.arrow_scratch_bytes + size_t ipc_budget_bytes; // pre-compression flush threshold (estimated) + int max_rows; // upper bound on rows per batch (sizes memo tables) + const char* extra_attributes; // GUC pg_stat_ch.extra_attributes ("k:v;k:v") + const char* service_version; // PG_STAT_CH_VERSION +} PschArrowBuilderConfig; + +typedef enum PschArrowAppendResult { + PSCH_ARROW_APPEND_OK = 0, + PSCH_ARROW_APPEND_FULL, // batch reached budget/max_rows: Finish + send + Reset, then retry + PSCH_ARROW_APPEND_ERR, +} PschArrowAppendResult; + +// Preallocates everything; returns NULL with a reason in errbuf on failure. +extern PschArrowBuilder* PschArrowBuilderCreate(const PschArrowBuilderConfig* cfg, char* errbuf, + size_t errlen); +extern void PschArrowBuilderDestroy(PschArrowBuilder* b); + +// Re-parse extra_attributes after SIGHUP (cheap; reuses preallocated storage; +// values longer than the preallocated bound are truncated with a WARNING). +extern bool PschArrowBuilderSetAttributes(PschArrowBuilder* b, const char* extra_attributes); + +extern PschArrowAppendResult PschArrowBuilderAppend(PschArrowBuilder* b, const PschEvent* ev); + +// Serialize the accumulated rows. *data_out points into builder-owned memory, +// valid until the next Append/Finish/Reset/Destroy. Returns false on encode +// failure (caller records failure and decides whether rows are dropped). +extern bool PschArrowBuilderFinish(PschArrowBuilder* b, const uint8** data_out, size_t* len_out, + int* rows_out); + +extern void PschArrowBuilderReset(PschArrowBuilder* b); + +extern int PschArrowBuilderNumRows(const PschArrowBuilder* b); +extern size_t PschArrowBuilderEstimatedBytes(const PschArrowBuilder* b); +extern uint64 PschArrowBuilderMemUsed(const PschArrowBuilder* b); + +#endif // PG_STAT_CH_ARROW_BATCH_H diff --git a/src/export/arrow_ipc_emit.c b/src/export/arrow_ipc_emit.c new file mode 100644 index 0000000..ee8b970 --- /dev/null +++ b/src/export/arrow_ipc_emit.c @@ -0,0 +1,849 @@ +// Arrow IPC streaming emitter: flatcc-built metadata + ZSTD-framed bodies. +// +// Wire format (verified against Arrow C++ / pyarrow output, see +// /tmp/wf1-code-arrow-batch.md): +// * Every message: 0xFFFFFFFF continuation, int32 LE metadata length +// (multiple of 8, includes padding), flatbuffer, zero padding, body. +// * Schema message first (Message.bodyLength omitted, like Arrow C++), +// then one dictionary batch per DICT column (ids 0..N-1 in field order, +// isDelta omitted=false), one record batch, 8-byte EOS. +// * BodyCompression{codec=ZSTD}; method omitted (=BUFFER default). Every +// body buffer with size > 0 is unconditionally framed as int64 LE +// uncompressed length + ZSTD frame (level 1); zero-length buffers are +// stored raw with length 0. Buffers start 8-byte aligned, zero padded; +// bodyLength includes the final padding. +// * All fields nullable=true, null_count=0, no custom metadata anywhere. +// +// Deviation from Arrow C++ (semantically transparent to flatbuffers +// readers): metadata regions are padded up to a per-message-type constant +// slot so bodies can be compressed directly into the output buffer before +// the metadata (with its buffer lengths) is built; default-valued scalars +// we always store (DictionaryEncoding.id=0, Message.bodyLength) are +// explicitly written. +#include "postgres.h" + +#include +#include +#include + +#define ZSTD_STATIC_LINKING_ONLY +#include + +#include "flatcc/flatcc_builder.h" + +#include "export/arrow_ipc_emit.h" + +#ifdef WORDS_BIGENDIAN +#error "pg_stat_ch arrow_ipc_emit assumes a little-endian host" +#endif + +// MetadataVersion / MessageHeader / Type-union / TimeUnit / CompressionType +// values verified against the flatcc-generated header bundled in +// third_party/nanoarrow/src/nanoarrow_ipc.c. +#define PSCH_FB_METADATA_V5 ((int16)4) +#define PSCH_FB_HEADER_SCHEMA ((uint8)1) +#define PSCH_FB_HEADER_DICTIONARY_BATCH ((uint8)2) +#define PSCH_FB_HEADER_RECORD_BATCH ((uint8)3) +#define PSCH_FB_TYPE_INT ((uint8)2) +#define PSCH_FB_TYPE_UTF8 ((uint8)5) +#define PSCH_FB_TYPE_TIMESTAMP ((uint8)10) +#define PSCH_FB_TIMEUNIT_NANOSECOND ((int16)3) +#define PSCH_FB_COMPRESSION_ZSTD ((int8)1) + +static const size_t kSchemaMsgCap = 16384; +static const size_t kDictMetaCap = 768; +static const size_t kMetaSlack = 64; +static const size_t kVecMaxCount = 1 << 20; +// flatcc builder/emitter pages are warm-up allocated and reused; this is the +// accounting allowance used by both EstimateBytes and MemUsed. +static const size_t kFlatccSlackBytes = 256 * 1024; + +typedef struct PschIpcNode { + int64 length; + int64 null_count; +} PschIpcNode; + +typedef struct PschIpcBufEnt { + int64 offset; + int64 length; +} PschIpcBufEnt; + +StaticAssertDecl(sizeof(PschIpcNode) == 16, "FieldNode wire struct must be 16 bytes"); +StaticAssertDecl(sizeof(PschIpcBufEnt) == 16, "Buffer wire struct must be 16 bytes"); + +struct PschIpcEmitter { + int ncols; + int ndict; + PschIpcColSpec* specs; + + flatcc_builder_t fb; + bool fb_ready; + + ZSTD_CCtx* cctx; // points into cctx_ws (ZSTD_initStaticCCtx) + void* cctx_ws; + size_t cctx_ws_bytes; + + uint8* schema_msg; // complete prebuilt schema message (framing included) + size_t schema_msg_bytes; + + size_t dict_meta_slot; // padded metadata region per dictionary message + size_t rec_meta_slot; // padded metadata region of the record batch message + + uint8* out; + size_t out_cap; + + PschIpcNode* nodes; // scratch: ncols entries + PschIpcBufEnt* ents; // scratch: 3 * ncols entries + + uint64 mem_used; +}; + +static size_t Align8(size_t n) { + return (n + 7) & ~(size_t)7; +} + +static void EmitErr(char* errbuf, size_t errlen, const char* fmt, const char* detail) { + if (errbuf != NULL && errlen > 0) + snprintf(errbuf, errlen, fmt, detail); +} + +// --------------------------------------------------------------------------- +// Sizing (shared by EstimateBytes and Create so they can never disagree) +// --------------------------------------------------------------------------- + +static size_t RecMetaCap(int ncols) { + return 1024 + (size_t)ncols * 128; +} + +static size_t BodyBufCap(size_t src_cap) { + return src_cap > 0 ? Align8(8 + ZSTD_compressBound(src_cap)) : 0; +} + +static size_t DictBodyCap(const PschIpcColSpec* s) { + return BodyBufCap(s->offsets_cap) + BodyBufCap(s->var_cap); +} + +static size_t RecBodyCapForCol(const PschIpcColSpec* s) { + switch (s->kind) { + case PSCH_IPC_COL_UTF8: + return BodyBufCap(s->offsets_cap) + BodyBufCap(s->var_cap); + case PSCH_IPC_COL_FIXED: + case PSCH_IPC_COL_DICT: + default: + return BodyBufCap(s->data_cap); + } +} + +static size_t MaxCompressSrcCap(const PschIpcColSpec* specs, int ncols) { + size_t max = 1; + for (int i = 0; i < ncols; i++) { + if (specs[i].data_cap > max) + max = specs[i].data_cap; + if (specs[i].offsets_cap > max) + max = specs[i].offsets_cap; + if (specs[i].var_cap > max) + max = specs[i].var_cap; + } + return max; +} + +static size_t OutCapacity(const PschIpcColSpec* specs, int ncols) { + size_t cap = kSchemaMsgCap; + for (int i = 0; i < ncols; i++) { + if (specs[i].kind == PSCH_IPC_COL_DICT) + cap += 8 + kDictMetaCap + DictBodyCap(&specs[i]); + cap += RecBodyCapForCol(&specs[i]); + } + cap += 8 + RecMetaCap(ncols); + cap += 8 + 64; // EOS + slack + return cap; +} + +static size_t ZstdWorkspaceBytes(size_t max_src) { + ZSTD_compressionParameters cp = ZSTD_getCParams(1, (unsigned long long)max_src, 0); + size_t est = ZSTD_estimateCCtxSize_usingCParams(cp); + if (ZSTD_isError(est)) + est = 4 * 1024 * 1024; + return est + est / 4 + 65536; +} + +size_t PschIpcEmitterEstimateBytes(const PschIpcColSpec* specs, int ncols) { + size_t scratch = + (size_t)ncols * (sizeof(PschIpcColSpec) + sizeof(PschIpcNode) + 3 * sizeof(PschIpcBufEnt)); + return OutCapacity(specs, ncols) + ZstdWorkspaceBytes(MaxCompressSrcCap(specs, ncols)) + + kSchemaMsgCap + kFlatccSlackBytes + scratch + 4096; +} + +// --------------------------------------------------------------------------- +// flatbuffer metadata construction (flatcc runtime, hand-rolled tables) +// --------------------------------------------------------------------------- + +static bool AddScalar(flatcc_builder_t* B, int id, const void* src, size_t size) { + void* p = flatcc_builder_table_add(B, id, size, (uint16)size); + if (p == NULL) + return false; + memcpy(p, src, size); // host is little-endian (guarded above) + return true; +} + +static bool AddOffset(flatcc_builder_t* B, int id, flatcc_builder_ref_t ref) { + flatcc_builder_ref_t* p = flatcc_builder_table_add_offset(B, id); + if (p == NULL) + return false; + *p = ref; + return true; +} + +// Int{bitWidth, is_signed}; is_signed omitted when false (matches Arrow C++). +static flatcc_builder_ref_t BuildIntType(flatcc_builder_t* B, int32 bit_width, bool is_signed) { + if (flatcc_builder_start_table(B, 2) != 0) + return 0; + if (!AddScalar(B, 0, &bit_width, 4)) + return 0; + if (is_signed) { + uint8 one = 1; + if (!AddScalar(B, 1, &one, 1)) + return 0; + } + return flatcc_builder_end_table(B); +} + +static flatcc_builder_ref_t BuildEmptyTable(flatcc_builder_t* B) { + if (flatcc_builder_start_table(B, 0) != 0) + return 0; + return flatcc_builder_end_table(B); +} + +static flatcc_builder_ref_t BuildField(flatcc_builder_t* B, const PschIpcColSpec* spec, + int64 dict_id) { + uint8 type_type; + flatcc_builder_ref_t type_ref; + flatcc_builder_ref_t dict_ref = 0; + uint8 one = 1; + + flatcc_builder_ref_t name_ref = flatcc_builder_create_string(B, spec->name, strlen(spec->name)); + if (name_ref == 0) + return 0; + + if (spec->kind == PSCH_IPC_COL_UTF8 || spec->kind == PSCH_IPC_COL_DICT) { + // Dictionary fields carry the VALUE type (Utf8); indices live in + // DictionaryEncoding.indexType. + type_type = PSCH_FB_TYPE_UTF8; + type_ref = BuildEmptyTable(B); + } else if (spec->fixed_type == PSCH_IPC_TS_NS_UTC) { + flatcc_builder_ref_t tz_ref = flatcc_builder_create_string(B, "UTC", 3); + if (tz_ref == 0) + return 0; + type_type = PSCH_FB_TYPE_TIMESTAMP; + if (flatcc_builder_start_table(B, 2) != 0) + return 0; + { + int16 unit = PSCH_FB_TIMEUNIT_NANOSECOND; + if (!AddScalar(B, 0, &unit, 2)) + return 0; + if (!AddOffset(B, 1, tz_ref)) + return 0; + } + type_ref = flatcc_builder_end_table(B); + } else { + type_type = PSCH_FB_TYPE_INT; + switch (spec->fixed_type) { + case PSCH_IPC_INT32: + type_ref = BuildIntType(B, 32, true); + break; + case PSCH_IPC_UINT32: + type_ref = BuildIntType(B, 32, false); + break; + case PSCH_IPC_UINT64: + default: + type_ref = BuildIntType(B, 64, false); + break; + } + } + if (type_ref == 0) + return 0; + + if (spec->kind == PSCH_IPC_COL_DICT) { + flatcc_builder_ref_t idx_ref = BuildIntType(B, 32, true); + if (idx_ref == 0) + return 0; + if (flatcc_builder_start_table(B, 2) != 0) + return 0; + if (!AddScalar(B, 0, &dict_id, 8)) + return 0; + if (!AddOffset(B, 1, idx_ref)) + return 0; + dict_ref = flatcc_builder_end_table(B); // isOrdered/dictionaryKind omitted (defaults) + if (dict_ref == 0) + return 0; + } + + // Arrow C++ writes an empty (not absent) children vector. + if (flatcc_builder_start_offset_vector(B) != 0) + return 0; + flatcc_builder_ref_t children_ref = flatcc_builder_end_offset_vector(B); + if (children_ref == 0) + return 0; + + if (flatcc_builder_start_table(B, 6) != 0) + return 0; + if (!AddOffset(B, 0, name_ref)) + return 0; + if (!AddScalar(B, 1, &one, 1)) + return 0; // nullable=true on every field + if (!AddScalar(B, 2, &type_type, 1)) + return 0; + if (!AddOffset(B, 3, type_ref)) + return 0; + if (dict_ref != 0 && !AddOffset(B, 4, dict_ref)) + return 0; + if (!AddOffset(B, 5, children_ref)) + return 0; + return flatcc_builder_end_table(B); +} + +// Message{version=V5, header_type, header, [bodyLength]}. bodyLength is +// omitted for the schema message (Arrow C++ behavior; it is always 0 there). +static flatcc_builder_ref_t BuildMessageTable(flatcc_builder_t* B, uint8 header_type, + flatcc_builder_ref_t header_ref, int64 body_len, + bool with_body_len) { + int16 version = PSCH_FB_METADATA_V5; + + if (flatcc_builder_start_table(B, 4) != 0) + return 0; + if (!AddScalar(B, 0, &version, 2)) + return 0; + if (!AddScalar(B, 1, &header_type, 1)) + return 0; + if (!AddOffset(B, 2, header_ref)) + return 0; + if (with_body_len && !AddScalar(B, 3, &body_len, 8)) + return 0; + return flatcc_builder_end_table(B); +} + +static flatcc_builder_ref_t BuildStructVector(flatcc_builder_t* B, const void* data, int count) { + if (flatcc_builder_start_vector(B, 16, 8, kVecMaxCount) != 0) + return 0; + void* dst = flatcc_builder_extend_vector(B, (size_t)count); + if (dst == NULL) + return 0; + memcpy(dst, data, (size_t)count * 16); + return flatcc_builder_end_vector(B); +} + +// RecordBatch{length, nodes, buffers, compression=BodyCompression{ZSTD}}. +static flatcc_builder_ref_t BuildRecordBatchTable(flatcc_builder_t* B, int64 length, + const PschIpcNode* nodes, int nnodes, + const PschIpcBufEnt* ents, int nents) { + flatcc_builder_ref_t nodes_ref = BuildStructVector(B, nodes, nnodes); + if (nodes_ref == 0) + return 0; + flatcc_builder_ref_t bufs_ref = BuildStructVector(B, ents, nents); + if (bufs_ref == 0) + return 0; + + if (flatcc_builder_start_table(B, 2) != 0) + return 0; + { + int8 codec = PSCH_FB_COMPRESSION_ZSTD; + if (!AddScalar(B, 0, &codec, 1)) + return 0; // method omitted (=BUFFER default) + } + flatcc_builder_ref_t comp_ref = flatcc_builder_end_table(B); + if (comp_ref == 0) + return 0; + + if (flatcc_builder_start_table(B, 4) != 0) + return 0; + if (!AddScalar(B, 0, &length, 8)) + return 0; + if (!AddOffset(B, 1, nodes_ref)) + return 0; + if (!AddOffset(B, 2, bufs_ref)) + return 0; + if (!AddOffset(B, 3, comp_ref)) + return 0; + return flatcc_builder_end_table(B); +} + +static bool BuildSchemaMessage(flatcc_builder_t* B, const PschIpcColSpec* specs, int ncols) { + if (flatcc_builder_start_buffer(B, NULL, 0, 0) != 0) + return false; + + if (flatcc_builder_start_offset_vector(B) != 0) + return false; + int64 dict_id = 0; + for (int i = 0; i < ncols; i++) { + int64 id = specs[i].kind == PSCH_IPC_COL_DICT ? dict_id++ : -1; + flatcc_builder_ref_t f = BuildField(B, &specs[i], id); + if (f == 0) + return false; + if (flatcc_builder_offset_vector_push(B, f) == NULL) + return false; + } + flatcc_builder_ref_t fields_ref = flatcc_builder_end_offset_vector(B); + if (fields_ref == 0) + return false; + + // Schema{fields}; endianness omitted (=Little), no features/metadata. + if (flatcc_builder_start_table(B, 2) != 0) + return false; + if (!AddOffset(B, 1, fields_ref)) + return false; + flatcc_builder_ref_t schema_ref = flatcc_builder_end_table(B); + if (schema_ref == 0) + return false; + + flatcc_builder_ref_t msg = BuildMessageTable(B, PSCH_FB_HEADER_SCHEMA, schema_ref, 0, false); + if (msg == 0) + return false; + return flatcc_builder_end_buffer(B, msg) != 0; +} + +static bool BuildDictBatchMessage(flatcc_builder_t* B, int64 dict_id, int64 dict_count, + const PschIpcNode* nodes, int nnodes, const PschIpcBufEnt* ents, + int nents, int64 body_len) { + if (flatcc_builder_start_buffer(B, NULL, 0, 0) != 0) + return false; + + flatcc_builder_ref_t rb = BuildRecordBatchTable(B, dict_count, nodes, nnodes, ents, nents); + if (rb == 0) + return false; + + // DictionaryBatch{id, data}; isDelta omitted (=false). id is stored even + // when 0 so all dictionary messages have identical metadata size. + if (flatcc_builder_start_table(B, 3) != 0) + return false; + if (!AddScalar(B, 0, &dict_id, 8)) + return false; + if (!AddOffset(B, 1, rb)) + return false; + flatcc_builder_ref_t db = flatcc_builder_end_table(B); + if (db == 0) + return false; + + flatcc_builder_ref_t msg = + BuildMessageTable(B, PSCH_FB_HEADER_DICTIONARY_BATCH, db, body_len, true); + if (msg == 0) + return false; + return flatcc_builder_end_buffer(B, msg) != 0; +} + +static bool BuildRecBatchMessage(flatcc_builder_t* B, int64 num_rows, const PschIpcNode* nodes, + int nnodes, const PschIpcBufEnt* ents, int nents, int64 body_len) { + if (flatcc_builder_start_buffer(B, NULL, 0, 0) != 0) + return false; + flatcc_builder_ref_t rb = BuildRecordBatchTable(B, num_rows, nodes, nnodes, ents, nents); + if (rb == 0) + return false; + flatcc_builder_ref_t msg = BuildMessageTable(B, PSCH_FB_HEADER_RECORD_BATCH, rb, body_len, true); + if (msg == 0) + return false; + return flatcc_builder_end_buffer(B, msg) != 0; +} + +// --------------------------------------------------------------------------- +// Message emission +// --------------------------------------------------------------------------- + +static void WriteFraming(uint8* dst, size_t meta_len) { + int32 cont = -1; + int32 len32 = (int32)meta_len; + memcpy(dst, &cont, 4); + memcpy(dst + 4, &len32, 4); +} + +// Copies the finished flatbuffer into the fixed metadata slot at meta_off+8, +// zero-pads the slot remainder, writes framing, and resets the builder. +static bool FinalizeMetaIntoSlot(PschIpcEmitter* e, size_t meta_off, size_t slot) { + size_t size = flatcc_builder_get_buffer_size(&e->fb); + + if (size == 0 || size > slot || meta_off + 8 + slot > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC metadata size %zu exceeds slot %zu", size, slot); + flatcc_builder_reset(&e->fb); + return false; + } + if (flatcc_builder_copy_buffer(&e->fb, e->out + meta_off + 8, size) == NULL) { + elog(WARNING, "pg_stat_ch: Arrow IPC metadata copy failed"); + flatcc_builder_reset(&e->fb); + return false; + } + memset(e->out + meta_off + 8 + size, 0, slot - size); + WriteFraming(e->out + meta_off, slot); + flatcc_builder_reset(&e->fb); + return true; +} + +// Appends one body buffer at *used (relative to body_base, 8-aligned) and +// records its Buffer entry. size==0 buffers are stored raw with length 0 +// and do not advance the cursor (Arrow C++ behavior). +static bool EmitBodyBuffer(PschIpcEmitter* e, size_t body_base, size_t* used, const void* src, + size_t src_len, int* nents) { + PschIpcBufEnt* ent = &e->ents[*nents]; + size_t off = *used; + + ent->offset = (int64)off; + ent->length = 0; + (*nents)++; + if (src_len == 0) + return true; + + size_t abs = body_base + off; + if (abs + 8 > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC output buffer overflow (body prefix)"); + return false; + } + { + int64 unc = (int64)src_len; + memcpy(e->out + abs, &unc, 8); + } + size_t r = ZSTD_compress2(e->cctx, e->out + abs + 8, e->out_cap - abs - 8, src, src_len); + if (ZSTD_isError(r)) { + elog(WARNING, "pg_stat_ch: ZSTD buffer compression failed: %s", ZSTD_getErrorName(r)); + return false; + } + + size_t len = 8 + r; + size_t new_used = Align8(off + len); + if (body_base + new_used > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC output buffer overflow (body padding)"); + return false; + } + memset(e->out + abs + len, 0, new_used - (off + len)); + ent->length = (int64)len; + *used = new_used; + return true; +} + +static bool EmitDictMessage(PschIpcEmitter* e, const PschIpcColData* col, int64 dict_id, + size_t* pos) { + size_t meta_off = *pos; + size_t slot = e->dict_meta_slot; + size_t body_base = meta_off + 8 + slot; + size_t used = 0; + int nents = 0; + + if (body_base > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC output buffer overflow (dictionary metadata)"); + return false; + } + if (!EmitBodyBuffer(e, body_base, &used, NULL, 0, &nents)) + return false; // validity + if (!EmitBodyBuffer(e, body_base, &used, col->offsets, (size_t)(col->dict_count + 1) * 4, &nents)) + return false; + if (!EmitBodyBuffer(e, body_base, &used, col->var_data, col->var_len, &nents)) + return false; + + e->nodes[0].length = col->dict_count; + e->nodes[0].null_count = 0; + if (!BuildDictBatchMessage(&e->fb, dict_id, col->dict_count, e->nodes, 1, e->ents, nents, + (int64)used)) { + elog(WARNING, "pg_stat_ch: Arrow IPC dictionary metadata build failed"); + flatcc_builder_reset(&e->fb); + return false; + } + if (!FinalizeMetaIntoSlot(e, meta_off, slot)) + return false; + *pos = body_base + used; + return true; +} + +static bool EmitRecordBatchMessage(PschIpcEmitter* e, const PschIpcColData* cols, int64 num_rows, + size_t* pos) { + size_t meta_off = *pos; + size_t slot = e->rec_meta_slot; + size_t body_base = meta_off + 8 + slot; + size_t used = 0; + int nents = 0; + + if (body_base > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC output buffer overflow (record batch metadata)"); + return false; + } + for (int i = 0; i < e->ncols; i++) { + const PschIpcColData* c = &cols[i]; + + e->nodes[i].length = num_rows; + e->nodes[i].null_count = 0; + if (!EmitBodyBuffer(e, body_base, &used, NULL, 0, &nents)) + return false; // validity + switch (e->specs[i].kind) { + case PSCH_IPC_COL_UTF8: + if (!EmitBodyBuffer(e, body_base, &used, c->offsets, (size_t)(num_rows + 1) * 4, &nents)) + return false; + if (!EmitBodyBuffer(e, body_base, &used, c->var_data, c->var_len, &nents)) + return false; + break; + case PSCH_IPC_COL_FIXED: + case PSCH_IPC_COL_DICT: + default: + if (!EmitBodyBuffer(e, body_base, &used, c->data, c->data_len, &nents)) + return false; + break; + } + } + + if (!BuildRecBatchMessage(&e->fb, num_rows, e->nodes, e->ncols, e->ents, nents, (int64)used)) { + elog(WARNING, "pg_stat_ch: Arrow IPC record batch metadata build failed"); + flatcc_builder_reset(&e->fb); + return false; + } + if (!FinalizeMetaIntoSlot(e, meta_off, slot)) + return false; + *pos = body_base + used; + return true; +} + +bool PschIpcEmitterEmit(PschIpcEmitter* e, const PschIpcColData* cols, int ncols, int64 num_rows, + const uint8** out_data, size_t* out_len) { + if (e == NULL || cols == NULL || out_data == NULL || out_len == NULL) + return false; + if (ncols != e->ncols || num_rows <= 0) + return false; + + // A longjmp may have interrupted a previous Emit between flatcc calls. + flatcc_builder_reset(&e->fb); + + size_t pos = 0; + memcpy(e->out, e->schema_msg, e->schema_msg_bytes); + pos += e->schema_msg_bytes; + + int64 dict_id = 0; + for (int i = 0; i < e->ncols; i++) { + if (e->specs[i].kind != PSCH_IPC_COL_DICT) + continue; + if (!EmitDictMessage(e, &cols[i], dict_id, &pos)) + return false; + dict_id++; + } + if (!EmitRecordBatchMessage(e, cols, num_rows, &pos)) + return false; + + if (pos + 8 > e->out_cap) { + elog(WARNING, "pg_stat_ch: Arrow IPC output buffer overflow (EOS)"); + return false; + } + WriteFraming(e->out + pos, 0); + pos += 8; + + *out_data = e->out; + *out_len = pos; + return true; +} + +// --------------------------------------------------------------------------- +// Create / Destroy +// --------------------------------------------------------------------------- + +// Builds the schema message once into an exact-sized owned buffer. +static bool CreateSchemaMessage(PschIpcEmitter* e, char* errbuf, size_t errlen) { + if (!BuildSchemaMessage(&e->fb, e->specs, e->ncols)) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "schema flatbuffer build failed%s", ""); + return false; + } + size_t size = flatcc_builder_get_buffer_size(&e->fb); + size_t padded = Align8(size); + if (size == 0 || 8 + padded > kSchemaMsgCap) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "schema message exceeds reserved capacity%s", ""); + return false; + } + e->schema_msg = malloc(8 + padded); + if (e->schema_msg == NULL) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "out of memory (schema message)%s", ""); + return false; + } + WriteFraming(e->schema_msg, padded); + if (flatcc_builder_copy_buffer(&e->fb, e->schema_msg + 8, size) == NULL) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "schema flatbuffer copy failed%s", ""); + return false; + } + memset(e->schema_msg + 8 + size, 0, padded - size); + e->schema_msg_bytes = 8 + padded; + flatcc_builder_reset(&e->fb); + return true; +} + +// Determines the fixed metadata slot sizes by building structurally +// identical template messages (metadata size depends only on node/buffer +// counts, not values), and warms up the flatcc builder pages in the +// process so Emit() never grows them. +static bool ComputeMetaSlots(PschIpcEmitter* e, char* errbuf, size_t errlen) { + if (e->ndict > 0) { + PschIpcNode node = {1, 0}; + PschIpcBufEnt ents[3] = {{0, 0}, {0, 16}, {16, 16}}; + + if (!BuildDictBatchMessage(&e->fb, (int64)e->ndict - 1, 1, &node, 1, ents, 3, 32)) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "dictionary metadata template build failed%s", ""); + return false; + } + e->dict_meta_slot = Align8(flatcc_builder_get_buffer_size(&e->fb) + kMetaSlack); + flatcc_builder_reset(&e->fb); + if (e->dict_meta_slot > kDictMetaCap) { + EmitErr(errbuf, errlen, "dictionary metadata exceeds reserved capacity%s", ""); + return false; + } + } + + { + int nents = 0; + + for (int i = 0; i < e->ncols; i++) { + e->nodes[i].length = 1; + e->nodes[i].null_count = 0; + nents += e->specs[i].kind == PSCH_IPC_COL_UTF8 ? 3 : 2; + } + for (int i = 0; i < nents; i++) { + e->ents[i].offset = 0; + e->ents[i].length = 0; + } + if (!BuildRecBatchMessage(&e->fb, 1, e->nodes, e->ncols, e->ents, nents, 0)) { + flatcc_builder_reset(&e->fb); + EmitErr(errbuf, errlen, "record batch metadata template build failed%s", ""); + return false; + } + e->rec_meta_slot = Align8(flatcc_builder_get_buffer_size(&e->fb) + kMetaSlack); + flatcc_builder_reset(&e->fb); + if (e->rec_meta_slot > RecMetaCap(e->ncols)) { + EmitErr(errbuf, errlen, "record batch metadata exceeds reserved capacity%s", ""); + return false; + } + } + return true; +} + +// Static-workspace CCtx + verify-at-start compression of a max-size input. +// If the estimate proves too small, degrade windowLog (with a LOG) rather +// than risking hot-path failure. +static bool CreateZstd(PschIpcEmitter* e, size_t max_src, char* errbuf, size_t errlen) { + e->cctx_ws_bytes = ZstdWorkspaceBytes(max_src); + e->cctx_ws = malloc(e->cctx_ws_bytes); + if (e->cctx_ws == NULL) { + EmitErr(errbuf, errlen, "out of memory (ZSTD workspace)%s", ""); + return false; + } + e->cctx = ZSTD_initStaticCCtx(e->cctx_ws, e->cctx_ws_bytes); + if (e->cctx == NULL) { + EmitErr(errbuf, errlen, "ZSTD_initStaticCCtx failed%s", ""); + return false; + } + { + size_t rc = ZSTD_CCtx_setParameter(e->cctx, ZSTD_c_compressionLevel, 1); + if (ZSTD_isError(rc)) { + EmitErr(errbuf, errlen, "ZSTD level: %s", ZSTD_getErrorName(rc)); + return false; + } + } + + void* src = calloc(1, max_src); + void* dst = malloc(ZSTD_compressBound(max_src)); + bool ok = false; + + if (src != NULL && dst != NULL) { + size_t rc = ZSTD_compress2(e->cctx, dst, ZSTD_compressBound(max_src), src, max_src); + + if (ZSTD_isError(rc)) { + ZSTD_compressionParameters cp = ZSTD_getCParams(1, (unsigned long long)max_src, 0); + int wlog = (int)cp.windowLog - 1; + + for (; wlog >= ZSTD_WINDOWLOG_MIN; wlog--) { + if (ZSTD_isError(ZSTD_CCtx_setParameter(e->cctx, ZSTD_c_windowLog, wlog))) + break; + rc = ZSTD_compress2(e->cctx, dst, ZSTD_compressBound(max_src), src, max_src); + if (!ZSTD_isError(rc)) { + elog(LOG, "pg_stat_ch: ZSTD workspace verify degraded windowLog to %d", wlog); + break; + } + } + } + if (!ZSTD_isError(rc)) + ok = true; + if (!ok) + EmitErr(errbuf, errlen, "ZSTD verify compression failed: %s", ZSTD_getErrorName(rc)); + } else { + EmitErr(errbuf, errlen, "out of memory (ZSTD verify buffers)%s", ""); + } + free(src); + free(dst); + return ok; +} + +PschIpcEmitter* PschIpcEmitterCreate(const PschIpcColSpec* specs, int ncols, char* errbuf, + size_t errlen) { + if (specs == NULL || ncols <= 0 || ncols > 1024) { + EmitErr(errbuf, errlen, "invalid emitter column specs%s", ""); + return NULL; + } + + PschIpcEmitter* e = calloc(1, sizeof(PschIpcEmitter)); + if (e == NULL) { + EmitErr(errbuf, errlen, "out of memory (emitter)%s", ""); + return NULL; + } + e->ncols = ncols; + + e->specs = malloc((size_t)ncols * sizeof(PschIpcColSpec)); + e->nodes = malloc((size_t)ncols * sizeof(PschIpcNode)); + e->ents = malloc((size_t)ncols * 3 * sizeof(PschIpcBufEnt)); + if (e->specs == NULL || e->nodes == NULL || e->ents == NULL) { + EmitErr(errbuf, errlen, "out of memory (emitter scratch)%s", ""); + goto fail; + } + memcpy(e->specs, specs, (size_t)ncols * sizeof(PschIpcColSpec)); + for (int i = 0; i < ncols; i++) { + if (e->specs[i].kind == PSCH_IPC_COL_DICT) + e->ndict++; + } + + if (flatcc_builder_init(&e->fb) != 0) { + EmitErr(errbuf, errlen, "flatcc builder init failed%s", ""); + goto fail; + } + e->fb_ready = true; + + if (!CreateSchemaMessage(e, errbuf, errlen)) + goto fail; + if (!ComputeMetaSlots(e, errbuf, errlen)) + goto fail; + if (!CreateZstd(e, MaxCompressSrcCap(e->specs, ncols), errbuf, errlen)) + goto fail; + + e->out_cap = OutCapacity(e->specs, ncols); + e->out = malloc(e->out_cap); + if (e->out == NULL) { + EmitErr(errbuf, errlen, "out of memory (IPC output buffer)%s", ""); + goto fail; + } + + e->mem_used = sizeof(PschIpcEmitter) + (uint64)ncols * sizeof(PschIpcColSpec) + + (uint64)ncols * sizeof(PschIpcNode) + (uint64)ncols * 3 * sizeof(PschIpcBufEnt) + + e->schema_msg_bytes + e->cctx_ws_bytes + e->out_cap + kFlatccSlackBytes; + return e; + +fail: + PschIpcEmitterDestroy(e); + return NULL; +} + +void PschIpcEmitterDestroy(PschIpcEmitter* e) { + if (e == NULL) + return; + if (e->fb_ready) + flatcc_builder_clear(&e->fb); + free(e->cctx_ws); // cctx lives inside the workspace + free(e->schema_msg); + free(e->out); + free(e->nodes); + free(e->ents); + free(e->specs); + free(e); +} + +uint64 PschIpcEmitterMemUsed(const PschIpcEmitter* e) { + return e != NULL ? e->mem_used : 0; +} diff --git a/src/export/arrow_ipc_emit.h b/src/export/arrow_ipc_emit.h new file mode 100644 index 0000000..e59a6c2 --- /dev/null +++ b/src/export/arrow_ipc_emit.h @@ -0,0 +1,79 @@ +// Internal Arrow IPC streaming-format emitter used by arrow_batch.c. +// +// nanoarrow's ArrowIpcEncoder can encode neither dictionary batches nor +// compressed buffers (see /tmp/wf1-research-nanoarrow.md), so this module +// emits the encapsulated messages itself: flatbuffer metadata is built with +// the flatcc runtime bundled with the vendored nanoarrow +// (third_party/nanoarrow/src/flatcc.c), bodies are ZSTD-framed per buffer +// (int64-LE uncompressed-length prefix + ZSTD frame, level 1, no -1 raw +// escape; zero-length buffers stay raw, matching Arrow C++). +// +// Memory model: Create() preallocates the output buffer, the ZSTD CCtx +// (static workspace), and warms up the flatcc builder pages by building +// worst-case template messages. Emit() performs zero heap allocation. +// PschIpcEmitterEstimateBytes() is the pure sizing oracle Create() also +// allocates by, so callers can budget-fit specs before creating. +#ifndef PG_STAT_CH_ARROW_IPC_EMIT_H +#define PG_STAT_CH_ARROW_IPC_EMIT_H + +typedef enum PschIpcColKind { + PSCH_IPC_COL_FIXED = 0, // body: validity + fixed-width data + PSCH_IPC_COL_UTF8, // body: validity + int32 offsets + data + PSCH_IPC_COL_DICT, // body: validity + int32 indices; plus one dictionary batch +} PschIpcColKind; + +typedef enum PschIpcFixedType { + PSCH_IPC_TS_NS_UTC = 0, // timestamp[ns, tz="UTC"], 8 bytes + PSCH_IPC_INT32, + PSCH_IPC_UINT32, + PSCH_IPC_UINT64, +} PschIpcFixedType; + +// Capacities are worst-case uncompressed byte counts; they size the output +// buffer and the ZSTD workspace. `name` must outlive the emitter (string +// literals in practice). +typedef struct PschIpcColSpec { + const char* name; + PschIpcColKind kind; + PschIpcFixedType fixed_type; // FIXED only + size_t data_cap; // FIXED: value bytes; DICT: int32 index bytes + size_t offsets_cap; // UTF8: row offsets bytes; DICT: value offsets bytes + size_t var_cap; // UTF8: data bytes; DICT: dictionary value bytes +} PschIpcColSpec; + +// Per-column views for one Emit() call. Lengths must not exceed the +// corresponding spec capacities. +typedef struct PschIpcColData { + const void* data; // FIXED values / DICT indices + size_t data_len; // bytes + const int32* offsets; // UTF8: rows+1 entries; DICT: dict_count+1 entries + const void* var_data; // UTF8 data / DICT value bytes + size_t var_len; // bytes + int64 dict_count; // DICT only: number of dictionary values +} PschIpcColData; + +typedef struct PschIpcEmitter PschIpcEmitter; + +// Total bytes Create() will preallocate for these specs (output buffer + +// ZSTD workspace + schema message + flatcc page slack). Pure function. +extern size_t PschIpcEmitterEstimateBytes(const PschIpcColSpec* specs, int ncols); + +// Preallocates everything (including the prebuilt schema message and +// metadata-size templates). Returns NULL with a reason in errbuf on +// failure. Dictionary ids are assigned 0..N-1 to DICT columns in spec +// order, both in the schema and in the emitted dictionary batches. +extern PschIpcEmitter* PschIpcEmitterCreate(const PschIpcColSpec* specs, int ncols, char* errbuf, + size_t errlen); +extern void PschIpcEmitterDestroy(PschIpcEmitter* e); + +extern uint64 PschIpcEmitterMemUsed(const PschIpcEmitter* e); + +// Serializes one complete IPC stream payload: schema message, one +// dictionary batch per DICT column (isDelta=false), one record batch with +// BodyCompression{ZSTD, BUFFER}, 8-byte EOS. *out_data points into +// emitter-owned memory, valid until the next Emit/Destroy. Returns false +// on encode failure (logs WARNING; never ereport(ERROR)). +extern bool PschIpcEmitterEmit(PschIpcEmitter* e, const PschIpcColData* cols, int ncols, + int64 num_rows, const uint8** out_data, size_t* out_len); + +#endif // PG_STAT_CH_ARROW_IPC_EMIT_H diff --git a/src/export/flatcc_emitter_alloc.c b/src/export/flatcc_emitter_alloc.c new file mode 100644 index 0000000..8fc43d8 --- /dev/null +++ b/src/export/flatcc_emitter_alloc.c @@ -0,0 +1,72 @@ +// Implementation of the flatcc emitter page pool (see flatcc_emitter_alloc.h). +// +// The pool is a fixed array of 64-byte-aligned slots carved into a free list on +// first use. flatcc requests pages of a fixed size (sizeof(flatcc_emitter_page_t), +// ~3 KB); kSlotBytes is comfortably above that. kSlotCount covers the +// worst-case concurrent page count (the one-time schema message needs the most, +// ~6 native pages; steady-state flushes need only 2-3) with wide margin. + +#include "postgres.h" + +#include +#include + +#include "export/flatcc_emitter_alloc.h" + +// Larger than sizeof(flatcc_emitter_page_t) (FLATCC_EMITTER_PAGE_SIZE 2944 + +// list pointers) and 64-aligned. A request above this falls back to malloc. +#define PSCH_FLATCC_SLOT_BYTES 4096 +#define PSCH_FLATCC_SLOT_COUNT 16 + +typedef union PschFlatccSlot { + // next is valid only while the slot is on the free list; the page bytes + // overlay it once handed out. + union PschFlatccSlot* next; + pg_attribute_aligned(64) char page[PSCH_FLATCC_SLOT_BYTES]; +} PschFlatccSlot; + +static pg_attribute_aligned(64) PschFlatccSlot g_pool[PSCH_FLATCC_SLOT_COUNT]; +static PschFlatccSlot* g_free_list = NULL; +static bool g_pool_initialized = false; + +static void PschFlatccPoolInit(void) { + g_free_list = NULL; + for (int i = 0; i < PSCH_FLATCC_SLOT_COUNT; i++) { + g_pool[i].next = g_free_list; + g_free_list = &g_pool[i]; + } + g_pool_initialized = true; +} + +static inline bool PschFlatccFromPool(const void* p) { + return (const char*)p >= (const char*)g_pool && + (const char*)p < (const char*)g_pool + sizeof(g_pool); +} + +void* PschFlatccEmitterAlloc(size_t n) { + if (!g_pool_initialized) { + PschFlatccPoolInit(); + } + // Pool slots are fixed-size; an out-of-range request or an exhausted pool + // falls back to the system allocator (correctness over the zero-alloc + // guarantee — sizing keeps this off the steady-state path). + if (n <= PSCH_FLATCC_SLOT_BYTES && g_free_list != NULL) { + PschFlatccSlot* slot = g_free_list; + g_free_list = slot->next; + return slot; + } + return malloc(n); +} + +void PschFlatccEmitterFree(void* p) { + if (p == NULL) { + return; + } + if (PschFlatccFromPool(p)) { + PschFlatccSlot* slot = (PschFlatccSlot*)p; + slot->next = g_free_list; + g_free_list = slot; + return; + } + free(p); +} diff --git a/src/export/flatcc_emitter_alloc.h b/src/export/flatcc_emitter_alloc.h new file mode 100644 index 0000000..7b138b9 --- /dev/null +++ b/src/export/flatcc_emitter_alloc.h @@ -0,0 +1,37 @@ +// Fixed page-pool allocator for flatcc's emitter, force-included into the +// vendored third_party/nanoarrow/src/flatcc.c translation unit (see +// CMakeLists.txt). See OTEL_REWRITE_DESIGN.md §4 and the review finding +// "flatcc-emitter-page-malloc-hot-path". +// +// Why this exists: flatcc's default emitter malloc/free's its ~3 KB pages, and +// flatcc_emitter_reset's "used_average" heuristic frees pages when usage drops. +// Across our per-flush lifecycle (one large schema once, then 13 tiny dict +// messages + one record-batch message per Arrow flush) that heuristic frees a +// page on every reset and re-mallocs it building the next record batch — i.e. +// heap allocation on the steady-state export path, the exact behavior the +// rewrite forbids. A NULL malloc there would drop the batch under +// vm.overcommit_memory=2. +// +// This routes FLATCC_EMITTER_ALLOC/FREE through a fixed pool of pre-reserved, +// 64-byte-aligned page slots (matching flatcc's aligned_alloc(64, ...) +// default). Alloc/free become O(1) free-list ops that never touch the system +// allocator in steady state; flatcc's page-shrink logic is unchanged but now +// only cycles pages in and out of the pool. If the pool is ever exhausted the +// allocator falls back to malloc so correctness is preserved (only the +// zero-allocation guarantee degrades — the pool is sized well above the +// worst-case concurrent page count). The bgworker is the sole flatcc user, so +// no locking is needed. +#ifndef PG_STAT_CH_FLATCC_EMITTER_ALLOC_H +#define PG_STAT_CH_FLATCC_EMITTER_ALLOC_H + +#include + +void* PschFlatccEmitterAlloc(size_t n); +void PschFlatccEmitterFree(void* p); + +// Consumed by flatcc_emitter.h's #ifndef guards (this header is force-included +// before it when compiling flatcc.c). +#define FLATCC_EMITTER_ALLOC(n) PschFlatccEmitterAlloc((size_t)(n)) +#define FLATCC_EMITTER_FREE(p) PschFlatccEmitterFree(p) + +#endif // PG_STAT_CH_FLATCC_EMITTER_ALLOC_H From 7a3fc8ffea318e8f5264440e889d940de0df7d90 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:07 -0500 Subject: [PATCH 06/11] feat(export): OTLP/HTTP exporter backend in C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the gRPC direct-proto exporter with a hand-rolled HTTP/1.1 client over blocking sockets on the bgworker thread (OpenSSL when the endpoint is https), emitting the identical OTLP ExportLogsServiceRequest payloads for both the per-record and Arrow-passthrough paths. Encode/network buffers and the constant request-head prefix are preallocated; reconnects allocate but never per batch. Removes gRPC entirely — and with it the gpr_malloc abort site and the background gRPC threads in the shmem-attached bgworker. Retry only on 429/502/503/504 and connection drop (Retry-After honored); other 4xx/5xx are permanent. otel_headers values are rejected if they contain control characters (header-injection guard); db.name/db.user clamp to NAMEDATALEN-1, matching the other paths. --- src/export/otel_exporter.c | 1371 +++++++++++++++++++++++++++++++++++ src/export/otel_exporter.cc | 522 ------------- src/export/otel_exporter.h | 10 - 3 files changed, 1371 insertions(+), 532 deletions(-) create mode 100644 src/export/otel_exporter.c delete mode 100644 src/export/otel_exporter.cc delete mode 100644 src/export/otel_exporter.h diff --git a/src/export/otel_exporter.c b/src/export/otel_exporter.c new file mode 100644 index 0000000..2b3c546 --- /dev/null +++ b/src/export/otel_exporter.c @@ -0,0 +1,1371 @@ +// OTLP/HTTP exporter backend. +// +// Hand-rolled HTTP/1.1 client over blocking sockets on the bgworker thread +// (TLS via OpenSSL when the endpoint scheme is https). Replaces the gRPC +// direct-proto exporter: same OTLP ExportLogsServiceRequest payloads, but +// with zero heap allocation on the steady-state export path — the protobuf +// encode buffer, network buffer, and constant request-head prefix are all +// preallocated in PschOtelExporterCreate. Reconnects (getaddrinfo, SSL_new) +// allocate, but only on the connect path, never per batch. +// +// Wire compatibility notes (oracle: the old otel_exporter.cc): +// * Per-record path: attributes-only LogRecords (no body); zero-valued int +// attrs are skipped, string attrs always emitted (even empty); duration +// dual-encoded (db.client.operation.duration seconds-double + duration_us +// int); time_unix_nano = (ts_start + PG epoch offset) * 1000. +// * Arrow path: one LogRecord, body = bytes(IPC), block_format/block_rows +// attrs, plus a resource-level pg_stat_ch.block_format attr. +// * Encoded field surface pinned to opentelemetry-proto v1.9.0. + +#include "postgres.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "miscadmin.h" +#include "utils/memutils.h" + +#include "pg_stat_ch/pg_stat_ch.h" +#include "config/guc.h" +#include "config/memory_budget.h" +#include "export/exporter.h" +#include "export/otlp_encode.h" +#include "queue/shmem.h" + +// PostgreSQL epoch (2000-01-01) to Unix epoch (1970-01-01), in microseconds. +static const int64 kPostgresEpochOffsetUs = INT64CONST(946684800000000); + +static const char kServiceName[] = "pg_stat_ch"; +static const char kDefaultEndpoint[] = "http://localhost:4318"; +static const char kDefaultPath[] = "/v1/logs"; +static const int kDefaultTimeoutMs = 1000; + +// Per-event encode ceiling used to decide when a chunk is full. Must exceed +// the worst-case encoded LogRecord: all string payloads (~4.4 KiB after the +// clamps) + ~44 attributes of key/tag/length-slot overhead (~2.7 KiB) + ints. +enum { kEventEncodeMargin = 16 * 1024 }; +StaticAssertDecl(PSCH_MAX_QUERY_LEN + PSCH_MAX_ERR_MSG_LEN + 8192 <= kEventEncodeMargin, + "encode margin must cover a worst-case event record"); + +// Room reserved in the net buffer after the head prefix for the +// "\r\n\r\n" tail. +enum { kContentLengthTailMax = 32 }; + +typedef struct PschOtelExporter { + PschExporter base; + + // Endpoint, parsed once at create (psch_otel_endpoint is PGC_POSTMASTER). + char host[256]; + char path[512]; + int port; + bool use_tls; + + char hostname[256]; // resource attr host.name + + // Constant request head up to and including "Content-Length: ". + char* head_prefix; + size_t head_prefix_len; + Size head_alloc_bytes; + + uint8* encode_buf; // OTLP request bodies (uncompressed protobuf) + size_t encode_cap; + uint8* net_buf; // request head assembly + HTTP response + size_t net_cap; + + int fd; + SSL_CTX* ssl_ctx; // created once at create() when use_tls + SSL* ssl; + bool connected; + bool conn_reused; // connection has completed >= 1 request (stale-retry gate) + bool in_flight; // wire exchange interrupted (longjmp) -> connection poisoned + + int consecutive_failures; + uint64 mem_used; +} PschOtelExporter; + +typedef struct PschHttpResponse { + int status; + const uint8* body; // points into net_buf; valid only when body_complete + size_t body_len; + bool body_complete; + long retry_after_s; // -1 when absent / not delta-seconds + bool reusable; +} PschHttpResponse; + +// --------------------------------------------------------------------------- +// Small helpers +// --------------------------------------------------------------------------- + +static int64 PschMonotonicNowUs(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64)ts.tv_sec * 1000000 + ts.tv_nsec / 1000; +} + +static int PschOtelTimeoutMs(void) { + return psch_export_timeout_ms > 0 ? psch_export_timeout_ms : kDefaultTimeoutMs; +} + +static void* PschOtelAlloc(Size size) { + return MemoryContextAllocExtended(TopMemoryContext, size, + MCXT_ALLOC_NO_OOM | MCXT_ALLOC_ZERO | MCXT_ALLOC_HUGE); +} + +// Leading-whitespace-tolerant delta-seconds / decimal parser; -1 if the +// value does not start with a digit (e.g. an HTTP-date Retry-After). +static long PschParseDigits(const char* s, size_t len) { + long v = 0; + bool any = false; + for (size_t i = 0; i < len; i++) { + char c = s[i]; + if (c == ' ' || c == '\t') { + if (any) + break; + continue; + } + if (c < '0' || c > '9') + break; + if (v > (LONG_MAX - 9) / 10) + return -1; + v = v * 10 + (c - '0'); + any = true; + } + return any ? v : -1; +} + +static bool PschValueContains(const char* v, size_t vlen, const char* token) { + size_t tlen = strlen(token); + for (size_t i = 0; i + tlen <= vlen; i++) { + if (pg_strncasecmp(v + i, token, tlen) == 0) + return true; + } + return false; +} + +static uint32 PschClampLen(uint32 len, uint32 max, const char* field_name) { + if (len <= max) + return len; + // Rate-limit to at most one WARNING/sec: a corrupt or oversized field could + // otherwise flood the log at the event rate. + static time_t last_log = 0; + time_t now = time(NULL); + if (now - last_log >= 1) { + elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, len); + last_log = now; + } + return max; +} + +static void PschOtelFormatSslError(char* errbuf, size_t errlen, const char* what) { + unsigned long e = ERR_get_error(); + if (e != 0) { + char ebuf[256]; + ERR_error_string_n(e, ebuf, sizeof ebuf); + snprintf(errbuf, errlen, "%s: %s", what, ebuf); + } else { + snprintf(errbuf, errlen, "%s", what); + } + ERR_clear_error(); +} + +// WARNING + consecutive-failure increment, exactly once per failed +// export_events/send_arrow call. Shmem failure stats are recorded by the +// driver (stats_exporter.c) from the returned status, so the backend must NOT +// call PschRecordExportFailure here (it would double-count send_failures); the +// detailed message lives in this WARNING. +static void PschOtelFail(PschOtelExporter* exp, const char* context, const char* msg) { + elog(WARNING, "pg_stat_ch: %s: %s", context, msg); + exp->consecutive_failures++; +} + +// --------------------------------------------------------------------------- +// Connection management (patterns from the proven ClickHouse exporter path) +// --------------------------------------------------------------------------- + +static void PschOtelCloseConn(PschOtelExporter* exp) { + if (exp->ssl != NULL) { + (void)SSL_shutdown(exp->ssl); // best-effort; bounded by SO_SNDTIMEO + SSL_free(exp->ssl); + exp->ssl = NULL; + } + if (exp->fd >= 0) { + close(exp->fd); + exp->fd = -1; + } + exp->connected = false; + exp->conn_reused = false; + exp->in_flight = false; +} + +// Nonblocking connect bounded by deadline; restores blocking mode afterwards +// (the send/recv paths rely on SO_RCVTIMEO/SNDTIMEO). +static bool PschOtelSocketConnect(int fd, const struct sockaddr* sa, socklen_t slen, + int64 deadline_us) { + int flags = fcntl(fd, F_GETFL, 0); + if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) + return false; + + bool ok = false; + int save_errno = 0; + if (connect(fd, sa, slen) == 0) { + ok = true; + } else if (errno == EINPROGRESS) { + for (;;) { + if (ProcDiePending) { + save_errno = ECANCELED; + break; + } + const int64 remaining_us = deadline_us - PschMonotonicNowUs(); + if (remaining_us <= 0) { + save_errno = ETIMEDOUT; + break; + } + struct pollfd pfd = {.fd = fd, .events = POLLOUT, .revents = 0}; + int pr = poll(&pfd, 1, (int)((remaining_us + 999) / 1000)); + if (pr < 0) { + if (errno == EINTR) + continue; // signal (e.g. bgworker latch); retry within deadline + save_errno = errno; + break; + } + if (pr == 0) { + save_errno = ETIMEDOUT; + break; + } + int soerr = 0; + socklen_t l = sizeof soerr; + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &soerr, &l) < 0) { + save_errno = errno; + break; + } + save_errno = soerr; + ok = soerr == 0; + break; + } + } else { + save_errno = errno; + } + + if (fcntl(fd, F_SETFL, flags) < 0) + return false; + if (!ok) + errno = save_errno; + return ok; +} + +static bool PschOtelTcpConnect(PschOtelExporter* exp, int64 deadline_us, char* errbuf, + size_t errlen) { + struct addrinfo hints = {0}; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + char port_s[16]; + snprintf(port_s, sizeof port_s, "%d", exp->port); + + struct addrinfo* res = NULL; + int rc = getaddrinfo(exp->host, port_s, &hints, &res); + if (rc != 0) { + snprintf(errbuf, errlen, "getaddrinfo(%s:%d): %s", exp->host, exp->port, gai_strerror(rc)); + return false; + } + + int fd = -1; + int save_errno = ECONNREFUSED; + for (struct addrinfo* ai = res; ai != NULL; ai = ai->ai_next) { + if (ProcDiePending) { + save_errno = ECANCELED; + break; + } + fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (fd < 0) { + save_errno = errno; + continue; + } + if (PschOtelSocketConnect(fd, ai->ai_addr, ai->ai_addrlen, deadline_us)) + break; + save_errno = errno; + close(fd); + fd = -1; + } + freeaddrinfo(res); + if (fd < 0) { + snprintf(errbuf, errlen, "connect(%s:%d): %s", exp->host, exp->port, strerror(save_errno)); + return false; + } + + const int one = 1; + (void)setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof one); + (void)setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); +#ifdef SO_NOSIGPIPE + (void)setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof one); +#endif + const int timeout_ms = PschOtelTimeoutMs(); + struct timeval tv = {timeout_ms / 1000, (timeout_ms % 1000) * 1000}; + (void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv); + (void)setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv); + exp->fd = fd; + return true; +} + +static bool PschOtelTlsHandshake(PschOtelExporter* exp, int64 deadline_us, char* errbuf, + size_t errlen) { + exp->ssl = SSL_new(exp->ssl_ctx); + if (exp->ssl == NULL) { + PschOtelFormatSslError(errbuf, errlen, "SSL_new failed"); + return false; + } + if (SSL_set_tlsext_host_name(exp->ssl, exp->host) != 1) { // SNI + snprintf(errbuf, errlen, "could not set TLS SNI host name"); + return false; + } + SSL_set_hostflags(exp->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); + if (SSL_set1_host(exp->ssl, exp->host) != 1) { + snprintf(errbuf, errlen, "could not set TLS verification host"); + return false; + } + if (SSL_set_fd(exp->ssl, exp->fd) != 1) { + snprintf(errbuf, errlen, "SSL_set_fd failed"); + return false; + } + ERR_clear_error(); // queue is per-thread, drop residue from a prior retry + for (;;) { + if (ProcDiePending) { + snprintf(errbuf, errlen, "terminating (SIGTERM)"); + return false; + } + if (PschMonotonicNowUs() >= deadline_us) { + snprintf(errbuf, errlen, "TLS handshake timeout"); + return false; + } + int rc = SSL_connect(exp->ssl); + if (rc == 1) + return true; + int serr = SSL_get_error(exp->ssl, rc); + if (serr == SSL_ERROR_WANT_READ || serr == SSL_ERROR_WANT_WRITE) + continue; + if (serr == SSL_ERROR_SYSCALL && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) + continue; + // cert-verify failures leave the OpenSSL error queue empty, so check vr first + const long vr = SSL_get_verify_result(exp->ssl); + if (vr != X509_V_OK) { + snprintf(errbuf, errlen, "TLS handshake failed: certificate verify failed: %s", + X509_verify_cert_error_string(vr)); + } else { + PschOtelFormatSslError(errbuf, errlen, "TLS handshake failed"); + } + return false; + } +} + +static bool PschOtelEstablish(PschOtelExporter* exp, int64 deadline_us, char* errbuf, + size_t errlen) { + PschOtelCloseConn(exp); + if (!PschOtelTcpConnect(exp, deadline_us, errbuf, errlen)) + return false; + if (exp->use_tls && !PschOtelTlsHandshake(exp, deadline_us, errbuf, errlen)) { + PschOtelCloseConn(exp); + return false; + } + exp->connected = true; + exp->conn_reused = false; + elog(DEBUG1, "pg_stat_ch: connected to OTLP endpoint %s:%d%s", exp->host, exp->port, + exp->use_tls ? " (TLS)" : ""); + return true; +} + +// --------------------------------------------------------------------------- +// Bounded blocking I/O +// --------------------------------------------------------------------------- + +static bool PschOtelSendAll(PschOtelExporter* exp, const void* data, size_t len, int64 deadline_us, + char* errbuf, size_t errlen) { + const uint8* p = data; + size_t left = len; + while (left > 0) { + if (ProcDiePending) { + snprintf(errbuf, errlen, "terminating (SIGTERM)"); + return false; + } + if (PschMonotonicNowUs() >= deadline_us) { + snprintf(errbuf, errlen, "send timeout (%d ms)", PschOtelTimeoutMs()); + return false; + } + ssize_t n; + if (exp->ssl != NULL) { + n = SSL_write(exp->ssl, p, (int)Min(left, (size_t)INT_MAX)); + if (n <= 0) { + int serr = SSL_get_error(exp->ssl, (int)n); + if (serr == SSL_ERROR_WANT_READ || serr == SSL_ERROR_WANT_WRITE) + continue; + if (serr == SSL_ERROR_SYSCALL && + (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) + continue; + PschOtelFormatSslError(errbuf, errlen, "TLS send failed"); + return false; + } + } else { +#ifdef MSG_NOSIGNAL + n = send(exp->fd, p, left, MSG_NOSIGNAL); +#else + n = send(exp->fd, p, left, 0); +#endif + if (n < 0) { + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + continue; + snprintf(errbuf, errlen, "send failed: %s", strerror(errno)); + return false; + } + } + p += n; + left -= (size_t)n; + } + return true; +} + +// Returns >0 bytes read, 0 on EOF, -1 on error/timeout (errbuf filled). +static int PschOtelRecvSome(PschOtelExporter* exp, uint8* buf, size_t cap, int64 deadline_us, + char* errbuf, size_t errlen) { + for (;;) { + if (ProcDiePending) { + snprintf(errbuf, errlen, "terminating (SIGTERM)"); + return -1; + } + if (PschMonotonicNowUs() >= deadline_us) { + snprintf(errbuf, errlen, "response timeout (%d ms)", PschOtelTimeoutMs()); + return -1; + } + if (exp->ssl != NULL) { + int n = SSL_read(exp->ssl, buf, (int)Min(cap, (size_t)INT_MAX)); + if (n > 0) + return n; + int serr = SSL_get_error(exp->ssl, n); + if (serr == SSL_ERROR_ZERO_RETURN) + return 0; + if (serr == SSL_ERROR_WANT_READ || serr == SSL_ERROR_WANT_WRITE) + continue; + if (serr == SSL_ERROR_SYSCALL) { + if (n == 0 || errno == 0) + return 0; // unclean close + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + continue; + snprintf(errbuf, errlen, "TLS recv failed: %s", strerror(errno)); + return -1; + } + PschOtelFormatSslError(errbuf, errlen, "TLS recv failed"); + return -1; + } + ssize_t n = recv(exp->fd, buf, Min(cap, (size_t)INT_MAX), 0); + if (n > 0) + return (int)n; + if (n == 0) + return 0; + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + continue; + snprintf(errbuf, errlen, "recv failed: %s", strerror(errno)); + return -1; + } +} + +// Consume exactly n more body bytes, discarding them (body larger than the +// net buffer). False means the connection can no longer be reused. +static bool PschOtelDrainN(PschOtelExporter* exp, size_t n, int64 deadline_us) { + char ebuf[64]; + while (n > 0) { + int got = + PschOtelRecvSome(exp, exp->net_buf, Min(n, exp->net_cap), deadline_us, ebuf, sizeof ebuf); + if (got <= 0) + return false; + n -= (size_t)got; + } + return true; +} + +static void PschOtelDrainToEof(PschOtelExporter* exp, int64 deadline_us) { + char ebuf[64]; + for (;;) { + int got = PschOtelRecvSome(exp, exp->net_buf, exp->net_cap, deadline_us, ebuf, sizeof ebuf); + if (got <= 0) + return; + } +} + +// --------------------------------------------------------------------------- +// HTTP request / response +// --------------------------------------------------------------------------- + +static bool PschOtelSendRequest(PschOtelExporter* exp, const uint8* body, size_t body_len, + int64 deadline_us, char* errbuf, size_t errlen) { + // Assemble the head in net_buf (free until the response is read). + char* head = (char*)exp->net_buf; + memcpy(head, exp->head_prefix, exp->head_prefix_len); + int n = snprintf(head + exp->head_prefix_len, exp->net_cap - exp->head_prefix_len, "%zu\r\n\r\n", + body_len); + if (n < 0 || (size_t)n >= exp->net_cap - exp->head_prefix_len) { + snprintf(errbuf, errlen, "request head does not fit network buffer"); + return false; + } + if (!PschOtelSendAll(exp, head, exp->head_prefix_len + (size_t)n, deadline_us, errbuf, errlen)) + return false; + return PschOtelSendAll(exp, body, body_len, deadline_us, errbuf, errlen); +} + +// Reads status line + headers + body into net_buf. Returns false only for +// transport-level failures (caller treats as send failure / stale retry); +// HTTP error statuses return true with r->status set. *got_any reports +// whether any response byte arrived (gates the silent stale-retry). +static bool PschOtelReadResponse(PschOtelExporter* exp, int64 deadline_us, PschHttpResponse* r, + bool* got_any, char* errbuf, size_t errlen) { + uint8* buf = exp->net_buf; + const size_t cap = exp->net_cap; + size_t have = 0; + size_t header_end = 0; + size_t scanned = 0; + + memset(r, 0, sizeof *r); + r->retry_after_s = -1; + *got_any = false; + + for (;;) { + while (scanned + 4 <= have) { + if (memcmp(buf + scanned, "\r\n\r\n", 4) == 0) { + header_end = scanned + 4; + break; + } + scanned++; + } + if (header_end != 0) + break; + if (have == cap) { + snprintf(errbuf, errlen, "response headers exceed %zu bytes", cap); + return false; + } + int n = PschOtelRecvSome(exp, buf + have, cap - have, deadline_us, errbuf, errlen); + if (n < 0) + return false; + if (n == 0) { + snprintf(errbuf, errlen, + have == 0 ? "connection closed before response" : "connection closed mid-headers"); + return false; + } + have += (size_t)n; + *got_any = true; + } + + if (have < 12 || memcmp(buf, "HTTP/1.", 7) != 0) { + snprintf(errbuf, errlen, "malformed HTTP status line"); + return false; + } + r->reusable = buf[7] == '1'; // HTTP/1.1 defaults to keep-alive + + const uint8* sp = memchr(buf, ' ', header_end); + long status = + sp != NULL ? PschParseDigits((const char*)sp + 1, header_end - (size_t)(sp + 1 - buf)) : -1; + if (status < 100 || status > 999) { + snprintf(errbuf, errlen, "malformed HTTP status line"); + return false; + } + r->status = (int)status; + + size_t pos = 0; + while (pos + 2 <= header_end && !(buf[pos] == '\r' && buf[pos + 1] == '\n')) + pos++; + pos += 2; // first header line + + long content_length = -1; + bool chunked = false; + while (pos + 2 <= header_end) { + size_t eol = pos; + while (eol + 1 < header_end && !(buf[eol] == '\r' && buf[eol + 1] == '\n')) + eol++; + size_t llen = eol - pos; + if (llen == 0) + break; // blank line terminates headers + const char* line = (const char*)buf + pos; + const char* colon = memchr(line, ':', llen); + if (colon != NULL) { + size_t nlen = (size_t)(colon - line); + const char* val = colon + 1; + size_t vlen = llen - nlen - 1; + while (vlen > 0 && (*val == ' ' || *val == '\t')) { + val++; + vlen--; + } + if (nlen == 14 && pg_strncasecmp(line, "Content-Length", 14) == 0) { + content_length = PschParseDigits(val, vlen); + } else if (nlen == 17 && pg_strncasecmp(line, "Transfer-Encoding", 17) == 0) { + chunked |= PschValueContains(val, vlen, "chunked"); + } else if (nlen == 11 && pg_strncasecmp(line, "Retry-After", 11) == 0) { + r->retry_after_s = PschParseDigits(val, vlen); + } else if (nlen == 10 && pg_strncasecmp(line, "Connection", 10) == 0) { + if (PschValueContains(val, vlen, "close")) + r->reusable = false; + else if (PschValueContains(val, vlen, "keep-alive")) + r->reusable = true; + } + } + pos = eol + 2; + } + + size_t body_have = have - header_end; + + if (chunked) { + // We do not parse chunked framing; the connection cannot be reused. + r->reusable = false; + r->body_complete = false; + PschOtelDrainToEof(exp, deadline_us); + return true; + } + + if (content_length < 0) { + // No length: body is delimited by connection close. + r->reusable = false; + bool eof = false; + while (have < cap) { + int n = PschOtelRecvSome(exp, buf + have, cap - have, deadline_us, errbuf, errlen); + if (n < 0) { + r->body_complete = false; + return true; // status is known; give up on the body + } + if (n == 0) { + eof = true; + break; + } + have += (size_t)n; + } + if (eof) { + r->body = buf + header_end; + r->body_len = have - header_end; + r->body_complete = true; + } else { + PschOtelDrainToEof(exp, deadline_us); + r->body_complete = false; + } + return true; + } + + if ((size_t)content_length <= cap - header_end) { + while (body_have < (size_t)content_length) { + int n = PschOtelRecvSome(exp, buf + have, cap - have, deadline_us, errbuf, errlen); + if (n <= 0) { + r->reusable = false; + r->body_complete = false; + // A 200 status already arrived: the export succeeded server-side, so + // do not fail the call (a resend would duplicate the whole batch). + if (r->status == 200) + return true; + snprintf(errbuf, errlen, "connection closed mid-response body (HTTP %d)", r->status); + return false; + } + have += (size_t)n; + body_have += (size_t)n; + } + r->body = buf + header_end; + r->body_len = (size_t)content_length; + r->body_complete = true; + } else { + if (!PschOtelDrainN(exp, (size_t)content_length - body_have, deadline_us)) + r->reusable = false; + r->body_complete = false; + } + return true; +} + +static PschExportStatus PschOtelHandleResponse(const PschHttpResponse* r, char* errbuf, + size_t errlen) { + if (r->status == 200) { + if (r->body_complete && r->body_len > 0) { + int64 rejected = 0; + char msg[256] = ""; + if (PschOtlpParseLogsResponse(r->body, r->body_len, &rejected, msg, sizeof msg)) { + // Spec: partial success is NOT retried; rejected records are dropped. + if (rejected > 0) { + elog(WARNING, "pg_stat_ch: OTLP partial success: %lld log records rejected: %s", + (long long)rejected, msg[0] != '\0' ? msg : "(no message)"); + } else if (msg[0] != '\0') { + elog(LOG, "pg_stat_ch: OTLP export warning from collector: %s", msg); + } + } + } else if (!r->body_complete) { + elog(WARNING, + "pg_stat_ch: OTLP response body unparseable (chunked or oversized); " + "treating export as success"); + } + return PSCH_EXPORT_OK; + } + + if (r->status == 429 || r->status == 502 || r->status == 503 || r->status == 504) { + if (r->retry_after_s >= 0) + snprintf(errbuf, errlen, "collector returned HTTP %d (Retry-After: %ld s)", r->status, + r->retry_after_s); + else + snprintf(errbuf, errlen, "collector returned HTTP %d", r->status); + return PSCH_EXPORT_ERR_SEND; + } + + // Non-retryable per OTLP spec: permanent failure for this batch. + int32 code = 0; + char msg[256] = ""; + if (r->body_complete && r->body_len > 0 && + PschRpcStatusParse(r->body, r->body_len, &code, msg, sizeof msg) && msg[0] != '\0') { + snprintf(errbuf, errlen, "collector rejected request: HTTP %d, rpc status %d: %s", r->status, + (int)code, msg); + } else { + snprintf(errbuf, errlen, "collector rejected request: HTTP %d", r->status); + } + return PSCH_EXPORT_ERR_INTERNAL; +} + +// One deadline-bounded POST of `body`, including connect-if-needed and one +// silent reconnect when a kept-alive connection turns out stale (failure +// before any response byte on a connection that already served a request). +static PschExportStatus PschOtelDoRequest(PschOtelExporter* exp, const uint8* body, size_t body_len, + char* errbuf, size_t errlen) { + const int64 deadline_us = PschMonotonicNowUs() + (int64)PschOtelTimeoutMs() * 1000; + bool retried = false; + + for (;;) { + if (!exp->connected && !PschOtelEstablish(exp, deadline_us, errbuf, errlen)) + return PSCH_EXPORT_ERR_CONN; + + const bool reusing = exp->conn_reused; + exp->in_flight = true; + bool got_any = false; + PschHttpResponse resp; + bool ok = PschOtelSendRequest(exp, body, body_len, deadline_us, errbuf, errlen) && + PschOtelReadResponse(exp, deadline_us, &resp, &got_any, errbuf, errlen); + exp->in_flight = false; + + if (!ok) { + PschOtelCloseConn(exp); + if (reusing && !got_any && !retried && !ProcDiePending && + PschMonotonicNowUs() < deadline_us) { + retried = true; // stale keep-alive connection: one silent reconnect + continue; + } + return PSCH_EXPORT_ERR_SEND; + } + + exp->conn_reused = true; + if (!resp.reusable) + PschOtelCloseConn(exp); + return PschOtelHandleResponse(&resp, errbuf, errlen); + } +} + +// --------------------------------------------------------------------------- +// OTLP payload encoding (opentelemetry-proto v1.9.0 surface) +// --------------------------------------------------------------------------- + +// Opens ResourceLogs + Resource(+attrs) + ScopeLogs + scope; leaves the +// ResourceLogs and ScopeLogs length slots open for LogRecords. +static void PschOtelEnvelopeBegin(PschPbBuf* b, const PschOtelExporter* exp, bool arrow_ipc, + size_t* rl_slot, size_t* sl_slot) { + *rl_slot = PschPbMsgBegin(b, PSCH_OTLP_REQ_RESOURCE_LOGS); + size_t res = PschPbMsgBegin(b, PSCH_OTLP_RL_RESOURCE); + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "service.name", kServiceName, strlen(kServiceName)); + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "service.version", PG_STAT_CH_VERSION, + strlen(PG_STAT_CH_VERSION)); + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "host.name", exp->hostname, strlen(exp->hostname)); + if (arrow_ipc) + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "pg_stat_ch.block_format", "arrow_ipc", 9); + PschPbMsgEnd(b, res); + + *sl_slot = PschPbMsgBegin(b, PSCH_OTLP_RL_SCOPE_LOGS); + size_t scope = PschPbMsgBegin(b, PSCH_OTLP_SL_SCOPE); + PschPbString(b, PSCH_OTLP_SCOPE_NAME, kServiceName, strlen(kServiceName)); + PschPbString(b, PSCH_OTLP_SCOPE_VERSION, PG_STAT_CH_VERSION, strlen(PG_STAT_CH_VERSION)); + PschPbMsgEnd(b, scope); +} + +static void PschOtelEnvelopeEnd(PschPbBuf* b, size_t rl_slot, size_t sl_slot) { + PschPbMsgEnd(b, sl_slot); + PschPbMsgEnd(b, rl_slot); +} + +// Zero-valued int attrs are skipped (sparse encoding quirk of the original). +static inline void PschKvIntNz(PschPbBuf* b, const char* key, int64 v) { + if (v != 0) + PschPbKvInt(b, PSCH_OTLP_LR_ATTRIBUTES, key, v); +} + +static void PschOtelEncodeEvent(PschPbBuf* b, const PschEvent* ev) { + const uint32 attr = PSCH_OTLP_LR_ATTRIBUTES; + size_t rec = PschPbMsgBegin(b, PSCH_OTLP_SL_LOG_RECORDS); + + const int64 ts_unix_us = ev->ts_start + kPostgresEpochOffsetUs; + PschPbFixed64(b, PSCH_OTLP_LR_TIME_UNIX_NANO, (uint64)ts_unix_us * 1000); + PschPbKvInt(b, attr, "ts_start", ts_unix_us); + + PschPbKvDouble(b, attr, "db.client.operation.duration", (double)ev->duration_us / 1e6); + PschPbKvInt(b, attr, "duration_us", (int64)ev->duration_us); + + // Clamp to sizeof-1 (63), matching the Arrow and ClickHouse paths: emitting + // the full 64-byte buffer could surface a trailing non-NUL byte on a corrupt + // event and diverges from the NAMEDATALEN-1 contract. + PschPbKvString(b, attr, "db.name", ev->datname, + Min(ev->datname_len, (uint8)(sizeof(ev->datname) - 1))); + PschPbKvString(b, attr, "db.user", ev->username, + Min(ev->username_len, (uint8)(sizeof(ev->username) - 1))); + PschKvIntNz(b, "pid", ev->pid); + PschKvIntNz(b, "query_id", (int64)ev->queryid); + { + const char* cmd = PschCmdTypeToString(ev->cmd_type); + PschPbKvString(b, attr, "db.operation.name", cmd, strlen(cmd)); + } + PschKvIntNz(b, "rows", (int64)ev->rows); + PschPbKvString(b, attr, "db.query.text", ev->query, + PschClampLen(ev->query_len, PSCH_MAX_QUERY_LEN, "query_len")); + + PschKvIntNz(b, "shared_blks_hit", ev->shared_blks_hit); + PschKvIntNz(b, "shared_blks_read", ev->shared_blks_read); + PschKvIntNz(b, "shared_blks_dirtied", ev->shared_blks_dirtied); + PschKvIntNz(b, "shared_blks_written", ev->shared_blks_written); + PschKvIntNz(b, "local_blks_hit", ev->local_blks_hit); + PschKvIntNz(b, "local_blks_read", ev->local_blks_read); + PschKvIntNz(b, "local_blks_dirtied", ev->local_blks_dirtied); + PschKvIntNz(b, "local_blks_written", ev->local_blks_written); + PschKvIntNz(b, "temp_blks_read", ev->temp_blks_read); + PschKvIntNz(b, "temp_blks_written", ev->temp_blks_written); + + PschKvIntNz(b, "shared_blk_read_time_us", ev->shared_blk_read_time_us); + PschKvIntNz(b, "shared_blk_write_time_us", ev->shared_blk_write_time_us); + PschKvIntNz(b, "local_blk_read_time_us", ev->local_blk_read_time_us); + PschKvIntNz(b, "local_blk_write_time_us", ev->local_blk_write_time_us); + PschKvIntNz(b, "temp_blk_read_time_us", ev->temp_blk_read_time_us); + PschKvIntNz(b, "temp_blk_write_time_us", ev->temp_blk_write_time_us); + + PschKvIntNz(b, "wal_records", ev->wal_records); + PschKvIntNz(b, "wal_fpi", ev->wal_fpi); + PschKvIntNz(b, "wal_bytes", (int64)ev->wal_bytes); + + PschKvIntNz(b, "cpu_user_time_us", ev->cpu_user_time_us); + PschKvIntNz(b, "cpu_sys_time_us", ev->cpu_sys_time_us); + + PschKvIntNz(b, "jit_functions", ev->jit_functions); + PschKvIntNz(b, "jit_generation_time_us", ev->jit_generation_time_us); + PschKvIntNz(b, "jit_deform_time_us", ev->jit_deform_time_us); + PschKvIntNz(b, "jit_inlining_time_us", ev->jit_inlining_time_us); + PschKvIntNz(b, "jit_optimization_time_us", ev->jit_optimization_time_us); + PschKvIntNz(b, "jit_emission_time_us", ev->jit_emission_time_us); + + PschKvIntNz(b, "parallel_workers_planned", ev->parallel_workers_planned); + PschKvIntNz(b, "parallel_workers_launched", ev->parallel_workers_launched); + + // Always exactly 5 bytes, embedded NULs included (collector-side contract). + PschPbKvString(b, attr, "err_sqlstate", ev->err_sqlstate, 5); + PschKvIntNz(b, "err_elevel", ev->err_elevel); + PschPbKvString(b, attr, "err_message", ev->err_message, + PschClampLen(ev->err_message_len, PSCH_MAX_ERR_MSG_LEN, "err_message_len")); + + PschPbKvString(b, attr, "app", ev->application_name, + PschClampLen(ev->application_name_len, PSCH_MAX_APP_NAME_LEN, "app_name_len")); + PschPbKvString(b, attr, "client_addr", ev->client_addr, + PschClampLen(ev->client_addr_len, PSCH_MAX_CLIENT_ADDR_LEN, "client_addr_len")); + + PschPbMsgEnd(b, rec); +} + +static void PschOtelEncodeArrowRecord(PschPbBuf* b, const uint8* ipc_data, size_t ipc_len, + int num_rows) { + size_t rec = PschPbMsgBegin(b, PSCH_OTLP_SL_LOG_RECORDS); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + const uint64 now_ns = (uint64)ts.tv_sec * 1000000000 + (uint64)ts.tv_nsec; + PschPbFixed64(b, PSCH_OTLP_LR_TIME_UNIX_NANO, now_ns); + PschPbFixed64(b, PSCH_OTLP_LR_OBSERVED_TIME_UNIX_NANO, now_ns); + + size_t body = PschPbMsgBegin(b, PSCH_OTLP_LR_BODY); + PschPbBytes(b, PSCH_OTLP_ANY_BYTES, ipc_data, ipc_len); + PschPbMsgEnd(b, body); + + PschPbKvString(b, PSCH_OTLP_LR_ATTRIBUTES, "pg_stat_ch.block_format", "arrow_ipc", 9); + PschPbKvInt(b, PSCH_OTLP_LR_ATTRIBUTES, "pg_stat_ch.block_rows", num_rows); + + PschPbMsgEnd(b, rec); +} + +// --------------------------------------------------------------------------- +// PschExporterOps implementation +// --------------------------------------------------------------------------- + +static bool PschOtelOpConnect(PschExporter* self, char* errbuf, size_t errlen) { + PschOtelExporter* exp = (PschOtelExporter*)self; + char local_err[256]; + if (errbuf == NULL || errlen == 0) { + errbuf = local_err; + errlen = sizeof local_err; + } + errbuf[0] = '\0'; + + const int64 deadline_us = PschMonotonicNowUs() + (int64)PschOtelTimeoutMs() * 1000; + if (!PschOtelEstablish(exp, deadline_us, errbuf, errlen)) { + exp->consecutive_failures++; + return false; + } + return true; +} + +static bool PschOtelOpIsConnected(const PschExporter* self) { + return ((const PschOtelExporter*)self)->connected; +} + +static PschExportStatus PschOtelOpExportEvents(PschExporter* self, const PschEvent* events, + int nevents, int* exported_out) { + PschOtelExporter* exp = (PschOtelExporter*)self; + char errbuf[512]; + + if (exported_out != NULL) + *exported_out = 0; + if (events == NULL || nevents <= 0) + return PSCH_EXPORT_OK; + + // A longjmp interrupted the previous call mid-exchange: the HTTP state on + // that connection is poisoned, force a reconnect. + if (exp->in_flight) + PschOtelCloseConn(exp); + + int idx = 0; + while (idx < nevents) { + PschPbBuf b; + PschPbInit(&b, exp->encode_buf, exp->encode_cap); + size_t rl_slot; + size_t sl_slot; + PschOtelEnvelopeBegin(&b, exp, false, &rl_slot, &sl_slot); + + int in_chunk = 0; + while (idx < nevents) { + if (b.len + kEventEncodeMargin > b.cap) + break; // chunk full: send and continue + const size_t mark = b.len; + PschOtelEncodeEvent(&b, &events[idx]); + if (b.overflow) { + // Margin backstop: roll the partial record back and flush the chunk. + b.overflow = false; + b.len = mark; + break; + } + idx++; + in_chunk++; + } + PschOtelEnvelopeEnd(&b, rl_slot, sl_slot); + + if (in_chunk == 0 || b.overflow) { + PschOtelFail(exp, "OTLP export failed", "event record does not fit encode buffer"); + return PSCH_EXPORT_ERR_INTERNAL; + } + + PschExportStatus st = PschOtelDoRequest(exp, exp->encode_buf, b.len, errbuf, sizeof errbuf); + if (st != PSCH_EXPORT_OK) { + // All-or-nothing: earlier chunks of this call may already be at the + // collector, but the caller sees 0 exported and decides consume/requeue. + PschOtelFail(exp, "OTLP export failed", errbuf); + return st; + } + } + + if (exported_out != NULL) + *exported_out = nevents; + exp->consecutive_failures = 0; + return PSCH_EXPORT_OK; +} + +static PschExportStatus PschOtelOpSendArrow(PschExporter* self, const uint8* ipc_data, + size_t ipc_len, int num_rows) { + PschOtelExporter* exp = (PschOtelExporter*)self; + char errbuf[512]; + + if (exp->in_flight) + PschOtelCloseConn(exp); + + if (ipc_data == NULL || ipc_len == 0 || num_rows <= 0) { + PschOtelFail(exp, "OTLP Arrow export failed", "invalid Arrow IPC payload"); + return PSCH_EXPORT_ERR_INTERNAL; + } + + PschPbBuf b; + PschPbInit(&b, exp->encode_buf, exp->encode_cap); + size_t rl_slot; + size_t sl_slot; + PschOtelEnvelopeBegin(&b, exp, true, &rl_slot, &sl_slot); + PschOtelEncodeArrowRecord(&b, ipc_data, ipc_len, num_rows); + PschOtelEnvelopeEnd(&b, rl_slot, sl_slot); + if (b.overflow) { + snprintf(errbuf, sizeof errbuf, "Arrow IPC payload (%zu bytes) exceeds encode buffer (%zu)", + ipc_len, exp->encode_cap); + PschOtelFail(exp, "OTLP Arrow export failed", errbuf); + return PSCH_EXPORT_ERR_INTERNAL; + } + + PschExportStatus st = PschOtelDoRequest(exp, exp->encode_buf, b.len, errbuf, sizeof errbuf); + if (st != PSCH_EXPORT_OK) { + PschOtelFail(exp, "OTLP Arrow export failed", errbuf); + return st; + } + + exp->consecutive_failures = 0; + return PSCH_EXPORT_OK; +} + +static int PschOtelOpConsecutiveFailures(const PschExporter* self) { + return ((const PschOtelExporter*)self)->consecutive_failures; +} + +static void PschOtelOpResetFailures(PschExporter* self) { + ((PschOtelExporter*)self)->consecutive_failures = 0; +} + +static uint64 PschOtelOpMemUsed(const PschExporter* self) { + return ((const PschOtelExporter*)self)->mem_used; +} + +static void PschOtelOpDestroy(PschExporter* self) { + if (self == NULL) + return; + PschOtelExporter* exp = (PschOtelExporter*)self; + PschOtelCloseConn(exp); + if (exp->ssl_ctx != NULL) { + SSL_CTX_free(exp->ssl_ctx); + exp->ssl_ctx = NULL; + } + if (exp->head_prefix != NULL) + pfree(exp->head_prefix); + if (exp->encode_buf != NULL) + pfree(exp->encode_buf); + if (exp->net_buf != NULL) + pfree(exp->net_buf); + pfree(exp); +} + +static const PschExporterOps kOtelExporterOps = { + .connect = PschOtelOpConnect, + .is_connected = PschOtelOpIsConnected, + .export_events = PschOtelOpExportEvents, + .send_arrow = PschOtelOpSendArrow, + .consecutive_failures = PschOtelOpConsecutiveFailures, + .reset_failures = PschOtelOpResetFailures, + .mem_used = PschOtelOpMemUsed, + .destroy = PschOtelOpDestroy, +}; + +// --------------------------------------------------------------------------- +// Creation (the only place allocation is allowed) +// --------------------------------------------------------------------------- + +// URL semantics per include/config/guc.h: scheme decides TLS; bare host:port +// is http; missing path means /v1/logs. Missing port: scheme default when a +// scheme was given (80/443), conventional OTLP/HTTP port 4318 otherwise. +static bool PschOtelParseEndpoint(const char* raw, PschOtelExporter* exp, char* errbuf, + size_t errlen) { + const char* p = (raw != NULL && raw[0] != '\0') ? raw : kDefaultEndpoint; + const char* display = p; + bool tls = false; + bool have_scheme = false; + + if (pg_strncasecmp(p, "http://", 7) == 0) { + p += 7; + have_scheme = true; + } else if (pg_strncasecmp(p, "https://", 8) == 0) { + p += 8; + tls = true; + have_scheme = true; + } else if (strstr(p, "://") != NULL) { + snprintf(errbuf, errlen, "unsupported scheme in otel_endpoint \"%s\" (use http:// or https://)", + display); + return false; + } + + const char* host_start; + const char* host_end; + if (*p == '[') { // IPv6 literal + host_start = p + 1; + const char* close_br = strchr(host_start, ']'); + if (close_br == NULL) { + snprintf(errbuf, errlen, "malformed IPv6 host in otel_endpoint \"%s\"", display); + return false; + } + host_end = close_br; + p = close_br + 1; + } else { + host_start = p; + while (*p != '\0' && *p != ':' && *p != '/') + p++; + host_end = p; + } + if (host_end == host_start) { + snprintf(errbuf, errlen, "missing host in otel_endpoint \"%s\"", display); + return false; + } + size_t hlen = (size_t)(host_end - host_start); + if (hlen >= sizeof(exp->host)) { + snprintf(errbuf, errlen, "host too long in otel_endpoint \"%s\"", display); + return false; + } + memcpy(exp->host, host_start, hlen); + exp->host[hlen] = '\0'; + + int port = -1; + if (*p == ':') { + p++; + port = 0; + bool any = false; + while (*p >= '0' && *p <= '9' && port <= 65535) { + port = port * 10 + (*p - '0'); + p++; + any = true; + } + if (!any || port < 1 || port > 65535) { + snprintf(errbuf, errlen, "invalid port in otel_endpoint \"%s\"", display); + return false; + } + } + if (*p != '\0' && *p != '/') { + snprintf(errbuf, errlen, "malformed otel_endpoint \"%s\"", display); + return false; + } + if (port < 0) + port = have_scheme ? (tls ? 443 : 80) : 4318; + + if (*p == '\0' || strcmp(p, "/") == 0) { + strlcpy(exp->path, kDefaultPath, sizeof(exp->path)); + } else { + if (strlen(p) >= sizeof(exp->path)) { + snprintf(errbuf, errlen, "path too long in otel_endpoint \"%s\"", display); + return false; + } + strlcpy(exp->path, p, sizeof(exp->path)); + } + + exp->use_tls = tls; + exp->port = port; + return true; +} + +static void PschOtelResolveHostname(char* out, size_t outlen) { + if (psch_hostname != NULL && psch_hostname[0] != '\0') { + strlcpy(out, psch_hostname, outlen); + return; + } + const char* env = getenv("HOSTNAME"); + if (env != NULL && env[0] != '\0') { + strlcpy(out, env, outlen); + return; + } + if (gethostname(out, outlen) == 0) { + out[outlen - 1] = '\0'; + if (out[0] != '\0') + return; + } + strlcpy(out, "postgres-primary", outlen); +} + +static bool PschHeaderNameReserved(const char* name, size_t len) { + static const char* const kReserved[] = {"host", "content-length", "content-type", + "connection", "transfer-encoding", "content-encoding"}; + for (size_t i = 0; i < lengthof(kReserved); i++) { + if (strlen(kReserved[i]) == len && pg_strncasecmp(name, kReserved[i], len) == 0) + return true; + } + return false; +} + +// psch_otel_headers: newline-separated "Name: value" lines. Returns a +// palloc'd "Name: value\r\n..." block ("" when none), NULL on alloc failure. +static char* PschOtelBuildHeaderBlock(const char* raw, char* errbuf, size_t errlen) { + if (raw == NULL) + raw = ""; + Size cap = strlen(raw) + 3; + for (const char* q = raw; *q != '\0'; q++) { + if (*q == '\n') + cap += 2; + } + char* out = PschOtelAlloc(cap); + if (out == NULL) { + snprintf(errbuf, errlen, "out of memory parsing otel_headers"); + return NULL; + } + + size_t olen = 0; + const char* p = raw; + while (*p != '\0') { + const char* nl = strchr(p, '\n'); + const char* line = p; + size_t llen = nl != NULL ? (size_t)(nl - p) : strlen(p); + p = nl != NULL ? nl + 1 : p + llen; + + while (llen > 0 && (line[0] == ' ' || line[0] == '\t')) { + line++; + llen--; + } + while (llen > 0 && (line[llen - 1] == '\r' || line[llen - 1] == ' ' || line[llen - 1] == '\t')) + llen--; + if (llen == 0) + continue; + + // Reject embedded control characters (CR, NUL, other C0 except TAB). A + // mid-line CR would otherwise smuggle a second header into the request + // head (header injection); only the trailing CR was stripped above. + bool ctl = false; + for (size_t i = 0; i < llen; i++) { + unsigned char c = (unsigned char)line[i]; + if (c < 0x20 && c != '\t') { + ctl = true; + break; + } + } + if (ctl) { + elog(WARNING, "pg_stat_ch: ignoring otel_headers entry containing a control character"); + continue; + } + + const char* colon = memchr(line, ':', llen); + if (colon == NULL || colon == line) { + elog(WARNING, "pg_stat_ch: ignoring malformed otel_headers entry (expected \"Name: value\")"); + continue; + } + size_t nlen = (size_t)(colon - line); + while (nlen > 0 && (line[nlen - 1] == ' ' || line[nlen - 1] == '\t')) + nlen--; + if (PschHeaderNameReserved(line, nlen)) { + elog(WARNING, "pg_stat_ch: ignoring otel_headers entry overriding a reserved HTTP header"); + continue; + } + + memcpy(out + olen, line, llen); + olen += llen; + out[olen++] = '\r'; + out[olen++] = '\n'; + } + out[olen] = '\0'; + return out; +} + +static bool PschOtelBuildHead(PschOtelExporter* exp, char* errbuf, size_t errlen) { + char host_hdr[300]; + const bool v6 = strchr(exp->host, ':') != NULL; + const bool default_port = + (exp->use_tls && exp->port == 443) || (!exp->use_tls && exp->port == 80); + if (v6 && default_port) + snprintf(host_hdr, sizeof host_hdr, "[%s]", exp->host); + else if (v6) + snprintf(host_hdr, sizeof host_hdr, "[%s]:%d", exp->host, exp->port); + else if (default_port) + snprintf(host_hdr, sizeof host_hdr, "%s", exp->host); + else + snprintf(host_hdr, sizeof host_hdr, "%s:%d", exp->host, exp->port); + + char* hdr_block = PschOtelBuildHeaderBlock(psch_otel_headers, errbuf, errlen); + if (hdr_block == NULL) + return false; + + Size need = + strlen(exp->path) + strlen(host_hdr) + strlen(hdr_block) + strlen(PG_STAT_CH_VERSION) + 128; + exp->head_prefix = PschOtelAlloc(need); + if (exp->head_prefix == NULL) { + pfree(hdr_block); + snprintf(errbuf, errlen, "out of memory building HTTP request head"); + return false; + } + int n = snprintf(exp->head_prefix, need, + "POST %s HTTP/1.1\r\n" + "Host: %s\r\n" + "User-Agent: pg_stat_ch/%s\r\n" + "Content-Type: application/x-protobuf\r\n" + "Connection: keep-alive\r\n" + "%s" + "Content-Length: ", + exp->path, host_hdr, PG_STAT_CH_VERSION, hdr_block); + pfree(hdr_block); + if (n < 0 || (Size)n >= need) { + snprintf(errbuf, errlen, "HTTP request head too large"); + return false; + } + exp->head_prefix_len = (size_t)n; + exp->head_alloc_bytes = need; + return true; +} + +static bool PschOtelInitSslCtx(PschOtelExporter* exp, char* errbuf, size_t errlen) { + // OpenSSL 1.1.0+ auto-initializes on first use; no explicit library init. + exp->ssl_ctx = SSL_CTX_new(TLS_client_method()); + if (exp->ssl_ctx == NULL) { + PschOtelFormatSslError(errbuf, errlen, "SSL_CTX_new failed"); + return false; + } + SSL_CTX_set_verify(exp->ssl_ctx, SSL_VERIFY_PEER, NULL); + SSL_CTX_set_mode(exp->ssl_ctx, + SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); + if (psch_otel_ca_file != NULL && psch_otel_ca_file[0] != '\0') { + if (SSL_CTX_load_verify_locations(exp->ssl_ctx, psch_otel_ca_file, NULL) != 1) { + snprintf(errbuf, errlen, "could not load CA bundle \"%s\"", psch_otel_ca_file); + return false; + } + } else if (SSL_CTX_set_default_verify_paths(exp->ssl_ctx) != 1) { + snprintf(errbuf, errlen, "could not load default CA certificates"); + return false; + } + return true; +} + +PschExporter* PschOtelExporterCreate(char* errbuf, size_t errlen) { + char local_err[256]; + if (errbuf == NULL || errlen == 0) { + errbuf = local_err; + errlen = sizeof local_err; + } + errbuf[0] = '\0'; + + PschOtelExporter* exp = PschOtelAlloc(sizeof(PschOtelExporter)); + if (exp == NULL) { + snprintf(errbuf, errlen, "out of memory allocating OTel exporter state"); + return NULL; + } + exp->base.ops = &kOtelExporterOps; + exp->fd = -1; + + if (!PschOtelParseEndpoint(psch_otel_endpoint, exp, errbuf, errlen)) + goto fail; + PschOtelResolveHostname(exp->hostname, sizeof(exp->hostname)); + if (exp->use_tls && !PschOtelInitSslCtx(exp, errbuf, errlen)) + goto fail; + if (!PschOtelBuildHead(exp, errbuf, errlen)) + goto fail; + + { + PschExportArenaPlan plan; + PschExportArenaSplit(PschMemoryBudgetGet()->export_arena_bytes, &plan); + exp->encode_buf = PschOtelAlloc(plan.encode_buf_bytes); + exp->net_buf = PschOtelAlloc(plan.net_buf_bytes); + if (exp->encode_buf == NULL || exp->net_buf == NULL) { + snprintf(errbuf, errlen, "out of memory preallocating OTLP export buffers (%zu + %zu bytes)", + plan.encode_buf_bytes, plan.net_buf_bytes); + goto fail; + } + exp->encode_cap = plan.encode_buf_bytes; + exp->net_cap = plan.net_buf_bytes; + } + + if (exp->head_prefix_len + kContentLengthTailMax > exp->net_cap) { + snprintf(errbuf, errlen, "otel_headers too large (%zu bytes) for network buffer (%zu bytes)", + exp->head_prefix_len, exp->net_cap); + goto fail; + } + + exp->mem_used = + sizeof(*exp) + exp->head_alloc_bytes + (uint64)exp->encode_cap + (uint64)exp->net_cap; + return &exp->base; + +fail: + PschOtelOpDestroy(&exp->base); + return NULL; +} diff --git a/src/export/otel_exporter.cc b/src/export/otel_exporter.cc deleted file mode 100644 index ad9228e..0000000 --- a/src/export/otel_exporter.cc +++ /dev/null @@ -1,522 +0,0 @@ -// Direct-proto OTel exporter. -// -// Builds OTLP ExportLogsServiceRequest protobuf messages directly on a -// google::protobuf::Arena, bypassing the OTel SDK entirely. Our bgworker -// already owns batching and retry, so the SDK's pipelines are redundant. -// -// Arena allocation eliminates per-object malloc/free (the largest cost in the -// SDK path) and makes batch destruction O(1) via Arena::Reset(). - -#include -#include -#include -#include -#include -#include -#include - -#include "config/guc.h" -#include "export/exporter_interface.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace otlp = opentelemetry::exporter::otlp; -namespace logs_pb = opentelemetry::proto::logs::v1; -namespace common_pb = opentelemetry::proto::common::v1; -namespace resource_pb = opentelemetry::proto::resource::v1; -namespace collector_logs = opentelemetry::proto::collector::logs::v1; - -// Exposed with external linkage so unit tests can link against it directly. -std::string GetAHostname(const char* fallback) { - if (psch_hostname != nullptr && *psch_hostname != '\0') { - return psch_hostname; - } - const char* env = getenv("HOSTNAME"); - if (env != nullptr && *env != '\0') { - return env; - } - char buf[256]; - if (gethostname(buf, sizeof(buf)) == 0) { - buf[sizeof(buf) - 1] = '\0'; - return buf; - } - return fallback; -} - -namespace { - -using string = std::string; -using string_view = std::string_view; - -// Create a gRPC channel with compression and keepalive settings optimized -// for high-throughput telemetry export from a long-lived bgworker. -std::shared_ptr MakeOptimizedChannel( - const otlp::OtlpGrpcLogRecordExporterOptions& opts) { - grpc::ChannelArguments args; - - // gzip — telemetry payloads with repeated attribute keys compress very well. - args.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP); - - // Keepalive: the bgworker holds a persistent channel. Without keepalive - // pings, idle periods cause silent TCP drops and surprise RPC failures. - args.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, 30000); - args.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 10000); - args.SetInt(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1); - args.SetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0); - - std::shared_ptr credentials; - if (opts.use_ssl_credentials) { - grpc::SslCredentialsOptions ssl_opts; - if (!opts.ssl_credentials_cacert_as_string.empty()) { - ssl_opts.pem_root_certs = opts.ssl_credentials_cacert_as_string; - } - credentials = grpc::SslCredentials(ssl_opts); - } else { - credentials = grpc::InsecureChannelCredentials(); - } - - return grpc::CreateCustomChannel(opts.endpoint, credentials, args); -} - -common_pb::KeyValue* AddAttr(logs_pb::LogRecord* rec) { - return rec->add_attributes(); -} - -void SetString(common_pb::KeyValue* kv, string_view key, string_view val) { - kv->set_key(key.data(), key.size()); - kv->mutable_value()->set_string_value(val.data(), val.size()); -} - -void SetInt(common_pb::KeyValue* kv, string_view key, int64_t val) { - kv->set_key(key.data(), key.size()); - kv->mutable_value()->set_int_value(val); -} - -void SetDouble(common_pb::KeyValue* kv, string_view key, double val) { - kv->set_key(key.data(), key.size()); - kv->mutable_value()->set_double_value(val); -} - -// Conservative sizing constants to stay under the gRPC message budget. -constexpr size_t kMinBytesPerRecord = 1200; -constexpr size_t kRequestOverheadBytes = 512; -constexpr size_t kLogRecordOverheadBytes = 128; -constexpr size_t kAttrOverheadBytes = 24; - -size_t EstimateStringAttrBytes(string_view key, string_view value) { - return kAttrOverheadBytes + key.size() + value.size(); -} - -size_t EstimateScalarAttrBytes(string_view key) { - return kAttrOverheadBytes + key.size() + sizeof(int64_t); -} - -// --------------------------------------------------------------------------- -// Direct-proto exporter — no OTel SDK dependency on the hot path. -// --------------------------------------------------------------------------- -class OTelExporter : public StatsExporter { - public: - void BeginBatch() final { - exported_count_ = 0; - batch_failed_ = false; - ResetChunk(); - } - - void BeginRow() final { - if (batch_failed_) { - return; - } - if (ChunkFull()) { - if (!FlushChunk()) { - batch_failed_ = true; - return; - } - ResetChunk(); - } - current_record_ = scope_logs_->add_log_records(); - ++chunk_count_; - chunk_bytes_ += kLogRecordOverheadBytes; - } - - bool CommitBatch() final; - - // -- Column factories (all write directly to the arena-allocated LogRecord) -- - - shared_ptr> TagString(string_view name) final { return MakeStringCol(name); } - - shared_ptr> MetricInt16(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> MetricInt32(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> MetricInt64(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> MetricUInt8(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> MetricUInt64(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> MetricFixedString(int /*len*/, string_view name) final { - return MakeSvCol(name); - } - - shared_ptr> RecordInt16(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> RecordInt32(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> RecordInt64(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> RecordUInt8(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> RecordUInt64(string_view name) final { - return MakeIntCol(name); - } - shared_ptr> RecordDateTime(string_view name) final { - return MakeDateTimeCol(name); - } - shared_ptr> RecordString(string_view name) final { return MakeSvCol(name); } - - // Semantic columns - shared_ptr> DbNameColumn() final { return MakeStringCol("db.name"); } - shared_ptr> DbUserColumn() final { return MakeStringCol("db.user"); } - shared_ptr> DbDurationColumn() final { return MakeDurationCol(); } - shared_ptr> DbOperationColumn() final { - return MakeStringCol("db.operation.name"); - } - shared_ptr> DbQueryTextColumn() final { return MakeSvCol("db.query.text"); } - - bool EstablishNewConnection() final; - bool IsConnected() const final { return stub_ != nullptr; } - int NumConsecutiveFailures() const final { return consecutive_failures_; } - void ResetFailures() final { consecutive_failures_ = 0; } - int NumExported() const final { return exported_count_; } - bool SendArrowBatch(const uint8_t* ipc_data, size_t ipc_len, int num_rows) final; - - private: - // -- Lightweight column types (no SDK, no Crunch, direct proto writes) ----- - - template - class IntColumn : public Column { - public: - IntColumn(OTelExporter* e, string_view n) : exp_(e), name_(n) {} - void Append(const T& v) final { - if (exp_->current_record_ == nullptr || v == 0) { - return; - } - SetInt(AddAttr(exp_->current_record_), name_, static_cast(v)); - exp_->chunk_bytes_ += EstimateScalarAttrBytes(name_); - } - void Crunch() final {} - - private: - OTelExporter* exp_; - string name_; - }; - - class SvColumn : public Column { - public: - SvColumn(OTelExporter* e, string_view n) : exp_(e), name_(n) {} - void Append(const string_view& v) final { - if (exp_->current_record_ == nullptr) { - return; - } - SetString(AddAttr(exp_->current_record_), name_, v); - exp_->chunk_bytes_ += EstimateStringAttrBytes(name_, v); - } - void Crunch() final {} - - private: - OTelExporter* exp_; - string name_; - }; - - class StrColumn : public Column { - public: - StrColumn(OTelExporter* e, string_view n) : exp_(e), name_(n) {} - void Append(const string& v) final { - if (exp_->current_record_ == nullptr) { - return; - } - SetString(AddAttr(exp_->current_record_), name_, v); - exp_->chunk_bytes_ += EstimateStringAttrBytes(name_, v); - } - void Crunch() final {} - - private: - OTelExporter* exp_; - string name_; - }; - - class DateTimeCol : public Column { - public: - DateTimeCol(OTelExporter* e, string_view n) : exp_(e), name_(n) {} - void Append(const int64_t& v) final { - if (exp_->current_record_ == nullptr) { - return; - } - exp_->current_record_->set_time_unix_nano(static_cast(v) * 1000ULL); - SetInt(AddAttr(exp_->current_record_), name_, v); - exp_->chunk_bytes_ += EstimateScalarAttrBytes(name_) + sizeof(uint64_t); - } - void Crunch() final {} - - private: - OTelExporter* exp_; - string name_; - }; - - class DurationCol : public Column { - public: - explicit DurationCol(OTelExporter* e) : exp_(e) {} - void Append(const uint64_t& v) final { - if (exp_->current_record_ == nullptr) { - return; - } - double seconds = static_cast(v) / 1e6; - SetDouble(AddAttr(exp_->current_record_), "db.client.operation.duration", seconds); - SetInt(AddAttr(exp_->current_record_), "duration_us", static_cast(v)); - exp_->chunk_bytes_ += EstimateScalarAttrBytes("db.client.operation.duration") + - EstimateScalarAttrBytes("duration_us"); - } - void Crunch() final {} - - private: - OTelExporter* exp_; - }; - - // -- Column factory helpers ------------------------------------------------ - - template - shared_ptr> MakeIntCol(string_view name) { - return std::make_shared>(this, name); - } - - shared_ptr> MakeSvCol(string_view name) { - return std::make_shared(this, name); - } - - shared_ptr> MakeStringCol(string_view name) { - return std::make_shared(this, name); - } - - shared_ptr> MakeDateTimeCol(string_view name) { - return std::make_shared(this, name); - } - - shared_ptr> MakeDurationCol() { return std::make_shared(this); } - - // -- Chunk management ------------------------------------------------------ - - bool ChunkFull() const { - return chunk_count_ >= max_chunk_records_ || chunk_bytes_ >= max_chunk_bytes_; - } - - void ResetChunk() { - google::protobuf::ArenaOptions arena_opts; - arena_opts.initial_block_size = 65536; // 64 KiB — skip many small doublings - arena_opts.max_block_size = 1048576; // 1 MiB — sized for 3 MiB chunk budget - arena_ = std::make_unique(arena_opts); - - request_ = - google::protobuf::Arena::Create(arena_.get()); - chunk_count_ = 0; - chunk_bytes_ = kRequestOverheadBytes; - current_record_ = nullptr; - - auto* resource_logs = request_->add_resource_logs(); - PopulateResource(resource_logs->mutable_resource()); - scope_logs_ = resource_logs->add_scope_logs(); - scope_logs_->mutable_scope()->set_name("pg_stat_ch"); - scope_logs_->mutable_scope()->set_version(PG_STAT_CH_VERSION); - } - - bool FlushChunk() { - if (stub_ == nullptr || chunk_count_ == 0) { - return true; - } - - auto context = otlp::OtlpGrpcClient::MakeClientContext(grpc_opts_); - collector_logs::ExportLogsServiceResponse response; - auto status = otlp::OtlpGrpcClient::DelegateExport( - stub_.get(), std::move(context), std::move(arena_), std::move(*request_), &response); - - request_ = nullptr; - scope_logs_ = nullptr; - current_record_ = nullptr; - - if (status.ok()) { - exported_count_ += static_cast(chunk_count_); - chunk_count_ = 0; - chunk_bytes_ = 0; - return true; - } - - LogExporterWarning("gRPC export failed", status.error_message().c_str()); - RecordExporterFailure(status.error_message().c_str()); - consecutive_failures_++; - return false; - } - - static void PopulateResource(resource_pb::Resource* resource, bool arrow_ipc = false) { - auto add = [&](string_view key, string_view val) { - SetString(resource->add_attributes(), key, val); - }; - add("service.name", "pg_stat_ch"); - add("service.version", PG_STAT_CH_VERSION); - add("host.name", GetAHostname("postgres-primary")); - if (arrow_ipc) { - add("pg_stat_ch.block_format", "arrow_ipc"); - } - } - - void ConfigureLogExport(const string& endpoint) { - grpc_opts_ = otlp::OtlpGrpcLogRecordExporterOptions(); - if (!endpoint.empty()) { - grpc_opts_.endpoint = endpoint; - } - grpc_opts_.timeout = std::chrono::milliseconds(psch_otel_log_delay_ms); - - max_chunk_bytes_ = std::max(kMinBytesPerRecord, psch_otel_log_max_bytes); - max_chunk_records_ = std::max( - 1, std::min(psch_otel_log_batch_size, max_chunk_bytes_ / kMinBytesPerRecord)); - } - - // gRPC state - otlp::OtlpGrpcLogRecordExporterOptions grpc_opts_; - std::unique_ptr stub_; - size_t max_chunk_records_ = 1; - size_t max_chunk_bytes_ = kMinBytesPerRecord; - int consecutive_failures_ = 0; - int exported_count_ = 0; - bool batch_failed_ = false; - - // Per-chunk state (arena-allocated) - std::unique_ptr arena_; - collector_logs::ExportLogsServiceRequest* request_ = nullptr; - logs_pb::ScopeLogs* scope_logs_ = nullptr; - logs_pb::LogRecord* current_record_ = nullptr; - size_t chunk_count_ = 0; - size_t chunk_bytes_ = 0; -}; - -bool OTelExporter::EstablishNewConnection() { - try { - const string endpoint = - (psch_otel_endpoint != nullptr && *psch_otel_endpoint != '\0') ? psch_otel_endpoint : ""; - - ConfigureLogExport(endpoint); - auto channel = MakeOptimizedChannel(grpc_opts_); - if (channel == nullptr) { - LogExporterWarning("OTel init failed", "invalid or empty OTLP endpoint"); - stub_.reset(); - return false; - } - stub_ = collector_logs::LogsService::NewStub(channel); - return true; - } catch (const std::exception& e) { - LogExporterWarning("OTel init failed", e.what()); - stub_.reset(); - return false; - } -} - -bool OTelExporter::CommitBatch() { - if (batch_failed_) { - return false; - } - - if (stub_ == nullptr) { - ResetFailures(); - return true; - } - - try { - bool ok = FlushChunk(); - if (ok) { - ResetFailures(); - } - return ok; - } catch (const std::exception& e) { - LogExporterWarning("export exception", e.what()); - RecordExporterFailure(e.what()); - consecutive_failures_++; - return false; - } -} - -bool OTelExporter::SendArrowBatch(const uint8_t* ipc_data, size_t ipc_len, int num_rows) { - if (stub_ == nullptr || ipc_data == nullptr || ipc_len == 0 || num_rows <= 0) { - return false; - } - - try { - google::protobuf::ArenaOptions arena_opts; - arena_opts.initial_block_size = 8192; - arena_opts.max_block_size = 65536; - auto arena = std::make_unique(arena_opts); - - auto* request = - google::protobuf::Arena::Create(arena.get()); - auto* resource_logs = request->add_resource_logs(); - PopulateResource(resource_logs->mutable_resource(), /*arrow_ipc=*/true); - auto* scope_logs = resource_logs->add_scope_logs(); - scope_logs->mutable_scope()->set_name("pg_stat_ch"); - scope_logs->mutable_scope()->set_version(PG_STAT_CH_VERSION); - - auto* record = scope_logs->add_log_records(); - const auto now_ns = - static_cast(std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count()); - record->set_time_unix_nano(now_ns); - record->set_observed_time_unix_nano(now_ns); - record->mutable_body()->set_bytes_value(reinterpret_cast(ipc_data), ipc_len); - SetString(AddAttr(record), "pg_stat_ch.block_format", "arrow_ipc"); - SetInt(AddAttr(record), "pg_stat_ch.block_rows", num_rows); - - auto context = otlp::OtlpGrpcClient::MakeClientContext(grpc_opts_); - collector_logs::ExportLogsServiceResponse response; - auto status = otlp::OtlpGrpcClient::DelegateExport( - stub_.get(), std::move(context), std::move(arena), std::move(*request), &response); - - if (status.ok()) { - exported_count_ += num_rows; - consecutive_failures_ = 0; - return true; - } - - LogExporterWarning("Arrow batch gRPC failed", status.error_message().c_str()); - RecordExporterFailure(status.error_message().c_str()); - consecutive_failures_++; - return false; - } catch (const std::exception& e) { - LogExporterWarning("Arrow batch export exception", e.what()); - RecordExporterFailure(e.what()); - consecutive_failures_++; - return false; - } -} - -} // namespace - -std::unique_ptr MakeOpenTelemetryExporter() { - return std::make_unique(); -} diff --git a/src/export/otel_exporter.h b/src/export/otel_exporter.h deleted file mode 100644 index 88dafd6..0000000 --- a/src/export/otel_exporter.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef PG_STAT_CH_SRC_EXPORT_OTEL_EXPORTER_H_ -#define PG_STAT_CH_SRC_EXPORT_OTEL_EXPORTER_H_ - -#include "export/exporter_interface.h" - -#include - -std::unique_ptr MakeOpenTelemetryExporter(); - -#endif // PG_STAT_CH_SRC_EXPORT_OTEL_EXPORTER_H_ From 40fd8f868ce4f8a6eef42afbf77cc7d9b313cc6d Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:07 -0500 Subject: [PATCH 07/11] feat(export): port ClickHouse backend to C C port of the clickhouse_exporter (clickhouse-c is already C underneath). Static column descriptor table replaces the C++ column-factory/registry; goto-cleanup replaces the RAII guards; preallocated per-column buffers replace std::vector. An in_flight flag forces a reconnect after a longjmp interrupts a wire exchange. The cancel callback now also fires on ProcSignalBarrierPending so a DROP DATABASE barrier is not blocked behind a flowing ClickHouse read. Backend failure stats are recorded by the driver, not here (avoids double-counting). --- src/export/clickhouse_c_impl.c | 6 +- src/export/clickhouse_exporter.c | 1174 +++++++++++++++++++++++++++++ src/export/clickhouse_exporter.cc | 771 ------------------- src/export/clickhouse_exporter.h | 11 - 4 files changed, 1177 insertions(+), 785 deletions(-) create mode 100644 src/export/clickhouse_exporter.c delete mode 100644 src/export/clickhouse_exporter.cc delete mode 100644 src/export/clickhouse_exporter.h diff --git a/src/export/clickhouse_c_impl.c b/src/export/clickhouse_c_impl.c index d7a302b..fb45b50 100644 --- a/src/export/clickhouse_c_impl.c +++ b/src/export/clickhouse_c_impl.c @@ -1,6 +1,6 @@ #define CHC_IMPLEMENTATION -#include "clickhouse.h" +#include "clickhouse-client.h" #include "clickhouse-compression.h" -#include "clickhouse-posix-io.h" #include "clickhouse-openssl.h" -#include "clickhouse-client.h" +#include "clickhouse-posix-io.h" +#include "clickhouse.h" diff --git a/src/export/clickhouse_exporter.c b/src/export/clickhouse_exporter.c new file mode 100644 index 0000000..df5fd5e --- /dev/null +++ b/src/export/clickhouse_exporter.c @@ -0,0 +1,1174 @@ +// pg_stat_ch ClickHouse exporter — C port of the former C++ implementation. +// +// Contract (src/export/exporter.h): no function here may ereport(ERROR) or +// otherwise longjmp; WARNING/LOG/DEBUG1 only. All column buffers are +// preallocated in PschClickHouseExporterCreate, sized for the driver's +// staging chunk, so the steady-state export path performs zero heap +// allocation outside the two reset-per-batch memory contexts that +// clickhouse-c draws from (via NO_OOM allocators that return NULL). + +#include "postgres.h" + +#include "miscadmin.h" // ProcDiePending +#include "storage/procsignal.h" // ProcSignalBarrierPending +#include "utils/memutils.h" +#include "utils/palloc.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "clickhouse-client.h" +#include "clickhouse-compression.h" +#include "clickhouse-openssl.h" +#include "clickhouse-posix-io.h" +#include "clickhouse.h" + +#include "config/guc.h" +#include "config/memory_budget.h" +#include "export/exporter.h" +#include "queue/shmem.h" // PschRecordExportFailure / PschRecordExportSuccess + +static const int kSocketTimeoutSec = 30; + +// Bound packets consumed while awaiting response +static const int kMaxRecvPackets = 4096; + +// PostgreSQL epoch is 2000-01-01, Unix epoch is 1970-01-01. +static const int64 kPostgresEpochOffsetUs = INT64CONST(946684800000000); + +// --------------------------------------------------------------------------- +// Static schema. Exactly the columns the old driver registered, in the same +// order (the old stats_exporter.cc:236-286 registration sequence). This +// table is the single source of truth for names, ClickHouse types, buffer +// sizing, and the INSERT column list. +// --------------------------------------------------------------------------- + +typedef enum ChTypeId { + CH_TYPE_INT16 = 0, + CH_TYPE_INT32, + CH_TYPE_INT64, + CH_TYPE_UINT8, + CH_TYPE_UINT64, + CH_TYPE_DATETIME64_6, + CH_TYPE_FIXEDSTRING_5, + CH_NUM_TYPES, + CH_TYPE_NONE = -1, // String columns carry no parsed type on the wire +} ChTypeId; + +static const char* const kChTypeNames[CH_NUM_TYPES] = { + "Int16", "Int32", "Int64", "UInt8", "UInt64", "DateTime64(6)", "FixedString(5)", +}; + +typedef enum ChColId { + CH_COL_TS_START = 0, + CH_COL_DURATION_US, + CH_COL_DB, + CH_COL_USERNAME, + CH_COL_PID, + CH_COL_QUERY_ID, + CH_COL_CMD_TYPE, + CH_COL_ROWS, + CH_COL_QUERY, + CH_COL_SHARED_BLKS_HIT, + CH_COL_SHARED_BLKS_READ, + CH_COL_SHARED_BLKS_DIRTIED, + CH_COL_SHARED_BLKS_WRITTEN, + CH_COL_LOCAL_BLKS_HIT, + CH_COL_LOCAL_BLKS_READ, + CH_COL_LOCAL_BLKS_DIRTIED, + CH_COL_LOCAL_BLKS_WRITTEN, + CH_COL_TEMP_BLKS_READ, + CH_COL_TEMP_BLKS_WRITTEN, + CH_COL_SHARED_BLK_READ_TIME_US, + CH_COL_SHARED_BLK_WRITE_TIME_US, + CH_COL_LOCAL_BLK_READ_TIME_US, + CH_COL_LOCAL_BLK_WRITE_TIME_US, + CH_COL_TEMP_BLK_READ_TIME_US, + CH_COL_TEMP_BLK_WRITE_TIME_US, + CH_COL_WAL_RECORDS, + CH_COL_WAL_FPI, + CH_COL_WAL_BYTES, + CH_COL_CPU_USER_TIME_US, + CH_COL_CPU_SYS_TIME_US, + CH_COL_JIT_FUNCTIONS, + CH_COL_JIT_GENERATION_TIME_US, + CH_COL_JIT_DEFORM_TIME_US, + CH_COL_JIT_INLINING_TIME_US, + CH_COL_JIT_OPTIMIZATION_TIME_US, + CH_COL_JIT_EMISSION_TIME_US, + CH_COL_PARALLEL_WORKERS_PLANNED, + CH_COL_PARALLEL_WORKERS_LAUNCHED, + CH_COL_ERR_SQLSTATE, + CH_COL_ERR_ELEVEL, + CH_COL_ERR_MESSAGE, + CH_COL_APP, + CH_COL_CLIENT_ADDR, + CH_NUM_COLS, +} ChColId; + +typedef enum ChColKind { + CH_KIND_FIXED = 0, // n_rows * elem_size slab via append_fixed + CH_KIND_STRING, // bytes slab + cumulative uint64 end-offsets via append_string + CH_KIND_FIXEDSTRING, // n_rows * elem_size slab via append_fixed (FixedString type) +} ChColKind; + +typedef struct ChColDesc { + const char* name; + ChColKind kind; + ChTypeId type_id; // CH_TYPE_NONE for CH_KIND_STRING + uint16 elem_size; // FIXED: element bytes; FIXEDSTRING: width + uint16 max_len; // STRING: clamp limit == per-row buffer reservation +} ChColDesc; + +#define CH_FIXED(nm, tid, sz) {(nm), CH_KIND_FIXED, (tid), (sz), 0} +#define CH_STRING(nm, maxlen) {(nm), CH_KIND_STRING, CH_TYPE_NONE, 0, (maxlen)} + +// cmd_type values come from PschCmdTypeToString: longest is "UNKNOWN" (7). +#define CH_CMD_TYPE_MAX_LEN 8 + +static const ChColDesc kChCols[CH_NUM_COLS] = { + [CH_COL_TS_START] = CH_FIXED("ts_start", CH_TYPE_DATETIME64_6, 8), + [CH_COL_DURATION_US] = CH_FIXED("duration_us", CH_TYPE_UINT64, 8), + [CH_COL_DB] = CH_STRING("db", NAMEDATALEN), + [CH_COL_USERNAME] = CH_STRING("username", NAMEDATALEN), + [CH_COL_PID] = CH_FIXED("pid", CH_TYPE_INT32, 4), + [CH_COL_QUERY_ID] = CH_FIXED("query_id", CH_TYPE_INT64, 8), + [CH_COL_CMD_TYPE] = CH_STRING("cmd_type", CH_CMD_TYPE_MAX_LEN), + [CH_COL_ROWS] = CH_FIXED("rows", CH_TYPE_UINT64, 8), + [CH_COL_QUERY] = CH_STRING("query", PSCH_MAX_QUERY_LEN), + [CH_COL_SHARED_BLKS_HIT] = CH_FIXED("shared_blks_hit", CH_TYPE_INT64, 8), + [CH_COL_SHARED_BLKS_READ] = CH_FIXED("shared_blks_read", CH_TYPE_INT64, 8), + [CH_COL_SHARED_BLKS_DIRTIED] = CH_FIXED("shared_blks_dirtied", CH_TYPE_INT64, 8), + [CH_COL_SHARED_BLKS_WRITTEN] = CH_FIXED("shared_blks_written", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLKS_HIT] = CH_FIXED("local_blks_hit", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLKS_READ] = CH_FIXED("local_blks_read", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLKS_DIRTIED] = CH_FIXED("local_blks_dirtied", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLKS_WRITTEN] = CH_FIXED("local_blks_written", CH_TYPE_INT64, 8), + [CH_COL_TEMP_BLKS_READ] = CH_FIXED("temp_blks_read", CH_TYPE_INT64, 8), + [CH_COL_TEMP_BLKS_WRITTEN] = CH_FIXED("temp_blks_written", CH_TYPE_INT64, 8), + [CH_COL_SHARED_BLK_READ_TIME_US] = CH_FIXED("shared_blk_read_time_us", CH_TYPE_INT64, 8), + [CH_COL_SHARED_BLK_WRITE_TIME_US] = CH_FIXED("shared_blk_write_time_us", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLK_READ_TIME_US] = CH_FIXED("local_blk_read_time_us", CH_TYPE_INT64, 8), + [CH_COL_LOCAL_BLK_WRITE_TIME_US] = CH_FIXED("local_blk_write_time_us", CH_TYPE_INT64, 8), + [CH_COL_TEMP_BLK_READ_TIME_US] = CH_FIXED("temp_blk_read_time_us", CH_TYPE_INT64, 8), + [CH_COL_TEMP_BLK_WRITE_TIME_US] = CH_FIXED("temp_blk_write_time_us", CH_TYPE_INT64, 8), + [CH_COL_WAL_RECORDS] = CH_FIXED("wal_records", CH_TYPE_INT64, 8), + [CH_COL_WAL_FPI] = CH_FIXED("wal_fpi", CH_TYPE_INT64, 8), + [CH_COL_WAL_BYTES] = CH_FIXED("wal_bytes", CH_TYPE_UINT64, 8), + [CH_COL_CPU_USER_TIME_US] = CH_FIXED("cpu_user_time_us", CH_TYPE_INT64, 8), + [CH_COL_CPU_SYS_TIME_US] = CH_FIXED("cpu_sys_time_us", CH_TYPE_INT64, 8), + [CH_COL_JIT_FUNCTIONS] = CH_FIXED("jit_functions", CH_TYPE_INT32, 4), + [CH_COL_JIT_GENERATION_TIME_US] = CH_FIXED("jit_generation_time_us", CH_TYPE_INT32, 4), + [CH_COL_JIT_DEFORM_TIME_US] = CH_FIXED("jit_deform_time_us", CH_TYPE_INT32, 4), + [CH_COL_JIT_INLINING_TIME_US] = CH_FIXED("jit_inlining_time_us", CH_TYPE_INT32, 4), + [CH_COL_JIT_OPTIMIZATION_TIME_US] = CH_FIXED("jit_optimization_time_us", CH_TYPE_INT32, 4), + [CH_COL_JIT_EMISSION_TIME_US] = CH_FIXED("jit_emission_time_us", CH_TYPE_INT32, 4), + [CH_COL_PARALLEL_WORKERS_PLANNED] = CH_FIXED("parallel_workers_planned", CH_TYPE_INT16, 2), + [CH_COL_PARALLEL_WORKERS_LAUNCHED] = CH_FIXED("parallel_workers_launched", CH_TYPE_INT16, 2), + [CH_COL_ERR_SQLSTATE] = {"err_sqlstate", CH_KIND_FIXEDSTRING, CH_TYPE_FIXEDSTRING_5, 5, 0}, + [CH_COL_ERR_ELEVEL] = CH_FIXED("err_elevel", CH_TYPE_UINT8, 1), + [CH_COL_ERR_MESSAGE] = CH_STRING("err_message", PSCH_MAX_ERR_MSG_LEN), + [CH_COL_APP] = CH_STRING("app", PSCH_MAX_APP_NAME_LEN), + [CH_COL_CLIENT_ADDR] = CH_STRING("client_addr", PSCH_MAX_CLIENT_ADDR_LEN), +}; + +// Preallocated per-column storage. Fixed columns: chunk_rows * elem_size. +// String columns keep the cumulative uint64 end-offset layout that +// chc_block_builder_append_string consumes directly. +typedef struct ChColData { + char* data; + uint64_t* offsets; // CH_KIND_STRING only; uint64_t (not PG uint64) — consumed by clickhouse-c + size_t bytes_used; // CH_KIND_STRING fill cursor, reset per chunk +} ChColData; + +typedef struct ClickHouseExporter { + PschExporter base; + + MemoryContext conn_cxt; // connection-lifetime clickhouse-c allocations + MemoryContext batch_cxt; // reset after every commit attempt + MemoryContext col_cxt; // create-time column buffers, never reset + chc_alloc conn_al; + chc_alloc batch_al; + + chc_client* client; + int fd; + SSL_CTX* ssl_ctx; + SSL* ssl; + chc_posix_io posix_io; + chc_openssl_io openssl_io; + chc_io io; + chc_codec codec; + + chc_block_builder* bb; // live only inside ChCommitChunk + chc_err build_err; + chc_type* types[CH_NUM_TYPES]; // parsed eagerly at connect, conn_cxt-owned + + int chunk_rows; // rows per INSERT == driver staging chunk capacity + ChColData cols[CH_NUM_COLS]; + char* insert_query; + size_t insert_query_len; + + // True while a wire exchange is outstanding. Still set on entry means a + // longjmp cut the previous INSERT mid-protocol: the server is wedged + // waiting for data, so the connection must be dropped, not reused. + bool in_flight; + + int consecutive_failures; + uint64 mem_used; // preallocated bytes, for pg_stat_ch_memory() +} ClickHouseExporter; + +// --------------------------------------------------------------------------- +// Forward declarations +// --------------------------------------------------------------------------- + +static bool ChConnect(PschExporter* self, char* errbuf, size_t errlen); +static bool ChIsConnected(const PschExporter* self); +static PschExportStatus ChExportEvents(PschExporter* self, const PschEvent* events, int nevents, + int* exported_out); +static int ChConsecutiveFailures(const PschExporter* self); +static void ChResetFailures(PschExporter* self); +static uint64 ChMemUsed(const PschExporter* self); +static void ChDestroy(PschExporter* self); + +static bool EstablishNewConnection(ClickHouseExporter* exp); +static void CloseConnection(ClickHouseExporter* exp); +static void ResetBatchContext(ClickHouseExporter* exp); + +static const PschExporterOps kClickHouseOps = { + .connect = ChConnect, + .is_connected = ChIsConnected, + .export_events = ChExportEvents, + .send_arrow = NULL, // ClickHouse backend does not speak Arrow IPC + .consecutive_failures = ChConsecutiveFailures, + .reset_failures = ChResetFailures, + .mem_used = ChMemUsed, + .destroy = ChDestroy, +}; + +// --------------------------------------------------------------------------- +// Small helpers +// --------------------------------------------------------------------------- + +// Abort blocking reads when the bgworker receives SIGTERM (ProcDiePending) or +// a procsignal barrier is pending (ProcSignalBarrierPending — e.g. DROP +// DATABASE/TABLESPACE). clickhouse-c checks this before each socket refill +// (clickhouse.h:708,758), so returning true here surfaces as CHC_ERR_CANCELLED +// -> ERR_SEND -> the batch is requeued and the bgworker loop promptly runs +// ProcessProcSignalBarrier. This bounds barrier-ack latency to one read while +// data is flowing; a hard-stalled connection is still bounded by the socket +// deadline (kSocketTimeoutSec), since clickhouse-c does not poll the cancel +// callback while blocked inside poll(). +static bool PschChcCheckCancel(void* ud) { + (void)ud; + return ProcDiePending != 0 || ProcSignalBarrierPending; +} + +// palloc ereport(ERROR)s on requests beyond MaxAllocHugeSize even with +// NO_OOM; refuse them here so the whole clickhouse-c call tree stays +// longjmp-free (OOM and oversize both surface as NULL -> CHC_ERR_OOM). +static void* PschChcAlloc(void* ud, size_t bytes) { + if (bytes > MaxAllocHugeSize) + return NULL; + return MemoryContextAllocExtended((MemoryContext)ud, bytes, MCXT_ALLOC_HUGE | MCXT_ALLOC_NO_OOM); +} + +static void* PschChcRealloc(void* ud, void* p, size_t old_bytes, size_t new_bytes) { + (void)old_bytes; + if (p == NULL) + return PschChcAlloc(ud, new_bytes); + if (new_bytes > MaxAllocHugeSize) + return NULL; + return repalloc_extended(p, new_bytes, MCXT_ALLOC_HUGE | MCXT_ALLOC_NO_OOM); +} + +static void PschChcFree(void* ud, void* p, size_t bytes) { + (void)ud; + (void)bytes; + if (p != NULL) + pfree(p); +} + +static chc_alloc MakePschChcAlloc(MemoryContext cxt) { + return (chc_alloc){cxt, PschChcAlloc, PschChcRealloc, PschChcFree}; +} + +static int64 MonotonicNowUs(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ((int64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); +} + +// msg need not be NUL-terminated (server-controlled exception text); always +// truncates and NUL-terminates within errlen. +static void ErrBufSetN(char* errbuf, size_t errlen, const char* msg, size_t msg_len) { + size_t n; + + if (errbuf == NULL || errlen == 0) + return; + n = Min(msg_len, errlen - 1); + if (n > 0) + memcpy(errbuf, msg, n); + errbuf[n] = '\0'; +} + +static void ErrBufSet(char* errbuf, size_t errlen, const char* msg) { + ErrBufSetN(errbuf, errlen, msg, strlen(msg)); +} + +// Clamp a field length to its buffer maximum, warning on overflow. Must be +// applied BEFORE any memcpy into the preallocated column buffers. +static inline uint32 ClampFieldLen(uint32 len, uint32 max, const char* field_name) { + if (len <= max) + return len; + // Rate-limit to at most one WARNING/sec: a corrupt or oversized field could + // otherwise flood the log at the event rate. + static time_t last_log = 0; + time_t now = time(NULL); + if (now - last_log >= 1) { + elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, (unsigned)len); + last_log = now; + } + return max; +} + +// --------------------------------------------------------------------------- +// Connection plumbing (near-verbatim port of the C++ implementation) +// --------------------------------------------------------------------------- + +// Restore blocking mode after bounded connect, clickhouse-c I/O expects it +static bool ConnectWithTimeout(int fd, const struct sockaddr* sa, socklen_t slen, int timeout_sec) { + int flags = fcntl(fd, F_GETFL, 0); + bool ok = false; + int save_errno = 0; + + if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) + return false; + + if (connect(fd, sa, slen) == 0) { + ok = true; + } else if (errno == EINPROGRESS) { + const int64 deadline = MonotonicNowUs() + (int64)timeout_sec * 1000000; + for (;;) { + const int64 remaining_us = deadline - MonotonicNowUs(); + struct pollfd pfd; + int pr; + int soerr = 0; + socklen_t l = sizeof soerr; + + if (remaining_us <= 0) { + save_errno = ETIMEDOUT; + break; + } + pfd.fd = fd; + pfd.events = POLLOUT; + pfd.revents = 0; + pr = poll(&pfd, 1, (int)((remaining_us + 999) / 1000)); + if (pr < 0) { + if (errno == EINTR) + continue; // signal (eg bgworker latch); retry within deadline + save_errno = errno; + break; + } + if (pr == 0) { + save_errno = ETIMEDOUT; + break; + } + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &soerr, &l) < 0) { + save_errno = errno; + break; + } + save_errno = soerr; + ok = soerr == 0; + break; + } + } else { + save_errno = errno; + } + + // Always restore blocking mode, even on failure: keeps the helper safe to + // reuse and matches clickhouse-c I/O expectations + if (fcntl(fd, F_SETFL, flags) < 0) + return false; + if (!ok) + errno = save_errno; + return ok; +} + +static bool MemoryContextsReady(const ClickHouseExporter* exp) { + return exp->conn_cxt != NULL && exp->batch_cxt != NULL; +} + +// Sole longjmp source in the connection path: AllocSetContextCreate ereports on +// OOM. Swallow it here so EstablishNewConnection stays a pure bool — callers +// then need no PG_TRY frame around it. elog.c leaves CurrentMemoryContext at +// ErrorContext after a caught error, so restore it before returning. +static bool EnsureMemoryContexts(ClickHouseExporter* exp) { + MemoryContext oldcontext; + + if (MemoryContextsReady(exp) && exp->col_cxt != NULL) + return true; + + oldcontext = CurrentMemoryContext; + PG_TRY(); + { + if (exp->conn_cxt == NULL) + exp->conn_cxt = AllocSetContextCreate(TopMemoryContext, "pg_stat_ch clickhouse-c", + ALLOCSET_DEFAULT_SIZES); + if (exp->batch_cxt == NULL) + exp->batch_cxt = AllocSetContextCreate(TopMemoryContext, "pg_stat_ch clickhouse-c batch", + ALLOCSET_DEFAULT_SIZES); + if (exp->col_cxt == NULL) + exp->col_cxt = AllocSetContextCreate(TopMemoryContext, "pg_stat_ch clickhouse-c columns", + ALLOCSET_DEFAULT_SIZES); + } + PG_CATCH(); + { + MemoryContextSwitchTo(oldcontext); + if (exp->col_cxt != NULL) { + MemoryContextDelete(exp->col_cxt); + exp->col_cxt = NULL; + } + if (exp->batch_cxt != NULL) { + MemoryContextDelete(exp->batch_cxt); + exp->batch_cxt = NULL; + } + if (exp->conn_cxt != NULL) { + MemoryContextDelete(exp->conn_cxt); + exp->conn_cxt = NULL; + } + exp->conn_al = (chc_alloc){0}; + exp->batch_al = (chc_alloc){0}; + EmitErrorReport(); + FlushErrorState(); + return false; + } + PG_END_TRY(); + + exp->conn_al = MakePschChcAlloc(exp->conn_cxt); + exp->batch_al = MakePschChcAlloc(exp->batch_cxt); + return true; +} + +static void ClearTypes(ClickHouseExporter* exp) { + for (int t = 0; t < CH_NUM_TYPES; t++) { + if (exp->types[t] != NULL) { + chc_type_destroy(exp->types[t], &exp->conn_al); + exp->types[t] = NULL; + } + } +} + +static void ResetBatchContext(ClickHouseExporter* exp) { + if (exp->batch_cxt != NULL) { + MemoryContextReset(exp->batch_cxt); + exp->batch_al = MakePschChcAlloc(exp->batch_cxt); + } +} + +static void ResetConnectionContext(ClickHouseExporter* exp) { + ClearTypes(exp); + if (exp->conn_cxt != NULL) { + MemoryContextReset(exp->conn_cxt); + exp->conn_al = MakePschChcAlloc(exp->conn_cxt); + } +} + +// WARNING + consecutive-failure increment (+ optional close). Shmem failure +// stats are recorded by the driver (stats_exporter.c) from the returned +// status, so the backend must NOT call PschRecordExportFailure here (it would +// double-count send_failures); the detailed message lives in this WARNING. +static void RecordFailure(ClickHouseExporter* exp, const char* context, const char* message, + bool close_conn) { + const char* m = (message != NULL && message[0] != '\0') ? message : "unknown failure"; + + elog(WARNING, "pg_stat_ch: %s: %s", context, m); + exp->consecutive_failures++; + if (close_conn) + CloseConnection(exp); +} + +static void SetReadDeadline(ClickHouseExporter* exp) { + const int64 dl = MonotonicNowUs() + (int64)kSocketTimeoutSec * 1000000; + + if (psch_clickhouse_use_tls) + chc_openssl_io_set_deadline(&exp->openssl_io, dl); + else + chc_posix_io_set_deadline(&exp->posix_io, dl); +} + +static bool TcpConnect(ClickHouseExporter* exp, const char* host, int port) { + struct addrinfo hints; + struct addrinfo* res = NULL; + char port_s[16]; + int fd = -1; + int save_errno = ECONNREFUSED; + int rc; + const int one = 1; + struct timeval tv; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + snprintf(port_s, sizeof port_s, "%d", port); + + rc = getaddrinfo(host, port_s, &hints, &res); + if (rc != 0) { + elog(WARNING, "pg_stat_ch: getaddrinfo(%s:%d): %s", host, port, gai_strerror(rc)); + return false; + } + + for (struct addrinfo* ai = res; ai != NULL; ai = ai->ai_next) { + fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (fd < 0) { + save_errno = errno; + continue; + } + if (ConnectWithTimeout(fd, ai->ai_addr, ai->ai_addrlen, kSocketTimeoutSec)) + break; + save_errno = errno; + close(fd); + fd = -1; + } + freeaddrinfo(res); + if (fd < 0) { + elog(WARNING, "pg_stat_ch: connect(%s:%d): %s", host, port, strerror(save_errno)); + return false; + } + + (void)setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof one); + (void)setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); + tv.tv_sec = kSocketTimeoutSec; + tv.tv_usec = 0; + (void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv); + (void)setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv); + exp->fd = fd; + return true; +} + +static bool TlsConnect(ClickHouseExporter* exp, const char* host) { + // OpenSSL 1.1.0+ auto-initializes on first use; no explicit library init. + exp->ssl_ctx = SSL_CTX_new(TLS_client_method()); + if (exp->ssl_ctx == NULL) { + elog(WARNING, "pg_stat_ch: SSL_CTX_new failed"); + return false; + } + if (!psch_clickhouse_skip_tls_verify) { + SSL_CTX_set_verify(exp->ssl_ctx, SSL_VERIFY_PEER, NULL); + if (SSL_CTX_set_default_verify_paths(exp->ssl_ctx) != 1) { + elog(WARNING, "pg_stat_ch: could not load default CA certificates"); + return false; + } + } + + exp->ssl = SSL_new(exp->ssl_ctx); + if (exp->ssl == NULL) { + elog(WARNING, "pg_stat_ch: SSL_new failed"); + return false; + } + if (SSL_set_tlsext_host_name(exp->ssl, host) != 1) { // SNI + elog(WARNING, "pg_stat_ch: could not set TLS SNI host name"); + return false; + } + if (!psch_clickhouse_skip_tls_verify) { + SSL_set_hostflags(exp->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); + if (SSL_set1_host(exp->ssl, host) != 1) { + elog(WARNING, "pg_stat_ch: could not set TLS verification host"); + return false; + } + } + if (SSL_set_fd(exp->ssl, exp->fd) != 1) { + elog(WARNING, "pg_stat_ch: SSL_set_fd failed"); + return false; + } + ERR_clear_error(); // queue is per-thread, drop any residue from a prior retry + if (SSL_connect(exp->ssl) != 1) { + // cert-verify failures leave the error queue empty, so check vr first + const long vr = SSL_get_verify_result(exp->ssl); + char ebuf[256]; + + if (vr != X509_V_OK) { + snprintf(ebuf, sizeof ebuf, "certificate verify failed: %s", + X509_verify_cert_error_string(vr)); + } else { + const unsigned long e = ERR_get_error(); + if (e != 0) + ERR_error_string_n(e, ebuf, sizeof ebuf); // cipher / protocol mismatch etc + else + snprintf(ebuf, sizeof ebuf, "SSL_connect failed"); + } + elog(WARNING, "pg_stat_ch: TLS handshake failed: %s", ebuf); + return false; + } + return true; +} + +static void CloseConnection(ClickHouseExporter* exp) { + if (exp->client != NULL) { + chc_client_close(exp->client); + exp->client = NULL; + } + if (exp->ssl != NULL) { + SSL_shutdown(exp->ssl); + SSL_free(exp->ssl); + exp->ssl = NULL; + } + if (exp->ssl_ctx != NULL) { + SSL_CTX_free(exp->ssl_ctx); + exp->ssl_ctx = NULL; + } + if (exp->fd >= 0) { + close(exp->fd); + exp->fd = -1; + } + ResetConnectionContext(exp); +} + +static bool EstablishNewConnection(ClickHouseExporter* exp) { + const char* host; + int port; + chc_client_opts opts; + chc_err err; + + if (!EnsureMemoryContexts(exp)) + return false; + CloseConnection(exp); + + host = psch_clickhouse_host != NULL ? psch_clickhouse_host : "localhost"; + port = psch_clickhouse_port; + + if (!TcpConnect(exp, host, port)) + return false; + + if (psch_clickhouse_use_tls) { + if (!TlsConnect(exp, host)) { + CloseConnection(exp); + return false; + } + chc_openssl_io_init(&exp->openssl_io, &exp->io, exp->ssl, PschChcCheckCancel, NULL); + } else { + chc_posix_io_init(&exp->posix_io, &exp->io, exp->fd, PschChcCheckCancel, NULL); + } + + chc_lz4_codec_init(&exp->codec); + + // GUC string pointers are consumed synchronously inside chc_client_init; + // never stash them (SIGHUP reload frees the old values). + memset(&opts, 0, sizeof opts); + opts.client_name = "pg_stat_ch"; + opts.database = psch_clickhouse_database != NULL ? psch_clickhouse_database : "pg_stat_ch"; + opts.user = psch_clickhouse_user != NULL ? psch_clickhouse_user : "default"; + opts.password = psch_clickhouse_password != NULL ? psch_clickhouse_password : ""; + opts.compression = CHC_COMP_LZ4; + opts.codec = &exp->codec; + + SetReadDeadline(exp); // bound the Hello / Ping handshake reads + memset(&err, 0, sizeof err); + if (chc_client_init(&exp->client, &opts, &exp->conn_al, &exp->io, &err) != CHC_OK) { + elog(WARNING, "pg_stat_ch: failed to connect to ClickHouse: %s", + err.msg[0] ? err.msg : "init failed"); + if (exp->client != NULL) { + chc_client_close(exp->client); + exp->client = NULL; + } + CloseConnection(exp); + return false; + } + + // Parse all column types eagerly (replaces the old lazy ResolveType map): + // the append path must never allocate type ASTs mid-batch. + for (int t = 0; t < CH_NUM_TYPES; t++) { + chc_err terr = {0}; + if (chc_type_parse(kChTypeNames[t], strlen(kChTypeNames[t]), &exp->conn_al, &exp->types[t], + &terr) != CHC_OK) { + elog(WARNING, "pg_stat_ch: failed to parse ClickHouse type %s: %s", kChTypeNames[t], + terr.msg[0] ? terr.msg : "parse failed"); + CloseConnection(exp); + return false; + } + } + + elog(LOG, "pg_stat_ch: connected to ClickHouse at %s:%d%s", host, port, + psch_clickhouse_use_tls ? " (TLS)" : ""); + return true; +} + +// --------------------------------------------------------------------------- +// INSERT protocol loop +// --------------------------------------------------------------------------- + +// chc_packet_clear runs on EVERY exit path (replaces the old PacketGuard): +// a missed clear leaks server packets — exception payloads included — into +// conn_cxt until the next reconnect. +static bool RecvUntil(ClickHouseExporter* exp, chc_packet_kind target, char* errbuf, + size_t errlen) { + for (int i = 0; i < kMaxRecvPackets; i++) { + chc_packet pkt = {0}; + chc_err err = {0}; + chc_packet_kind kind; + + if (chc_client_recv_packet(exp->client, &pkt, &err) != CHC_OK) { + chc_packet_clear(exp->client, &pkt); + ErrBufSet(errbuf, errlen, err.msg[0] ? err.msg : "recv_packet failed"); + return false; + } + kind = pkt.kind; + if (kind == CHC_PKT_EXCEPTION) { + // display_text is server-controlled and not NUL-terminated; bounded + // copy only — never strcpy/strlcpy from it. + if (pkt.exception != NULL && pkt.exception->display_text != NULL) + ErrBufSetN(errbuf, errlen, pkt.exception->display_text, pkt.exception->display_text_len); + else + ErrBufSet(errbuf, errlen, "server exception"); + chc_packet_clear(exp->client, &pkt); + return false; + } + chc_packet_clear(exp->client, &pkt); + if (kind == target) + return true; + } + ErrBufSet(errbuf, errlen, "too many packets awaiting response"); + return false; +} + +static bool SendInsert(ClickHouseExporter* exp, const chc_block_builder* bb, char* errbuf, + size_t errlen) { + chc_err err = {0}; + + SetReadDeadline(exp); + + if (chc_client_send_query(exp->client, exp->insert_query, exp->insert_query_len, "", 0, &err) != + CHC_OK) { + ErrBufSet(errbuf, errlen, err.msg[0] ? err.msg : "send_query failed"); + return false; + } + // Server echoes a 0-row Data block describing the target columns. + if (!RecvUntil(exp, CHC_PKT_DATA, errbuf, errlen)) + return false; + + if (chc_client_send_data(exp->client, bb, &err) != CHC_OK) { + ErrBufSet(errbuf, errlen, err.msg[0] ? err.msg : "send_data failed"); + return false; + } + // Empty trailing block terminates the INSERT stream. + if (chc_client_send_data(exp->client, NULL, &err) != CHC_OK) { + ErrBufSet(errbuf, errlen, err.msg[0] ? err.msg : "send_data terminator failed"); + return false; + } + + SetReadDeadline(exp); + return RecvUntil(exp, CHC_PKT_END_OF_STREAM, errbuf, errlen); +} + +// --------------------------------------------------------------------------- +// Column fill (pure memcpy into preallocated buffers; infallible by +// construction: every length is clamped to the buffer reservation first) +// --------------------------------------------------------------------------- + +static inline void PutI16(ChColData* cd, int row, int16 v) { + ((int16*)cd->data)[row] = v; +} +static inline void PutI32(ChColData* cd, int row, int32 v) { + ((int32*)cd->data)[row] = v; +} +static inline void PutI64(ChColData* cd, int row, int64 v) { + ((int64*)cd->data)[row] = v; +} +static inline void PutU8(ChColData* cd, int row, uint8 v) { + ((uint8*)cd->data)[row] = v; +} +static inline void PutU64(ChColData* cd, int row, uint64 v) { + ((uint64*)cd->data)[row] = v; +} + +// Caller guarantees len <= the column's max_len reservation (clamped). +static inline void PutStr(ChColData* cd, int row, const char* src, uint32 len) { + if (len > 0) + memcpy(cd->data + cd->bytes_used, src, len); + cd->bytes_used += len; + cd->offsets[row] = cd->bytes_used; +} + +static void FillColumns(ClickHouseExporter* exp, const PschEvent* events, int n) { + ChColData* cols = exp->cols; + + for (int c = 0; c < CH_NUM_COLS; c++) + cols[c].bytes_used = 0; + + for (int i = 0; i < n; i++) { + const PschEvent* ev = &events[i]; + const char* cmd = PschCmdTypeToString(ev->cmd_type); + uint32 len; + + PutI64(&cols[CH_COL_TS_START], i, ev->ts_start + kPostgresEpochOffsetUs); + PutU64(&cols[CH_COL_DURATION_US], i, ev->duration_us); + + len = ClampFieldLen(ev->datname_len, sizeof(ev->datname), "datname_len"); + PutStr(&cols[CH_COL_DB], i, ev->datname, len); + len = ClampFieldLen(ev->username_len, sizeof(ev->username), "username_len"); + PutStr(&cols[CH_COL_USERNAME], i, ev->username, len); + + PutI32(&cols[CH_COL_PID], i, ev->pid); + PutI64(&cols[CH_COL_QUERY_ID], i, (int64)ev->queryid); + PutStr(&cols[CH_COL_CMD_TYPE], i, cmd, (uint32)strlen(cmd)); + PutU64(&cols[CH_COL_ROWS], i, ev->rows); + + len = ClampFieldLen(ev->query_len, PSCH_MAX_QUERY_LEN, "query_len"); + PutStr(&cols[CH_COL_QUERY], i, ev->query, len); + + PutI64(&cols[CH_COL_SHARED_BLKS_HIT], i, ev->shared_blks_hit); + PutI64(&cols[CH_COL_SHARED_BLKS_READ], i, ev->shared_blks_read); + PutI64(&cols[CH_COL_SHARED_BLKS_DIRTIED], i, ev->shared_blks_dirtied); + PutI64(&cols[CH_COL_SHARED_BLKS_WRITTEN], i, ev->shared_blks_written); + PutI64(&cols[CH_COL_LOCAL_BLKS_HIT], i, ev->local_blks_hit); + PutI64(&cols[CH_COL_LOCAL_BLKS_READ], i, ev->local_blks_read); + PutI64(&cols[CH_COL_LOCAL_BLKS_DIRTIED], i, ev->local_blks_dirtied); + PutI64(&cols[CH_COL_LOCAL_BLKS_WRITTEN], i, ev->local_blks_written); + PutI64(&cols[CH_COL_TEMP_BLKS_READ], i, ev->temp_blks_read); + PutI64(&cols[CH_COL_TEMP_BLKS_WRITTEN], i, ev->temp_blks_written); + + PutI64(&cols[CH_COL_SHARED_BLK_READ_TIME_US], i, ev->shared_blk_read_time_us); + PutI64(&cols[CH_COL_SHARED_BLK_WRITE_TIME_US], i, ev->shared_blk_write_time_us); + PutI64(&cols[CH_COL_LOCAL_BLK_READ_TIME_US], i, ev->local_blk_read_time_us); + PutI64(&cols[CH_COL_LOCAL_BLK_WRITE_TIME_US], i, ev->local_blk_write_time_us); + PutI64(&cols[CH_COL_TEMP_BLK_READ_TIME_US], i, ev->temp_blk_read_time_us); + PutI64(&cols[CH_COL_TEMP_BLK_WRITE_TIME_US], i, ev->temp_blk_write_time_us); + + PutI64(&cols[CH_COL_WAL_RECORDS], i, ev->wal_records); + PutI64(&cols[CH_COL_WAL_FPI], i, ev->wal_fpi); + PutU64(&cols[CH_COL_WAL_BYTES], i, ev->wal_bytes); + + PutI64(&cols[CH_COL_CPU_USER_TIME_US], i, ev->cpu_user_time_us); + PutI64(&cols[CH_COL_CPU_SYS_TIME_US], i, ev->cpu_sys_time_us); + + PutI32(&cols[CH_COL_JIT_FUNCTIONS], i, ev->jit_functions); + PutI32(&cols[CH_COL_JIT_GENERATION_TIME_US], i, ev->jit_generation_time_us); + PutI32(&cols[CH_COL_JIT_DEFORM_TIME_US], i, ev->jit_deform_time_us); + PutI32(&cols[CH_COL_JIT_INLINING_TIME_US], i, ev->jit_inlining_time_us); + PutI32(&cols[CH_COL_JIT_OPTIMIZATION_TIME_US], i, ev->jit_optimization_time_us); + PutI32(&cols[CH_COL_JIT_EMISSION_TIME_US], i, ev->jit_emission_time_us); + + PutI16(&cols[CH_COL_PARALLEL_WORKERS_PLANNED], i, ev->parallel_workers_planned); + PutI16(&cols[CH_COL_PARALLEL_WORKERS_LAUNCHED], i, ev->parallel_workers_launched); + + // FixedString(5): err_sqlstate[6] always holds >= 5 bytes, NUL-filled + // when shorter — a verbatim 5-byte copy matches the old NUL-padded slab. + memcpy(cols[CH_COL_ERR_SQLSTATE].data + (size_t)i * 5, ev->err_sqlstate, 5); + PutU8(&cols[CH_COL_ERR_ELEVEL], i, ev->err_elevel); + len = ClampFieldLen(ev->err_message_len, PSCH_MAX_ERR_MSG_LEN, "err_message_len"); + PutStr(&cols[CH_COL_ERR_MESSAGE], i, ev->err_message, len); + + len = ClampFieldLen(ev->application_name_len, PSCH_MAX_APP_NAME_LEN, "app_name_len"); + PutStr(&cols[CH_COL_APP], i, ev->application_name, len); + len = ClampFieldLen(ev->client_addr_len, PSCH_MAX_CLIENT_ADDR_LEN, "client_addr_len"); + PutStr(&cols[CH_COL_CLIENT_ADDR], i, ev->client_addr, len); + } +} + +static void AppendColumn(ClickHouseExporter* exp, int col, size_t n_rows) { + const ChColDesc* d = &kChCols[col]; + const ChColData* cd = &exp->cols[col]; + + if (exp->build_err.code != CHC_OK) + return; + + if (d->kind == CH_KIND_STRING) { + chc_block_builder_append_string(exp->bb, d->name, strlen(d->name), cd->offsets, + (const uint8_t*)cd->data, n_rows, &exp->build_err); + return; + } + + // Eager parse at connect guarantees the type; unreachable unless the + // commit path ran without a connection. + if (exp->types[d->type_id] == NULL) { + exp->build_err.code = CHC_ERR_USAGE; + snprintf(exp->build_err.msg, sizeof exp->build_err.msg, "type %s not parsed", + kChTypeNames[d->type_id]); + return; + } + chc_block_builder_append_fixed(exp->bb, d->name, strlen(d->name), exp->types[d->type_id], + cd->data, n_rows, &exp->build_err); +} + +// One INSERT for up to chunk_rows events. The goto tail replaces the three +// C++ RAII guards: destroy the live builder, clear the slot, and ALWAYS +// reset the batch context — a missed reset is unbounded TopMemoryContext +// growth (the original SIGABRT failure class). +static PschExportStatus ChCommitChunk(ClickHouseExporter* exp, const PschEvent* events, int n) { + PschExportStatus status; + chc_block_builder* bb = NULL; + chc_err err = {0}; + char errbuf[256]; + bool sent; + + if (!MemoryContextsReady(exp)) { + RecordFailure(exp, "ClickHouse commit failed", "allocator not initialized", false); + return PSCH_EXPORT_ERR_NOMEM; + } + + if (chc_block_builder_init(&bb, &exp->batch_al, &err) != CHC_OK) { + RecordFailure(exp, "block builder init failed", err.msg[0] ? err.msg : "OOM", false); + status = PSCH_EXPORT_ERR_NOMEM; + goto done; + } + exp->bb = bb; + + if (exp->client == NULL && (!EstablishNewConnection(exp) || exp->client == NULL)) { + RecordFailure(exp, "ClickHouse connection failed", "connection not established", false); + status = PSCH_EXPORT_ERR_CONN; + goto done; + } + + FillColumns(exp, events, n); + + chc_err_reset(&exp->build_err); + for (int c = 0; c < CH_NUM_COLS; c++) + AppendColumn(exp, c, (size_t)n); + if (exp->build_err.code != CHC_OK) { + RecordFailure(exp, "failed to build ClickHouse block", + exp->build_err.msg[0] ? exp->build_err.msg : "block build failed", false); + status = PSCH_EXPORT_ERR_INTERNAL; + goto done; + } + + elog(DEBUG1, "pg_stat_ch: Inserting Block to ClickHouse"); + exp->in_flight = true; // survives a longjmp; forces reconnect on next entry + sent = SendInsert(exp, exp->bb, errbuf, sizeof errbuf); + exp->in_flight = false; // a returned failure closes the connection below + if (!sent) { + RecordFailure(exp, "failed to insert to ClickHouse", errbuf, true); + status = PSCH_EXPORT_ERR_SEND; + goto done; + } + + elog(DEBUG1, "pg_stat_ch: exported %d events to ClickHouse", n); + status = PSCH_EXPORT_OK; + +done: + if (exp->bb != NULL) { + chc_block_builder_destroy(exp->bb); + exp->bb = NULL; + } + ResetBatchContext(exp); + return status; +} + +// --------------------------------------------------------------------------- +// PschExporterOps implementation +// --------------------------------------------------------------------------- + +static bool ChConnect(PschExporter* self, char* errbuf, size_t errlen) { + ClickHouseExporter* exp = (ClickHouseExporter*)self; + + if (exp->in_flight) { + CloseConnection(exp); + exp->in_flight = false; + } + if (!EstablishNewConnection(exp)) { + ErrBufSet(errbuf, errlen, "could not connect to ClickHouse"); + exp->consecutive_failures++; + return false; + } + return true; +} + +static bool ChIsConnected(const PschExporter* self) { + const ClickHouseExporter* exp = (const ClickHouseExporter*)self; + return exp->client != NULL; +} + +static PschExportStatus ChExportEvents(PschExporter* self, const PschEvent* events, int nevents, + int* exported_out) { + ClickHouseExporter* exp = (ClickHouseExporter*)self; + int done = 0; + + if (exported_out != NULL) + *exported_out = 0; + + // Recover from a longjmp that interrupted the previous call: drop any live + // builder (the context reset reclaims its memory) and force a reconnect if + // a wire exchange was cut mid-protocol — the server would still be waiting + // for INSERT data on the old stream. + exp->bb = NULL; + ResetBatchContext(exp); + if (exp->in_flight) { + elog(WARNING, "pg_stat_ch: previous ClickHouse exchange was interrupted; reconnecting"); + CloseConnection(exp); + exp->in_flight = false; + } + + if (events == NULL || nevents <= 0) + return PSCH_EXPORT_OK; + + // The driver stages at most chunk_rows (== PschExportArenaPlan.staging_events) + // per call, so this loop normally runs once; the split only guards against + // a caller exceeding the preallocated column capacity. + while (done < nevents) { + int n = Min(nevents - done, exp->chunk_rows); + PschExportStatus status = ChCommitChunk(exp, events + done, n); + + if (status != PSCH_EXPORT_OK) + return status; + done += n; + } + + exp->consecutive_failures = 0; + if (exported_out != NULL) + *exported_out = nevents; + return PSCH_EXPORT_OK; +} + +static int ChConsecutiveFailures(const PschExporter* self) { + return ((const ClickHouseExporter*)self)->consecutive_failures; +} + +static void ChResetFailures(PschExporter* self) { + ((ClickHouseExporter*)self)->consecutive_failures = 0; +} + +static uint64 ChMemUsed(const PschExporter* self) { + return ((const ClickHouseExporter*)self)->mem_used; +} + +static void ChDestroy(PschExporter* self) { + ClickHouseExporter* exp = (ClickHouseExporter*)self; + + if (exp == NULL) + return; + // A longjmp may have left a builder live inside batch_cxt; the context + // delete below reclaims its memory, so only the pointer is dropped here. + exp->bb = NULL; + CloseConnection(exp); + if (exp->batch_cxt != NULL) { + MemoryContextDelete(exp->batch_cxt); + exp->batch_cxt = NULL; + } + if (exp->col_cxt != NULL) { + MemoryContextDelete(exp->col_cxt); + exp->col_cxt = NULL; + } + if (exp->conn_cxt != NULL) { + MemoryContextDelete(exp->conn_cxt); + exp->conn_cxt = NULL; + } + pfree(exp); +} + +// --------------------------------------------------------------------------- +// Creation +// --------------------------------------------------------------------------- + +static char* BuildInsertQuery(ClickHouseExporter* exp, size_t* len_out) { + static const char kPrefix[] = "INSERT INTO events_raw ("; + static const char kSuffix[] = ") VALUES"; + size_t need = (sizeof kPrefix - 1) + (sizeof kSuffix - 1); + char* q; + char* p; + + for (int c = 0; c < CH_NUM_COLS; c++) + need += strlen(kChCols[c].name) + (c != 0 ? 2 : 0); + + q = (char*)MemoryContextAllocExtended(exp->col_cxt, need + 1, MCXT_ALLOC_NO_OOM); + if (q == NULL) + return NULL; + + p = q; + memcpy(p, kPrefix, sizeof kPrefix - 1); + p += sizeof kPrefix - 1; + for (int c = 0; c < CH_NUM_COLS; c++) { + size_t l = strlen(kChCols[c].name); + + if (c != 0) { + *p++ = ','; + *p++ = ' '; + } + memcpy(p, kChCols[c].name, l); + p += l; + } + memcpy(p, kSuffix, sizeof kSuffix - 1); + p += sizeof kSuffix - 1; + *p = '\0'; + + Assert((size_t)(p - q) == need); + *len_out = need; + return q; +} + +PschExporter* PschClickHouseExporterCreate(char* errbuf, size_t errlen) { + ClickHouseExporter* exp; + const PschMemoryBudget* budget; + PschExportArenaPlan plan; + + exp = (ClickHouseExporter*)MemoryContextAllocExtended( + TopMemoryContext, sizeof(ClickHouseExporter), MCXT_ALLOC_NO_OOM | MCXT_ALLOC_ZERO); + if (exp == NULL) { + ErrBufSet(errbuf, errlen, "out of memory allocating ClickHouse exporter"); + return NULL; + } + exp->base.ops = &kClickHouseOps; + exp->fd = -1; + exp->mem_used = sizeof(ClickHouseExporter); + + if (!EnsureMemoryContexts(exp)) { + ErrBufSet(errbuf, errlen, "out of memory creating exporter memory contexts"); + goto fail; + } + + // Buffer sizes are init-time constants: the budget is resolved once per + // process, deliberately independent of SIGHUP-reloadable GUCs. + budget = PschMemoryBudgetGet(); + PschExportArenaSplit(budget->export_arena_bytes, &plan); + exp->chunk_rows = plan.staging_events > 0 ? plan.staging_events : 256; + + for (int c = 0; c < CH_NUM_COLS; c++) { + const ChColDesc* d = &kChCols[c]; + size_t data_bytes; + + Assert(d->name != NULL); + Assert(d->kind == CH_KIND_STRING ? d->max_len > 0 : d->elem_size > 0); + + if (d->kind == CH_KIND_STRING) { + size_t off_bytes = (size_t)exp->chunk_rows * sizeof(uint64_t); + + data_bytes = (size_t)exp->chunk_rows * d->max_len; + exp->cols[c].offsets = (uint64_t*)MemoryContextAllocExtended( + exp->col_cxt, off_bytes, MCXT_ALLOC_NO_OOM | MCXT_ALLOC_HUGE); + if (exp->cols[c].offsets == NULL) + goto oom; + exp->mem_used += off_bytes; + } else { + data_bytes = (size_t)exp->chunk_rows * d->elem_size; + } + + exp->cols[c].data = (char*)MemoryContextAllocExtended(exp->col_cxt, data_bytes, + MCXT_ALLOC_NO_OOM | MCXT_ALLOC_HUGE); + if (exp->cols[c].data == NULL) + goto oom; + exp->mem_used += data_bytes; + } + + exp->insert_query = BuildInsertQuery(exp, &exp->insert_query_len); + if (exp->insert_query == NULL) + goto oom; + exp->mem_used += exp->insert_query_len + 1; + + return &exp->base; + +oom: + ErrBufSet(errbuf, errlen, "out of memory preallocating ClickHouse column buffers"); +fail: + ChDestroy(&exp->base); + return NULL; +} diff --git a/src/export/clickhouse_exporter.cc b/src/export/clickhouse_exporter.cc deleted file mode 100644 index aaaf2f8..0000000 --- a/src/export/clickhouse_exporter.cc +++ /dev/null @@ -1,771 +0,0 @@ -// pg_stat_ch ClickHouse exporter implementation - -extern "C" { -#include "postgres.h" - -#include "miscadmin.h" // ProcDiePending -#include "utils/memutils.h" -#include "utils/palloc.h" -} - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "clickhouse-client.h" -#include "clickhouse-compression.h" -#include "clickhouse-openssl.h" -#include "clickhouse-posix-io.h" -#include "clickhouse.h" - -#include "config/guc.h" -#include "export/exporter_interface.h" -#include "queue/shmem.h" // PschRecordExportFailure - -// Abort blocking reads when bgworker receives SIGTERM -extern "C" { -static bool PschChcCheckCancel(void* /*ud*/) { - return ProcDiePending != 0; -} -} - -namespace { - -constexpr int kSocketTimeoutSec = 30; - -// Bound packets consumed while awaiting response -constexpr int kMaxRecvPackets = 4096; - -void* PschChcAlloc(void* ud, size_t bytes) { - return MemoryContextAllocExtended(static_cast(ud), bytes, - MCXT_ALLOC_HUGE | MCXT_ALLOC_NO_OOM); -} - -void* PschChcRealloc(void* ud, void* p, size_t /*old_bytes*/, size_t new_bytes) { - if (p == nullptr) - return PschChcAlloc(ud, new_bytes); - return repalloc_extended(p, new_bytes, MCXT_ALLOC_HUGE | MCXT_ALLOC_NO_OOM); -} - -void PschChcFree(void* /*ud*/, void* p, size_t /*bytes*/) { - if (p != nullptr) - pfree(p); -} - -chc_alloc MakePschChcAlloc(MemoryContext cxt) { - return {cxt, PschChcAlloc, PschChcRealloc, PschChcFree}; -} - -int64_t MonotonicNowUs() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (static_cast(ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); -} - -// Restore blocking mode after bounded connect, clickhouse-c I/O expects it -bool ConnectWithTimeout(int fd, const struct sockaddr* sa, socklen_t slen, int timeout_sec) { - int flags = fcntl(fd, F_GETFL, 0); - if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) - return false; - - bool ok = false; - int save_errno = 0; - if (connect(fd, sa, slen) == 0) { - ok = true; - } else if (errno == EINPROGRESS) { - const int64_t deadline = MonotonicNowUs() + static_cast(timeout_sec) * 1000000; - for (;;) { - const int64_t remaining_us = deadline - MonotonicNowUs(); - if (remaining_us <= 0) { - save_errno = ETIMEDOUT; - break; - } - struct pollfd pfd = {fd, POLLOUT, 0}; - int pr = poll(&pfd, 1, static_cast((remaining_us + 999) / 1000)); - if (pr < 0) { - if (errno == EINTR) - continue; // signal (eg bgworker latch); retry within deadline - save_errno = errno; - break; - } - if (pr == 0) { - save_errno = ETIMEDOUT; - break; - } - int soerr = 0; - socklen_t l = sizeof soerr; - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &soerr, &l) < 0) { - save_errno = errno; - break; - } - save_errno = soerr; - ok = soerr == 0; - break; - } - } else { - save_errno = errno; - } - - // Always restore blocking mode, even on failure: keeps the helper safe to - // reuse and matches clickhouse-c I/O expectations - if (fcntl(fd, F_SETFL, flags) < 0) - return false; - if (!ok) - errno = save_errno; - return ok; -} - -struct ChcBlockBuilderDeleter { - void operator()(chc_block_builder* bb) const { chc_block_builder_destroy(bb); } -}; - -using ChcBlockBuilderPtr = std::unique_ptr; - -class ClickHouseExporter : public StatsExporter { - public: - ClickHouseExporter() = default; - ~ClickHouseExporter() override { - CloseConnection(); - ClearTypes(); - if (batch_cxt_ != nullptr) - MemoryContextDelete(batch_cxt_); - if (conn_cxt_ != nullptr) - MemoryContextDelete(conn_cxt_); - } - - // Server casts String to LowCardinality(String) on INSERT - shared_ptr> TagString(string_view name) final { - return MakeCol>(name); - } - shared_ptr> MetricInt16(string_view name) final { - return MakeCol>(name, "Int16"); - } - shared_ptr> MetricInt32(string_view name) final { - return MakeCol>(name, "Int32"); - } - shared_ptr> MetricInt64(string_view name) final { - return MakeCol>(name, "Int64"); - } - shared_ptr> MetricUInt8(string_view name) final { - return MakeCol>(name, "UInt8"); - } - shared_ptr> MetricUInt64(string_view name) final { - return MakeCol>(name, "UInt64"); - } - shared_ptr> MetricFixedString(int len, string_view name) final { - return MakeCol(name, len); - } - - shared_ptr> RecordInt16(string_view name) final { - return MakeCol>(name, "Int16"); - } - shared_ptr> RecordInt32(string_view name) final { - return MakeCol>(name, "Int32"); - } - shared_ptr> RecordInt64(string_view name) final { - return MakeCol>(name, "Int64"); - } - shared_ptr> RecordUInt8(string_view name) final { - return MakeCol>(name, "UInt8"); - } - shared_ptr> RecordUInt64(string_view name) final { - return MakeCol>(name, "UInt64"); - } - shared_ptr> RecordDateTime(string_view name) final { - return MakeCol>(name, "DateTime64(6)"); - } - shared_ptr> RecordString(string_view name) final { - return MakeCol>(name); - } - - shared_ptr> DbNameColumn() final { return TagString("db"); } - shared_ptr> DbUserColumn() final { return TagString("username"); } - shared_ptr> DbDurationColumn() final { return MetricUInt64("duration_us"); } - shared_ptr> DbOperationColumn() final { return TagString("cmd_type"); } - shared_ptr> DbQueryTextColumn() final { return RecordString("query"); } - - void BeginBatch() final { - for (auto& col : columns_) - col->Clear(); - exported_count_ = 0; - } - void BeginRow() final { ++exported_count_; } - bool CommitBatch() final; - - bool EstablishNewConnection() final; - bool IsConnected() const final { return client_ != nullptr; } - int NumConsecutiveFailures() const final { return consecutive_failures_; } - void ResetFailures() final { consecutive_failures_ = 0; } - int NumExported() const final { return exported_count_; } - - private: - template - class FixedCol : public Column { - public: - FixedCol(ClickHouseExporter* exp, string_view name, const char* type_name) - : exp_(exp), name_(name), type_name_(type_name) {} - void Append(const T& v) final { data_.push_back(v); } - void Crunch() final { exp_->AppendFixed(name_, type_name_, data_.data(), data_.size()); } - void Clear() final { data_.clear(); } - - private: - ClickHouseExporter* const exp_; - const std::string name_; - const char* const type_name_; - std::vector data_; - }; - - template - class StringCol : public Column { - public: - StringCol(ClickHouseExporter* exp, string_view name) : exp_(exp), name_(name) {} - void Append(const T& s) final { - bytes_.insert(bytes_.end(), s.data(), s.data() + s.size()); - offsets_.push_back(bytes_.size()); - } - void Crunch() final { - exp_->AppendString(name_, offsets_.data(), reinterpret_cast(bytes_.data()), - offsets_.size()); - } - void Clear() final { - bytes_.clear(); - offsets_.clear(); - } - - private: - ClickHouseExporter* const exp_; - const std::string name_; - std::vector bytes_; - std::vector offsets_; - }; - - class FixedStringCol : public Column { - public: - FixedStringCol(ClickHouseExporter* exp, string_view name, int n) - : exp_(exp), - name_(name), - width_(static_cast(n)), - type_name_("FixedString(" + std::to_string(n) + ")") {} - void Append(const string_view& s) final { - const size_t start = data_.size(); - data_.resize(start + width_, '\0'); - std::memcpy(data_.data() + start, s.data(), std::min(s.size(), width_)); - ++rows_; - } - void Crunch() final { exp_->AppendFixed(name_, type_name_.c_str(), data_.data(), rows_); } - void Clear() final { - data_.clear(); - rows_ = 0; - } - - private: - ClickHouseExporter* const exp_; - const std::string name_; - const size_t width_; - const std::string type_name_; - std::vector data_; - size_t rows_ = 0; - }; - - template - shared_ptr MakeCol(string_view name, Args&&... args) { - if (auto it = col_index_.find(name); it != col_index_.end()) { - if (auto col = std::dynamic_pointer_cast(columns_[it->second])) - return col; - - throw std::logic_error("ClickHouse column `" + std::string(name) + - "` requested with incompatible type"); - } - - std::string key(name); - auto col = std::make_shared(this, key, std::forward(args)...); - const size_t index = columns_.size(); - - columns_.reserve(index + 1); - col_names_.reserve(index + 1); - try { - columns_.push_back(col); - col_names_.push_back(key); - col_index_.emplace(col_names_.back(), index); - } catch (...) { - columns_.resize(index); - col_names_.resize(index); - throw; - } - return col; - } - - const chc_type* ResolveType(const char* type_name); - - void AppendFixed(string_view name, const char* type_name, const void* data, size_t n_rows); - void AppendString(string_view name, const uint64_t* offsets, const uint8_t* data, size_t n_rows); - - bool RecordFailure(const char* context, const char* message, bool close_conn); - bool EnsureMemoryContexts(); - bool MemoryContextsReady() const { return conn_cxt_ != nullptr && batch_cxt_ != nullptr; } - void ClearTypes(); - void ResetBatchContext(); - void ResetConnectionContext(); - bool TcpConnect(const char* host, int port); - bool TlsConnect(const char* host); - void CloseConnection(); - void SetReadDeadline(); - std::string BuildInsertQuery() const; - bool SendInsert(const chc_block_builder* bb, std::string& err_out); - bool RecvUntil(chc_packet_kind target, std::string& err_out); - - MemoryContext conn_cxt_ = nullptr; - MemoryContext batch_cxt_ = nullptr; - chc_alloc conn_al_{}; - chc_alloc batch_al_{}; - chc_client* client_ = nullptr; - int fd_ = -1; - SSL_CTX* ssl_ctx_ = nullptr; - SSL* ssl_ = nullptr; - chc_posix_io posix_io_{}; - chc_openssl_io openssl_io_{}; - chc_io io_{}; - chc_codec codec_{}; - - chc_block_builder* bb_ = nullptr; - chc_err build_err_{}; - - std::map> types_; - std::vector> columns_; - std::map> col_index_; // name -> index in columns_ - std::vector col_names_; - int consecutive_failures_ = 0; - int exported_count_ = 0; -}; - -// Sole longjmp source in the connection path: AllocSetContextCreate ereports on -// OOM. Swallow it here so EstablishNewConnection stays a pure bool — callers -// then need no PG_TRY frame around it. elog.c leaves CurrentMemoryContext at -// ErrorContext after a caught error, so restore it before returning. -bool ClickHouseExporter::EnsureMemoryContexts() { - if (MemoryContextsReady()) - return true; - - MemoryContext oldcontext = CurrentMemoryContext; - PG_TRY(); - { - if (conn_cxt_ == nullptr) - conn_cxt_ = AllocSetContextCreate(TopMemoryContext, "pg_stat_ch clickhouse-c", - ALLOCSET_DEFAULT_SIZES); - if (batch_cxt_ == nullptr) - batch_cxt_ = AllocSetContextCreate(TopMemoryContext, "pg_stat_ch clickhouse-c batch", - ALLOCSET_DEFAULT_SIZES); - } - PG_CATCH(); - { - MemoryContextSwitchTo(oldcontext); - if (batch_cxt_ != nullptr) { - MemoryContextDelete(batch_cxt_); - batch_cxt_ = nullptr; - } - if (conn_cxt_ != nullptr) { - MemoryContextDelete(conn_cxt_); - conn_cxt_ = nullptr; - } - conn_al_ = {}; - batch_al_ = {}; - EmitErrorReport(); - FlushErrorState(); - return false; - } - PG_END_TRY(); - - conn_al_ = MakePschChcAlloc(conn_cxt_); - batch_al_ = MakePschChcAlloc(batch_cxt_); - return true; -} - -void ClickHouseExporter::ClearTypes() { - for (auto& kv : types_) - chc_type_destroy(kv.second, &conn_al_); - types_.clear(); -} - -void ClickHouseExporter::ResetBatchContext() { - if (batch_cxt_ != nullptr) { - MemoryContextReset(batch_cxt_); - batch_al_ = MakePschChcAlloc(batch_cxt_); - } -} - -void ClickHouseExporter::ResetConnectionContext() { - ClearTypes(); - if (conn_cxt_ != nullptr) { - MemoryContextReset(conn_cxt_); - conn_al_ = MakePschChcAlloc(conn_cxt_); - } -} - -bool ClickHouseExporter::RecordFailure(const char* context, const char* message, bool close_conn) { - const char* m = message != nullptr ? message : "unknown failure"; - elog(WARNING, "pg_stat_ch: %s: %s", context, m); - ++consecutive_failures_; - PschRecordExportFailure(m); - if (close_conn) - CloseConnection(); - return false; -} - -const chc_type* ClickHouseExporter::ResolveType(const char* type_name) { - auto it = types_.find(type_name); - if (it != types_.end()) - return it->second; - chc_type* t = nullptr; - chc_err err = {}; - if (chc_type_parse(type_name, std::strlen(type_name), &conn_al_, &t, &err) != CHC_OK) { - build_err_ = err; - return nullptr; - } - types_.emplace(type_name, t); - return t; -} - -void ClickHouseExporter::AppendFixed(string_view name, const char* type_name, const void* data, - size_t n_rows) { - if (build_err_.code != CHC_OK) - return; - const chc_type* t = ResolveType(type_name); - if (t == nullptr) - return; - chc_block_builder_append_fixed(bb_, name.data(), name.size(), t, data, n_rows, &build_err_); -} - -void ClickHouseExporter::AppendString(string_view name, const uint64_t* offsets, - const uint8_t* data, size_t n_rows) { - if (build_err_.code != CHC_OK) - return; - chc_block_builder_append_string(bb_, name.data(), name.size(), offsets, data, n_rows, - &build_err_); -} - -std::string ClickHouseExporter::BuildInsertQuery() const { - std::string q = "INSERT INTO events_raw ("; - for (size_t i = 0; i < col_names_.size(); ++i) { - if (i != 0) - q += ", "; - q += col_names_[i]; - } - q += ") VALUES"; - return q; -} - -void ClickHouseExporter::SetReadDeadline() { - const int64_t dl = MonotonicNowUs() + static_cast(kSocketTimeoutSec) * 1000000; - if (psch_clickhouse_use_tls) - chc_openssl_io_set_deadline(&openssl_io_, dl); - else - chc_posix_io_set_deadline(&posix_io_, dl); -} - -bool ClickHouseExporter::RecvUntil(chc_packet_kind target, std::string& err_out) { - struct PacketGuard { - chc_client* client; - chc_packet* packet; - ~PacketGuard() { chc_packet_clear(client, packet); } - }; - - for (int i = 0; i < kMaxRecvPackets; ++i) { - chc_packet pkt = {}; - chc_err err = {}; - if (chc_client_recv_packet(client_, &pkt, &err) != CHC_OK) { - err_out = err.msg[0] ? err.msg : "recv_packet failed"; - return false; - } - PacketGuard guard{client_, &pkt}; - const chc_packet_kind kind = pkt.kind; - if (kind == CHC_PKT_EXCEPTION) { - if (pkt.exception != nullptr && pkt.exception->display_text != nullptr) - err_out.assign(pkt.exception->display_text, pkt.exception->display_text_len); - else - err_out = "server exception"; - return false; - } - if (kind == target) - return true; - } - err_out = "too many packets awaiting response"; - return false; -} - -bool ClickHouseExporter::SendInsert(const chc_block_builder* bb, std::string& err_out) { - chc_err err = {}; - SetReadDeadline(); - - const std::string query = BuildInsertQuery(); - if (chc_client_send_query(client_, query.data(), query.size(), "", 0, &err) != CHC_OK) { - err_out = err.msg[0] ? err.msg : "send_query failed"; - return false; - } - // Server echoes a 0-row Data block describing the target columns. - if (!RecvUntil(CHC_PKT_DATA, err_out)) - return false; - - if (chc_client_send_data(client_, bb, &err) != CHC_OK) { - err_out = err.msg[0] ? err.msg : "send_data failed"; - return false; - } - // Empty trailing block terminates the INSERT stream. - if (chc_client_send_data(client_, nullptr, &err) != CHC_OK) { - err_out = err.msg[0] ? err.msg : "send_data terminator failed"; - return false; - } - - SetReadDeadline(); - return RecvUntil(CHC_PKT_END_OF_STREAM, err_out); -} - -bool ClickHouseExporter::CommitBatch() { - struct ActiveBuilder { - chc_block_builder*& slot; - ~ActiveBuilder() { slot = nullptr; } - }; - struct BatchReset { - ClickHouseExporter* exporter; - ~BatchReset() { exporter->ResetBatchContext(); } - }; - - try { - if (!MemoryContextsReady()) - return RecordFailure("ClickHouse commit failed", "allocator not initialized", false); - - BatchReset reset{this}; - chc_block_builder* raw_bb = nullptr; - chc_err err = {}; - if (chc_block_builder_init(&raw_bb, &batch_al_, &err) != CHC_OK) { - return RecordFailure("block builder init failed", err.msg[0] ? err.msg : "OOM", false); - } - ChcBlockBuilderPtr bb(raw_bb); - - bb_ = bb.get(); - ActiveBuilder active{bb_}; - - if (client_ == nullptr && (!EstablishNewConnection() || client_ == nullptr)) { - return RecordFailure("ClickHouse connection failed", "connection not established", false); - } - - build_err_ = {}; - for (const auto& col : columns_) - col->Crunch(); - if (build_err_.code != CHC_OK) { - return RecordFailure("failed to build ClickHouse block", - build_err_.msg[0] ? build_err_.msg : "block build failed", false); - } - - elog(DEBUG1, "pg_stat_ch: Inserting Block to ClickHouse"); - std::string emsg; - if (!SendInsert(bb.get(), emsg)) { - return RecordFailure("failed to insert to ClickHouse", emsg.c_str(), true); - } - - consecutive_failures_ = 0; - elog(DEBUG1, "pg_stat_ch: exported %d events to ClickHouse", exported_count_); - return true; - } catch (const std::bad_alloc&) { - return RecordFailure("ClickHouse commit failed", "out of memory", true); - } catch (const std::exception& e) { - return RecordFailure("ClickHouse commit failed", e.what(), true); - } -} - -bool ClickHouseExporter::TcpConnect(const char* host, int port) { - struct addrinfo hints = {}; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - char port_s[16]; - snprintf(port_s, sizeof port_s, "%d", port); - - struct addrinfo* res = nullptr; - const int rc = getaddrinfo(host, port_s, &hints, &res); - if (rc != 0) { - elog(WARNING, "pg_stat_ch: getaddrinfo(%s:%d): %s", host, port, gai_strerror(rc)); - return false; - } - - int fd = -1; - int save_errno = ECONNREFUSED; - for (struct addrinfo* ai = res; ai != nullptr; ai = ai->ai_next) { - fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (fd < 0) { - save_errno = errno; - continue; - } - if (ConnectWithTimeout(fd, ai->ai_addr, ai->ai_addrlen, kSocketTimeoutSec)) - break; - save_errno = errno; - close(fd); - fd = -1; - } - freeaddrinfo(res); - if (fd < 0) { - elog(WARNING, "pg_stat_ch: connect(%s:%d): %s", host, port, strerror(save_errno)); - return false; - } - - const int one = 1; - (void)setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof one); - (void)setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); - struct timeval tv = {kSocketTimeoutSec, 0}; - (void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv); - (void)setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv); - fd_ = fd; - return true; -} - -bool ClickHouseExporter::TlsConnect(const char* host) { - // OpenSSL 1.1.0+ auto-initializes on first use; no explicit library init. - ssl_ctx_ = SSL_CTX_new(TLS_client_method()); - if (ssl_ctx_ == nullptr) { - elog(WARNING, "pg_stat_ch: SSL_CTX_new failed"); - return false; - } - if (!psch_clickhouse_skip_tls_verify) { - SSL_CTX_set_verify(ssl_ctx_, SSL_VERIFY_PEER, nullptr); - if (SSL_CTX_set_default_verify_paths(ssl_ctx_) != 1) { - elog(WARNING, "pg_stat_ch: could not load default CA certificates"); - return false; - } - } - - ssl_ = SSL_new(ssl_ctx_); - if (ssl_ == nullptr) { - elog(WARNING, "pg_stat_ch: SSL_new failed"); - return false; - } - if (SSL_set_tlsext_host_name(ssl_, host) != 1) { // SNI - elog(WARNING, "pg_stat_ch: could not set TLS SNI host name"); - return false; - } - if (!psch_clickhouse_skip_tls_verify) { - SSL_set_hostflags(ssl_, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); - if (SSL_set1_host(ssl_, host) != 1) { - elog(WARNING, "pg_stat_ch: could not set TLS verification host"); - return false; - } - } - if (SSL_set_fd(ssl_, fd_) != 1) { - elog(WARNING, "pg_stat_ch: SSL_set_fd failed"); - return false; - } - ERR_clear_error(); // queue is per-thread, drop any residue from a prior retry - if (SSL_connect(ssl_) != 1) { - // cert-verify failures leave the error queue empty, so check vr first - const long vr = SSL_get_verify_result(ssl_); - char ebuf[256]; - if (vr != X509_V_OK) { - snprintf(ebuf, sizeof ebuf, "certificate verify failed: %s", - X509_verify_cert_error_string(vr)); - } else if (const unsigned long e = ERR_get_error()) { - ERR_error_string_n(e, ebuf, sizeof ebuf); // cipher / protocol mismatch etc - } else { - snprintf(ebuf, sizeof ebuf, "SSL_connect failed"); - } - elog(WARNING, "pg_stat_ch: TLS handshake failed: %s", ebuf); - return false; - } - return true; -} - -void ClickHouseExporter::CloseConnection() { - if (client_ != nullptr) { - chc_client_close(client_); - client_ = nullptr; - } - if (ssl_ != nullptr) { - SSL_shutdown(ssl_); - SSL_free(ssl_); - ssl_ = nullptr; - } - if (ssl_ctx_ != nullptr) { - SSL_CTX_free(ssl_ctx_); - ssl_ctx_ = nullptr; - } - if (fd_ >= 0) { - close(fd_); - fd_ = -1; - } - ResetConnectionContext(); -} - -bool ClickHouseExporter::EstablishNewConnection() { - if (!EnsureMemoryContexts()) - return false; - CloseConnection(); - - const char* host = psch_clickhouse_host != nullptr ? psch_clickhouse_host : "localhost"; - const int port = psch_clickhouse_port; - - if (!TcpConnect(host, port)) - return false; - - if (psch_clickhouse_use_tls) { - if (!TlsConnect(host)) { - CloseConnection(); - return false; - } - chc_openssl_io_init(&openssl_io_, &io_, ssl_, PschChcCheckCancel, nullptr); - } else { - chc_posix_io_init(&posix_io_, &io_, fd_, PschChcCheckCancel, nullptr); - } - - chc_lz4_codec_init(&codec_); - - chc_client_opts opts = {}; - opts.client_name = "pg_stat_ch"; - opts.database = psch_clickhouse_database != nullptr ? psch_clickhouse_database : "pg_stat_ch"; - opts.user = psch_clickhouse_user != nullptr ? psch_clickhouse_user : "default"; - opts.password = psch_clickhouse_password != nullptr ? psch_clickhouse_password : ""; - opts.compression = CHC_COMP_LZ4; - opts.codec = &codec_; - - SetReadDeadline(); // bound the Hello / Ping handshake reads - chc_err err = {}; - if (chc_client_init(&client_, &opts, &conn_al_, &io_, &err) != CHC_OK) { - elog(WARNING, "pg_stat_ch: failed to connect to ClickHouse: %s", - err.msg[0] ? err.msg : "init failed"); - if (client_ != nullptr) { - chc_client_close(client_); - client_ = nullptr; - } - CloseConnection(); - return false; - } - - elog(LOG, "pg_stat_ch: connected to ClickHouse at %s:%d%s", host, port, - psch_clickhouse_use_tls ? " (TLS)" : ""); - return true; -} - -} // namespace - -std::unique_ptr MakeClickHouseExporter() { - return std::make_unique(); -} diff --git a/src/export/clickhouse_exporter.h b/src/export/clickhouse_exporter.h deleted file mode 100644 index 13442d1..0000000 --- a/src/export/clickhouse_exporter.h +++ /dev/null @@ -1,11 +0,0 @@ -// pg_stat_ch ClickHouse exporter -#ifndef PG_STAT_CH_SRC_EXPORT_CLICKHOUSE_EXPORTER_H_ -#define PG_STAT_CH_SRC_EXPORT_CLICKHOUSE_EXPORTER_H_ - -#include "export/exporter_interface.h" - -#include - -std::unique_ptr MakeClickHouseExporter(); - -#endif // PG_STAT_CH_SRC_EXPORT_CLICKHOUSE_EXPORTER_H_ From e9697b9ad072a8e9d48067fb7281f3eebe5b84a7 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:48 -0500 Subject: [PATCH 08/11] feat(queue,worker): peek/commit dequeue, requeue semantics, SIGABRT backstop Port the export driver to C and harden the failure path (OTEL_REWRITE_DESIGN.md section 5a): - shmem.c gains two-phase consume: PschPeekEvents resolves DSA strings without freeing or advancing the tail; PschConsumeEvents frees and advances. Slot dsa_pointers are cleared BEFORE freeing so a longjmp out of dsa_free leaks rather than double-frees on retry. - Failure routing: ERR_CONN never consumes (events survive a collector outage); ERR_SEND requeues until a poison threshold; ERR_NOMEM/ERR_INTERNAL drop. A mid-chunk Arrow failure counts already-delivered events as exported and only drops/requeues the undelivered remainder. New export_dropped counter, distinct from enqueue overflow. Every failure mode increments the backoff counter. - bgworker.c installs a SIGABRT backstop (async-signal-safe write + _exit(1)) so a residual abort costs a bgworker restart, not database-wide crash recovery; SIGSEGV/SIGBUS keep full crash semantics. Drain loop is bounded per cycle so procsignal barriers are processed promptly. Ring-sanity check at worker start. --- src/export/stats_exporter.c | 424 +++++++++++++++++++++++++++ src/export/stats_exporter.cc | 544 ----------------------------------- src/export/stats_exporter.h | 36 +-- src/queue/psch_dsa.h | 3 + src/queue/query_intern.c | 19 +- src/queue/query_intern.h | 8 + src/queue/shmem.c | 307 +++++++++++++++----- src/queue/shmem.h | 36 ++- src/worker/bgworker.c | 94 ++++-- 9 files changed, 809 insertions(+), 662 deletions(-) create mode 100644 src/export/stats_exporter.c delete mode 100644 src/export/stats_exporter.cc diff --git a/src/export/stats_exporter.c b/src/export/stats_exporter.c new file mode 100644 index 0000000..b6ceb57 --- /dev/null +++ b/src/export/stats_exporter.c @@ -0,0 +1,424 @@ +// pg_stat_ch statistics export driver. +// +// Owns the bgworker-side export pipeline: peek a chunk of events from the +// shmem ring into a preallocated staging buffer, dispatch it to the selected +// backend (ClickHouse native or OTLP/HTTP, optionally as Arrow IPC), then +// consume or requeue per OTEL_REWRITE_DESIGN.md §5a. +// +// Memory discipline: the staging chunk and the Arrow builder are preallocated +// in PschExporterInit (the only place allowed to ereport(FATAL)); the export +// path performs zero heap allocation and never ereport(ERROR)s. A longjmp +// can still arrive from elsewhere (bgworker.c PG_CATCHes around us), so batch +// state is reset on entry and no non-reclaimable resource is held across PG +// calls — every buffer here lives for the worker's lifetime. + +#include "postgres.h" + +#include "utils/timestamp.h" + +#include "pg_stat_ch/pg_stat_ch.h" +#include "config/guc.h" +#include "config/memory_budget.h" +#include "export/arrow_batch.h" +#include "export/exporter.h" +#include "export/stats_exporter.h" +#include "queue/event.h" +#include "queue/shmem.h" + +// PostgreSQL epoch is 2000-01-01, Unix epoch is 1970-01-01: +// 946684800 seconds = 946684800000000 microseconds. +static const int64 kPostgresEpochOffsetUs = INT64CONST(946684800000000); + +// Exponential backoff: 1s * 2^(n-1), capped at 60s. kMaxConsecutiveFailures +// both caps the exponent (shift stays well under 31 bits) and arms the +// poison-batch valve in PschExportBatch. +static const int kBaseDelayMs = 1000; +static const int kMaxDelayMs = 60000; +static const int kMaxConsecutiveFailures = 10; + +// Bound on the psch_extra_attributes change-detection snapshot. Matches the +// builder's own preallocated attribute storage order of magnitude; a change +// beyond this bound is not detected, which is the same truncation the builder +// applies anyway (arrow_batch.h). +#define PSCH_ATTRS_SNAPSHOT_CAP 2048 + +// Bgworker-local exporter state. Everything is preallocated in +// PschExporterInit and released only in PschExporterShutdown. +static PschExporter* g_exporter = NULL; +static PschEvent* g_staging = NULL; +static int g_staging_cap = 0; +static PschArrowBuilder* g_arrow = NULL; +static char g_attrs_snapshot[PSCH_ATTRS_SNAPSHOT_CAP]; + +static void MaybeDumpArrowBatch(const uint8* data, size_t len) { + unsigned long long unix_now_ns; + char path[MAXPGPATH]; + char tmp_path[MAXPGPATH]; + FILE* file; + size_t written; + + if (data == NULL || len == 0 || psch_debug_arrow_dump_dir == NULL || + *psch_debug_arrow_dump_dir == '\0') { + return; + } + + unix_now_ns = + (unsigned long long)((GetCurrentTimestamp() + kPostgresEpochOffsetUs) * INT64CONST(1000)); + snprintf(path, sizeof(path), "%s/arrow_%llu.ipc", psch_debug_arrow_dump_dir, unix_now_ns); + snprintf(tmp_path, sizeof(tmp_path), "%s/arrow_%llu.ipc.tmp", psch_debug_arrow_dump_dir, + unix_now_ns); + + file = fopen(tmp_path, "wb"); + if (file == NULL) { + elog(WARNING, "pg_stat_ch: failed to open Arrow dump file '%s'", tmp_path); + return; + } + + written = fwrite(data, 1, len, file); + fclose(file); + if (written != len) { + remove(tmp_path); + elog(WARNING, "pg_stat_ch: short Arrow dump write to '%s' (%zu/%zu bytes)", tmp_path, written, + len); + return; + } + + // tmp + rename keeps test readers (t/026_arrow_dump.pl) from ever seeing a + // partially-written payload. + if (rename(tmp_path, path) != 0) { + remove(tmp_path); + elog(WARNING, "pg_stat_ch: failed to finalize Arrow dump file '%s'", path); + } +} + +// Re-parse extra_attributes after a SIGHUP changed the GUC. The snapshot is +// updated even when the re-parse fails so a persistently-bad value warns once +// per change, not once per batch (the 2/sec flood class this rewrite kills). +static void MaybeRefreshArrowAttributes(void) { + const char* attrs = (psch_extra_attributes != NULL) ? psch_extra_attributes : ""; + + if (strncmp(attrs, g_attrs_snapshot, sizeof(g_attrs_snapshot) - 1) == 0) { + return; + } + if (!PschArrowBuilderSetAttributes(g_arrow, attrs)) { + elog(WARNING, + "pg_stat_ch: failed to apply pg_stat_ch.extra_attributes; keeping previous attributes"); + } + strlcpy(g_attrs_snapshot, attrs, sizeof(g_attrs_snapshot)); +} + +// Finish + dump + send + reset the accumulated Arrow rows. On success adds +// the sent rows to *flushed_rows. An empty builder is a successful no-op. +static PschExportStatus FlushArrowBuilder(PschExporter* ex, int* flushed_rows) { + const uint8* data = NULL; + size_t len = 0; + int rows = 0; + PschExportStatus status; + + if (!PschArrowBuilderFinish(g_arrow, &data, &len, &rows)) { + return PSCH_EXPORT_ERR_INTERNAL; + } + if (rows <= 0 || data == NULL || len == 0) { + PschArrowBuilderReset(g_arrow); + return PSCH_EXPORT_OK; + } + + MaybeDumpArrowBatch(data, len); + + if (ex->ops->send_arrow == NULL) { + return PSCH_EXPORT_ERR_INTERNAL; + } + status = ex->ops->send_arrow(ex, data, len, rows); + if (status != PSCH_EXPORT_OK) { + return status; + } + + *flushed_rows += rows; + PschArrowBuilderReset(g_arrow); + return PSCH_EXPORT_OK; +} + +// Arrow passthrough path: append the chunk, flushing whenever the builder +// reports FULL. *exported_out is set to the number of rows actually delivered +// to the collector (sum of successful sub-batch flushes), on BOTH success and +// failure returns. This lets the caller count already-delivered events as +// exported and avoid dropping or re-sending them when a later sub-batch fails +// mid-chunk. +static PschExportStatus ExportChunkAsArrow(PschExporter* ex, const PschEvent* events, int n, + int* exported_out) { + int flushed = 0; + int i; + + *exported_out = 0; + if (g_arrow == NULL) { + return PSCH_EXPORT_ERR_INTERNAL; + } + + MaybeRefreshArrowAttributes(); + + // A longjmp may have interrupted the previous batch mid-build; start clean. + PschArrowBuilderReset(g_arrow); + + for (i = 0; i < n; i++) { + PschArrowAppendResult res = PschArrowBuilderAppend(g_arrow, &events[i]); + + if (res == PSCH_ARROW_APPEND_FULL) { + PschExportStatus status = FlushArrowBuilder(ex, &flushed); + if (status != PSCH_EXPORT_OK) { + *exported_out = flushed; + return status; + } + res = PschArrowBuilderAppend(g_arrow, &events[i]); + } + if (res != PSCH_ARROW_APPEND_OK) { + // FULL on a fresh builder means a single un-appendable event: an + // INTERNAL failure so the poison-batch path drops it instead of + // wedging the ring. + *exported_out = flushed; + return PSCH_EXPORT_ERR_INTERNAL; + } + } + + if (PschArrowBuilderNumRows(g_arrow) > 0) { + PschExportStatus status = FlushArrowBuilder(ex, &flushed); + if (status != PSCH_EXPORT_OK) { + *exported_out = flushed; + return status; + } + } + + *exported_out = flushed; + return PSCH_EXPORT_OK; +} + +// Initialize the exporter: select the backend per psch_use_otel (POSTMASTER +// GUC, read once), preallocate the staging chunk and — for the OTel backend — +// the Arrow builder. Both OTel paths are preallocated up front because +// otel_arrow_passthrough is SIGHUP-switchable. Allocation/creation failure +// is FATAL (clean bgworker-only restart; bgworker.c registered the shutdown +// callback before calling us, so half-initialized state is reclaimed). +// A connect failure is NOT fatal: events stay queued and the first export +// cycle retries. +bool PschExporterInit(void) { + const PschMemoryBudget* budget; + PschExportArenaPlan plan; + char errbuf[256]; + + if (g_exporter != NULL || g_staging != NULL) { + PschExporterShutdown(); + } + + budget = PschMemoryBudgetGet(); + PschExportArenaSplit(budget->export_arena_bytes, &plan); + + g_staging = malloc(plan.staging_bytes); + if (g_staging == NULL) { + ereport(FATAL, (errmsg("pg_stat_ch: out of memory preallocating %zu-byte export staging " + "buffer; bgworker will be restarted", + plan.staging_bytes))); + } + g_staging_cap = plan.staging_events; + + errbuf[0] = '\0'; + if (psch_use_otel) { + g_exporter = PschOtelExporterCreate(errbuf, sizeof(errbuf)); + } else { + g_exporter = PschClickHouseExporterCreate(errbuf, sizeof(errbuf)); + } + if (g_exporter == NULL) { + ereport(FATAL, + (errmsg("pg_stat_ch: failed to create %s exporter: %s; bgworker will be restarted", + psch_use_otel ? "OTel" : "ClickHouse", + errbuf[0] != '\0' ? errbuf : "unknown error"))); + } + + if (psch_use_otel) { + PschArrowBuilderConfig cfg; + const char* attrs = (psch_extra_attributes != NULL) ? psch_extra_attributes : ""; + + memset(&cfg, 0, sizeof(cfg)); + cfg.scratch_budget_bytes = plan.arrow_scratch_bytes; + cfg.ipc_budget_bytes = plan.encode_buf_bytes; + cfg.max_rows = plan.staging_events; + cfg.extra_attributes = attrs; + cfg.service_version = PG_STAT_CH_VERSION; + + errbuf[0] = '\0'; + g_arrow = PschArrowBuilderCreate(&cfg, errbuf, sizeof(errbuf)); + if (g_arrow == NULL) { + ereport(FATAL, + (errmsg("pg_stat_ch: failed to create Arrow batch builder: %s; bgworker will be " + "restarted", + errbuf[0] != '\0' ? errbuf : "unknown error"))); + } + strlcpy(g_attrs_snapshot, attrs, sizeof(g_attrs_snapshot)); + } + + elog(DEBUG1, "pg_stat_ch: exporter initialized (staging=%d events, arena=" UINT64_FORMAT "B)", + g_staging_cap, budget->export_arena_bytes); + + errbuf[0] = '\0'; + if (!g_exporter->ops->connect(g_exporter, errbuf, sizeof(errbuf))) { + elog(DEBUG1, "pg_stat_ch: initial exporter connect failed: %s", + errbuf[0] != '\0' ? errbuf : "unknown error"); + return false; + } + return true; +} + +// Export one staged chunk. Returns the number of events exported; 0 on +// empty queue or any failure (the bgworker drain loop breaks on 0 and the +// consecutive-failure state drives backoff — never return a count for a +// failed-but-requeued chunk or the loop spins hot against a dead collector). +int PschExportBatch(void) { + PschExporter* ex = g_exporter; + PschExportStatus status; + int exported = 0; + int n; + + if (ex == NULL || g_staging == NULL) { + return 0; + } + + // Connection check BEFORE peek: a collector/server outage leaves events + // queued (they survive until the ring overflows, which drops newest-first + // at the producers — preferable to losing already-captured events). + if (!ex->ops->is_connected(ex)) { + char errbuf[256]; + + errbuf[0] = '\0'; + if (!ex->ops->connect(ex, errbuf, sizeof(errbuf))) { + PschRecordExportFailure(errbuf[0] != '\0' ? errbuf : "failed to connect to exporter backend"); + return 0; + } + } + + n = PschPeekEvents(g_staging, g_staging_cap); + if (n <= 0) { + return 0; + } + + if (psch_use_otel && psch_otel_arrow_passthrough) { + status = ExportChunkAsArrow(ex, g_staging, n, &exported); + } else { + status = ex->ops->export_events(ex, g_staging, n, &exported); + } + + if (status == PSCH_EXPORT_OK) { + PschConsumeEvents(n); + if (psch_shared_state != NULL && exported > 0) { + pg_atomic_fetch_add_u64(&psch_shared_state->exported, (uint64)exported); + } + PschRecordExportSuccess(); + return exported; + } + + // On a mid-chunk failure the Arrow path may have already delivered a prefix + // of `exported` events (the per-record path always reports 0 on failure). + // Those events are in ClickHouse: count them, never drop them, never re-send + // them. Only the undelivered remainder is requeued or dropped. `exported` + // is bounded by n, so `undelivered` is non-negative. + int undelivered = n - exported; + + if (psch_shared_state != NULL && exported > 0) { + pg_atomic_fetch_add_u64(&psch_shared_state->exported, (uint64)exported); + } + + switch (status) { + case PSCH_EXPORT_ERR_CONN: + // Consume only the delivered prefix; the undelivered remainder is + // retried once the connection recovers. + if (exported > 0) { + PschConsumeEvents(exported); + } + PschRecordExportFailure("exporter connection failed"); + break; + + case PSCH_EXPORT_ERR_SEND: + if (ex->ops->consecutive_failures(ex) >= kMaxConsecutiveFailures) { + // Poison-batch valve: a chunk that keeps failing to send must not + // wedge the ring forever. Consume the whole chunk; drop only the + // undelivered remainder (the prefix was delivered, counted above). + PschConsumeEvents(n); + if (undelivered > 0) { + PschRecordExportDrop(undelivered); + } + PschRecordExportFailure("send failed repeatedly; batch dropped"); + elog(WARNING, "pg_stat_ch: dropping %d events after %d consecutive send failures", + undelivered, ex->ops->consecutive_failures(ex)); + } else { + // Consume the delivered prefix; requeue the undelivered remainder so a + // retry does not re-send the events already accepted by the collector. + if (exported > 0) { + PschConsumeEvents(exported); + } + PschRecordExportFailure("exporter send failed"); + } + break; + + case PSCH_EXPORT_ERR_NOMEM: + case PSCH_EXPORT_ERR_INTERNAL: + // Build/encode failures are a property of the batch, not the wire: + // retrying the identical bytes cannot succeed, so drop the undelivered + // remainder immediately (the delivered prefix was counted above). + PschConsumeEvents(n); + if (undelivered > 0) { + PschRecordExportDrop(undelivered); + } + PschRecordExportFailure(status == PSCH_EXPORT_ERR_NOMEM + ? "exporter out of memory; batch dropped" + : "exporter internal error; batch dropped"); + elog(WARNING, "pg_stat_ch: dropping %d events after %s", undelivered, + status == PSCH_EXPORT_ERR_NOMEM ? "exporter OOM" : "internal export error"); + break; + + default: + PschRecordExportFailure("unexpected export status"); + break; + } + + return 0; +} + +int PschGetRetryDelayMs(void) { + int failures; + int capped; + int delay; + + if (g_exporter == NULL) { + return 0; + } + failures = g_exporter->ops->consecutive_failures(g_exporter); + if (failures <= 0) { + return 0; + } + capped = (failures > kMaxConsecutiveFailures) ? kMaxConsecutiveFailures : failures; + delay = kBaseDelayMs * (1 << (capped - 1)); + return (delay > kMaxDelayMs) ? kMaxDelayMs : delay; +} + +int PschGetConsecutiveFailures(void) { + if (g_exporter == NULL) { + return 0; + } + return g_exporter->ops->consecutive_failures(g_exporter); +} + +// Idempotent; runs from the on_proc_exit chain, possibly after a FATAL that +// interrupted PschExporterInit, so every member is NULL-guarded and backend +// destroy must tolerate half-initialized state (exporter.h contract). +void PschExporterShutdown(void) { + if (g_exporter != NULL) { + g_exporter->ops->destroy(g_exporter); + g_exporter = NULL; + } + if (g_arrow != NULL) { + PschArrowBuilderDestroy(g_arrow); + g_arrow = NULL; + } + free(g_staging); + g_staging = NULL; + g_staging_cap = 0; + g_attrs_snapshot[0] = '\0'; + elog(LOG, "pg_stat_ch: statistics exporter shutdown"); +} diff --git a/src/export/stats_exporter.cc b/src/export/stats_exporter.cc deleted file mode 100644 index f4f2f06..0000000 --- a/src/export/stats_exporter.cc +++ /dev/null @@ -1,544 +0,0 @@ -// pg_stat_ch statistics exporter implementation - -extern "C" { -#include "postgres.h" - -#include "utils/timestamp.h" -} - -#include -#include -#include -#include -#include -#include - -#include "config/guc.h" -#include "export/arrow_batch.h" -#include "export/clickhouse_exporter.h" -#include "export/exporter_interface.h" -#include "export/otel_exporter.h" -#include "export/stats_exporter.h" -#include "queue/event.h" -#include "queue/shmem.h" - -namespace { - -// PostgreSQL epoch is 2000-01-01, Unix epoch is 1970-01-01 -// Difference is 946684800 seconds = 946684800000000 microseconds -constexpr int64_t kPostgresEpochOffsetUs = 946684800000000LL; - -// Exponential backoff constants -constexpr int kBaseDelayMs = 1000; // 1 second -constexpr int kMaxDelayMs = 60000; // 60 seconds -constexpr int kMaxConsecutiveFailures = 10; // Cap for exponential growth - -// Exporter state - encapsulates all bgworker-local state -struct ExporterState { - std::unique_ptr exporter; -}; - -// [[clang::no_destroy]] (Clang only — GCC has no equivalent). Suppresses -// the implicit exit-time destructor on namespace-scope variables that need -// one. PschExporterShutdown (registered with on_proc_exit) resets -// g_exporter.exporter before the C++ atexit chain ever runs, so the -// implicit ~ExporterState would be a no-op anyway. Making the suppression -// explicit satisfies -Werror=global-constructors (Clang's -// "namespace-scope variable with non-trivial dtor" diagnostic). -#if __has_cpp_attribute(clang::no_destroy) -#define PSCH_NO_DESTROY [[clang::no_destroy]] -#else -#define PSCH_NO_DESTROY -#endif - -// Bgworker-local exporter state (no locking needed). -PSCH_NO_DESTROY ExporterState g_exporter; - -// Catch-all for C++ exceptions that escape every explicit barrier in the -// extension. The default std::terminate calls abort() -> SIGABRT, which the -// postmaster treats as a backend crash and uses to trigger DB-wide crash -// recovery (every connection severed, WAL replayed). Routing through -// ereport(FATAL) instead gives us a clean proc_exit(1): postmaster respawns -// just our bgworker on its bgw_restart_time. The explicit catches elsewhere -// in this file still run first when they apply — this handler is only the -// backstop for whatever they miss. -// -// The handler is installed inside PschExporterInit (below) rather than from -// _PG_init: after the C99 port of the plugin layer, _PG_init lives in C and -// cannot call std::set_terminate, and PschExporterInit is the first C++ code -// that runs in the bgworker — the only process that ever executes our C++ -// exception-throwing code paths. -[[noreturn]] void PschTerminateHandler() noexcept { - if (auto eptr = std::current_exception()) { - try { - std::rethrow_exception(eptr); - } catch (const std::bad_alloc&) { - ereport(FATAL, (errmsg("pg_stat_ch: uncaught std::bad_alloc"))); - } catch (const std::exception& e) { - ereport(FATAL, (errmsg("pg_stat_ch: uncaught C++ exception: %s", e.what()))); - } catch (...) { - ereport(FATAL, (errmsg("pg_stat_ch: uncaught non-standard C++ exception"))); - } - } else { - ereport(FATAL, (errmsg("pg_stat_ch: std::terminate called without an active exception"))); - } - pg_unreachable(); -} - -// Clamp a field length to its buffer maximum, warning on overflow. -template -LenT ClampFieldLen(LenT len, LenT max, const char* field_name) { - if (len <= max) - return len; - elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, static_cast(len)); - return max; -} - -// Dequeue events from the shared memory queue -std::vector DequeueEvents(int max_events) { - std::vector events; - events.reserve(max_events); - - PschEvent event; - while (events.size() < static_cast(max_events) && PschDequeueEvent(&event)) { - events.push_back(event); - } - return events; -} - -void MaybeDumpArrowBatch(const uint8_t* data, size_t len) { - if (data == nullptr || len == 0 || psch_debug_arrow_dump_dir == nullptr || - *psch_debug_arrow_dump_dir == '\0') { - return; - } - - const auto unix_now_ns = - static_cast((GetCurrentTimestamp() + kPostgresEpochOffsetUs) * 1000LL); - char path[MAXPGPATH]; - char tmp_path[MAXPGPATH]; - snprintf(path, sizeof(path), "%s/arrow_%llu.ipc", psch_debug_arrow_dump_dir, unix_now_ns); - snprintf(tmp_path, sizeof(tmp_path), "%s/arrow_%llu.ipc.tmp", psch_debug_arrow_dump_dir, - unix_now_ns); - - FILE* file = fopen(tmp_path, "wb"); - if (file == nullptr) { - elog(WARNING, "pg_stat_ch: failed to open Arrow dump file '%s'", tmp_path); - return; - } - - const size_t written = fwrite(data, 1, len, file); - fclose(file); - if (written != len) { - remove(tmp_path); - elog(WARNING, "pg_stat_ch: short Arrow dump write to '%s' (%zu/%zu bytes)", tmp_path, written, - len); - return; - } - - if (rename(tmp_path, path) != 0) { - remove(tmp_path); - elog(WARNING, "pg_stat_ch: failed to finalize Arrow dump file '%s'", path); - } -} - -int ExportEventsAsArrowInternal(const std::vector& events, StatsExporter* exporter) { - ArrowBatchBuilder builder; - if (!builder.Init(psch_extra_attributes, PG_STAT_CH_VERSION)) { - LogExporterWarning("Arrow init", "failed to initialize Arrow batch builder"); - RecordExporterFailure("Arrow batch builder init failed"); - return 0; - } - - const size_t max_block_bytes = - std::max(65536, static_cast(psch_otel_max_block_bytes)); - int total_exported = 0; - bool export_failed = false; - - auto flush_builder = [&]() -> bool { - ArrowBatchBuilder::FinishResult result = builder.Finish(); - if (result.ipc_buffer == nullptr || result.num_rows <= 0) { - return false; - } - - const auto ipc_len = static_cast(result.ipc_buffer->size()); - MaybeDumpArrowBatch(result.ipc_buffer->data(), ipc_len); - if (!exporter->SendArrowBatch(result.ipc_buffer->data(), ipc_len, result.num_rows)) { - return false; - } - - total_exported += result.num_rows; - return true; - }; - - for (const auto& event : events) { - if (!builder.Append(event)) { - export_failed = true; - break; - } - if (builder.EstimatedBytes() >= max_block_bytes) { - if (!flush_builder()) { - export_failed = true; - break; - } - builder.Reset(); - } - } - - if (!export_failed && builder.NumRows() > 0 && !flush_builder()) { - export_failed = true; - } - - if (export_failed) { - RecordExporterFailure("Arrow batch build/send failed"); - } - - // INVARIANT: `builder` (and any other C++ RAII object) is still live below. - // The PG calls that follow — pg_atomic_fetch_add_u64, PschRecordExportSuccess, - // RecordExporterFailure — must not longjmp, or builder's Arrow/protobuf/ZSTD - // allocations leak (heap, not palloc) when destructors are skipped. None - // longjmp today (LWLock acquire is not interruptible; atomics are pure), - // but if you add a PG call here that can longjmp (elog(ERROR), table_open, - // SPI, etc.), wrap the builder ops above in a nested {} block first so it - // destructs before this point. - if (!export_failed && total_exported > 0) { - if (psch_shared_state != nullptr) { - pg_atomic_fetch_add_u64(&psch_shared_state->exported, total_exported); - } - PschRecordExportSuccess(); - } - - return total_exported; -} - -// Exception barrier: Arrow + protobuf + ZSTD allocate via ::operator new and -// throw std::bad_alloc on OOM. Catching here keeps the bgworker from unwinding -// across PostgreSQL's PG_TRY/longjmp frames. -int ExportEventsAsArrow(const std::vector& events, StatsExporter* exporter) { - try { - return ExportEventsAsArrowInternal(events, exporter); - } catch (const std::bad_alloc&) { - LogExporterWarning("Arrow export", "out of memory"); - RecordExporterFailure("Arrow export OOM"); - return 0; - } catch (const std::exception& e) { - LogExporterWarning("Arrow export exception", e.what()); - RecordExporterFailure(e.what()); - return 0; - } -} - -// Build and export stats (records, metrics, ClickHouse rows) from events -void ExportEventStatsInternal(const std::vector& events, StatsExporter* exporter) { - elog(DEBUG1, "pg_stat_ch: ExportEventStatsInternal() called with %zu events", events.size()); - - exporter->BeginBatch(); - - auto col_ts_start = exporter->RecordDateTime("ts_start"); - auto col_duration_us = exporter->DbDurationColumn(); - auto col_db = exporter->DbNameColumn(); - auto col_username = exporter->DbUserColumn(); - auto col_pid = exporter->RecordInt32("pid"); - auto col_query_id = exporter->RecordInt64("query_id"); - auto col_cmd_type = exporter->DbOperationColumn(); - auto col_rows = exporter->MetricUInt64("rows"); - auto col_query = exporter->DbQueryTextColumn(); - - auto col_shared_blks_hit = exporter->MetricInt64("shared_blks_hit"); - auto col_shared_blks_read = exporter->MetricInt64("shared_blks_read"); - auto col_shared_blks_dirtied = exporter->RecordInt64("shared_blks_dirtied"); - auto col_shared_blks_written = exporter->RecordInt64("shared_blks_written"); - auto col_local_blks_hit = exporter->RecordInt64("local_blks_hit"); - auto col_local_blks_read = exporter->RecordInt64("local_blks_read"); - auto col_local_blks_dirtied = exporter->RecordInt64("local_blks_dirtied"); - auto col_local_blks_written = exporter->RecordInt64("local_blks_written"); - auto col_temp_blks_read = exporter->RecordInt64("temp_blks_read"); - auto col_temp_blks_written = exporter->RecordInt64("temp_blks_written"); - - auto col_shared_blk_read_time_us = exporter->RecordInt64("shared_blk_read_time_us"); - auto col_shared_blk_write_time_us = exporter->RecordInt64("shared_blk_write_time_us"); - auto col_local_blk_read_time_us = exporter->RecordInt64("local_blk_read_time_us"); - auto col_local_blk_write_time_us = exporter->RecordInt64("local_blk_write_time_us"); - auto col_temp_blk_read_time_us = exporter->RecordInt64("temp_blk_read_time_us"); - auto col_temp_blk_write_time_us = exporter->RecordInt64("temp_blk_write_time_us"); - - auto col_wal_records = exporter->RecordInt64("wal_records"); - auto col_wal_fpi = exporter->RecordInt64("wal_fpi"); - auto col_wal_bytes = exporter->RecordUInt64("wal_bytes"); - - auto col_cpu_user_time_us = exporter->RecordInt64("cpu_user_time_us"); - auto col_cpu_sys_time_us = exporter->RecordInt64("cpu_sys_time_us"); - - auto col_jit_functions = exporter->RecordInt32("jit_functions"); - auto col_jit_generation_time_us = exporter->RecordInt32("jit_generation_time_us"); - auto col_jit_deform_time_us = exporter->RecordInt32("jit_deform_time_us"); - auto col_jit_inlining_time_us = exporter->RecordInt32("jit_inlining_time_us"); - auto col_jit_optimization_time_us = exporter->RecordInt32("jit_optimization_time_us"); - auto col_jit_emission_time_us = exporter->RecordInt32("jit_emission_time_us"); - - auto col_parallel_workers_planned = exporter->RecordInt16("parallel_workers_planned"); - auto col_parallel_workers_launched = exporter->RecordInt16("parallel_workers_launched"); - - auto col_err_sqlstate = exporter->MetricFixedString(5, "err_sqlstate"); - auto col_err_elevel = exporter->RecordUInt8("err_elevel"); - auto col_err_message = exporter->RecordString("err_message"); - - auto col_app = exporter->RecordString("app"); - auto col_client_addr = exporter->RecordString("client_addr"); - - for (const auto& ev : events) { - exporter->BeginRow(); - - col_ts_start->Append(ev.ts_start + kPostgresEpochOffsetUs); - col_duration_us->Append(ev.duration_us); - col_db->Append(std::string(ev.datname, ev.datname_len)); - col_username->Append(std::string(ev.username, ev.username_len)); - col_pid->Append(ev.pid); - col_query_id->Append(static_cast(ev.queryid)); - col_cmd_type->Append(PschCmdTypeToString(ev.cmd_type)); - col_rows->Append(ev.rows); - - auto qlen = ClampFieldLen(ev.query_len, static_cast(PSCH_MAX_QUERY_LEN), "query_len"); - col_query->Append(std::string(ev.query, qlen)); - - col_shared_blks_hit->Append(ev.shared_blks_hit); - col_shared_blks_read->Append(ev.shared_blks_read); - col_shared_blks_dirtied->Append(ev.shared_blks_dirtied); - col_shared_blks_written->Append(ev.shared_blks_written); - col_local_blks_hit->Append(ev.local_blks_hit); - col_local_blks_read->Append(ev.local_blks_read); - col_local_blks_dirtied->Append(ev.local_blks_dirtied); - col_local_blks_written->Append(ev.local_blks_written); - col_temp_blks_read->Append(ev.temp_blks_read); - col_temp_blks_written->Append(ev.temp_blks_written); - - col_shared_blk_read_time_us->Append(ev.shared_blk_read_time_us); - col_shared_blk_write_time_us->Append(ev.shared_blk_write_time_us); - col_local_blk_read_time_us->Append(ev.local_blk_read_time_us); - col_local_blk_write_time_us->Append(ev.local_blk_write_time_us); - col_temp_blk_read_time_us->Append(ev.temp_blk_read_time_us); - col_temp_blk_write_time_us->Append(ev.temp_blk_write_time_us); - - col_wal_records->Append(ev.wal_records); - col_wal_fpi->Append(ev.wal_fpi); - col_wal_bytes->Append(ev.wal_bytes); - - col_cpu_user_time_us->Append(ev.cpu_user_time_us); - col_cpu_sys_time_us->Append(ev.cpu_sys_time_us); - - col_jit_functions->Append(ev.jit_functions); - col_jit_generation_time_us->Append(ev.jit_generation_time_us); - col_jit_deform_time_us->Append(ev.jit_deform_time_us); - col_jit_inlining_time_us->Append(ev.jit_inlining_time_us); - col_jit_optimization_time_us->Append(ev.jit_optimization_time_us); - col_jit_emission_time_us->Append(ev.jit_emission_time_us); - - col_parallel_workers_planned->Append(ev.parallel_workers_planned); - col_parallel_workers_launched->Append(ev.parallel_workers_launched); - - col_err_sqlstate->Append(std::string_view(ev.err_sqlstate, 5)); - col_err_elevel->Append(ev.err_elevel); - auto elen = ClampFieldLen(ev.err_message_len, static_cast(PSCH_MAX_ERR_MSG_LEN), - "err_message_len"); - col_err_message->Append(std::string(ev.err_message, elen)); - - auto alen = ClampFieldLen(ev.application_name_len, static_cast(PSCH_MAX_APP_NAME_LEN), - "app_name_len"); - auto clen = ClampFieldLen(ev.client_addr_len, static_cast(PSCH_MAX_CLIENT_ADDR_LEN), - "client_addr_len"); - col_app->Append(std::string(ev.application_name, alen)); - col_client_addr->Append(std::string(ev.client_addr, clen)); - } - elog(DEBUG1, "pg_stat_ch: finished processing %zu events", events.size()); -} - -// Exception barrier: protobuf arena, column factories, and per-row appends can -// throw std::bad_alloc. Catching here prevents the throw from crossing the -// bgworker's PG_TRY frame. Returns false on failure so the caller skips -// CommitBatch and avoids flushing partial / stale exporter state. -bool ExportEventStats(const std::vector& events, StatsExporter* exporter) { - try { - ExportEventStatsInternal(events, exporter); - return true; - } catch (const std::bad_alloc&) { - LogExporterWarning("event stats export", "out of memory"); - RecordExporterFailure("event stats OOM"); - return false; - } catch (const std::exception& e) { - LogExporterWarning("event stats exception", e.what()); - RecordExporterFailure(e.what()); - return false; - } -} - -} // namespace - -void LogExporterWarning(const char* context, const char* message) { - ereport(WARNING, errmsg("pg_stat_ch: %s: %s", context, message)); -} - -void RecordExporterFailure(const char* message) { - PschRecordExportFailure(message); -} - -// Used to report negative values, which are not supported by OTel. -void LogNegativeValue(const std::string& column_name, int64_t value) { - static std::chrono::steady_clock::time_point last_log = {}; - auto now = std::chrono::steady_clock::now(); - if (now - last_log > std::chrono::seconds(1)) { - elog(WARNING, "pg_stat_ch: Negative value " INT64_FORMAT " clamped to 0 for column `%s`", value, - column_name.c_str()); - last_log = now; - } -} - -extern "C" { - -// Exception barrier: factory and connection setup allocate via std::make_unique -// and can throw std::bad_alloc. An uncaught throw would unwind out of this -// extern "C" entry point through PostgreSQL's bgworker startup (which has no -// C++ handler), terminating the process via std::terminate -> SIGABRT. The -// postmaster would treat that as a backend crash and trigger DB-wide crash -// recovery. Instead, log FATAL so PostgreSQL records the cause and exits via -// proc_exit; the postmaster respawns just our bgworker on its bgw_restart_time. -// The exporter is the only reason this extension runs, so there is nothing -// useful to do without one — graceful exit is strictly better than limping. -bool PschExporterInit(void) { - // Install the C++ terminate handler before any other C++ work runs in this - // process. See PschTerminateHandler above for the rationale. Idempotent — - // a second call in the same process would just reinstall the same handler. - std::set_terminate(PschTerminateHandler); - - try { - if (psch_use_otel) { - g_exporter.exporter = MakeOpenTelemetryExporter(); - } else { - g_exporter.exporter = MakeClickHouseExporter(); - } - return g_exporter.exporter->EstablishNewConnection(); - } catch (const std::bad_alloc&) { - ereport(FATAL, (errmsg("pg_stat_ch: out of memory constructing exporter; " - "bgworker will be restarted"))); - pg_unreachable(); - } catch (const std::exception& e) { - ereport(FATAL, (errmsg("pg_stat_ch: exception constructing exporter: %s", e.what()))); - pg_unreachable(); - } -} - -// Exception barrier: DequeueEvents reserves a std::vector sized for -// psch_batch_max events and can throw std::bad_alloc. Catching here prevents -// C++ exceptions from escaping this extern "C" entry point or crossing -// PostgreSQL C frames. -int PschExportBatch(void) { - try { - elog(DEBUG1, "pg_stat_ch: PschExportBatch() called"); - StatsExporter* exporter = g_exporter.exporter.get(); - - if (!exporter->IsConnected()) { - elog(DEBUG1, "pg_stat_ch: client is null, initializing"); - if (!exporter->EstablishNewConnection()) { - PschRecordExportFailure("Failed to connect to exporter backend"); - return 0; - } - } - - elog(DEBUG1, "pg_stat_ch: dequeuing events (max=%d)", psch_batch_max); - std::vector events = DequeueEvents(psch_batch_max); - if (events.empty()) { - elog(DEBUG1, "pg_stat_ch: no events to export"); - return 0; - } - - if (psch_use_otel && psch_otel_arrow_passthrough) { - elog(DEBUG1, "pg_stat_ch: exporting batch of %zu events as Arrow IPC", events.size()); - return ExportEventsAsArrow(events, exporter); - } - - elog(DEBUG1, "pg_stat_ch: exporting batch of %zu events", events.size()); - if (!ExportEventStats(events, exporter)) { - return 0; - } - - // INVARIANT: `events` (std::vector) and any other C++ RAII - // object in this scope must not be live across a PG call that can longjmp. - // CommitBatch, pg_atomic_fetch_add_u64, and PschRecordExportSuccess do not - // longjmp today, but if you add a PG call (e.g. elog(ERROR), table_open) - // here, narrow the scope of `events` to a nested {} block first or move - // the call below this point. A longjmp through these frames skips - // destructors and leaks the events buffer (heap, not palloc). - if (exporter->CommitBatch()) { - if (psch_shared_state != nullptr) { - pg_atomic_fetch_add_u64(&psch_shared_state->exported, exporter->NumExported()); - } - PschRecordExportSuccess(); - } - - return exporter->NumExported(); - } catch (const std::bad_alloc&) { - LogExporterWarning("export batch", "out of memory"); - RecordExporterFailure("export batch OOM"); - return 0; - } catch (const std::exception& e) { - LogExporterWarning("export batch exception", e.what()); - RecordExporterFailure(e.what()); - return 0; - } -} - -// Exception barrier: NumConsecutiveFailures / ResetFailures are trivial -// `return int_;` / `member = 0` today, but they are virtual and could grow. -// Match the rest of the C-ABI surface so a future override that allocates -// cannot escape this entry point. -void PschResetRetryState(void) { - try { - if (g_exporter.exporter) - g_exporter.exporter->ResetFailures(); - } catch (const std::exception& e) { - LogExporterWarning("reset retry state exception", e.what()); - } -} - -int PschGetRetryDelayMs(void) { - try { - StatsExporter* exporter = g_exporter.exporter.get(); - if (!exporter) { - return 0; - } - int failures = exporter->NumConsecutiveFailures(); - if (failures <= 0) { - return 0; - } - // Exponential backoff: base * 2^(failures-1), capped at max - int capped_failures = (failures > kMaxConsecutiveFailures) ? kMaxConsecutiveFailures : failures; - int delay = kBaseDelayMs * (1 << (capped_failures - 1)); - return (delay > kMaxDelayMs) ? kMaxDelayMs : delay; - } catch (const std::exception& e) { - LogExporterWarning("retry delay exception", e.what()); - return 0; - } -} - -int PschGetConsecutiveFailures(void) { - try { - return g_exporter.exporter ? g_exporter.exporter->NumConsecutiveFailures() : 0; - } catch (const std::exception& e) { - LogExporterWarning("get failures exception", e.what()); - return 0; - } -} - -// Exception barrier: the OTel exporter's destructors (gRPC stub teardown, -// protobuf arena release) can throw. Catching here prevents the throw from -// crossing the on_proc_exit chain. -void PschExporterShutdown(void) { - try { - g_exporter.exporter.reset(); - } catch (const std::bad_alloc&) { - LogExporterWarning("exporter shutdown", "out of memory"); - } catch (const std::exception& e) { - LogExporterWarning("exporter shutdown exception", e.what()); - } - elog(LOG, "pg_stat_ch: statistics exporter shutdown"); -} - -} // extern "C" diff --git a/src/export/stats_exporter.h b/src/export/stats_exporter.h index 14a48e6..7c60e12 100644 --- a/src/export/stats_exporter.h +++ b/src/export/stats_exporter.h @@ -1,29 +1,33 @@ -// pg_stat_ch statistics exporter +// pg_stat_ch export driver — the C ABI surface bgworker.c drives. +// +// Contract (OTEL_REWRITE_DESIGN.md §5a): +// * PschExporterInit preallocates everything the export path needs; the only +// failure mode is ereport(FATAL) (a worker without its preallocation is +// useless; FATAL -> proc_exit(1) -> clean bgworker-only restart). A false +// return means "created but not yet connected" — events stay queued and +// the first export retries the connect. +// * PschExportBatch never ereport(ERROR)s and performs zero heap allocation. +// Returns the number of events exported; 0 means queue empty OR failure — +// load-bearing for the bgworker drain loop, which must break (and let +// consecutive-failure backoff engage) rather than spin. #ifndef PG_STAT_CH_SRC_EXPORT_STATS_EXPORTER_H_ #define PG_STAT_CH_SRC_EXPORT_STATS_EXPORTER_H_ -#ifdef __cplusplus -extern "C" { -#endif - -#include "postgres.h" - -// Initialize the statistics exporter (called once at bgworker startup) +// Initialize the statistics exporter (called once at bgworker startup). +// Returns true when the initial backend connect succeeded. bool PschExporterInit(void); -// Export one batch. Returns number of events exported (0 = queue empty or error). +// Export one staged chunk. Returns number of events exported (0 = queue empty +// or failure). int PschExportBatch(void); -// Shutdown the exporter and close connection +// Shutdown the exporter and release preallocations. Idempotent; runs from +// the on_proc_exit chain (possibly after a FATAL mid-init), so it tolerates +// half-initialized state and never ereport(ERROR)s. void PschExporterShutdown(void); -// Retry state management for exponential backoff -void PschResetRetryState(void); +// Retry state for exponential backoff (read by the bgworker sleep logic). int PschGetRetryDelayMs(void); int PschGetConsecutiveFailures(void); -#ifdef __cplusplus -} -#endif - #endif // PG_STAT_CH_SRC_EXPORT_STATS_EXPORTER_H_ diff --git a/src/queue/psch_dsa.h b/src/queue/psch_dsa.h index 77db84f..2b6263f 100644 --- a/src/queue/psch_dsa.h +++ b/src/queue/psch_dsa.h @@ -85,6 +85,9 @@ typedef struct PschSharedState { // --- Exporter stats (written by bgworker, read by stats function) -------- pg_atomic_uint64 send_failures; + // Events destructively consumed after export failure (poison-batch valve / + // internal error) — distinct from `dropped`, which counts enqueue overflow. + pg_atomic_uint64 export_dropped; TimestampTz last_success_ts; TimestampTz last_error_ts; char last_error_text[256]; diff --git a/src/queue/query_intern.c b/src/queue/query_intern.c index 4517d8b..8b41a1f 100644 --- a/src/queue/query_intern.c +++ b/src/queue/query_intern.c @@ -94,9 +94,9 @@ void PschQueryInternShmemInit(LWLockPadded* lwlock_base) { // given key is derived from dynahash's own hashcode (get_hash_value) so the // external and internal partition agree, matching the LockTagHashCode / // LockHashPartitionLock pattern in src/backend/storage/lmgr/lock.c. - psch_query_intern_htab = ShmemInitHash( - "pg_stat_ch query intern", PschQueryInternMaxEntries(), PschQueryInternMaxEntries(), &info, - HASH_ELEM | HASH_BLOBS | HASH_PARTITION); + psch_query_intern_htab = + ShmemInitHash("pg_stat_ch query intern", PschQueryInternMaxEntries(), + PschQueryInternMaxEntries(), &info, HASH_ELEM | HASH_BLOBS | HASH_PARTITION); } static void MakeKey(PschQueryInternKey* key, Oid dbid, uint64 queryid, const char* query, @@ -334,6 +334,19 @@ static void ResolveInto(dsa_pointer ref, char* dst, uint16 dst_size, uint16* out *out_len = copy_len; } +void PschQueryInternResolve(dsa_pointer ref, char* dst, uint16 dst_size, uint16* out_len) { + // Zero outputs first for the same consistent-empty-result contract as + // PschQueryInternResolveAndRelease; the refcount is deliberately untouched. + if (out_len != NULL) { + *out_len = 0; + } + if (dst != NULL && dst_size > 0) { + dst[0] = '\0'; + } + + ResolveInto(ref, dst, dst_size, out_len); +} + void PschQueryInternResolveAndRelease(dsa_pointer ref, char* dst, uint16 dst_size, uint16* out_len) { // Zero outputs first so callers see a consistent empty result on any diff --git a/src/queue/query_intern.h b/src/queue/query_intern.h index 148d773..8b3e2a2 100644 --- a/src/queue/query_intern.h +++ b/src/queue/query_intern.h @@ -68,6 +68,14 @@ void PschQueryInternShmemInit(LWLockPadded* lwlock_base); // unavailable. dsa_pointer PschQueryInternAcquire(Oid dbid, uint64 queryid, const char* query, uint16 query_len); +// Resolve `ref` into the caller's buffer WITHOUT touching the refcount. +// +// Read-only peek used by the two-phase ring consumer (PschPeekEvents): the +// caller's ring slot still holds a reference, so the object cannot be freed +// underneath the copy. On any failure (invalid ref, DSA unavailable, magic +// mismatch) the output is zeroed. +void PschQueryInternResolve(dsa_pointer ref, char* dst, uint16 dst_size, uint16* out_len); + // Resolve `ref` into the caller's buffer and drop one reference. // // Copies up to `dst_size - 1` bytes of the interned query into `dst` and diff --git a/src/queue/shmem.c b/src/queue/shmem.c index 93f8181..74b1003 100644 --- a/src/queue/shmem.c +++ b/src/queue/shmem.c @@ -39,6 +39,7 @@ #include "utils/timestamp.h" #include "config/guc.h" +#include "config/memory_budget.h" #include "hooks/hooks.h" #include "queue/local_batch.h" #include "queue/psch_dsa.h" @@ -66,9 +67,9 @@ static inline PschRingEntry* GetRingBuffer(void) { // - Telemetry is "best effort" - missing some events during spikes is acceptable // - The dropped counter lets operators detect and address capacity issues // -// SIZING GUIDANCE: The queue should be sized to handle burst query loads plus some -// headroom for bgworker export delays. Monitor pg_stat_ch_stats().queue_size and -// .dropped to tune capacity. A good starting point is 1024-4096 events. +// SIZING GUIDANCE: The ring is sized from pg_stat_ch.memory_limit (see +// src/config/memory_budget.h). Monitor pg_stat_ch_stats().queue_size and +// .dropped to tune the budget. // // DETECTING OVERFLOW: Check pg_stat_ch_stats().dropped > 0 or look for the WARNING // in PostgreSQL logs. The overflow_logged flag prevents log spam by warning only once @@ -78,9 +79,10 @@ static void HandleOverflow(void) { // Log overflow warning once to avoid log spam (pg_stat_monitor pattern) if (pg_atomic_test_set_flag(&psch_shared_state->overflow_logged)) { - ereport(WARNING, - (errmsg("pg_stat_ch: queue overflow, events being dropped"), - errhint("Consider increasing pg_stat_ch.queue_capacity or reducing query load."))); + ereport(WARNING, (errmsg("pg_stat_ch: queue overflow, events being dropped"), + errhint("Raise pg_stat_ch.memory_limit (requires restart), or reduce capture " + "volume with pg_stat_ch.sample_rate / pg_stat_ch.min_duration_us " + "(no restart)."))); } } @@ -129,8 +131,8 @@ static bool TryEnqueueLocked(const PschEvent* event, uint32 capacity) { // Clamp the input length to what we'd have stored anyway, so the intern // key doesn't include trailing bytes the consumer would have truncated. uint16 clamped_len = Min(event->query_len, (uint16)(PSCH_MAX_QUERY_LEN - 1)); - slot->query_dsa = PschQueryInternAcquire(event->dbid, event->queryid, - event->query, clamped_len); + slot->query_dsa = + PschQueryInternAcquire(event->dbid, event->queryid, event->query, clamped_len); if (!DsaPointerIsValid(slot->query_dsa)) { slot->query_len = 0; } else { @@ -150,25 +152,35 @@ static bool TryEnqueueLocked(const PschEvent* event, uint32 capacity) { return true; } -static void PschShmemShutdown(int code pg_attribute_unused(), - Datum arg pg_attribute_unused()) { +static void PschShmemShutdown(int code pg_attribute_unused(), Datum arg pg_attribute_unused()) { if (psch_shared_state != NULL) { elog(LOG, "pg_stat_ch: shutdown (enqueued=" UINT64_FORMAT ", dropped=" UINT64_FORMAT - ", exported=" UINT64_FORMAT ")", + ", exported=" UINT64_FORMAT ", export_dropped=" UINT64_FORMAT ")", pg_atomic_read_u64(&psch_shared_state->enqueued), pg_atomic_read_u64(&psch_shared_state->dropped), - pg_atomic_read_u64(&psch_shared_state->exported)); + pg_atomic_read_u64(&psch_shared_state->exported), + pg_atomic_read_u64(&psch_shared_state->export_dropped)); } } // Size of the contiguous shmem block that ShmemInitStruct("pg_stat_ch", ...) // allocates. Layout: [PschSharedState] [PschRingEntry × capacity] [DSA area]. +// +// All components are sized from the resolved memory budget (memory_budget.h), +// not from raw GUC reads — the budget is the single authority that charges +// ring + intern + DSA + export arena against pg_stat_ch.memory_limit. static Size PschSharedBlockSize(void) { + const PschMemoryBudget* budget = PschMemoryBudgetGet(); Size ring_end = - add_size(sizeof(PschSharedState), mul_size(psch_queue_capacity, sizeof(PschRingEntry))); + add_size(sizeof(PschSharedState), mul_size(budget->ring_slots, sizeof(PschRingEntry))); Size dsa_offset = MAXALIGN(ring_end); - Size total = add_size(dsa_offset, PschDsaShmemSize()); + // PschDsaInit() still sizes the in-place area from psch_string_area_size + // (written back by the budget). Reserve the max of the two so the created + // area can never overrun the reservation, even if write-back rounds the MB + // value up. + Size dsa_size = Max((Size)budget->dsa_bytes, PschDsaShmemSize()); + Size total = add_size(dsa_offset, dsa_size); return MAXALIGN(total); } @@ -179,6 +191,15 @@ Size PschShmemSize(void) { } static void RequestSharedResources(void) { + // Resolve the budget and write the component values back to their GUCs + // BEFORE any size computation: PschQueryInternShmemSize() still reads + // psch_queue_capacity, which only matches budget->ring_slots after the + // write-back. SetConfigOption is legal here — this runs in the postmaster + // (shmem_request_hook on PG15+, _PG_init below) before shmem creation, the + // wal_buffers/XLOGShmemSize idiom. + PschMemoryBudgetWriteBack(); + PschMemoryBudgetLogStartup(); + RequestAddinShmemSpace(PschShmemSize()); // 1 main queue lock + N partition locks for the query-text interner, all // in the single "pg_stat_ch" named tranche so we read them as a contiguous @@ -198,12 +219,14 @@ static void PschShmemRequestHook(void) { // Initialize shared state fields on first-time setup. // Called with AddinShmemInitLock held. static void InitializeSharedState(void) { + const PschMemoryBudget* budget = PschMemoryBudgetGet(); + // The pg_stat_ch named tranche owns 1 main queue lock at index 0 and // PSCH_QUERY_INTERN_PARTITIONS partition locks at indices 1..N for the // query-text interner (see PschQueryInternShmemInit). LWLockPadded* lwlocks = GetNamedLWLockTranche("pg_stat_ch"); psch_shared_state->lock = &lwlocks[0].lock; - psch_shared_state->capacity = psch_queue_capacity; + psch_shared_state->capacity = budget->ring_slots; pg_atomic_init_u64(&psch_shared_state->head, 0); pg_atomic_init_u64(&psch_shared_state->enqueued, 0); pg_atomic_init_u64(&psch_shared_state->dropped, 0); @@ -212,6 +235,7 @@ static void InitializeSharedState(void) { pg_atomic_init_u64(&psch_shared_state->exported, 0); pg_atomic_init_u64(&psch_shared_state->send_failures, 0); + pg_atomic_init_u64(&psch_shared_state->export_dropped, 0); psch_shared_state->last_success_ts = 0; psch_shared_state->last_error_ts = 0; MemSet(psch_shared_state->last_error_text, 0, sizeof(psch_shared_state->last_error_text)); @@ -219,17 +243,18 @@ static void InitializeSharedState(void) { pg_atomic_init_u64(&psch_shared_state->dsa_oom_count, 0); // Zero ring buffer (InvalidDsaPointer == 0, so dsa fields are implicitly invalid) - MemSet(GetRingBuffer(), 0, psch_queue_capacity * sizeof(PschRingEntry)); + MemSet(GetRingBuffer(), 0, (Size)budget->ring_slots * sizeof(PschRingEntry)); // Create DSA area for variable-length string storage. // See psch_dsa.h for the shared memory layout diagram. - char* dsa_place = (char*)psch_shared_state + - MAXALIGN(sizeof(PschSharedState) + psch_queue_capacity * sizeof(PschRingEntry)); + char* dsa_place = + (char*)psch_shared_state + + MAXALIGN(sizeof(PschSharedState) + (Size)budget->ring_slots * sizeof(PschRingEntry)); PschDsaInit(psch_shared_state, dsa_place); - elog(LOG, "pg_stat_ch: initialized shared memory (capacity=%d, ring=%zuKB, dsa=%zuMB, total=%zu)", - psch_queue_capacity, (psch_queue_capacity * sizeof(PschRingEntry)) / 1024, - PschDsaShmemSize() / (1024 * 1024), PschShmemSize()); + elog(LOG, "pg_stat_ch: initialized shared memory (capacity=%u, ring=%zuKB, dsa=%zuMB, total=%zu)", + budget->ring_slots, ((Size)budget->ring_slots * sizeof(PschRingEntry)) / 1024, + (Size)budget->dsa_bytes / (1024 * 1024), PschShmemSize()); } static void PschShmemStartupHook(void) { @@ -267,14 +292,6 @@ static void PschShmemStartupHook(void) { on_shmem_exit(PschShmemShutdown, 0); } -void PschShmemRequest(void) { -#if PG_VERSION_NUM < 150000 - RequestSharedResources(); -#endif -} - -void PschShmemStartup(void) {} - void PschInstallShmemHooks(void) { #if PG_VERSION_NUM >= 150000 prev_shmem_request_hook = shmem_request_hook; @@ -387,63 +404,189 @@ int PschEnqueueBatch(const PschEvent* events, int count) { return enqueued; } -// Dequeue an event from the ring buffer (single-consumer, called by bgworker) -// -// LOCK-FREE DESIGN: This function runs lock-free because there's only one consumer -// (the bgworker). We use atomic reads and memory barriers instead of locks. This -// prevents producer contention from affecting the consumer's ability to drain the -// queue. Pattern from PostgreSQL's shm_mq.c. +// Read-only resolve of a per-event DSA string (err_message). Mirrors +// PschDsaResolveString but never frees: peek must leave the ring slot's +// allocations intact so a failed export can retry the same events. +static void DsaPeekString(dsa_pointer dp, uint16 src_len, char* dst_buf, uint16 max_len, + uint16* out_len) { + dsa_area* dsa; + char* src; + uint16 len; + + dst_buf[0] = '\0'; + *out_len = 0; + + if (!DsaPointerIsValid(dp)) { + return; + } + dsa = PschDsaGetArea(); + if (dsa == NULL) { + return; + } + src = (char*)dsa_get_address(dsa, dp); + len = Min(src_len, (uint16)(max_len - 1)); + memcpy(dst_buf, src, len); + dst_buf[len] = '\0'; + *out_len = len; +} + +// Two-phase consume, phase 1 (single-consumer, called by bgworker). // -// DSA STRING RESOLUTION: The ring buffer stores PschRingEntry with dsa_pointer -// references. This function copies numeric fields into the output PschEvent, -// resolves DSA strings into PschEvent's inline buffers, and frees the DSA memory. -// After return the caller owns a self-contained PschEvent with inline strings. +// LOCK-FREE DESIGN: Runs lock-free because there's only one consumer (the +// bgworker). Atomic reads + memory barriers instead of locks, pattern from +// PostgreSQL's shm_mq.c: pg_read_barrier() after reading head ensures the +// producer's slot writes are visible before we copy. // -// MEMORY BARRIERS: Critical for correctness on weakly-ordered CPUs: -// 1. pg_read_barrier() after reading head ensures we see the producer's writes -// 2. pg_write_barrier() before updating tail ensures our copy completes first -// Without these, we could read stale event data or signal completion too early. +// The tail does NOT advance and no DSA memory is freed: producers cannot +// reuse the peeked slots (they check head - tail against capacity), so the +// copies stay valid and a failed export can peek the same events again. +// Interned query objects stay referenced by the slots, so the read-only +// resolve cannot race a free. // -// WRAPAROUND SAFETY: Using uint64 for head/tail means wraparound takes ~584 years -// at 1M events/sec. Even after wraparound, (head - tail) arithmetic works correctly -// because both wrap at the same point (2^64). -bool PschDequeueEvent(PschEvent* event) { - if (psch_shared_state == NULL) { - return false; +// WRAPAROUND SAFETY: uint64 head/tail wrap at the same point (2^64), so +// (head - tail) arithmetic stays correct (~584 years at 1M events/sec). +int PschPeekEvents(PschEvent* buf, int max) { + uint64 head; + uint64 tail; + uint64 avail; + uint32 mask; + int n; + int i; + + if (psch_shared_state == NULL || buf == NULL || max <= 0) { + return 0; } - // Read head with acquire semantics - we must see producer's latest writes - uint64 head = pg_atomic_read_u64(&psch_shared_state->head); - // pg_read_barrier() is sufficient here (vs full pg_memory_barrier() in GetStats) - // because this is a read-only path - we're not writing anything that needs to be - // visible to producers before we complete the read. + head = pg_atomic_read_u64(&psch_shared_state->head); pg_read_barrier(); - uint64 tail = pg_atomic_read_u64(&psch_shared_state->tail); + tail = pg_atomic_read_u64(&psch_shared_state->tail); - if (head == tail) { - return false; // Queue is empty + avail = head - tail; + if (avail == 0) { + return 0; + } + n = (avail < (uint64)max) ? (int)avail : max; + mask = psch_shared_state->capacity - 1; + + for (i = 0; i < n; i++) { + PschRingEntry* slot = &GetRingBuffer()[(tail + (uint64)i) & mask]; + PschEvent* event = &buf[i]; + + // Copy the fixed-field prefix, then resolve the DSA-backed strings into + // the event's inline buffers without freeing or releasing anything. + memcpy(event, slot, kFixedPrefixSize); + DsaPeekString(slot->err_message_dsa, slot->err_message_len, event->err_message, + PSCH_MAX_ERR_MSG_LEN, &event->err_message_len); + PschQueryInternResolve(slot->query_dsa, event->query, PSCH_MAX_QUERY_LEN, &event->query_len); } - // Fast modulo via bitmask (requires power-of-2 capacity) - uint32 capacity = psch_shared_state->capacity; - uint32 mask = capacity - 1; - PschRingEntry* slot = &GetRingBuffer()[tail & mask]; + return n; +} - // 1. Copy the entire fixed-field prefix (all numeric fields, app_name, - // client_addr, lengths — everything before the variable-length data). - memcpy(event, slot, kFixedPrefixSize); +// Two-phase consume, phase 2: free the DSA strings of the first n queued +// events and advance the tail past them. Slot dsa_pointers are cleared as +// they are freed so that a longjmp landing mid-loop cannot cause a double +// free on a later retry (the not-yet-advanced tail would re-expose the +// slots). The write barrier ensures all frees complete before producers can +// reuse the slots. +void PschConsumeEvents(int n) { + uint64 head; + uint64 tail; + uint32 mask; + dsa_area* dsa; + int i; + + if (psch_shared_state == NULL || n <= 0) { + return; + } - // 2. Resolve err_message (per-event DSA) and query text (shared interner). - PschDsaResolveString(slot->err_message_dsa, slot->err_message_len, event->err_message, - PSCH_MAX_ERR_MSG_LEN, &event->err_message_len); - PschQueryInternResolveAndRelease(slot->query_dsa, event->query, PSCH_MAX_QUERY_LEN, - &event->query_len); + head = pg_atomic_read_u64(&psch_shared_state->head); + pg_read_barrier(); + tail = pg_atomic_read_u64(&psch_shared_state->tail); + + if ((uint64)n > head - tail) { + elog(WARNING, "pg_stat_ch: consume of %d events exceeds " UINT64_FORMAT " queued; clamping", n, + head - tail); + n = (int)(head - tail); + } + + dsa = PschDsaGetArea(); + mask = psch_shared_state->capacity - 1; + + for (i = 0; i < n; i++) { + PschRingEntry* slot = &GetRingBuffer()[(tail + (uint64)i) & mask]; + dsa_pointer err_dsa = slot->err_message_dsa; + dsa_pointer query_dsa = slot->query_dsa; + + // Clear the slot pointers BEFORE freeing. dsa_free / the interner release + // can ereport(ERROR) on a damaged DSA, and PschExportBatch runs inside the + // drain loop's PG_TRY/PG_CATCH (bgworker.c): a longjmp out of a free leaves + // the tail un-advanced, so the slot would be re-resolved (use-after-free) + // and re-freed (double free) on the next cycle. Clearing first means such + // a longjmp merely leaks the allocation — the documented safe policy + // (matching PschDsaResolveString) — instead of corrupting the DSA. + slot->err_message_dsa = InvalidDsaPointer; + slot->query_dsa = InvalidDsaPointer; + + if (DsaPointerIsValid(err_dsa) && dsa != NULL) { + dsa_free(dsa, err_dsa); + } + + // NULL output args make this a pure refcount release (see query_intern.h). + PschQueryInternResolveAndRelease(query_dsa, NULL, 0, NULL); + } - // CRITICAL: Write barrier ensures all reads and DSA frees complete before we - // update tail. Producers cannot reuse this slot until tail advances past it. pg_write_barrier(); - pg_atomic_write_u64(&psch_shared_state->tail, tail + 1); - return true; + pg_atomic_write_u64(&psch_shared_state->tail, tail + (uint64)n); +} + +// Validate ring invariants at bgworker start. The SIGABRT backstop exits +// with _exit(1), which skips shmem reinit — if the abort happened while ring +// state was being mutated, the indices could be inconsistent. Producers +// mutate head only under the main lock, so holding it exclusively makes the +// paired reset race-free; lock-free fast-path readers may observe one +// spurious overflow during the reset, which is acceptable for a corrupt-only +// worker-start path. +void PschRingSanityCheck(void) { + const PschMemoryBudget* budget; + uint64 head; + uint64 tail; + uint32 capacity; + bool corrupt = false; + + if (psch_shared_state == NULL) { + return; + } + budget = PschMemoryBudgetGet(); + + LWLockAcquire(psch_shared_state->lock, LW_EXCLUSIVE); + capacity = psch_shared_state->capacity; + head = pg_atomic_read_u64(&psch_shared_state->head); + tail = pg_atomic_read_u64(&psch_shared_state->tail); + + if (capacity == 0 || (capacity & (capacity - 1)) != 0 || capacity != budget->ring_slots) { + psch_shared_state->capacity = budget->ring_slots; + corrupt = true; + } + if (head - tail > (uint64)psch_shared_state->capacity) { + corrupt = true; + } + + if (corrupt) { + // Discards queued events: their slot mapping / DSA pointers can no + // longer be trusted, so referenced DSA strings are leaked, not freed. + // Tail is reset before head: fast-path readers load head first, so a + // torn pair can never underflow (head - tail); at worst one producer + // sees a stale-full ring and overflow-drops a single event. + pg_atomic_write_u64(&psch_shared_state->tail, 0); + pg_write_barrier(); + pg_atomic_write_u64(&psch_shared_state->head, 0); + elog(LOG, + "pg_stat_ch: ring state corrupt at worker start (capacity=%u head=" UINT64_FORMAT + " tail=" UINT64_FORMAT "); indices reset, queued events discarded", + capacity, head, tail); + } + LWLockRelease(psch_shared_state->lock); } // Get queue statistics (called by SQL function pg_stat_ch_stats()) @@ -516,6 +659,7 @@ void PschResetStats(void) { pg_atomic_write_u64(&psch_shared_state->dropped, 0); pg_atomic_write_u64(&psch_shared_state->exported, 0); pg_atomic_write_u64(&psch_shared_state->send_failures, 0); + pg_atomic_write_u64(&psch_shared_state->export_dropped, 0); pg_atomic_clear_flag(&psch_shared_state->overflow_logged); pg_atomic_write_u64(&psch_shared_state->dsa_oom_count, 0); psch_shared_state->last_success_ts = 0; @@ -553,6 +697,23 @@ void PschRecordExportFailure(const char* error_msg) { LWLockRelease(psch_shared_state->lock); } +// Count events destructively consumed after an export failure (poison-batch +// valve, internal error, or exporter OOM). Distinct from the enqueue-overflow +// 'dropped' counter so operators can tell capture loss from export loss. +void PschRecordExportDrop(int n) { + if (psch_shared_state == NULL || n <= 0) { + return; + } + pg_atomic_fetch_add_u64(&psch_shared_state->export_dropped, (uint64)n); +} + +uint64 PschGetExportDropped(void) { + if (psch_shared_state == NULL) { + return 0; + } + return pg_atomic_read_u64(&psch_shared_state->export_dropped); +} + pid_t PschGetBgworkerPid(void) { if (psch_shared_state == NULL) { return 0; diff --git a/src/queue/shmem.h b/src/queue/shmem.h index ebe5737..af270d2 100644 --- a/src/queue/shmem.h +++ b/src/queue/shmem.h @@ -14,12 +14,6 @@ extern "C" { // Calculate total shared memory size needed Size PschShmemSize(void); -// Request shared memory allocation (called from _PG_init) -void PschShmemRequest(void); - -// Initialize shared memory structures (called from shmem_startup_hook) -void PschShmemStartup(void); - // Install shmem hooks (called from _PG_init) void PschInstallShmemHooks(void); @@ -31,8 +25,26 @@ bool PschEnqueueEvent(const PschEvent* event); // Returns the number of events successfully enqueued (rest are dropped via overflow). int PschEnqueueBatch(const PschEvent* events, int count); -// Dequeue an event from the ring buffer (returns true if event was available) -bool PschDequeueEvent(PschEvent* event); +// Two-phase consume (single consumer: the bgworker). See OTEL_REWRITE_DESIGN.md +// §5a — peek/consume replaces the destructive dequeue so a failed export can +// leave events queued for retry. +// +// PschPeekEvents copies up to `max` events from the tail into `buf`, resolving +// DSA-backed strings into the copies' inline buffers WITHOUT freeing them and +// WITHOUT advancing the tail. Read-only with respect to the ring; safe to +// call repeatedly (retry path) before a consume. Returns the number copied. +int PschPeekEvents(PschEvent* buf, int max); + +// PschConsumeEvents frees the DSA strings of the first `n` queued events and +// advances the tail past them. Must only follow a PschPeekEvents that +// returned >= n. +void PschConsumeEvents(int n); + +// Validate ring invariants (capacity power-of-2 and matching the resolved +// budget; head-tail distance within capacity). On corruption: LOG and reset +// the indices, discarding queued events. Called once at bgworker start to +// compensate for the SIGABRT handler's _exit(1) skipping shmem reinit. +void PschRingSanityCheck(void); // Get current queue statistics. // last_error_buf must point to a caller-owned buffer of last_error_buf_size bytes; @@ -51,6 +63,14 @@ void PschRecordExportSuccess(void); // Record export failure (called by bgworker on export error) void PschRecordExportFailure(const char* error_msg); +// Count n events destructively consumed after an export failure (poison-batch +// valve or internal/OOM failure). Distinct from the enqueue-overflow +// `dropped` counter. +void PschRecordExportDrop(int n); + +// Read the export-drop counter (consumed by pg_stat_ch_memory()/stats views). +uint64 PschGetExportDropped(void); + // Get the background worker PID (for signaling) pid_t PschGetBgworkerPid(void); diff --git a/src/worker/bgworker.c b/src/worker/bgworker.c index 97a61a0..2094436 100644 --- a/src/worker/bgworker.c +++ b/src/worker/bgworker.c @@ -12,7 +12,7 @@ // to hang indefinitely. The fix: // 1. Use procsignal_sigusr1_handler for SIGUSR1 (handles barriers) // 2. Use SIGUSR2 for extension-specific immediate flush requests -// 3. Add socket timeouts to ClickHouse connections as a safety net +// 3. Add socket timeouts to backend connections as a safety net // // Signal assignments: // SIGHUP -> SignalHandlerForConfigReload (reload postgresql.conf) @@ -20,6 +20,7 @@ // SIGUSR1 -> procsignal_sigusr1_handler (PostgreSQL internal - barriers, etc.) // SIGUSR2 -> HandleFlushSignal (extension-specific - immediate flush) // SIGPIPE -> SIG_IGN (ignore broken pipe from network) +// SIGABRT -> HandleAbortSignal (bgworker-only restart instead of cluster crash) #include "postgres.h" @@ -38,14 +39,54 @@ #include "queue/shmem.h" #include +#include #include "config/guc.h" #include "export/stats_exporter.h" #include "worker/bgworker.h" +// Upper bound on staged chunks drained per export cycle. One PschExportBatch +// call processes at most one staging chunk and returns 0 on failure or empty +// queue, so under sustained load the loop would otherwise run until the ring +// drains; 16 chunks bounds the time between WaitLatch returns so procsignal +// barriers (DROP DATABASE), SIGTERM, and config reloads stay responsive. +static const int kMaxChunksPerCycle = 16; + // Custom wait event for pg_stat_activity visibility static uint32 psch_wait_event_main = 0; +// SIGABRT backstop. The C++ terminate handler that used to convert stray +// aborts into ereport(FATAL) is gone with the C++ runtime, but residual +// abort() sources remain (libc heap-corruption checks, assert() inside +// linked C libraries). Exit-status semantics make this handler load-bearing: +// +// * exit status 0 or 1 -> postmaster restarts ONLY this bgworker after +// bgw_restart_time (10 s; see PschRegisterBgworker below) +// * death by signal, or any other exit status -> postmaster assumes shared +// memory may be corrupt and crash-recovers the WHOLE cluster (every +// connection severed, WAL replayed) — the 2026-06-10 production incident. +// +// _exit(1) therefore converts an abort into a clean bgworker-only restart. +// Only async-signal-safe work is allowed here: never ereport/elog (palloc +// into ErrorContext from a signal handler corrupts memory), never proc_exit +// (runs arbitrary callbacks). The handler must not return either: abort() +// re-raises SIGABRT with SIG_DFL if the handler returns, restoring the +// cluster-crash path. _exit skips the on_proc_exit chain, leaving a stale +// bgworker_pid in shmem — PschSignalFlush's ESRCH compare-exchange recovery +// (below) cleans that up on the next flush attempt. SIGSEGV/SIGBUS are +// deliberately left untouched: for those, shared memory really may be +// corrupt, so full crash-recovery semantics are correct. +static void HandleAbortSignal(SIGNAL_ARGS) { + static const char msg[] = + "pg_stat_ch: bgworker caught SIGABRT; exiting with status 1 for bgworker-only restart\n"; + ssize_t rc; + + (void)postgres_signal_arg; + rc = write(STDERR_FILENO, msg, sizeof(msg) - 1); + (void)rc; + _exit(1); +} + // SIGUSR2 handler: wake the worker for immediate flush. // Note: SIGUSR1 is reserved for PostgreSQL's procsignal mechanism. static void HandleFlushSignal(SIGNAL_ARGS) { @@ -88,8 +129,7 @@ static void HandleConfigReload(void) { // Callback for bgworker process exit (registered via on_proc_exit). // Clear bgworker_pid before exporter teardown so a concurrent // pg_stat_ch_flush() cannot race a SIGUSR2 to a recycled PID. -static void PschBgworkerShutdown(int code pg_attribute_unused(), - Datum arg pg_attribute_unused()) { +static void PschBgworkerShutdown(int code pg_attribute_unused(), Datum arg pg_attribute_unused()) { PschSetBgworkerPid(0); PschExporterShutdown(); } @@ -107,14 +147,19 @@ static void ProcessPendingSignals(void) { HandleConfigReload(); } -// Drain the queue: loop exporting batches until a partial batch (< batch_max) -// indicates the queue is nearly empty. Each batch gets its own PG_TRY/PG_CATCH -// so an error on batch N+1 doesn't lose batches 1..N. Signals are processed -// between batches to stay responsive to SIGTERM, barriers, and config reload. +// Drain the queue, at most kMaxChunksPerCycle staged chunks per cycle. Each +// chunk gets its own PG_TRY/PG_CATCH so an error on chunk N+1 doesn't lose +// chunks 1..N. PschExportBatch returns 0 on failure or empty queue (the +// chunk stays in the ring on requeueable failures), so 0 always breaks the +// loop and lets CalculateSleepMs apply consecutive-failure backoff instead +// of spinning. Signals are processed between chunks to stay responsive to +// SIGTERM, barriers, and config reload. static void ExportBatchWithRecovery(void) { - pgstat_report_activity(STATE_RUNNING, "exporting to ClickHouse"); + int chunk; - for (;;) { + pgstat_report_activity(STATE_RUNNING, "exporting telemetry events"); + + for (chunk = 0; chunk < kMaxChunksPerCycle; chunk++) { // volatile: required because PG_TRY/PG_CATCH uses setjmp/longjmp. // Without it, the compiler may keep 'exported' in a register that // gets clobbered on longjmp, making the value undefined in PG_CATCH. @@ -130,7 +175,7 @@ static void ExportBatchWithRecovery(void) { } PG_END_TRY(); - if (exported < psch_batch_max) { + if (exported <= 0) { break; } @@ -166,9 +211,10 @@ static int CalculateSleepMs(void) { // Run one export cycle: sleep, process signals, then drain queue if enabled. // -// Note on blocking: If we're blocked in ClickHouse network I/O when a barrier +// Note on blocking: If we're blocked in backend network I/O when a barrier // signal arrives, we can't process it until the I/O completes. The socket -// timeouts configured in stats_exporter.cc (30 seconds) bound this delay. +// deadlines configured by the export backends (pg_stat_ch.export_timeout) +// bound this delay. static void RunExportCycle(uint32 wait_event) { int sleep_ms = CalculateSleepMs(); (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, sleep_ms, wait_event); @@ -182,6 +228,12 @@ static void RunExportCycle(uint32 wait_event) { } void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { + // Install the SIGABRT backstop before anything else: bgworkers start with + // all signals blocked, so installing it before + // BackgroundWorkerUnblockSignals leaves no window where an abort would + // crash-recover the whole cluster. + pqsignal(SIGABRT, HandleAbortSignal); + SetupSignalHandlers(); BackgroundWorkerUnblockSignals(); BackgroundWorkerInitializeConnection("postgres", NULL, 0); @@ -195,6 +247,10 @@ void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { // Attach to DSA area eagerly so the first dequeue doesn't hit lazy init PschDsaAttach(); + // The SIGABRT handler's _exit(1) skips shmem-corruption reinit; verify the + // ring invariants before trusting head/tail from a previous incarnation. + PschRingSanityCheck(); + elog(LOG, "pg_stat_ch: background worker started (pid=%d)", MyProcPid); // Register custom wait event for pg_stat_activity visibility @@ -202,13 +258,14 @@ void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { psch_wait_event_main = InitializeWaitEvent(); } - // Initialize ClickHouse exporter and verify connectivity - pgstat_report_activity(STATE_RUNNING, "initializing ClickHouse exporter"); + // Initialize the export backend and verify connectivity + pgstat_report_activity(STATE_RUNNING, "initializing telemetry exporter"); if (PschExporterInit()) { - elog(LOG, "pg_stat_ch: ClickHouse connectivity verified on startup"); + elog(LOG, "pg_stat_ch: exporter connectivity verified on startup"); } else { elog(WARNING, - "pg_stat_ch: failed to connect to ClickHouse on startup, will retry on first export"); + "pg_stat_ch: failed to connect to telemetry backend on startup, " + "will retry on first export"); } pgstat_report_activity(STATE_IDLE, NULL); @@ -226,8 +283,9 @@ void PschSignalFlush(void) { if (bgworker_pid == 0) { ereport(WARNING, (errmsg("pg_stat_ch: background worker not running"))); } else if (kill(bgworker_pid, SIGUSR2) != 0) { - // Stale pid: worker died without running on_proc_exit. Clear shmem so we - // don't keep signaling a recycled pid; postmaster restart will repopulate. + // Stale pid: worker died without running on_proc_exit (kill -9, OOM + // killer, or the SIGABRT handler's _exit(1)). Clear shmem so we don't + // keep signaling a recycled pid; postmaster restart will repopulate. // Only clear when shmem still holds the stale pid we observed. if (errno == ESRCH) { uint32 expected = (uint32)bgworker_pid; From 8a03f595da2b319623e9a56a4f591236c2ba2d82 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:48 -0500 Subject: [PATCH 09/11] feat(config): consolidate memory GUCs around pg_stat_ch.memory_limit Collapse 8 interacting memory knobs into one operator knob plus three -1=auto expert overrides (OTEL_REWRITE_DESIGN.md section 6): - pg_stat_ch.memory_limit (default 160 MB = verified equivalence point of the old defaults; -1 = opt-in auto from shared_buffers; min 32 MB so a configured value is honored rather than always auto-raised). - queue_capacity/string_area_size/export_buffer_size default -1=auto; explicit queue_capacity is rounded up to a power of 2 and floored at the ring minimum. - Overrides auto-raise the budget with a WARNING, never FATAL; resolved values are written back so SHOW reports effective sizes. The intern HTAB is charged to the budget. Deleted dead shims; legacy knobs (batch_max, otel_*) become hidden one-release compat bridges; otel_log_delay_ms -> export_timeout (1000 ms). - pg_stat_ch_memory() view exposes per-component budget/source; control bumped to 0.4 with a migration; guc.out updated. --- include/config/guc.h | 53 +++- pg_stat_ch.control | 2 +- sql/pg_stat_ch--0.3--0.4.sql | 11 + sql/pg_stat_ch--0.4.sql | 59 +++++ src/config/guc.c | 422 ++++++++++++++++++++++--------- src/config/memory_budget.c | 289 +++++++++++++++++++++ src/config/memory_budget.h | 53 ++++ src/config/memory_view.c | 63 +++++ test/regression/expected/guc.out | 43 +++- test/regression/sql/guc.sql | 8 +- 10 files changed, 857 insertions(+), 146 deletions(-) create mode 100644 sql/pg_stat_ch--0.3--0.4.sql create mode 100644 sql/pg_stat_ch--0.4.sql create mode 100644 src/config/memory_budget.c create mode 100644 src/config/memory_budget.h create mode 100644 src/config/memory_view.c diff --git a/include/config/guc.h b/include/config/guc.h index eb0d4a9..6ba8fc0 100644 --- a/include/config/guc.h +++ b/include/config/guc.h @@ -1,4 +1,11 @@ // pg_stat_ch GUC (Grand Unified Configuration) declarations +// +// Memory surface (OTEL_REWRITE_DESIGN.md §6): one operator knob +// (memory_limit) + three -1=auto expert overrides (queue_capacity, +// string_area_size, export_buffer_size). Resolution lives in +// src/config/memory_budget.h. Legacy knobs kept as hidden one-release +// bridges are marked below; deleted knobs: otel_log_queue_size, +// otel_metric_interval_ms. #ifndef PG_STAT_CH_GUC_H #define PG_STAT_CH_GUC_H @@ -9,6 +16,8 @@ extern "C" { extern bool psch_enabled; extern bool psch_use_otel; + +// ClickHouse native-protocol connection (unchanged) extern char* psch_clickhouse_host; extern int psch_clickhouse_port; extern char* psch_clickhouse_user; @@ -16,26 +25,48 @@ extern char* psch_clickhouse_password; extern char* psch_clickhouse_database; extern bool psch_clickhouse_use_tls; extern bool psch_clickhouse_skip_tls_verify; + +// OTLP/HTTP endpoint configuration. otel_endpoint is now a URL: scheme +// decides TLS (http/https); a bare "host:port" is accepted and treated as +// http://host:port; the path defaults to /v1/logs when absent. +// Default: "http://localhost:4318". extern char* psch_otel_endpoint; +extern char* psch_otel_headers; // NEW: "Name: value\nName2: value2" static headers (auth) +extern char* psch_otel_ca_file; // NEW: PEM CA bundle path for https endpoints ("" = system) extern char* psch_hostname; -extern int psch_queue_capacity; -extern int psch_string_area_size; + +// Memory budget: the operator knob + auto-defaulted expert overrides. +extern int psch_memory_limit_mb; // default 160; -1 = auto from shared_buffers +extern int psch_queue_capacity; // slots; default -1 = auto; explicit values pow2-rounded +extern int psch_string_area_size; // MB; default -1 = auto +extern int psch_export_buffer_size_mb; // MB; default -1 = auto (NEW) + +// Export timing extern int psch_flush_interval_ms; -extern int psch_batch_max; +extern int + psch_export_timeout_ms; // per-request deadline; default 1000 (renames otel_log_delay_ms) + +// Capture behavior (unchanged) extern int psch_log_min_elevel; -extern int psch_otel_log_queue_size; -extern int psch_otel_log_batch_size; -extern int psch_otel_log_max_bytes; -extern int psch_otel_log_delay_ms; -extern int psch_otel_metric_interval_ms; -extern bool psch_debug_force_locked_overflow; extern int psch_min_duration_us; -extern int psch_normalize_cache_max; +extern int psch_normalize_cache_max; // per-backend; deliberately OUTSIDE memory_limit extern double psch_sample_rate; extern bool psch_otel_arrow_passthrough; -extern int psch_otel_max_block_bytes; extern char* psch_extra_attributes; + +// Debug (unchanged) extern char* psch_debug_arrow_dump_dir; +extern bool psch_debug_force_locked_overflow; + +// --- Hidden one-release compat bridges (GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE). +// Honored iff the successor GUC is -1/unset; explicit use logs a deprecation +// WARNING. guc.c folds them into the resolved values; no other module may +// read these. +extern int psch_bridge_batch_max; // -> export_buffer_size (staging) +extern int psch_bridge_otel_max_block_bytes; // -> export_buffer_size (arrow/ipc budget) +extern int psch_bridge_otel_log_max_bytes; // -> export_buffer_size (encode) +extern int psch_bridge_otel_log_batch_size; // -> export_buffer_size (encode) +extern int psch_bridge_otel_log_delay_ms; // -> export_timeout // Initialize GUC variables void PschInitGuc(void); diff --git a/pg_stat_ch.control b/pg_stat_ch.control index 0ea7393..e46b91c 100644 --- a/pg_stat_ch.control +++ b/pg_stat_ch.control @@ -1,4 +1,4 @@ comment = 'Query telemetry exporter to ClickHouse' -default_version = '0.3' +default_version = '0.4' module_pathname = '$libdir/pg_stat_ch' relocatable = false diff --git a/sql/pg_stat_ch--0.3--0.4.sql b/sql/pg_stat_ch--0.3--0.4.sql new file mode 100644 index 0000000..02a7536 --- /dev/null +++ b/sql/pg_stat_ch--0.3--0.4.sql @@ -0,0 +1,11 @@ +\echo Use "ALTER EXTENSION pg_stat_ch UPDATE TO '0.4'" to load this file. \quit + +-- 0.4 adds the memory-budget observability surface for the consolidated +-- pg_stat_ch.memory_limit GUC (OTEL_REWRITE_DESIGN.md §6). +CREATE FUNCTION pg_stat_ch_memory() +RETURNS TABLE(component text, budget_bytes bigint, source text) +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_memory() +IS 'Returns the resolved pg_stat_ch.memory_limit budget per component and export drop counters'; diff --git a/sql/pg_stat_ch--0.4.sql b/sql/pg_stat_ch--0.4.sql new file mode 100644 index 0000000..4d0a965 --- /dev/null +++ b/sql/pg_stat_ch--0.4.sql @@ -0,0 +1,59 @@ +-- pg_stat_ch extension SQL definitions + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION pg_stat_ch" to load this file. \quit + +-- Version function +CREATE FUNCTION pg_stat_ch_version() +RETURNS text +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_version() +IS 'Returns the pg_stat_ch extension version'; + +-- Stats function (11 columns) +CREATE FUNCTION pg_stat_ch_stats( + OUT enqueued_events bigint, + OUT dropped_events bigint, + OUT exported_events bigint, + OUT send_failures bigint, + OUT last_success_ts timestamptz, + OUT last_error_text text, + OUT last_error_ts timestamptz, + OUT queue_size integer, + OUT queue_capacity integer, + OUT queue_usage_pct double precision, + OUT dsa_oom_count bigint +) +RETURNS record +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_stats() +IS 'Returns pg_stat_ch queue and exporter statistics'; + +-- Reset function +CREATE FUNCTION pg_stat_ch_reset() RETURNS void +AS 'MODULE_PATHNAME', 'pg_stat_ch_reset' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_reset() +IS 'Resets all pg_stat_ch queue counters to zero'; + +-- Flush function (trigger immediate export) +CREATE FUNCTION pg_stat_ch_flush() RETURNS void +AS 'MODULE_PATHNAME', 'pg_stat_ch_flush' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_flush() +IS 'Trigger immediate flush of queued events to ClickHouse'; + +-- Memory budget view (one row per component + drop counters) +CREATE FUNCTION pg_stat_ch_memory() +RETURNS TABLE(component text, budget_bytes bigint, source text) +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +COMMENT ON FUNCTION pg_stat_ch_memory() +IS 'Returns the resolved pg_stat_ch.memory_limit budget per component and export drop counters'; diff --git a/src/config/guc.c b/src/config/guc.c index 97b5473..2dd0cc4 100644 --- a/src/config/guc.c +++ b/src/config/guc.c @@ -1,14 +1,29 @@ // pg_stat_ch GUC (Grand Unified Configuration) implementation +// +// Memory surface (OTEL_REWRITE_DESIGN.md §6): pg_stat_ch.memory_limit is the +// one operator knob; queue_capacity / string_area_size / export_buffer_size +// are -1=auto expert overrides. Resolution and the SetConfigOption +// write-back of effective values live in src/config/memory_budget.c. +// +// Deleted outright: pg_stat_ch.otel_log_queue_size and +// pg_stat_ch.otel_metric_interval_ms. Because MarkGUCPrefixReserved makes +// the prefix reserved, SET/ALTER SYSTEM of the deleted names now errors — +// release notes must flag the fleet-template / postgresql.auto.conf scrub. +// +// Five legacy knobs survive one release as hidden bridges (see the bridge +// section at the bottom of PschInitGuc). #include "postgres.h" -#include "utils/guc.h" - #include +#include "utils/guc.h" + #include "config/guc.h" -// GUC variable storage +// GUC variable storage. Initializers mirror the boot values so the globals +// are sane even when _PG_init bails out before registration (extension loaded +// without shared_preload_libraries). bool psch_enabled = true; bool psch_use_otel = false; char* psch_clickhouse_host = NULL; @@ -19,25 +34,30 @@ char* psch_clickhouse_database = NULL; bool psch_clickhouse_use_tls = false; bool psch_clickhouse_skip_tls_verify = false; char* psch_otel_endpoint = NULL; +char* psch_otel_headers = NULL; +char* psch_otel_ca_file = NULL; char* psch_hostname = NULL; -int psch_queue_capacity = 131072; -int psch_string_area_size = 64; // MB, for DSA string storage +int psch_memory_limit_mb = 160; +int psch_queue_capacity = -1; +int psch_string_area_size = -1; +int psch_export_buffer_size_mb = -1; int psch_flush_interval_ms = 500; -int psch_batch_max = 200000; +int psch_export_timeout_ms = 1000; int psch_log_min_elevel = WARNING; -int psch_otel_log_queue_size = 65536; -int psch_otel_log_batch_size = 8192; -int psch_otel_log_max_bytes = 3 * 1024 * 1024; // 3 MiB: gRPC default max is 4 MiB -int psch_otel_log_delay_ms = 100; -int psch_otel_metric_interval_ms = 5000; -bool psch_debug_force_locked_overflow = false; int psch_min_duration_us = 0; int psch_normalize_cache_max = 32768; double psch_sample_rate = 1.0; bool psch_otel_arrow_passthrough = false; -int psch_otel_max_block_bytes = 3 * 1024 * 1024; // 3 MiB (max: 16 MiB) char* psch_extra_attributes = NULL; char* psch_debug_arrow_dump_dir = NULL; +bool psch_debug_force_locked_overflow = false; + +// Hidden one-release compat bridges (-1 = unset; see guc.h). +int psch_bridge_batch_max = -1; +int psch_bridge_otel_max_block_bytes = -1; +int psch_bridge_otel_log_max_bytes = -1; +int psch_bridge_otel_log_batch_size = -1; +int psch_bridge_otel_log_delay_ms = -1; // Log level options (matches PostgreSQL's server_message_level_options pattern) // clang-format off @@ -58,27 +78,126 @@ static const struct config_enum_entry log_elevel_options[] = { }; // clang-format on -// Check hook to ensure queue_capacity is a power of 2. -// Parameters follow PostgreSQL GUC check hook signature. -static bool check_psch_queue_capacity(int* newval, void** extra pg_attribute_unused(), - GucSource source pg_attribute_unused()) { - // Check if value is positive and a power of 2 +// The declared GUC range is -1..4096 so -1 (= auto from shared_buffers) can +// pass the built-in range check; the real lower bound for explicit values is +// enforced here. +static bool CheckMemoryLimit(int* newval, void** extra pg_attribute_unused(), + GucSource source pg_attribute_unused()) { + if (*newval == -1) { + return true; + } + // 32 MB is the smallest budget the component floors actually fit within + // (ring floor ~2 MB + intern + export-arena floor 8 MB + DSA floor 8 MB). A + // value below this would always be silently auto-raised, so reject it as a + // configuration error rather than honor it dishonestly. + if (*newval < 32) { + GUC_check_errdetail( + "pg_stat_ch.memory_limit must be at least 32 MB, " + "or -1 for automatic sizing from shared_buffers."); + return false; + } + return true; +} + +// -1 = auto. Explicit values are rounded UP to the next power of 2 in place +// (replaces the old must-be-pow2 startup error). The declared maximum +// (4194304 = 2^22) is itself a power of 2 and range checking runs before this +// hook, so rounding cannot exceed the maximum. +static bool CheckQueueCapacity(int* newval, void** extra pg_attribute_unused(), + GucSource source pg_attribute_unused()) { + uint32 pow2; + + if (*newval == -1) { + return true; + } if (*newval <= 0) { - GUC_check_errdetail("pg_stat_ch.queue_capacity must be positive."); + GUC_check_errdetail("pg_stat_ch.queue_capacity must be positive, or -1 for automatic sizing."); return false; } - // Check if power of 2: value & (value - 1) == 0 - if ((*newval & (*newval - 1)) != 0) { + pow2 = 1; + while (pow2 < (uint32)*newval) { + pow2 <<= 1; + } + *newval = (int)pow2; + return true; +} + +static bool CheckStringAreaSize(int* newval, void** extra pg_attribute_unused(), + GucSource source pg_attribute_unused()) { + if (*newval == -1) { + return true; + } + if (*newval < 8) { GUC_check_errdetail( - "pg_stat_ch.queue_capacity must be a power of 2 " - "(e.g., 1024, 2048, 4096, 8192, 16384, 32768, 65536)."); + "pg_stat_ch.string_area_size must be between 8 and 1024 MB, " + "or -1 for automatic sizing."); return false; } + return true; +} +static bool CheckExportBufferSize(int* newval, void** extra pg_attribute_unused(), + GucSource source pg_attribute_unused()) { + if (*newval == -1) { + return true; + } + if (*newval < 8) { + GUC_check_errdetail( + "pg_stat_ch.export_buffer_size must be between 8 and 512 MB, " + "or -1 for automatic sizing."); + return false; + } + return true; +} + +// One-time deprecation WARNING for a bridge GUC explicitly set by the +// operator. PGC_S_DEFAULT covers definition time; PGC_S_DYNAMIC_DEFAULT +// covers our own write-backs — neither is operator intent. +static bool BridgeDeprecationCheck(const int* newval, GucSource source, bool* warned, + const char* old_name, const char* successor) { + if (*newval == -1 || source <= PGC_S_DYNAMIC_DEFAULT || *warned) { + return true; + } + *warned = true; + ereport(WARNING, + (errmsg("pg_stat_ch.%s is deprecated and will be removed in the next release", old_name), + errhint("Use pg_stat_ch.%s instead.", successor))); return true; } +static bool CheckBridgeBatchMax(int* newval, void** extra pg_attribute_unused(), GucSource source) { + static bool warned = false; + return BridgeDeprecationCheck(newval, source, &warned, "batch_max", "export_buffer_size"); +} + +static bool CheckBridgeOtelMaxBlockBytes(int* newval, void** extra pg_attribute_unused(), + GucSource source) { + static bool warned = false; + return BridgeDeprecationCheck(newval, source, &warned, "otel_max_block_bytes", + "export_buffer_size"); +} + +static bool CheckBridgeOtelLogMaxBytes(int* newval, void** extra pg_attribute_unused(), + GucSource source) { + static bool warned = false; + return BridgeDeprecationCheck(newval, source, &warned, "otel_log_max_bytes", + "export_buffer_size"); +} + +static bool CheckBridgeOtelLogBatchSize(int* newval, void** extra pg_attribute_unused(), + GucSource source) { + static bool warned = false; + return BridgeDeprecationCheck(newval, source, &warned, "otel_log_batch_size", + "export_buffer_size"); +} + +static bool CheckBridgeOtelLogDelayMs(int* newval, void** extra pg_attribute_unused(), + GucSource source) { + static bool warned = false; + return BridgeDeprecationCheck(newval, source, &warned, "otel_log_delay_ms", "export_timeout_ms"); +} + // When adding a GUC here, also update test/regression/expected/guc.out. void PschInitGuc(void) { // clang-format off @@ -94,8 +213,8 @@ void PschInitGuc(void) { DefineCustomBoolVariable( "pg_stat_ch.use_otel", - "Send metrics through OpenTelemetry instead of ClickHouse.", - "When enabled, stats will be sent to an OTel endpoint instead of ClickHouse.", + "Send telemetry through OpenTelemetry instead of ClickHouse.", + "When enabled, events are sent to an OTLP/HTTP endpoint instead of ClickHouse.", &psch_use_otel, false, PGC_POSTMASTER, @@ -175,14 +294,36 @@ void PschInitGuc(void) { DefineCustomStringVariable( "pg_stat_ch.otel_endpoint", - "OpenTelemetry gRPC endpoint (host:port).", - NULL, + "OTLP/HTTP endpoint URL for telemetry export.", + "The scheme decides TLS (http or https). A bare host:port is treated as " + "http://host:port; the request path defaults to /v1/logs when absent.", &psch_otel_endpoint, - "localhost:4317", + "http://localhost:4318", PGC_POSTMASTER, 0, NULL, NULL, NULL); + DefineCustomStringVariable( + "pg_stat_ch.otel_headers", + "Static HTTP headers added to every OTLP request.", + "Newline-separated \"Name: value\" pairs, typically used for authentication " + "(parity with OTEL_EXPORTER_OTLP_HEADERS).", + &psch_otel_headers, + "", + PGC_SIGHUP, + GUC_SUPERUSER_ONLY, + NULL, NULL, NULL); + + DefineCustomStringVariable( + "pg_stat_ch.otel_ca_file", + "PEM CA bundle used to verify https OTLP endpoints.", + "Empty means the system default trust store.", + &psch_otel_ca_file, + "", + PGC_SIGHUP, + 0, + NULL, NULL, NULL); + DefineCustomStringVariable( "pg_stat_ch.hostname", "Override the hostname of the current machine.", @@ -193,32 +334,61 @@ void PschInitGuc(void) { 0, NULL, NULL, NULL); + DefineCustomIntVariable( + "pg_stat_ch.memory_limit", + "Total memory budget for pg_stat_ch (ring queue + intern table + string area + export arena).", + "The default equals the footprint of the pre-0.4 defaults. -1 sizes the budget " + "automatically as shared_buffers/16 clamped to [48 MB, 256 MB]. Component overrides " + "raise the effective budget with a WARNING; resolved sizes are reported by " + "pg_stat_ch_memory().", + &psch_memory_limit_mb, + 160, // bootValue + -1, 4096, // min (-1 = auto; explicit minimum 16 via check hook), max + PGC_POSTMASTER, + GUC_UNIT_MB, + CheckMemoryLimit, NULL, NULL); + DefineCustomIntVariable( "pg_stat_ch.queue_capacity", - "Maximum number of events in the shared memory queue (must be a power of 2).", - NULL, + "Number of slots in the shared memory event queue.", + "-1 derives the largest power of 2 whose ring + intern-table cost fits half of " + "pg_stat_ch.memory_limit. Explicit values are rounded up to the next power of 2.", &psch_queue_capacity, - 131072, // bootValue - 1024, 4194304, // min, max + -1, // bootValue: auto + -1, 4194304, // min (-1 = auto), max (2^22) PGC_POSTMASTER, 0, - check_psch_queue_capacity, NULL, NULL); + CheckQueueCapacity, NULL, NULL); DefineCustomIntVariable( "pg_stat_ch.string_area_size", "Size in MB of the DSA area for variable-length string storage.", "Query text and error messages are stored in a DSA (Dynamic Shared Memory Area) " - "rather than inline in ring buffer slots. This controls the total DSA area size.", + "rather than inline in ring buffer slots. -1 lets the area absorb whatever remains " + "of pg_stat_ch.memory_limit after the other components are sized.", &psch_string_area_size, - 64, // bootValue: 64 MB - 8, 1024, // min: 8 MB, max: 1024 MB + -1, // bootValue: auto + -1, 1024, // min (-1 = auto; explicit minimum 8 via check hook), max PGC_POSTMASTER, GUC_UNIT_MB, - NULL, NULL, NULL); + CheckStringAreaSize, NULL, NULL); + + DefineCustomIntVariable( + "pg_stat_ch.export_buffer_size", + "Size in MB of the bgworker export arena.", + "Covers the event staging chunk, Arrow build scratch, OTLP encode buffer and " + "network buffers. -1 = 1/8 of pg_stat_ch.memory_limit clamped to [8 MB, 64 MB]. " + "Replaces batch_max, otel_max_block_bytes, otel_log_max_bytes and otel_log_batch_size.", + &psch_export_buffer_size_mb, + -1, // bootValue: auto + -1, 512, // min (-1 = auto; explicit minimum 8 via check hook), max + PGC_POSTMASTER, + GUC_UNIT_MB, + CheckExportBufferSize, NULL, NULL); DefineCustomIntVariable( "pg_stat_ch.flush_interval_ms", - "Interval in milliseconds between ClickHouse export batches.", + "Interval in milliseconds between export batches.", NULL, &psch_flush_interval_ms, 500, // bootValue @@ -228,73 +398,15 @@ void PschInitGuc(void) { NULL, NULL, NULL); DefineCustomIntVariable( - "pg_stat_ch.batch_max", - "Maximum number of events per ClickHouse insert batch.", - NULL, - &psch_batch_max, - 200000, // bootValue - 1, 1000000, // min, max - PGC_SIGHUP, - 0, - NULL, NULL, NULL); - - DefineCustomIntVariable( - "pg_stat_ch.otel_log_queue_size", - "Compatibility setting for legacy OTel queue sizing.", - "Retained for compatibility. The direct OTLP log exporter uses pg_stat_ch's " - "shared-memory queue instead of allocating a second OTel queue.", - &psch_otel_log_queue_size, - 65536, // bootValue - 512, 1048576, // min, max - PGC_POSTMASTER, - 0, - NULL, NULL, NULL); - - DefineCustomIntVariable( - "pg_stat_ch.otel_log_batch_size", - "Maximum records per OTLP log export call.", - "Caps how many log records the direct OTLP exporter puts into a single " - "gRPC ExportLogs request.", - &psch_otel_log_batch_size, - 8192, // bootValue - 1, 131072, // min, max - PGC_POSTMASTER, - 0, - NULL, NULL, NULL); - - DefineCustomIntVariable( - "pg_stat_ch.otel_log_max_bytes", - "Soft byte budget for a single OTLP log export call.", - "The direct OTLP exporter chunks log records to stay under this per-request " - "budget. The gRPC default is 4 MiB; the default leaves a safety margin.", - &psch_otel_log_max_bytes, - 3 * 1024 * 1024, // bootValue: 3 MiB - 65536, 64 * 1024 * 1024, // min: 64 KiB, max: 64 MiB - PGC_POSTMASTER, - GUC_UNIT_BYTE, - NULL, NULL, NULL); - - DefineCustomIntVariable( - "pg_stat_ch.otel_log_delay_ms", - "Deadline in milliseconds for a single OTLP log export call.", - "The direct OTLP exporter uses this as the per-request gRPC timeout so " - "the bgworker cannot block indefinitely on a slow collector.", - &psch_otel_log_delay_ms, - 100, // bootValue + "pg_stat_ch.export_timeout_ms", + "Deadline in milliseconds for a single export request.", + "Bounds connect plus request/response per export call so the bgworker cannot " + "block indefinitely on a slow collector. Renames otel_log_delay_ms; the default " + "leaves room for a TLS reconnect inside one request.", + &psch_export_timeout_ms, + 1000, // bootValue 10, 60000, // min, max - PGC_POSTMASTER, - GUC_UNIT_MS, - NULL, NULL, NULL); - - DefineCustomIntVariable( - "pg_stat_ch.otel_metric_interval_ms", - "Compatibility setting for legacy OTel metric export interval.", - "Retained for compatibility. The direct OTLP exporter currently sends logs only, " - "so this setting has no effect.", - &psch_otel_metric_interval_ms, - 5000, // bootValue - 100, 300000, // min, max (100ms to 5min) - PGC_POSTMASTER, + PGC_SIGHUP, GUC_UNIT_MS, NULL, NULL, NULL); @@ -309,6 +421,7 @@ void PschInitGuc(void) { PGC_SUSET, 0, NULL, NULL, NULL); + DefineCustomIntVariable( "pg_stat_ch.min_duration_us", "Minimum query duration in microseconds to always capture.", @@ -325,7 +438,8 @@ void PschInitGuc(void) { "pg_stat_ch.normalize_cache_max", "Maximum entries in the per-backend normalized query cache.", "Controls the LRU cache that bridges parse-time normalization to " - "executor-time event export. Takes effect at first query after backend start.", + "executor-time event export. Takes effect at first query after backend start. " + "Per-backend memory, deliberately outside pg_stat_ch.memory_limit.", &psch_normalize_cache_max, 32768, // bootValue 64, 65536, // min, max @@ -348,7 +462,7 @@ void PschInitGuc(void) { DefineCustomBoolVariable( "pg_stat_ch.otel_arrow_passthrough", "Send Arrow IPC batches via OTel instead of per-record proto.", - "When enabled together with use_otel, the bgworker builds Arrow RecordBatches " + "When enabled together with use_otel, the bgworker builds Arrow record batches " "from the event queue and sends them as opaque OTLP LogRecord bodies.", &psch_otel_arrow_passthrough, false, @@ -356,19 +470,6 @@ void PschInitGuc(void) { 0, NULL, NULL, NULL); - DefineCustomIntVariable( - "pg_stat_ch.otel_max_block_bytes", - "Maximum Arrow batch size in bytes per OTLP request.", - "Controls the soft byte budget (estimated, pre-compression) for a single " - "Arrow IPC batch before it is flushed. ZSTD compression typically shrinks " - "the payload 20-30x, so this budget can safely exceed the gRPC wire limit.", - &psch_otel_max_block_bytes, - 3 * 1024 * 1024, // bootValue: 3 MiB - 65536, 16 * 1024 * 1024, // min: 64 KiB, max: 16 MiB - PGC_SIGHUP, - GUC_UNIT_BYTE, - NULL, NULL, NULL); - DefineCustomStringVariable( "pg_stat_ch.extra_attributes", "Key-value pairs appended to exported Arrow batches.", @@ -382,7 +483,7 @@ void PschInitGuc(void) { DefineCustomStringVariable( "pg_stat_ch.debug_arrow_dump_dir", - "Directory for dumping raw Arrow IPC payloads before gRPC send.", + "Directory for dumping raw Arrow IPC payloads before send.", "When non-empty, each Arrow IPC payload is written to this directory before " "being sent through OTLP. Intended for test validation and debugging only.", &psch_debug_arrow_dump_dir, @@ -401,7 +502,86 @@ void PschInitGuc(void) { PGC_SUSET, 0, NULL, NULL, NULL); + + // --- Deprecated one-release bridges -------------------------------------- + // Hidden (GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE), default -1 = unset; explicit + // use draws a one-time deprecation WARNING naming the successor. Only + // memory_budget.c may read these; it folds them in iff the successor GUC is + // still -1/at default: + // batch_max, otel_log_batch_size -> export_buffer_size: arena sized so its + // staging share holds that many PschEvents. + // otel_max_block_bytes -> export_buffer_size: arena sized so its Arrow + // scratch share covers the requested block bytes. + // otel_log_max_bytes -> export_buffer_size: arena sized so its encode + // share covers it (the 16 MiB encode ceiling still applies). + // otel_log_delay_ms -> export_timeout_ms via a dynamic-default + // write-back in PschMemoryBudgetWriteBack(). + // Bridge-derived arena sizes are clamped to [8 MB, 64 MB] (the old 200000 + // event batch_max default implied ~880 MB of transient staging — that is the + // bug this rewrite deletes, deliberately not honored). Contexts are + // POSTMASTER (batch_max and otel_max_block_bytes were SIGHUP) because + // folding happens once at budget resolution. + + DefineCustomIntVariable( + "pg_stat_ch.batch_max", + "DEPRECATED: use pg_stat_ch.export_buffer_size.", + "Maximum number of events per export batch. Folded into the export arena " + "staging size when export_buffer_size is -1.", + &psch_bridge_batch_max, + -1, // bootValue: unset + -1, 1000000, // min, max + PGC_POSTMASTER, + GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE, + CheckBridgeBatchMax, NULL, NULL); + + DefineCustomIntVariable( + "pg_stat_ch.otel_max_block_bytes", + "DEPRECATED: use pg_stat_ch.export_buffer_size.", + "Soft byte budget for a single Arrow IPC batch. Folded into the export arena " + "Arrow scratch size when export_buffer_size is -1.", + &psch_bridge_otel_max_block_bytes, + -1, // bootValue: unset + -1, 16 * 1024 * 1024, // min, max: 16 MiB + PGC_POSTMASTER, + GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_UNIT_BYTE, + CheckBridgeOtelMaxBlockBytes, NULL, NULL); + + DefineCustomIntVariable( + "pg_stat_ch.otel_log_max_bytes", + "DEPRECATED: use pg_stat_ch.export_buffer_size.", + "Soft byte budget for a single OTLP export request. Folded into the export " + "arena encode buffer size when export_buffer_size is -1.", + &psch_bridge_otel_log_max_bytes, + -1, // bootValue: unset + -1, 64 * 1024 * 1024, // min, max: 64 MiB + PGC_POSTMASTER, + GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_UNIT_BYTE, + CheckBridgeOtelLogMaxBytes, NULL, NULL); + + DefineCustomIntVariable( + "pg_stat_ch.otel_log_batch_size", + "DEPRECATED: use pg_stat_ch.export_buffer_size.", + "Maximum records per OTLP export call. Folded into the export arena staging " + "size when export_buffer_size is -1.", + &psch_bridge_otel_log_batch_size, + -1, // bootValue: unset + -1, 131072, // min, max + PGC_POSTMASTER, + GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE, + CheckBridgeOtelLogBatchSize, NULL, NULL); + + DefineCustomIntVariable( + "pg_stat_ch.otel_log_delay_ms", + "DEPRECATED: use pg_stat_ch.export_timeout_ms.", + "Deadline in milliseconds for a single export call. Becomes the dynamic " + "default of export_timeout_ms when that GUC is not set explicitly.", + &psch_bridge_otel_log_delay_ms, + -1, // bootValue: unset + -1, 60000, // min, max + PGC_POSTMASTER, + GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_UNIT_MS, + CheckBridgeOtelLogDelayMs, NULL, NULL); // clang-format on - EmitWarningsOnPlaceholders("pg_stat_ch"); + MarkGUCPrefixReserved("pg_stat_ch"); } diff --git a/src/config/memory_budget.c b/src/config/memory_budget.c new file mode 100644 index 0000000..0825f33 --- /dev/null +++ b/src/config/memory_budget.c @@ -0,0 +1,289 @@ +// Resolution of pg_stat_ch.memory_limit into per-component budgets. +// Policy in src/config/memory_budget.h and OTEL_REWRITE_DESIGN.md §6. +// +// Resolution order: total -> ring slots (+ charged intern HTAB) -> export +// arena -> DSA string area (absorbs the remainder). Explicit overrides win +// and auto-raise the total with one WARNING; nothing here is ever FATAL. +// +// All entry points are init-path only (postmaster shmem_request_hook, or a +// backend running pg_stat_ch_memory()); the result is cached after the first +// call. On fork-based platforms backends inherit the postmaster's cache, so +// source attribution survives the write-back; under EXEC_BACKEND a backend +// re-resolves against written-back values, which yields identical sizes but +// may report "override" for auto-derived components. + +#include "postgres.h" + +#include "storage/bufmgr.h" +#include "utils/guc.h" +#include "utils/hsearch.h" + +#include "config/guc.h" +#include "config/memory_budget.h" +#include "export/exporter.h" +#include "queue/ring_entry.h" + +static const uint64 kMegabyte = 1024 * 1024; + +// sizeof(PschQueryInternEntry) in src/queue/query_intern.c. The struct is +// private to that file: key {Oid + pad, uint64, uint64, uint16 + pad} = 32, +// dsa_pointer = 8, uint32 refcount + tail pad = 8. Keep in sync if the +// interner key/entry changes (panel-verified figure: 48). +static const Size kInternEntrySize = 48; + +// Ring floor per design §6; max mirrors the pg_stat_ch.queue_capacity range. +static const uint32 kMinRingSlots = 4096; +static const uint32 kMaxRingSlots = 4194304; // 2^22 + +static const uint64 kMinArenaBytes = 8 * 1024 * 1024; +static const uint64 kMaxArenaBytes = 64 * 1024 * 1024; + +static PschMemoryBudget budget_cache; +static bool budget_cache_valid = false; + +static uint64 ClampU64(uint64 v, uint64 lo, uint64 hi) { + if (v < lo) { + return lo; + } + if (v > hi) { + return hi; + } + return v; +} + +static uint64 RoundUpToMb(uint64 v) { + return ((v + kMegabyte - 1) / kMegabyte) * kMegabyte; +} + +static uint32 RoundUpPow2(uint32 v) { + uint32 pow2 = 1; + + // The queue_capacity GUC range caps v at 2^22, so the shift cannot overflow. + while (pow2 < v) { + pow2 <<= 1; + } + return pow2; +} + +// Full per-capacity cost charged to the budget: ring slots plus the intern +// HTAB, which is sized at queue_capacity entries (query_intern.c) and must +// not ride for free. +static uint64 RingPlusInternBytes(uint32 slots) { + return (uint64)slots * sizeof(PschRingEntry) + + (uint64)hash_estimate_size((long)slots, kInternEntrySize); +} + +// Largest power of 2 whose ring+intern cost fits half the total, floor 4096. +static uint32 AutoRingSlots(uint64 total_bytes) { + uint64 half = total_bytes / 2; + uint32 best = kMinRingSlots; + uint32 slots = kMinRingSlots; + + for (;;) { + if (RingPlusInternBytes(slots) <= half) { + best = slots; + } else { + break; + } + if (slots == kMaxRingSlots) { + break; + } + slots <<= 1; + } + return best; +} + +// Smallest whole-MB arena in [8 MB, 64 MB] whose PschExportArenaSplit plan +// satisfies every explicitly-set byte/count bridge GUC. Using the real split +// function keeps the bridge mapping drift-proof against share changes in +// exporter.h. Requests beyond what 64 MB can honor are clamped — the old +// batch_max=200000 default implied ~880 MB of staging, which is exactly the +// transient-heap bug this rewrite deletes. +static uint64 BridgeArenaBytes(void) { + uint64 arena; + + for (arena = kMinArenaBytes; arena <= kMaxArenaBytes; arena += kMegabyte) { + PschExportArenaPlan plan; + + PschExportArenaSplit(arena, &plan); + if (psch_bridge_batch_max > 0 && plan.staging_events < psch_bridge_batch_max) { + continue; + } + if (psch_bridge_otel_log_batch_size > 0 && + plan.staging_events < psch_bridge_otel_log_batch_size) { + continue; + } + if (psch_bridge_otel_max_block_bytes > 0 && + plan.arrow_scratch_bytes < (size_t)psch_bridge_otel_max_block_bytes) { + continue; + } + if (psch_bridge_otel_log_max_bytes > 0 && + plan.encode_buf_bytes < + Min((size_t)psch_bridge_otel_log_max_bytes, PSCH_EXPORT_ENCODE_CEILING)) { + continue; + } + return arena; + } + return kMaxArenaBytes; +} + +static bool AnyByteBridgeSet(void) { + return psch_bridge_batch_max > 0 || psch_bridge_otel_max_block_bytes > 0 || + psch_bridge_otel_log_max_bytes > 0 || psch_bridge_otel_log_batch_size > 0; +} + +static void Resolve(PschMemoryBudget* budget) { + uint64 total; + uint64 component_sum; + + MemSet(budget, 0, sizeof(*budget)); + + if (psch_memory_limit_mb == -1) { + // Opt-in auto: clamp(shared_buffers/16, 48 MB, 256 MB). NBuffers is in + // BLCKSZ pages and is final by shmem_request_hook time. + uint64 shared_buffers_bytes = (uint64)NBuffers * BLCKSZ; + + total = ClampU64(shared_buffers_bytes / 16, 48 * kMegabyte, 256 * kMegabyte); + } else { + total = (uint64)psch_memory_limit_mb * kMegabyte; + } + + if (psch_queue_capacity > 0) { + // The check hook already rounded; round again defensively for the + // not-via-GUC path (extension loaded without registration). Honor the + // same kMinRingSlots floor as the auto path so an explicit tiny value + // cannot produce a uselessly small ring. + budget->ring_slots = Max(RoundUpPow2((uint32)psch_queue_capacity), kMinRingSlots); + budget->ring_source = PSCH_BUDGET_OVERRIDE; + } else { + budget->ring_slots = AutoRingSlots(total); + budget->ring_source = PSCH_BUDGET_AUTO; + } + budget->ring_bytes = (uint64)budget->ring_slots * sizeof(PschRingEntry); + budget->intern_bytes = (uint64)hash_estimate_size((long)budget->ring_slots, kInternEntrySize); + + if (psch_export_buffer_size_mb > 0) { + budget->export_arena_bytes = (uint64)psch_export_buffer_size_mb * kMegabyte; + budget->arena_source = PSCH_BUDGET_OVERRIDE; + } else if (AnyByteBridgeSet()) { + // Bridge-derived counts as an override: the operator asked for specific + // capacities, just via deprecated knobs. + budget->export_arena_bytes = BridgeArenaBytes(); + budget->arena_source = PSCH_BUDGET_OVERRIDE; + } else { + budget->export_arena_bytes = RoundUpToMb(ClampU64(total / 8, kMinArenaBytes, kMaxArenaBytes)); + budget->arena_source = PSCH_BUDGET_AUTO; + } + + if (psch_string_area_size > 0) { + budget->dsa_bytes = (uint64)psch_string_area_size * kMegabyte; + budget->dsa_source = PSCH_BUDGET_OVERRIDE; + } else { + // DSA absorbs the remainder (pow2 rounding loss becomes string capacity). + // Truncated to whole MB so the value round-trips through the GUC + // write-back (psch_dsa.c sizes the area from the GUC), and clamped to the + // 8..1024 MB GUC range. + uint64 used = budget->ring_bytes + budget->intern_bytes + budget->export_arena_bytes; + uint64 remainder = total > used ? total - used : 0; + + remainder -= remainder % kMegabyte; + budget->dsa_bytes = ClampU64(remainder, 8 * kMegabyte, 1024 * kMegabyte); + budget->dsa_source = PSCH_BUDGET_AUTO; + } + + // Overrides (and component floors) never starve siblings: the total gives + // way instead. Never FATAL — old fleet templates must keep booting. + component_sum = + budget->ring_bytes + budget->intern_bytes + budget->export_arena_bytes + budget->dsa_bytes; + if (component_sum > total) { + total = component_sum; + budget->raised = true; + } + budget->total_bytes = total; +} + +const PschMemoryBudget* PschMemoryBudgetGet(void) { + if (!budget_cache_valid) { + Resolve(&budget_cache); + budget_cache_valid = true; + } + return &budget_cache; +} + +static const char* SourceText(PschBudgetSource source) { + return source == PSCH_BUDGET_OVERRIDE ? "override" : "auto"; +} + +static const char* TotalSourceText(const PschMemoryBudget* budget) { + if (budget->raised) { + return "raised"; + } + return psch_memory_limit_mb == -1 ? "auto" : "configured"; +} + +void PschMemoryBudgetWriteBack(void) { + const PschMemoryBudget* budget = PschMemoryBudgetGet(); + static bool done = false; + char value[32]; + + if (done) { + return; + } + done = true; + + // wal_buffers idiom: PGC_S_DYNAMIC_DEFAULT loses to explicit settings, so + // operator-set components keep their (check-hook-normalized) values and + // auto components start SHOWing their effective sizes. + snprintf(value, sizeof(value), "%u", budget->ring_slots); + SetConfigOption("pg_stat_ch.queue_capacity", value, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT); + + snprintf(value, sizeof(value), UINT64_FORMAT, budget->dsa_bytes / kMegabyte); + SetConfigOption("pg_stat_ch.string_area_size", value, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT); + + snprintf(value, sizeof(value), UINT64_FORMAT, budget->export_arena_bytes / kMegabyte); + SetConfigOption("pg_stat_ch.export_buffer_size", value, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT); + + // otel_log_delay_ms bridge: becomes the dynamic default of its successor; + // ignored automatically when export_timeout_ms was set explicitly. + if (psch_bridge_otel_log_delay_ms > 0) { + snprintf(value, sizeof(value), "%d", psch_bridge_otel_log_delay_ms); + SetConfigOption("pg_stat_ch.export_timeout_ms", value, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT); + } + + if (budget->raised) { + uint64 raised_mb = (budget->total_bytes + kMegabyte - 1) / kMegabyte; + + // Component maxima keep the sum under the 4096 MB GUC max, but clamp so a + // future range change cannot turn the write-back into a boot failure. + snprintf(value, sizeof(value), UINT64_FORMAT, Min(raised_mb, (uint64)4096)); + SetConfigOption("pg_stat_ch.memory_limit", value, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT); + + ereport(WARNING, + (errmsg("pg_stat_ch: effective memory_limit raised to " UINT64_FORMAT + " MB to fit configured components", + raised_mb), + errdetail("ring_queue=%u slots/" UINT64_FORMAT " kB (%s), intern_table=" UINT64_FORMAT + " kB (derived), string_area=" UINT64_FORMAT " kB (%s), " + "export_arena=" UINT64_FORMAT " kB (%s).", + budget->ring_slots, budget->ring_bytes / 1024, + SourceText(budget->ring_source), budget->intern_bytes / 1024, + budget->dsa_bytes / 1024, SourceText(budget->dsa_source), + budget->export_arena_bytes / 1024, SourceText(budget->arena_source)), + errhint("Raise pg_stat_ch.memory_limit or remove the component overrides."))); + } +} + +void PschMemoryBudgetLogStartup(void) { + const PschMemoryBudget* budget = PschMemoryBudgetGet(); + + ereport( + LOG, + (errmsg("pg_stat_ch: memory budget total=" UINT64_FORMAT + " kB (%s): ring_queue=%u slots/" UINT64_FORMAT " kB (%s), intern_table=" UINT64_FORMAT + " kB (derived), string_area=" UINT64_FORMAT " kB (%s), export_arena=" UINT64_FORMAT + " kB (%s)", + budget->total_bytes / 1024, TotalSourceText(budget), budget->ring_slots, + budget->ring_bytes / 1024, SourceText(budget->ring_source), + budget->intern_bytes / 1024, budget->dsa_bytes / 1024, SourceText(budget->dsa_source), + budget->export_arena_bytes / 1024, SourceText(budget->arena_source)))); +} diff --git a/src/config/memory_budget.h b/src/config/memory_budget.h new file mode 100644 index 0000000..d638a70 --- /dev/null +++ b/src/config/memory_budget.h @@ -0,0 +1,53 @@ +// Resolution of pg_stat_ch.memory_limit into component budgets. +// See OTEL_REWRITE_DESIGN.md §6. Pure computation + GUC write-back; the +// consumers are src/queue/shmem.c (ring slots, DSA size, intern HTAB) and +// src/export/stats_exporter.c (export arena), plus pg_stat_ch_memory(). +// +// Policy (critique-hardened): +// * memory_limit default 160 MB == verified equivalence point of the old +// defaults (131072 slots x 520 B ring + intern HTAB + 64 MB DSA + arena). +// -1 = opt-in auto: clamp(shared_buffers/16, 48 MB, 256 MB). +// * Per-slot ring cost = sizeof(PschRingEntry) + intern HTAB estimate +// (hash_estimate_size(cap, entry) / cap) — the intern table is sized by +// queue_capacity and MUST be charged to the budget. +// * Explicit overrides win and AUTO-RAISE the total with a WARNING; never +// FATAL, never starve sibling components. DSA absorbs the power-of-2 +// rounding remainder. +// * Resolved values are written back via SetConfigOption(PGC_S_DYNAMIC_DEFAULT) +// so SHOW reports effective sizes (wal_buffers idiom). +#ifndef PG_STAT_CH_MEMORY_BUDGET_H +#define PG_STAT_CH_MEMORY_BUDGET_H + +typedef enum PschBudgetSource { + PSCH_BUDGET_AUTO = 0, // derived from memory_limit + PSCH_BUDGET_OVERRIDE, // operator set the component GUC explicitly +} PschBudgetSource; + +typedef struct PschMemoryBudget { + uint64 total_bytes; // effective total (>= configured if overrides raised it) + bool raised; // true when overrides pushed past configured memory_limit + + uint32 ring_slots; // power of 2 + uint64 ring_bytes; // ring_slots * sizeof(PschRingEntry) + uint64 intern_bytes; + PschBudgetSource ring_source; + + uint64 dsa_bytes; + PschBudgetSource dsa_source; + + uint64 export_arena_bytes; + PschBudgetSource arena_source; +} PschMemoryBudget; + +// Resolve once per process (idempotent, cached). Safe to call from +// shmem_request_hook (shared_buffers is final there) and later. +extern const PschMemoryBudget* PschMemoryBudgetGet(void); + +// SetConfigOption(PGC_S_DYNAMIC_DEFAULT) write-back of resolved component +// values + one WARNING if `raised`. Call once from shmem_request_hook. +extern void PschMemoryBudgetWriteBack(void); + +// One startup LOG line with the full resolved derivation table. +extern void PschMemoryBudgetLogStartup(void); + +#endif // PG_STAT_CH_MEMORY_BUDGET_H diff --git a/src/config/memory_view.c b/src/config/memory_view.c new file mode 100644 index 0000000..d6cb744 --- /dev/null +++ b/src/config/memory_view.c @@ -0,0 +1,63 @@ +// pg_stat_ch_memory() — SQL surface for the resolved memory budget. +// One row per budget component (total, ring_queue, intern_table, string_area, +// export_arena) plus the export_dropped counter (post-dequeue poison-batch +// drops, distinct from enqueue-overflow drops in pg_stat_ch_stats). + +#include "postgres.h" + +#include "fmgr.h" +#include "funcapi.h" +#include "nodes/execnodes.h" +#include "utils/builtins.h" +#include "utils/tuplestore.h" + +#include "config/guc.h" +#include "config/memory_budget.h" + +// Canonical declaration belongs to src/queue/shmem.h (export-driver lane); +// duplicated here so the lanes compile independently until integration. +extern uint64 PschGetExportDropped(void); + +static const char* SourceText(PschBudgetSource source) { + return source == PSCH_BUDGET_OVERRIDE ? "override" : "auto"; +} + +static void PutRow(ReturnSetInfo* rsinfo, const char* component, uint64 bytes, const char* source) { + Datum values[3]; + bool nulls[3] = {false, false, false}; + + values[0] = CStringGetTextDatum(component); + values[1] = Int64GetDatum((int64)bytes); + values[2] = CStringGetTextDatum(source); + tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls); +} + +// SQL function: pg_stat_ch_memory() +// RETURNS TABLE(component text, budget_bytes bigint, source text) +PG_FUNCTION_INFO_V1(pg_stat_ch_memory); +Datum pg_stat_ch_memory(PG_FUNCTION_ARGS) { + ReturnSetInfo* rsinfo = (ReturnSetInfo*)fcinfo->resultinfo; + const PschMemoryBudget* budget; + const char* total_source; + + InitMaterializedSRF(fcinfo, 0); + + budget = PschMemoryBudgetGet(); + if (budget->raised) { + total_source = "raised"; + } else { + total_source = psch_memory_limit_mb == -1 ? "auto" : "configured"; + } + + PutRow(rsinfo, "total", budget->total_bytes, total_source); + PutRow(rsinfo, "ring_queue", budget->ring_bytes, SourceText(budget->ring_source)); + PutRow(rsinfo, "intern_table", budget->intern_bytes, "derived"); + PutRow(rsinfo, "string_area", budget->dsa_bytes, SourceText(budget->dsa_source)); + PutRow(rsinfo, "export_arena", budget->export_arena_bytes, SourceText(budget->arena_source)); + + // budget_bytes carries the count for counter rows; the column name is a + // compromise to keep the view single-shape. + PutRow(rsinfo, "export_dropped", PschGetExportDropped(), "counter"); + + return (Datum)0; +} diff --git a/test/regression/expected/guc.out b/test/regression/expected/guc.out index 0707840..6062947 100644 --- a/test/regression/expected/guc.out +++ b/test/regression/expected/guc.out @@ -3,7 +3,6 @@ CREATE EXTENSION pg_stat_ch; SELECT name FROM pg_settings WHERE name LIKE 'pg_stat_ch.%' ORDER BY name COLLATE "C"; name ---------------------------------------- - pg_stat_ch.batch_max pg_stat_ch.clickhouse_database pg_stat_ch.clickhouse_host pg_stat_ch.clickhouse_password @@ -14,25 +13,24 @@ SELECT name FROM pg_settings WHERE name LIKE 'pg_stat_ch.%' ORDER BY name COLLAT pg_stat_ch.debug_arrow_dump_dir pg_stat_ch.debug_force_locked_overflow pg_stat_ch.enabled + pg_stat_ch.export_buffer_size + pg_stat_ch.export_timeout_ms pg_stat_ch.extra_attributes pg_stat_ch.flush_interval_ms pg_stat_ch.hostname pg_stat_ch.log_min_elevel + pg_stat_ch.memory_limit pg_stat_ch.min_duration_us pg_stat_ch.normalize_cache_max pg_stat_ch.otel_arrow_passthrough + pg_stat_ch.otel_ca_file pg_stat_ch.otel_endpoint - pg_stat_ch.otel_log_batch_size - pg_stat_ch.otel_log_delay_ms - pg_stat_ch.otel_log_max_bytes - pg_stat_ch.otel_log_queue_size - pg_stat_ch.otel_max_block_bytes - pg_stat_ch.otel_metric_interval_ms + pg_stat_ch.otel_headers pg_stat_ch.queue_capacity pg_stat_ch.sample_rate pg_stat_ch.string_area_size pg_stat_ch.use_otel -(29 rows) +(27 rows) SHOW pg_stat_ch.enabled; pg_stat_ch.enabled @@ -40,12 +38,33 @@ SHOW pg_stat_ch.enabled; on (1 row) -SHOW pg_stat_ch.string_area_size; - pg_stat_ch.string_area_size ------------------------------ - 64MB +SHOW pg_stat_ch.memory_limit; + pg_stat_ch.memory_limit +------------------------- + 160MB (1 row) +-- Deprecated bridge GUCs are GUC_NO_SHOW_ALL: absent from the pg_settings +-- list above, but still individually SHOWable until their removal release. +SHOW pg_stat_ch.batch_max; + pg_stat_ch.batch_max +---------------------- + -1 +(1 row) + +-- Memory budget surface: byte values vary with PG version and configuration, +-- but the component set and source attribution are stable. +SELECT component, source FROM pg_stat_ch_memory() ORDER BY component COLLATE "C"; + component | source +----------------+------------ + export_arena | auto + export_dropped | counter + intern_table | derived + ring_queue | auto + string_area | auto + total | configured +(6 rows) + -- Test log_min_elevel GUC SHOW pg_stat_ch.log_min_elevel; pg_stat_ch.log_min_elevel diff --git a/test/regression/sql/guc.sql b/test/regression/sql/guc.sql index de01fba..a15a0a0 100644 --- a/test/regression/sql/guc.sql +++ b/test/regression/sql/guc.sql @@ -2,7 +2,13 @@ CREATE EXTENSION pg_stat_ch; SELECT name FROM pg_settings WHERE name LIKE 'pg_stat_ch.%' ORDER BY name COLLATE "C"; SHOW pg_stat_ch.enabled; -SHOW pg_stat_ch.string_area_size; +SHOW pg_stat_ch.memory_limit; +-- Deprecated bridge GUCs are GUC_NO_SHOW_ALL: absent from the pg_settings +-- list above, but still individually SHOWable until their removal release. +SHOW pg_stat_ch.batch_max; +-- Memory budget surface: byte values vary with PG version and configuration, +-- but the component set and source attribution are stable. +SELECT component, source FROM pg_stat_ch_memory() ORDER BY component COLLATE "C"; -- Test log_min_elevel GUC SHOW pg_stat_ch.log_min_elevel; SET pg_stat_ch.log_min_elevel = 'error'; From 5d6d93dfbe61f054582c27bbd512b7f2ddda7d98 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:49 -0500 Subject: [PATCH 10/11] build: convert build system and tooling to pure C project(LANGUAGES C); any .cc/.cxx/.cpp under src/ is now a configure-time FATAL_ERROR. Drop opentelemetry-cpp/Arrow (and transitively gRPC/protobuf/ abseil) from vcpkg.json, leaving openssl/lz4/zstd; vcpkg is kept (3 deps) for static, pinned release artifacts. Remove the cxx_std_17 / -include libintl.h / -Wglobal-constructors C++ scaffolding; pin C_STANDARD 17 + C_EXTENSIONS. .clang-tidy drops google-*/modernize-* and adds bugprone-*; mise/CI format and lint globs now cover .c. CI drops g++/CXX settings. Update CLAUDE.md and README for the C/dependency story; retire the cpp-* skills. --- .clang-format | 11 +- .clang-tidy | 13 +- .claude/skills/cpp-header-template/SKILL.md | 137 -------- .claude/skills/cpp-naming-check/SKILL.md | 74 ---- .claude/skills/cpp-review/SKILL.md | 74 ---- .claude/skills/google-cpp-style/SKILL.md | 141 -------- .claude/skills/google-cpp-style/classes.md | 203 ----------- .claude/skills/google-cpp-style/comments.md | 175 ---------- .claude/skills/google-cpp-style/features.md | 206 ------------ .claude/skills/google-cpp-style/formatting.md | 316 ------------------ .claude/skills/google-cpp-style/functions.md | 140 -------- .claude/skills/google-cpp-style/headers.md | 118 ------- .claude/skills/google-cpp-style/naming.md | 204 ----------- .claude/skills/google-cpp-style/scoping.md | 175 ---------- .github/actions/setup-vcpkg/action.yml | 5 +- .github/workflows/ci-tap.yml | 3 +- .github/workflows/ci.yml | 19 +- .github/workflows/release.yml | 2 +- CLAUDE.md | 43 ++- CMakeLists.txt | 111 +++--- README.md | 2 +- cmake/CompilerWarnings.cmake | 13 +- docker/postgres-ext.Dockerfile | 2 + mise.toml | 8 +- vcpkg.json | 10 +- 25 files changed, 117 insertions(+), 2088 deletions(-) delete mode 100644 .claude/skills/cpp-header-template/SKILL.md delete mode 100644 .claude/skills/cpp-naming-check/SKILL.md delete mode 100644 .claude/skills/cpp-review/SKILL.md delete mode 100644 .claude/skills/google-cpp-style/SKILL.md delete mode 100644 .claude/skills/google-cpp-style/classes.md delete mode 100644 .claude/skills/google-cpp-style/comments.md delete mode 100644 .claude/skills/google-cpp-style/features.md delete mode 100644 .claude/skills/google-cpp-style/formatting.md delete mode 100644 .claude/skills/google-cpp-style/functions.md delete mode 100644 .claude/skills/google-cpp-style/headers.md delete mode 100644 .claude/skills/google-cpp-style/naming.md delete mode 100644 .claude/skills/google-cpp-style/scoping.md diff --git a/.clang-format b/.clang-format index b86dade..40d5d5e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,11 +1,11 @@ --- +# Language stays Cpp: clang-format has no separate C mode; Cpp mode formats C. Language: Cpp BasedOnStyle: Google ColumnLimit: 100 IndentWidth: 2 TabWidth: 2 UseTab: Never -AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignConsecutiveMacros: true AlignTrailingComments: true @@ -14,14 +14,10 @@ AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Empty AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: Inline AllowShortLoopsOnASingleLine: false -AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true BreakBeforeBraces: Attach -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon DerivePointerAlignment: false PointerAlignment: Left IncludeBlocks: Preserve @@ -42,14 +38,11 @@ IncludeCategories: Priority: 3 SortIncludes: true SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false -SpacesInAngles: false SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: true SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: c++17 +Standard: Latest diff --git a/.clang-tidy b/.clang-tidy index 26c57c2..a6b90cf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,12 +1,15 @@ --- +# C codebase: google-* and modernize-* (C++-only check sets) are intentionally +# absent; bugprone-* carries the leak/UB checks the C error paths rely on. +# bugprone-easily-swappable-parameters is excluded: the (buf, len) and +# (errbuf, errlen) parameter pairs used throughout the export API trip it on +# nearly every function. Checks: > -*, + bugprone-*, + -bugprone-easily-swappable-parameters, clang-analyzer-*, clang-diagnostic-*, - google-*, - -google-readability-todo, - modernize-*, - -modernize-use-trailing-return-type, readability-*, -readability-magic-numbers, -readability-identifier-length @@ -15,7 +18,7 @@ WarningsAsErrors: > clang-analyzer-core.NullDereference, clang-analyzer-unix.* -HeaderFilterRegex: 'include/pg_stat_ch/.*' +HeaderFilterRegex: '(include/(pg_stat_ch|config)|src)/.*' CheckOptions: - key: readability-identifier-naming.ClassCase diff --git a/.claude/skills/cpp-header-template/SKILL.md b/.claude/skills/cpp-header-template/SKILL.md deleted file mode 100644 index 6351bff..0000000 --- a/.claude/skills/cpp-header-template/SKILL.md +++ /dev/null @@ -1,137 +0,0 @@ ---- -name: cpp-header-template -description: Generate C++ header files following Google Style Guide. Use when creating new header files or asking for a header template. -disable-model-invocation: true ---- - -# C++ Header File Template Generator - -Generate header files following Google C++ Style Guide conventions. - -## Usage - -Provide: class name, namespace, and file path to generate a compliant header. - -## Template - -```cpp -// Copyright [year] [copyright holder] -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. - -#ifndef [PROJECT]_[PATH]_[FILENAME]_H_ -#define [PROJECT]_[PATH]_[FILENAME]_H_ - -// C system headers (if needed) -// #include - -// C++ standard library headers -#include -#include -#include - -// Other library headers -// #include "other/library.h" - -// Project headers -// #include "project/base.h" - -namespace [namespace] { - -// Forward declarations (avoid when possible) - -/// Brief description of the class. -/// -/// Detailed description if needed. Include: -/// - Purpose and responsibilities -/// - Thread safety guarantees -/// - Example usage (for complex classes) -class [ClassName] { - public: - // Types and type aliases - using ValueType = int; - - // Static constants - static constexpr int kDefaultSize = 100; - - // Factory functions (if needed) - static std::unique_ptr<[ClassName]> Create(); - - // Constructors - [ClassName](); - explicit [ClassName](int value); - - // Rule of five - be explicit about copy/move - [ClassName](const [ClassName]&) = default; - [ClassName]& operator=([const ClassName]&) = default; - [ClassName]([ClassName]&&) noexcept = default; - [ClassName]& operator=([ClassName]&&) noexcept = default; - - // Destructor - ~[ClassName](); - - // Public methods - void Process(); - - // Accessors and mutators - int value() const { return value_; } - void set_value(int value) { value_ = value; } - - protected: - // Protected members (only if needed for inheritance) - - private: - // Private methods - void InternalHelper(); - - // Data members (always private for classes) - int value_ = 0; - std::string name_; -}; - -} // namespace [namespace] - -#endif // [PROJECT]_[PATH]_[FILENAME]_H_ -``` - -## Include Guard Format - -Convert path to uppercase with underscores: - -| File Path | Guard | -|-----------|-------| -| `foo/bar/baz.h` | `FOO_BAR_BAZ_H_` | -| `src/http/parser.h` | `SRC_HTTP_PARSER_H_` | -| `my_project/utils.h` | `MY_PROJECT_UTILS_H_` | - -## Struct Template - -For passive data with public members and no invariants: - -```cpp -namespace [namespace] { - -/// Brief description. -struct [StructName] { - int field_one; // No trailing underscore for structs - std::string field_two; - float field_three = 0.0f; // Default values OK -}; - -} // namespace [namespace] -``` - -## Include Order - -1. Related header (for `.cc` files) -2. Blank line -3. C system headers (``) -4. Blank line -5. C++ standard library (``, ``) -6. Blank line -7. Other libraries -8. Blank line -9. Project headers - -Each section sorted alphabetically. diff --git a/.claude/skills/cpp-naming-check/SKILL.md b/.claude/skills/cpp-naming-check/SKILL.md deleted file mode 100644 index 38f417f..0000000 --- a/.claude/skills/cpp-naming-check/SKILL.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -name: cpp-naming-check -description: Check C++ naming conventions against Google Style Guide. Use when checking if names follow conventions or when renaming identifiers. ---- - -# C++ Naming Convention Checker - -Verify names follow Google C++ Style Guide conventions. - -## Naming Rules Quick Check - -| Entity | Convention | Pattern | Examples | -|--------|------------|---------|----------| -| Files | lowercase + `_` or `-` | `snake_case.cc` | `my_class.cc`, `http-parser.h` | -| Classes | PascalCase | `[A-Z][a-zA-Z0-9]*` | `MyClass`, `UrlParser` | -| Structs | PascalCase | `[A-Z][a-zA-Z0-9]*` | `Point`, `HttpRequest` | -| Type aliases | PascalCase | `[A-Z][a-zA-Z0-9]*` | `DataMap`, `StringList` | -| Enums | PascalCase | `[A-Z][a-zA-Z0-9]*` | `ErrorCode`, `State` | -| Enumerators | kPascalCase | `k[A-Z][a-zA-Z0-9]*` | `kOk`, `kNotFound` | -| Functions | PascalCase | `[A-Z][a-zA-Z0-9]*` | `ProcessData()`, `GetValue()` | -| Accessors | snake_case | `[a-z][a-z0-9_]*` | `count()`, `set_count()` | -| Variables | snake_case | `[a-z][a-z0-9_]*` | `table_name`, `num_items` | -| Class members | snake_case_ | `[a-z][a-z0-9_]*_` | `value_`, `data_map_` | -| Struct members | snake_case | `[a-z][a-z0-9_]*` | `width`, `height` | -| Constants | kPascalCase | `k[A-Z][a-zA-Z0-9]*` | `kMaxSize`, `kPi` | -| Macros | UPPER_CASE | `[A-Z][A-Z0-9_]*` | `MY_MACRO`, `DEBUG_LOG` | -| Namespaces | snake_case | `[a-z][a-z0-9_]*` | `my_project`, `internal` | -| Template params | Varies | Type=`T`, value=`n` | `T`, `InputIterator`, `N` | - -## Common Mistakes - -### ❌ Wrong → ✅ Correct - -```cpp -// Classes -class myClass; → class MyClass; -class HTTPParser; → class HttpParser; // Treat acronyms as words - -// Variables -int TableName; → int table_name; -int tablename; → int table_name; // Use underscores - -// Class members -int value; → int value_; // Trailing underscore -int m_value; → int value_; // No Hungarian notation - -// Functions -void process_data(); → void ProcessData(); -void getValue(); → void GetValue(); // Or get_value() if accessor - -// Constants -const int MAX_SIZE; → const int kMaxSize; -const int maxSize; → const int kMaxSize; - -// Enumerators -enum { ERROR_OK }; → enum { kErrorOk }; -enum { Ok }; → enum { kOk }; - -// Macros (must be UPPER_CASE with prefix) -#define DEBUG → #define MYPROJECT_DEBUG -``` - -## Abbreviations - -- **OK**: Listed in Wikipedia or universally known (`i`, `n`, `id`, `url`) -- **Capitalize as word**: `StartRpc()` not `StartRPC()` -- **Don't delete letters**: `customer` not `cstmr` - -## Check Process - -1. Identify the entity type (class, function, variable, etc.) -2. Apply the corresponding naming rule -3. Check for consistency with surrounding code -4. Flag any Hungarian notation or other outdated styles diff --git a/.claude/skills/cpp-review/SKILL.md b/.claude/skills/cpp-review/SKILL.md deleted file mode 100644 index 0b151b6..0000000 --- a/.claude/skills/cpp-review/SKILL.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -name: cpp-review -description: Review C++ code against Google C++ Style Guide. Use when reviewing C++ code, pull requests, or when asked to check code style compliance. ---- - -# C++ Code Review (Google Style) - -Review C++ code for compliance with the Google C++ Style Guide. - -## Review Checklist - -### Naming -- [ ] Types use `PascalCase` -- [ ] Functions use `PascalCase` (accessors use `snake_case`) -- [ ] Variables use `snake_case` -- [ ] Class members have trailing underscore: `member_` -- [ ] Constants use `kPascalCase` -- [ ] Macros use `UPPER_CASE` with project prefix - -### Headers -- [ ] Has `#define` guard: `PROJECT_PATH_FILE_H_` -- [ ] Self-contained (includes all dependencies) -- [ ] Includes ordered: related header, C system, C++ stdlib, other libs, project -- [ ] No forward declarations unless necessary - -### Classes -- [ ] Single-argument constructors are `explicit` -- [ ] Data members are `private` -- [ ] Copy/move semantics explicit (= default, = delete) -- [ ] No virtual calls in constructors -- [ ] Uses composition over inheritance when appropriate - -### Functions -- [ ] Returns values instead of output parameters when possible -- [ ] Parameters ordered: inputs before outputs -- [ ] Functions are ≤40 lines (prefer smaller) -- [ ] Uses `override`/`final` for virtual overrides - -### Modern C++ -- [ ] Uses `nullptr` (not `NULL` or `0`) -- [ ] Uses C++ casts (not C-style) -- [ ] Uses range-based for loops where appropriate -- [ ] Uses `auto` appropriately (not excessively) -- [ ] Smart pointers for ownership (`unique_ptr`, `shared_ptr`) - -### Formatting -- [ ] 80 character line limit -- [ ] 2-space indent -- [ ] Braces on same line as control structures -- [ ] Spaces around binary operators - -## Feedback Format - -Use severity levels: - -- 🔴 **MUST FIX**: Style violations or bugs that must be fixed -- 🟡 **SHOULD FIX**: Strong recommendations for improvement -- 🟢 **CONSIDER**: Optional enhancements or suggestions - -## Example Review Comment - -``` -🔴 **MUST FIX**: Missing `explicit` on single-argument constructor -Line 45: `Foo(int value)` should be `explicit Foo(int value)` to prevent -implicit conversions. - -🟡 **SHOULD FIX**: Function too long -Lines 78-145: `ProcessData()` is 67 lines. Consider breaking into smaller -functions for readability and testability. - -🟢 **CONSIDER**: Use structured bindings -Line 23: `auto [iter, success] = map.insert({key, value});` would be clearer -than separate `.first` and `.second` access. -``` diff --git a/.claude/skills/google-cpp-style/SKILL.md b/.claude/skills/google-cpp-style/SKILL.md deleted file mode 100644 index 6552671..0000000 --- a/.claude/skills/google-cpp-style/SKILL.md +++ /dev/null @@ -1,141 +0,0 @@ ---- -name: google-cpp-style -description: Google C++ Style Guide rules for writing clean, maintainable C++ code. Use when writing C++, reviewing code, discussing naming conventions, formatting, class design, or any C++ best practices. Covers headers, scoping, classes, functions, naming, comments, and formatting. ---- - -# Google C++ Style Guide - -This skill provides the complete Google C++ Style Guide for C++20. Apply these rules when writing or reviewing C++ code. - -## Quick Reference - -| Topic | Key Rules | -|-------|-----------| -| **Naming** | Types: `PascalCase`, functions: `PascalCase`, variables: `snake_case`, constants: `kPascalCase`, macros: `UPPER_CASE` | -| **Formatting** | 80 char lines, 2-space indent, spaces (not tabs), `{` on same line | -| **Headers** | Self-contained, `#define` guards, include what you use | -| **Classes** | Prefer composition over inheritance, explicit constructors, `private` data members | - -## Core Principles - -1. **Optimize for the reader** - Code is read more than written -2. **Be consistent** - Follow existing patterns in the codebase -3. **Avoid surprising constructs** - Prefer clear over clever - -## Target Version - -Code should target **C++20**. Do not use C++23 features or non-standard extensions. - -## Detailed References - -For complete rules on specific topics: - -- [Header Files](headers.md) - Include guards, ordering, forward declarations -- [Scoping](scoping.md) - Namespaces, linkage, static/global variables -- [Classes](classes.md) - Constructors, inheritance, operator overloading -- [Functions](functions.md) - Parameters, overloading, default arguments -- [C++ Features](features.md) - Smart pointers, exceptions, RTTI, lambdas -- [Naming](naming.md) - All naming conventions with examples -- [Comments](comments.md) - Documentation style and requirements -- [Formatting](formatting.md) - Whitespace, braces, line length - -## Common Patterns - -### Header File Template - -```cpp -#ifndef PROJECT_PATH_FILE_H_ -#define PROJECT_PATH_FILE_H_ - -#include "project/public/header.h" - -#include - -#include -#include - -#include "other/library.h" -#include "project/internal.h" - -namespace project { - -class MyClass { - public: - MyClass(); - explicit MyClass(int value); - - void DoSomething(); - int count() const { return count_; } - void set_count(int count) { count_ = count; } - - private: - int count_; -}; - -} // namespace project - -#endif // PROJECT_PATH_FILE_H_ -``` - -### Class Declaration Order - -```cpp -class MyClass { - public: - // Types and type aliases - using ValueType = int; - - // Static constants - static constexpr int kMaxSize = 100; - - // Constructors and assignment - MyClass(); - MyClass(const MyClass&) = default; - MyClass& operator=(const MyClass&) = default; - - // Destructor - ~MyClass(); - - // All other methods - void Process(); - - protected: - // Protected members (if needed) - - private: - // Private methods - void InternalHelper(); - - // Data members - int value_; -}; -``` - -### Function Comments - -```cpp -// Returns an iterator positioned at the first entry >= `start_word`. -// Returns nullptr if no such entry exists. -// The client must not use the iterator after the table is destroyed. -std::unique_ptr GetIterator(absl::string_view start_word) const; -``` - -## Critical Rules Summary - -### Always Do - -- Use `#define` guards in all headers -- Make single-argument constructors `explicit` -- Use `nullptr` (not `NULL` or `0`) for pointers -- Use `override` or `final` for virtual function overrides -- Declare data members `private` -- Initialize variables at declaration - -### Never Do - -- Use `using namespace` directives -- Use C-style casts (use `static_cast`, etc.) -- Use exceptions (in Google code) -- Use non-standard extensions -- Define macros in headers (when possible) -- Use `std::auto_ptr` (use `std::unique_ptr`) diff --git a/.claude/skills/google-cpp-style/classes.md b/.claude/skills/google-cpp-style/classes.md deleted file mode 100644 index 72ad904..0000000 --- a/.claude/skills/google-cpp-style/classes.md +++ /dev/null @@ -1,203 +0,0 @@ -# Classes - -## Doing Work in Constructors - -- Never call virtual functions in constructors -- If initialization can fail, use factory functions or `Init()` methods -- Constructors should not do complex work that could fail - -```cpp -// Bad - virtual call in constructor -class Base { - public: - Base() { DoWork(); } // Bad if DoWork is virtual - virtual void DoWork(); -}; - -// Good - factory function for fallible initialization -class Widget { - public: - static std::unique_ptr Create(Config config); - private: - Widget() = default; -}; -``` - -## Implicit Conversions - -Mark all single-argument constructors and conversion operators `explicit`: - -```cpp -class Foo { - public: - explicit Foo(int x); // Required - explicit Foo(int x, int y = 0); // Required (can be called with 1 arg) - Foo(int x, int y); // OK - requires 2 args - explicit operator bool() const; // Required - - // Copy/move constructors are exceptions - don't mark explicit - Foo(const Foo&) = default; - Foo(Foo&&) = default; -}; -``` - -**Exception**: `std::initializer_list` constructors may omit `explicit`. - -## Copyable and Movable Types - -Make copy/move semantics explicit in the public interface: - -```cpp -// Copyable class -class Copyable { - public: - Copyable(const Copyable&) = default; - Copyable& operator=(const Copyable&) = default; -}; - -// Move-only class -class MoveOnly { - public: - MoveOnly(MoveOnly&&) = default; - MoveOnly& operator=(MoveOnly&&) = default; - MoveOnly(const MoveOnly&) = delete; - MoveOnly& operator=(const MoveOnly&) = delete; -}; - -// Non-copyable, non-movable -class NotCopyableOrMovable { - public: - NotCopyableOrMovable(const NotCopyableOrMovable&) = delete; - NotCopyableOrMovable& operator=(const NotCopyableOrMovable&) = delete; -}; -``` - -## Structs vs. Classes - -Use `struct` for passive data carriers with public fields and no invariants: - -```cpp -// Good use of struct -struct Point { - float x; - float y; -}; - -// Should be a class - has invariants -class Rectangle { - public: - void SetDimensions(int w, int h); - private: - int width_; // Must be positive - int height_; // Must be positive -}; -``` - -**Note**: Struct members use `snake_case`, class members use `snake_case_` (trailing underscore). - -## Structs vs. Pairs and Tuples - -Prefer structs with named fields over `std::pair` and `std::tuple`: - -```cpp -// Bad - unclear what .first and .second mean -std::pair GetUserInfo(); - -// Good - self-documenting -struct UserInfo { - int user_id; - std::string username; -}; -UserInfo GetUserInfo(); -``` - -## Inheritance - -- Use `public` inheritance only -- Prefer composition over inheritance -- Use `final` when not designing for inheritance -- Mark base class destructors `protected` or classes `abstract` to prevent slicing - -```cpp -// Good - explicitly marks override -class Derived : public Base { - public: - void Method() override; // Use override, not virtual - void Other() final; // Cannot be overridden further -}; - -// Prefer composition -class Car { - private: - Engine engine_; // Has-a, not is-a -}; -``` - -Multiple inheritance is allowed but multiple *implementation* inheritance is discouraged. - -## Operator Overloading - -- Only overload operators when meaning is obvious -- Define operators for your own types only -- Prefer non-member binary operators - -```cpp -// Good - obvious meaning -bool operator==(const Point& a, const Point& b); -bool operator<(const Point& a, const Point& b); -Point operator+(const Point& a, const Point& b); - -// Bad - non-obvious meaning -void operator|(const Config& a, const Config& b); // What does this do? -``` - -**Do not overload**: `&&`, `||`, `,`, unary `&`, or `operator""` (user-defined literals). - -## Access Control - -- Make data members `private` -- Use accessors when needed - -```cpp -class MyClass { - public: - int value() const { return value_; } - void set_value(int v) { value_ = v; } - - private: - int value_; -}; -``` - -## Declaration Order - -Within each access specifier section, order as: - -1. Types and type aliases -2. (structs only) Non-static data members -3. Static constants -4. Factory functions -5. Constructors and assignment operators -6. Destructor -7. All other functions -8. All other data members - -```cpp -class MyClass { - public: - using ValueType = int; - static constexpr int kMax = 100; - - static std::unique_ptr Create(); - - MyClass(); - ~MyClass(); - - void DoSomething(); - int value() const; - - private: - void Helper(); - int value_; -}; -``` diff --git a/.claude/skills/google-cpp-style/comments.md b/.claude/skills/google-cpp-style/comments.md deleted file mode 100644 index 6b76f96..0000000 --- a/.claude/skills/google-cpp-style/comments.md +++ /dev/null @@ -1,175 +0,0 @@ -# Comments - -## Comment Style - -Use `//` or `/* */` consistently. `//` is more common. - -## File Comments - -Start with license boilerplate. Include a file comment only if declaring multiple abstractions: - -```cpp -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 ... - -// This file contains utilities for processing network requests. -// It provides the HttpClient class and related helper functions. -``` - -Don't duplicate file comments in `.h` and `.cc` - put it where the interface is defined. - -## Class Comments - -Document what the class is for and how to use it: - -```cpp -// Iterates over the contents of a GargantuanTable. -// Example: -// std::unique_ptr iter = table->NewIterator(); -// for (iter->Seek("foo"); !iter->done(); iter->Next()) { -// process(iter->key(), iter->value()); -// } -class GargantuanTableIterator { - // ... -}; -``` - -Include: -- Purpose and usage -- Thread safety requirements -- Small example code when helpful - -## Function Comments - -### Declaration comments - -Document what the function does and how to use it: - -```cpp -// Returns an iterator for this table, positioned at the first entry -// lexically greater than or equal to `start_word`. If there is no -// such entry, returns a null pointer. The client must not use the -// iterator after the underlying GargantuanTable has been destroyed. -// -// This method is equivalent to: -// std::unique_ptr iter = table->NewIterator(); -// iter->Seek(start_word); -// return iter; -std::unique_ptr GetIterator(absl::string_view start_word) const; -``` - -Document: -- What inputs and outputs are (use backticks for parameter names) -- Ownership semantics for pointers -- Whether null is allowed -- Performance implications - -### Definition comments - -Explain how the function works (tricky parts, algorithms used): - -```cpp -void MyClass::Process() { - // We use a two-phase approach here because... - // First, collect all items that need processing. - // ... -} -``` - -Don't repeat the declaration comment. - -### Overrides - -Focus on specifics of the override, not the base class behavior: - -```cpp -// Overrides base class to also log the operation. -void LoggingWidget::DoOperation() override; -``` - -## Variable Comments - -### Class data members - -Comment if the purpose isn't obvious: - -```cpp -private: - // Used to bounds-check table accesses. -1 means - // that we don't yet know how many entries the table has. - int num_total_entries_; -``` - -### Global variables - -Always comment: - -```cpp -// The total number of test cases that we run through in this regression test. -const int kNumTestCases = 6; -``` - -## Implementation Comments - -### Tricky code - -Explain non-obvious code before it: - -```cpp -// Divide result by two, rounding down, using a bit shift because -// the standard division operator rounds toward zero for negative numbers. -result >>= 1; -``` - -### Function argument comments - -Use when arguments aren't self-documenting: - -```cpp -// Prefer named variables or enums -ProductOptions options; -options.set_precision_decimals(7); -const DecimalNumber product = CalculateProduct(values, options); - -// Or use comments for clarity -const DecimalNumber product = - CalculateProduct(values, options, /*completion_callback=*/nullptr); -``` - -### Don'ts - -Don't state the obvious: - -```cpp -// Bad - obvious -// Find the element in the vector. -if (std::find(v.begin(), v.end(), element) != v.end()) { - -// Good - explains why -// Process "element" unless it was already processed. -if (std::find(v.begin(), v.end(), element) != v.end()) { - -// Better - self-documenting -if (!IsAlreadyProcessed(element)) { -``` - -## Punctuation, Spelling, and Grammar - -Write comments as readable prose with proper punctuation. Complete sentences are more readable than fragments. - -## TODO Comments - -Format: `TODO: context - explanation` - -```cpp -// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. -// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. -// TODO(bug 12345678): Update this list after the Foo service is turned down. -// TODO(John): Use a "*" here for concatenation operator. -``` - -Include either: -- A bug number -- A username -- A specific date/event ("Fix by November 2025") diff --git a/.claude/skills/google-cpp-style/features.md b/.claude/skills/google-cpp-style/features.md deleted file mode 100644 index 4a3e2a8..0000000 --- a/.claude/skills/google-cpp-style/features.md +++ /dev/null @@ -1,206 +0,0 @@ -# Other C++ Features - -## Smart Pointers and Ownership - -- Prefer single, fixed ownership -- Use `std::unique_ptr` for exclusive ownership -- Use `std::shared_ptr` only when truly needed (immutable shared data) -- Never use `std::auto_ptr` - -```cpp -// Good - clear ownership transfer -std::unique_ptr CreateFoo(); -void ConsumeFoo(std::unique_ptr foo); - -// Shared ownership - use sparingly -std::shared_ptr GetConfig(); -``` - -## Exceptions - -**Do not use C++ exceptions** (in Google code). - -Also avoid: `std::exception_ptr`, `std::nested_exception`. - -Use error codes, `absl::Status`, or assertions instead. - -## noexcept - -Use `noexcept` when: -- It accurately reflects the function won't throw -- There's meaningful performance benefit (especially move constructors) - -```cpp -// Good - move operations benefit from noexcept -MyClass(MyClass&&) noexcept; -MyClass& operator=(MyClass&&) noexcept; - -// Unconditional noexcept when exceptions are disabled -void Process() noexcept; -``` - -## RTTI (Run-Time Type Information) - -Avoid `typeid` and `dynamic_cast`. Prefer: -- Virtual methods -- Visitor pattern -- Redesigning the class hierarchy - -```cpp -// Bad - type-based decision tree -if (typeid(*obj) == typeid(Derived1)) { ... } -else if (typeid(*obj) == typeid(Derived2)) { ... } - -// Good - virtual method -obj->Process(); // Each derived class implements appropriately -``` - -`dynamic_cast` is OK when logic guarantees the type, but prefer `static_cast` in those cases. - -## Casting - -Use C++ casts, never C-style casts: - -| Cast | Use For | -|------|---------| -| `static_cast` | Value conversions, explicit upcasts, known downcasts | -| `const_cast` | Removing `const` (use sparingly) | -| `reinterpret_cast` | Pointer/integer conversions (dangerous) | -| `std::bit_cast` | Type punning (reinterpret bits) | -| Brace initialization | Safe arithmetic conversion: `int64_t{x}` | - -```cpp -// Good -double d = static_cast(i); -auto* derived = static_cast(base_ptr); - -// Bad -double d = (double)i; // C-style cast -``` - -## Streams - -Use streams for: -- Debug logging -- Ad-hoc, developer-facing output -- Simple I/O - -Avoid streams for: -- User-facing output (use templating libraries) -- Performance-critical code -- Untrusted input - -```cpp -// OK for debug output -std::cerr << "Debug: value = " << value << "\n"; - -// Prefer explicit formatting -std::string result = absl::StrFormat("Value: %d", value); -``` - -Do not use stateful stream features (`imbue()`, `xalloc()`, manipulators for formatting). - -## Preincrement and Predecrement - -Prefer prefix (`++i`) over postfix (`i++`) when the value isn't used: - -```cpp -for (int i = 0; i < n; ++i) { // Good - // ... -} -``` - -## const - -Use `const` wherever meaningful: -- Function parameters passed by reference/pointer -- Methods that don't modify state -- Local variables that don't change - -```cpp -void Process(const std::string& input); // Won't modify input -int GetValue() const; // Doesn't modify object -const int kBufferSize = 1024; // Constant -``` - -Put `const` first: `const int*` preferred over `int const*`. - -## constexpr, constinit, consteval - -- `constexpr`: True compile-time constants and functions -- `constinit`: Ensure constant initialization for non-const variables -- `consteval`: Functions that must run at compile time - -```cpp -constexpr int kMaxSize = 100; -constexpr int Square(int x) { return x * x; } -constinit thread_local int counter = 0; -``` - -## Integer Types - -- Use `int` for general integers -- Use `` types (`int32_t`, `int64_t`) when size matters -- Avoid unsigned types except for bit patterns - -```cpp -int count; // General use -int64_t large_value; // When > 2^31 possible -uint32_t flags; // Bit patterns OK -size_t index; // Container sizes OK -``` - -## Lambda Expressions - -```cpp -// Capture by reference when lambda's lifetime < captures -std::sort(v.begin(), v.end(), [&](int a, int b) { return a < b; }); - -// Explicit captures for escaping lambdas -executor->Schedule([&foo] { Process(foo); }); // Make captures explicit - -// Init captures for move-only types -[ptr = std::move(unique_ptr)] { ... } -``` - -**Rules:** -- Prefer explicit captures for lambdas that escape current scope -- Use default capture `[&]` only for short-lived lambdas -- Avoid default `[=]` capturing `this` implicitly - -## Template Metaprogramming - -Use sparingly. Prefer: -- Clear, simple implementations -- Well-commented complex templates -- Hiding metaprogramming as implementation details - -## Concepts and Constraints (C++20) - -- Use standard library concepts over type traits -- Avoid defining new public concepts -- Prefer `requires(Concept)` syntax - -```cpp -// Good - use standard concepts -template - requires std::integral -T Add(T a, T b); - -// Avoid - custom concept at API boundary -template // Don't expose custom concepts -void Process(T value); -``` - -## Boost - -Only use approved Boost libraries. See style guide for current list. - -## Disallowed Features - -- `` header -- `` / `` headers -- `` header -- C++20 modules -- Coroutines (without approved library) -- Non-standard extensions (`__attribute__`, inline assembly, etc.) diff --git a/.claude/skills/google-cpp-style/formatting.md b/.claude/skills/google-cpp-style/formatting.md deleted file mode 100644 index beee3b2..0000000 --- a/.claude/skills/google-cpp-style/formatting.md +++ /dev/null @@ -1,316 +0,0 @@ -# Formatting - -## Line Length - -**80 characters maximum.** - -Exceptions: -- Comment lines with URLs or long commands -- Include statements -- Header guards -- Using-declarations - -## Non-ASCII Characters - -- Use UTF-8 encoding -- Use non-ASCII characters rarely (unit tests, data parsing) -- Prefer hex encoding for clarity: `"\xEF\xBB\xBF"` or `"\uFEFF"` -- Don't use `u8` prefix, `wchar_t`, `char16_t`, `char32_t` - -## Spaces vs. Tabs - -**Use only spaces. 2-space indent.** - -## Function Declarations - -```cpp -// Fits on one line -ReturnType ClassName::FunctionName(Type par1, Type par2) { - -// Wrap at parenthesis -ReturnType ClassName::ReallyLongFunctionName(Type par_name1, Type par_name2, - Type par_name3) { - -// 4-space indent if first param doesn't fit -ReturnType LongClassName::ReallyReallyReallyLongFunctionName( - Type par_name1, // 4 space indent - Type par_name2, - Type par_name3) { - DoSomething(); // 2 space indent -} -``` - -**Rules:** -- Return type on same line as function name (or break before function name) -- No space between function name and `(` -- Open brace on same line as declaration -- Align parameters when wrapping - -## Lambda Expressions - -```cpp -int x = 0; -auto x_plus_n = [&x](int n) -> int { return x + n; }; - -// Short lambdas inline -digits.erase(std::remove_if(digits.begin(), digits.end(), [&to_remove](int i) { - return to_remove.contains(i); - }), - digits.end()); -``` - -## Floating-Point Literals - -Always include radix point with digits on both sides: - -```cpp -// Good -float f = 1.0f; -double d = 1248.0e6; -long double ld = -0.5L; - -// Bad -float f = 1.f; // Missing leading digit -double d = 1248e6; // Missing radix point -``` - -## Function Calls - -```cpp -// Fits on one line -bool result = DoSomething(argument1, argument2, argument3); - -// Align at parenthesis -bool result = DoSomething(averyveryveryverylongargument1, - argument2, argument3); - -// 4-space indent -if (...) { - bool result = DoSomething( - argument1, argument2, - argument3, argument4); -} -``` - -## Braced Initializer Lists - -Format like function calls: - -```cpp -return {foo, bar}; -std::pair p{foo, bar}; - -SomeType variable{ - "This is too long to fit all in one line"}; -``` - -## Looping and Branching - -```cpp -if (condition) { // Space after keyword, before brace - DoOneThing(); - DoAnotherThing(); -} else if (int a = f(); a != 3) { // Closing brace, else on same line - DoAThirdThing(a); -} else { - DoNothing(); -} - -while (condition) { - RepeatAThing(); -} - -for (int i = 0; i < 10; ++i) { - RepeatAThing(); -} - -switch (var) { - case 0: { - Foo(); - break; - } - default: { - Bar(); - } -} -``` - -**Always use braces**, except for single-line statements: - -```cpp -// OK - fits on one line -if (x == kFoo) return new Foo(); - -// OK - condition and body each fit on one line -if (x == kBar) - Bar(arg1, arg2, arg3); -``` - -**Fall-through** requires `[[fallthrough]]`: - -```cpp -switch (x) { - case 41: - case 43: // No annotation needed for empty cases - if (condition) { - [[fallthrough]]; - } - break; - case 42: - DoSomething(); - [[fallthrough]]; - default: - DoDefault(); - break; -} -``` - -## Pointer and Reference Expressions - -```cpp -x = *p; -p = &x; -x = r.y; -x = r->y; - -// Type declarations - no space between type and */& -char* c; -const std::string& str; -std::vector v; - -// Multiple declarations with pointers - disallowed -int x, *y; // Bad -int* x, *y; // Bad -``` - -## Boolean Expressions - -Break after operator, keep operators at end of line: - -```cpp -if (this_one_thing > this_other_thing && - a_third_thing == a_fourth_thing && - yet_another && last_one) { -``` - -Use `&&` and `||`, not `and` and `or`. - -## Return Values - -No parentheses unless needed for readability: - -```cpp -return result; - -return (some_long_condition && - another_condition); - -// Bad -return (value); -return(result); -``` - -## Variable Initialization - -All forms are acceptable: - -```cpp -int x = 3; -int x(3); -int x{3}; // Prevents narrowing - -std::vector v(100, 1); // 100 ones -std::vector v{100, 1}; // Two elements: 100, 1 -``` - -## Preprocessor Directives - -Always at beginning of line: - -```cpp - if (lopsided_score) { -#if DISASTER_PENDING // Correct - at line start - DropEverything(); -#endif - BackToNormal(); - } -``` - -## Class Format - -```cpp -class MyClass : public OtherClass { - public: // 1 space indent - MyClass(); // 2 space indent - explicit MyClass(int var); - ~MyClass() {} - - void SomeFunction(); - void set_some_var(int var) { some_var_ = var; } - int some_var() const { return some_var_; } - - private: - bool SomeInternalFunction(); - - int some_var_; - int some_other_var_; -}; -``` - -## Constructor Initializer Lists - -```cpp -// All on one line -MyClass::MyClass(int var) : some_var_(var) { - -// Wrap before colon, 4-space indent -MyClass::MyClass(int var) - : some_var_(var), some_other_var_(var + 1) { - -// One per line when it spans multiple lines -MyClass::MyClass(int var) - : some_var_(var), - some_other_var_(var + 1) { -``` - -## Namespace Formatting - -No indentation inside namespaces: - -```cpp -namespace outer { -namespace inner { - -void foo() { // No extra indentation - // ... -} - -} // namespace inner -} // namespace outer -``` - -## Horizontal Whitespace - -```cpp -int i = 0; // Two spaces before end-of-line comments -void f(bool b) { // Space before { -int x[] = {0}; // Spaces inside braces optional, be consistent - -// Operators -x = 0; // Spaces around assignment -v = w * x + y/z; // OK to omit around factors - -// Loops and conditionals -if (condition) { // Space after keyword -while (test) {} // Usually no space inside () -for (int i = 0; i < 5; ++i) { -for (auto x : counts) { // Space around : in range-for -``` - -## Vertical Whitespace - -Use sparingly. Don't add blank lines: -- At start/end of code blocks -- Where indentation shows structure - -Use blank lines to separate logical sections (like paragraph breaks). diff --git a/.claude/skills/google-cpp-style/functions.md b/.claude/skills/google-cpp-style/functions.md deleted file mode 100644 index c7e751b..0000000 --- a/.claude/skills/google-cpp-style/functions.md +++ /dev/null @@ -1,140 +0,0 @@ -# Functions - -## Inputs and Outputs - -**Prefer return values over output parameters.** - -| Parameter Type | Use For | -|---------------|---------| -| Value or `const T&` | Non-optional inputs | -| `std::optional` | Optional by-value inputs | -| `const T*` | Optional inputs (when reference would be used) | -| Reference `T&` | Non-optional outputs/in-out | -| Pointer `T*` | Optional outputs/in-out | - -```cpp -// Good - return value -std::string ProcessData(const Input& input); - -// Good - reference for non-optional output -void ProcessData(const Input& input, Output& output); - -// Good - pointer for optional output -void ProcessData(const Input& input, Output* output); // output may be nullptr -``` - -**Parameter order**: inputs before outputs. - -Avoid functions requiring reference parameters to outlive the call (dangling reference risk). - -## Write Short Functions - -- Prefer functions ≤40 lines -- Break up long functions when it improves readability -- Small functions are easier to test and understand - -## Function Overloading - -Use overloading when behavior is obvious without knowing which overload is called: - -```cpp -// Good - obvious what happens -class MyClass { - public: - void Analyze(const std::string& text); - void Analyze(const char* text, size_t len); -}; - -// Consider string_view instead of multiple overloads -void Analyze(std::string_view text); -``` - -For overload sets, provide a single umbrella comment before the first declaration. - -## Default Arguments - -Allowed on non-virtual functions when: -- Default always has the same value -- Readability benefit outweighs downsides - -```cpp -// Good -void SetTimeout(int timeout_ms = 1000); - -// Bad - default on virtual function -class Base { - virtual void Process(int mode = 0); // Don't do this -}; - -// Bad - default varies -void Log(int level = GetDefaultLevel()); // Re-evaluated each call -``` - -When in doubt, use overloads instead of default arguments. - -## Trailing Return Type Syntax - -Use only when required or when it significantly improves readability: - -```cpp -// Required for lambdas with explicit return type -auto lambda = [](int x) -> double { return x * 1.5; }; - -// Helpful for complex template returns -template -auto Add(T t, U u) -> decltype(t + u); - -// Not needed for simple cases - prefer traditional style -int Foo(int x); // Good -auto Foo(int x) -> int; // Unnecessary -``` - -## Rvalue References - -Use only for: - -1. **Move constructors and assignment**: -```cpp -class MyClass { - public: - MyClass(MyClass&& other) = default; - MyClass& operator=(MyClass&& other) = default; -}; -``` - -2. **`&&`-qualified methods** that consume `*this`: -```cpp -class Builder { - public: - Result Build() &&; // Consumes the builder -}; -``` - -3. **Perfect forwarding**: -```cpp -template -void Forward(Args&&... args) { - target(std::forward(args)...); -} -``` - -4. **Performance-critical overload pairs** (when justified): -```cpp -void Process(const std::string& s); -void Process(std::string&& s); // Only if measurably faster -``` - -## Friends - -- Define friends in the same file when possible -- Use for factory classes, test classes, or tightly coupled helpers - -```cpp -class Foo { - public: - // ... - private: - friend class FooBuilder; // Can access Foo's private members - int internal_state_; -}; -``` diff --git a/.claude/skills/google-cpp-style/headers.md b/.claude/skills/google-cpp-style/headers.md deleted file mode 100644 index e78569d..0000000 --- a/.claude/skills/google-cpp-style/headers.md +++ /dev/null @@ -1,118 +0,0 @@ -# Header Files - -## Self-Contained Headers - -Headers must be self-contained (compile on their own) and end in `.h`. All headers should: -- Have header guards -- Include all headers they need -- Not rely on transitive inclusions - -## The #define Guard - -Format: `___H_` - -```cpp -// File: foo/src/bar/baz.h -#ifndef FOO_BAR_BAZ_H_ -#define FOO_BAR_BAZ_H_ - -// ... contents ... - -#endif // FOO_BAR_BAZ_H_ -``` - -## Include What You Use - -If a file refers to a symbol, it must directly include the header that provides it. Do not rely on transitive inclusions. - -```cpp -// foo.cc uses string and vector -#include // Required - don't rely on bar.h including it -#include // Required -#include "bar.h" -``` - -## Forward Declarations - -**Avoid forward declarations.** Include the headers you need instead. - -Forward declarations: -- Can hide dependencies -- May break with library changes -- Make tooling harder -- Can change code behavior subtly - -```cpp -// Bad - forward declaration -class B; -void FuncInB(); - -// Good - include the header -#include "b.h" -``` - -**Exception**: Forward declaring symbols from `namespace std` is undefined behavior. - -## Inline Functions - -Only define functions inline in headers when: -- The function is short (≤10 lines) -- Performance requires it - -Put longer definitions in `.cc` files or in an internal section of the header. - -```cpp -class Foo { - public: - int bar() { return bar_; } // OK - short accessor - - void MethodWithHugeBody(); // Declaration only - - private: - int bar_; -}; - -// Below public API or in .cc file -void Foo::MethodWithHugeBody() { - // Long implementation... -} -``` - -## Names and Order of Includes - -Order includes as follows, with blank lines between groups: - -1. Related header (`dir2/foo2.h` for `dir/foo.cc`) -2. C system headers (``, ``) -3. C++ standard library headers (``, ``) -4. Other libraries' headers -5. Your project's headers - -```cpp -#include "foo/server/fooserver.h" - -#include -#include - -#include -#include - -#include "base/basictypes.h" -#include "foo/server/bar.h" -#include "third_party/absl/flags/flag.h" -``` - -**Rules:** -- Use angle brackets only for system/standard headers -- Sort alphabetically within each group -- No UNIX directory aliases (`.` or `..`) - -**Conditional includes** (platform-specific) go after other includes: - -```cpp -#include "foo/public/fooserver.h" - -#ifdef _WIN32 -#include -#endif -``` diff --git a/.claude/skills/google-cpp-style/naming.md b/.claude/skills/google-cpp-style/naming.md deleted file mode 100644 index 7f3150d..0000000 --- a/.claude/skills/google-cpp-style/naming.md +++ /dev/null @@ -1,204 +0,0 @@ -# Naming Conventions - -## General Principles - -- Names should be descriptive and proportional to scope -- Minimize abbreviations (OK if in Wikipedia or universally known) -- Capitalize abbreviations as single words: `StartRpc()` not `StartRPC()` - -## Quick Reference - -| Entity | Style | Example | -|--------|-------|---------| -| Files | `snake_case` | `my_useful_class.cc` | -| Types (class, struct, enum, alias) | `PascalCase` | `MyExcitingClass` | -| Variables | `snake_case` | `table_name` | -| Class data members | `snake_case_` | `table_name_` | -| Struct data members | `snake_case` | `num_entries` | -| Constants | `kPascalCase` | `kDaysInAWeek` | -| Functions | `PascalCase` | `AddTableEntry()` | -| Accessors/mutators | `snake_case` | `count()`, `set_count()` | -| Namespaces | `snake_case` | `my_project` | -| Enumerators | `kPascalCase` | `kErrorOutOfMemory` | -| Macros | `UPPER_CASE` | `MY_MACRO_NAME` | - -## File Names - -- All lowercase with underscores or dashes -- C++ source: `.cc`, headers: `.h` -- Be specific: `http_server_logs.h` not `logs.h` - -``` -my_useful_class.cc -my_useful_class.h -my_useful_class_test.cc -``` - -## Type Names - -PascalCase for all types: - -```cpp -class UrlTable { ... }; -struct UrlTableProperties { ... }; -typedef hash_map<...> PropertiesMap; -using PropertiesMap = hash_map<...>; -enum class UrlTableError { ... }; -template class MyTemplate { ... }; -``` - -## Variable Names - -### Local and parameter variables - -```cpp -std::string table_name; // Good -std::string tableName; // Bad - mixed case -``` - -### Class data members - -Trailing underscore: - -```cpp -class TableInfo { - private: - std::string table_name_; - static Pool* pool_; -}; -``` - -### Struct data members - -No trailing underscore: - -```cpp -struct UrlTableProperties { - std::string name; - int num_entries; -}; -``` - -## Constant Names - -`k` prefix + PascalCase for static/global constants: - -```cpp -const int kDaysInAWeek = 7; -const int kAndroid8_0_0 = 24; // Underscores OK for versions -constexpr float kPi = 3.14159f; - -void Compute() { - // Local constants - either style OK - const int kLocalMax = 100; - const int local_max = 100; -} -``` - -## Function Names - -PascalCase: - -```cpp -AddTableEntry(); -DeleteUrl(); -OpenFileOrDie(); -``` - -Accessors and mutators use `snake_case`: - -```cpp -int count() const { return count_; } -void set_count(int count) { count_ = count; } -``` - -## Namespace Names - -All lowercase with underscores: - -```cpp -namespace my_project { -namespace internal { -// ... -} // namespace internal -} // namespace my_project - -// Single-line nested OK -namespace my_project::internal { -// ... -} -``` - -## Enumerator Names - -`k` prefix + PascalCase: - -```cpp -enum class UrlTableError { - kOk = 0, - kOutOfMemory, - kMalformedInput, -}; - -// Old MACRO_STYLE is deprecated -enum class AlternateError { - OK = 0, // Deprecated style - OUT_OF_MEMORY, // Deprecated style -}; -``` - -## Template Parameter Names - -Follow type or variable rules: - -```cpp -template // Type parameter -template -template // Non-type uses variable rules -template -``` - -## Macro Names - -All caps with underscores, project-specific prefix: - -```cpp -#define MYPROJECT_ROUND(x) ... -#define MY_MACRO_THAT_DOES_SOMETHING ... -``` - -## Choosing Good Names - -```cpp -// Good - clear in context -class MyClass { - public: - int CountFooErrors(const std::vector& foos) { - int n = 0; // Clear given limited scope - for (const auto& foo : foos) { - // ... - ++n; - } - return n; - } - - private: - const int kMaxAllowedConnections = ...; // Clear in class context -}; - -// Bad - overly verbose or unclear -int total_number_of_foo_errors = 0; // Too verbose for local scope -int cstmr_id = ...; // Don't delete letters -const int kNum = ...; // Too vague for wide scope -``` - -## Exceptions to Naming Rules - -When mimicking existing C/C++ entities: - -```cpp -bigopen() // Matches open() -uint // typedef, matches C style -sparse_hash_map // STL-like, follows STL conventions -LONGLONG_MAX // Matches INT_MAX -``` diff --git a/.claude/skills/google-cpp-style/scoping.md b/.claude/skills/google-cpp-style/scoping.md deleted file mode 100644 index a1249c0..0000000 --- a/.claude/skills/google-cpp-style/scoping.md +++ /dev/null @@ -1,175 +0,0 @@ -# Scoping - -## Namespaces - -Place code in a namespace with a unique name based on project name/path. - -```cpp -// In .h file -namespace mynamespace { - -class MyClass { - public: - void Foo(); -}; - -} // namespace mynamespace - -// In .cc file -namespace mynamespace { - -void MyClass::Foo() { - // ... -} - -} // namespace mynamespace -``` - -**Rules:** -- Do not indent namespace contents -- Terminate with `// namespace name` comment -- Single-line nested namespaces allowed: `namespace my_project::my_component {` -- Do not use `using namespace foo;` (pollutes namespace) -- Do not use inline namespaces -- Do not declare anything in `namespace std` - -**Namespace aliases** - allowed in `.cc` files and internal namespaces, not in public headers: - -```cpp -// In .cc file - OK -namespace sidetable = ::pipeline_diagnostics::sidetable; - -// In .h file - only in internal namespaces -namespace internal { -namespace sidetable = ::pipeline_diagnostics::sidetable; -} -``` - -## Internal Linkage - -Give definitions in `.cc` files internal linkage when not referenced elsewhere: - -```cpp -// In .cc file -namespace { - -void HelperFunction() { - // Only used in this file -} - -} // namespace - -// Or use static -static void AnotherHelper() { - // Only used in this file -} -``` - -Do not use unnamed namespaces or `static` in `.h` files. - -## Nonmember, Static Member, and Global Functions - -- Prefer nonmember functions in a namespace over global functions -- Do not create classes just to group static members -- Use internal linkage for `.cc`-only functions - -```cpp -// Good - nonmember in namespace -namespace myproject { -void UtilityFunction(); -} - -// Bad - class just for static grouping -class MyUtilities { - public: - static void Function1(); - static void Function2(); -}; -``` - -## Local Variables - -- Declare in the narrowest scope possible -- Initialize at declaration -- Declare loop variables in the loop statement - -```cpp -// Good -int jobs = NumJobs(); -f(jobs); - -std::vector v = {1, 2}; - -while (const char* p = strchr(str, '/')) { - str = p + 1; -} - -// Bad -int i; -i = f(); // Separate declaration and initialization - -std::vector v; -v.push_back(1); -v.push_back(2); -``` - -**Exception**: Move expensive object construction outside loops when performance matters: - -```cpp -Foo f; // Construct once -for (int i = 0; i < 1000000; ++i) { - f.DoSomething(i); -} -``` - -## Static and Global Variables - -Objects with static storage duration must be **trivially destructible**. - -```cpp -// Allowed - trivially destructible -const int kNum = 10; -struct X { int n; }; -const X kX[] = {{1}, {2}, {3}}; -constexpr std::array kArray = {1, 2, 3}; - -void foo() { - static const char* const kMessages[] = {"hello", "world"}; // OK -} - -// Bad - non-trivial destructor -const std::string kFoo = "foo"; // Bad -static std::map kData = {{1, 0}}; // Bad -``` - -**Constant initialization** - use `constexpr` or `constinit`: - -```cpp -struct Foo { constexpr Foo(int) {} }; - -constexpr int n = 5; // OK -constexpr Foo x(2); // OK -constinit int p = getpid(); // OK if no ordering dependencies -``` - -**Common patterns for static data:** -- Use `constexpr` `string_view` or char arrays for strings -- Use arrays of trivial types instead of `std::map`/`std::set` -- Use function-local static pointer: `static const auto& impl = *new T(args...);` - -## thread_local Variables - -Must be initialized with a true compile-time constant at namespace/class scope: - -```cpp -// OK - compile-time constant -constinit thread_local Foo foo = ...; - -// OK - function scope (no constinit needed) -Foo& MyThreadLocalFoo() { - thread_local Foo result = ComplicatedInitialization(); - return result; -} -``` - -Prefer `thread_local` over other thread-local mechanisms. Prefer trivial types to avoid destruction-order issues. diff --git a/.github/actions/setup-vcpkg/action.yml b/.github/actions/setup-vcpkg/action.yml index d04afee..f640bef 100644 --- a/.github/actions/setup-vcpkg/action.yml +++ b/.github/actions/setup-vcpkg/action.yml @@ -20,7 +20,10 @@ runs: VCPKG_COMMIT: 56bb2411609227288b70117ead2c47585ba07713 run: | if [ ! -d "$HOME/vcpkg" ]; then - # Full clone required — Arrow depends on Boost, which needs vcpkg git history + # Full clone: vcpkg-configuration.json pins a builtin-registry + # baseline, which vcpkg resolves through the repo's git history — + # a shallow clone breaks the versions database. (The manifest is + # now just openssl/lz4/zstd; Arrow/Boost are long gone.) git clone https://github.com/microsoft/vcpkg.git "$HOME/vcpkg" git -C "$HOME/vcpkg" checkout "$VCPKG_COMMIT" "$HOME/vcpkg/bootstrap-vcpkg.sh" -disableMetrics diff --git a/.github/workflows/ci-tap.yml b/.github/workflows/ci-tap.yml index e6e96ae..bcb2ed8 100644 --- a/.github/workflows/ci-tap.yml +++ b/.github/workflows/ci-tap.yml @@ -79,8 +79,7 @@ jobs: -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_TARGET_TRIPLET=x64-linux-pic \ -DVCPKG_OVERLAY_TRIPLETS=${{ github.workspace }}/triplets \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + -DCMAKE_C_COMPILER_LAUNCHER=ccache cmake --build build --parallel cmake --install build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4468d2c..cc66ec5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: postgresql-server-dev-${{ matrix.pg_version }} - name: Install build dependencies - run: sudo apt-get install -y cmake ninja-build g++ libssl-dev pkg-config curl zip unzip tar + run: sudo apt-get install -y cmake ninja-build gcc libssl-dev pkg-config curl zip unzip tar - uses: ./.github/actions/setup-vcpkg with: @@ -69,8 +69,7 @@ jobs: cmake --preset default \ -DPG_CONFIG=/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config \ -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + -DCMAKE_C_COMPILER_LAUNCHER=ccache - name: Build run: cmake --build build --parallel @@ -120,13 +119,12 @@ jobs: - name: Check formatting run: | sudo apt-get update && sudo apt-get install -y clang-format - find src include -name '*.cc' -o -name '*.h' | xargs clang-format --dry-run --Werror + find src include -name '*.c' -o -name '*.h' | xargs clang-format --dry-run --Werror - # Clang build: exercises -Werror=global-constructors on the C++ exporter - # (Clang-only flag). GCC has no equivalent, so we run a separate Clang job - # to ensure the warning catches regressions before they merge. One PG - # version / one arch is enough — this job exists to surface compile errors, - # not to duplicate test coverage. + # Clang build: second-compiler coverage. GCC and Clang warn about + # different things under -Werror, so building with both keeps the tree + # clean for either toolchain. One PG version / one arch is enough — this + # job exists to surface compile errors, not to duplicate test coverage. build-clang: name: Build (Clang, PG 18) runs-on: depot-ubuntu-22.04-16 @@ -161,8 +159,7 @@ jobs: cmake --preset default \ -DPG_CONFIG=/usr/lib/postgresql/18/bin/pg_config \ -DVCPKG_TARGET_TRIPLET=x64-linux-pic \ - -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ + -DCMAKE_C_COMPILER=clang - name: Build run: cmake --build build --parallel diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 819d41c..5381e0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,7 +45,7 @@ jobs: sudo apt-get install -y \ postgresql-${{ matrix.pg }} \ postgresql-server-dev-${{ matrix.pg }} \ - cmake ninja-build g++ \ + cmake ninja-build gcc \ binutils libssl-dev \ pkg-config curl zip unzip tar diff --git a/CLAUDE.md b/CLAUDE.md index 2cc2d16..c3c7c04 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,16 +4,24 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project Overview -pg_stat_ch is a PostgreSQL 16+ extension written in C++ that captures query execution telemetry via server hooks and exports it to ClickHouse. The architecture is: -`hooks (foreground) → shared-memory queue → bgworker exporter → ClickHouse events_raw` +pg_stat_ch is a PostgreSQL 16+ extension written in C that captures query execution telemetry via server hooks and exports it to ClickHouse (native protocol) or to any OTLP/HTTP collector. The architecture is: +`hooks (foreground) → shared-memory queue → bgworker exporter → ClickHouse events_raw / OTLP collector` All aggregation (p50/p95/p99, top queries, errors) happens in ClickHouse via materialized views, not in the extension. +The export path is a from-scratch C rewrite of an earlier C++ implementation, motivated by a production SIGABRT under memory pressure. **`OTEL_REWRITE_DESIGN.md` is the authoritative reference** for the exporter architecture, the preallocated memory model, the OTLP/Arrow wire contracts, and the failure semantics — read it before touching `src/export/` or `src/config/`. + ## Dependencies -Most third-party dependencies (OpenTelemetry, Arrow, OpenSSL, lz4, zstd) are managed via **vcpkg** (manifest mode). The vcpkg submodule lives at `third_party/vcpkg`; the manifest is `vcpkg.json`. +Third-party C libraries (OpenSSL, lz4, zstd) are managed via **vcpkg** (manifest mode) so release artifacts stay statically linked and version-pinned. The vcpkg submodule lives at `third_party/vcpkg`; the manifest is `vcpkg.json`. + +The ClickHouse client is **clickhouse-c** (`https://github.com/ClickHouse/clickhouse-c`), a header-only C library vendored as the `third_party/clickhouse-c` submodule. Its sole `CHC_IMPLEMENTATION` unit is `src/export/clickhouse_c_impl.c`; the exporter includes the headers for declarations only. -The ClickHouse client is **clickhouse-c** (`https://github.com/ClickHouse/clickhouse-c`), a header-only C library vendored as the `third_party/clickhouse-c` submodule. Its sole `CHC_IMPLEMENTATION` unit is `src/export/clickhouse_c_impl.c`; the C++ exporter includes the headers for declarations only. +Arrow IPC support uses **nanoarrow**, vendored as a checked-in amalgamation (NOT a submodule) under `third_party/nanoarrow/`, with the upstream tag/commit pinned in `third_party/nanoarrow/VERSION`. Never patch the amalgamation files; write-side ZSTD buffer compression and dictionary-batch emission live in `src/export/` on top of it. To upgrade, regenerate from an `apache/arrow-nanoarrow` checkout at the new tag and update `VERSION`: + +```bash +python3 ci/scripts/bundle.py --output-dir --with-ipc --with-flatcc --symbol-namespace PgStatCh +``` **First-time setup:** ```bash @@ -74,23 +82,27 @@ mise run test:isolation # Isolation tests (race conditions) ## Code Style -- C++17 with Google style guide (`.clang-format`) +- C (gnu17; `C_STANDARD 17` + `C_EXTENSIONS ON` are pinned in CMake) with Google-derived formatting (`.clang-format` — `Language: Cpp` stays because clang-format has no separate C mode) - Column limit: 100, 2-space indent -- `postgres.h` must be included first in any source file -- Use `extern "C"` blocks for PostgreSQL C ABI compatibility -- Naming: CamelCase for classes/functions, lower_case for variables, kCamelCase for constants -- No STL in shared memory; use Postgres allocators and shmem APIs +- `postgres.h` must be included first in any `.c` file; project headers assume it was already included +- Naming: CamelCase for functions (`PschFooBar`), lower_case for variables, kCamelCase for file-local constants, UPPER_CASE for macros; `static` for internal linkage +- Error handling: error-code returns with goto-style cleanup; every early-exit path releases what it acquired (no RAII exists to save you) +- **No longjmp on export/commit paths:** never call `ereport(ERROR)`/`elog(ERROR)` (or any PG function that can throw) from export or ring-commit code — WARNING/LOG/DEBUG1 only. `ereport(FATAL)` is allowed only in bgworker init paths, where a clean worker restart is the correct outcome. Assume a longjmp may still arrive from elsewhere: reset state on entry and never hold non-reclaimable resources across PG calls. +- **Zero heap allocation on steady-state export paths:** all buffers are preallocated at create/init; allocation failure at init returns an error (never aborts) +- No heap-allocating helpers in shared memory; use Postgres allocators and shmem APIs ## Architecture **Source files:** -- `src/pg_stat_ch.cc` - Main entry point with `_PG_init()` and SQL functions +- `src/pg_stat_ch.c` - Main entry point with `_PG_init()` and SQL functions +- `src/export/` - Exporter driver (`stats_exporter.c`), backends (`clickhouse_exporter.c`, `otel_exporter.c`), OTLP protobuf encoder (`otlp_encode.c`), Arrow IPC builder (`arrow_batch.c`); interface contract in `src/export/exporter.h` +- `src/config/` - GUC definitions and the `memory_limit` budget resolution (`memory_budget.h`) - `include/pg_stat_ch/pg_stat_ch.h` - Public header with version macro and declarations - `sql/pg_stat_ch--0.1.sql` - SQL function definitions **Build system:** -- CMake with presets (default=debug, release, release-arm64) -- vcpkg manifest mode (`vcpkg.json`) with custom triplets in `triplets/` +- CMake with presets (default=debug, release, release-arm64); `project(LANGUAGES C)` — any `.cc/.cxx/.cpp` under `src/` is a configure-time FATAL_ERROR +- vcpkg manifest mode (`vcpkg.json`, 3 deps: openssl/lz4/zstd) with custom triplets in `triplets/` - `cmake/FindPostgreSQLServer.cmake` - Finds PostgreSQL via pg_config - `cmake/CompilerWarnings.cmake` - Strict warning flags - `cmake/GitVersion.cmake` - Version extraction from git @@ -129,10 +141,5 @@ These projects are available in the workspace as references: - **`../pg_stat_monitor`** - Primary reference for PostgreSQL hook patterns, shared memory management, and query statistics collection. Our hook implementations are based on patterns from this project. - **`~/s/pg_clickhouse`** - Sibling PG extension that embeds clickhouse-c; reference for the connection setup, `CHC_IMPLEMENTATION` TU, and INSERT packet loop (`src/binary/connection.c`, `insert.c`) -- **`../pg_duckdb`** - Another PG extension in C++; reference for C++/PostgreSQL integration patterns +- **`../pg_duckdb`** - Another PostgreSQL extension (C++); occasionally useful for comparing hook usage and build patterns - **`../postgres`** - PostgreSQL source code for understanding internal APIs - -## Useful Skills - -- `/cpp-review` - Review C++ code against Google Style Guide -- `/cpp-naming-check` - Check naming conventions diff --git a/CMakeLists.txt b/CMakeLists.txt index e3fabfd..e74fa88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(pg_stat_ch VERSION 0.1.0 LANGUAGES CXX C) +project(pg_stat_ch VERSION 0.1.0 LANGUAGES C) if(WIN32) message(FATAL_ERROR "Windows is not supported") @@ -20,105 +20,97 @@ message(STATUS "PostgreSQL ${PostgreSQLServer_VERSION} found") # Compiler warnings include(CompilerWarnings) -# OpenSSL (required for clickhouse-c TLS transport) +# OpenSSL (required for clickhouse-c TLS transport and the OTLP https path) find_package(OpenSSL REQUIRED) message(STATUS "OpenSSL ${OPENSSL_VERSION} found") # --------------------------------------------------------------------------- # Third-party dependencies (via vcpkg) # --------------------------------------------------------------------------- -find_package(opentelemetry-cpp CONFIG REQUIRED) -find_package(Arrow CONFIG REQUIRED) # clickhouse-c (vendored under third_party/) is header-only; its compression -# codecs link against lz4 + zstd. +# codecs link against lz4 + zstd. zstd is also used directly for Arrow IPC +# per-buffer body compression in the export path. find_package(lz4 CONFIG REQUIRED) find_package(zstd CONFIG REQUIRED) -# Source layout: src/*.c is the C plugin layer; src/export/*.cc is the C++ -# exporter. Keeping the PG ↔ extension boundary in pure C is what prevents -# an uncaught C++ throw from unwinding across PG's longjmp frames. Reject -# anything that fell outside the two legitimate globs — C++ in the wrong -# location, or any C++ extension we don't compile (.cxx/.cpp/.c++) that -# would otherwise be silently dropped from the build. -file(GLOB_RECURSE PG_STAT_CH_PLUGIN_SOURCES CONFIGURE_DEPENDS src/*.c) -file(GLOB_RECURSE PG_STAT_CH_EXPORTER_SOURCES CONFIGURE_DEPENDS src/export/*.cc) - +# The extension is pure C. PostgreSQL's error handling is longjmp-based, and +# the production SIGABRT this rewrite removed came from C++ dependencies that +# abort() under memory pressure (see OTEL_REWRITE_DESIGN.md). Reject any C++ +# source — with LANGUAGES C it could not be compiled anyway, but the explicit +# check turns "silently dropped from the build" into a configure-time error. +# # CONFIGURE_DEPENDS: re-run the glob on every build, not just at first -# configure. Without it, a newly-added src/foo.cc would silently slip past -# the stray check until someone manually reconfigured. +# configure. Without it, a newly-added source would slip past the build (and +# the stray check) until someone manually reconfigured. +file(GLOB_RECURSE PG_STAT_CH_SOURCES CONFIGURE_DEPENDS src/*.c) file(GLOB_RECURSE PG_STAT_CH_OFFENDING_SOURCES CONFIGURE_DEPENDS src/*.cc src/*.cxx src/*.cpp src/*.c++ ) -list(FILTER PG_STAT_CH_OFFENDING_SOURCES - EXCLUDE REGEX "^${CMAKE_SOURCE_DIR}/src/export/.*\\.cc$") if(PG_STAT_CH_OFFENDING_SOURCES) message(FATAL_ERROR - "pg_stat_ch: C++ sources are allowed only as *.cc under src/export/. " - "Port to C, move under src/export/, or rename to .cc. Offending:\n" + "pg_stat_ch is pure C (project LANGUAGES C): C++ sources are not " + "compiled. Port to C. Offending:\n" " ${PG_STAT_CH_OFFENDING_SOURCES}") endif() -# Defense in depth on top of the C-only plugin lock above: when building the -# exporter with Clang, forbid namespace-scope C++ variables that need a -# non-trivial constructor or destructor. -Wglobal-constructors catches both -# halves at namespace scope: the load-time "std::thread above main" / "static -# std::map<...> g_cache" hazard, and the exit-time "destructor runs after PG -# has already torn down" hazard. -# -# Clang-only: GCC has no equivalent flag (the warning has been requested -# upstream for years but never landed). GCC builds rely on code review + -# clang-tidy. Our CI runs an additional Clang build job so regressions are -# caught before they merge. -# -# -Wexit-time-destructors (the sibling warning) is intentionally NOT enabled -# here. At namespace scope, -Wglobal-constructors already covers what we -# care about. -Wexit-time-destructors additionally fires on function-local -# statics — the two cached Arrow DataType shared_ptrs in arrow_batch.cc -# would trip it today. Not enabling it avoids those annotations for now; -# easy to layer on later if a regression motivates it. -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set_source_files_properties(${PG_STAT_CH_EXPORTER_SOURCES} - PROPERTIES COMPILE_OPTIONS - "-Wglobal-constructors;-Werror=global-constructors") -endif() +# nanoarrow (vendored amalgamation, see third_party/nanoarrow/VERSION): array +# building + IPC flatbuffer machinery for the C exporter. Symbols are +# namespaced (PgStatCh prefix) by the upstream bundler. Compiled as ordinary +# TUs; warnings suppressed because it is third-party code (headers are SYSTEM). +# FLATCC_NO_ASSERT outside Debug: every failure path in nanoarrow/flatcc then +# returns an error code (ENOMEM etc.) — no abort()/assert() reachable from the +# export path, which is the property the exporter rewrite exists to guarantee. +set(PG_STAT_CH_NANOARROW_SOURCES + third_party/nanoarrow/src/nanoarrow.c + third_party/nanoarrow/src/nanoarrow_ipc.c + third_party/nanoarrow/src/flatcc.c +) +set_source_files_properties(${PG_STAT_CH_NANOARROW_SOURCES} PROPERTIES + COMPILE_OPTIONS "-w" + COMPILE_DEFINITIONS "$<$>:FLATCC_NO_ASSERT>" +) +# flatcc's emitter must allocate its pages from our fixed pool, not the system +# heap, so steady-state Arrow export stays allocation-free (see +# src/export/flatcc_emitter_alloc.h). Force-include the override header before +# flatcc_emitter.h's #ifndef FLATCC_EMITTER_ALLOC guard sees the defaults. +set_source_files_properties(third_party/nanoarrow/src/flatcc.c PROPERTIES + COMPILE_OPTIONS "-w;-include;${CMAKE_SOURCE_DIR}/src/export/flatcc_emitter_alloc.h" + COMPILE_DEFINITIONS "$<$>:FLATCC_NO_ASSERT>" +) # Build shared library add_library(pg_stat_ch MODULE - ${PG_STAT_CH_PLUGIN_SOURCES} - ${PG_STAT_CH_EXPORTER_SOURCES} + ${PG_STAT_CH_SOURCES} + ${PG_STAT_CH_NANOARROW_SOURCES} ) -target_compile_features(pg_stat_ch PRIVATE cxx_std_17) target_compile_definitions(pg_stat_ch PRIVATE PG_STAT_CH_VERSION="${GIT_VERSION}") -# Force-include libintl.h before any source file so its declarations are parsed -# before PostgreSQL's postgres.h defines gettext/ngettext as macros. The include -# guard then prevents re-inclusion when C++ pulls it in later (via Arrow). -target_compile_options(pg_stat_ch PRIVATE -include libintl.h) target_include_directories(pg_stat_ch PRIVATE include src ) -# clickhouse-c is vendored third-party code: include it as SYSTEM so its -# header-only bodies don't trip the strict warning flags / -Werror below. +# clickhouse-c and nanoarrow are vendored third-party code: include them as +# SYSTEM so their header-only bodies don't trip the strict warning flags / +# -Werror below. target_include_directories(pg_stat_ch SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/third_party/clickhouse-c + ${CMAKE_SOURCE_DIR}/third_party/nanoarrow/include ) target_link_libraries(pg_stat_ch PRIVATE PostgreSQLServer::PostgreSQLServer - opentelemetry-cpp::api - opentelemetry-cpp::sdk - opentelemetry-cpp::otlp_grpc_metrics_exporter - opentelemetry-cpp::otlp_grpc_log_record_exporter - opentelemetry-cpp::metrics - opentelemetry-cpp::logs - Arrow::arrow_static ) target_link_libraries(pg_stat_ch PRIVATE OpenSSL::SSL OpenSSL::Crypto lz4::lz4 zstd::libzstd) pg_stat_ch_set_warnings(pg_stat_ch) +# gnu17, not c17: PostgreSQL headers rely on GNU extensions, and C23 (some +# compilers' default) repurposes `bool` in a way that conflicts with older PG +# headers. Pinned here so builds outside mise (CI, Docker) don't depend on +# env CFLAGS. set_target_properties(pg_stat_ch PROPERTIES PREFIX "" SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" + C_STANDARD 17 + C_EXTENSIONS ON ) if(APPLE) # PGXS uses -bundle_loader on Darwin (Makefile.port) instead of @@ -138,4 +130,3 @@ install(TARGETS pg_stat_ch LIBRARY DESTINATION ${PostgreSQLServer_PKGLIB_DIR}) install(FILES pg_stat_ch.control DESTINATION ${PostgreSQLServer_SHARE_DIR}/extension) file(GLOB SQL_FILES sql/pg_stat_ch--*.sql) install(FILES ${SQL_FILES} DESTINATION ${PostgreSQLServer_SHARE_DIR}/extension) - diff --git a/README.md b/README.md index 8947a6d..08808bd 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ PostgreSQL 16, 17, and 18 are fully supported. See [docs/version-compatibility.m Prerequisites: -- CMake 3.16+, C++17 compiler (GCC 9+, Clang 10+) +- CMake 3.16+, C compiler with C17 support (GCC 9+, Clang 10+) - PostgreSQL 16+ development headers - [mise](https://mise.jdx.dev/) (recommended) or manual PostgreSQL installation diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index c31dac2..5c14bc9 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -1,5 +1,5 @@ # CompilerWarnings.cmake -# Common compiler warning flags for C++ targets +# Common compiler warning flags for the project's C targets # # Provides: # pg_stat_ch_set_warnings(target) - Apply warning flags to a target @@ -16,6 +16,14 @@ function(pg_stat_ch_set_warnings target) -Wunused-parameter -Wunreachable-code + # C interface hygiene (PostgreSQL practice): every external function has + # a prototype, no K&R declarations/definitions, no stack-sized-by-input + # variable-length arrays. + -Wmissing-prototypes + -Wstrict-prototypes + -Wold-style-definition + -Wvla + # Suppress noisy warnings -Wno-sign-compare @@ -23,9 +31,6 @@ function(pg_stat_ch_set_warnings target) -fPIC -fvisibility=hidden -fno-omit-frame-pointer # Enable frame pointers for perf profiling - # Note: We need exceptions and RTTI for the OpenTelemetry/Arrow exporters - # -fno-exceptions - # -fno-rtti ) # Optional: treat warnings as errors in CI diff --git a/docker/postgres-ext.Dockerfile b/docker/postgres-ext.Dockerfile index f961a1e..6d516f4 100644 --- a/docker/postgres-ext.Dockerfile +++ b/docker/postgres-ext.Dockerfile @@ -44,6 +44,8 @@ COPY pg_stat_ch.control ./ # Vendored header-only clickhouse-c client (git submodule, must be checked out # on the host before `docker build`). COPY third_party/clickhouse-c/ third_party/clickhouse-c/ +# Vendored nanoarrow amalgamation (ordinary tree content, not a submodule). +COPY third_party/nanoarrow/ third_party/nanoarrow/ RUN cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ diff --git a/mise.toml b/mise.toml index a602e41..698f699 100644 --- a/mise.toml +++ b/mise.toml @@ -1,6 +1,6 @@ [env] -# Force C17 standard to avoid C23 'bool' keyword conflict when building older PostgreSQL versions -CFLAGS = "-std=gnu17" +# The C standard (gnu17, dodging the C23 'bool' clash with PG headers) is +# pinned in CMakeLists.txt via C_STANDARD/C_EXTENSIONS — no CFLAGS needed. VCPKG_ROOT = "{{config_root}}/third_party/vcpkg" [tools] @@ -36,11 +36,11 @@ run = "cp build/compile_commands.json ." description = "Copy compile_commands.json to project root" [tasks.format] -run = "fd -e cc -e h . src include | xargs clang-format -i" +run = "fd -e c -e h . src include | xargs clang-format -i" description = "Format code with clang-format" [tasks.lint] -run = "fd -e cc . src | xargs clang-tidy" +run = "fd -e c . src | xargs clang-tidy" description = "Run clang-tidy linting" [tasks.installcheck] diff --git a/vcpkg.json b/vcpkg.json index d2720ee..3c9eb2e 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,17 +1,9 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "$comment": "vcpkg is deliberately kept for these three C libraries (decision in OTEL_REWRITE_DESIGN.md §7): release tarballs must stay statically linked and version-pinned, independent of distro OpenSSL/lz4/zstd ABI skew. Dropping vcpkg for system libs is a flagged follow-up decision.", "name": "pg-stat-ch", "version-string": "0.1.0", "dependencies": [ - { - "name": "opentelemetry-cpp", - "default-features": false, - "features": ["otlp-grpc"] - }, - { - "name": "arrow", - "default-features": false - }, "lz4", "openssl", "zstd" From 0722b2fcfa134a8b745620ca29630255e161eb53 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 10 Jun 2026 12:26:49 -0500 Subject: [PATCH 11/11] test: add OTLP encoder and Arrow IPC builder unit tests otlp_encode_test.c: 541 known-answer/overflow/parser checks, clean under ASan/UBSan. arrow_batch_test.sh: builds the IPC payload for synthetic events and validates schema + decoded values against pyarrow (the byte-compat oracle). --- test/unit/arrow_batch_harness.c | 330 ++++++++++++++++ test/unit/arrow_batch_test.sh | 97 +++++ test/unit/arrow_batch_validate.py | 322 +++++++++++++++ test/unit/otlp_encode_test.c | 637 ++++++++++++++++++++++++++++++ 4 files changed, 1386 insertions(+) create mode 100644 test/unit/arrow_batch_harness.c create mode 100755 test/unit/arrow_batch_test.sh create mode 100644 test/unit/arrow_batch_validate.py create mode 100644 test/unit/otlp_encode_test.c diff --git a/test/unit/arrow_batch_harness.c b/test/unit/arrow_batch_harness.c new file mode 100644 index 0000000..1aed573 --- /dev/null +++ b/test/unit/arrow_batch_harness.c @@ -0,0 +1,330 @@ +// Standalone harness for the Arrow IPC batch builder (no postgres server). +// +// Compiles src/export/arrow_batch.c + arrow_ipc_emit.c against the real +// PostgreSQL server headers and stubs the few elog symbols the export path +// references (errstart returning false suppresses message evaluation). +// Generates deterministic synthetic events — the SAME recipe is mirrored in +// arrow_batch_validate.py, which decodes the payloads with pyarrow and +// asserts schema and value equality. +#include "postgres.h" + +#include +#include +#include +#include + +#include "export/arrow_batch.h" +#include "queue/event.h" + +// --- PG snprintf replacements (port.h redirects to pg_*; back them with libc) --- +#undef snprintf +#undef vsnprintf +#undef fprintf +#undef vfprintf +#undef printf +#undef vprintf + +int pg_snprintf(char* str, size_t count, const char* fmt, ...) { + va_list args; + int n; + + va_start(args, fmt); + n = vsnprintf(str, count, fmt, args); + va_end(args); + return n; +} + +int pg_fprintf(FILE* stream, const char* fmt, ...) { + va_list args; + int n; + + va_start(args, fmt); + n = vfprintf(stream, fmt, args); + va_end(args); + return n; +} + +int pg_printf(const char* fmt, ...) { + va_list args; + int n; + + va_start(args, fmt); + n = vprintf(fmt, args); + va_end(args); + return n; +} + +// --- PG error-API stubs (errstart=false => message args never evaluated) --- +static int warn_count = 0; + +bool errstart(int elevel, const char* domain) { + (void)domain; + if (elevel == WARNING) + warn_count++; + return false; +} + +bool errstart_cold(int elevel, const char* domain) { + return errstart(elevel, domain); +} + +void errfinish(const char* filename, int lineno, const char* funcname) { + (void)filename; + (void)lineno; + (void)funcname; +} + +int errmsg(const char* fmt, ...) { + (void)fmt; + return 0; +} + +int errmsg_internal(const char* fmt, ...) { + (void)fmt; + return 0; +} + +int errcode(int sqlerrcode) { + (void)sqlerrcode; + return 0; +} + +// --- synthetic event recipe (mirrored in arrow_batch_validate.py) --- +static void FillEvent(PschEvent* ev, int i) { + memset(ev, 0, sizeof(*ev)); + ev->ts_start = 1000000 + (int64)i * 1000; + ev->queryid = i == 3 ? UINT64_MAX : (uint64)(i % 7) * UINT64CONST(1234567890123); + ev->pid = i == 5 ? 2147483647 : 100000 + i; + + if (i == 19) { + memset(ev->datname, 'x', sizeof(ev->datname)); + ev->datname_len = 70; // invalid (> 63): exercises the clamp + WARNING path + } else { + ev->datname_len = (uint8)snprintf(ev->datname, sizeof(ev->datname), "db_%d", i % 3); + } + ev->username_len = (uint8)snprintf(ev->username, sizeof(ev->username), "user_%d", i % 2); + + if (i == 7) { + memset(ev->application_name, 'a', 63); + ev->application_name_len = 63; + } else { + ev->application_name_len = + (uint8)snprintf(ev->application_name, sizeof(ev->application_name), "app"); + } + + if (i % 4 == 0) { + ev->client_addr_len = 0; + } else if (i == 9) { + memset(ev->client_addr, 'c', 45); + ev->client_addr_len = 45; + } else { + ev->client_addr_len = (uint8)snprintf(ev->client_addr, sizeof(ev->client_addr), "10.0.0.%d", i); + } + + if (i == 11) { + memset(ev->query, 'q', PSCH_MAX_QUERY_LEN); + ev->query_len = PSCH_MAX_QUERY_LEN; + } else { + ev->query_len = (uint16)snprintf(ev->query, sizeof(ev->query), "SELECT %d", i); + } + + if (i == 13) { + memset(ev->err_message, 'e', PSCH_MAX_ERR_MSG_LEN); + ev->err_message_len = PSCH_MAX_ERR_MSG_LEN; + } else if (i % 5 == 0) { + ev->err_message_len = 0; + } else { + ev->err_message_len = (uint16)snprintf(ev->err_message, sizeof(ev->err_message), "error %d", i); + } + + if (i % 6 != 0) + memcpy(ev->err_sqlstate, "42P01", 6); + ev->err_elevel = i % 3 == 0 ? 0 : 21; + ev->cmd_type = (PschCmdType)(i % 8); + + ev->duration_us = (uint64)i * 10 + 1; + ev->rows = (uint64)i * 100; + ev->wal_bytes = (uint64)i * 67; + + ev->shared_blks_hit = i == 17 ? -5 : (int64)i * 2; + ev->shared_blks_read = (int64)i * 3; + ev->shared_blks_written = (int64)i * 7; + ev->shared_blks_dirtied = (int64)i * 5; + ev->shared_blk_read_time_us = (int64)i * 31; + ev->shared_blk_write_time_us = (int64)i * 37; + ev->local_blks_hit = (int64)i * 11; + ev->local_blks_read = (int64)i * 13; + ev->local_blks_written = (int64)i * 19; + ev->local_blks_dirtied = (int64)i * 17; + ev->local_blk_read_time_us = (int64)i * 41; + ev->local_blk_write_time_us = (int64)i * 43; + ev->temp_blks_read = (int64)i * 23; + ev->temp_blks_written = (int64)i * 29; + ev->temp_blk_read_time_us = (int64)i * 47; + ev->temp_blk_write_time_us = (int64)i * 53; + ev->wal_records = (int64)i * 59; + ev->wal_fpi = (int64)i * 61; + ev->cpu_user_time_us = (int64)i * 71; + ev->cpu_sys_time_us = (int64)i * 73; + + ev->jit_functions = i == 17 ? -1 : i % 50; + ev->jit_generation_time_us = i * 3 + 1; + ev->jit_deform_time_us = i * 5 + 2; + ev->jit_inlining_time_us = i * 7 + 3; + ev->jit_optimization_time_us = i * 11 + 4; + ev->jit_emission_time_us = i * 13 + 5; + + ev->parallel_workers_planned = (int16)(i == 17 ? -2 : i % 10); + ev->parallel_workers_launched = (int16)((i + 1) % 10); +} + +#define ATTRS1 \ + "instance_ubid: inst-1 ;server_ubid:srv-9; server_role : primary; " \ + "read_replica_type:; region:us-east-1;cell:cell-7;host_id:host-abc;" \ + "pod_name:pod-xyz;region:OTHER; bogus; unknown_key:zzz" +#define ATTRS2 \ + "instance_ubid:inst-1;server_ubid:srv-9;server_role:primary;read_replica_type:;" \ + "region:eu-west-1;cell:cell-7;host_id:host-abc;pod_name:pod-xyz" + +#define CHECK(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ + exit(1); \ + } \ + } while (0) + +static void WritePayload(const char* dir, const char* name, const uint8* data, size_t len) { + char path[1024]; + FILE* f; + + snprintf(path, sizeof(path), "%s/%s", dir, name); + f = fopen(path, "wb"); + CHECK(f != NULL); + CHECK(fwrite(data, 1, len, f) == len); + fclose(f); +} + +int main(int argc, char** argv) { + char errbuf[256] = ""; + PschEvent* ev = malloc(sizeof(PschEvent)); + const uint8* data; + size_t len; + int rows; + + CHECK(argc == 2); + CHECK(ev != NULL); + + // --- main payload: 50 events covering the edge cases --- + { + PschArrowBuilderConfig cfg = { + .scratch_budget_bytes = 64 * 1024 * 1024, + .ipc_budget_bytes = 4 * 1024 * 1024, + .max_rows = 1024, + .extra_attributes = ATTRS1, + .service_version = "0.4.0-test", + }; + PschArrowBuilder* b = PschArrowBuilderCreate(&cfg, errbuf, sizeof(errbuf)); + + if (b == NULL) { + fprintf(stderr, "create failed: %s\n", errbuf); + return 1; + } + CHECK(PschArrowBuilderMemUsed(b) > 0); + CHECK(PschArrowBuilderNumRows(b) == 0); + CHECK(PschArrowBuilderEstimatedBytes(b) == 1024); + + for (int i = 0; i < 50; i++) { + size_t before = PschArrowBuilderEstimatedBytes(b); + + FillEvent(ev, i); + CHECK(PschArrowBuilderAppend(b, ev) == PSCH_ARROW_APPEND_OK); + CHECK(PschArrowBuilderEstimatedBytes(b) > before); + } + CHECK(PschArrowBuilderNumRows(b) == 50); + CHECK(warn_count >= 2); // negative clamp (i=17) + invalid datname_len (i=19) + + CHECK(PschArrowBuilderFinish(b, &data, &len, &rows)); + CHECK(rows == 50); + CHECK(len > 16); + CHECK(memcmp(data + len - 8, "\xff\xff\xff\xff\x00\x00\x00\x00", 8) == 0); + WritePayload(argv[1], "payload1.bin", data, len); + + // Finish is repeatable until the state changes. + { + size_t len2; + + CHECK(PschArrowBuilderFinish(b, &data, &len2, &rows)); + CHECK(len2 == len); + } + + // --- second payload after Reset + attribute reload: fresh dictionaries --- + PschArrowBuilderReset(b); + CHECK(PschArrowBuilderNumRows(b) == 0); + CHECK(!PschArrowBuilderFinish(b, &data, &len, &rows)); // nothing to serialize + CHECK(PschArrowBuilderSetAttributes(b, ATTRS2)); + for (int i = 100; i < 105; i++) { + FillEvent(ev, i); + CHECK(PschArrowBuilderAppend(b, ev) == PSCH_ARROW_APPEND_OK); + } + CHECK(PschArrowBuilderFinish(b, &data, &len, &rows)); + CHECK(rows == 5); + WritePayload(argv[1], "payload2.bin", data, len); + + PschArrowBuilderDestroy(b); + } + + // --- max_rows bound: FULL, then Finish+Reset+retry --- + { + PschArrowBuilderConfig cfg = {.max_rows = 4, .service_version = "t"}; + PschArrowBuilder* b = PschArrowBuilderCreate(&cfg, errbuf, sizeof(errbuf)); + + CHECK(b != NULL); + for (int i = 0; i < 4; i++) { + FillEvent(ev, i); + CHECK(PschArrowBuilderAppend(b, ev) == PSCH_ARROW_APPEND_OK); + } + FillEvent(ev, 4); + CHECK(PschArrowBuilderAppend(b, ev) == PSCH_ARROW_APPEND_FULL); + CHECK(PschArrowBuilderFinish(b, &data, &len, &rows)); + CHECK(rows == 4); + PschArrowBuilderReset(b); + CHECK(PschArrowBuilderAppend(b, ev) == PSCH_ARROW_APPEND_OK); + PschArrowBuilderDestroy(b); + } + + // --- ipc-budget bound: estimate-driven FULL before 50 rows --- + { + PschArrowBuilderConfig cfg = {.ipc_budget_bytes = 65536, .service_version = "t"}; + PschArrowBuilder* b = PschArrowBuilderCreate(&cfg, errbuf, sizeof(errbuf)); + int appended = 0; + + CHECK(b != NULL); + for (int i = 0; i < 50; i++) { + PschArrowAppendResult r; + + FillEvent(ev, 11); // max-size query every row + r = PschArrowBuilderAppend(b, ev); + if (r == PSCH_ARROW_APPEND_FULL) + break; + CHECK(r == PSCH_ARROW_APPEND_OK); + appended++; + } + CHECK(appended >= 2 && appended < 50); + CHECK(PschArrowBuilderFinish(b, &data, &len, &rows)); + CHECK(rows == appended); + PschArrowBuilderDestroy(b); + } + + // --- NULL safety --- + PschArrowBuilderDestroy(NULL); + CHECK(PschArrowBuilderNumRows(NULL) == 0); + CHECK(PschArrowBuilderEstimatedBytes(NULL) == 0); + CHECK(PschArrowBuilderMemUsed(NULL) == 0); + CHECK(PschArrowBuilderAppend(NULL, ev) == PSCH_ARROW_APPEND_ERR); + CHECK(!PschArrowBuilderSetAttributes(NULL, "")); + + free(ev); + printf("harness OK\n"); + return 0; +} diff --git a/test/unit/arrow_batch_test.sh b/test/unit/arrow_batch_test.sh new file mode 100755 index 0000000..be4f47a --- /dev/null +++ b/test/unit/arrow_batch_test.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Unit test for src/export/arrow_batch.c + arrow_ipc_emit.c. +# +# Builds a standalone harness (real PostgreSQL server headers, stubbed elog +# symbols — see arrow_batch_harness.c), generates synthetic-event payloads, +# and validates them with arrow_batch_validate.py: structural V5/ZSTD framing +# checks plus pyarrow schema- and value-equality (via `uv run`, like +# t/026_arrow_dump.pl; falls back to structural-only if pyarrow is +# unavailable). +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +UNIT_DIR="$ROOT/test/unit" + +# --- locate pg_config --- +PG_CONFIG="${PG_CONFIG:-}" +if [[ -z "$PG_CONFIG" ]]; then + for cand in pg_config "mise x -- pg_config"; do + if $cand --includedir-server >/dev/null 2>&1; then + PG_CONFIG="$cand" + break + fi + done +fi +if [[ -z "$PG_CONFIG" ]] && command -v brew >/dev/null 2>&1; then + for ver in 18 17 16; do + cand="$(brew --prefix "postgresql@$ver" 2>/dev/null || true)/bin/pg_config" + if [[ -x "$cand" ]]; then + PG_CONFIG="$cand" + break + fi + done +fi +if [[ -z "$PG_CONFIG" ]]; then + echo "SKIP: pg_config not found (set PG_CONFIG)" >&2 + exit 1 +fi +PG_INC="$($PG_CONFIG --includedir-server)" +echo "using pg_config: $PG_CONFIG (server includes: $PG_INC)" + +# --- locate zstd (vcpkg dep in real builds; brew/system for the harness) --- +ZSTD_CFLAGS="" +ZSTD_LDFLAGS="-lzstd" +if command -v brew >/dev/null 2>&1 && brew --prefix zstd >/dev/null 2>&1; then + ZSTD_PREFIX="$(brew --prefix zstd)" + ZSTD_CFLAGS="-I$ZSTD_PREFIX/include" + ZSTD_LDFLAGS="-L$ZSTD_PREFIX/lib -lzstd" +fi + +# PG built with --enable-nls needs libintl.h (gettext) for c.h. +NLS_CFLAGS="" +if command -v brew >/dev/null 2>&1 && brew --prefix gettext >/dev/null 2>&1; then + NLS_CFLAGS="-I$(brew --prefix gettext)/include" +fi + +CC="${CC:-cc}" +BUILD_DIR="$(mktemp -d "${TMPDIR:-/tmp}/psch_arrow_test.XXXXXX")" +trap 'rm -rf "$BUILD_DIR"' EXIT + +INCLUDES=( + -I "$ROOT/include" + -I "$ROOT/src" + -I "$ROOT/third_party/nanoarrow/include" + -I "$PG_INC" +) +CFLAGS=(-std=gnu17 -g -O1 -DNDEBUG -DFLATCC_NO_ASSERT $ZSTD_CFLAGS $NLS_CFLAGS) + +echo "compiling harness..." +$CC "${CFLAGS[@]}" -Wall -Wextra "${INCLUDES[@]}" -c "$ROOT/src/export/arrow_batch.c" \ + -o "$BUILD_DIR/arrow_batch.o" +$CC "${CFLAGS[@]}" -Wall -Wextra "${INCLUDES[@]}" -c "$ROOT/src/export/arrow_ipc_emit.c" \ + -o "$BUILD_DIR/arrow_ipc_emit.o" +$CC "${CFLAGS[@]}" "${INCLUDES[@]}" -c "$ROOT/third_party/nanoarrow/src/flatcc.c" \ + -o "$BUILD_DIR/flatcc.o" +$CC "${CFLAGS[@]}" -Wall -Wextra "${INCLUDES[@]}" -c "$UNIT_DIR/arrow_batch_harness.c" \ + -o "$BUILD_DIR/harness.o" +$CC "$BUILD_DIR/arrow_batch.o" "$BUILD_DIR/arrow_ipc_emit.o" "$BUILD_DIR/flatcc.o" \ + "$BUILD_DIR/harness.o" $ZSTD_LDFLAGS -o "$BUILD_DIR/harness" + +echo "running harness..." +"$BUILD_DIR/harness" "$BUILD_DIR" + +P1="$BUILD_DIR/payload1.bin" +P2="$BUILD_DIR/payload2.bin" +[[ -s "$P1" && -s "$P2" ]] || { echo "FAIL: payloads missing" >&2; exit 1; } + +echo "validating payloads..." +if command -v uv >/dev/null 2>&1; then + uv run --quiet "$UNIT_DIR/arrow_batch_validate.py" "$P1" "$P2" +elif python3 -c "import pyarrow" >/dev/null 2>&1; then + python3 "$UNIT_DIR/arrow_batch_validate.py" "$P1" "$P2" +else + echo "WARNING: uv/pyarrow unavailable; running structural-only validation" >&2 + python3 "$UNIT_DIR/arrow_batch_validate.py" --structural-only "$P1" "$P2" +fi + +echo "arrow_batch_test PASS" diff --git a/test/unit/arrow_batch_validate.py b/test/unit/arrow_batch_validate.py new file mode 100644 index 0000000..02dd624 --- /dev/null +++ b/test/unit/arrow_batch_validate.py @@ -0,0 +1,322 @@ +# /// script +# requires-python = ">=3.9" +# dependencies = ["pyarrow"] +# /// +"""Validates pg_stat_ch Arrow IPC payloads produced by arrow_batch_harness.c. + +Two layers: + 1. Structural: stdlib-only V5 framing + flatbuffer walk — message sequence + (schema, 13 dictionary batches with ids 0..12, record batch, EOS), + BodyCompression{ZSTD}, null_count=0, 8-byte alignment, ZSTD frame magic. + 2. Decoded (pyarrow): schema equality against the documented 56-field + schema and per-cell value equality against the synthetic event recipe + mirrored from arrow_batch_harness.c (FillEvent). + +Usage: validate.py [--structural-only] payload1.bin payload2.bin +""" +import struct +import sys + +# --------------------------------------------------------------------------- +# Expected data (mirror of FillEvent in arrow_batch_harness.c) +# --------------------------------------------------------------------------- + +CMD = ["UNKNOWN", "SELECT", "UPDATE", "INSERT", "DELETE", "MERGE", "UTILITY", "NOTHING"] + +U64_COLS = [ + "duration_us", "rows", "shared_blks_hit", "shared_blks_read", "shared_blks_written", + "shared_blks_dirtied", "shared_blk_read_time_us", "shared_blk_write_time_us", + "local_blks_hit", "local_blks_read", "local_blks_written", "local_blks_dirtied", + "local_blk_read_time_us", "local_blk_write_time_us", "temp_blks_read", "temp_blks_written", + "temp_blk_read_time_us", "temp_blk_write_time_us", "wal_records", "wal_bytes", "wal_fpi", + "cpu_user_time_us", "cpu_sys_time_us", "jit_functions", "jit_generation_time_us", + "jit_inlining_time_us", "jit_optimization_time_us", "jit_emission_time_us", + "jit_deform_time_us", +] + +NUM_DICT_COLS = 13 + + +def expected_row(i, region): + return { + "ts": (1000000 + i * 1000 + 946684800000000) * 1000, + "severity": "", + "body": "", + "trace_id": "", + "span_id": "", + "query_id": str(2**64 - 1 if i == 3 else (i % 7) * 1234567890123), + "db_name": "x" * 63 if i == 19 else f"db_{i % 3}", + "db_user": f"user_{i % 2}", + "db_operation": CMD[i % 8], + "app": "a" * 63 if i == 7 else "app", + "client_addr": "" if i % 4 == 0 else ("c" * 45 if i == 9 else f"10.0.0.{i}"), + "query_text": "q" * 2048 if i == 11 else f"SELECT {i}", + "pid": "2147483647" if i == 5 else str(100000 + i), + "err_message": "e" * 2048 if i == 13 else ("" if i % 5 == 0 else f"error {i}"), + "err_sqlstate": "" if i % 6 == 0 else "42P01", + "err_elevel": 0 if i % 3 == 0 else 21, + "duration_us": i * 10 + 1, + "rows": i * 100, + "shared_blks_hit": 0 if i == 17 else i * 2, + "shared_blks_read": i * 3, + "shared_blks_written": i * 7, + "shared_blks_dirtied": i * 5, + "shared_blk_read_time_us": i * 31, + "shared_blk_write_time_us": i * 37, + "local_blks_hit": i * 11, + "local_blks_read": i * 13, + "local_blks_written": i * 19, + "local_blks_dirtied": i * 17, + "local_blk_read_time_us": i * 41, + "local_blk_write_time_us": i * 43, + "temp_blks_read": i * 23, + "temp_blks_written": i * 29, + "temp_blk_read_time_us": i * 47, + "temp_blk_write_time_us": i * 53, + "wal_records": i * 59, + "wal_bytes": i * 67, + "wal_fpi": i * 61, + "cpu_user_time_us": i * 71, + "cpu_sys_time_us": i * 73, + "jit_functions": 0 if i == 17 else i % 50, + "jit_generation_time_us": i * 3 + 1, + "jit_inlining_time_us": i * 7 + 3, + "jit_optimization_time_us": i * 11 + 4, + "jit_emission_time_us": i * 13 + 5, + "jit_deform_time_us": i * 5 + 2, + "parallel_workers_planned": 0 if i == 17 else i % 10, + "parallel_workers_launched": (i + 1) % 10, + "instance_ubid": "inst-1", + "server_ubid": "srv-9", + "server_role": "primary", + "read_replica_type": "", + "region": region, + "cell": "cell-7", + "service_version": "0.4.0-test", + "host_id": "host-abc", + "pod_name": "pod-xyz", + } + + +# --------------------------------------------------------------------------- +# Minimal flatbuffer walker (little-endian) +# --------------------------------------------------------------------------- + + +def _i8(b, o): + return struct.unpack_from(" 0: + assert ln >= 9, f"{what}: compressed buffer too short" + unc = struct.unpack_from("= 0, f"{what}: -1 raw escape emitted" + assert body[off + 8 : off + 12] == b"\x28\xb5\x2f\xfd", f"{what}: no ZSTD magic" + end = max(end, off + ln) + assert m["bodyLength"] == (end + 7) & ~7, f"{what}: bodyLength mismatch" + + +def validate_structural(buf, num_rows): + msgs = parse_stream(buf) + assert len(msgs) == 1 + NUM_DICT_COLS + 1, f"expected 15 messages, got {len(msgs)}" + assert msgs[0]["header_type"] == 1 and msgs[0]["version"] == 4, "first message not V5 schema" + assert msgs[0]["bodyLength"] == 0, "schema message has a body" + for k in range(NUM_DICT_COLS): + m = msgs[1 + k] + assert m["header_type"] == 2, f"message {1 + k} not a dictionary batch" + assert m["dict_id"] == k, f"dictionary ids out of order: {m['dict_id']} != {k}" + assert m["is_delta"] == 0, "isDelta set" + ndict = m["batch"]["length"] + assert 1 <= ndict <= num_rows, "dictionary cardinality out of range" + check_batch_structural(m, ndict, 1, f"dict {k}") + assert len(m["batch"]["buffers"]) == 3, "dict batch buffer count" + rb = msgs[1 + NUM_DICT_COLS] + assert rb["header_type"] == 3, "missing record batch" + check_batch_structural(rb, num_rows, 56, "record batch") + assert len(rb["batch"]["buffers"]) == 122, "record batch buffer count" + + +# --------------------------------------------------------------------------- +# Decoded validation (pyarrow) +# --------------------------------------------------------------------------- + + +def expected_schema(pa): + d = pa.dictionary(pa.int32(), pa.utf8()) + f = [ + ("ts", pa.timestamp("ns", tz="UTC")), ("severity", d), ("body", pa.utf8()), + ("trace_id", pa.utf8()), ("span_id", pa.utf8()), ("query_id", d), ("db_name", d), + ("db_user", d), ("db_operation", d), ("app", d), ("client_addr", d), + ("query_text", pa.utf8()), ("pid", pa.utf8()), ("err_message", pa.utf8()), + ("err_sqlstate", d), ("err_elevel", pa.int32()), + ] + f += [(name, pa.uint64()) for name in U64_COLS] + f += [ + ("parallel_workers_planned", pa.uint32()), ("parallel_workers_launched", pa.uint32()), + ("instance_ubid", pa.utf8()), ("server_ubid", pa.utf8()), ("server_role", d), + ("read_replica_type", d), ("region", d), ("cell", d), ("service_version", d), + ("host_id", pa.utf8()), ("pod_name", pa.utf8()), + ] + return pa.schema([pa.field(n, t) for n, t in f]) + + +def validate_decoded(pa, buf, indices, region): + reader = pa.ipc.open_stream(buf) + schema = expected_schema(pa) + assert reader.schema.equals(schema), ( + f"schema mismatch:\n--- got ---\n{reader.schema}\n--- want ---\n{schema}" + ) + table = reader.read_all() + assert table.num_rows == len(indices), "row count" + + rows = [expected_row(i, region) for i in indices] + for name in schema.names: + want = [r[name] for r in rows] + col = table.column(name) + if name == "ts": + got = col.cast(pa.int64()).to_pylist() + else: + got = col.to_pylist() + assert got == want, f"column {name}: {got[:5]}... != {want[:5]}..." + # the 13 dictionary-encoded columns must arrive dictionary-encoded + for name in schema.names: + if pa.types.is_dictionary(schema.field(name).type): + chunk = table.column(name).chunk(0) + assert pa.types.is_dictionary(chunk.type), f"{name} not dictionary-encoded" + assert chunk.type.value_type.equals(pa.utf8()), f"{name} dict value type" + + +def main(): + args = sys.argv[1:] + structural_only = False + if args and args[0] == "--structural-only": + structural_only = True + args = args[1:] + assert len(args) == 2, "usage: validate.py [--structural-only] payload1 payload2" + + with open(args[0], "rb") as fh: + p1 = fh.read() + with open(args[1], "rb") as fh: + p2 = fh.read() + + validate_structural(p1, 50) + validate_structural(p2, 5) + print("structural checks OK") + + if structural_only: + print("SKIP decoded checks (pyarrow unavailable)") + return + + import pyarrow as pa + + validate_decoded(pa, p1, list(range(50)), "us-east-1") + validate_decoded(pa, p2, list(range(100, 105)), "eu-west-1") + print(f"decoded checks OK (pyarrow {pa.__version__})") + + +if __name__ == "__main__": + main() diff --git a/test/unit/otlp_encode_test.c b/test/unit/otlp_encode_test.c new file mode 100644 index 0000000..f95cd35 --- /dev/null +++ b/test/unit/otlp_encode_test.c @@ -0,0 +1,637 @@ +// Host unit test for src/export/otlp_encode.c — runs without a PostgreSQL +// build. +// +// THE TRICK: otlp_encode.c normally compiles inside the extension with +// postgres.h as its first include. Here we define PSCH_OTLP_ENCODE_HOST_TEST +// (which suppresses that include), provide the minimal PG type surface the +// encoder needs — fixed-width typedefs via , bool via , +// Assert via assert(3), USE_ASSERT_CHECKING so the debug depth guard is +// exercised — and then #include the header and the .c directly. +// +// Build & run: +// cc -std=gnu17 test/unit/otlp_encode_test.c -o /tmp/otlp_test && /tmp/otlp_test +// Optional: /tmp/otlp_test dumps a sample ExportLogsServiceRequest for +// external decoding (e.g. `protoc --decode_raw`). +#include +#include +#include +#include +#include +#include + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; +typedef size_t Size; + +#define USE_ASSERT_CHECKING 1 +#define Assert(condition) assert(condition) +#define PSCH_OTLP_ENCODE_HOST_TEST 1 + +#include "../../src/export/otlp_encode.h" + +// The implementation under test, in the same translation unit (see THE TRICK +// above). Kept in its own include block so tooling cannot resort it above +// the header. +#include "../../src/export/otlp_encode.c" + +static int failures = 0; +static int checks = 0; + +#define CHECK(cond) \ + do { \ + checks++; \ + if (!(cond)) { \ + printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ + failures++; \ + } \ + } while (0) + +static void HexDump(const char* label, const uint8* p, size_t n) { + printf(" %s (%zu):", label, n); + for (size_t i = 0; i < n; i++) + printf(" %02X", p[i]); + printf("\n"); +} + +static void CheckBytes(int line, const PschPbBuf* b, const uint8* want, size_t want_len) { + checks++; + if (b->overflow || b->len != want_len || memcmp(b->data, want, want_len) != 0) { + printf("FAIL %s:%d: byte vector mismatch (overflow=%d)\n", __FILE__, line, (int)b->overflow); + HexDump("got ", b->data, b->len); + HexDump("want", want, want_len); + failures++; + } +} + +// --------------------------------------------------------------------------- +// Known-answer vectors for the writer primitives (hand-computed per +// https://protobuf.dev/programming-guides/encoding/) +// --------------------------------------------------------------------------- + +typedef void (*EmitFn)(PschPbBuf* b); + +static void RunVector(int line, EmitFn emit, const uint8* want, size_t want_len) { + uint8 storage[256]; + PschPbBuf b; + + PschPbInit(&b, storage, sizeof(storage)); + emit(&b); + CheckBytes(line, &b, want, want_len); +} + +static void EmitVarint0(PschPbBuf* b) { + PschPbVarint(b, 1, 0); +} +static void EmitVarint1(PschPbBuf* b) { + PschPbVarint(b, 1, 1); +} +static void EmitVarint127(PschPbBuf* b) { + PschPbVarint(b, 1, 127); +} +static void EmitVarint128(PschPbBuf* b) { + PschPbVarint(b, 1, 128); +} +static void EmitVarint300(PschPbBuf* b) { + PschPbVarint(b, 1, 300); +} +static void EmitVarintMax(PschPbBuf* b) { + PschPbVarint(b, 1, UINT64_MAX); +} +static void EmitVarintField16(PschPbBuf* b) { + PschPbVarint(b, 16, 1); +} +static void EmitFixed64(PschPbBuf* b) { + PschPbFixed64(b, 1, 0x0102030405060708ULL); +} +static void EmitFixed32(PschPbBuf* b) { + PschPbFixed32(b, 8, 0xDEADBEEFu); +} +static void EmitDouble1(PschPbBuf* b) { + PschPbDouble(b, 4, 1.0); +} +static void EmitDoubleNeg(PschPbBuf* b) { + PschPbDouble(b, 4, -2.5); +} +static void EmitStringAbc(PschPbBuf* b) { + PschPbString(b, 2, "abc", 3); +} +static void EmitStringEmpty(PschPbBuf* b) { + PschPbString(b, 2, "", 0); +} +static void EmitBytesNul(PschPbBuf* b) { + PschPbBytes(b, 15, "\x00\xFF", 2); +} +static void EmitKvString(PschPbBuf* b) { + PschPbKvString(b, 6, "a", "b", 1); +} +static void EmitKvIntNeg(PschPbBuf* b) { + PschPbKvInt(b, 6, "n", -1); +} +static void EmitKvIntZero(PschPbBuf* b) { + PschPbKvInt(b, 1, "z", 0); +} +static void EmitKvDouble(PschPbBuf* b) { + PschPbKvDouble(b, 6, "d", 0.5); +} + +static void EmitNested(PschPbBuf* b) { + size_t outer = PschPbMsgBegin(b, 1); + size_t inner; + + PschPbVarint(b, 1, 150); + inner = PschPbMsgBegin(b, 2); + PschPbString(b, 1, "hi", 2); + PschPbMsgEnd(b, inner); + PschPbMsgEnd(b, outer); +} + +static void TestPrimitiveVectors(void) { + static const uint8 v0[] = {0x08, 0x00}; + static const uint8 v1[] = {0x08, 0x01}; + static const uint8 v127[] = {0x08, 0x7F}; + static const uint8 v128[] = {0x08, 0x80, 0x01}; + static const uint8 v300[] = {0x08, 0xAC, 0x02}; + static const uint8 vmax[] = {0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}; + static const uint8 vf16[] = {0x80, 0x01, 0x01}; // field 16: tag itself is a 2-byte varint + static const uint8 f64[] = {0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}; + static const uint8 f32[] = {0x45, 0xEF, 0xBE, 0xAD, 0xDE}; + static const uint8 d1[] = {0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F}; + static const uint8 dneg[] = {0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xC0}; + static const uint8 sabc[] = {0x12, 0x03, 0x61, 0x62, 0x63}; + static const uint8 sempty[] = {0x12, 0x00}; + static const uint8 bnul[] = {0x7A, 0x02, 0x00, 0xFF}; + // KeyValue{key="a" value{string_value="b"}}, overlong 4-byte length slots + static const uint8 kvs[] = {0x32, 0x8B, 0x80, 0x80, 0x00, 0x0A, 0x01, 0x61, + 0x12, 0x83, 0x80, 0x80, 0x00, 0x0A, 0x01, 0x62}; + // int_value -1 encodes as the 10-byte two's-complement varint + static const uint8 kvi[] = {0x32, 0x93, 0x80, 0x80, 0x00, 0x0A, 0x01, 0x6E, + 0x12, 0x8B, 0x80, 0x80, 0x00, 0x18, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}; + static const uint8 kvz[] = {0x0A, 0x8A, 0x80, 0x80, 0x00, 0x0A, 0x01, 0x7A, + 0x12, 0x82, 0x80, 0x80, 0x00, 0x18, 0x00}; + static const uint8 kvd[] = {0x32, 0x91, 0x80, 0x80, 0x00, 0x0A, 0x01, 0x64, 0x12, 0x89, 0x80, + 0x80, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x3F}; + // msg1{ varint1=150 msg2{ string1="hi" } } — verifies slot patching + static const uint8 nested[] = {0x0A, 0x8C, 0x80, 0x80, 0x00, 0x08, 0x96, 0x01, 0x12, + 0x84, 0x80, 0x80, 0x00, 0x0A, 0x02, 0x68, 0x69}; + + RunVector(__LINE__, EmitVarint0, v0, sizeof(v0)); + RunVector(__LINE__, EmitVarint1, v1, sizeof(v1)); + RunVector(__LINE__, EmitVarint127, v127, sizeof(v127)); + RunVector(__LINE__, EmitVarint128, v128, sizeof(v128)); + RunVector(__LINE__, EmitVarint300, v300, sizeof(v300)); + RunVector(__LINE__, EmitVarintMax, vmax, sizeof(vmax)); + RunVector(__LINE__, EmitVarintField16, vf16, sizeof(vf16)); + RunVector(__LINE__, EmitFixed64, f64, sizeof(f64)); + RunVector(__LINE__, EmitFixed32, f32, sizeof(f32)); + RunVector(__LINE__, EmitDouble1, d1, sizeof(d1)); + RunVector(__LINE__, EmitDoubleNeg, dneg, sizeof(dneg)); + RunVector(__LINE__, EmitStringAbc, sabc, sizeof(sabc)); + RunVector(__LINE__, EmitStringEmpty, sempty, sizeof(sempty)); + RunVector(__LINE__, EmitBytesNul, bnul, sizeof(bnul)); + RunVector(__LINE__, EmitKvString, kvs, sizeof(kvs)); + RunVector(__LINE__, EmitKvIntNeg, kvi, sizeof(kvi)); + RunVector(__LINE__, EmitKvIntZero, kvz, sizeof(kvz)); + RunVector(__LINE__, EmitKvDouble, kvd, sizeof(kvd)); + RunVector(__LINE__, EmitNested, nested, sizeof(nested)); +} + +// --------------------------------------------------------------------------- +// Overflow safety: full encode sequence against every undersized cap. +// No byte beyond cap (or beyond len) may ever be touched. +// --------------------------------------------------------------------------- + +static void EncodeAll(PschPbBuf* b) { + size_t m; + + PschPbVarint(b, 1, 300); + PschPbFixed64(b, 2, 0x1122334455667788ULL); + PschPbFixed32(b, 3, 0xCAFEBABEu); + PschPbDouble(b, 4, 3.14); + PschPbString(b, 5, "hello", 5); + PschPbBytes(b, 6, "\x00\x01", 2); + m = PschPbMsgBegin(b, 7); + PschPbKvString(b, 1, "k", "v", 1); + PschPbKvInt(b, 1, "i", -7); + PschPbKvDouble(b, 1, "d", 2.5); + PschPbMsgEnd(b, m); +} + +static void TestOverflowFuzz(void) { + uint8 golden[512]; + uint8 storage[512 + 64]; + PschPbBuf b; + size_t golden_len; + + PschPbInit(&b, golden, sizeof(golden)); + EncodeAll(&b); + CHECK(!b.overflow); + golden_len = b.len; + CHECK(golden_len > 0 && golden_len < sizeof(golden)); + + for (size_t cap = 0; cap < golden_len; cap++) { + memset(storage, 0xAA, sizeof(storage)); + PschPbInit(&b, cap == 0 ? NULL : storage, cap); + if (cap == 0) + b.data = storage; // keep a real pointer so sentinels are checkable + EncodeAll(&b); + CHECK(b.overflow); + CHECK(b.len <= cap); + // Bytes written so far must be a prefix of the full encoding (no + // partial/odd writes), except inside unpatched 4-byte slots. + bool prefix_ok = true; + for (size_t i = 0; i < b.len; i++) { + if (storage[i] != golden[i] && storage[i] != 0x00) + prefix_ok = false; + } + CHECK(prefix_ok); + bool untouched = true; + for (size_t i = b.len; i < sizeof(storage); i++) { + if (storage[i] != 0xAA) + untouched = false; + } + CHECK(untouched); + } + + // Exact-fit cap must reproduce the golden bytes with no overflow. + memset(storage, 0xAA, sizeof(storage)); + PschPbInit(&b, storage, golden_len); + EncodeAll(&b); + CHECK(!b.overflow); + CHECK(b.len == golden_len); + CHECK(memcmp(storage, golden, golden_len) == 0); + + // NULL/zero-cap buffer: overflow without dereferencing data. + PschPbInit(&b, NULL, 0); + EncodeAll(&b); + CHECK(b.overflow); + CHECK(b.len == 0); +} + +static void TestOverflowSemantics(void) { + uint8 st[8]; + PschPbBuf b; + size_t m; + size_t len_before; + + // MsgEnd on an overflowed buffer is a no-op: slot keeps its zero padding. + memset(st, 0xAA, sizeof(st)); + PschPbInit(&b, st, sizeof(st)); + m = PschPbMsgBegin(&b, 1); + CHECK(!b.overflow); + CHECK(m == 1); + CHECK(b.len == 5); + PschPbString(&b, 2, "hello", 5); // needs 7 bytes, 3 remain + CHECK(b.overflow); + len_before = b.len; + PschPbMsgEnd(&b, m); + CHECK(b.len == len_before); + CHECK(st[1] == 0 && st[2] == 0 && st[3] == 0 && st[4] == 0); + + // Every subsequent write is a no-op once overflow is set. + PschPbVarint(&b, 1, 7); + PschPbFixed64(&b, 1, 7); + PschPbFixed32(&b, 1, 7); + PschPbDouble(&b, 1, 7.0); + PschPbBytes(&b, 1, "x", 1); + CHECK(PschPbMsgBegin(&b, 1) == b.len); + CHECK(b.len == len_before); + + // 1-byte buffer: nothing fits, first byte untouched. + st[0] = 0xAA; + PschPbInit(&b, st, 1); + PschPbVarint(&b, 1, 0); + CHECK(b.overflow); + CHECK(b.len == 0); + CHECK(st[0] == 0xAA); +} + +static void TestMsgEndLengthCeiling(void) { + // A message body larger than the 4-byte slot can represent (2^28-1) must + // flag overflow instead of patching garbage. Simulated by lying about + // len/cap; MsgEnd's size check fires before any write. + uint8 st[16]; + PschPbBuf b; + size_t m; + + PschPbInit(&b, st, sizeof(st)); + m = PschPbMsgBegin(&b, 1); + b.cap = SIZE_MAX / 2; + b.len = m + 4 + 0x0FFFFFFF + 1; + PschPbMsgEnd(&b, m); + CHECK(b.overflow); + CHECK(st[m] == 0 && st[m + 1] == 0 && st[m + 2] == 0 && st[m + 3] == 0); +} + +// --------------------------------------------------------------------------- +// Independent structural decode of an encoded sample request. Deliberately +// re-implements varint/length reading here rather than reusing the .c's +// internals, so encoder bugs cannot self-validate. +// --------------------------------------------------------------------------- + +typedef struct TR { + const uint8* p; + const uint8* end; +} TR; + +static bool TrVarint(TR* t, uint64* v) { + *v = 0; + for (int i = 0; i < 10; i++) { + if (t->p >= t->end) + return false; + uint8 byte = *t->p++; + *v |= (uint64)(byte & 0x7F) << (7 * i); + if (!(byte & 0x80)) + return true; + } + return false; +} + +static bool TrTag(TR* t, uint64* field, uint32* wt) { + uint64 tag; + if (!TrVarint(t, &tag)) + return false; + *field = tag >> 3; + *wt = (uint32)(tag & 7); + return true; +} + +// Expects a length-delimited field with the given number; returns its slice. +static bool TrExpectLen(TR* t, uint64 want_field, TR* sub) { + uint64 field, n; + uint32 wt; + if (!TrTag(t, &field, &wt)) + return false; + if (field != want_field || wt != 2) + return false; + if (!TrVarint(t, &n)) + return false; + if (n > (uint64)(t->end - t->p)) + return false; + sub->p = t->p; + sub->end = t->p + n; + t->p += n; + return true; +} + +static bool TrExpectString(TR* t, uint64 want_field, const char* want) { + TR s; + if (!TrExpectLen(t, want_field, &s)) + return false; + size_t n = (size_t)(s.end - s.p); + return n == strlen(want) && memcmp(s.p, want, n) == 0; +} + +static bool TrExpectKvString(TR* t, uint64 want_field, const char* key, const char* val) { + TR kv, any; + if (!TrExpectLen(t, want_field, &kv)) + return false; + if (!TrExpectString(&kv, 1, key)) + return false; + if (!TrExpectLen(&kv, 2, &any)) + return false; + if (!TrExpectString(&any, 1, val)) + return false; + return any.p == any.end && kv.p == kv.end; +} + +static void BuildSampleRequest(PschPbBuf* b) { + size_t rl = PschPbMsgBegin(b, PSCH_OTLP_REQ_RESOURCE_LOGS); + size_t res = PschPbMsgBegin(b, PSCH_OTLP_RL_RESOURCE); + size_t sl, scope, lr; + + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "service.name", "pg_stat_ch", 10); + PschPbKvString(b, PSCH_OTLP_RES_ATTRIBUTES, "host.name", "testhost", 8); + PschPbMsgEnd(b, res); + sl = PschPbMsgBegin(b, PSCH_OTLP_RL_SCOPE_LOGS); + scope = PschPbMsgBegin(b, PSCH_OTLP_SL_SCOPE); + PschPbString(b, PSCH_OTLP_SCOPE_NAME, "pg_stat_ch", 10); + PschPbString(b, PSCH_OTLP_SCOPE_VERSION, "0.4.0", 5); + PschPbMsgEnd(b, scope); + lr = PschPbMsgBegin(b, PSCH_OTLP_SL_LOG_RECORDS); + PschPbFixed64(b, PSCH_OTLP_LR_TIME_UNIX_NANO, 1760000000000000000ULL); + PschPbVarint(b, PSCH_OTLP_LR_SEVERITY_NUMBER, 9); + PschPbKvString(b, PSCH_OTLP_LR_ATTRIBUTES, "db", "postgres", 8); + PschPbMsgEnd(b, lr); + PschPbMsgEnd(b, sl); + PschPbMsgEnd(b, rl); +} + +static void TestSampleRequestStructure(const char* dump_path) { + uint8 storage[1024]; + PschPbBuf b; + TR t, rl, res, sl, scope, lr; + uint64 field, v; + uint32 wt; + + PschPbInit(&b, storage, sizeof(storage)); + BuildSampleRequest(&b); + CHECK(!b.overflow); + + if (dump_path != NULL) { + FILE* f = fopen(dump_path, "wb"); + if (f != NULL) { + fwrite(b.data, 1, b.len, f); + fclose(f); + printf("sample request dumped to %s (%zu bytes)\n", dump_path, b.len); + } + } + + t.p = b.data; + t.end = b.data + b.len; + CHECK(TrExpectLen(&t, 1, &rl)); // ResourceLogs + CHECK(t.p == t.end); // request has exactly one top-level field + CHECK(TrExpectLen(&rl, 1, &res)); // Resource + CHECK(TrExpectKvString(&res, 1, "service.name", "pg_stat_ch")); + CHECK(TrExpectKvString(&res, 1, "host.name", "testhost")); + CHECK(res.p == res.end); + CHECK(TrExpectLen(&rl, 2, &sl)); // ScopeLogs + CHECK(rl.p == rl.end); + CHECK(TrExpectLen(&sl, 1, &scope)); // InstrumentationScope + CHECK(TrExpectString(&scope, 1, "pg_stat_ch")); + CHECK(TrExpectString(&scope, 2, "0.4.0")); + CHECK(scope.p == scope.end); + CHECK(TrExpectLen(&sl, 2, &lr)); // LogRecord + CHECK(sl.p == sl.end); + CHECK(TrTag(&lr, &field, &wt)); + CHECK(field == 1 && wt == 1); // time_unix_nano fixed64 + CHECK((size_t)(lr.end - lr.p) >= 8); + v = 0; + for (int i = 7; i >= 0; i--) + v = (v << 8) | lr.p[i]; + lr.p += 8; + CHECK(v == 1760000000000000000ULL); + CHECK(TrTag(&lr, &field, &wt)); + CHECK(field == 2 && wt == 0); + CHECK(TrVarint(&lr, &v)); + CHECK(v == 9); + CHECK(TrExpectKvString(&lr, 6, "db", "postgres")); + CHECK(lr.p == lr.end); +} + +// --------------------------------------------------------------------------- +// Response parsers +// --------------------------------------------------------------------------- + +static void TestLogsResponseParser(void) { + // partial_success{ rejected_log_records=5, error_message="boom" } + static const uint8 ok[] = {0x0A, 0x08, 0x08, 0x05, 0x12, 0x04, 0x62, 0x6F, 0x6F, 0x6D}; + // Same, with the nested length written as an overlong 4-byte varint (the + // form our own encoder emits) — parsers must accept non-canonical varints. + static const uint8 overlong[] = {0x0A, 0x88, 0x80, 0x80, 0x00, 0x08, 0x05, + 0x12, 0x04, 0x62, 0x6F, 0x6F, 0x6D}; + // Unknown fields of every wire type at top level, then partial_success + static const uint8 unknown_top[] = {0x10, 0x07, 0x19, 1, 2, 3, 4, 5, + 6, 7, 8, 0x25, 1, 2, 3, 4, + 0x22, 0x02, 0x61, 0x62, 0x0A, 0x02, 0x08, 0x09}; + // Unknown field inside partial_success + static const uint8 unknown_in[] = {0x0A, 0x0A, 0x08, 0x05, 0x18, 0x07, + 0x12, 0x04, 0x62, 0x6F, 0x6F, 0x6D}; + static const uint8 rejected_only[] = {0x0A, 0x02, 0x08, 0x07}; + int64 rejected; + char msg[64]; + + CHECK(PschOtlpParseLogsResponse(ok, sizeof(ok), &rejected, msg, sizeof(msg))); + CHECK(rejected == 5); + CHECK(strcmp(msg, "boom") == 0); + + CHECK(PschOtlpParseLogsResponse(NULL, 0, &rejected, msg, sizeof(msg))); + CHECK(rejected == 0); + CHECK(msg[0] == '\0'); + + CHECK(PschOtlpParseLogsResponse(overlong, sizeof(overlong), &rejected, msg, sizeof(msg))); + CHECK(rejected == 5); + CHECK(strcmp(msg, "boom") == 0); + + CHECK(PschOtlpParseLogsResponse(unknown_top, sizeof(unknown_top), &rejected, msg, sizeof(msg))); + CHECK(rejected == 9); + + CHECK(PschOtlpParseLogsResponse(unknown_in, sizeof(unknown_in), &rejected, msg, sizeof(msg))); + CHECK(rejected == 5); + CHECK(strcmp(msg, "boom") == 0); + + CHECK( + PschOtlpParseLogsResponse(rejected_only, sizeof(rejected_only), &rejected, msg, sizeof(msg))); + CHECK(rejected == 7); + CHECK(msg[0] == '\0'); + + // NULL outputs must be tolerated. + CHECK(PschOtlpParseLogsResponse(ok, sizeof(ok), NULL, NULL, 0)); + + // Truncation: ok[] has no field boundary between 1 and 9 bytes, so every + // proper prefix is malformed. + for (size_t n = 1; n < sizeof(ok); n++) { + CHECK(!PschOtlpParseLogsResponse(ok, n, &rejected, msg, sizeof(msg))); + } + + // msgbuf truncation: only msglen-1 chars + NUL are written. + CHECK(PschOtlpParseLogsResponse(ok, sizeof(ok), &rejected, msg, 3)); + CHECK(strcmp(msg, "bo") == 0); +} + +static void TestGarbageRejection(void) { + static const uint8 group_start[] = {0x0B}; // field 1, wire type 3 + static const uint8 group_end[] = {0x0C}; // field 1, wire type 4 + static const uint8 wt6[] = {0x0E}; // wire type 6 + static const uint8 wt7[] = {0x0F}; // wire type 7 + static const uint8 field0[] = {0x00}; // field number 0 + static const uint8 trunc_varint[] = {0x08}; // tag then nothing + static const uint8 varint_11b[] = {0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}; + static const uint8 len_overrun[] = {0x12, 0x05, 0x01}; // says 5, has 1 + static const uint8 fixed64_short[] = {0x19, 0x01, 0x02, 0x03}; + static const uint8 fixed32_short[] = {0x25, 0x01}; + static const uint8 nested_overrun[] = {0x0A, 0x05, 0x08, 0x05}; // inner says 5, has 2 + static const uint8 garbage[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + int64 rejected; + int32 code; + char msg[16]; + + CHECK(!PschOtlpParseLogsResponse(group_start, sizeof(group_start), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(group_end, sizeof(group_end), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(wt6, sizeof(wt6), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(wt7, sizeof(wt7), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(field0, sizeof(field0), &rejected, msg, sizeof(msg))); + CHECK( + !PschOtlpParseLogsResponse(trunc_varint, sizeof(trunc_varint), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(varint_11b, sizeof(varint_11b), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(len_overrun, sizeof(len_overrun), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(fixed64_short, sizeof(fixed64_short), &rejected, msg, + sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(fixed32_short, sizeof(fixed32_short), &rejected, msg, + sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(nested_overrun, sizeof(nested_overrun), &rejected, msg, + sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(garbage, sizeof(garbage), &rejected, msg, sizeof(msg))); + CHECK(!PschOtlpParseLogsResponse(NULL, 5, &rejected, msg, sizeof(msg))); + + CHECK(!PschRpcStatusParse(group_start, sizeof(group_start), &code, msg, sizeof(msg))); + CHECK(!PschRpcStatusParse(varint_11b, sizeof(varint_11b), &code, msg, sizeof(msg))); + CHECK(!PschRpcStatusParse(len_overrun, sizeof(len_overrun), &code, msg, sizeof(msg))); + CHECK(!PschRpcStatusParse(NULL, 5, &code, msg, sizeof(msg))); + + // Garbage prefixes of valid input must never over-read (run under ASan). + static const uint8 ok[] = {0x0A, 0x08, 0x08, 0x05, 0x12, 0x04, 0x62, 0x6F, 0x6F, 0x6D}; + uint8 fuzz[sizeof(ok)]; + for (size_t flip = 0; flip < sizeof(ok) * 8; flip++) { + memcpy(fuzz, ok, sizeof(ok)); + fuzz[flip / 8] ^= (uint8)(1u << (flip % 8)); + (void)PschOtlpParseLogsResponse(fuzz, sizeof(fuzz), &rejected, msg, sizeof(msg)); + } +} + +static void TestRpcStatusParser(void) { + static const uint8 ok[] = {0x08, 0x03, 0x12, 0x03, 0x62, 0x61, 0x64}; + static const uint8 neg[] = {0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}; + static const uint8 last_wins[] = {0x08, 0x01, 0x08, 0x02}; + // details=3 (google.protobuf.Any) must be skipped + static const uint8 with_details[] = {0x08, 0x05, 0x1A, 0x02, 0x0A, 0x00, 0x12, 0x02, 0x68, 0x69}; + int32 code; + char msg[64]; + + CHECK(PschRpcStatusParse(ok, sizeof(ok), &code, msg, sizeof(msg))); + CHECK(code == 3); + CHECK(strcmp(msg, "bad") == 0); + + CHECK(PschRpcStatusParse(NULL, 0, &code, msg, sizeof(msg))); + CHECK(code == 0); + CHECK(msg[0] == '\0'); + + CHECK(PschRpcStatusParse(neg, sizeof(neg), &code, msg, sizeof(msg))); + CHECK(code == -1); + + CHECK(PschRpcStatusParse(last_wins, sizeof(last_wins), &code, msg, sizeof(msg))); + CHECK(code == 2); + + CHECK(PschRpcStatusParse(with_details, sizeof(with_details), &code, msg, sizeof(msg))); + CHECK(code == 5); + CHECK(strcmp(msg, "hi") == 0); + + CHECK(PschRpcStatusParse(ok, sizeof(ok), &code, msg, 2)); + CHECK(strcmp(msg, "b") == 0); +} + +int main(int argc, char** argv) { + TestPrimitiveVectors(); + TestOverflowFuzz(); + TestOverflowSemantics(); + TestMsgEndLengthCeiling(); + TestSampleRequestStructure(argc > 1 ? argv[1] : NULL); + TestLogsResponseParser(); + TestGarbageRejection(); + TestRpcStatusParser(); + + if (failures > 0) { + printf("FAILED: %d of %d checks\n", failures, checks); + return 1; + } + printf("OK: %d checks passed\n", checks); + return 0; +}