diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e78dda7..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - - - name: Install V - uses: vlang/setup-v@v1 - with: - version: latest - - - name: Build C library - run: make -C libpg_query build - - - name: Run V tests - run: v test pg_query/ - - - name: Verify example compiles - run: v -o /tmp/parse_sql_example examples/parse_sql.v diff --git a/.gitignore b/.gitignore index 93a6cf3..f85dd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,9 +26,12 @@ bin/ # Ignore installed modules through `v install --local`: modules/ +# Module resolution symlink (Option B layout) +pg_query + # Compiled C bridge objects -pg_query/*.o -pg_query/*.o.tmp +*.o +*.o.tmp # Compiled example binaries examples/bench diff --git a/Makefile b/Makefile index 0557120..5a42303 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,17 @@ -.PHONY: all build test clean +.PHONY: all build test clean dev-setup all: build -build: pg_query/c_bridge.o libpg_query/libpg_query.a - -pg_query/c_bridge.o: pg_query/c_bridge.c pg_query/c_bridge.h libpg_query/pg_query.h - cc -c -I libpg_query pg_query/c_bridge.c -o pg_query/c_bridge.o - -libpg_query/libpg_query.a: +build: make -C libpg_query build + cp libpg_query/libpg_query.a c/libpg_query.a + +dev-setup: + ln -sf . pg_query test: build - v test pg_query/ + v test . clean: - rm -f pg_query/c_bridge.o make -C libpg_query clean + rm -rf c/libpg_query.a diff --git a/README.md b/README.md index 576b142..abcd070 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,8 @@ cd pg_query.v # Build the static C library (requires Internet — downloads Postgres 17.7 source) make -C libpg_query build -# Build the C helper object -make build - # Verify everything works -v test pg_query/ +v test . ``` ## Usage @@ -188,11 +185,8 @@ parse('SELECT $$$') or { # Build C library make -C libpg_query build -# Build the C helper object -make build - # Run tests -v test pg_query/ +v test . # Run examples v run examples/parse_sql.v @@ -204,22 +198,18 @@ v -o examples/parse_sql examples/parse_sql.v && ./examples/parse_sql v -o examples/concurrent_parse examples/concurrent_parse.v && ./examples/concurrent_parse v -o examples/bench examples/bench.v && ./examples/bench -# Rebuild C helper (after editing c_bridge.c) -cc -c -I libpg_query pg_query/c_bridge.c -o pg_query/c_bridge.o - # Regenerate AST structs and decoders (after changing proto schema) v run tools/gen_ast.v ``` ## How it works -The library bundles [libpg_query](https://github.com/pganalyze/libpg_query) (version 6.2.2, wrapping PostgreSQL 17.7), pre-built as a static archive (`libpg_query.a`). The V wrapper in `pg_query/` has these layers: +The library bundles [libpg_query](https://github.com/pganalyze/libpg_query) (version 6.2.2, wrapping PostgreSQL 17.7), pre-built as a static archive (`libpg_query.a`). The V wrapper has these layers: | Layer | Files | Role | |---|---|---| | **C bindings** | `pgquery.c.v` | `#flag` / `#include` declarations for the C ABI | | **V wrapper** | `pgquery.v` | Safe `!` result types for all public APIs | -| **C helpers** | `c_bridge.c/h` | Thin C helpers for deparse opts, version strings | | **Protobuf helpers** | `pg_query_protobuf.v` | V-native protobuf wire-format read/write helpers | | **Generated decoders** | `pg_query_decode.v` (generated) | 270+ per-message `decode_*` functions | | **Generated encoders** | `pg_query_encode.v` (generated) | 270+ per-message `encode_*` functions | diff --git a/c/libpg_query.a b/c/libpg_query.a new file mode 100644 index 0000000..5906d41 Binary files /dev/null and b/c/libpg_query.a differ diff --git a/c/pg_query.h b/c/pg_query.h new file mode 100644 index 0000000..def0254 --- /dev/null +++ b/c/pg_query.h @@ -0,0 +1,177 @@ +#ifndef PG_QUERY_H +#define PG_QUERY_H + +#include +#include +#include + +#include "postgres_deparse.h" + +typedef struct { + char* message; // exception message + char* funcname; // source function of exception (e.g. SearchSysCache) + char* filename; // source of exception (e.g. parse.l) + int lineno; // source of exception (e.g. 104) + int cursorpos; // char in query at which exception occurred + char* context; // additional context (optional, can be NULL) +} PgQueryError; + +typedef struct { + int length; + bool *items; + PgQueryError* error; +} PgQueryIsUtilityResult; + +typedef struct { + size_t len; + char* data; +} PgQueryProtobuf; + +typedef struct { + PgQueryProtobuf pbuf; + char* stderr_buffer; + PgQueryError* error; +} PgQueryScanResult; + +typedef struct { + char* parse_tree; + char* stderr_buffer; + PgQueryError* error; +} PgQueryParseResult; + +typedef struct { + PgQueryProtobuf parse_tree; + char* stderr_buffer; + PgQueryError* error; +} PgQueryProtobufParseResult; + +typedef struct { + int stmt_location; + int stmt_len; +} PgQuerySplitStmt; + +typedef struct { + PgQuerySplitStmt **stmts; + int n_stmts; + char* stderr_buffer; + PgQueryError* error; +} PgQuerySplitResult; + +typedef struct { + char* query; + PgQueryError* error; +} PgQueryDeparseResult; + +typedef struct { + PostgresDeparseComment **comments; + size_t comment_count; + PgQueryError* error; +} PgQueryDeparseCommentsResult; + +typedef struct { + char* plpgsql_funcs; + PgQueryError* error; +} PgQueryPlpgsqlParseResult; + +typedef struct { + uint64_t fingerprint; + char* fingerprint_str; + char* stderr_buffer; + PgQueryError* error; +} PgQueryFingerprintResult; + +typedef struct { + char* normalized_query; + PgQueryError* error; +} PgQueryNormalizeResult; + +typedef struct { + PgQueryProtobuf summary; + char* stderr_buffer; + PgQueryError* error; +} PgQuerySummaryParseResult; + +// Postgres parser options (parse mode and GUCs that affect parsing) + +typedef enum +{ + PG_QUERY_PARSE_DEFAULT = 0, + PG_QUERY_PARSE_TYPE_NAME, + PG_QUERY_PARSE_PLPGSQL_EXPR, + PG_QUERY_PARSE_PLPGSQL_ASSIGN1, + PG_QUERY_PARSE_PLPGSQL_ASSIGN2, + PG_QUERY_PARSE_PLPGSQL_ASSIGN3 +} PgQueryParseMode; + +// We technically only need 3 bits to store parse mode, but +// having 4 bits avoids API breaks if another one gets added. +#define PG_QUERY_PARSE_MODE_BITS 4 +#define PG_QUERY_PARSE_MODE_BITMASK ((1 << PG_QUERY_PARSE_MODE_BITS) - 1) + +#define PG_QUERY_DISABLE_BACKSLASH_QUOTE 16 // backslash_quote = off (default is safe_encoding, which is effectively on) +#define PG_QUERY_DISABLE_STANDARD_CONFORMING_STRINGS 32 // standard_conforming_strings = off (default is on) +#define PG_QUERY_DISABLE_ESCAPE_STRING_WARNING 64 // escape_string_warning = off (default is on) + +#ifdef __cplusplus +extern "C" { +#endif + +PgQueryNormalizeResult pg_query_normalize(const char* input); +PgQueryNormalizeResult pg_query_normalize_utility(const char* input); +PgQueryScanResult pg_query_scan(const char* input); +PgQueryParseResult pg_query_parse(const char* input); +PgQueryParseResult pg_query_parse_opts(const char* input, int parser_options); +PgQueryProtobufParseResult pg_query_parse_protobuf(const char* input); +PgQueryProtobufParseResult pg_query_parse_protobuf_opts(const char* input, int parser_options); +PgQueryPlpgsqlParseResult pg_query_parse_plpgsql(const char* input); + +PgQueryFingerprintResult pg_query_fingerprint(const char* input); +PgQueryFingerprintResult pg_query_fingerprint_opts(const char* input, int parser_options); + +// Use pg_query_split_with_scanner when you need to split statements that may +// contain parse errors, otherwise pg_query_split_with_parser is recommended +// for improved accuracy due the parser adding additional token handling. +// +// Note that we try to support special cases like comments, strings containing +// ";" on both, as well as oddities like "CREATE RULE .. (SELECT 1; SELECT 2);" +// which is treated as as single statement. +PgQuerySplitResult pg_query_split_with_scanner(const char *input); +PgQuerySplitResult pg_query_split_with_parser(const char *input); + +PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree); +PgQueryDeparseResult pg_query_deparse_protobuf_opts(PgQueryProtobuf parse_tree, struct PostgresDeparseOpts opts); +PgQueryDeparseCommentsResult pg_query_deparse_comments_for_query(const char *query); + +PgQueryIsUtilityResult pg_query_is_utility_stmt(const char *query); + +PgQuerySummaryParseResult pg_query_summary(const char* input, int parser_options, int truncate_limit); + +void pg_query_free_normalize_result(PgQueryNormalizeResult result); +void pg_query_free_scan_result(PgQueryScanResult result); +void pg_query_free_parse_result(PgQueryParseResult result); +void pg_query_free_split_result(PgQuerySplitResult result); +void pg_query_free_deparse_result(PgQueryDeparseResult result); +void pg_query_free_deparse_comments_result(PgQueryDeparseCommentsResult result); +void pg_query_free_protobuf_parse_result(PgQueryProtobufParseResult result); +void pg_query_free_plpgsql_parse_result(PgQueryPlpgsqlParseResult result); +void pg_query_free_fingerprint_result(PgQueryFingerprintResult result); +void pg_query_free_is_utility_result(PgQueryIsUtilityResult result); +void pg_query_free_summary_parse_result(PgQuerySummaryParseResult result); + +// Optional, cleans up the top-level memory context (automatically done for threads that exit) +void pg_query_exit(void); + +// Postgres version information +#define PG_MAJORVERSION "17" +#define PG_VERSION "17.7" +#define PG_VERSION_NUM 170007 + +// Deprecated APIs below + +void pg_query_init(void); // Deprecated as of 9.5-1.4.1, this is now run automatically as needed + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/c/postgres_deparse.h b/c/postgres_deparse.h new file mode 100644 index 0000000..05d7490 --- /dev/null +++ b/c/postgres_deparse.h @@ -0,0 +1,34 @@ +#ifndef POSTGRES_DEPARSE_H +#define POSTGRES_DEPARSE_H + +#include +#include + +typedef struct PostgresDeparseComment { + int match_location; // Insert comment before a node, once we find a node whose location field is equal-or-higher than this location + int newlines_before_comment; // Insert newlines before inserting the comment (set to non-zero if the source comment was separated from the prior token by at least one newline) + int newlines_after_comment; // Insert newlines after inserting the comment (set to non-zero if the source comment was separated from the next token by at least one newline) + char *str; // The actual comment string, including comment start/end tokens, and newline characters in comment (if any) +} PostgresDeparseComment; + +typedef struct PostgresDeparseOpts { + PostgresDeparseComment **comments; + size_t comment_count; + + // Pretty print options + bool pretty_print; + int indent_size; // Indentation size (Default 4 spaces) + int max_line_length; // Restricts the line length of certain lists of items (Default 80 characters) + bool trailing_newline; // Whether to add a trailing newline at the end of the output (Default off) + bool commas_start_of_line; // Place separating commas at start of line (Default off) +} PostgresDeparseOpts; + +/* Forward declarations to allow referencing the structs in this include file without needing Postgres includes */ +struct StringInfoData; +typedef struct StringInfoData *StringInfo; +struct RawStmt; + +extern void deparseRawStmt(StringInfo str, struct RawStmt *raw_stmt); +extern void deparseRawStmtOpts(StringInfo str, struct RawStmt *raw_stmt, PostgresDeparseOpts opts); + +#endif diff --git a/c/vendor/protobuf-c/protobuf-c.c b/c/vendor/protobuf-c/protobuf-c.c new file mode 100644 index 0000000..1f8e607 --- /dev/null +++ b/c/vendor/protobuf-c/protobuf-c.c @@ -0,0 +1,3667 @@ +/* + * Copyright (c) 2008-2015, Dave Benson and the protobuf-c authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + */ + +/*! \file + * Support library for `protoc-c` generated code. + * + * This file implements the public API used by the code generated + * by `protoc-c`. + * + * \authors Dave Benson and the protobuf-c authors + * + * \copyright 2008-2014. Licensed under the terms of the [BSD-2-Clause] license. + */ + +/** + * \todo 64-BIT OPTIMIZATION: certain implementations use 32-bit math + * even on 64-bit platforms (uint64_size, uint64_pack, parse_uint64). + * + * \todo Use size_t consistently. + */ + +#include /* for malloc, free */ +#include /* for strcmp, strlen, memcpy, memmove, memset */ + +#include "protobuf-c.h" + +#define TRUE 1 +#define FALSE 0 + +#define PROTOBUF_C__ASSERT_NOT_REACHED() assert(0) + +/* Workaround for Microsoft compilers. */ +#ifdef _MSC_VER +# define inline __inline +#endif + +/** + * \defgroup internal Internal functions and macros + * + * These are not exported by the library but are useful to developers working + * on `libprotobuf-c` itself. + */ + +/** + * \defgroup macros Utility macros for manipulating structures + * + * Macros and constants used to manipulate the base "classes" generated by + * `protobuf-c`. They also define limits and check correctness. + * + * \ingroup internal + * @{ + */ + +/** The maximum length of a 64-bit integer in varint encoding. */ +#define MAX_UINT64_ENCODED_SIZE 10 + +#ifndef PROTOBUF_C_UNPACK_ERROR +# define PROTOBUF_C_UNPACK_ERROR(...) +#endif + +#if !defined(_WIN32) || !defined(PROTOBUF_C_USE_SHARED_LIB) +const char protobuf_c_empty_string[] = ""; +#endif + +/** + * Internal `ProtobufCMessage` manipulation macro. + * + * Base macro for manipulating a `ProtobufCMessage`. Used by STRUCT_MEMBER() and + * STRUCT_MEMBER_PTR(). + */ +#define STRUCT_MEMBER_P(struct_p, struct_offset) \ + ((void *) ((uint8_t *) (struct_p) + (struct_offset))) + +/** + * Return field in a `ProtobufCMessage` based on offset. + * + * Take a pointer to a `ProtobufCMessage` and find the field at the offset. + * Cast it to the passed type. + */ +#define STRUCT_MEMBER(member_type, struct_p, struct_offset) \ + (*(member_type *) STRUCT_MEMBER_P((struct_p), (struct_offset))) + +/** + * Return field in a `ProtobufCMessage` based on offset. + * + * Take a pointer to a `ProtobufCMessage` and find the field at the offset. Cast + * it to a pointer to the passed type. + */ +#define STRUCT_MEMBER_PTR(member_type, struct_p, struct_offset) \ + ((member_type *) STRUCT_MEMBER_P((struct_p), (struct_offset))) + +/* Assertions for magic numbers. */ + +#define ASSERT_IS_ENUM_DESCRIPTOR(desc) \ + assert((desc)->magic == PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC) + +#define ASSERT_IS_MESSAGE_DESCRIPTOR(desc) \ + assert((desc)->magic == PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC) + +#define ASSERT_IS_MESSAGE(message) \ + ASSERT_IS_MESSAGE_DESCRIPTOR((message)->descriptor) + +#define ASSERT_IS_SERVICE_DESCRIPTOR(desc) \ + assert((desc)->magic == PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC) + +/**@}*/ + +/* --- version --- */ + +const char * +protobuf_c_version(void) +{ + return PROTOBUF_C_VERSION; +} + +uint32_t +protobuf_c_version_number(void) +{ + return PROTOBUF_C_VERSION_NUMBER; +} + +/* --- allocator --- */ + +static void * +system_alloc(void *allocator_data, size_t size) +{ + (void)allocator_data; + return malloc(size); +} + +static void +system_free(void *allocator_data, void *data) +{ + (void)allocator_data; + free(data); +} + +static inline void * +do_alloc(ProtobufCAllocator *allocator, size_t size) +{ + return allocator->alloc(allocator->allocator_data, size); +} + +static inline void +do_free(ProtobufCAllocator *allocator, void *data) +{ + if (data != NULL) + allocator->free(allocator->allocator_data, data); +} + +/* + * This allocator uses the system's malloc() and free(). It is the default + * allocator used if NULL is passed as the ProtobufCAllocator to an exported + * function. + */ +static ProtobufCAllocator protobuf_c__allocator = { + .alloc = &system_alloc, + .free = &system_free, + .allocator_data = NULL, +}; + +/* === buffer-simple === */ + +void +protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, + size_t len, const uint8_t *data) +{ + ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer; + size_t new_len = simp->len + len; + + if (new_len > simp->alloced) { + ProtobufCAllocator *allocator = simp->allocator; + size_t new_alloced = simp->alloced * 2; + uint8_t *new_data; + + if (allocator == NULL) + allocator = &protobuf_c__allocator; + while (new_alloced < new_len) + new_alloced += new_alloced; + new_data = do_alloc(allocator, new_alloced); + if (!new_data) + return; + memcpy(new_data, simp->data, simp->len); + if (simp->must_free_data) + do_free(allocator, simp->data); + else + simp->must_free_data = TRUE; + simp->data = new_data; + simp->alloced = new_alloced; + } + memcpy(simp->data + simp->len, data, len); + simp->len = new_len; +} + +/** + * \defgroup packedsz protobuf_c_message_get_packed_size() implementation + * + * Routines mainly used by protobuf_c_message_get_packed_size(). + * + * \ingroup internal + * @{ + */ + +/** + * Return the number of bytes required to store the tag for the field. Includes + * 3 bits for the wire-type, and a single bit that denotes the end-of-tag. + * + * \param number + * Field tag to encode. + * \return + * Number of bytes required. + */ +static inline size_t +get_tag_size(uint32_t number) +{ + if (number < (1UL << 4)) { + return 1; + } else if (number < (1UL << 11)) { + return 2; + } else if (number < (1UL << 18)) { + return 3; + } else if (number < (1UL << 25)) { + return 4; + } else { + return 5; + } +} + +/** + * Return the number of bytes required to store a variable-length unsigned + * 32-bit integer in base-128 varint encoding. + * + * \param v + * Value to encode. + * \return + * Number of bytes required. + */ +static inline size_t +uint32_size(uint32_t v) +{ + if (v < (1UL << 7)) { + return 1; + } else if (v < (1UL << 14)) { + return 2; + } else if (v < (1UL << 21)) { + return 3; + } else if (v < (1UL << 28)) { + return 4; + } else { + return 5; + } +} + +/** + * Return the number of bytes required to store a variable-length signed 32-bit + * integer in base-128 varint encoding. + * + * \param v + * Value to encode. + * \return + * Number of bytes required. + */ +static inline size_t +int32_size(int32_t v) +{ + if (v < 0) { + return 10; + } else if (v < (1L << 7)) { + return 1; + } else if (v < (1L << 14)) { + return 2; + } else if (v < (1L << 21)) { + return 3; + } else if (v < (1L << 28)) { + return 4; + } else { + return 5; + } +} + +/** + * Return the ZigZag-encoded 32-bit unsigned integer form of a 32-bit signed + * integer. + * + * \param v + * Value to encode. + * \return + * ZigZag encoded integer. + */ +static inline uint32_t +zigzag32(int32_t v) +{ + // Note: the right-shift must be arithmetic + // Note: left shift must be unsigned because of overflow + return ((uint32_t)(v) << 1) ^ (uint32_t)(v >> 31); +} + +/** + * Return the number of bytes required to store a signed 32-bit integer, + * converted to an unsigned 32-bit integer with ZigZag encoding, using base-128 + * varint encoding. + * + * \param v + * Value to encode. + * \return + * Number of bytes required. + */ +static inline size_t +sint32_size(int32_t v) +{ + return uint32_size(zigzag32(v)); +} + +/** + * Return the number of bytes required to store a 64-bit unsigned integer in + * base-128 varint encoding. + * + * \param v + * Value to encode. + * \return + * Number of bytes required. + */ +static inline size_t +uint64_size(uint64_t v) +{ + uint32_t upper_v = (uint32_t) (v >> 32); + + if (upper_v == 0) { + return uint32_size((uint32_t) v); + } else if (upper_v < (1UL << 3)) { + return 5; + } else if (upper_v < (1UL << 10)) { + return 6; + } else if (upper_v < (1UL << 17)) { + return 7; + } else if (upper_v < (1UL << 24)) { + return 8; + } else if (upper_v < (1UL << 31)) { + return 9; + } else { + return 10; + } +} + +/** + * Return the ZigZag-encoded 64-bit unsigned integer form of a 64-bit signed + * integer. + * + * \param v + * Value to encode. + * \return + * ZigZag encoded integer. + */ +static inline uint64_t +zigzag64(int64_t v) +{ + // Note: the right-shift must be arithmetic + // Note: left shift must be unsigned because of overflow + return ((uint64_t)(v) << 1) ^ (uint64_t)(v >> 63); +} + +/** + * Return the number of bytes required to store a signed 64-bit integer, + * converted to an unsigned 64-bit integer with ZigZag encoding, using base-128 + * varint encoding. + * + * \param v + * Value to encode. + * \return + * Number of bytes required. + */ +static inline size_t +sint64_size(int64_t v) +{ + return uint64_size(zigzag64(v)); +} + +/** + * Calculate the serialized size of a single required message field, including + * the space needed by the preceding tag. + * + * \param field + * Field descriptor for member. + * \param member + * Field to encode. + * \return + * Number of bytes required. + */ +static size_t +required_field_get_packed_size(const ProtobufCFieldDescriptor *field, + const void *member) +{ + size_t rv = get_tag_size(field->id); + + switch (field->type) { + case PROTOBUF_C_TYPE_SINT32: + return rv + sint32_size(*(const int32_t *) member); + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + return rv + int32_size(*(const int32_t *) member); + case PROTOBUF_C_TYPE_UINT32: + return rv + uint32_size(*(const uint32_t *) member); + case PROTOBUF_C_TYPE_SINT64: + return rv + sint64_size(*(const int64_t *) member); + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + return rv + uint64_size(*(const uint64_t *) member); + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + return rv + 4; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + return rv + 8; + case PROTOBUF_C_TYPE_BOOL: + return rv + 1; + case PROTOBUF_C_TYPE_FLOAT: + return rv + 4; + case PROTOBUF_C_TYPE_DOUBLE: + return rv + 8; + case PROTOBUF_C_TYPE_STRING: { + const char *str = *(char * const *) member; + size_t len = str ? strlen(str) : 0; + return rv + uint32_size(len) + len; + } + case PROTOBUF_C_TYPE_BYTES: { + size_t len = ((const ProtobufCBinaryData *) member)->len; + return rv + uint32_size(len) + len; + } + case PROTOBUF_C_TYPE_MESSAGE: { + const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member; + size_t subrv = msg ? protobuf_c_message_get_packed_size(msg) : 0; + return rv + uint32_size(subrv) + subrv; + } + } + PROTOBUF_C__ASSERT_NOT_REACHED(); + return 0; +} + +/** + * Calculate the serialized size of a single oneof message field, including + * the space needed by the preceding tag. Returns 0 if the oneof field isn't + * selected or is not set. + * + * \param field + * Field descriptor for member. + * \param oneof_case + * Enum value that selects the field in the oneof. + * \param member + * Field to encode. + * \return + * Number of bytes required. + */ +static size_t +oneof_field_get_packed_size(const ProtobufCFieldDescriptor *field, + uint32_t oneof_case, + const void *member) +{ + if (oneof_case != field->id) { + return 0; + } + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void * const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } + return required_field_get_packed_size(field, member); +} + +/** + * Calculate the serialized size of a single optional message field, including + * the space needed by the preceding tag. Returns 0 if the optional field isn't + * set. + * + * \param field + * Field descriptor for member. + * \param has + * True if the field exists, false if not. + * \param member + * Field to encode. + * \return + * Number of bytes required. + */ +static size_t +optional_field_get_packed_size(const ProtobufCFieldDescriptor *field, + const protobuf_c_boolean has, + const void *member) +{ + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void * const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } else { + if (!has) + return 0; + } + return required_field_get_packed_size(field, member); +} + +static protobuf_c_boolean +field_is_zeroish(const ProtobufCFieldDescriptor *field, + const void *member) +{ + protobuf_c_boolean ret = FALSE; + + switch (field->type) { + case PROTOBUF_C_TYPE_BOOL: + ret = (0 == *(const protobuf_c_boolean *) member); + break; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_SINT32: + case PROTOBUF_C_TYPE_INT32: + case PROTOBUF_C_TYPE_UINT32: + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + ret = (0 == *(const uint32_t *) member); + break; + case PROTOBUF_C_TYPE_SINT64: + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + ret = (0 == *(const uint64_t *) member); + break; + case PROTOBUF_C_TYPE_FLOAT: + ret = (0 == *(const float *) member); + break; + case PROTOBUF_C_TYPE_DOUBLE: + ret = (0 == *(const double *) member); + break; + case PROTOBUF_C_TYPE_STRING: + ret = (NULL == *(const char * const *) member) || + ('\0' == **(const char * const *) member); + break; + case PROTOBUF_C_TYPE_BYTES: + case PROTOBUF_C_TYPE_MESSAGE: + ret = (NULL == *(const void * const *) member); + break; + default: + ret = TRUE; + break; + } + + return ret; +} + +/** + * Calculate the serialized size of a single unlabeled message field, including + * the space needed by the preceding tag. Returns 0 if the field isn't set or + * if it is set to a "zeroish" value (null pointer or 0 for numerical values). + * Unlabeled fields are supported only in proto3. + * + * \param field + * Field descriptor for member. + * \param member + * Field to encode. + * \return + * Number of bytes required. + */ +static size_t +unlabeled_field_get_packed_size(const ProtobufCFieldDescriptor *field, + const void *member) +{ + if (field_is_zeroish(field, member)) + return 0; + return required_field_get_packed_size(field, member); +} + +/** + * Calculate the serialized size of repeated message fields, which may consist + * of any number of values (including 0). Includes the space needed by the + * preceding tags (as needed). + * + * \param field + * Field descriptor for member. + * \param count + * Number of repeated field members. + * \param member + * Field to encode. + * \return + * Number of bytes required. + */ +static size_t +repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field, + size_t count, const void *member) +{ + size_t header_size; + size_t rv = 0; + unsigned i; + void *array = *(void * const *) member; + + if (count == 0) + return 0; + header_size = get_tag_size(field->id); + if (0 == (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) + header_size *= count; + + switch (field->type) { + case PROTOBUF_C_TYPE_SINT32: + for (i = 0; i < count; i++) + rv += sint32_size(((int32_t *) array)[i]); + break; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + for (i = 0; i < count; i++) + rv += int32_size(((int32_t *) array)[i]); + break; + case PROTOBUF_C_TYPE_UINT32: + for (i = 0; i < count; i++) + rv += uint32_size(((uint32_t *) array)[i]); + break; + case PROTOBUF_C_TYPE_SINT64: + for (i = 0; i < count; i++) + rv += sint64_size(((int64_t *) array)[i]); + break; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + for (i = 0; i < count; i++) + rv += uint64_size(((uint64_t *) array)[i]); + break; + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + rv += 4 * count; + break; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + rv += 8 * count; + break; + case PROTOBUF_C_TYPE_BOOL: + rv += count; + break; + case PROTOBUF_C_TYPE_STRING: + for (i = 0; i < count; i++) { + size_t len = strlen(((char **) array)[i]); + rv += uint32_size(len) + len; + } + break; + case PROTOBUF_C_TYPE_BYTES: + for (i = 0; i < count; i++) { + size_t len = ((ProtobufCBinaryData *) array)[i].len; + rv += uint32_size(len) + len; + } + break; + case PROTOBUF_C_TYPE_MESSAGE: + for (i = 0; i < count; i++) { + size_t len = protobuf_c_message_get_packed_size( + ((ProtobufCMessage **) array)[i]); + rv += uint32_size(len) + len; + } + break; + } + + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) + header_size += uint32_size(rv); + return header_size + rv; +} + +/** + * Calculate the serialized size of an unknown field, i.e. one that is passed + * through mostly uninterpreted. This is required for forward compatibility if + * new fields are added to the message descriptor. + * + * \param field + * Unknown field type. + * \return + * Number of bytes required. + */ +static inline size_t +unknown_field_get_packed_size(const ProtobufCMessageUnknownField *field) +{ + return get_tag_size(field->tag) + field->len; +} + +/**@}*/ + +/* + * Calculate the serialized size of the message. + */ +size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message) +{ + unsigned i; + size_t rv = 0; + + ASSERT_IS_MESSAGE(message); + for (i = 0; i < message->descriptor->n_fields; i++) { + const ProtobufCFieldDescriptor *field = + message->descriptor->fields + i; + const void *member = + ((const char *) message) + field->offset; + const void *qmember = + ((const char *) message) + field->quantifier_offset; + + if (field->label == PROTOBUF_C_LABEL_REQUIRED) { + rv += required_field_get_packed_size(field, member); + } else if ((field->label == PROTOBUF_C_LABEL_OPTIONAL || + field->label == PROTOBUF_C_LABEL_NONE) && + (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF))) { + rv += oneof_field_get_packed_size( + field, + *(const uint32_t *) qmember, + member + ); + } else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) { + rv += optional_field_get_packed_size( + field, + *(protobuf_c_boolean *) qmember, + member + ); + } else if (field->label == PROTOBUF_C_LABEL_NONE) { + rv += unlabeled_field_get_packed_size( + field, + member + ); + } else { + rv += repeated_field_get_packed_size( + field, + *(const size_t *) qmember, + member + ); + } + } + for (i = 0; i < message->n_unknown_fields; i++) + rv += unknown_field_get_packed_size(&message->unknown_fields[i]); + return rv; +} + +/** + * \defgroup pack protobuf_c_message_pack() implementation + * + * Routines mainly used by protobuf_c_message_pack(). + * + * \ingroup internal + * @{ + */ + +/** + * Pack an unsigned 32-bit integer in base-128 varint encoding and return the + * number of bytes written, which must be 5 or less. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +uint32_pack(uint32_t value, uint8_t *out) +{ + unsigned rv = 0; + + if (value >= 0x80) { + out[rv++] = value | 0x80; + value >>= 7; + if (value >= 0x80) { + out[rv++] = value | 0x80; + value >>= 7; + if (value >= 0x80) { + out[rv++] = value | 0x80; + value >>= 7; + if (value >= 0x80) { + out[rv++] = value | 0x80; + value >>= 7; + } + } + } + } + /* assert: value<128 */ + out[rv++] = value; + return rv; +} + +/** + * Pack a signed 32-bit integer and return the number of bytes written. + * Negative numbers are encoded as two's complement 64-bit integers. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +int32_pack(int32_t value, uint8_t *out) +{ + if (value < 0) { + out[0] = value | 0x80; + out[1] = (value >> 7) | 0x80; + out[2] = (value >> 14) | 0x80; + out[3] = (value >> 21) | 0x80; + out[4] = (value >> 28) | 0x80; + out[5] = out[6] = out[7] = out[8] = 0xff; + out[9] = 0x01; + return 10; + } else { + return uint32_pack(value, out); + } +} + +/** + * Pack a signed 32-bit integer using ZigZag encoding and return the number of + * bytes written. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +sint32_pack(int32_t value, uint8_t *out) +{ + return uint32_pack(zigzag32(value), out); +} + +/** + * Pack a 64-bit unsigned integer using base-128 varint encoding and return the + * number of bytes written. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +uint64_pack(uint64_t value, uint8_t *out) +{ + uint32_t hi = (uint32_t) (value >> 32); + uint32_t lo = (uint32_t) value; + unsigned rv; + + if (hi == 0) + return uint32_pack((uint32_t) lo, out); + out[0] = (lo) | 0x80; + out[1] = (lo >> 7) | 0x80; + out[2] = (lo >> 14) | 0x80; + out[3] = (lo >> 21) | 0x80; + if (hi < 8) { + out[4] = (hi << 4) | (lo >> 28); + return 5; + } else { + out[4] = ((hi & 7) << 4) | (lo >> 28) | 0x80; + hi >>= 3; + } + rv = 5; + while (hi >= 128) { + out[rv++] = hi | 0x80; + hi >>= 7; + } + out[rv++] = hi; + return rv; +} + +/** + * Pack a 64-bit signed integer in ZigZag encoding and return the number of + * bytes written. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +sint64_pack(int64_t value, uint8_t *out) +{ + return uint64_pack(zigzag64(value), out); +} + +/** + * Pack a 32-bit quantity in little-endian byte order. Used for protobuf wire + * types fixed32, sfixed32, float. Similar to "htole32". + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +fixed32_pack(uint32_t value, void *out) +{ +#if !defined(WORDS_BIGENDIAN) + memcpy(out, &value, 4); +#else + uint8_t *buf = out; + + buf[0] = value; + buf[1] = value >> 8; + buf[2] = value >> 16; + buf[3] = value >> 24; +#endif + return 4; +} + +/** + * Pack a 64-bit quantity in little-endian byte order. Used for protobuf wire + * types fixed64, sfixed64, double. Similar to "htole64". + * + * \todo The big-endian impl is really only good for 32-bit machines, a 64-bit + * version would be appreciated, plus a way to decide to use 64-bit math where + * convenient. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +fixed64_pack(uint64_t value, void *out) +{ +#if !defined(WORDS_BIGENDIAN) + memcpy(out, &value, 8); +#else + fixed32_pack(value, out); + fixed32_pack(value >> 32, ((char *) out) + 4); +#endif + return 8; +} + +/** + * Pack a boolean value as an integer and return the number of bytes written. + * + * \todo Perhaps on some platforms *out = !!value would be a better impl, b/c + * that is idiomatic C++ in some STL implementations. + * + * \param value + * Value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +boolean_pack(protobuf_c_boolean value, uint8_t *out) +{ + *out = value ? TRUE : FALSE; + return 1; +} + +/** + * Pack a NUL-terminated C string and return the number of bytes written. The + * output includes a length delimiter. + * + * The NULL pointer is treated as an empty string. This isn't really necessary, + * but it allows people to leave required strings blank. (See Issue #13 in the + * bug tracker for a little more explanation). + * + * \param str + * String to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +string_pack(const char *str, uint8_t *out) +{ + if (str == NULL) { + out[0] = 0; + return 1; + } else { + size_t len = strlen(str); + size_t rv = uint32_pack(len, out); + memcpy(out + rv, str, len); + return rv + len; + } +} + +/** + * Pack a ProtobufCBinaryData and return the number of bytes written. The output + * includes a length delimiter. + * + * \param bd + * ProtobufCBinaryData to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +binary_data_pack(const ProtobufCBinaryData *bd, uint8_t *out) +{ + size_t len = bd->len; + size_t rv = uint32_pack(len, out); + memcpy(out + rv, bd->data, len); + return rv + len; +} + +/** + * Pack a ProtobufCMessage and return the number of bytes written. The output + * includes a length delimiter. + * + * \param message + * ProtobufCMessage object to pack. + * \param[out] out + * Packed message. + * \return + * Number of bytes written to `out`. + */ +static inline size_t +prefixed_message_pack(const ProtobufCMessage *message, uint8_t *out) +{ + if (message == NULL) { + out[0] = 0; + return 1; + } else { + size_t rv = protobuf_c_message_pack(message, out + 1); + uint32_t rv_packed_size = uint32_size(rv); + if (rv_packed_size != 1) + memmove(out + rv_packed_size, out + 1, rv); + return uint32_pack(rv, out) + rv; + } +} + +/** + * Pack a field tag. + * + * Wire-type will be added in required_field_pack(). + * + * \todo Just call uint64_pack on 64-bit platforms. + * + * \param id + * Tag value to encode. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +tag_pack(uint32_t id, uint8_t *out) +{ + if (id < (1UL << (32 - 3))) + return uint32_pack(id << 3, out); + else + return uint64_pack(((uint64_t) id) << 3, out); +} + +/** + * Pack a required field and return the number of bytes written. + * + * \param field + * Field descriptor. + * \param member + * The field member. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +required_field_pack(const ProtobufCFieldDescriptor *field, + const void *member, uint8_t *out) +{ + size_t rv = tag_pack(field->id, out); + + switch (field->type) { + case PROTOBUF_C_TYPE_SINT32: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + sint32_pack(*(const int32_t *) member, out + rv); + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + int32_pack(*(const int32_t *) member, out + rv); + case PROTOBUF_C_TYPE_UINT32: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + uint32_pack(*(const uint32_t *) member, out + rv); + case PROTOBUF_C_TYPE_SINT64: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + sint64_pack(*(const int64_t *) member, out + rv); + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + uint64_pack(*(const uint64_t *) member, out + rv); + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT; + return rv + fixed32_pack(*(const uint32_t *) member, out + rv); + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT; + return rv + fixed64_pack(*(const uint64_t *) member, out + rv); + case PROTOBUF_C_TYPE_BOOL: + out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + return rv + boolean_pack(*(const protobuf_c_boolean *) member, out + rv); + case PROTOBUF_C_TYPE_STRING: + out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + return rv + string_pack(*(char *const *) member, out + rv); + case PROTOBUF_C_TYPE_BYTES: + out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + return rv + binary_data_pack((const ProtobufCBinaryData *) member, out + rv); + case PROTOBUF_C_TYPE_MESSAGE: + out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + return rv + prefixed_message_pack(*(ProtobufCMessage * const *) member, out + rv); + } + PROTOBUF_C__ASSERT_NOT_REACHED(); + return 0; +} + +/** + * Pack a oneof field and return the number of bytes written. Only packs the + * field that is selected by the case enum. + * + * \param field + * Field descriptor. + * \param oneof_case + * Enum value that selects the field in the oneof. + * \param member + * The field member. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +oneof_field_pack(const ProtobufCFieldDescriptor *field, + uint32_t oneof_case, + const void *member, uint8_t *out) +{ + if (oneof_case != field->id) { + return 0; + } + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void * const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } + return required_field_pack(field, member, out); +} + +/** + * Pack an optional field and return the number of bytes written. + * + * \param field + * Field descriptor. + * \param has + * Whether the field is set. + * \param member + * The field member. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +optional_field_pack(const ProtobufCFieldDescriptor *field, + const protobuf_c_boolean has, + const void *member, uint8_t *out) +{ + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void * const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } else { + if (!has) + return 0; + } + return required_field_pack(field, member, out); +} + +/** + * Pack an unlabeled field and return the number of bytes written. + * + * \param field + * Field descriptor. + * \param member + * The field member. + * \param[out] out + * Packed value. + * \return + * Number of bytes written to `out`. + */ +static size_t +unlabeled_field_pack(const ProtobufCFieldDescriptor *field, + const void *member, uint8_t *out) +{ + if (field_is_zeroish(field, member)) + return 0; + return required_field_pack(field, member, out); +} + +/** + * Given a field type, return the in-memory size. + * + * \todo Implement as a table lookup. + * + * \param type + * Field type. + * \return + * Size of the field. + */ +static inline size_t +sizeof_elt_in_repeated_array(ProtobufCType type) +{ + switch (type) { + case PROTOBUF_C_TYPE_SINT32: + case PROTOBUF_C_TYPE_INT32: + case PROTOBUF_C_TYPE_UINT32: + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + case PROTOBUF_C_TYPE_ENUM: + return 4; + case PROTOBUF_C_TYPE_SINT64: + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + return 8; + case PROTOBUF_C_TYPE_BOOL: + return sizeof(protobuf_c_boolean); + case PROTOBUF_C_TYPE_STRING: + case PROTOBUF_C_TYPE_MESSAGE: + return sizeof(void *); + case PROTOBUF_C_TYPE_BYTES: + return sizeof(ProtobufCBinaryData); + } + PROTOBUF_C__ASSERT_NOT_REACHED(); + return 0; +} + +/** + * Pack an array of 32-bit quantities. + * + * \param[out] out + * Destination. + * \param[in] in + * Source. + * \param[in] n + * Number of elements in the source array. + */ +static void +copy_to_little_endian_32(void *out, const void *in, const unsigned n) +{ +#if !defined(WORDS_BIGENDIAN) + memcpy(out, in, n * 4); +#else + unsigned i; + const uint32_t *ini = in; + for (i = 0; i < n; i++) + fixed32_pack(ini[i], (uint32_t *) out + i); +#endif +} + +/** + * Pack an array of 64-bit quantities. + * + * \param[out] out + * Destination. + * \param[in] in + * Source. + * \param[in] n + * Number of elements in the source array. + */ +static void +copy_to_little_endian_64(void *out, const void *in, const unsigned n) +{ +#if !defined(WORDS_BIGENDIAN) + memcpy(out, in, n * 8); +#else + unsigned i; + const uint64_t *ini = in; + for (i = 0; i < n; i++) + fixed64_pack(ini[i], (uint64_t *) out + i); +#endif +} + +/** + * Get the minimum number of bytes required to pack a field value of a + * particular type. + * + * \param type + * Field type. + * \return + * Number of bytes. + */ +static unsigned +get_type_min_size(ProtobufCType type) +{ + if (type == PROTOBUF_C_TYPE_SFIXED32 || + type == PROTOBUF_C_TYPE_FIXED32 || + type == PROTOBUF_C_TYPE_FLOAT) + { + return 4; + } + if (type == PROTOBUF_C_TYPE_SFIXED64 || + type == PROTOBUF_C_TYPE_FIXED64 || + type == PROTOBUF_C_TYPE_DOUBLE) + { + return 8; + } + return 1; +} + +/** + * Packs the elements of a repeated field and returns the serialised field and + * its length. + * + * \param field + * Field descriptor. + * \param count + * Number of elements in the repeated field array. + * \param member + * Pointer to the elements for this repeated field. + * \param[out] out + * Serialised representation of the repeated field. + * \return + * Number of bytes serialised to `out`. + */ +static size_t +repeated_field_pack(const ProtobufCFieldDescriptor *field, + size_t count, const void *member, uint8_t *out) +{ + void *array = *(void * const *) member; + unsigned i; + + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) { + unsigned header_len; + unsigned len_start; + unsigned min_length; + unsigned payload_len; + unsigned length_size_min; + unsigned actual_length_size; + uint8_t *payload_at; + + if (count == 0) + return 0; + header_len = tag_pack(field->id, out); + out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + len_start = header_len; + min_length = get_type_min_size(field->type) * count; + length_size_min = uint32_size(min_length); + header_len += length_size_min; + payload_at = out + header_len; + + switch (field->type) { + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + copy_to_little_endian_32(payload_at, array, count); + payload_at += count * 4; + break; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + copy_to_little_endian_64(payload_at, array, count); + payload_at += count * 8; + break; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: { + const int32_t *arr = (const int32_t *) array; + for (i = 0; i < count; i++) + payload_at += int32_pack(arr[i], payload_at); + break; + } + case PROTOBUF_C_TYPE_SINT32: { + const int32_t *arr = (const int32_t *) array; + for (i = 0; i < count; i++) + payload_at += sint32_pack(arr[i], payload_at); + break; + } + case PROTOBUF_C_TYPE_SINT64: { + const int64_t *arr = (const int64_t *) array; + for (i = 0; i < count; i++) + payload_at += sint64_pack(arr[i], payload_at); + break; + } + case PROTOBUF_C_TYPE_UINT32: { + const uint32_t *arr = (const uint32_t *) array; + for (i = 0; i < count; i++) + payload_at += uint32_pack(arr[i], payload_at); + break; + } + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: { + const uint64_t *arr = (const uint64_t *) array; + for (i = 0; i < count; i++) + payload_at += uint64_pack(arr[i], payload_at); + break; + } + case PROTOBUF_C_TYPE_BOOL: { + const protobuf_c_boolean *arr = (const protobuf_c_boolean *) array; + for (i = 0; i < count; i++) + payload_at += boolean_pack(arr[i], payload_at); + break; + } + default: + PROTOBUF_C__ASSERT_NOT_REACHED(); + } + + payload_len = payload_at - (out + header_len); + actual_length_size = uint32_size(payload_len); + if (length_size_min != actual_length_size) { + assert(actual_length_size == length_size_min + 1); + memmove(out + header_len + 1, out + header_len, + payload_len); + header_len++; + } + uint32_pack(payload_len, out + len_start); + return header_len + payload_len; + } else { + /* not "packed" cased */ + /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */ + size_t rv = 0; + unsigned siz = sizeof_elt_in_repeated_array(field->type); + + for (i = 0; i < count; i++) { + rv += required_field_pack(field, array, out + rv); + array = (char *)array + siz; + } + return rv; + } +} + +static size_t +unknown_field_pack(const ProtobufCMessageUnknownField *field, uint8_t *out) +{ + size_t rv = tag_pack(field->tag, out); + out[0] |= field->wire_type; + memcpy(out + rv, field->data, field->len); + return rv + field->len; +} + +/**@}*/ + +size_t +protobuf_c_message_pack(const ProtobufCMessage *message, uint8_t *out) +{ + unsigned i; + size_t rv = 0; + + ASSERT_IS_MESSAGE(message); + for (i = 0; i < message->descriptor->n_fields; i++) { + const ProtobufCFieldDescriptor *field = + message->descriptor->fields + i; + const void *member = ((const char *) message) + field->offset; + + /* + * It doesn't hurt to compute qmember (a pointer to the + * quantifier field of the structure), but the pointer is only + * valid if the field is: + * - a repeated field, or + * - a field that is part of a oneof + * - an optional field that isn't a pointer type + * (Meaning: not a message or a string). + */ + const void *qmember = + ((const char *) message) + field->quantifier_offset; + + if (field->label == PROTOBUF_C_LABEL_REQUIRED) { + rv += required_field_pack(field, member, out + rv); + } else if ((field->label == PROTOBUF_C_LABEL_OPTIONAL || + field->label == PROTOBUF_C_LABEL_NONE) && + (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF))) { + rv += oneof_field_pack( + field, + *(const uint32_t *) qmember, + member, + out + rv + ); + } else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) { + rv += optional_field_pack( + field, + *(const protobuf_c_boolean *) qmember, + member, + out + rv + ); + } else if (field->label == PROTOBUF_C_LABEL_NONE) { + rv += unlabeled_field_pack(field, member, out + rv); + } else { + rv += repeated_field_pack(field, *(const size_t *) qmember, + member, out + rv); + } + } + for (i = 0; i < message->n_unknown_fields; i++) + rv += unknown_field_pack(&message->unknown_fields[i], out + rv); + return rv; +} + +/** + * \defgroup packbuf protobuf_c_message_pack_to_buffer() implementation + * + * Routines mainly used by protobuf_c_message_pack_to_buffer(). + * + * \ingroup internal + * @{ + */ + +/** + * Pack a required field to a virtual buffer. + * + * \param field + * Field descriptor. + * \param member + * The element to be packed. + * \param[out] buffer + * Virtual buffer to append data to. + * \return + * Number of bytes packed. + */ +static size_t +required_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, + const void *member, ProtobufCBuffer *buffer) +{ + size_t rv; + uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2]; + + rv = tag_pack(field->id, scratch); + switch (field->type) { + case PROTOBUF_C_TYPE_SINT32: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += sint32_pack(*(const int32_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += int32_pack(*(const int32_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_UINT32: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += uint32_pack(*(const uint32_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_SINT64: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += sint64_pack(*(const int64_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += uint64_pack(*(const uint64_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT; + rv += fixed32_pack(*(const uint32_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT; + rv += fixed64_pack(*(const uint64_t *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_BOOL: + scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; + rv += boolean_pack(*(const protobuf_c_boolean *) member, scratch + rv); + buffer->append(buffer, rv, scratch); + break; + case PROTOBUF_C_TYPE_STRING: { + const char *str = *(char *const *) member; + size_t sublen = str ? strlen(str) : 0; + + scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + rv += uint32_pack(sublen, scratch + rv); + buffer->append(buffer, rv, scratch); + buffer->append(buffer, sublen, (const uint8_t *) str); + rv += sublen; + break; + } + case PROTOBUF_C_TYPE_BYTES: { + const ProtobufCBinaryData *bd = ((const ProtobufCBinaryData *) member); + size_t sublen = bd->len; + + scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + rv += uint32_pack(sublen, scratch + rv); + buffer->append(buffer, rv, scratch); + buffer->append(buffer, sublen, bd->data); + rv += sublen; + break; + } + case PROTOBUF_C_TYPE_MESSAGE: { + const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member; + + scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + if (msg == NULL) { + rv += uint32_pack(0, scratch + rv); + buffer->append(buffer, rv, scratch); + } else { + size_t sublen = protobuf_c_message_get_packed_size(msg); + rv += uint32_pack(sublen, scratch + rv); + buffer->append(buffer, rv, scratch); + protobuf_c_message_pack_to_buffer(msg, buffer); + rv += sublen; + } + break; + } + default: + PROTOBUF_C__ASSERT_NOT_REACHED(); + } + return rv; +} + +/** + * Pack a oneof field to a buffer. Only packs the field that is selected by the case enum. + * + * \param field + * Field descriptor. + * \param oneof_case + * Enum value that selects the field in the oneof. + * \param member + * The element to be packed. + * \param[out] buffer + * Virtual buffer to append data to. + * \return + * Number of bytes serialised to `buffer`. + */ +static size_t +oneof_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, + uint32_t oneof_case, + const void *member, ProtobufCBuffer *buffer) +{ + if (oneof_case != field->id) { + return 0; + } + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void *const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } + return required_field_pack_to_buffer(field, member, buffer); +} + +/** + * Pack an optional field to a buffer. + * + * \param field + * Field descriptor. + * \param has + * Whether the field is set. + * \param member + * The element to be packed. + * \param[out] buffer + * Virtual buffer to append data to. + * \return + * Number of bytes serialised to `buffer`. + */ +static size_t +optional_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, + const protobuf_c_boolean has, + const void *member, ProtobufCBuffer *buffer) +{ + if (field->type == PROTOBUF_C_TYPE_MESSAGE || + field->type == PROTOBUF_C_TYPE_STRING) + { + const void *ptr = *(const void *const *) member; + if (ptr == NULL || ptr == field->default_value) + return 0; + } else { + if (!has) + return 0; + } + return required_field_pack_to_buffer(field, member, buffer); +} + +/** + * Pack an unlabeled field to a buffer. + * + * \param field + * Field descriptor. + * \param member + * The element to be packed. + * \param[out] buffer + * Virtual buffer to append data to. + * \return + * Number of bytes serialised to `buffer`. + */ +static size_t +unlabeled_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, + const void *member, ProtobufCBuffer *buffer) +{ + if (field_is_zeroish(field, member)) + return 0; + return required_field_pack_to_buffer(field, member, buffer); +} + +/** + * Get the packed size of an array of same field type. + * + * \param field + * Field descriptor. + * \param count + * Number of elements of this type. + * \param array + * The elements to get the size of. + * \return + * Number of bytes required. + */ +static size_t +get_packed_payload_length(const ProtobufCFieldDescriptor *field, + unsigned count, const void *array) +{ + unsigned rv = 0; + unsigned i; + + switch (field->type) { + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + return count * 4; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + return count * 8; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: { + const int32_t *arr = (const int32_t *) array; + for (i = 0; i < count; i++) + rv += int32_size(arr[i]); + break; + } + case PROTOBUF_C_TYPE_SINT32: { + const int32_t *arr = (const int32_t *) array; + for (i = 0; i < count; i++) + rv += sint32_size(arr[i]); + break; + } + case PROTOBUF_C_TYPE_UINT32: { + const uint32_t *arr = (const uint32_t *) array; + for (i = 0; i < count; i++) + rv += uint32_size(arr[i]); + break; + } + case PROTOBUF_C_TYPE_SINT64: { + const int64_t *arr = (const int64_t *) array; + for (i = 0; i < count; i++) + rv += sint64_size(arr[i]); + break; + } + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: { + const uint64_t *arr = (const uint64_t *) array; + for (i = 0; i < count; i++) + rv += uint64_size(arr[i]); + break; + } + case PROTOBUF_C_TYPE_BOOL: + return count; + default: + PROTOBUF_C__ASSERT_NOT_REACHED(); + } + return rv; +} + +/** + * Pack an array of same field type to a virtual buffer. + * + * \param field + * Field descriptor. + * \param count + * Number of elements of this type. + * \param array + * The elements to get the size of. + * \param[out] buffer + * Virtual buffer to append data to. + * \return + * Number of bytes packed. + */ +static size_t +pack_buffer_packed_payload(const ProtobufCFieldDescriptor *field, + unsigned count, const void *array, + ProtobufCBuffer *buffer) +{ + uint8_t scratch[16]; + size_t rv = 0; + unsigned i; + + switch (field->type) { + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: +#if !defined(WORDS_BIGENDIAN) + rv = count * 4; + goto no_packing_needed; +#else + for (i = 0; i < count; i++) { + unsigned len = fixed32_pack(((uint32_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; +#endif + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: +#if !defined(WORDS_BIGENDIAN) + rv = count * 8; + goto no_packing_needed; +#else + for (i = 0; i < count; i++) { + unsigned len = fixed64_pack(((uint64_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; +#endif + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + for (i = 0; i < count; i++) { + unsigned len = int32_pack(((int32_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; + case PROTOBUF_C_TYPE_SINT32: + for (i = 0; i < count; i++) { + unsigned len = sint32_pack(((int32_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; + case PROTOBUF_C_TYPE_UINT32: + for (i = 0; i < count; i++) { + unsigned len = uint32_pack(((uint32_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; + case PROTOBUF_C_TYPE_SINT64: + for (i = 0; i < count; i++) { + unsigned len = sint64_pack(((int64_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + for (i = 0; i < count; i++) { + unsigned len = uint64_pack(((uint64_t *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + break; + case PROTOBUF_C_TYPE_BOOL: + for (i = 0; i < count; i++) { + unsigned len = boolean_pack(((protobuf_c_boolean *) array)[i], scratch); + buffer->append(buffer, len, scratch); + rv += len; + } + return count; + default: + PROTOBUF_C__ASSERT_NOT_REACHED(); + } + return rv; + +#if !defined(WORDS_BIGENDIAN) +no_packing_needed: + buffer->append(buffer, rv, array); + return rv; +#endif +} + +static size_t +repeated_field_pack_to_buffer(const ProtobufCFieldDescriptor *field, + unsigned count, const void *member, + ProtobufCBuffer *buffer) +{ + char *array = *(char * const *) member; + + if (count == 0) + return 0; + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) { + uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2]; + size_t rv = tag_pack(field->id, scratch); + size_t payload_len = get_packed_payload_length(field, count, array); + size_t tmp; + + scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; + rv += uint32_pack(payload_len, scratch + rv); + buffer->append(buffer, rv, scratch); + tmp = pack_buffer_packed_payload(field, count, array, buffer); + assert(tmp == payload_len); + return rv + payload_len; + } else { + size_t siz; + unsigned i; + /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */ + unsigned rv = 0; + + siz = sizeof_elt_in_repeated_array(field->type); + for (i = 0; i < count; i++) { + rv += required_field_pack_to_buffer(field, array, buffer); + array += siz; + } + return rv; + } +} + +static size_t +unknown_field_pack_to_buffer(const ProtobufCMessageUnknownField *field, + ProtobufCBuffer *buffer) +{ + uint8_t header[MAX_UINT64_ENCODED_SIZE]; + size_t rv = tag_pack(field->tag, header); + + header[0] |= field->wire_type; + buffer->append(buffer, rv, header); + buffer->append(buffer, field->len, field->data); + return rv + field->len; +} + +/**@}*/ + +size_t +protobuf_c_message_pack_to_buffer(const ProtobufCMessage *message, + ProtobufCBuffer *buffer) +{ + unsigned i; + size_t rv = 0; + + ASSERT_IS_MESSAGE(message); + for (i = 0; i < message->descriptor->n_fields; i++) { + const ProtobufCFieldDescriptor *field = + message->descriptor->fields + i; + const void *member = + ((const char *) message) + field->offset; + const void *qmember = + ((const char *) message) + field->quantifier_offset; + + if (field->label == PROTOBUF_C_LABEL_REQUIRED) { + rv += required_field_pack_to_buffer(field, member, buffer); + } else if ((field->label == PROTOBUF_C_LABEL_OPTIONAL || + field->label == PROTOBUF_C_LABEL_NONE) && + (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF))) { + rv += oneof_field_pack_to_buffer( + field, + *(const uint32_t *) qmember, + member, + buffer + ); + } else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) { + rv += optional_field_pack_to_buffer( + field, + *(const protobuf_c_boolean *) qmember, + member, + buffer + ); + } else if (field->label == PROTOBUF_C_LABEL_NONE) { + rv += unlabeled_field_pack_to_buffer( + field, + member, + buffer + ); + } else { + rv += repeated_field_pack_to_buffer( + field, + *(const size_t *) qmember, + member, + buffer + ); + } + } + for (i = 0; i < message->n_unknown_fields; i++) + rv += unknown_field_pack_to_buffer(&message->unknown_fields[i], buffer); + + return rv; +} + +/** + * \defgroup unpack unpacking implementation + * + * Routines mainly used by the unpacking functions. + * + * \ingroup internal + * @{ + */ + +static inline int +int_range_lookup(unsigned n_ranges, const ProtobufCIntRange *ranges, int value) +{ + unsigned n; + unsigned start; + + if (n_ranges == 0) + return -1; + start = 0; + n = n_ranges; + while (n > 1) { + unsigned mid = start + n / 2; + + if (value < ranges[mid].start_value) { + n = mid - start; + } else if (value >= ranges[mid].start_value + + (int) (ranges[mid + 1].orig_index - + ranges[mid].orig_index)) + { + unsigned new_start = mid + 1; + n = start + n - new_start; + start = new_start; + } else + return (value - ranges[mid].start_value) + + ranges[mid].orig_index; + } + if (n > 0) { + unsigned start_orig_index = ranges[start].orig_index; + unsigned range_size = + ranges[start + 1].orig_index - start_orig_index; + + if (ranges[start].start_value <= value && + value < (int) (ranges[start].start_value + range_size)) + { + return (value - ranges[start].start_value) + + start_orig_index; + } + } + return -1; +} + +static size_t +parse_tag_and_wiretype(size_t len, + const uint8_t *data, + uint32_t *tag_out, + uint8_t *wiretype_out) +{ + unsigned max_rv = len > 5 ? 5 : len; + uint32_t tag = (data[0] & 0x7f) >> 3; + unsigned shift = 4; + unsigned rv; + + /* 0 is not a valid tag value */ + if ((data[0] & 0xf8) == 0) { + return 0; + } + + *wiretype_out = data[0] & 7; + if ((data[0] & 0x80) == 0) { + *tag_out = tag; + return 1; + } + for (rv = 1; rv < max_rv; rv++) { + if (data[rv] & 0x80) { + tag |= (data[rv] & 0x7f) << shift; + shift += 7; + } else { + tag |= data[rv] << shift; + *tag_out = tag; + return rv + 1; + } + } + return 0; /* error: bad header */ +} + +/* sizeof(ScannedMember) must be <= (1UL< INT_MAX) { + // Protobuf messages should always be less than 2 GiB in size. + // We also want to return early here so that hdr_len + val does + // not overflow on 32-bit systems. + PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large", + (unsigned long int)val); + return 0; + } + if (hdr_len + val > len) { + PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu", + (unsigned long int)val); + return 0; + } + return hdr_len + val; +} + +static size_t +max_b128_numbers(size_t len, const uint8_t *data) +{ + size_t rv = 0; + while (len--) + if ((*data++ & 0x80) == 0) + ++rv; + return rv; +} + +/**@}*/ + +/** + * Merge earlier message into a latter message. + * + * For numeric types and strings, if the same value appears multiple + * times, the parser accepts the last value it sees. For embedded + * message fields, the parser merges multiple instances of the same + * field. That is, all singular scalar fields in the latter instance + * replace those in the former, singular embedded messages are merged, + * and repeated fields are concatenated. + * + * The earlier message should be freed after calling this function, as + * some of its fields may have been reused and changed to their default + * values during the merge. + */ +static protobuf_c_boolean +merge_messages(ProtobufCMessage *earlier_msg, + ProtobufCMessage *latter_msg, + ProtobufCAllocator *allocator) +{ + unsigned i; + const ProtobufCFieldDescriptor *fields = + latter_msg->descriptor->fields; + for (i = 0; i < latter_msg->descriptor->n_fields; i++) { + if (fields[i].label == PROTOBUF_C_LABEL_REPEATED) { + size_t *n_earlier = + STRUCT_MEMBER_PTR(size_t, earlier_msg, + fields[i].quantifier_offset); + uint8_t **p_earlier = + STRUCT_MEMBER_PTR(uint8_t *, earlier_msg, + fields[i].offset); + size_t *n_latter = + STRUCT_MEMBER_PTR(size_t, latter_msg, + fields[i].quantifier_offset); + uint8_t **p_latter = + STRUCT_MEMBER_PTR(uint8_t *, latter_msg, + fields[i].offset); + + if (*n_earlier > 0) { + if (*n_latter > 0) { + /* Concatenate the repeated field */ + size_t el_size = + sizeof_elt_in_repeated_array(fields[i].type); + uint8_t *new_field; + + new_field = do_alloc(allocator, + (*n_earlier + *n_latter) * el_size); + if (!new_field) + return FALSE; + + memcpy(new_field, *p_earlier, + *n_earlier * el_size); + memcpy(new_field + + *n_earlier * el_size, + *p_latter, + *n_latter * el_size); + + do_free(allocator, *p_latter); + do_free(allocator, *p_earlier); + *p_latter = new_field; + *n_latter = *n_earlier + *n_latter; + } else { + /* Zero copy the repeated field from the earlier message */ + *n_latter = *n_earlier; + *p_latter = *p_earlier; + } + /* Make sure the field does not get double freed */ + *n_earlier = 0; + *p_earlier = 0; + } + } else if (fields[i].label == PROTOBUF_C_LABEL_OPTIONAL || + fields[i].label == PROTOBUF_C_LABEL_NONE) { + const ProtobufCFieldDescriptor *field; + uint32_t *earlier_case_p = STRUCT_MEMBER_PTR(uint32_t, + earlier_msg, + fields[i]. + quantifier_offset); + uint32_t *latter_case_p = STRUCT_MEMBER_PTR(uint32_t, + latter_msg, + fields[i]. + quantifier_offset); + protobuf_c_boolean need_to_merge = FALSE; + void *earlier_elem; + void *latter_elem; + const void *def_val; + + if (fields[i].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) { + if (*latter_case_p == 0) { + /* lookup correct oneof field */ + int field_index = + int_range_lookup( + latter_msg->descriptor + ->n_field_ranges, + latter_msg->descriptor + ->field_ranges, + *earlier_case_p); + if (field_index < 0) + return FALSE; + field = latter_msg->descriptor->fields + + field_index; + } else { + /* Oneof is present in the latter message, move on */ + continue; + } + } else { + field = &fields[i]; + } + + earlier_elem = STRUCT_MEMBER_P(earlier_msg, field->offset); + latter_elem = STRUCT_MEMBER_P(latter_msg, field->offset); + def_val = field->default_value; + + switch (field->type) { + case PROTOBUF_C_TYPE_MESSAGE: { + ProtobufCMessage *em = *(ProtobufCMessage **) earlier_elem; + ProtobufCMessage *lm = *(ProtobufCMessage **) latter_elem; + if (em != NULL) { + if (lm != NULL) { + if (!merge_messages(em, lm, allocator)) + return FALSE; + /* Already merged */ + need_to_merge = FALSE; + } else { + /* Zero copy the message */ + need_to_merge = TRUE; + } + } + break; + } + case PROTOBUF_C_TYPE_BYTES: { + uint8_t *e_data = + ((ProtobufCBinaryData *) earlier_elem)->data; + uint8_t *l_data = + ((ProtobufCBinaryData *) latter_elem)->data; + const ProtobufCBinaryData *d_bd = + (ProtobufCBinaryData *) def_val; + + need_to_merge = + (e_data != NULL && + (d_bd == NULL || + e_data != d_bd->data)) && + (l_data == NULL || + (d_bd != NULL && + l_data == d_bd->data)); + break; + } + case PROTOBUF_C_TYPE_STRING: { + char *e_str = *(char **) earlier_elem; + char *l_str = *(char **) latter_elem; + const char *d_str = def_val; + + need_to_merge = e_str != d_str && l_str == d_str; + break; + } + default: { + /* Could be has field or case enum, the logic is + * equivalent, since 0 (FALSE) means not set for + * oneof */ + need_to_merge = (*earlier_case_p != 0) && + (*latter_case_p == 0); + break; + } + } + + if (need_to_merge) { + size_t el_size = + sizeof_elt_in_repeated_array(field->type); + memcpy(latter_elem, earlier_elem, el_size); + /* + * Reset the element from the old message to 0 + * to make sure earlier message deallocation + * doesn't corrupt zero-copied data in the new + * message, earlier message will be freed after + * this function is called anyway + */ + memset(earlier_elem, 0, el_size); + + if (field->quantifier_offset != 0) { + /* Set the has field or the case enum, + * if applicable */ + *latter_case_p = *earlier_case_p; + *earlier_case_p = 0; + } + } + } + } + return TRUE; +} + +/** + * Count packed elements. + * + * Given a raw slab of packed-repeated values, determine the number of + * elements. This function detects certain kinds of errors but not + * others; the remaining error checking is done by + * parse_packed_repeated_member(). + */ +static protobuf_c_boolean +count_packed_elements(ProtobufCType type, + size_t len, const uint8_t *data, size_t *count_out) +{ + switch (type) { + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + if (len % 4 != 0) { + PROTOBUF_C_UNPACK_ERROR("length must be a multiple of 4 for fixed-length 32-bit types"); + return FALSE; + } + *count_out = len / 4; + return TRUE; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + if (len % 8 != 0) { + PROTOBUF_C_UNPACK_ERROR("length must be a multiple of 8 for fixed-length 64-bit types"); + return FALSE; + } + *count_out = len / 8; + return TRUE; + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + case PROTOBUF_C_TYPE_SINT32: + case PROTOBUF_C_TYPE_UINT32: + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_SINT64: + case PROTOBUF_C_TYPE_UINT64: + *count_out = max_b128_numbers(len, data); + return TRUE; + case PROTOBUF_C_TYPE_BOOL: + *count_out = len; + return TRUE; + case PROTOBUF_C_TYPE_STRING: + case PROTOBUF_C_TYPE_BYTES: + case PROTOBUF_C_TYPE_MESSAGE: + default: + PROTOBUF_C_UNPACK_ERROR("bad protobuf-c type %u for packed-repeated", type); + return FALSE; + } +} + +static inline uint32_t +parse_uint32(unsigned len, const uint8_t *data) +{ + uint32_t rv = data[0] & 0x7f; + if (len > 1) { + rv |= ((uint32_t) (data[1] & 0x7f) << 7); + if (len > 2) { + rv |= ((uint32_t) (data[2] & 0x7f) << 14); + if (len > 3) { + rv |= ((uint32_t) (data[3] & 0x7f) << 21); + if (len > 4) + rv |= ((uint32_t) (data[4]) << 28); + } + } + } + return rv; +} + +static inline uint32_t +parse_int32(unsigned len, const uint8_t *data) +{ + return parse_uint32(len, data); +} + +static inline int32_t +unzigzag32(uint32_t v) +{ + // Note: Using unsigned types prevents undefined behavior + return (int32_t)((v >> 1) ^ (~(v & 1) + 1)); +} + +static inline uint32_t +parse_fixed_uint32(const uint8_t *data) +{ +#if !defined(WORDS_BIGENDIAN) + uint32_t t; + memcpy(&t, data, 4); + return t; +#else + return data[0] | + ((uint32_t) (data[1]) << 8) | + ((uint32_t) (data[2]) << 16) | + ((uint32_t) (data[3]) << 24); +#endif +} + +static uint64_t +parse_uint64(unsigned len, const uint8_t *data) +{ + unsigned shift, i; + uint64_t rv; + + if (len < 5) + return parse_uint32(len, data); + rv = ((uint64_t) (data[0] & 0x7f)) | + ((uint64_t) (data[1] & 0x7f) << 7) | + ((uint64_t) (data[2] & 0x7f) << 14) | + ((uint64_t) (data[3] & 0x7f) << 21); + shift = 28; + for (i = 4; i < len; i++) { + rv |= (((uint64_t) (data[i] & 0x7f)) << shift); + shift += 7; + } + return rv; +} + +static inline int64_t +unzigzag64(uint64_t v) +{ + // Note: Using unsigned types prevents undefined behavior + return (int64_t)((v >> 1) ^ (~(v & 1) + 1)); +} + +static inline uint64_t +parse_fixed_uint64(const uint8_t *data) +{ +#if !defined(WORDS_BIGENDIAN) + uint64_t t; + memcpy(&t, data, 8); + return t; +#else + return (uint64_t) parse_fixed_uint32(data) | + (((uint64_t) parse_fixed_uint32(data + 4)) << 32); +#endif +} + +static protobuf_c_boolean +parse_boolean(unsigned len, const uint8_t *data) +{ + unsigned i; + for (i = 0; i < len; i++) + if (data[i] & 0x7f) + return TRUE; + return FALSE; +} + +static protobuf_c_boolean +parse_required_member(ScannedMember *scanned_member, + void *member, + ProtobufCAllocator *allocator, + protobuf_c_boolean maybe_clear) +{ + unsigned len = scanned_member->len; + const uint8_t *data = scanned_member->data; + uint8_t wire_type = scanned_member->wire_type; + + switch (scanned_member->field->type) { + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) + return FALSE; + *(int32_t *) member = parse_int32(len, data); + return TRUE; + case PROTOBUF_C_TYPE_UINT32: + if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) + return FALSE; + *(uint32_t *) member = parse_uint32(len, data); + return TRUE; + case PROTOBUF_C_TYPE_SINT32: + if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) + return FALSE; + *(int32_t *) member = unzigzag32(parse_uint32(len, data)); + return TRUE; + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT) + return FALSE; + *(uint32_t *) member = parse_fixed_uint32(data); + return TRUE; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) + return FALSE; + *(uint64_t *) member = parse_uint64(len, data); + return TRUE; + case PROTOBUF_C_TYPE_SINT64: + if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) + return FALSE; + *(int64_t *) member = unzigzag64(parse_uint64(len, data)); + return TRUE; + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT) + return FALSE; + *(uint64_t *) member = parse_fixed_uint64(data); + return TRUE; + case PROTOBUF_C_TYPE_BOOL: + *(protobuf_c_boolean *) member = parse_boolean(len, data); + return TRUE; + case PROTOBUF_C_TYPE_STRING: { + char **pstr = member; + unsigned pref_len = scanned_member->length_prefix_len; + + if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) + return FALSE; + + if (maybe_clear && *pstr != NULL) { + const char *def = scanned_member->field->default_value; + if (*pstr != NULL && *pstr != def) + do_free(allocator, *pstr); + } + *pstr = do_alloc(allocator, len - pref_len + 1); + if (*pstr == NULL) + return FALSE; + memcpy(*pstr, data + pref_len, len - pref_len); + (*pstr)[len - pref_len] = 0; + return TRUE; + } + case PROTOBUF_C_TYPE_BYTES: { + ProtobufCBinaryData *bd = member; + const ProtobufCBinaryData *def_bd; + unsigned pref_len = scanned_member->length_prefix_len; + + if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) + return FALSE; + + def_bd = scanned_member->field->default_value; + if (maybe_clear && + bd->data != NULL && + (def_bd == NULL || bd->data != def_bd->data)) + { + do_free(allocator, bd->data); + } + if (len > pref_len) { + bd->data = do_alloc(allocator, len - pref_len); + if (bd->data == NULL) + return FALSE; + memcpy(bd->data, data + pref_len, len - pref_len); + } else { + bd->data = NULL; + } + bd->len = len - pref_len; + return TRUE; + } + case PROTOBUF_C_TYPE_MESSAGE: { + ProtobufCMessage **pmessage = member; + ProtobufCMessage *subm; + const ProtobufCMessage *def_mess; + protobuf_c_boolean merge_successful = TRUE; + unsigned pref_len = scanned_member->length_prefix_len; + + if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) + return FALSE; + + def_mess = scanned_member->field->default_value; + subm = protobuf_c_message_unpack(scanned_member->field->descriptor, + allocator, + len - pref_len, + data + pref_len); + + if (maybe_clear && + *pmessage != NULL && + *pmessage != def_mess) + { + if (subm != NULL) + merge_successful = merge_messages(*pmessage, subm, allocator); + /* Delete the previous message */ + protobuf_c_message_free_unpacked(*pmessage, allocator); + } + *pmessage = subm; + if (subm == NULL || !merge_successful) + return FALSE; + return TRUE; + } + } + return FALSE; +} + +static protobuf_c_boolean +parse_oneof_member (ScannedMember *scanned_member, + void *member, + ProtobufCMessage *message, + ProtobufCAllocator *allocator) +{ + uint32_t *oneof_case = STRUCT_MEMBER_PTR(uint32_t, message, + scanned_member->field->quantifier_offset); + + /* If we have already parsed a member of this oneof, free it. */ + if (*oneof_case != 0) { + const ProtobufCFieldDescriptor *old_field; + size_t el_size; + /* lookup field */ + int field_index = + int_range_lookup(message->descriptor->n_field_ranges, + message->descriptor->field_ranges, + *oneof_case); + if (field_index < 0) + return FALSE; + old_field = message->descriptor->fields + field_index; + el_size = sizeof_elt_in_repeated_array(old_field->type); + + switch (old_field->type) { + case PROTOBUF_C_TYPE_STRING: { + char **pstr = member; + const char *def = old_field->default_value; + if (*pstr != NULL && *pstr != def) + do_free(allocator, *pstr); + break; + } + case PROTOBUF_C_TYPE_BYTES: { + ProtobufCBinaryData *bd = member; + const ProtobufCBinaryData *def_bd = old_field->default_value; + if (bd->data != NULL && + (def_bd == NULL || bd->data != def_bd->data)) + { + do_free(allocator, bd->data); + } + break; + } + case PROTOBUF_C_TYPE_MESSAGE: { + ProtobufCMessage **pmessage = member; + const ProtobufCMessage *def_mess = old_field->default_value; + if (*pmessage != NULL && *pmessage != def_mess) + protobuf_c_message_free_unpacked(*pmessage, allocator); + break; + } + default: + break; + } + + memset (member, 0, el_size); + } + if (!parse_required_member (scanned_member, member, allocator, TRUE)) + return FALSE; + + *oneof_case = scanned_member->tag; + return TRUE; +} + + +static protobuf_c_boolean +parse_optional_member(ScannedMember *scanned_member, + void *member, + ProtobufCMessage *message, + ProtobufCAllocator *allocator) +{ + if (!parse_required_member(scanned_member, member, allocator, TRUE)) + return FALSE; + if (scanned_member->field->quantifier_offset != 0) + STRUCT_MEMBER(protobuf_c_boolean, + message, + scanned_member->field->quantifier_offset) = TRUE; + return TRUE; +} + +static protobuf_c_boolean +parse_repeated_member(ScannedMember *scanned_member, + void *member, + ProtobufCMessage *message, + ProtobufCAllocator *allocator) +{ + const ProtobufCFieldDescriptor *field = scanned_member->field; + size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset); + size_t siz = sizeof_elt_in_repeated_array(field->type); + char *array = *(char **) member; + + if (!parse_required_member(scanned_member, array + siz * (*p_n), + allocator, FALSE)) + { + return FALSE; + } + *p_n += 1; + return TRUE; +} + +static unsigned +scan_varint(unsigned len, const uint8_t *data) +{ + unsigned i; + if (len > 10) + len = 10; + for (i = 0; i < len; i++) + if ((data[i] & 0x80) == 0) + break; + if (i == len) + return 0; + return i + 1; +} + +static protobuf_c_boolean +parse_packed_repeated_member(ScannedMember *scanned_member, + void *member, + ProtobufCMessage *message) +{ + const ProtobufCFieldDescriptor *field = scanned_member->field; + size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset); + size_t siz = sizeof_elt_in_repeated_array(field->type); + void *array = *(char **) member + siz * (*p_n); + const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len; + size_t rem = scanned_member->len - scanned_member->length_prefix_len; + size_t count = 0; +#if defined(WORDS_BIGENDIAN) + unsigned i; +#endif + + switch (field->type) { + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + count = (scanned_member->len - scanned_member->length_prefix_len) / 4; +#if !defined(WORDS_BIGENDIAN) + goto no_unpacking_needed; +#else + for (i = 0; i < count; i++) { + ((uint32_t *) array)[i] = parse_fixed_uint32(at); + at += 4; + } + break; +#endif + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + count = (scanned_member->len - scanned_member->length_prefix_len) / 8; +#if !defined(WORDS_BIGENDIAN) + goto no_unpacking_needed; +#else + for (i = 0; i < count; i++) { + ((uint64_t *) array)[i] = parse_fixed_uint64(at); + at += 8; + } + break; +#endif + case PROTOBUF_C_TYPE_ENUM: + case PROTOBUF_C_TYPE_INT32: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int32 value"); + return FALSE; + } + ((int32_t *) array)[count++] = parse_int32(s, at); + at += s; + rem -= s; + } + break; + case PROTOBUF_C_TYPE_SINT32: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint32 value"); + return FALSE; + } + ((int32_t *) array)[count++] = unzigzag32(parse_uint32(s, at)); + at += s; + rem -= s; + } + break; + case PROTOBUF_C_TYPE_UINT32: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated enum or uint32 value"); + return FALSE; + } + ((uint32_t *) array)[count++] = parse_uint32(s, at); + at += s; + rem -= s; + } + break; + + case PROTOBUF_C_TYPE_SINT64: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint64 value"); + return FALSE; + } + ((int64_t *) array)[count++] = unzigzag64(parse_uint64(s, at)); + at += s; + rem -= s; + } + break; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_UINT64: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int64/uint64 value"); + return FALSE; + } + ((int64_t *) array)[count++] = parse_uint64(s, at); + at += s; + rem -= s; + } + break; + case PROTOBUF_C_TYPE_BOOL: + while (rem > 0) { + unsigned s = scan_varint(rem, at); + if (s == 0) { + PROTOBUF_C_UNPACK_ERROR("bad packed-repeated boolean value"); + return FALSE; + } + ((protobuf_c_boolean *) array)[count++] = parse_boolean(s, at); + at += s; + rem -= s; + } + break; + default: + PROTOBUF_C__ASSERT_NOT_REACHED(); + } + *p_n += count; + return TRUE; + +#if !defined(WORDS_BIGENDIAN) +no_unpacking_needed: + memcpy(array, at, count * siz); + *p_n += count; + return TRUE; +#endif +} + +static protobuf_c_boolean +is_packable_type(ProtobufCType type) +{ + return + type != PROTOBUF_C_TYPE_STRING && + type != PROTOBUF_C_TYPE_BYTES && + type != PROTOBUF_C_TYPE_MESSAGE; +} + +static protobuf_c_boolean +parse_member(ScannedMember *scanned_member, + ProtobufCMessage *message, + ProtobufCAllocator *allocator) +{ + const ProtobufCFieldDescriptor *field = scanned_member->field; + void *member; + + if (field == NULL) { + ProtobufCMessageUnknownField *ufield = + message->unknown_fields + + (message->n_unknown_fields++); + ufield->tag = scanned_member->tag; + ufield->wire_type = scanned_member->wire_type; + ufield->len = scanned_member->len; + ufield->data = do_alloc(allocator, scanned_member->len); + if (ufield->data == NULL) + return FALSE; + memcpy(ufield->data, scanned_member->data, ufield->len); + return TRUE; + } + member = (char *) message + field->offset; + switch (field->label) { + case PROTOBUF_C_LABEL_REQUIRED: + return parse_required_member(scanned_member, member, + allocator, TRUE); + case PROTOBUF_C_LABEL_OPTIONAL: + case PROTOBUF_C_LABEL_NONE: + if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) { + return parse_oneof_member(scanned_member, member, + message, allocator); + } else { + return parse_optional_member(scanned_member, member, + message, allocator); + } + case PROTOBUF_C_LABEL_REPEATED: + if (scanned_member->wire_type == + PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED && + (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) || + is_packable_type(field->type))) + { + return parse_packed_repeated_member(scanned_member, + member, message); + } else { + return parse_repeated_member(scanned_member, + member, message, + allocator); + } + } + PROTOBUF_C__ASSERT_NOT_REACHED(); + return 0; +} + +/** + * Initialise messages generated by old code. + * + * This function is used if desc->message_init == NULL (which occurs + * for old code, and which would be useful to support allocating + * descriptors dynamically). + */ +static void +message_init_generic(const ProtobufCMessageDescriptor *desc, + ProtobufCMessage *message) +{ + unsigned i; + + memset(message, 0, desc->sizeof_message); + message->descriptor = desc; + for (i = 0; i < desc->n_fields; i++) { + if (desc->fields[i].default_value != NULL && + desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED) + { + void *field = + STRUCT_MEMBER_P(message, desc->fields[i].offset); + const void *dv = desc->fields[i].default_value; + + switch (desc->fields[i].type) { + case PROTOBUF_C_TYPE_INT32: + case PROTOBUF_C_TYPE_SINT32: + case PROTOBUF_C_TYPE_SFIXED32: + case PROTOBUF_C_TYPE_UINT32: + case PROTOBUF_C_TYPE_FIXED32: + case PROTOBUF_C_TYPE_FLOAT: + case PROTOBUF_C_TYPE_ENUM: + memcpy(field, dv, 4); + break; + case PROTOBUF_C_TYPE_INT64: + case PROTOBUF_C_TYPE_SINT64: + case PROTOBUF_C_TYPE_SFIXED64: + case PROTOBUF_C_TYPE_UINT64: + case PROTOBUF_C_TYPE_FIXED64: + case PROTOBUF_C_TYPE_DOUBLE: + memcpy(field, dv, 8); + break; + case PROTOBUF_C_TYPE_BOOL: + memcpy(field, dv, sizeof(protobuf_c_boolean)); + break; + case PROTOBUF_C_TYPE_BYTES: + memcpy(field, dv, sizeof(ProtobufCBinaryData)); + break; + + case PROTOBUF_C_TYPE_STRING: + case PROTOBUF_C_TYPE_MESSAGE: + /* + * The next line essentially implements a cast + * from const, which is totally unavoidable. + */ + *(const void **) field = dv; + break; + } + } + } +} + +/**@}*/ + +/* + * ScannedMember slabs (an unpacking implementation detail). Before doing real + * unpacking, we first scan through the elements to see how many there are (for + * repeated fields), and which field to use (for non-repeated fields given + * twice). + * + * In order to avoid allocations for small messages, we keep a stack-allocated + * slab of ScannedMembers of size FIRST_SCANNED_MEMBER_SLAB_SIZE (16). After we + * fill that up, we allocate each slab twice as large as the previous one. + */ +#define FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2 4 + +/* + * The number of slabs, including the stack-allocated ones; choose the number so + * that we would overflow if we needed a slab larger than provided. + */ +#define MAX_SCANNED_MEMBER_SLAB \ + (sizeof(unsigned int)*8 - 1 \ + - BOUND_SIZEOF_SCANNED_MEMBER_LOG2 \ + - FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2) + +#define REQUIRED_FIELD_BITMAP_SET(index) \ + (required_fields_bitmap[(index)/8] |= (1UL<<((index)%8))) + +#define REQUIRED_FIELD_BITMAP_IS_SET(index) \ + (required_fields_bitmap[(index)/8] & (1UL<<((index)%8))) + +ProtobufCMessage * +protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc, + ProtobufCAllocator *allocator, + size_t len, const uint8_t *data) +{ + ProtobufCMessage *rv; + size_t rem = len; + const uint8_t *at = data; + const ProtobufCFieldDescriptor *last_field = desc->fields + 0; + ScannedMember first_member_slab[1UL << + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2]; + + /* + * scanned_member_slabs[i] is an array of arrays of ScannedMember. + * The first slab (scanned_member_slabs[0] is just a pointer to + * first_member_slab), above. All subsequent slabs will be allocated + * using the allocator. + */ + ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB + 1]; + unsigned which_slab = 0; /* the slab we are currently populating */ + unsigned in_slab_index = 0; /* number of members in the slab */ + size_t n_unknown = 0; + unsigned f; + unsigned j; + unsigned i_slab; + unsigned last_field_index = 0; + unsigned required_fields_bitmap_len; + unsigned char required_fields_bitmap_stack[16]; + unsigned char *required_fields_bitmap = required_fields_bitmap_stack; + protobuf_c_boolean required_fields_bitmap_alloced = FALSE; + + ASSERT_IS_MESSAGE_DESCRIPTOR(desc); + + if (allocator == NULL) + allocator = &protobuf_c__allocator; + + rv = do_alloc(allocator, desc->sizeof_message); + if (!rv) + return (NULL); + scanned_member_slabs[0] = first_member_slab; + + required_fields_bitmap_len = (desc->n_fields + 7) / 8; + if (required_fields_bitmap_len > sizeof(required_fields_bitmap_stack)) { + required_fields_bitmap = do_alloc(allocator, required_fields_bitmap_len); + if (!required_fields_bitmap) { + do_free(allocator, rv); + return (NULL); + } + required_fields_bitmap_alloced = TRUE; + } + memset(required_fields_bitmap, 0, required_fields_bitmap_len); + + /* + * Generated code always defines "message_init". However, we provide a + * fallback for (1) users of old protobuf-c generated-code that do not + * provide the function, and (2) descriptors constructed from some other + * source (most likely, direct construction from the .proto file). + */ + if (desc->message_init != NULL) + protobuf_c_message_init(desc, rv); + else + message_init_generic(desc, rv); + + while (rem > 0) { + uint32_t tag; + uint8_t wire_type; + size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type); + const ProtobufCFieldDescriptor *field; + ScannedMember tmp; + + if (used == 0) { + PROTOBUF_C_UNPACK_ERROR("error parsing tag/wiretype at offset %u", + (unsigned) (at - data)); + goto error_cleanup_during_scan; + } + /* + * \todo Consider optimizing for field[1].id == tag, if field[1] + * exists! + */ + if (last_field == NULL || last_field->id != tag) { + /* lookup field */ + int field_index = + int_range_lookup(desc->n_field_ranges, + desc->field_ranges, + tag); + if (field_index < 0) { + field = NULL; + n_unknown++; + } else { + field = desc->fields + field_index; + last_field = field; + last_field_index = field_index; + } + } else { + field = last_field; + } + + if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED) + REQUIRED_FIELD_BITMAP_SET(last_field_index); + + at += used; + rem -= used; + tmp.tag = tag; + tmp.wire_type = wire_type; + tmp.field = field; + tmp.data = at; + tmp.length_prefix_len = 0; + + switch (wire_type) { + case PROTOBUF_C_WIRE_TYPE_VARINT: { + unsigned max_len = rem < 10 ? rem : 10; + unsigned i; + + for (i = 0; i < max_len; i++) + if ((at[i] & 0x80) == 0) + break; + if (i == max_len) { + PROTOBUF_C_UNPACK_ERROR("unterminated varint at offset %u", + (unsigned) (at - data)); + goto error_cleanup_during_scan; + } + tmp.len = i + 1; + break; + } + case PROTOBUF_C_WIRE_TYPE_64BIT: + if (rem < 8) { + PROTOBUF_C_UNPACK_ERROR("too short after 64bit wiretype at offset %u", + (unsigned) (at - data)); + goto error_cleanup_during_scan; + } + tmp.len = 8; + break; + case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED: { + size_t pref_len; + + tmp.len = scan_length_prefixed_data(rem, at, &pref_len); + if (tmp.len == 0) { + /* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */ + goto error_cleanup_during_scan; + } + tmp.length_prefix_len = pref_len; + break; + } + case PROTOBUF_C_WIRE_TYPE_32BIT: + if (rem < 4) { + PROTOBUF_C_UNPACK_ERROR("too short after 32bit wiretype at offset %u", + (unsigned) (at - data)); + goto error_cleanup_during_scan; + } + tmp.len = 4; + break; + default: + PROTOBUF_C_UNPACK_ERROR("unsupported tag %u at offset %u", + wire_type, (unsigned) (at - data)); + goto error_cleanup_during_scan; + } + + if (in_slab_index == (1UL << + (which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2))) + { + size_t size; + + in_slab_index = 0; + if (which_slab == MAX_SCANNED_MEMBER_SLAB) { + PROTOBUF_C_UNPACK_ERROR("too many fields"); + goto error_cleanup_during_scan; + } + which_slab++; + size = sizeof(ScannedMember) + << (which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2); + scanned_member_slabs[which_slab] = do_alloc(allocator, size); + if (scanned_member_slabs[which_slab] == NULL) + goto error_cleanup_during_scan; + } + scanned_member_slabs[which_slab][in_slab_index++] = tmp; + + if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED) { + size_t *n = STRUCT_MEMBER_PTR(size_t, rv, + field->quantifier_offset); + if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED && + (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) || + is_packable_type(field->type))) + { + size_t count; + if (!count_packed_elements(field->type, + tmp.len - + tmp.length_prefix_len, + tmp.data + + tmp.length_prefix_len, + &count)) + { + PROTOBUF_C_UNPACK_ERROR("counting packed elements"); + goto error_cleanup_during_scan; + } + *n += count; + } else { + *n += 1; + } + } + + at += tmp.len; + rem -= tmp.len; + } + + /* allocate space for repeated fields, also check that all required fields have been set */ + for (f = 0; f < desc->n_fields; f++) { + const ProtobufCFieldDescriptor *field = desc->fields + f; + if (field->label == PROTOBUF_C_LABEL_REPEATED) { + size_t siz = + sizeof_elt_in_repeated_array(field->type); + size_t *n_ptr = + STRUCT_MEMBER_PTR(size_t, rv, + field->quantifier_offset); + if (*n_ptr != 0) { + unsigned n = *n_ptr; + void *a; + *n_ptr = 0; + assert(rv->descriptor != NULL); +#define CLEAR_REMAINING_N_PTRS() \ + for(f++;f < desc->n_fields; f++) \ + { \ + field = desc->fields + f; \ + if (field->label == PROTOBUF_C_LABEL_REPEATED) \ + STRUCT_MEMBER (size_t, rv, field->quantifier_offset) = 0; \ + } + a = do_alloc(allocator, siz * n); + if (!a) { + CLEAR_REMAINING_N_PTRS(); + goto error_cleanup; + } + STRUCT_MEMBER(void *, rv, field->offset) = a; + } + } else if (field->label == PROTOBUF_C_LABEL_REQUIRED) { + if (field->default_value == NULL && + !REQUIRED_FIELD_BITMAP_IS_SET(f)) + { + CLEAR_REMAINING_N_PTRS(); + PROTOBUF_C_UNPACK_ERROR("message '%s': missing required field '%s'", + desc->name, field->name); + goto error_cleanup; + } + } + } +#undef CLEAR_REMAINING_N_PTRS + + /* allocate space for unknown fields */ + if (n_unknown) { + rv->unknown_fields = do_alloc(allocator, + n_unknown * sizeof(ProtobufCMessageUnknownField)); + if (rv->unknown_fields == NULL) + goto error_cleanup; + } + + /* do real parsing */ + for (i_slab = 0; i_slab <= which_slab; i_slab++) { + unsigned max = (i_slab == which_slab) ? + in_slab_index : (1UL << (i_slab + 4)); + ScannedMember *slab = scanned_member_slabs[i_slab]; + + for (j = 0; j < max; j++) { + if (!parse_member(slab + j, rv, allocator)) { + PROTOBUF_C_UNPACK_ERROR("error parsing member %s of %s", + slab->field ? slab->field->name : "*unknown-field*", + desc->name); + goto error_cleanup; + } + } + } + + /* cleanup */ + for (j = 1; j <= which_slab; j++) + do_free(allocator, scanned_member_slabs[j]); + if (required_fields_bitmap_alloced) + do_free(allocator, required_fields_bitmap); + return rv; + +error_cleanup: + protobuf_c_message_free_unpacked(rv, allocator); + for (j = 1; j <= which_slab; j++) + do_free(allocator, scanned_member_slabs[j]); + if (required_fields_bitmap_alloced) + do_free(allocator, required_fields_bitmap); + return NULL; + +error_cleanup_during_scan: + do_free(allocator, rv); + for (j = 1; j <= which_slab; j++) + do_free(allocator, scanned_member_slabs[j]); + if (required_fields_bitmap_alloced) + do_free(allocator, required_fields_bitmap); + return NULL; +} + +void +protobuf_c_message_free_unpacked(ProtobufCMessage *message, + ProtobufCAllocator *allocator) +{ + const ProtobufCMessageDescriptor *desc; + unsigned f; + + if (message == NULL) + return; + + desc = message->descriptor; + + ASSERT_IS_MESSAGE(message); + + if (allocator == NULL) + allocator = &protobuf_c__allocator; + message->descriptor = NULL; + for (f = 0; f < desc->n_fields; f++) { + if (0 != (desc->fields[f].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) && + desc->fields[f].id != + STRUCT_MEMBER(uint32_t, message, desc->fields[f].quantifier_offset)) + { + /* This is not the selected oneof, skip it */ + continue; + } + + if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED) { + size_t n = STRUCT_MEMBER(size_t, + message, + desc->fields[f].quantifier_offset); + void *arr = STRUCT_MEMBER(void *, + message, + desc->fields[f].offset); + + if (arr != NULL) { + if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) { + unsigned i; + for (i = 0; i < n; i++) + do_free(allocator, ((char **) arr)[i]); + } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) { + unsigned i; + for (i = 0; i < n; i++) + do_free(allocator, ((ProtobufCBinaryData *) arr)[i].data); + } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) { + unsigned i; + for (i = 0; i < n; i++) + protobuf_c_message_free_unpacked( + ((ProtobufCMessage **) arr)[i], + allocator + ); + } + do_free(allocator, arr); + } + } else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) { + char *str = STRUCT_MEMBER(char *, message, + desc->fields[f].offset); + + if (str && str != desc->fields[f].default_value) + do_free(allocator, str); + } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) { + void *data = STRUCT_MEMBER(ProtobufCBinaryData, message, + desc->fields[f].offset).data; + const ProtobufCBinaryData *default_bd; + + default_bd = desc->fields[f].default_value; + if (data != NULL && + (default_bd == NULL || + default_bd->data != data)) + { + do_free(allocator, data); + } + } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) { + ProtobufCMessage *sm; + + sm = STRUCT_MEMBER(ProtobufCMessage *, message, + desc->fields[f].offset); + if (sm && sm != desc->fields[f].default_value) + protobuf_c_message_free_unpacked(sm, allocator); + } + } + + for (f = 0; f < message->n_unknown_fields; f++) + do_free(allocator, message->unknown_fields[f].data); + if (message->unknown_fields != NULL) + do_free(allocator, message->unknown_fields); + + do_free(allocator, message); +} + +void +protobuf_c_message_init(const ProtobufCMessageDescriptor * descriptor, + void *message) +{ + descriptor->message_init((ProtobufCMessage *) (message)); +} + +protobuf_c_boolean +protobuf_c_message_check(const ProtobufCMessage *message) +{ + unsigned i; + + if (!message || + !message->descriptor || + message->descriptor->magic != PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC) + { + return FALSE; + } + + for (i = 0; i < message->descriptor->n_fields; i++) { + const ProtobufCFieldDescriptor *f = message->descriptor->fields + i; + ProtobufCType type = f->type; + ProtobufCLabel label = f->label; + void *field = STRUCT_MEMBER_P (message, f->offset); + + if (f->flags & PROTOBUF_C_FIELD_FLAG_ONEOF) { + const uint32_t *oneof_case = STRUCT_MEMBER_P (message, f->quantifier_offset); + if (f->id != *oneof_case) { + continue; //Do not check if it is an unpopulated oneof member. + } + } + + if (label == PROTOBUF_C_LABEL_REPEATED) { + size_t *quantity = STRUCT_MEMBER_P (message, f->quantifier_offset); + + if (*quantity > 0 && *(void **) field == NULL) { + return FALSE; + } + + if (type == PROTOBUF_C_TYPE_MESSAGE) { + ProtobufCMessage **submessage = *(ProtobufCMessage ***) field; + unsigned j; + for (j = 0; j < *quantity; j++) { + if (!protobuf_c_message_check(submessage[j])) + return FALSE; + } + } else if (type == PROTOBUF_C_TYPE_STRING) { + char **string = *(char ***) field; + unsigned j; + for (j = 0; j < *quantity; j++) { + if (!string[j]) + return FALSE; + } + } else if (type == PROTOBUF_C_TYPE_BYTES) { + ProtobufCBinaryData *bd = *(ProtobufCBinaryData **) field; + unsigned j; + for (j = 0; j < *quantity; j++) { + if (bd[j].len > 0 && bd[j].data == NULL) + return FALSE; + } + } + + } else { /* PROTOBUF_C_LABEL_REQUIRED or PROTOBUF_C_LABEL_OPTIONAL */ + + if (type == PROTOBUF_C_TYPE_MESSAGE) { + ProtobufCMessage *submessage = *(ProtobufCMessage **) field; + if (label == PROTOBUF_C_LABEL_REQUIRED || submessage != NULL) { + if (!protobuf_c_message_check(submessage)) + return FALSE; + } + } else if (type == PROTOBUF_C_TYPE_STRING) { + char *string = *(char **) field; + if (label == PROTOBUF_C_LABEL_REQUIRED && string == NULL) + return FALSE; + } else if (type == PROTOBUF_C_TYPE_BYTES) { + protobuf_c_boolean *has = STRUCT_MEMBER_P (message, f->quantifier_offset); + ProtobufCBinaryData *bd = field; + if (label == PROTOBUF_C_LABEL_REQUIRED || *has == TRUE) { + if (bd->len > 0 && bd->data == NULL) + return FALSE; + } + } + } + } + + return TRUE; +} + +/* === services === */ + +typedef void (*GenericHandler) (void *service, + const ProtobufCMessage *input, + ProtobufCClosure closure, + void *closure_data); +void +protobuf_c_service_invoke_internal(ProtobufCService *service, + unsigned method_index, + const ProtobufCMessage *input, + ProtobufCClosure closure, + void *closure_data) +{ + GenericHandler *handlers; + GenericHandler handler; + + /* + * Verify that method_index is within range. If this fails, you are + * likely invoking a newly added method on an old service. (Although + * other memory corruption bugs can cause this assertion too.) + */ + assert(method_index < service->descriptor->n_methods); + + /* + * Get the array of virtual methods (which are enumerated by the + * generated code). + */ + handlers = (GenericHandler *) (service + 1); + + /* + * Get our method and invoke it. + * \todo Seems like handler == NULL is a situation that needs handling. + */ + handler = handlers[method_index]; + (*handler)(service, input, closure, closure_data); +} + +void +protobuf_c_service_generated_init(ProtobufCService *service, + const ProtobufCServiceDescriptor *descriptor, + ProtobufCServiceDestroy destroy) +{ + ASSERT_IS_SERVICE_DESCRIPTOR(descriptor); + service->descriptor = descriptor; + service->destroy = destroy; + service->invoke = protobuf_c_service_invoke_internal; + memset(service + 1, 0, descriptor->n_methods * sizeof(GenericHandler)); +} + +void protobuf_c_service_destroy(ProtobufCService *service) +{ + service->destroy(service); +} + +/* --- querying the descriptors --- */ + +const ProtobufCEnumValue * +protobuf_c_enum_descriptor_get_value_by_name(const ProtobufCEnumDescriptor *desc, + const char *name) +{ + unsigned start = 0; + unsigned count; + + if (desc == NULL || desc->values_by_name == NULL) + return NULL; + + count = desc->n_value_names; + + while (count > 1) { + unsigned mid = start + count / 2; + int rv = strcmp(desc->values_by_name[mid].name, name); + if (rv == 0) + return desc->values + desc->values_by_name[mid].index; + else if (rv < 0) { + count = start + count - (mid + 1); + start = mid + 1; + } else + count = mid - start; + } + if (count == 0) + return NULL; + if (strcmp(desc->values_by_name[start].name, name) == 0) + return desc->values + desc->values_by_name[start].index; + return NULL; +} + +const ProtobufCEnumValue * +protobuf_c_enum_descriptor_get_value(const ProtobufCEnumDescriptor *desc, + int value) +{ + int rv = int_range_lookup(desc->n_value_ranges, desc->value_ranges, value); + if (rv < 0) + return NULL; + return desc->values + rv; +} + +const ProtobufCFieldDescriptor * +protobuf_c_message_descriptor_get_field_by_name(const ProtobufCMessageDescriptor *desc, + const char *name) +{ + unsigned start = 0; + unsigned count; + const ProtobufCFieldDescriptor *field; + + if (desc == NULL || desc->fields_sorted_by_name == NULL) + return NULL; + + count = desc->n_fields; + + while (count > 1) { + unsigned mid = start + count / 2; + int rv; + field = desc->fields + desc->fields_sorted_by_name[mid]; + rv = strcmp(field->name, name); + if (rv == 0) + return field; + else if (rv < 0) { + count = start + count - (mid + 1); + start = mid + 1; + } else + count = mid - start; + } + if (count == 0) + return NULL; + field = desc->fields + desc->fields_sorted_by_name[start]; + if (strcmp(field->name, name) == 0) + return field; + return NULL; +} + +const ProtobufCFieldDescriptor * +protobuf_c_message_descriptor_get_field(const ProtobufCMessageDescriptor *desc, + unsigned value) +{ + int rv = int_range_lookup(desc->n_field_ranges,desc->field_ranges, value); + if (rv < 0) + return NULL; + return desc->fields + rv; +} + +const ProtobufCMethodDescriptor * +protobuf_c_service_descriptor_get_method_by_name(const ProtobufCServiceDescriptor *desc, + const char *name) +{ + unsigned start = 0; + unsigned count; + + if (desc == NULL || desc->method_indices_by_name == NULL) + return NULL; + + count = desc->n_methods; + + while (count > 1) { + unsigned mid = start + count / 2; + unsigned mid_index = desc->method_indices_by_name[mid]; + const char *mid_name = desc->methods[mid_index].name; + int rv = strcmp(mid_name, name); + + if (rv == 0) + return desc->methods + desc->method_indices_by_name[mid]; + if (rv < 0) { + count = start + count - (mid + 1); + start = mid + 1; + } else { + count = mid - start; + } + } + if (count == 0) + return NULL; + if (strcmp(desc->methods[desc->method_indices_by_name[start]].name, name) == 0) + return desc->methods + desc->method_indices_by_name[start]; + return NULL; +} \ No newline at end of file diff --git a/c/vendor/protobuf-c/protobuf-c.h b/c/vendor/protobuf-c/protobuf-c.h new file mode 100644 index 0000000..5df7e9b --- /dev/null +++ b/c/vendor/protobuf-c/protobuf-c.h @@ -0,0 +1,1110 @@ +/* + * Copyright (c) 2008-2018, Dave Benson and the protobuf-c authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + */ + +/*! \file + * \mainpage Introduction + * + * This is [protobuf-c], a C implementation of [Protocol Buffers]. + * + * This file defines the public API for the `libprotobuf-c` support library. + * This API includes interfaces that can be used directly by client code as well + * as the interfaces used by the code generated by the `protoc-c` compiler. + * + * The `libprotobuf-c` support library performs the actual serialization and + * deserialization of Protocol Buffers messages. It interacts with structures, + * definitions, and metadata generated by the `protoc-c` compiler from .proto + * files. + * + * \authors Dave Benson and the `protobuf-c` authors. + * + * \copyright 2008-2014. Licensed under the terms of the [BSD-2-Clause] license. + * + * [protobuf-c]: https://github.com/protobuf-c/protobuf-c + * [Protocol Buffers]: https://developers.google.com/protocol-buffers/ + * [BSD-2-Clause]: http://opensource.org/licenses/BSD-2-Clause + * + * \page gencode Generated Code + * + * For each enum, we generate a C enum. For each message, we generate a C + * structure which can be cast to a `ProtobufCMessage`. + * + * For each enum and message, we generate a descriptor object that allows us to + * implement a kind of reflection on the structures. + * + * First, some naming conventions: + * + * - The name of the type for enums and messages and services is camel case + * (meaning WordsAreCrammedTogether) except that double underscores are used + * to delimit scopes. For example, the following `.proto` file: + * +~~~{.proto} + package foo.bar; + message BazBah { + optional int32 val = 1; + } +~~~ + * + * would generate a C type `Foo__Bar__BazBah`. + * + * - Identifiers for functions and globals are all lowercase, with camel case + * words separated by single underscores. For example, one of the function + * prototypes generated by `protoc-c` for the above example: + * +~~~{.c} +Foo__Bar__BazBah * + foo__bar__baz_bah__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +~~~ + * + * - Identifiers for enum values contain an uppercase prefix which embeds the + * package name and the enum type name. + * + * - A double underscore is used to separate further components of identifier + * names. + * + * For example, in the name of the unpack function above, the package name + * `foo.bar` has become `foo__bar`, the message name BazBah has become + * `baz_bah`, and the method name is `unpack`. These are all joined with double + * underscores to form the C identifier `foo__bar__baz_bah__unpack`. + * + * We also generate descriptor objects for messages and enums. These are + * declared in the `.pb-c.h` files: + * +~~~{.c} +extern const ProtobufCMessageDescriptor foo__bar__baz_bah__descriptor; +~~~ + * + * The message structures all begin with `ProtobufCMessageDescriptor *` which is + * sufficient to allow them to be cast to `ProtobufCMessage`. + * + * For each message defined in a `.proto` file, we generate a number of + * functions and macros. Each function name contains a prefix based on the + * package name and message name in order to make it a unique C identifier. + * + * - `INIT`. Statically initializes a message object, initializing its + * descriptor and setting its fields to default values. Uninitialized + * messages cannot be processed by the protobuf-c library. + * +~~~{.c} +#define FOO__BAR__BAZ_BAH__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&foo__bar__baz_bah__descriptor), 0 } +~~~ + * - `init()`. Initializes a message object, initializing its descriptor and + * setting its fields to default values. Uninitialized messages cannot be + * processed by the protobuf-c library. + * +~~~{.c} +void foo__bar__baz_bah__init + (Foo__Bar__BazBah *message); +~~~ + * - `unpack()`. Unpacks data for a particular message format. Note that the + * `allocator` parameter is usually `NULL` to indicate that the system's + * `malloc()` and `free()` functions should be used for dynamically allocating + * memory. + * +~~~{.c} +Foo__Bar__BazBah * + foo__bar__baz_bah__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +~~~ + * + * - `free_unpacked()`. Frees a message object obtained with the `unpack()` + * method. Freeing `NULL` is allowed (the same as with `free()`). + * +~~~{.c} +void foo__bar__baz_bah__free_unpacked + (Foo__Bar__BazBah *message, + ProtobufCAllocator *allocator); +~~~ + * + * - `get_packed_size()`. Calculates the length in bytes of the serialized + * representation of the message object. + * +~~~{.c} +size_t foo__bar__baz_bah__get_packed_size + (const Foo__Bar__BazBah *message); +~~~ + * + * - `pack()`. Pack a message object into a preallocated buffer. Assumes that + * the buffer is large enough. (Use `get_packed_size()` first.) + * +~~~{.c} +size_t foo__bar__baz_bah__pack + (const Foo__Bar__BazBah *message, + uint8_t *out); +~~~ + * + * - `pack_to_buffer()`. Packs a message into a "virtual buffer". This is an + * object which defines an "append bytes" callback to consume data as it is + * serialized. + * +~~~{.c} +size_t foo__bar__baz_bah__pack_to_buffer + (const Foo__Bar__BazBah *message, + ProtobufCBuffer *buffer); +~~~ + * + * \page pack Packing and unpacking messages + * + * To pack a message, first compute the packed size of the message with + * protobuf_c_message_get_packed_size(), then allocate a buffer of at least + * that size, then call protobuf_c_message_pack(). + * + * Alternatively, a message can be serialized without calculating the final size + * first. Use the protobuf_c_message_pack_to_buffer() function and provide a + * ProtobufCBuffer object which implements an "append" method that consumes + * data. + * + * To unpack a message, call the protobuf_c_message_unpack() function. The + * result can be cast to an object of the type that matches the descriptor for + * the message. + * + * The result of unpacking a message should be freed with + * protobuf_c_message_free_unpacked(). + */ + +#ifndef PROTOBUF_C_H +#define PROTOBUF_C_H + +#include +#include +#include +#include + +#ifdef __cplusplus +# define PROTOBUF_C__BEGIN_DECLS extern "C" { +# define PROTOBUF_C__END_DECLS } +#else +# define PROTOBUF_C__BEGIN_DECLS +# define PROTOBUF_C__END_DECLS +#endif + +PROTOBUF_C__BEGIN_DECLS + +#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) +# ifdef PROTOBUF_C_EXPORT +# define PROTOBUF_C__API __declspec(dllexport) +# else +# define PROTOBUF_C__API __declspec(dllimport) +# endif +#else +# define PROTOBUF_C__API +#endif + +#if !defined(PROTOBUF_C__NO_DEPRECATED) && \ + ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +# define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__)) +#else +# define PROTOBUF_C__DEPRECATED +#endif + +#ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE + #define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \ + , _##enum_name##_IS_INT_SIZE = INT_MAX +#endif + +#define PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC 0x14159bc3 +#define PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9 +#define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af + +/* Empty string used for initializers */ +#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) +static const char protobuf_c_empty_string[] = ""; +#else +extern const char protobuf_c_empty_string[]; +#endif + +/** + * \defgroup api Public API + * + * This is the public API for `libprotobuf-c`. These interfaces are stable and + * subject to Semantic Versioning guarantees. + * + * @{ + */ + +/** + * Values for the `flags` word in `ProtobufCFieldDescriptor`. + */ +typedef enum { + /** Set if the field is repeated and marked with the `packed` option. */ + PROTOBUF_C_FIELD_FLAG_PACKED = (1 << 0), + + /** Set if the field is marked with the `deprecated` option. */ + PROTOBUF_C_FIELD_FLAG_DEPRECATED = (1 << 1), + + /** Set if the field is a member of a oneof (union). */ + PROTOBUF_C_FIELD_FLAG_ONEOF = (1 << 2), +} ProtobufCFieldFlag; + +/** + * Message field rules. + * + * \see [Defining A Message Type] in the Protocol Buffers documentation. + * + * [Defining A Message Type]: + * https://developers.google.com/protocol-buffers/docs/proto#simple + */ +typedef enum { + /** A well-formed message must have exactly one of this field. */ + PROTOBUF_C_LABEL_REQUIRED, + + /** + * A well-formed message can have zero or one of this field (but not + * more than one). + */ + PROTOBUF_C_LABEL_OPTIONAL, + + /** + * This field can be repeated any number of times (including zero) in a + * well-formed message. The order of the repeated values will be + * preserved. + */ + PROTOBUF_C_LABEL_REPEATED, + + /** + * This field has no label. This is valid only in proto3 and is + * equivalent to OPTIONAL but no "has" quantifier will be consulted. + */ + PROTOBUF_C_LABEL_NONE, +} ProtobufCLabel; + +/** + * Field value types. + * + * \see [Scalar Value Types] in the Protocol Buffers documentation. + * + * [Scalar Value Types]: + * https://developers.google.com/protocol-buffers/docs/proto#scalar + */ +typedef enum { + PROTOBUF_C_TYPE_INT32, /**< int32 */ + PROTOBUF_C_TYPE_SINT32, /**< signed int32 */ + PROTOBUF_C_TYPE_SFIXED32, /**< signed int32 (4 bytes) */ + PROTOBUF_C_TYPE_INT64, /**< int64 */ + PROTOBUF_C_TYPE_SINT64, /**< signed int64 */ + PROTOBUF_C_TYPE_SFIXED64, /**< signed int64 (8 bytes) */ + PROTOBUF_C_TYPE_UINT32, /**< unsigned int32 */ + PROTOBUF_C_TYPE_FIXED32, /**< unsigned int32 (4 bytes) */ + PROTOBUF_C_TYPE_UINT64, /**< unsigned int64 */ + PROTOBUF_C_TYPE_FIXED64, /**< unsigned int64 (8 bytes) */ + PROTOBUF_C_TYPE_FLOAT, /**< float */ + PROTOBUF_C_TYPE_DOUBLE, /**< double */ + PROTOBUF_C_TYPE_BOOL, /**< boolean */ + PROTOBUF_C_TYPE_ENUM, /**< enumerated type */ + PROTOBUF_C_TYPE_STRING, /**< UTF-8 or ASCII string */ + PROTOBUF_C_TYPE_BYTES, /**< arbitrary byte sequence */ + PROTOBUF_C_TYPE_MESSAGE, /**< nested message */ +} ProtobufCType; + +/** + * Field wire types. + * + * \see [Message Structure] in the Protocol Buffers documentation. + * + * [Message Structure]: + * https://developers.google.com/protocol-buffers/docs/encoding#structure + */ +typedef enum { + PROTOBUF_C_WIRE_TYPE_VARINT = 0, + PROTOBUF_C_WIRE_TYPE_64BIT = 1, + PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED = 2, + /* "Start group" and "end group" wire types are unsupported. */ + PROTOBUF_C_WIRE_TYPE_32BIT = 5, +} ProtobufCWireType; + +struct ProtobufCAllocator; +struct ProtobufCBinaryData; +struct ProtobufCBuffer; +struct ProtobufCBufferSimple; +struct ProtobufCEnumDescriptor; +struct ProtobufCEnumValue; +struct ProtobufCEnumValueIndex; +struct ProtobufCFieldDescriptor; +struct ProtobufCIntRange; +struct ProtobufCMessage; +struct ProtobufCMessageDescriptor; +struct ProtobufCMessageUnknownField; +struct ProtobufCMethodDescriptor; +struct ProtobufCService; +struct ProtobufCServiceDescriptor; + +typedef struct ProtobufCAllocator ProtobufCAllocator; +typedef struct ProtobufCBinaryData ProtobufCBinaryData; +typedef struct ProtobufCBuffer ProtobufCBuffer; +typedef struct ProtobufCBufferSimple ProtobufCBufferSimple; +typedef struct ProtobufCEnumDescriptor ProtobufCEnumDescriptor; +typedef struct ProtobufCEnumValue ProtobufCEnumValue; +typedef struct ProtobufCEnumValueIndex ProtobufCEnumValueIndex; +typedef struct ProtobufCFieldDescriptor ProtobufCFieldDescriptor; +typedef struct ProtobufCIntRange ProtobufCIntRange; +typedef struct ProtobufCMessage ProtobufCMessage; +typedef struct ProtobufCMessageDescriptor ProtobufCMessageDescriptor; +typedef struct ProtobufCMessageUnknownField ProtobufCMessageUnknownField; +typedef struct ProtobufCMethodDescriptor ProtobufCMethodDescriptor; +typedef struct ProtobufCService ProtobufCService; +typedef struct ProtobufCServiceDescriptor ProtobufCServiceDescriptor; + +/** Boolean type. */ +typedef int protobuf_c_boolean; + +typedef void (*ProtobufCClosure)(const ProtobufCMessage *, void *closure_data); +typedef void (*ProtobufCMessageInit)(ProtobufCMessage *); +typedef void (*ProtobufCServiceDestroy)(ProtobufCService *); + +/** + * Structure for defining a custom memory allocator. + */ +struct ProtobufCAllocator { + /** Function to allocate memory. */ + void *(*alloc)(void *allocator_data, size_t size); + + /** Function to free memory. */ + void (*free)(void *allocator_data, void *pointer); + + /** Opaque pointer passed to `alloc` and `free` functions. */ + void *allocator_data; +}; + +/** + * Structure for the protobuf `bytes` scalar type. + * + * The data contained in a `ProtobufCBinaryData` is an arbitrary sequence of + * bytes. It may contain embedded `NUL` characters and is not required to be + * `NUL`-terminated. + */ +struct ProtobufCBinaryData { + size_t len; /**< Number of bytes in the `data` field. */ + uint8_t *data; /**< Data bytes. */ +}; + +/** + * Structure for defining a virtual append-only buffer. Used by + * protobuf_c_message_pack_to_buffer() to abstract the consumption of serialized + * bytes. + * + * `ProtobufCBuffer` "subclasses" may be defined on the stack. For example, to + * write to a `FILE` object: + * +~~~{.c} +typedef struct { + ProtobufCBuffer base; + FILE *fp; +} BufferAppendToFile; + +static void +my_buffer_file_append(ProtobufCBuffer *buffer, + size_t len, + const uint8_t *data) +{ + BufferAppendToFile *file_buf = (BufferAppendToFile *) buffer; + fwrite(data, len, 1, file_buf->fp); // XXX: No error handling! +} +~~~ + * + * To use this new type of ProtobufCBuffer, it could be called as follows: + * +~~~{.c} +... +BufferAppendToFile tmp = {0}; +tmp.base.append = my_buffer_file_append; +tmp.fp = fp; +protobuf_c_message_pack_to_buffer(&message, &tmp); +... +~~~ + */ +struct ProtobufCBuffer { + /** Append function. Consumes the `len` bytes stored at `data`. */ + void (*append)(ProtobufCBuffer *buffer, + size_t len, + const uint8_t *data); +}; + +/** + * Simple buffer "subclass" of `ProtobufCBuffer`. + * + * A `ProtobufCBufferSimple` object is declared on the stack and uses a + * scratch buffer provided by the user for the initial allocation. It performs + * exponential resizing, using dynamically allocated memory. A + * `ProtobufCBufferSimple` object can be created and used as follows: + * +~~~{.c} +uint8_t pad[128]; +ProtobufCBufferSimple simple = PROTOBUF_C_BUFFER_SIMPLE_INIT(pad); +ProtobufCBuffer *buffer = (ProtobufCBuffer *) &simple; +~~~ + * + * `buffer` can now be used with `protobuf_c_message_pack_to_buffer()`. Once a + * message has been serialized to a `ProtobufCBufferSimple` object, the + * serialized data bytes can be accessed from the `.data` field. + * + * To free the memory allocated by a `ProtobufCBufferSimple` object, if any, + * call PROTOBUF_C_BUFFER_SIMPLE_CLEAR() on the object, for example: + * +~~~{.c} +PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple); +~~~ + * + * \see PROTOBUF_C_BUFFER_SIMPLE_INIT + * \see PROTOBUF_C_BUFFER_SIMPLE_CLEAR + */ +struct ProtobufCBufferSimple { + /** "Base class". */ + ProtobufCBuffer base; + /** Number of bytes allocated in `data`. */ + size_t alloced; + /** Number of bytes currently stored in `data`. */ + size_t len; + /** Data bytes. */ + uint8_t *data; + /** Whether `data` must be freed. */ + protobuf_c_boolean must_free_data; + /** Allocator to use. May be NULL to indicate the system allocator. */ + ProtobufCAllocator *allocator; +}; + +/** + * Describes an enumeration as a whole, with all of its values. + */ +struct ProtobufCEnumDescriptor { + /** Magic value checked to ensure that the API is used correctly. */ + uint32_t magic; + + /** The qualified name (e.g., "namespace.Type"). */ + const char *name; + /** The unqualified name as given in the .proto file (e.g., "Type"). */ + const char *short_name; + /** Identifier used in generated C code. */ + const char *c_name; + /** The dot-separated namespace. */ + const char *package_name; + + /** Number elements in `values`. */ + unsigned n_values; + /** Array of distinct values, sorted by numeric value. */ + const ProtobufCEnumValue *values; + + /** Number of elements in `values_by_name`. */ + unsigned n_value_names; + /** Array of named values, including aliases, sorted by name. */ + const ProtobufCEnumValueIndex *values_by_name; + + /** Number of elements in `value_ranges`. */ + unsigned n_value_ranges; + /** Value ranges, for faster lookups by numeric value. */ + const ProtobufCIntRange *value_ranges; + + /** Reserved for future use. */ + void *reserved1; + /** Reserved for future use. */ + void *reserved2; + /** Reserved for future use. */ + void *reserved3; + /** Reserved for future use. */ + void *reserved4; +}; + +/** + * Represents a single value of an enumeration. + */ +struct ProtobufCEnumValue { + /** The string identifying this value in the .proto file. */ + const char *name; + + /** The string identifying this value in generated C code. */ + const char *c_name; + + /** The numeric value assigned in the .proto file. */ + int value; +}; + +/** + * Used by `ProtobufCEnumDescriptor` to look up enum values. + */ +struct ProtobufCEnumValueIndex { + /** Name of the enum value. */ + const char *name; + /** Index into values[] array. */ + unsigned index; +}; + +/** + * Describes a single field in a message. + */ +struct ProtobufCFieldDescriptor { + /** Name of the field as given in the .proto file. */ + const char *name; + + /** Tag value of the field as given in the .proto file. */ + uint32_t id; + + /** Whether the field is `REQUIRED`, `OPTIONAL`, or `REPEATED`. */ + ProtobufCLabel label; + + /** The type of the field. */ + ProtobufCType type; + + /** + * The offset in bytes of the message's C structure's quantifier field + * (the `has_MEMBER` field for optional members or the `n_MEMBER` field + * for repeated members or the case enum for oneofs). + */ + unsigned quantifier_offset; + + /** + * The offset in bytes into the message's C structure for the member + * itself. + */ + unsigned offset; + + /** + * A type-specific descriptor. + * + * If `type` is `PROTOBUF_C_TYPE_ENUM`, then `descriptor` points to the + * corresponding `ProtobufCEnumDescriptor`. + * + * If `type` is `PROTOBUF_C_TYPE_MESSAGE`, then `descriptor` points to + * the corresponding `ProtobufCMessageDescriptor`. + * + * Otherwise this field is NULL. + */ + const void *descriptor; /* for MESSAGE and ENUM types */ + + /** The default value for this field, if defined. May be NULL. */ + const void *default_value; + + /** + * A flag word. Zero or more of the bits defined in the + * `ProtobufCFieldFlag` enum may be set. + */ + uint32_t flags; + + /** Reserved for future use. */ + unsigned reserved_flags; + /** Reserved for future use. */ + void *reserved2; + /** Reserved for future use. */ + void *reserved3; +}; + +/** + * Helper structure for optimizing int => index lookups in the case + * where the keys are mostly consecutive values, as they presumably are for + * enums and fields. + * + * The data structures requires that the values in the original array are + * sorted. + */ +struct ProtobufCIntRange { + int start_value; + unsigned orig_index; + /* + * NOTE: the number of values in the range can be inferred by looking + * at the next element's orig_index. A dummy element is added to make + * this simple. + */ +}; + +/** + * An instance of a message. + * + * `ProtobufCMessage` is a light-weight "base class" for all messages. + * + * In particular, `ProtobufCMessage` doesn't have any allocation policy + * associated with it. That's because it's common to create `ProtobufCMessage` + * objects on the stack. In fact, that's what we recommend for sending messages. + * If the object is allocated from the stack, you can't really have a memory + * leak. + * + * This means that calls to functions like protobuf_c_message_unpack() which + * return a `ProtobufCMessage` must be paired with a call to a free function, + * like protobuf_c_message_free_unpacked(). + */ +struct ProtobufCMessage { + /** The descriptor for this message type. */ + const ProtobufCMessageDescriptor *descriptor; + /** The number of elements in `unknown_fields`. */ + unsigned n_unknown_fields; + /** The fields that weren't recognized by the parser. */ + ProtobufCMessageUnknownField *unknown_fields; +}; + +/** + * Describes a message. + */ +struct ProtobufCMessageDescriptor { + /** Magic value checked to ensure that the API is used correctly. */ + uint32_t magic; + + /** The qualified name (e.g., "namespace.Type"). */ + const char *name; + /** The unqualified name as given in the .proto file (e.g., "Type"). */ + const char *short_name; + /** Identifier used in generated C code. */ + const char *c_name; + /** The dot-separated namespace. */ + const char *package_name; + + /** + * Size in bytes of the C structure representing an instance of this + * type of message. + */ + size_t sizeof_message; + + /** Number of elements in `fields`. */ + unsigned n_fields; + /** Field descriptors, sorted by tag number. */ + const ProtobufCFieldDescriptor *fields; + /** Used for looking up fields by name. */ + const unsigned *fields_sorted_by_name; + + /** Number of elements in `field_ranges`. */ + unsigned n_field_ranges; + /** Used for looking up fields by id. */ + const ProtobufCIntRange *field_ranges; + + /** Message initialisation function. */ + ProtobufCMessageInit message_init; + + /** Reserved for future use. */ + void *reserved1; + /** Reserved for future use. */ + void *reserved2; + /** Reserved for future use. */ + void *reserved3; +}; + +/** + * An unknown message field. + */ +struct ProtobufCMessageUnknownField { + /** The tag number. */ + uint32_t tag; + /** The wire type of the field. */ + ProtobufCWireType wire_type; + /** Number of bytes in `data`. */ + size_t len; + /** Field data. */ + uint8_t *data; +}; + +/** + * Method descriptor. + */ +struct ProtobufCMethodDescriptor { + /** Method name. */ + const char *name; + /** Input message descriptor. */ + const ProtobufCMessageDescriptor *input; + /** Output message descriptor. */ + const ProtobufCMessageDescriptor *output; +}; + +/** + * Service. + */ +struct ProtobufCService { + /** Service descriptor. */ + const ProtobufCServiceDescriptor *descriptor; + /** Function to invoke the service. */ + void (*invoke)(ProtobufCService *service, + unsigned method_index, + const ProtobufCMessage *input, + ProtobufCClosure closure, + void *closure_data); + /** Function to destroy the service. */ + void (*destroy)(ProtobufCService *service); +}; + +/** + * Service descriptor. + */ +struct ProtobufCServiceDescriptor { + /** Magic value checked to ensure that the API is used correctly. */ + uint32_t magic; + + /** Service name. */ + const char *name; + /** Short version of service name. */ + const char *short_name; + /** C identifier for the service name. */ + const char *c_name; + /** Package name. */ + const char *package; + /** Number of elements in `methods`. */ + unsigned n_methods; + /** Method descriptors, in the order defined in the .proto file. */ + const ProtobufCMethodDescriptor *methods; + /** Sort index of methods. */ + const unsigned *method_indices_by_name; +}; + +/** + * Get the version of the protobuf-c library. Note that this is the version of + * the library linked against, not the version of the headers compiled against. + * + * \return A string containing the version number of protobuf-c. + */ +PROTOBUF_C__API +const char * +protobuf_c_version(void); + +/** + * Get the version of the protobuf-c library. Note that this is the version of + * the library linked against, not the version of the headers compiled against. + * + * \return A 32 bit unsigned integer containing the version number of + * protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH. + */ +PROTOBUF_C__API +uint32_t +protobuf_c_version_number(void); + +/** + * The version of the protobuf-c headers, represented as a string using the same + * format as protobuf_c_version(). + */ +#define PROTOBUF_C_VERSION "1.4.0" + +/** + * The version of the protobuf-c headers, represented as an integer using the + * same format as protobuf_c_version_number(). + */ +#define PROTOBUF_C_VERSION_NUMBER 1004000 + +/** + * The minimum protoc-c version which works with the current version of the + * protobuf-c headers. + */ +#define PROTOBUF_C_MIN_COMPILER_VERSION 1000000 + +/** + * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by name. + * + * \param desc + * The `ProtobufCEnumDescriptor` object. + * \param name + * The `name` field from the corresponding `ProtobufCEnumValue` object to + * match. + * \return + * A `ProtobufCEnumValue` object. + * \retval NULL + * If not found or if the optimize_for = CODE_SIZE option was set. + */ +PROTOBUF_C__API +const ProtobufCEnumValue * +protobuf_c_enum_descriptor_get_value_by_name( + const ProtobufCEnumDescriptor *desc, + const char *name); + +/** + * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric + * value. + * + * \param desc + * The `ProtobufCEnumDescriptor` object. + * \param value + * The `value` field from the corresponding `ProtobufCEnumValue` object to + * match. + * + * \return + * A `ProtobufCEnumValue` object. + * \retval NULL + * If not found. + */ +PROTOBUF_C__API +const ProtobufCEnumValue * +protobuf_c_enum_descriptor_get_value( + const ProtobufCEnumDescriptor *desc, + int value); + +/** + * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by + * the name of the field. + * + * \param desc + * The `ProtobufCMessageDescriptor` object. + * \param name + * The name of the field. + * \return + * A `ProtobufCFieldDescriptor` object. + * \retval NULL + * If not found or if the optimize_for = CODE_SIZE option was set. + */ +PROTOBUF_C__API +const ProtobufCFieldDescriptor * +protobuf_c_message_descriptor_get_field_by_name( + const ProtobufCMessageDescriptor *desc, + const char *name); + +/** + * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by + * the tag value of the field. + * + * \param desc + * The `ProtobufCMessageDescriptor` object. + * \param value + * The tag value of the field. + * \return + * A `ProtobufCFieldDescriptor` object. + * \retval NULL + * If not found. + */ +PROTOBUF_C__API +const ProtobufCFieldDescriptor * +protobuf_c_message_descriptor_get_field( + const ProtobufCMessageDescriptor *desc, + unsigned value); + +/** + * Determine the number of bytes required to store the serialised message. + * + * \param message + * The message object to serialise. + * \return + * Number of bytes. + */ +PROTOBUF_C__API +size_t +protobuf_c_message_get_packed_size(const ProtobufCMessage *message); + +/** + * Serialise a message from its in-memory representation. + * + * This function stores the serialised bytes of the message in a pre-allocated + * buffer. + * + * \param message + * The message object to serialise. + * \param[out] out + * Buffer to store the bytes of the serialised message. This buffer must + * have enough space to store the packed message. Use + * protobuf_c_message_get_packed_size() to determine the number of bytes + * required. + * \return + * Number of bytes stored in `out`. + */ +PROTOBUF_C__API +size_t +protobuf_c_message_pack(const ProtobufCMessage *message, uint8_t *out); + +/** + * Serialise a message from its in-memory representation to a virtual buffer. + * + * This function calls the `append` method of a `ProtobufCBuffer` object to + * consume the bytes generated by the serialiser. + * + * \param message + * The message object to serialise. + * \param buffer + * The virtual buffer object. + * \return + * Number of bytes passed to the virtual buffer. + */ +PROTOBUF_C__API +size_t +protobuf_c_message_pack_to_buffer( + const ProtobufCMessage *message, + ProtobufCBuffer *buffer); + +/** + * Unpack a serialised message into an in-memory representation. + * + * \param descriptor + * The message descriptor. + * \param allocator + * `ProtobufCAllocator` to use for memory allocation. May be NULL to + * specify the default allocator. + * \param len + * Length in bytes of the serialised message. + * \param data + * Pointer to the serialised message. + * \return + * An unpacked message object. + * \retval NULL + * If an error occurred during unpacking. + */ +PROTOBUF_C__API +ProtobufCMessage * +protobuf_c_message_unpack( + const ProtobufCMessageDescriptor *descriptor, + ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); + +/** + * Free an unpacked message object. + * + * This function should be used to deallocate the memory used by a call to + * protobuf_c_message_unpack(). + * + * \param message + * The message object to free. May be NULL. + * \param allocator + * `ProtobufCAllocator` to use for memory deallocation. May be NULL to + * specify the default allocator. + */ +PROTOBUF_C__API +void +protobuf_c_message_free_unpacked( + ProtobufCMessage *message, + ProtobufCAllocator *allocator); + +/** + * Check the validity of a message object. + * + * Makes sure all required fields (`PROTOBUF_C_LABEL_REQUIRED`) are present. + * Recursively checks nested messages. + * + * \retval TRUE + * Message is valid. + * \retval FALSE + * Message is invalid. + */ +PROTOBUF_C__API +protobuf_c_boolean +protobuf_c_message_check(const ProtobufCMessage *); + +/** Message initialiser. */ +#define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL } + +/** + * Initialise a message object from a message descriptor. + * + * \param descriptor + * Message descriptor. + * \param message + * Allocated block of memory of size `descriptor->sizeof_message`. + */ +PROTOBUF_C__API +void +protobuf_c_message_init( + const ProtobufCMessageDescriptor *descriptor, + void *message); + +/** + * Free a service. + * + * \param service + * The service object to free. + */ +PROTOBUF_C__API +void +protobuf_c_service_destroy(ProtobufCService *service); + +/** + * Look up a `ProtobufCMethodDescriptor` by name. + * + * \param desc + * Service descriptor. + * \param name + * Name of the method. + * + * \return + * A `ProtobufCMethodDescriptor` object. + * \retval NULL + * If not found or if the optimize_for = CODE_SIZE option was set. + */ +PROTOBUF_C__API +const ProtobufCMethodDescriptor * +protobuf_c_service_descriptor_get_method_by_name( + const ProtobufCServiceDescriptor *desc, + const char *name); + +/** + * Initialise a `ProtobufCBufferSimple` object. + */ +#define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \ +{ \ + { protobuf_c_buffer_simple_append }, \ + sizeof(array_of_bytes), \ + 0, \ + (array_of_bytes), \ + 0, \ + NULL \ +} + +/** + * Clear a `ProtobufCBufferSimple` object, freeing any allocated memory. + */ +#define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \ +do { \ + if ((simp_buf)->must_free_data) { \ + if ((simp_buf)->allocator != NULL) \ + (simp_buf)->allocator->free( \ + (simp_buf)->allocator, \ + (simp_buf)->data); \ + else \ + free((simp_buf)->data); \ + } \ +} while (0) + +/** + * The `append` method for `ProtobufCBufferSimple`. + * + * \param buffer + * The buffer object to append to. Must actually be a + * `ProtobufCBufferSimple` object. + * \param len + * Number of bytes in `data`. + * \param data + * Data to append. + */ +PROTOBUF_C__API +void +protobuf_c_buffer_simple_append( + ProtobufCBuffer *buffer, + size_t len, + const unsigned char *data); + +PROTOBUF_C__API +void +protobuf_c_service_generated_init( + ProtobufCService *service, + const ProtobufCServiceDescriptor *descriptor, + ProtobufCServiceDestroy destroy); + +PROTOBUF_C__API +void +protobuf_c_service_invoke_internal( + ProtobufCService *service, + unsigned method_index, + const ProtobufCMessage *input, + ProtobufCClosure closure, + void *closure_data); + +/**@}*/ + +PROTOBUF_C__END_DECLS + +#endif /* PROTOBUF_C_H */ \ No newline at end of file diff --git a/c/vendor/xxhash/xxhash.c b/c/vendor/xxhash/xxhash.c new file mode 100644 index 0000000..728fd68 --- /dev/null +++ b/c/vendor/xxhash/xxhash.c @@ -0,0 +1,43 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Copyright (C) 2012-2020 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + + +/* + * xxhash.c instantiates functions defined in xxhash.h + */ + +#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */ +#define XXH_IMPLEMENTATION /* access definitions */ + +#include "xxhash.h" \ No newline at end of file diff --git a/c/vendor/xxhash/xxhash.h b/c/vendor/xxhash/xxhash.h new file mode 100644 index 0000000..4bdd13a --- /dev/null +++ b/c/vendor/xxhash/xxhash.h @@ -0,0 +1,5445 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Header File + * Copyright (C) 2012-2020 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ +/*! + * @mainpage xxHash + * + * @file xxhash.h + * xxHash prototypes and implementation + */ +/* TODO: update */ +/* Notice extracted from xxHash homepage: + +xxHash is an extremely fast hash algorithm, running at RAM speed limits. +It also successfully passes all tests from the SMHasher suite. + +Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) + +Name Speed Q.Score Author +xxHash 5.4 GB/s 10 +CrapWow 3.2 GB/s 2 Andrew +MurmurHash 3a 2.7 GB/s 10 Austin Appleby +SpookyHash 2.0 GB/s 10 Bob Jenkins +SBox 1.4 GB/s 9 Bret Mulvey +Lookup3 1.2 GB/s 9 Bob Jenkins +SuperFastHash 1.2 GB/s 1 Paul Hsieh +CityHash64 1.05 GB/s 10 Pike & Alakuijala +FNV 0.55 GB/s 5 Fowler, Noll, Vo +CRC32 0.43 GB/s 9 +MD5-32 0.33 GB/s 10 Ronald L. Rivest +SHA1-32 0.28 GB/s 10 + +Q.Score is a measure of quality of the hash function. +It depends on successfully passing SMHasher test set. +10 is a perfect score. + +Note: SMHasher's CRC32 implementation is not the fastest one. +Other speed-oriented implementations can be faster, +especially in combination with PCLMUL instruction: +https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html?showComment=1552696407071#c3490092340461170735 + +A 64-bit version, named XXH64, is available since r35. +It offers much better speed, but for 64-bit applications only. +Name Speed on 64 bits Speed on 32 bits +XXH64 13.8 GB/s 1.9 GB/s +XXH32 6.8 GB/s 6.0 GB/s +*/ + +#if defined (__cplusplus) +extern "C" { +#endif + +/* **************************** + * INLINE mode + ******************************/ +/*! + * XXH_INLINE_ALL (and XXH_PRIVATE_API) + * Use these build macros to inline xxhash into the target unit. + * Inlining improves performance on small inputs, especially when the length is + * expressed as a compile-time constant: + * + * https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html + * + * It also keeps xxHash symbols private to the unit, so they are not exported. + * + * Usage: + * #define XXH_INLINE_ALL + * #include "xxhash.h" + * + * Do not compile and link xxhash.o as a separate object, as it is not useful. + */ +#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \ + && !defined(XXH_INLINE_ALL_31684351384) + /* this section should be traversed only once */ +# define XXH_INLINE_ALL_31684351384 + /* give access to the advanced API, required to compile implementations */ +# undef XXH_STATIC_LINKING_ONLY /* avoid macro redef */ +# define XXH_STATIC_LINKING_ONLY + /* make all functions private */ +# undef XXH_PUBLIC_API +# if defined(__GNUC__) +# define XXH_PUBLIC_API static __inline __attribute__((unused)) +# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +# define XXH_PUBLIC_API static inline +# elif defined(_MSC_VER) +# define XXH_PUBLIC_API static __inline +# else + /* note: this version may generate warnings for unused static functions */ +# define XXH_PUBLIC_API static +# endif + + /* + * This part deals with the special case where a unit wants to inline xxHash, + * but "xxhash.h" has previously been included without XXH_INLINE_ALL, such + * as part of some previously included *.h header file. + * Without further action, the new include would just be ignored, + * and functions would effectively _not_ be inlined (silent failure). + * The following macros solve this situation by prefixing all inlined names, + * avoiding naming collision with previous inclusions. + */ +# ifdef XXH_NAMESPACE +# error "XXH_INLINE_ALL with XXH_NAMESPACE is not supported" + /* + * Note: Alternative: #undef all symbols (it's a pretty large list). + * Without #error: it compiles, but functions are actually not inlined. + */ +# endif +# define XXH_NAMESPACE XXH_INLINE_ + /* + * Some identifiers (enums, type names) are not symbols, but they must + * still be renamed to avoid redeclaration. + * Alternative solution: do not redeclare them. + * However, this requires some #ifdefs, and is a more dispersed action. + * Meanwhile, renaming can be achieved in a single block + */ +# define XXH_IPREF(Id) XXH_INLINE_ ## Id +# define XXH_OK XXH_IPREF(XXH_OK) +# define XXH_ERROR XXH_IPREF(XXH_ERROR) +# define XXH_errorcode XXH_IPREF(XXH_errorcode) +# define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t) +# define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t) +# define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t) +# define XXH32_state_s XXH_IPREF(XXH32_state_s) +# define XXH32_state_t XXH_IPREF(XXH32_state_t) +# define XXH64_state_s XXH_IPREF(XXH64_state_s) +# define XXH64_state_t XXH_IPREF(XXH64_state_t) +# define XXH3_state_s XXH_IPREF(XXH3_state_s) +# define XXH3_state_t XXH_IPREF(XXH3_state_t) +# define XXH128_hash_t XXH_IPREF(XXH128_hash_t) + /* Ensure the header is parsed again, even if it was previously included */ +# undef XXHASH_H_5627135585666179 +# undef XXHASH_H_STATIC_13879238742 +#endif /* XXH_INLINE_ALL || XXH_PRIVATE_API */ + + + +/* **************************************************************** + * Stable API + *****************************************************************/ +#ifndef XXHASH_H_5627135585666179 +#define XXHASH_H_5627135585666179 1 + + +/*! + * @defgroup public Public API + * Contains details on the public xxHash functions. + * @{ + */ +/* specific declaration modes for Windows */ +#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API) +# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT)) +# ifdef XXH_EXPORT +# define XXH_PUBLIC_API __declspec(dllexport) +# elif XXH_IMPORT +# define XXH_PUBLIC_API __declspec(dllimport) +# endif +# else +# define XXH_PUBLIC_API /* do nothing */ +# endif +#endif + +#ifdef XXH_DOXYGEN +/*! + * @brief Emulate a namespace by transparently prefixing all symbols. + * + * If you want to include _and expose_ xxHash functions from within your own + * library, but also want to avoid symbol collisions with other libraries which + * may also include xxHash, you can use XXH_NAMESPACE to automatically prefix + * any public symbol from xxhash library with the value of XXH_NAMESPACE + * (therefore, avoid empty or numeric values). + * + * Note that no change is required within the calling program as long as it + * includes `xxhash.h`: Regular symbol names will be automatically translated + * by this header. + */ +# define XXH_NAMESPACE /* YOUR NAME HERE */ +# undef XXH_NAMESPACE +#endif + +#ifdef XXH_NAMESPACE +# define XXH_CAT(A,B) A##B +# define XXH_NAME2(A,B) XXH_CAT(A,B) +# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber) +/* XXH32 */ +# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) +# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) +# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) +# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) +# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) +# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) +# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState) +# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash) +# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical) +/* XXH64 */ +# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) +# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) +# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) +# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) +# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) +# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) +# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState) +# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash) +# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical) +/* XXH3_64bits */ +# define XXH3_64bits XXH_NAME2(XXH_NAMESPACE, XXH3_64bits) +# define XXH3_64bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecret) +# define XXH3_64bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSeed) +# define XXH3_createState XXH_NAME2(XXH_NAMESPACE, XXH3_createState) +# define XXH3_freeState XXH_NAME2(XXH_NAMESPACE, XXH3_freeState) +# define XXH3_copyState XXH_NAME2(XXH_NAMESPACE, XXH3_copyState) +# define XXH3_64bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset) +# define XXH3_64bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSeed) +# define XXH3_64bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecret) +# define XXH3_64bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_update) +# define XXH3_64bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_digest) +# define XXH3_generateSecret XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret) +/* XXH3_128bits */ +# define XXH128 XXH_NAME2(XXH_NAMESPACE, XXH128) +# define XXH3_128bits XXH_NAME2(XXH_NAMESPACE, XXH3_128bits) +# define XXH3_128bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSeed) +# define XXH3_128bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecret) +# define XXH3_128bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset) +# define XXH3_128bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSeed) +# define XXH3_128bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecret) +# define XXH3_128bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_update) +# define XXH3_128bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_digest) +# define XXH128_isEqual XXH_NAME2(XXH_NAMESPACE, XXH128_isEqual) +# define XXH128_cmp XXH_NAME2(XXH_NAMESPACE, XXH128_cmp) +# define XXH128_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH128_canonicalFromHash) +# define XXH128_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH128_hashFromCanonical) +#endif + + +/* ************************************* +* Version +***************************************/ +#define XXH_VERSION_MAJOR 0 +#define XXH_VERSION_MINOR 8 +#define XXH_VERSION_RELEASE 0 +#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) + +/*! + * @brief Obtains the xxHash version. + * + * This is only useful when xxHash is compiled as a shared library, as it is + * independent of the version defined in the header. + * + * @return `XXH_VERSION_NUMBER` as of when the function was compiled. + */ +XXH_PUBLIC_API unsigned XXH_versionNumber (void); + + +/* **************************** +* Definitions +******************************/ +#include /* size_t */ +typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; + + +/*-********************************************************************** +* 32-bit hash +************************************************************************/ +#if defined(XXH_DOXYGEN) /* Don't show include */ +/*! + * @brief An unsigned 32-bit integer. + * + * Not necessarily defined to `uint32_t` but functionally equivalent. + */ +typedef uint32_t XXH32_hash_t; +#elif !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint32_t XXH32_hash_t; +#else +# include +# if UINT_MAX == 0xFFFFFFFFUL + typedef unsigned int XXH32_hash_t; +# else +# if ULONG_MAX == 0xFFFFFFFFUL + typedef unsigned long XXH32_hash_t; +# else +# error "unsupported platform: need a 32-bit type" +# endif +# endif +#endif + +/*! + * @} + * + * @defgroup xxh32_family XXH32 family + * @ingroup public + * Contains functions used in the classic 32-bit xxHash algorithm. + * + * @note + * XXH32 is considered rather weak by today's standards. + * The @ref xxh3_family provides competitive speed for both 32-bit and 64-bit + * systems, and offers true 64/128 bit hash results. It provides a superior + * level of dispersion, and greatly reduces the risks of collisions. + * + * @see @ref xxh64_family, @ref xxh3_family : Other xxHash families + * @see @ref xxh32_impl for implementation details + * @{ + */ + +/*! + * @brief Calculates the 32-bit hash of @p input using xxHash32. + * + * Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark): 5.4 GB/s + * + * @param input The block of data to be hashed, at least @p length bytes in size. + * @param length The length of @p input, in bytes. + * @param seed The 32-bit seed to alter the hash's output predictably. + * + * @pre + * The memory between @p input and @p input + @p length must be valid, + * readable, contiguous memory. However, if @p length is `0`, @p input may be + * `NULL`. In C++, this also must be *TriviallyCopyable*. + * + * @return The calculated 32-bit hash value. + * + * @see + * XXH64(), XXH3_64bits_withSeed(), XXH3_128bits_withSeed(), XXH128(): + * Direct equivalents for the other variants of xxHash. + * @see + * XXH32_createState(), XXH32_update(), XXH32_digest(): Streaming version. + */ +XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, XXH32_hash_t seed); + +/*! + * Streaming functions generate the xxHash value from an incremental input. + * This method is slower than single-call functions, due to state management. + * For small inputs, prefer `XXH32()` and `XXH64()`, which are better optimized. + * + * An XXH state must first be allocated using `XXH*_createState()`. + * + * Start a new hash by initializing the state with a seed using `XXH*_reset()`. + * + * Then, feed the hash state by calling `XXH*_update()` as many times as necessary. + * + * The function returns an error code, with 0 meaning OK, and any other value + * meaning there is an error. + * + * Finally, a hash value can be produced anytime, by using `XXH*_digest()`. + * This function returns the nn-bits hash as an int or long long. + * + * It's still possible to continue inserting input into the hash state after a + * digest, and generate new hash values later on by invoking `XXH*_digest()`. + * + * When done, release the state using `XXH*_freeState()`. + * + * Example code for incrementally hashing a file: + * @code{.c} + * #include + * #include + * #define BUFFER_SIZE 256 + * + * // Note: XXH64 and XXH3 use the same interface. + * XXH32_hash_t + * hashFile(FILE* stream) + * { + * XXH32_state_t* state; + * unsigned char buf[BUFFER_SIZE]; + * size_t amt; + * XXH32_hash_t hash; + * + * state = XXH32_createState(); // Create a state + * assert(state != NULL); // Error check here + * XXH32_reset(state, 0xbaad5eed); // Reset state with our seed + * while ((amt = fread(buf, 1, sizeof(buf), stream)) != 0) { + * XXH32_update(state, buf, amt); // Hash the file in chunks + * } + * hash = XXH32_digest(state); // Finalize the hash + * XXH32_freeState(state); // Clean up + * return hash; + * } + * @endcode + */ + +/*! + * @typedef struct XXH32_state_s XXH32_state_t + * @brief The opaque state struct for the XXH32 streaming API. + * + * @see XXH32_state_s for details. + */ +typedef struct XXH32_state_s XXH32_state_t; + +/*! + * @brief Allocates an @ref XXH32_state_t. + * + * Must be freed with XXH32_freeState(). + * @return An allocated XXH32_state_t on success, `NULL` on failure. + */ +XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void); +/*! + * @brief Frees an @ref XXH32_state_t. + * + * Must be allocated with XXH32_createState(). + * @param statePtr A pointer to an @ref XXH32_state_t allocated with @ref XXH32_createState(). + * @return XXH_OK. + */ +XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); +/*! + * @brief Copies one @ref XXH32_state_t to another. + * + * @param dst_state The state to copy to. + * @param src_state The state to copy from. + * @pre + * @p dst_state and @p src_state must not be `NULL` and must not overlap. + */ +XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dst_state, const XXH32_state_t* src_state); + +/*! + * @brief Resets an @ref XXH32_state_t to begin a new hash. + * + * This function resets and seeds a state. Call it before @ref XXH32_update(). + * + * @param statePtr The state struct to reset. + * @param seed The 32-bit seed to alter the hash result predictably. + * + * @pre + * @p statePtr must not be `NULL`. + * + * @return @ref XXH_OK on success, @ref XXH_ERROR on failure. + */ +XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, XXH32_hash_t seed); + +/*! + * @brief Consumes a block of @p input to an @ref XXH32_state_t. + * + * Call this to incrementally consume blocks of data. + * + * @param statePtr The state struct to update. + * @param input The block of data to be hashed, at least @p length bytes in size. + * @param length The length of @p input, in bytes. + * + * @pre + * @p statePtr must not be `NULL`. + * @pre + * The memory between @p input and @p input + @p length must be valid, + * readable, contiguous memory. However, if @p length is `0`, @p input may be + * `NULL`. In C++, this also must be *TriviallyCopyable*. + * + * @return @ref XXH_OK on success, @ref XXH_ERROR on failure. + */ +XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); + +/*! + * @brief Returns the calculated hash value from an @ref XXH32_state_t. + * + * @note + * Calling XXH32_digest() will not affect @p statePtr, so you can update, + * digest, and update again. + * + * @param statePtr The state struct to calculate the hash from. + * + * @pre + * @p statePtr must not be `NULL`. + * + * @return The calculated xxHash32 value from that state. + */ +XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); + +/******* Canonical representation *******/ + +/* + * The default return values from XXH functions are unsigned 32 and 64 bit + * integers. + * This the simplest and fastest format for further post-processing. + * + * However, this leaves open the question of what is the order on the byte level, + * since little and big endian conventions will store the same number differently. + * + * The canonical representation settles this issue by mandating big-endian + * convention, the same convention as human-readable numbers (large digits first). + * + * When writing hash values to storage, sending them over a network, or printing + * them, it's highly recommended to use the canonical representation to ensure + * portability across a wider range of systems, present and future. + * + * The following functions allow transformation of hash values to and from + * canonical format. + */ + +/*! + * @brief Canonical (big endian) representation of @ref XXH32_hash_t. + */ +typedef struct { + unsigned char digest[4]; /*!< Hash bytes, big endian */ +} XXH32_canonical_t; + +/*! + * @brief Converts an @ref XXH32_hash_t to a big endian @ref XXH32_canonical_t. + * + * @param dst The @ref XXH32_canonical_t pointer to be stored to. + * @param hash The @ref XXH32_hash_t to be converted. + * + * @pre + * @p dst must not be `NULL`. + */ +XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); + +/*! + * @brief Converts an @ref XXH32_canonical_t to a native @ref XXH32_hash_t. + * + * @param src The @ref XXH32_canonical_t to convert. + * + * @pre + * @p src must not be `NULL`. + * + * @return The converted hash. + */ +XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); + + +/*! + * @} + * @ingroup public + * @{ + */ + +#ifndef XXH_NO_LONG_LONG +/*-********************************************************************** +* 64-bit hash +************************************************************************/ +#if defined(XXH_DOXYGEN) /* don't include */ +/*! + * @brief An unsigned 64-bit integer. + * + * Not necessarily defined to `uint64_t` but functionally equivalent. + */ +typedef uint64_t XXH64_hash_t; +#elif !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint64_t XXH64_hash_t; +#else +# include +# if defined(__LP64__) && ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL + /* LP64 ABI says uint64_t is unsigned long */ + typedef unsigned long XXH64_hash_t; +# else + /* the following type must have a width of 64-bit */ + typedef unsigned long long XXH64_hash_t; +# endif +#endif + +/*! + * @} + * + * @defgroup xxh64_family XXH64 family + * @ingroup public + * @{ + * Contains functions used in the classic 64-bit xxHash algorithm. + * + * @note + * XXH3 provides competitive speed for both 32-bit and 64-bit systems, + * and offers true 64/128 bit hash results. It provides a superior level of + * dispersion, and greatly reduces the risks of collisions. + */ + + +/*! + * @brief Calculates the 64-bit hash of @p input using xxHash64. + * + * This function usually runs faster on 64-bit systems, but slower on 32-bit + * systems (see benchmark). + * + * @param input The block of data to be hashed, at least @p length bytes in size. + * @param length The length of @p input, in bytes. + * @param seed The 64-bit seed to alter the hash's output predictably. + * + * @pre + * The memory between @p input and @p input + @p length must be valid, + * readable, contiguous memory. However, if @p length is `0`, @p input may be + * `NULL`. In C++, this also must be *TriviallyCopyable*. + * + * @return The calculated 64-bit hash. + * + * @see + * XXH32(), XXH3_64bits_withSeed(), XXH3_128bits_withSeed(), XXH128(): + * Direct equivalents for the other variants of xxHash. + * @see + * XXH64_createState(), XXH64_update(), XXH64_digest(): Streaming version. + */ +XXH_PUBLIC_API XXH64_hash_t XXH64(const void* input, size_t length, XXH64_hash_t seed); + +/******* Streaming *******/ +/*! + * @brief The opaque state struct for the XXH64 streaming API. + * + * @see XXH64_state_s for details. + */ +typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ +XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void); +XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); +XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dst_state, const XXH64_state_t* src_state); + +XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, XXH64_hash_t seed); +XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); + +/******* Canonical representation *******/ +typedef struct { unsigned char digest[sizeof(XXH64_hash_t)]; } XXH64_canonical_t; +XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); +XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src); + +/*! + * @} + * ************************************************************************ + * @defgroup xxh3_family XXH3 family + * @ingroup public + * @{ + * + * XXH3 is a more recent hash algorithm featuring: + * - Improved speed for both small and large inputs + * - True 64-bit and 128-bit outputs + * - SIMD acceleration + * - Improved 32-bit viability + * + * Speed analysis methodology is explained here: + * + * https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html + * + * Compared to XXH64, expect XXH3 to run approximately + * ~2x faster on large inputs and >3x faster on small ones, + * exact differences vary depending on platform. + * + * XXH3's speed benefits greatly from SIMD and 64-bit arithmetic, + * but does not require it. + * Any 32-bit and 64-bit targets that can run XXH32 smoothly + * can run XXH3 at competitive speeds, even without vector support. + * Further details are explained in the implementation. + * + * Optimized implementations are provided for AVX512, AVX2, SSE2, NEON, POWER8, + * ZVector and scalar targets. This can be controlled via the XXH_VECTOR macro. + * + * XXH3 implementation is portable: + * it has a generic C90 formulation that can be compiled on any platform, + * all implementations generage exactly the same hash value on all platforms. + * Starting from v0.8.0, it's also labelled "stable", meaning that + * any future version will also generate the same hash value. + * + * XXH3 offers 2 variants, _64bits and _128bits. + * + * When only 64 bits are needed, prefer invoking the _64bits variant, as it + * reduces the amount of mixing, resulting in faster speed on small inputs. + * It's also generally simpler to manipulate a scalar return type than a struct. + * + * The API supports one-shot hashing, streaming mode, and custom secrets. + */ + +/*-********************************************************************** +* XXH3 64-bit variant +************************************************************************/ + +/* XXH3_64bits(): + * default 64-bit variant, using default secret and default seed of 0. + * It's the fastest variant. */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits(const void* data, size_t len); + +/* + * XXH3_64bits_withSeed(): + * This variant generates a custom secret on the fly + * based on default secret altered using the `seed` value. + * While this operation is decently fast, note that it's not completely free. + * Note: seed==0 produces the same results as XXH3_64bits(). + */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSeed(const void* data, size_t len, XXH64_hash_t seed); + +/*! + * The bare minimum size for a custom secret. + * + * @see + * XXH3_64bits_withSecret(), XXH3_64bits_reset_withSecret(), + * XXH3_128bits_withSecret(), XXH3_128bits_reset_withSecret(). + */ +#define XXH3_SECRET_SIZE_MIN 136 + +/* + * XXH3_64bits_withSecret(): + * It's possible to provide any blob of bytes as a "secret" to generate the hash. + * This makes it more difficult for an external actor to prepare an intentional collision. + * The main condition is that secretSize *must* be large enough (>= XXH3_SECRET_SIZE_MIN). + * However, the quality of produced hash values depends on secret's entropy. + * Technically, the secret must look like a bunch of random bytes. + * Avoid "trivial" or structured data such as repeated sequences or a text document. + * Whenever unsure about the "randomness" of the blob of bytes, + * consider relabelling it as a "custom seed" instead, + * and employ "XXH3_generateSecret()" (see below) + * to generate a high entropy secret derived from the custom seed. + */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize); + + +/******* Streaming *******/ +/* + * Streaming requires state maintenance. + * This operation costs memory and CPU. + * As a consequence, streaming is slower than one-shot hashing. + * For better performance, prefer one-shot functions whenever applicable. + */ + +/*! + * @brief The state struct for the XXH3 streaming API. + * + * @see XXH3_state_s for details. + */ +typedef struct XXH3_state_s XXH3_state_t; +XXH_PUBLIC_API XXH3_state_t* XXH3_createState(void); +XXH_PUBLIC_API XXH_errorcode XXH3_freeState(XXH3_state_t* statePtr); +XXH_PUBLIC_API void XXH3_copyState(XXH3_state_t* dst_state, const XXH3_state_t* src_state); + +/* + * XXH3_64bits_reset(): + * Initialize with default parameters. + * digest will be equivalent to `XXH3_64bits()`. + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset(XXH3_state_t* statePtr); +/* + * XXH3_64bits_reset_withSeed(): + * Generate a custom secret from `seed`, and store it into `statePtr`. + * digest will be equivalent to `XXH3_64bits_withSeed()`. + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed); +/* + * XXH3_64bits_reset_withSecret(): + * `secret` is referenced, it _must outlive_ the hash streaming session. + * Similar to one-shot API, `secretSize` must be >= `XXH3_SECRET_SIZE_MIN`, + * and the quality of produced hash values depends on secret's entropy + * (secret's content should look like a bunch of random bytes). + * When in doubt about the randomness of a candidate `secret`, + * consider employing `XXH3_generateSecret()` instead (see below). + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize); + +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update (XXH3_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_digest (const XXH3_state_t* statePtr); + +/* note : canonical representation of XXH3 is the same as XXH64 + * since they both produce XXH64_hash_t values */ + + +/*-********************************************************************** +* XXH3 128-bit variant +************************************************************************/ + +/*! + * @brief The return value from 128-bit hashes. + * + * Stored in little endian order, although the fields themselves are in native + * endianness. + */ +typedef struct { + XXH64_hash_t low64; /*!< `value & 0xFFFFFFFFFFFFFFFF` */ + XXH64_hash_t high64; /*!< `value >> 64` */ +} XXH128_hash_t; + +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits(const void* data, size_t len); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSeed(const void* data, size_t len, XXH64_hash_t seed); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize); + +/******* Streaming *******/ +/* + * Streaming requires state maintenance. + * This operation costs memory and CPU. + * As a consequence, streaming is slower than one-shot hashing. + * For better performance, prefer one-shot functions whenever applicable. + * + * XXH3_128bits uses the same XXH3_state_t as XXH3_64bits(). + * Use already declared XXH3_createState() and XXH3_freeState(). + * + * All reset and streaming functions have same meaning as their 64-bit counterpart. + */ + +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset(XXH3_state_t* statePtr); +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed); +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize); + +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_update (XXH3_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (const XXH3_state_t* statePtr); + +/* Following helper functions make it possible to compare XXH128_hast_t values. + * Since XXH128_hash_t is a structure, this capability is not offered by the language. + * Note: For better performance, these functions can be inlined using XXH_INLINE_ALL */ + +/*! + * XXH128_isEqual(): + * Return: 1 if `h1` and `h2` are equal, 0 if they are not. + */ +XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2); + +/*! + * XXH128_cmp(): + * + * This comparator is compatible with stdlib's `qsort()`/`bsearch()`. + * + * return: >0 if *h128_1 > *h128_2 + * =0 if *h128_1 == *h128_2 + * <0 if *h128_1 < *h128_2 + */ +XXH_PUBLIC_API int XXH128_cmp(const void* h128_1, const void* h128_2); + + +/******* Canonical representation *******/ +typedef struct { unsigned char digest[sizeof(XXH128_hash_t)]; } XXH128_canonical_t; +XXH_PUBLIC_API void XXH128_canonicalFromHash(XXH128_canonical_t* dst, XXH128_hash_t hash); +XXH_PUBLIC_API XXH128_hash_t XXH128_hashFromCanonical(const XXH128_canonical_t* src); + + +#endif /* XXH_NO_LONG_LONG */ + +/*! + * @} + */ +#endif /* XXHASH_H_5627135585666179 */ + + + +#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742) +#define XXHASH_H_STATIC_13879238742 +/* **************************************************************************** + * This section contains declarations which are not guaranteed to remain stable. + * They may change in future versions, becoming incompatible with a different + * version of the library. + * These declarations should only be used with static linking. + * Never use them in association with dynamic linking! + ***************************************************************************** */ + +/* + * These definitions are only present to allow static allocation + * of XXH states, on stack or in a struct, for example. + * Never **ever** access their members directly. + */ + +/*! + * @internal + * @brief Structure for XXH32 streaming API. + * + * @note This is only defined when @ref XXH_STATIC_LINKING_ONLY, + * @ref XXH_INLINE_ALL, or @ref XXH_IMPLEMENTATION is defined. Otherwise it is + * an opaque type. This allows fields to safely be changed. + * + * Typedef'd to @ref XXH32_state_t. + * Do not access the members of this struct directly. + * @see XXH64_state_s, XXH3_state_s + */ +struct XXH32_state_s { + XXH32_hash_t total_len_32; /*!< Total length hashed, modulo 2^32 */ + XXH32_hash_t large_len; /*!< Whether the hash is >= 16 (handles @ref total_len_32 overflow) */ + XXH32_hash_t v1; /*!< First accumulator lane */ + XXH32_hash_t v2; /*!< Second accumulator lane */ + XXH32_hash_t v3; /*!< Third accumulator lane */ + XXH32_hash_t v4; /*!< Fourth accumulator lane */ + XXH32_hash_t mem32[4]; /*!< Internal buffer for partial reads. Treated as unsigned char[16]. */ + XXH32_hash_t memsize; /*!< Amount of data in @ref mem32 */ + XXH32_hash_t reserved; /*!< Reserved field. Do not read or write to it, it may be removed. */ +}; /* typedef'd to XXH32_state_t */ + + +#ifndef XXH_NO_LONG_LONG /* defined when there is no 64-bit support */ + +/*! + * @internal + * @brief Structure for XXH64 streaming API. + * + * @note This is only defined when @ref XXH_STATIC_LINKING_ONLY, + * @ref XXH_INLINE_ALL, or @ref XXH_IMPLEMENTATION is defined. Otherwise it is + * an opaque type. This allows fields to safely be changed. + * + * Typedef'd to @ref XXH64_state_t. + * Do not access the members of this struct directly. + * @see XXH32_state_s, XXH3_state_s + */ +struct XXH64_state_s { + XXH64_hash_t total_len; /*!< Total length hashed. This is always 64-bit. */ + XXH64_hash_t v1; /*!< First accumulator lane */ + XXH64_hash_t v2; /*!< Second accumulator lane */ + XXH64_hash_t v3; /*!< Third accumulator lane */ + XXH64_hash_t v4; /*!< Fourth accumulator lane */ + XXH64_hash_t mem64[4]; /*!< Internal buffer for partial reads. Treated as unsigned char[32]. */ + XXH32_hash_t memsize; /*!< Amount of data in @ref mem64 */ + XXH32_hash_t reserved32; /*!< Reserved field, needed for padding anyways*/ + XXH64_hash_t reserved64; /*!< Reserved field. Do not read or write to it, it may be removed. */ +}; /* typedef'd to XXH64_state_t */ + +#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11+ */ +# include +# define XXH_ALIGN(n) alignas(n) +#elif defined(__GNUC__) +# define XXH_ALIGN(n) __attribute__ ((aligned(n))) +#elif defined(_MSC_VER) +# define XXH_ALIGN(n) __declspec(align(n)) +#else +# define XXH_ALIGN(n) /* disabled */ +#endif + +/* Old GCC versions only accept the attribute after the type in structures. */ +#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) /* C11+ */ \ + && defined(__GNUC__) +# define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align) +#else +# define XXH_ALIGN_MEMBER(align, type) XXH_ALIGN(align) type +#endif + +/*! + * @brief The size of the internal XXH3 buffer. + * + * This is the optimal update size for incremental hashing. + * + * @see XXH3_64b_update(), XXH3_128b_update(). + */ +#define XXH3_INTERNALBUFFER_SIZE 256 + +/*! + * @brief Default size of the secret buffer (and @ref XXH3_kSecret). + * + * This is the size used in @ref XXH3_kSecret and the seeded functions. + * + * Not to be confused with @ref XXH3_SECRET_SIZE_MIN. + */ +#define XXH3_SECRET_DEFAULT_SIZE 192 + +/*! + * @internal + * @brief Structure for XXH3 streaming API. + * + * @note This is only defined when @ref XXH_STATIC_LINKING_ONLY, + * @ref XXH_INLINE_ALL, or @ref XXH_IMPLEMENTATION is defined. Otherwise it is + * an opaque type. This allows fields to safely be changed. + * + * @note **This structure has a strict alignment requirement of 64 bytes.** Do + * not allocate this with `malloc()` or `new`, it will not be sufficiently + * aligned. Use @ref XXH3_createState() and @ref XXH3_freeState(), or stack + * allocation. + * + * Typedef'd to @ref XXH3_state_t. + * Do not access the members of this struct directly. + * + * @see XXH3_INITSTATE() for stack initialization. + * @see XXH3_createState(), XXH3_freeState(). + * @see XXH32_state_s, XXH64_state_s + */ +struct XXH3_state_s { + XXH_ALIGN_MEMBER(64, XXH64_hash_t acc[8]); + /*!< The 8 accumulators. Similar to `vN` in @ref XXH32_state_s::v1 and @ref XXH64_state_s */ + XXH_ALIGN_MEMBER(64, unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]); + /*!< Used to store a custom secret generated from a seed. */ + XXH_ALIGN_MEMBER(64, unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]); + /*!< The internal buffer. @see XXH32_state_s::mem32 */ + XXH32_hash_t bufferedSize; + /*!< The amount of memory in @ref buffer, @see XXH32_state_s::memsize */ + XXH32_hash_t reserved32; + /*!< Reserved field. Needed for padding on 64-bit. */ + size_t nbStripesSoFar; + /*!< Number or stripes processed. */ + XXH64_hash_t totalLen; + /*!< Total length hashed. 64-bit even on 32-bit targets. */ + size_t nbStripesPerBlock; + /*!< Number of stripes per block. */ + size_t secretLimit; + /*!< Size of @ref customSecret or @ref extSecret */ + XXH64_hash_t seed; + /*!< Seed for _withSeed variants. Must be zero otherwise, @see XXH3_INITSTATE() */ + XXH64_hash_t reserved64; + /*!< Reserved field. */ + const unsigned char* extSecret; + /*!< Reference to an external secret for the _withSecret variants, NULL + * for other variants. */ + /* note: there may be some padding at the end due to alignment on 64 bytes */ +}; /* typedef'd to XXH3_state_t */ + +#undef XXH_ALIGN_MEMBER + +/*! + * @brief Initializes a stack-allocated `XXH3_state_s`. + * + * When the @ref XXH3_state_t structure is merely emplaced on stack, + * it should be initialized with XXH3_INITSTATE() or a memset() + * in case its first reset uses XXH3_NNbits_reset_withSeed(). + * This init can be omitted if the first reset uses default or _withSecret mode. + * This operation isn't necessary when the state is created with XXH3_createState(). + * Note that this doesn't prepare the state for a streaming operation, + * it's still necessary to use XXH3_NNbits_reset*() afterwards. + */ +#define XXH3_INITSTATE(XXH3_state_ptr) { (XXH3_state_ptr)->seed = 0; } + + +/* === Experimental API === */ +/* Symbols defined below must be considered tied to a specific library version. */ + +/* + * XXH3_generateSecret(): + * + * Derive a high-entropy secret from any user-defined content, named customSeed. + * The generated secret can be used in combination with `*_withSecret()` functions. + * The `_withSecret()` variants are useful to provide a higher level of protection than 64-bit seed, + * as it becomes much more difficult for an external actor to guess how to impact the calculation logic. + * + * The function accepts as input a custom seed of any length and any content, + * and derives from it a high-entropy secret of length XXH3_SECRET_DEFAULT_SIZE + * into an already allocated buffer secretBuffer. + * The generated secret is _always_ XXH_SECRET_DEFAULT_SIZE bytes long. + * + * The generated secret can then be used with any `*_withSecret()` variant. + * Functions `XXH3_128bits_withSecret()`, `XXH3_64bits_withSecret()`, + * `XXH3_128bits_reset_withSecret()` and `XXH3_64bits_reset_withSecret()` + * are part of this list. They all accept a `secret` parameter + * which must be very long for implementation reasons (>= XXH3_SECRET_SIZE_MIN) + * _and_ feature very high entropy (consist of random-looking bytes). + * These conditions can be a high bar to meet, so + * this function can be used to generate a secret of proper quality. + * + * customSeed can be anything. It can have any size, even small ones, + * and its content can be anything, even stupidly "low entropy" source such as a bunch of zeroes. + * The resulting `secret` will nonetheless provide all expected qualities. + * + * Supplying NULL as the customSeed copies the default secret into `secretBuffer`. + * When customSeedSize > 0, supplying NULL as customSeed is undefined behavior. + */ +XXH_PUBLIC_API void XXH3_generateSecret(void* secretBuffer, const void* customSeed, size_t customSeedSize); + + +/* simple short-cut to pre-selected XXH3_128bits variant */ +XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t seed); + + +#endif /* XXH_NO_LONG_LONG */ +#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) +# define XXH_IMPLEMENTATION +#endif + +#endif /* defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742) */ + + +/* ======================================================================== */ +/* ======================================================================== */ +/* ======================================================================== */ + + +/*-********************************************************************** + * xxHash implementation + *-********************************************************************** + * xxHash's implementation used to be hosted inside xxhash.c. + * + * However, inlining requires implementation to be visible to the compiler, + * hence be included alongside the header. + * Previously, implementation was hosted inside xxhash.c, + * which was then #included when inlining was activated. + * This construction created issues with a few build and install systems, + * as it required xxhash.c to be stored in /include directory. + * + * xxHash implementation is now directly integrated within xxhash.h. + * As a consequence, xxhash.c is no longer needed in /include. + * + * xxhash.c is still available and is still useful. + * In a "normal" setup, when xxhash is not inlined, + * xxhash.h only exposes the prototypes and public symbols, + * while xxhash.c can be built into an object file xxhash.o + * which can then be linked into the final binary. + ************************************************************************/ + +#if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \ + || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387) +# define XXH_IMPLEM_13a8737387 + +/* ************************************* +* Tuning parameters +***************************************/ + +/*! + * @defgroup tuning Tuning parameters + * @{ + * + * Various macros to control xxHash's behavior. + */ +#ifdef XXH_DOXYGEN +/*! + * @brief Define this to disable 64-bit code. + * + * Useful if only using the @ref xxh32_family and you have a strict C90 compiler. + */ +# define XXH_NO_LONG_LONG +# undef XXH_NO_LONG_LONG /* don't actually */ +/*! + * @brief Controls how unaligned memory is accessed. + * + * By default, access to unaligned memory is controlled by `memcpy()`, which is + * safe and portable. + * + * Unfortunately, on some target/compiler combinations, the generated assembly + * is sub-optimal. + * + * The below switch allow selection of a different access method + * in the search for improved performance. + * + * @par Possible options: + * + * - `XXH_FORCE_MEMORY_ACCESS=0` (default): `memcpy` + * @par + * Use `memcpy()`. Safe and portable. Note that most modern compilers will + * eliminate the function call and treat it as an unaligned access. + * + * - `XXH_FORCE_MEMORY_ACCESS=1`: `__attribute__((packed))` + * @par + * Depends on compiler extensions and is therefore not portable. + * This method is safe _if_ your compiler supports it, + * and *generally* as fast or faster than `memcpy`. + * + * - `XXH_FORCE_MEMORY_ACCESS=2`: Direct cast + * @par + * Casts directly and dereferences. This method doesn't depend on the + * compiler, but it violates the C standard as it directly dereferences an + * unaligned pointer. It can generate buggy code on targets which do not + * support unaligned memory accesses, but in some circumstances, it's the + * only known way to get the most performance. + * + * - `XXH_FORCE_MEMORY_ACCESS=3`: Byteshift + * @par + * Also portable. This can generate the best code on old compilers which don't + * inline small `memcpy()` calls, and it might also be faster on big-endian + * systems which lack a native byteswap instruction. However, some compilers + * will emit literal byteshifts even if the target supports unaligned access. + * . + * + * @warning + * Methods 1 and 2 rely on implementation-defined behavior. Use these with + * care, as what works on one compiler/platform/optimization level may cause + * another to read garbage data or even crash. + * + * See https://stackoverflow.com/a/32095106/646947 for details. + * + * Prefer these methods in priority order (0 > 3 > 1 > 2) + */ +# define XXH_FORCE_MEMORY_ACCESS 0 +/*! + * @def XXH_ACCEPT_NULL_INPUT_POINTER + * @brief Whether to add explicit `NULL` checks. + * + * If the input pointer is `NULL` and the length is non-zero, xxHash's default + * behavior is to dereference it, triggering a segfault. + * + * When this macro is enabled, xxHash actively checks the input for a null pointer. + * If it is, the result for null input pointers is the same as a zero-length input. + */ +# define XXH_ACCEPT_NULL_INPUT_POINTER 0 +/*! + * @def XXH_FORCE_ALIGN_CHECK + * @brief If defined to non-zero, adds a special path for aligned inputs (XXH32() + * and XXH64() only). + * + * This is an important performance trick for architectures without decent + * unaligned memory access performance. + * + * It checks for input alignment, and when conditions are met, uses a "fast + * path" employing direct 32-bit/64-bit reads, resulting in _dramatically + * faster_ read speed. + * + * The check costs one initial branch per hash, which is generally negligible, + * but not zero. + * + * Moreover, it's not useful to generate an additional code path if memory + * access uses the same instruction for both aligned and unaligned + * addresses (e.g. x86 and aarch64). + * + * In these cases, the alignment check can be removed by setting this macro to 0. + * Then the code will always use unaligned memory access. + * Align check is automatically disabled on x86, x64 & arm64, + * which are platforms known to offer good unaligned memory accesses performance. + * + * This option does not affect XXH3 (only XXH32 and XXH64). + */ +# define XXH_FORCE_ALIGN_CHECK 0 + +/*! + * @def XXH_NO_INLINE_HINTS + * @brief When non-zero, sets all functions to `static`. + * + * By default, xxHash tries to force the compiler to inline almost all internal + * functions. + * + * This can usually improve performance due to reduced jumping and improved + * constant folding, but significantly increases the size of the binary which + * might not be favorable. + * + * Additionally, sometimes the forced inlining can be detrimental to performance, + * depending on the architecture. + * + * XXH_NO_INLINE_HINTS marks all internal functions as static, giving the + * compiler full control on whether to inline or not. + * + * When not optimizing (-O0), optimizing for size (-Os, -Oz), or using + * -fno-inline with GCC or Clang, this will automatically be defined. + */ +# define XXH_NO_INLINE_HINTS 0 + +/*! + * @def XXH_REROLL + * @brief Whether to reroll `XXH32_finalize` and `XXH64_finalize`. + * + * For performance, `XXH32_finalize` and `XXH64_finalize` use an unrolled loop + * in the form of a switch statement. + * + * This is not always desirable, as it generates larger code, and depending on + * the architecture, may even be slower + * + * This is automatically defined with `-Os`/`-Oz` on GCC and Clang. + */ +# define XXH_REROLL 0 + +/*! + * @internal + * @brief Redefines old internal names. + * + * For compatibility with code that uses xxHash's internals before the names + * were changed to improve namespacing. There is no other reason to use this. + */ +# define XXH_OLD_NAMES +# undef XXH_OLD_NAMES /* don't actually use, it is ugly. */ +#endif /* XXH_DOXYGEN */ +/*! + * @} + */ + +#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ + /* prefer __packed__ structures (method 1) for gcc on armv7 and armv8 */ +# if !defined(__clang__) && ( \ + (defined(__INTEL_COMPILER) && !defined(_WIN32)) || \ + (defined(__GNUC__) && (defined(__ARM_ARCH) && __ARM_ARCH >= 7)) ) +# define XXH_FORCE_MEMORY_ACCESS 1 +# endif +#endif + +#ifndef XXH_ACCEPT_NULL_INPUT_POINTER /* can be defined externally */ +# define XXH_ACCEPT_NULL_INPUT_POINTER 0 +#endif + +#ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */ +# if defined(__i386) || defined(__x86_64__) || defined(__aarch64__) \ + || defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64) /* visual */ +# define XXH_FORCE_ALIGN_CHECK 0 +# else +# define XXH_FORCE_ALIGN_CHECK 1 +# endif +#endif + +#ifndef XXH_NO_INLINE_HINTS +# if defined(__OPTIMIZE_SIZE__) /* -Os, -Oz */ \ + || defined(__NO_INLINE__) /* -O0, -fno-inline */ +# define XXH_NO_INLINE_HINTS 1 +# else +# define XXH_NO_INLINE_HINTS 0 +# endif +#endif + +#ifndef XXH_REROLL +# if defined(__OPTIMIZE_SIZE__) +# define XXH_REROLL 1 +# else +# define XXH_REROLL 0 +# endif +#endif + +/*! + * @defgroup impl Implementation + * @{ + */ + + +/* ************************************* +* Includes & Memory related functions +***************************************/ +/* + * Modify the local functions below should you wish to use + * different memory routines for malloc() and free() + */ +#include + +/*! + * @internal + * @brief Modify this function to use a different routine than malloc(). + */ +static void* XXH_malloc(size_t s) { return malloc(s); } + +/*! + * @internal + * @brief Modify this function to use a different routine than free(). + */ +static void XXH_free(void* p) { free(p); } + +#include + +/*! + * @internal + * @brief Modify this function to use a different routine than memcpy(). + */ +static void* XXH_memcpy(void* dest, const void* src, size_t size) +{ + return memcpy(dest,src,size); +} + +#include /* ULLONG_MAX */ + + +/* ************************************* +* Compiler Specific Options +***************************************/ +#ifdef _MSC_VER /* Visual Studio warning fix */ +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ +#endif + +#if XXH_NO_INLINE_HINTS /* disable inlining hints */ +# if defined(__GNUC__) +# define XXH_FORCE_INLINE static __attribute__((unused)) +# else +# define XXH_FORCE_INLINE static +# endif +# define XXH_NO_INLINE static +/* enable inlining hints */ +#elif defined(_MSC_VER) /* Visual Studio */ +# define XXH_FORCE_INLINE static __forceinline +# define XXH_NO_INLINE static __declspec(noinline) +#elif defined(__GNUC__) +# define XXH_FORCE_INLINE static __inline__ __attribute__((always_inline, unused)) +# define XXH_NO_INLINE static __attribute__((noinline)) +#elif defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* C99 */ +# define XXH_FORCE_INLINE static inline +# define XXH_NO_INLINE static +#else +# define XXH_FORCE_INLINE static +# define XXH_NO_INLINE static +#endif + + + +/* ************************************* +* Debug +***************************************/ +/*! + * @ingroup tuning + * @def XXH_DEBUGLEVEL + * @brief Sets the debugging level. + * + * XXH_DEBUGLEVEL is expected to be defined externally, typically via the + * compiler's command line options. The value must be a number. + */ +#ifndef XXH_DEBUGLEVEL +# ifdef DEBUGLEVEL /* backwards compat */ +# define XXH_DEBUGLEVEL DEBUGLEVEL +# else +# define XXH_DEBUGLEVEL 0 +# endif +#endif + +#if (XXH_DEBUGLEVEL>=1) +# include /* note: can still be disabled with NDEBUG */ +# define XXH_ASSERT(c) assert(c) +#else +# define XXH_ASSERT(c) ((void)0) +#endif + +/* note: use after variable declarations */ +#define XXH_STATIC_ASSERT(c) do { enum { XXH_sa = 1/(int)(!!(c)) }; } while (0) + + +/* ************************************* +* Basic Types +***************************************/ +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint8_t xxh_u8; +#else + typedef unsigned char xxh_u8; +#endif +typedef XXH32_hash_t xxh_u32; + +#ifdef XXH_OLD_NAMES +# define BYTE xxh_u8 +# define U8 xxh_u8 +# define U32 xxh_u32 +#endif + +/* *** Memory access *** */ + +/*! + * @internal + * @fn xxh_u32 XXH_read32(const void* ptr) + * @brief Reads an unaligned 32-bit integer from @p ptr in native endianness. + * + * Affected by @ref XXH_FORCE_MEMORY_ACCESS. + * + * @param ptr The pointer to read from. + * @return The 32-bit native endian integer from the bytes at @p ptr. + */ + +/*! + * @internal + * @fn xxh_u32 XXH_readLE32(const void* ptr) + * @brief Reads an unaligned 32-bit little endian integer from @p ptr. + * + * Affected by @ref XXH_FORCE_MEMORY_ACCESS. + * + * @param ptr The pointer to read from. + * @return The 32-bit little endian integer from the bytes at @p ptr. + */ + +/*! + * @internal + * @fn xxh_u32 XXH_readBE32(const void* ptr) + * @brief Reads an unaligned 32-bit big endian integer from @p ptr. + * + * Affected by @ref XXH_FORCE_MEMORY_ACCESS. + * + * @param ptr The pointer to read from. + * @return The 32-bit big endian integer from the bytes at @p ptr. + */ + +/*! + * @internal + * @fn xxh_u32 XXH_readLE32_align(const void* ptr, XXH_alignment align) + * @brief Like @ref XXH_readLE32(), but has an option for aligned reads. + * + * Affected by @ref XXH_FORCE_MEMORY_ACCESS. + * Note that when @ref XXH_FORCE_ALIGN_CHECK == 0, the @p align parameter is + * always @ref XXH_alignment::XXH_unaligned. + * + * @param ptr The pointer to read from. + * @param align Whether @p ptr is aligned. + * @pre + * If @p align == @ref XXH_alignment::XXH_aligned, @p ptr must be 4 byte + * aligned. + * @return The 32-bit little endian integer from the bytes at @p ptr. + */ + +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) +/* + * Manual byteshift. Best for old compilers which don't inline memcpy. + * We actually directly use XXH_readLE32 and XXH_readBE32. + */ +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) + +/* + * Force direct memory access. Only works on CPU which support unaligned memory + * access in hardware. + */ +static xxh_u32 XXH_read32(const void* memPtr) { return *(const xxh_u32*) memPtr; } + +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) + +/* + * __pack instructions are safer but compiler specific, hence potentially + * problematic for some compilers. + * + * Currently only defined for GCC and ICC. + */ +#ifdef XXH_OLD_NAMES +typedef union { xxh_u32 u32; } __attribute__((packed)) unalign; +#endif +static xxh_u32 XXH_read32(const void* ptr) +{ + typedef union { xxh_u32 u32; } __attribute__((packed)) xxh_unalign; + return ((const xxh_unalign*)ptr)->u32; +} + +#else + +/* + * Portable and safe solution. Generally efficient. + * see: https://stackoverflow.com/a/32095106/646947 + */ +static xxh_u32 XXH_read32(const void* memPtr) +{ + xxh_u32 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */ + + +/* *** Endianness *** */ +typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; + +/*! + * @ingroup tuning + * @def XXH_CPU_LITTLE_ENDIAN + * @brief Whether the target is little endian. + * + * Defined to 1 if the target is little endian, or 0 if it is big endian. + * It can be defined externally, for example on the compiler command line. + * + * If it is not defined, a runtime check (which is usually constant folded) + * is used instead. + * + * @note + * This is not necessarily defined to an integer constant. + * + * @see XXH_isLittleEndian() for the runtime check. + */ +#ifndef XXH_CPU_LITTLE_ENDIAN +/* + * Try to detect endianness automatically, to avoid the nonstandard behavior + * in `XXH_isLittleEndian()` + */ +# if defined(_WIN32) /* Windows is always little endian */ \ + || defined(__LITTLE_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +# define XXH_CPU_LITTLE_ENDIAN 1 +# elif defined(__BIG_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define XXH_CPU_LITTLE_ENDIAN 0 +# else +/*! + * @internal + * @brief Runtime check for @ref XXH_CPU_LITTLE_ENDIAN. + * + * Most compilers will constant fold this. + */ +static int XXH_isLittleEndian(void) +{ + /* + * Portable and well-defined behavior. + * Don't use static: it is detrimental to performance. + */ + const union { xxh_u32 u; xxh_u8 c[4]; } one = { 1 }; + return one.c[0]; +} +# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian() +# endif +#endif + + + + +/* **************************************** +* Compiler-specific Functions and Macros +******************************************/ +#define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) + +#ifdef __has_builtin +# define XXH_HAS_BUILTIN(x) __has_builtin(x) +#else +# define XXH_HAS_BUILTIN(x) 0 +#endif + +/*! + * @internal + * @def XXH_rotl32(x,r) + * @brief 32-bit rotate left. + * + * @param x The 32-bit integer to be rotated. + * @param r The number of bits to rotate. + * @pre + * @p r > 0 && @p r < 32 + * @note + * @p x and @p r may be evaluated multiple times. + * @return The rotated result. + */ +#if !defined(NO_CLANG_BUILTIN) && XXH_HAS_BUILTIN(__builtin_rotateleft32) \ + && XXH_HAS_BUILTIN(__builtin_rotateleft64) +# define XXH_rotl32 __builtin_rotateleft32 +# define XXH_rotl64 __builtin_rotateleft64 +/* Note: although _rotl exists for minGW (GCC under windows), performance seems poor */ +#elif defined(_MSC_VER) +# define XXH_rotl32(x,r) _rotl(x,r) +# define XXH_rotl64(x,r) _rotl64(x,r) +#else +# define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) +# define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r)))) +#endif + +/*! + * @internal + * @fn xxh_u32 XXH_swap32(xxh_u32 x) + * @brief A 32-bit byteswap. + * + * @param x The 32-bit integer to byteswap. + * @return @p x, byteswapped. + */ +#if defined(_MSC_VER) /* Visual Studio */ +# define XXH_swap32 _byteswap_ulong +#elif XXH_GCC_VERSION >= 403 +# define XXH_swap32 __builtin_bswap32 +#else +static xxh_u32 XXH_swap32 (xxh_u32 x) +{ + return ((x << 24) & 0xff000000 ) | + ((x << 8) & 0x00ff0000 ) | + ((x >> 8) & 0x0000ff00 ) | + ((x >> 24) & 0x000000ff ); +} +#endif + + +/* *************************** +* Memory reads +*****************************/ + +/*! + * @internal + * @brief Enum to indicate whether a pointer is aligned. + */ +typedef enum { + XXH_aligned, /*!< Aligned */ + XXH_unaligned /*!< Possibly unaligned */ +} XXH_alignment; + +/* + * XXH_FORCE_MEMORY_ACCESS==3 is an endian-independent byteshift load. + * + * This is ideal for older compilers which don't inline memcpy. + */ +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) + +XXH_FORCE_INLINE xxh_u32 XXH_readLE32(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[0] + | ((xxh_u32)bytePtr[1] << 8) + | ((xxh_u32)bytePtr[2] << 16) + | ((xxh_u32)bytePtr[3] << 24); +} + +XXH_FORCE_INLINE xxh_u32 XXH_readBE32(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[3] + | ((xxh_u32)bytePtr[2] << 8) + | ((xxh_u32)bytePtr[1] << 16) + | ((xxh_u32)bytePtr[0] << 24); +} + +#else +XXH_FORCE_INLINE xxh_u32 XXH_readLE32(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); +} + +static xxh_u32 XXH_readBE32(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr); +} +#endif + +XXH_FORCE_INLINE xxh_u32 +XXH_readLE32_align(const void* ptr, XXH_alignment align) +{ + if (align==XXH_unaligned) { + return XXH_readLE32(ptr); + } else { + return XXH_CPU_LITTLE_ENDIAN ? *(const xxh_u32*)ptr : XXH_swap32(*(const xxh_u32*)ptr); + } +} + + +/* ************************************* +* Misc +***************************************/ +/*! @ingroup public */ +XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; } + + +/* ******************************************************************* +* 32-bit hash functions +*********************************************************************/ +/*! + * @} + * @defgroup xxh32_impl XXH32 implementation + * @ingroup impl + * @{ + */ +static const xxh_u32 XXH_PRIME32_1 = 0x9E3779B1U; /*!< 0b10011110001101110111100110110001 */ +static const xxh_u32 XXH_PRIME32_2 = 0x85EBCA77U; /*!< 0b10000101111010111100101001110111 */ +static const xxh_u32 XXH_PRIME32_3 = 0xC2B2AE3DU; /*!< 0b11000010101100101010111000111101 */ +static const xxh_u32 XXH_PRIME32_4 = 0x27D4EB2FU; /*!< 0b00100111110101001110101100101111 */ +static const xxh_u32 XXH_PRIME32_5 = 0x165667B1U; /*!< 0b00010110010101100110011110110001 */ + +#ifdef XXH_OLD_NAMES +# define PRIME32_1 XXH_PRIME32_1 +# define PRIME32_2 XXH_PRIME32_2 +# define PRIME32_3 XXH_PRIME32_3 +# define PRIME32_4 XXH_PRIME32_4 +# define PRIME32_5 XXH_PRIME32_5 +#endif + +/*! + * @internal + * @brief Normal stripe processing routine. + * + * This shuffles the bits so that any bit from @p input impacts several bits in + * @p acc. + * + * @param acc The accumulator lane. + * @param input The stripe of input to mix. + * @return The mixed accumulator lane. + */ +static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input) +{ + acc += input * XXH_PRIME32_2; + acc = XXH_rotl32(acc, 13); + acc *= XXH_PRIME32_1; +#if defined(__GNUC__) && defined(__SSE4_1__) && !defined(XXH_ENABLE_AUTOVECTORIZE) + /* + * UGLY HACK: + * This inline assembly hack forces acc into a normal register. This is the + * only thing that prevents GCC and Clang from autovectorizing the XXH32 + * loop (pragmas and attributes don't work for some reason) without globally + * disabling SSE4.1. + * + * The reason we want to avoid vectorization is because despite working on + * 4 integers at a time, there are multiple factors slowing XXH32 down on + * SSE4: + * - There's a ridiculous amount of lag from pmulld (10 cycles of latency on + * newer chips!) making it slightly slower to multiply four integers at + * once compared to four integers independently. Even when pmulld was + * fastest, Sandy/Ivy Bridge, it is still not worth it to go into SSE + * just to multiply unless doing a long operation. + * + * - Four instructions are required to rotate, + * movqda tmp, v // not required with VEX encoding + * pslld tmp, 13 // tmp <<= 13 + * psrld v, 19 // x >>= 19 + * por v, tmp // x |= tmp + * compared to one for scalar: + * roll v, 13 // reliably fast across the board + * shldl v, v, 13 // Sandy Bridge and later prefer this for some reason + * + * - Instruction level parallelism is actually more beneficial here because + * the SIMD actually serializes this operation: While v1 is rotating, v2 + * can load data, while v3 can multiply. SSE forces them to operate + * together. + * + * How this hack works: + * __asm__("" // Declare an assembly block but don't declare any instructions + * : // However, as an Input/Output Operand, + * "+r" // constrain a read/write operand (+) as a general purpose register (r). + * (acc) // and set acc as the operand + * ); + * + * Because of the 'r', the compiler has promised that seed will be in a + * general purpose register and the '+' says that it will be 'read/write', + * so it has to assume it has changed. It is like volatile without all the + * loads and stores. + * + * Since the argument has to be in a normal register (not an SSE register), + * each time XXH32_round is called, it is impossible to vectorize. + */ + __asm__("" : "+r" (acc)); +#endif + return acc; +} + +/*! + * @internal + * @brief Mixes all bits to finalize the hash. + * + * The final mix ensures that all input bits have a chance to impact any bit in + * the output digest, resulting in an unbiased distribution. + * + * @param h32 The hash to avalanche. + * @return The avalanched hash. + */ +static xxh_u32 XXH32_avalanche(xxh_u32 h32) +{ + h32 ^= h32 >> 15; + h32 *= XXH_PRIME32_2; + h32 ^= h32 >> 13; + h32 *= XXH_PRIME32_3; + h32 ^= h32 >> 16; + return(h32); +} + +#define XXH_get32bits(p) XXH_readLE32_align(p, align) + +/*! + * @internal + * @brief Processes the last 0-15 bytes of @p ptr. + * + * There may be up to 15 bytes remaining to consume from the input. + * This final stage will digest them to ensure that all input bytes are present + * in the final mix. + * + * @param h32 The hash to finalize. + * @param ptr The pointer to the remaining input. + * @param len The remaining length, modulo 16. + * @param align Whether @p ptr is aligned. + * @return The finalized hash. + */ +static xxh_u32 +XXH32_finalize(xxh_u32 h32, const xxh_u8* ptr, size_t len, XXH_alignment align) +{ +#define XXH_PROCESS1 do { \ + h32 += (*ptr++) * XXH_PRIME32_5; \ + h32 = XXH_rotl32(h32, 11) * XXH_PRIME32_1; \ +} while (0) + +#define XXH_PROCESS4 do { \ + h32 += XXH_get32bits(ptr) * XXH_PRIME32_3; \ + ptr += 4; \ + h32 = XXH_rotl32(h32, 17) * XXH_PRIME32_4; \ +} while (0) + + /* Compact rerolled version */ + if (XXH_REROLL) { + len &= 15; + while (len >= 4) { + XXH_PROCESS4; + len -= 4; + } + while (len > 0) { + XXH_PROCESS1; + --len; + } + return XXH32_avalanche(h32); + } else { + switch(len&15) /* or switch(bEnd - p) */ { + case 12: XXH_PROCESS4; + /* fallthrough */ + case 8: XXH_PROCESS4; + /* fallthrough */ + case 4: XXH_PROCESS4; + return XXH32_avalanche(h32); + + case 13: XXH_PROCESS4; + /* fallthrough */ + case 9: XXH_PROCESS4; + /* fallthrough */ + case 5: XXH_PROCESS4; + XXH_PROCESS1; + return XXH32_avalanche(h32); + + case 14: XXH_PROCESS4; + /* fallthrough */ + case 10: XXH_PROCESS4; + /* fallthrough */ + case 6: XXH_PROCESS4; + XXH_PROCESS1; + XXH_PROCESS1; + return XXH32_avalanche(h32); + + case 15: XXH_PROCESS4; + /* fallthrough */ + case 11: XXH_PROCESS4; + /* fallthrough */ + case 7: XXH_PROCESS4; + /* fallthrough */ + case 3: XXH_PROCESS1; + /* fallthrough */ + case 2: XXH_PROCESS1; + /* fallthrough */ + case 1: XXH_PROCESS1; + /* fallthrough */ + case 0: return XXH32_avalanche(h32); + } + XXH_ASSERT(0); + return h32; /* reaching this point is deemed impossible */ + } +} + +#ifdef XXH_OLD_NAMES +# define PROCESS1 XXH_PROCESS1 +# define PROCESS4 XXH_PROCESS4 +#else +# undef XXH_PROCESS1 +# undef XXH_PROCESS4 +#endif + +/*! + * @internal + * @brief The implementation for @ref XXH32(). + * + * @param input, len, seed Directly passed from @ref XXH32(). + * @param align Whether @p input is aligned. + * @return The calculated hash. + */ +XXH_FORCE_INLINE xxh_u32 +XXH32_endian_align(const xxh_u8* input, size_t len, xxh_u32 seed, XXH_alignment align) +{ + const xxh_u8* bEnd = input + len; + xxh_u32 h32; + +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + if (input==NULL) { + len=0; + bEnd=input=(const xxh_u8*)(size_t)16; + } +#endif + + if (len>=16) { + const xxh_u8* const limit = bEnd - 15; + xxh_u32 v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + xxh_u32 v2 = seed + XXH_PRIME32_2; + xxh_u32 v3 = seed + 0; + xxh_u32 v4 = seed - XXH_PRIME32_1; + + do { + v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4; + v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4; + v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4; + v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4; + } while (input < limit); + + h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); + } else { + h32 = seed + XXH_PRIME32_5; + } + + h32 += (xxh_u32)len; + + return XXH32_finalize(h32, input, len&15, align); +} + +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t len, XXH32_hash_t seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH32_state_t state; + XXH32_reset(&state, seed); + XXH32_update(&state, (const xxh_u8*)input, len); + return XXH32_digest(&state); +#else + if (XXH_FORCE_ALIGN_CHECK) { + if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */ + return XXH32_endian_align((const xxh_u8*)input, len, seed, XXH_aligned); + } } + + return XXH32_endian_align((const xxh_u8*)input, len, seed, XXH_unaligned); +#endif +} + + + +/******* Hash streaming *******/ +/*! + * @ingroup xxh32_family + */ +XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void) +{ + return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t)); +} +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dstState, const XXH32_state_t* srcState) +{ + memcpy(dstState, srcState, sizeof(*dstState)); +} + +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, XXH32_hash_t seed) +{ + XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */ + memset(&state, 0, sizeof(state)); + state.v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + state.v2 = seed + XXH_PRIME32_2; + state.v3 = seed + 0; + state.v4 = seed - XXH_PRIME32_1; + /* do not write into reserved, planned to be removed in a future version */ + memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved)); + return XXH_OK; +} + + +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH_errorcode +XXH32_update(XXH32_state_t* state, const void* input, size_t len) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* p = (const xxh_u8*)input; + const xxh_u8* const bEnd = p + len; + + state->total_len_32 += (XXH32_hash_t)len; + state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16)); + + if (state->memsize + len < 16) { /* fill in tmp buffer */ + XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, len); + state->memsize += (XXH32_hash_t)len; + return XXH_OK; + } + + if (state->memsize) { /* some data left from previous update */ + XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, 16-state->memsize); + { const xxh_u32* p32 = state->mem32; + state->v1 = XXH32_round(state->v1, XXH_readLE32(p32)); p32++; + state->v2 = XXH32_round(state->v2, XXH_readLE32(p32)); p32++; + state->v3 = XXH32_round(state->v3, XXH_readLE32(p32)); p32++; + state->v4 = XXH32_round(state->v4, XXH_readLE32(p32)); + } + p += 16-state->memsize; + state->memsize = 0; + } + + if (p <= bEnd-16) { + const xxh_u8* const limit = bEnd - 16; + xxh_u32 v1 = state->v1; + xxh_u32 v2 = state->v2; + xxh_u32 v3 = state->v3; + xxh_u32 v4 = state->v4; + + do { + v1 = XXH32_round(v1, XXH_readLE32(p)); p+=4; + v2 = XXH32_round(v2, XXH_readLE32(p)); p+=4; + v3 = XXH32_round(v3, XXH_readLE32(p)); p+=4; + v4 = XXH32_round(v4, XXH_readLE32(p)); p+=4; + } while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) { + XXH_memcpy(state->mem32, p, (size_t)(bEnd-p)); + state->memsize = (unsigned)(bEnd-p); + } + } + + return XXH_OK; +} + + +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH32_hash_t XXH32_digest(const XXH32_state_t* state) +{ + xxh_u32 h32; + + if (state->large_len) { + h32 = XXH_rotl32(state->v1, 1) + + XXH_rotl32(state->v2, 7) + + XXH_rotl32(state->v3, 12) + + XXH_rotl32(state->v4, 18); + } else { + h32 = state->v3 /* == seed */ + XXH_PRIME32_5; + } + + h32 += state->total_len_32; + + return XXH32_finalize(h32, (const xxh_u8*)state->mem32, state->memsize, XXH_aligned); +} + + +/******* Canonical representation *******/ + +/*! + * @ingroup xxh32_family + * The default return values from XXH functions are unsigned 32 and 64 bit + * integers. + * + * The canonical representation uses big endian convention, the same convention + * as human-readable numbers (large digits first). + * + * This way, hash values can be written into a file or buffer, remaining + * comparable across different systems. + * + * The following functions allow transformation of hash values to and from their + * canonical format. + */ +XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash); + memcpy(dst, &hash, sizeof(*dst)); +} +/*! @ingroup xxh32_family */ +XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src) +{ + return XXH_readBE32(src); +} + + +#ifndef XXH_NO_LONG_LONG + +/* ******************************************************************* +* 64-bit hash functions +*********************************************************************/ +/*! + * @} + * @ingroup impl + * @{ + */ +/******* Memory access *******/ + +typedef XXH64_hash_t xxh_u64; + +#ifdef XXH_OLD_NAMES +# define U64 xxh_u64 +#endif + +/*! + * XXH_REROLL_XXH64: + * Whether to reroll the XXH64_finalize() loop. + * + * Just like XXH32, we can unroll the XXH64_finalize() loop. This can be a + * performance gain on 64-bit hosts, as only one jump is required. + * + * However, on 32-bit hosts, because arithmetic needs to be done with two 32-bit + * registers, and 64-bit arithmetic needs to be simulated, it isn't beneficial + * to unroll. The code becomes ridiculously large (the largest function in the + * binary on i386!), and rerolling it saves anywhere from 3kB to 20kB. It is + * also slightly faster because it fits into cache better and is more likely + * to be inlined by the compiler. + * + * If XXH_REROLL is defined, this is ignored and the loop is always rerolled. + */ +#ifndef XXH_REROLL_XXH64 +# if (defined(__ILP32__) || defined(_ILP32)) /* ILP32 is often defined on 32-bit GCC family */ \ + || !(defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) /* x86-64 */ \ + || defined(_M_ARM64) || defined(__aarch64__) || defined(__arm64__) /* aarch64 */ \ + || defined(__PPC64__) || defined(__PPC64LE__) || defined(__ppc64__) || defined(__powerpc64__) /* ppc64 */ \ + || defined(__mips64__) || defined(__mips64)) /* mips64 */ \ + || (!defined(SIZE_MAX) || SIZE_MAX < ULLONG_MAX) /* check limits */ +# define XXH_REROLL_XXH64 1 +# else +# define XXH_REROLL_XXH64 0 +# endif +#endif /* !defined(XXH_REROLL_XXH64) */ + +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) +/* + * Manual byteshift. Best for old compilers which don't inline memcpy. + * We actually directly use XXH_readLE64 and XXH_readBE64. + */ +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) + +/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */ +static xxh_u64 XXH_read64(const void* memPtr) +{ + return *(const xxh_u64*) memPtr; +} + +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) + +/* + * __pack instructions are safer, but compiler specific, hence potentially + * problematic for some compilers. + * + * Currently only defined for GCC and ICC. + */ +#ifdef XXH_OLD_NAMES +typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((packed)) unalign64; +#endif +static xxh_u64 XXH_read64(const void* ptr) +{ + typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((packed)) xxh_unalign64; + return ((const xxh_unalign64*)ptr)->u64; +} + +#else + +/* + * Portable and safe solution. Generally efficient. + * see: https://stackoverflow.com/a/32095106/646947 + */ +static xxh_u64 XXH_read64(const void* memPtr) +{ + xxh_u64 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */ + +#if defined(_MSC_VER) /* Visual Studio */ +# define XXH_swap64 _byteswap_uint64 +#elif XXH_GCC_VERSION >= 403 +# define XXH_swap64 __builtin_bswap64 +#else +static xxh_u64 XXH_swap64(xxh_u64 x) +{ + return ((x << 56) & 0xff00000000000000ULL) | + ((x << 40) & 0x00ff000000000000ULL) | + ((x << 24) & 0x0000ff0000000000ULL) | + ((x << 8) & 0x000000ff00000000ULL) | + ((x >> 8) & 0x00000000ff000000ULL) | + ((x >> 24) & 0x0000000000ff0000ULL) | + ((x >> 40) & 0x000000000000ff00ULL) | + ((x >> 56) & 0x00000000000000ffULL); +} +#endif + + +/* XXH_FORCE_MEMORY_ACCESS==3 is an endian-independent byteshift load. */ +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) + +XXH_FORCE_INLINE xxh_u64 XXH_readLE64(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[0] + | ((xxh_u64)bytePtr[1] << 8) + | ((xxh_u64)bytePtr[2] << 16) + | ((xxh_u64)bytePtr[3] << 24) + | ((xxh_u64)bytePtr[4] << 32) + | ((xxh_u64)bytePtr[5] << 40) + | ((xxh_u64)bytePtr[6] << 48) + | ((xxh_u64)bytePtr[7] << 56); +} + +XXH_FORCE_INLINE xxh_u64 XXH_readBE64(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[7] + | ((xxh_u64)bytePtr[6] << 8) + | ((xxh_u64)bytePtr[5] << 16) + | ((xxh_u64)bytePtr[4] << 24) + | ((xxh_u64)bytePtr[3] << 32) + | ((xxh_u64)bytePtr[2] << 40) + | ((xxh_u64)bytePtr[1] << 48) + | ((xxh_u64)bytePtr[0] << 56); +} + +#else +XXH_FORCE_INLINE xxh_u64 XXH_readLE64(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); +} + +static xxh_u64 XXH_readBE64(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr); +} +#endif + +XXH_FORCE_INLINE xxh_u64 +XXH_readLE64_align(const void* ptr, XXH_alignment align) +{ + if (align==XXH_unaligned) + return XXH_readLE64(ptr); + else + return XXH_CPU_LITTLE_ENDIAN ? *(const xxh_u64*)ptr : XXH_swap64(*(const xxh_u64*)ptr); +} + + +/******* xxh64 *******/ +/*! + * @} + * @defgroup xxh64_impl XXH64 implementation + * @ingroup impl + * @{ + */ +static const xxh_u64 XXH_PRIME64_1 = 0x9E3779B185EBCA87ULL; /*!< 0b1001111000110111011110011011000110000101111010111100101010000111 */ +static const xxh_u64 XXH_PRIME64_2 = 0xC2B2AE3D27D4EB4FULL; /*!< 0b1100001010110010101011100011110100100111110101001110101101001111 */ +static const xxh_u64 XXH_PRIME64_3 = 0x165667B19E3779F9ULL; /*!< 0b0001011001010110011001111011000110011110001101110111100111111001 */ +static const xxh_u64 XXH_PRIME64_4 = 0x85EBCA77C2B2AE63ULL; /*!< 0b1000010111101011110010100111011111000010101100101010111001100011 */ +static const xxh_u64 XXH_PRIME64_5 = 0x27D4EB2F165667C5ULL; /*!< 0b0010011111010100111010110010111100010110010101100110011111000101 */ + +#ifdef XXH_OLD_NAMES +# define PRIME64_1 XXH_PRIME64_1 +# define PRIME64_2 XXH_PRIME64_2 +# define PRIME64_3 XXH_PRIME64_3 +# define PRIME64_4 XXH_PRIME64_4 +# define PRIME64_5 XXH_PRIME64_5 +#endif + +static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input) +{ + acc += input * XXH_PRIME64_2; + acc = XXH_rotl64(acc, 31); + acc *= XXH_PRIME64_1; + return acc; +} + +static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val) +{ + val = XXH64_round(0, val); + acc ^= val; + acc = acc * XXH_PRIME64_1 + XXH_PRIME64_4; + return acc; +} + +static xxh_u64 XXH64_avalanche(xxh_u64 h64) +{ + h64 ^= h64 >> 33; + h64 *= XXH_PRIME64_2; + h64 ^= h64 >> 29; + h64 *= XXH_PRIME64_3; + h64 ^= h64 >> 32; + return h64; +} + + +#define XXH_get64bits(p) XXH_readLE64_align(p, align) + +static xxh_u64 +XXH64_finalize(xxh_u64 h64, const xxh_u8* ptr, size_t len, XXH_alignment align) +{ +#define XXH_PROCESS1_64 do { \ + h64 ^= (*ptr++) * XXH_PRIME64_5; \ + h64 = XXH_rotl64(h64, 11) * XXH_PRIME64_1; \ +} while (0) + +#define XXH_PROCESS4_64 do { \ + h64 ^= (xxh_u64)(XXH_get32bits(ptr)) * XXH_PRIME64_1; \ + ptr += 4; \ + h64 = XXH_rotl64(h64, 23) * XXH_PRIME64_2 + XXH_PRIME64_3; \ +} while (0) + +#define XXH_PROCESS8_64 do { \ + xxh_u64 const k1 = XXH64_round(0, XXH_get64bits(ptr)); \ + ptr += 8; \ + h64 ^= k1; \ + h64 = XXH_rotl64(h64,27) * XXH_PRIME64_1 + XXH_PRIME64_4; \ +} while (0) + + /* Rerolled version for 32-bit targets is faster and much smaller. */ + if (XXH_REROLL || XXH_REROLL_XXH64) { + len &= 31; + while (len >= 8) { + XXH_PROCESS8_64; + len -= 8; + } + if (len >= 4) { + XXH_PROCESS4_64; + len -= 4; + } + while (len > 0) { + XXH_PROCESS1_64; + --len; + } + return XXH64_avalanche(h64); + } else { + switch(len & 31) { + case 24: XXH_PROCESS8_64; + /* fallthrough */ + case 16: XXH_PROCESS8_64; + /* fallthrough */ + case 8: XXH_PROCESS8_64; + return XXH64_avalanche(h64); + + case 28: XXH_PROCESS8_64; + /* fallthrough */ + case 20: XXH_PROCESS8_64; + /* fallthrough */ + case 12: XXH_PROCESS8_64; + /* fallthrough */ + case 4: XXH_PROCESS4_64; + return XXH64_avalanche(h64); + + case 25: XXH_PROCESS8_64; + /* fallthrough */ + case 17: XXH_PROCESS8_64; + /* fallthrough */ + case 9: XXH_PROCESS8_64; + XXH_PROCESS1_64; + return XXH64_avalanche(h64); + + case 29: XXH_PROCESS8_64; + /* fallthrough */ + case 21: XXH_PROCESS8_64; + /* fallthrough */ + case 13: XXH_PROCESS8_64; + /* fallthrough */ + case 5: XXH_PROCESS4_64; + XXH_PROCESS1_64; + return XXH64_avalanche(h64); + + case 26: XXH_PROCESS8_64; + /* fallthrough */ + case 18: XXH_PROCESS8_64; + /* fallthrough */ + case 10: XXH_PROCESS8_64; + XXH_PROCESS1_64; + XXH_PROCESS1_64; + return XXH64_avalanche(h64); + + case 30: XXH_PROCESS8_64; + /* fallthrough */ + case 22: XXH_PROCESS8_64; + /* fallthrough */ + case 14: XXH_PROCESS8_64; + /* fallthrough */ + case 6: XXH_PROCESS4_64; + XXH_PROCESS1_64; + XXH_PROCESS1_64; + return XXH64_avalanche(h64); + + case 27: XXH_PROCESS8_64; + /* fallthrough */ + case 19: XXH_PROCESS8_64; + /* fallthrough */ + case 11: XXH_PROCESS8_64; + XXH_PROCESS1_64; + XXH_PROCESS1_64; + XXH_PROCESS1_64; + return XXH64_avalanche(h64); + + case 31: XXH_PROCESS8_64; + /* fallthrough */ + case 23: XXH_PROCESS8_64; + /* fallthrough */ + case 15: XXH_PROCESS8_64; + /* fallthrough */ + case 7: XXH_PROCESS4_64; + /* fallthrough */ + case 3: XXH_PROCESS1_64; + /* fallthrough */ + case 2: XXH_PROCESS1_64; + /* fallthrough */ + case 1: XXH_PROCESS1_64; + /* fallthrough */ + case 0: return XXH64_avalanche(h64); + } + } + /* impossible to reach */ + XXH_ASSERT(0); + return 0; /* unreachable, but some compilers complain without it */ +} + +#ifdef XXH_OLD_NAMES +# define PROCESS1_64 XXH_PROCESS1_64 +# define PROCESS4_64 XXH_PROCESS4_64 +# define PROCESS8_64 XXH_PROCESS8_64 +#else +# undef XXH_PROCESS1_64 +# undef XXH_PROCESS4_64 +# undef XXH_PROCESS8_64 +#endif + +XXH_FORCE_INLINE xxh_u64 +XXH64_endian_align(const xxh_u8* input, size_t len, xxh_u64 seed, XXH_alignment align) +{ + const xxh_u8* bEnd = input + len; + xxh_u64 h64; + +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + if (input==NULL) { + len=0; + bEnd=input=(const xxh_u8*)(size_t)32; + } +#endif + + if (len>=32) { + const xxh_u8* const limit = bEnd - 32; + xxh_u64 v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + xxh_u64 v2 = seed + XXH_PRIME64_2; + xxh_u64 v3 = seed + 0; + xxh_u64 v4 = seed - XXH_PRIME64_1; + + do { + v1 = XXH64_round(v1, XXH_get64bits(input)); input+=8; + v2 = XXH64_round(v2, XXH_get64bits(input)); input+=8; + v3 = XXH64_round(v3, XXH_get64bits(input)); input+=8; + v4 = XXH64_round(v4, XXH_get64bits(input)); input+=8; + } while (input<=limit); + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + h64 = XXH64_mergeRound(h64, v1); + h64 = XXH64_mergeRound(h64, v2); + h64 = XXH64_mergeRound(h64, v3); + h64 = XXH64_mergeRound(h64, v4); + + } else { + h64 = seed + XXH_PRIME64_5; + } + + h64 += (xxh_u64) len; + + return XXH64_finalize(h64, input, len, align); +} + + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t len, XXH64_hash_t seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH64_state_t state; + XXH64_reset(&state, seed); + XXH64_update(&state, (const xxh_u8*)input, len); + return XXH64_digest(&state); +#else + if (XXH_FORCE_ALIGN_CHECK) { + if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */ + return XXH64_endian_align((const xxh_u8*)input, len, seed, XXH_aligned); + } } + + return XXH64_endian_align((const xxh_u8*)input, len, seed, XXH_unaligned); + +#endif +} + +/******* Hash Streaming *******/ + +/*! @ingroup xxh64_family*/ +XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void) +{ + return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t)); +} +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dstState, const XXH64_state_t* srcState) +{ + memcpy(dstState, srcState, sizeof(*dstState)); +} + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, XXH64_hash_t seed) +{ + XXH64_state_t state; /* use a local state to memcpy() in order to avoid strict-aliasing warnings */ + memset(&state, 0, sizeof(state)); + state.v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + state.v2 = seed + XXH_PRIME64_2; + state.v3 = seed + 0; + state.v4 = seed - XXH_PRIME64_1; + /* do not write into reserved64, might be removed in a future version */ + memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved64)); + return XXH_OK; +} + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH_errorcode +XXH64_update (XXH64_state_t* state, const void* input, size_t len) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* p = (const xxh_u8*)input; + const xxh_u8* const bEnd = p + len; + + state->total_len += len; + + if (state->memsize + len < 32) { /* fill in tmp buffer */ + XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, len); + state->memsize += (xxh_u32)len; + return XXH_OK; + } + + if (state->memsize) { /* tmp buffer is full */ + XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, 32-state->memsize); + state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0)); + state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1)); + state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2)); + state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3)); + p += 32 - state->memsize; + state->memsize = 0; + } + + if (p+32 <= bEnd) { + const xxh_u8* const limit = bEnd - 32; + xxh_u64 v1 = state->v1; + xxh_u64 v2 = state->v2; + xxh_u64 v3 = state->v3; + xxh_u64 v4 = state->v4; + + do { + v1 = XXH64_round(v1, XXH_readLE64(p)); p+=8; + v2 = XXH64_round(v2, XXH_readLE64(p)); p+=8; + v3 = XXH64_round(v3, XXH_readLE64(p)); p+=8; + v4 = XXH64_round(v4, XXH_readLE64(p)); p+=8; + } while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) { + XXH_memcpy(state->mem64, p, (size_t)(bEnd-p)); + state->memsize = (unsigned)(bEnd-p); + } + } + + return XXH_OK; +} + + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH64_hash_t XXH64_digest(const XXH64_state_t* state) +{ + xxh_u64 h64; + + if (state->total_len >= 32) { + xxh_u64 const v1 = state->v1; + xxh_u64 const v2 = state->v2; + xxh_u64 const v3 = state->v3; + xxh_u64 const v4 = state->v4; + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + h64 = XXH64_mergeRound(h64, v1); + h64 = XXH64_mergeRound(h64, v2); + h64 = XXH64_mergeRound(h64, v3); + h64 = XXH64_mergeRound(h64, v4); + } else { + h64 = state->v3 /*seed*/ + XXH_PRIME64_5; + } + + h64 += (xxh_u64) state->total_len; + + return XXH64_finalize(h64, (const xxh_u8*)state->mem64, (size_t)state->total_len, XXH_aligned); +} + + +/******* Canonical representation *******/ + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash); + memcpy(dst, &hash, sizeof(*dst)); +} + +/*! @ingroup xxh64_family */ +XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src) +{ + return XXH_readBE64(src); +} + + + +/* ********************************************************************* +* XXH3 +* New generation hash designed for speed on small keys and vectorization +************************************************************************ */ +/*! + * @} + * @defgroup xxh3_impl XXH3 implementation + * @ingroup impl + * @{ + */ + +/* === Compiler specifics === */ + +#if ((defined(sun) || defined(__sun)) && __cplusplus) /* Solaris includes __STDC_VERSION__ with C++. Tested with GCC 5.5 */ +# define XXH_RESTRICT /* disable */ +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* >= C99 */ +# define XXH_RESTRICT restrict +#else +/* Note: it might be useful to define __restrict or __restrict__ for some C++ compilers */ +# define XXH_RESTRICT /* disable */ +#endif + +#if (defined(__GNUC__) && (__GNUC__ >= 3)) \ + || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \ + || defined(__clang__) +# define XXH_likely(x) __builtin_expect(x, 1) +# define XXH_unlikely(x) __builtin_expect(x, 0) +#else +# define XXH_likely(x) (x) +# define XXH_unlikely(x) (x) +#endif + +#if defined(__GNUC__) +# if defined(__AVX2__) +# include +# elif defined(__SSE2__) +# include +# elif defined(__ARM_NEON__) || defined(__ARM_NEON) +# define inline __inline__ /* circumvent a clang bug */ +# include +# undef inline +# endif +#elif defined(_MSC_VER) +# include +#endif + +/* + * One goal of XXH3 is to make it fast on both 32-bit and 64-bit, while + * remaining a true 64-bit/128-bit hash function. + * + * This is done by prioritizing a subset of 64-bit operations that can be + * emulated without too many steps on the average 32-bit machine. + * + * For example, these two lines seem similar, and run equally fast on 64-bit: + * + * xxh_u64 x; + * x ^= (x >> 47); // good + * x ^= (x >> 13); // bad + * + * However, to a 32-bit machine, there is a major difference. + * + * x ^= (x >> 47) looks like this: + * + * x.lo ^= (x.hi >> (47 - 32)); + * + * while x ^= (x >> 13) looks like this: + * + * // note: funnel shifts are not usually cheap. + * x.lo ^= (x.lo >> 13) | (x.hi << (32 - 13)); + * x.hi ^= (x.hi >> 13); + * + * The first one is significantly faster than the second, simply because the + * shift is larger than 32. This means: + * - All the bits we need are in the upper 32 bits, so we can ignore the lower + * 32 bits in the shift. + * - The shift result will always fit in the lower 32 bits, and therefore, + * we can ignore the upper 32 bits in the xor. + * + * Thanks to this optimization, XXH3 only requires these features to be efficient: + * + * - Usable unaligned access + * - A 32-bit or 64-bit ALU + * - If 32-bit, a decent ADC instruction + * - A 32 or 64-bit multiply with a 64-bit result + * - For the 128-bit variant, a decent byteswap helps short inputs. + * + * The first two are already required by XXH32, and almost all 32-bit and 64-bit + * platforms which can run XXH32 can run XXH3 efficiently. + * + * Thumb-1, the classic 16-bit only subset of ARM's instruction set, is one + * notable exception. + * + * First of all, Thumb-1 lacks support for the UMULL instruction which + * performs the important long multiply. This means numerous __aeabi_lmul + * calls. + * + * Second of all, the 8 functional registers are just not enough. + * Setup for __aeabi_lmul, byteshift loads, pointers, and all arithmetic need + * Lo registers, and this shuffling results in thousands more MOVs than A32. + * + * A32 and T32 don't have this limitation. They can access all 14 registers, + * do a 32->64 multiply with UMULL, and the flexible operand allowing free + * shifts is helpful, too. + * + * Therefore, we do a quick sanity check. + * + * If compiling Thumb-1 for a target which supports ARM instructions, we will + * emit a warning, as it is not a "sane" platform to compile for. + * + * Usually, if this happens, it is because of an accident and you probably need + * to specify -march, as you likely meant to compile for a newer architecture. + * + * Credit: large sections of the vectorial and asm source code paths + * have been contributed by @easyaspi314 + */ +#if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM) +# warning "XXH3 is highly inefficient without ARM or Thumb-2." +#endif + +/* ========================================== + * Vectorization detection + * ========================================== */ + +#ifdef XXH_DOXYGEN +/*! + * @ingroup tuning + * @brief Overrides the vectorization implementation chosen for XXH3. + * + * Can be defined to 0 to disable SIMD or any of the values mentioned in + * @ref XXH_VECTOR_TYPE. + * + * If this is not defined, it uses predefined macros to determine the best + * implementation. + */ +# define XXH_VECTOR XXH_SCALAR +/*! + * @ingroup tuning + * @brief Possible values for @ref XXH_VECTOR. + * + * Note that these are actually implemented as macros. + * + * If this is not defined, it is detected automatically. + * @ref XXH_X86DISPATCH overrides this. + */ +enum XXH_VECTOR_TYPE /* fake enum */ { + XXH_SCALAR = 0, /*!< Portable scalar version */ + XXH_SSE2 = 1, /*!< + * SSE2 for Pentium 4, Opteron, all x86_64. + * + * @note SSE2 is also guaranteed on Windows 10, macOS, and + * Android x86. + */ + XXH_AVX2 = 2, /*!< AVX2 for Haswell and Bulldozer */ + XXH_AVX512 = 3, /*!< AVX512 for Skylake and Icelake */ + XXH_NEON = 4, /*!< NEON for most ARMv7-A and all AArch64 */ + XXH_VSX = 5, /*!< VSX and ZVector for POWER8/z13 (64-bit) */ +}; +/*! + * @ingroup tuning + * @brief Selects the minimum alignment for XXH3's accumulators. + * + * When using SIMD, this should match the alignment reqired for said vector + * type, so, for example, 32 for AVX2. + * + * Default: Auto detected. + */ +# define XXH_ACC_ALIGN 8 +#endif + +/* Actual definition */ +#ifndef XXH_DOXYGEN +# define XXH_SCALAR 0 +# define XXH_SSE2 1 +# define XXH_AVX2 2 +# define XXH_AVX512 3 +# define XXH_NEON 4 +# define XXH_VSX 5 +#endif + +#ifndef XXH_VECTOR /* can be defined on command line */ +# if defined(__AVX512F__) +# define XXH_VECTOR XXH_AVX512 +# elif defined(__AVX2__) +# define XXH_VECTOR XXH_AVX2 +# elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2)) +# define XXH_VECTOR XXH_SSE2 +# elif defined(__GNUC__) /* msvc support maybe later */ \ + && (defined(__ARM_NEON__) || defined(__ARM_NEON)) \ + && (defined(__LITTLE_ENDIAN__) /* We only support little endian NEON */ \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) +# define XXH_VECTOR XXH_NEON +# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \ + || (defined(__s390x__) && defined(__VEC__)) \ + && defined(__GNUC__) /* TODO: IBM XL */ +# define XXH_VECTOR XXH_VSX +# else +# define XXH_VECTOR XXH_SCALAR +# endif +#endif + +/* + * Controls the alignment of the accumulator, + * for compatibility with aligned vector loads, which are usually faster. + */ +#ifndef XXH_ACC_ALIGN +# if defined(XXH_X86DISPATCH) +# define XXH_ACC_ALIGN 64 /* for compatibility with avx512 */ +# elif XXH_VECTOR == XXH_SCALAR /* scalar */ +# define XXH_ACC_ALIGN 8 +# elif XXH_VECTOR == XXH_SSE2 /* sse2 */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_AVX2 /* avx2 */ +# define XXH_ACC_ALIGN 32 +# elif XXH_VECTOR == XXH_NEON /* neon */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_VSX /* vsx */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_AVX512 /* avx512 */ +# define XXH_ACC_ALIGN 64 +# endif +#endif + +#if defined(XXH_X86DISPATCH) || XXH_VECTOR == XXH_SSE2 \ + || XXH_VECTOR == XXH_AVX2 || XXH_VECTOR == XXH_AVX512 +# define XXH_SEC_ALIGN XXH_ACC_ALIGN +#else +# define XXH_SEC_ALIGN 8 +#endif + +/* + * UGLY HACK: + * GCC usually generates the best code with -O3 for xxHash. + * + * However, when targeting AVX2, it is overzealous in its unrolling resulting + * in code roughly 3/4 the speed of Clang. + * + * There are other issues, such as GCC splitting _mm256_loadu_si256 into + * _mm_loadu_si128 + _mm256_inserti128_si256. This is an optimization which + * only applies to Sandy and Ivy Bridge... which don't even support AVX2. + * + * That is why when compiling the AVX2 version, it is recommended to use either + * -O2 -mavx2 -march=haswell + * or + * -O2 -mavx2 -mno-avx256-split-unaligned-load + * for decent performance, or to use Clang instead. + * + * Fortunately, we can control the first one with a pragma that forces GCC into + * -O2, but the other one we can't control without "failed to inline always + * inline function due to target mismatch" warnings. + */ +#if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \ + && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) /* respect -O0 and -Os */ +# pragma GCC push_options +# pragma GCC optimize("-O2") +#endif + + +#if XXH_VECTOR == XXH_NEON +/* + * NEON's setup for vmlal_u32 is a little more complicated than it is on + * SSE2, AVX2, and VSX. + * + * While PMULUDQ and VMULEUW both perform a mask, VMLAL.U32 performs an upcast. + * + * To do the same operation, the 128-bit 'Q' register needs to be split into + * two 64-bit 'D' registers, performing this operation:: + * + * [ a | b ] + * | '---------. .--------' | + * | x | + * | .---------' '--------. | + * [ a & 0xFFFFFFFF | b & 0xFFFFFFFF ],[ a >> 32 | b >> 32 ] + * + * Due to significant changes in aarch64, the fastest method for aarch64 is + * completely different than the fastest method for ARMv7-A. + * + * ARMv7-A treats D registers as unions overlaying Q registers, so modifying + * D11 will modify the high half of Q5. This is similar to how modifying AH + * will only affect bits 8-15 of AX on x86. + * + * VZIP takes two registers, and puts even lanes in one register and odd lanes + * in the other. + * + * On ARMv7-A, this strangely modifies both parameters in place instead of + * taking the usual 3-operand form. + * + * Therefore, if we want to do this, we can simply use a D-form VZIP.32 on the + * lower and upper halves of the Q register to end up with the high and low + * halves where we want - all in one instruction. + * + * vzip.32 d10, d11 @ d10 = { d10[0], d11[0] }; d11 = { d10[1], d11[1] } + * + * Unfortunately we need inline assembly for this: Instructions modifying two + * registers at once is not possible in GCC or Clang's IR, and they have to + * create a copy. + * + * aarch64 requires a different approach. + * + * In order to make it easier to write a decent compiler for aarch64, many + * quirks were removed, such as conditional execution. + * + * NEON was also affected by this. + * + * aarch64 cannot access the high bits of a Q-form register, and writes to a + * D-form register zero the high bits, similar to how writes to W-form scalar + * registers (or DWORD registers on x86_64) work. + * + * The formerly free vget_high intrinsics now require a vext (with a few + * exceptions) + * + * Additionally, VZIP was replaced by ZIP1 and ZIP2, which are the equivalent + * of PUNPCKL* and PUNPCKH* in SSE, respectively, in order to only modify one + * operand. + * + * The equivalent of the VZIP.32 on the lower and upper halves would be this + * mess: + * + * ext v2.4s, v0.4s, v0.4s, #2 // v2 = { v0[2], v0[3], v0[0], v0[1] } + * zip1 v1.2s, v0.2s, v2.2s // v1 = { v0[0], v2[0] } + * zip2 v0.2s, v0.2s, v1.2s // v0 = { v0[1], v2[1] } + * + * Instead, we use a literal downcast, vmovn_u64 (XTN), and vshrn_n_u64 (SHRN): + * + * shrn v1.2s, v0.2d, #32 // v1 = (uint32x2_t)(v0 >> 32); + * xtn v0.2s, v0.2d // v0 = (uint32x2_t)(v0 & 0xFFFFFFFF); + * + * This is available on ARMv7-A, but is less efficient than a single VZIP.32. + */ + +/*! + * Function-like macro: + * void XXH_SPLIT_IN_PLACE(uint64x2_t &in, uint32x2_t &outLo, uint32x2_t &outHi) + * { + * outLo = (uint32x2_t)(in & 0xFFFFFFFF); + * outHi = (uint32x2_t)(in >> 32); + * in = UNDEFINED; + * } + */ +# if !defined(XXH_NO_VZIP_HACK) /* define to disable */ \ + && defined(__GNUC__) \ + && !defined(__aarch64__) && !defined(__arm64__) +# define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \ + do { \ + /* Undocumented GCC/Clang operand modifier: %e0 = lower D half, %f0 = upper D half */ \ + /* https://github.com/gcc-mirror/gcc/blob/38cf91e5/gcc/config/arm/arm.c#L22486 */ \ + /* https://github.com/llvm-mirror/llvm/blob/2c4ca683/lib/Target/ARM/ARMAsmPrinter.cpp#L399 */ \ + __asm__("vzip.32 %e0, %f0" : "+w" (in)); \ + (outLo) = vget_low_u32 (vreinterpretq_u32_u64(in)); \ + (outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \ + } while (0) +# else +# define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \ + do { \ + (outLo) = vmovn_u64 (in); \ + (outHi) = vshrn_n_u64 ((in), 32); \ + } while (0) +# endif +#endif /* XXH_VECTOR == XXH_NEON */ + +/* + * VSX and Z Vector helpers. + * + * This is very messy, and any pull requests to clean this up are welcome. + * + * There are a lot of problems with supporting VSX and s390x, due to + * inconsistent intrinsics, spotty coverage, and multiple endiannesses. + */ +#if XXH_VECTOR == XXH_VSX +# if defined(__s390x__) +# include +# else +/* gcc's altivec.h can have the unwanted consequence to unconditionally + * #define bool, vector, and pixel keywords, + * with bad consequences for programs already using these keywords for other purposes. + * The paragraph defining these macros is skipped when __APPLE_ALTIVEC__ is defined. + * __APPLE_ALTIVEC__ is _generally_ defined automatically by the compiler, + * but it seems that, in some cases, it isn't. + * Force the build macro to be defined, so that keywords are not altered. + */ +# if defined(__GNUC__) && !defined(__APPLE_ALTIVEC__) +# define __APPLE_ALTIVEC__ +# endif +# include +# endif + +typedef __vector unsigned long long xxh_u64x2; +typedef __vector unsigned char xxh_u8x16; +typedef __vector unsigned xxh_u32x4; + +# ifndef XXH_VSX_BE +# if defined(__BIG_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define XXH_VSX_BE 1 +# elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__ +# warning "-maltivec=be is not recommended. Please use native endianness." +# define XXH_VSX_BE 1 +# else +# define XXH_VSX_BE 0 +# endif +# endif /* !defined(XXH_VSX_BE) */ + +# if XXH_VSX_BE +# if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__)) +# define XXH_vec_revb vec_revb +# else +/*! + * A polyfill for POWER9's vec_revb(). + */ +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val) +{ + xxh_u8x16 const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 }; + return vec_perm(val, val, vByteSwap); +} +# endif +# endif /* XXH_VSX_BE */ + +/*! + * Performs an unaligned vector load and byte swaps it on big endian. + */ +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(const void *ptr) +{ + xxh_u64x2 ret; + memcpy(&ret, ptr, sizeof(xxh_u64x2)); +# if XXH_VSX_BE + ret = XXH_vec_revb(ret); +# endif + return ret; +} + +/* + * vec_mulo and vec_mule are very problematic intrinsics on PowerPC + * + * These intrinsics weren't added until GCC 8, despite existing for a while, + * and they are endian dependent. Also, their meaning swap depending on version. + * */ +# if defined(__s390x__) + /* s390x is always big endian, no issue on this platform */ +# define XXH_vec_mulo vec_mulo +# define XXH_vec_mule vec_mule +# elif defined(__clang__) && XXH_HAS_BUILTIN(__builtin_altivec_vmuleuw) +/* Clang has a better way to control this, we can just use the builtin which doesn't swap. */ +# define XXH_vec_mulo __builtin_altivec_vmulouw +# define XXH_vec_mule __builtin_altivec_vmuleuw +# else +/* gcc needs inline assembly */ +/* Adapted from https://github.com/google/highwayhash/blob/master/highwayhash/hh_vsx.h. */ +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4 a, xxh_u32x4 b) +{ + xxh_u64x2 result; + __asm__("vmulouw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b)); + return result; +} +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b) +{ + xxh_u64x2 result; + __asm__("vmuleuw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b)); + return result; +} +# endif /* XXH_vec_mulo, XXH_vec_mule */ +#endif /* XXH_VECTOR == XXH_VSX */ + + +/* prefetch + * can be disabled, by declaring XXH_NO_PREFETCH build macro */ +#if defined(XXH_NO_PREFETCH) +# define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */ +#else +# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) /* _mm_prefetch() not defined outside of x86/x64 */ +# include /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ +# define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) +# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) ) +# define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */) +# else +# define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */ +# endif +#endif /* XXH_NO_PREFETCH */ + + +/* ========================================== + * XXH3 default settings + * ========================================== */ + +#define XXH_SECRET_DEFAULT_SIZE 192 /* minimum XXH3_SECRET_SIZE_MIN */ + +#if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN) +# error "default keyset is not large enough" +#endif + +/*! Pseudorandom secret taken directly from FARSH. */ +XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = { + 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, + 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, + 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, + 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, + 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, + 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, + 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, + 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, + 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, + 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, + 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, + 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, +}; + + +#ifdef XXH_OLD_NAMES +# define kSecret XXH3_kSecret +#endif + +#ifdef XXH_DOXYGEN +/*! + * @brief Calculates a 32-bit to 64-bit long multiply. + * + * Implemented as a macro. + * + * Wraps `__emulu` on MSVC x86 because it tends to call `__allmul` when it doesn't + * need to (but it shouldn't need to anyways, it is about 7 instructions to do + * a 64x64 multiply...). Since we know that this will _always_ emit `MULL`, we + * use that instead of the normal method. + * + * If you are compiling for platforms like Thumb-1 and don't have a better option, + * you may also want to write your own long multiply routine here. + * + * @param x, y Numbers to be multiplied + * @return 64-bit product of the low 32 bits of @p x and @p y. + */ +XXH_FORCE_INLINE xxh_u64 +XXH_mult32to64(xxh_u64 x, xxh_u64 y) +{ + return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF); +} +#elif defined(_MSC_VER) && defined(_M_IX86) +# include +# define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y)) +#else +/* + * Downcast + upcast is usually better than masking on older compilers like + * GCC 4.2 (especially 32-bit ones), all without affecting newer compilers. + * + * The other method, (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF), will AND both operands + * and perform a full 64x64 multiply -- entirely redundant on 32-bit. + */ +# define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y)) +#endif + +/*! + * @brief Calculates a 64->128-bit long multiply. + * + * Uses `__uint128_t` and `_umul128` if available, otherwise uses a scalar + * version. + * + * @param lhs, rhs The 64-bit integers to be multiplied + * @return The 128-bit result represented in an @ref XXH128_hash_t. + */ +static XXH128_hash_t +XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs) +{ + /* + * GCC/Clang __uint128_t method. + * + * On most 64-bit targets, GCC and Clang define a __uint128_t type. + * This is usually the best way as it usually uses a native long 64-bit + * multiply, such as MULQ on x86_64 or MUL + UMULH on aarch64. + * + * Usually. + * + * Despite being a 32-bit platform, Clang (and emscripten) define this type + * despite not having the arithmetic for it. This results in a laggy + * compiler builtin call which calculates a full 128-bit multiply. + * In that case it is best to use the portable one. + * https://github.com/Cyan4973/xxHash/issues/211#issuecomment-515575677 + */ +#if defined(__GNUC__) && !defined(__wasm__) \ + && defined(__SIZEOF_INT128__) \ + || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128) + + __uint128_t const product = (__uint128_t)lhs * (__uint128_t)rhs; + XXH128_hash_t r128; + r128.low64 = (xxh_u64)(product); + r128.high64 = (xxh_u64)(product >> 64); + return r128; + + /* + * MSVC for x64's _umul128 method. + * + * xxh_u64 _umul128(xxh_u64 Multiplier, xxh_u64 Multiplicand, xxh_u64 *HighProduct); + * + * This compiles to single operand MUL on x64. + */ +#elif defined(_M_X64) || defined(_M_IA64) + +#ifndef _MSC_VER +# pragma intrinsic(_umul128) +#endif + xxh_u64 product_high; + xxh_u64 const product_low = _umul128(lhs, rhs, &product_high); + XXH128_hash_t r128; + r128.low64 = product_low; + r128.high64 = product_high; + return r128; + +#else + /* + * Portable scalar method. Optimized for 32-bit and 64-bit ALUs. + * + * This is a fast and simple grade school multiply, which is shown below + * with base 10 arithmetic instead of base 0x100000000. + * + * 9 3 // D2 lhs = 93 + * x 7 5 // D2 rhs = 75 + * ---------- + * 1 5 // D2 lo_lo = (93 % 10) * (75 % 10) = 15 + * 4 5 | // D2 hi_lo = (93 / 10) * (75 % 10) = 45 + * 2 1 | // D2 lo_hi = (93 % 10) * (75 / 10) = 21 + * + 6 3 | | // D2 hi_hi = (93 / 10) * (75 / 10) = 63 + * --------- + * 2 7 | // D2 cross = (15 / 10) + (45 % 10) + 21 = 27 + * + 6 7 | | // D2 upper = (27 / 10) + (45 / 10) + 63 = 67 + * --------- + * 6 9 7 5 // D4 res = (27 * 10) + (15 % 10) + (67 * 100) = 6975 + * + * The reasons for adding the products like this are: + * 1. It avoids manual carry tracking. Just like how + * (9 * 9) + 9 + 9 = 99, the same applies with this for UINT64_MAX. + * This avoids a lot of complexity. + * + * 2. It hints for, and on Clang, compiles to, the powerful UMAAL + * instruction available in ARM's Digital Signal Processing extension + * in 32-bit ARMv6 and later, which is shown below: + * + * void UMAAL(xxh_u32 *RdLo, xxh_u32 *RdHi, xxh_u32 Rn, xxh_u32 Rm) + * { + * xxh_u64 product = (xxh_u64)*RdLo * (xxh_u64)*RdHi + Rn + Rm; + * *RdLo = (xxh_u32)(product & 0xFFFFFFFF); + * *RdHi = (xxh_u32)(product >> 32); + * } + * + * This instruction was designed for efficient long multiplication, and + * allows this to be calculated in only 4 instructions at speeds + * comparable to some 64-bit ALUs. + * + * 3. It isn't terrible on other platforms. Usually this will be a couple + * of 32-bit ADD/ADCs. + */ + + /* First calculate all of the cross products. */ + xxh_u64 const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF); + xxh_u64 const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF); + xxh_u64 const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32); + xxh_u64 const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32); + + /* Now add the products together. These will never overflow. */ + xxh_u64 const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi; + xxh_u64 const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi; + xxh_u64 const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF); + + XXH128_hash_t r128; + r128.low64 = lower; + r128.high64 = upper; + return r128; +#endif +} + +/*! + * @brief Calculates a 64-bit to 128-bit multiply, then XOR folds it. + * + * The reason for the separate function is to prevent passing too many structs + * around by value. This will hopefully inline the multiply, but we don't force it. + * + * @param lhs, rhs The 64-bit integers to multiply + * @return The low 64 bits of the product XOR'd by the high 64 bits. + * @see XXH_mult64to128() + */ +static xxh_u64 +XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs) +{ + XXH128_hash_t product = XXH_mult64to128(lhs, rhs); + return product.low64 ^ product.high64; +} + +/*! Seems to produce slightly better code on GCC for some reason. */ +XXH_FORCE_INLINE xxh_u64 XXH_xorshift64(xxh_u64 v64, int shift) +{ + XXH_ASSERT(0 <= shift && shift < 64); + return v64 ^ (v64 >> shift); +} + +/* + * This is a fast avalanche stage, + * suitable when input bits are already partially mixed + */ +static XXH64_hash_t XXH3_avalanche(xxh_u64 h64) +{ + h64 = XXH_xorshift64(h64, 37); + h64 *= 0x165667919E3779F9ULL; + h64 = XXH_xorshift64(h64, 32); + return h64; +} + +/* + * This is a stronger avalanche, + * inspired by Pelle Evensen's rrmxmx + * preferable when input has not been previously mixed + */ +static XXH64_hash_t XXH3_rrmxmx(xxh_u64 h64, xxh_u64 len) +{ + /* this mix is inspired by Pelle Evensen's rrmxmx */ + h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24); + h64 *= 0x9FB21C651E98DF25ULL; + h64 ^= (h64 >> 35) + len ; + h64 *= 0x9FB21C651E98DF25ULL; + return XXH_xorshift64(h64, 28); +} + + +/* ========================================== + * Short keys + * ========================================== + * One of the shortcomings of XXH32 and XXH64 was that their performance was + * sub-optimal on short lengths. It used an iterative algorithm which strongly + * favored lengths that were a multiple of 4 or 8. + * + * Instead of iterating over individual inputs, we use a set of single shot + * functions which piece together a range of lengths and operate in constant time. + * + * Additionally, the number of multiplies has been significantly reduced. This + * reduces latency, especially when emulating 64-bit multiplies on 32-bit. + * + * Depending on the platform, this may or may not be faster than XXH32, but it + * is almost guaranteed to be faster than XXH64. + */ + +/* + * At very short lengths, there isn't enough input to fully hide secrets, or use + * the entire secret. + * + * There is also only a limited amount of mixing we can do before significantly + * impacting performance. + * + * Therefore, we use different sections of the secret and always mix two secret + * samples with an XOR. This should have no effect on performance on the + * seedless or withSeed variants because everything _should_ be constant folded + * by modern compilers. + * + * The XOR mixing hides individual parts of the secret and increases entropy. + * + * This adds an extra layer of strength for custom secrets. + */ +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_1to3_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(1 <= len && len <= 3); + XXH_ASSERT(secret != NULL); + /* + * len = 1: combined = { input[0], 0x01, input[0], input[0] } + * len = 2: combined = { input[1], 0x02, input[0], input[1] } + * len = 3: combined = { input[2], 0x03, input[0], input[1] } + */ + { xxh_u8 const c1 = input[0]; + xxh_u8 const c2 = input[len >> 1]; + xxh_u8 const c3 = input[len - 1]; + xxh_u32 const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24) + | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8); + xxh_u64 const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed; + xxh_u64 const keyed = (xxh_u64)combined ^ bitflip; + return XXH64_avalanche(keyed); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_4to8_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(4 <= len && len < 8); + seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32; + { xxh_u32 const input1 = XXH_readLE32(input); + xxh_u32 const input2 = XXH_readLE32(input + len - 4); + xxh_u64 const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed; + xxh_u64 const input64 = input2 + (((xxh_u64)input1) << 32); + xxh_u64 const keyed = input64 ^ bitflip; + return XXH3_rrmxmx(keyed, len); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_9to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(8 <= len && len <= 16); + { xxh_u64 const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed; + xxh_u64 const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed; + xxh_u64 const input_lo = XXH_readLE64(input) ^ bitflip1; + xxh_u64 const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2; + xxh_u64 const acc = len + + XXH_swap64(input_lo) + input_hi + + XXH3_mul128_fold64(input_lo, input_hi); + return XXH3_avalanche(acc); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_0to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(len <= 16); + { if (XXH_likely(len > 8)) return XXH3_len_9to16_64b(input, len, secret, seed); + if (XXH_likely(len >= 4)) return XXH3_len_4to8_64b(input, len, secret, seed); + if (len) return XXH3_len_1to3_64b(input, len, secret, seed); + return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64))); + } +} + +/* + * DISCLAIMER: There are known *seed-dependent* multicollisions here due to + * multiplication by zero, affecting hashes of lengths 17 to 240. + * + * However, they are very unlikely. + * + * Keep this in mind when using the unseeded XXH3_64bits() variant: As with all + * unseeded non-cryptographic hashes, it does not attempt to defend itself + * against specially crafted inputs, only random inputs. + * + * Compared to classic UMAC where a 1 in 2^31 chance of 4 consecutive bytes + * cancelling out the secret is taken an arbitrary number of times (addressed + * in XXH3_accumulate_512), this collision is very unlikely with random inputs + * and/or proper seeding: + * + * This only has a 1 in 2^63 chance of 8 consecutive bytes cancelling out, in a + * function that is only called up to 16 times per hash with up to 240 bytes of + * input. + * + * This is not too bad for a non-cryptographic hash function, especially with + * only 64 bit outputs. + * + * The 128-bit variant (which trades some speed for strength) is NOT affected + * by this, although it is always a good idea to use a proper seed if you care + * about strength. + */ +XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(const xxh_u8* XXH_RESTRICT input, + const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64) +{ +#if defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__i386__) && defined(__SSE2__) /* x86 + SSE2 */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable like XXH32 hack */ + /* + * UGLY HACK: + * GCC for x86 tends to autovectorize the 128-bit multiply, resulting in + * slower code. + * + * By forcing seed64 into a register, we disrupt the cost model and + * cause it to scalarize. See `XXH32_round()` + * + * FIXME: Clang's output is still _much_ faster -- On an AMD Ryzen 3600, + * XXH3_64bits @ len=240 runs at 4.6 GB/s with Clang 9, but 3.3 GB/s on + * GCC 9.2, despite both emitting scalar code. + * + * GCC generates much better scalar code than Clang for the rest of XXH3, + * which is why finding a more optimal codepath is an interest. + */ + __asm__ ("" : "+r" (seed64)); +#endif + { xxh_u64 const input_lo = XXH_readLE64(input); + xxh_u64 const input_hi = XXH_readLE64(input+8); + return XXH3_mul128_fold64( + input_lo ^ (XXH_readLE64(secret) + seed64), + input_hi ^ (XXH_readLE64(secret+8) - seed64) + ); + } +} + +/* For mid range keys, XXH3 uses a Mum-hash variant. */ +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_17to128_64b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(16 < len && len <= 128); + + { xxh_u64 acc = len * XXH_PRIME64_1; + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc += XXH3_mix16B(input+48, secret+96, seed); + acc += XXH3_mix16B(input+len-64, secret+112, seed); + } + acc += XXH3_mix16B(input+32, secret+64, seed); + acc += XXH3_mix16B(input+len-48, secret+80, seed); + } + acc += XXH3_mix16B(input+16, secret+32, seed); + acc += XXH3_mix16B(input+len-32, secret+48, seed); + } + acc += XXH3_mix16B(input+0, secret+0, seed); + acc += XXH3_mix16B(input+len-16, secret+16, seed); + + return XXH3_avalanche(acc); + } +} + +#define XXH3_MIDSIZE_MAX 240 + +XXH_NO_INLINE XXH64_hash_t +XXH3_len_129to240_64b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX); + + #define XXH3_MIDSIZE_STARTOFFSET 3 + #define XXH3_MIDSIZE_LASTOFFSET 17 + + { xxh_u64 acc = len * XXH_PRIME64_1; + int const nbRounds = (int)len / 16; + int i; + for (i=0; i<8; i++) { + acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed); + } + acc = XXH3_avalanche(acc); + XXH_ASSERT(nbRounds >= 8); +#if defined(__clang__) /* Clang */ \ + && (defined(__ARM_NEON) || defined(__ARM_NEON__)) /* NEON */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable */ + /* + * UGLY HACK: + * Clang for ARMv7-A tries to vectorize this loop, similar to GCC x86. + * In everywhere else, it uses scalar code. + * + * For 64->128-bit multiplies, even if the NEON was 100% optimal, it + * would still be slower than UMAAL (see XXH_mult64to128). + * + * Unfortunately, Clang doesn't handle the long multiplies properly and + * converts them to the nonexistent "vmulq_u64" intrinsic, which is then + * scalarized into an ugly mess of VMOV.32 instructions. + * + * This mess is difficult to avoid without turning autovectorization + * off completely, but they are usually relatively minor and/or not + * worth it to fix. + * + * This loop is the easiest to fix, as unlike XXH32, this pragma + * _actually works_ because it is a loop vectorization instead of an + * SLP vectorization. + */ + #pragma clang loop vectorize(disable) +#endif + for (i=8 ; i < nbRounds; i++) { + acc += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed); + } + /* last bytes */ + acc += XXH3_mix16B(input + len - 16, secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed); + return XXH3_avalanche(acc); + } +} + + +/* ======= Long Keys ======= */ + +#define XXH_STRIPE_LEN 64 +#define XXH_SECRET_CONSUME_RATE 8 /* nb of secret bytes consumed at each accumulation */ +#define XXH_ACC_NB (XXH_STRIPE_LEN / sizeof(xxh_u64)) + +#ifdef XXH_OLD_NAMES +# define STRIPE_LEN XXH_STRIPE_LEN +# define ACC_NB XXH_ACC_NB +#endif + +XXH_FORCE_INLINE void XXH_writeLE64(void* dst, xxh_u64 v64) +{ + if (!XXH_CPU_LITTLE_ENDIAN) v64 = XXH_swap64(v64); + memcpy(dst, &v64, sizeof(v64)); +} + +/* Several intrinsic functions below are supposed to accept __int64 as argument, + * as documented in https://software.intel.com/sites/landingpage/IntrinsicsGuide/ . + * However, several environments do not define __int64 type, + * requiring a workaround. + */ +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) + typedef int64_t xxh_i64; +#else + /* the following type must have a width of 64-bit */ + typedef long long xxh_i64; +#endif + +/* + * XXH3_accumulate_512 is the tightest loop for long inputs, and it is the most optimized. + * + * It is a hardened version of UMAC, based off of FARSH's implementation. + * + * This was chosen because it adapts quite well to 32-bit, 64-bit, and SIMD + * implementations, and it is ridiculously fast. + * + * We harden it by mixing the original input to the accumulators as well as the product. + * + * This means that in the (relatively likely) case of a multiply by zero, the + * original input is preserved. + * + * On 128-bit inputs, we swap 64-bit pairs when we add the input to improve + * cross-pollination, as otherwise the upper and lower halves would be + * essentially independent. + * + * This doesn't matter on 64-bit hashes since they all get merged together in + * the end, so we skip the extra step. + * + * Both XXH3_64bits and XXH3_128bits use this subroutine. + */ + +#if (XXH_VECTOR == XXH_AVX512) \ + || (defined(XXH_DISPATCH_AVX512) && XXH_DISPATCH_AVX512 != 0) + +#ifndef XXH_TARGET_AVX512 +# define XXH_TARGET_AVX512 /* disable attribute target */ +#endif + +XXH_FORCE_INLINE XXH_TARGET_AVX512 void +XXH3_accumulate_512_avx512(void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + XXH_ALIGN(64) __m512i* const xacc = (__m512i *) acc; + XXH_ASSERT((((size_t)acc) & 63) == 0); + XXH_STATIC_ASSERT(XXH_STRIPE_LEN == sizeof(__m512i)); + + { + /* data_vec = input[0]; */ + __m512i const data_vec = _mm512_loadu_si512 (input); + /* key_vec = secret[0]; */ + __m512i const key_vec = _mm512_loadu_si512 (secret); + /* data_key = data_vec ^ key_vec; */ + __m512i const data_key = _mm512_xor_si512 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m512i const data_key_lo = _mm512_shuffle_epi32 (data_key, (_MM_PERM_ENUM)_MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m512i const product = _mm512_mul_epu32 (data_key, data_key_lo); + /* xacc[0] += swap(data_vec); */ + __m512i const data_swap = _mm512_shuffle_epi32(data_vec, (_MM_PERM_ENUM)_MM_SHUFFLE(1, 0, 3, 2)); + __m512i const sum = _mm512_add_epi64(*xacc, data_swap); + /* xacc[0] += product; */ + *xacc = _mm512_add_epi64(product, sum); + } +} + +/* + * XXH3_scrambleAcc: Scrambles the accumulators to improve mixing. + * + * Multiplication isn't perfect, as explained by Google in HighwayHash: + * + * // Multiplication mixes/scrambles bytes 0-7 of the 64-bit result to + * // varying degrees. In descending order of goodness, bytes + * // 3 4 2 5 1 6 0 7 have quality 228 224 164 160 100 96 36 32. + * // As expected, the upper and lower bytes are much worse. + * + * Source: https://github.com/google/highwayhash/blob/0aaf66b/highwayhash/hh_avx2.h#L291 + * + * Since our algorithm uses a pseudorandom secret to add some variance into the + * mix, we don't need to (or want to) mix as often or as much as HighwayHash does. + * + * This isn't as tight as XXH3_accumulate, but still written in SIMD to avoid + * extraction. + * + * Both XXH3_64bits and XXH3_128bits use this subroutine. + */ + +XXH_FORCE_INLINE XXH_TARGET_AVX512 void +XXH3_scrambleAcc_avx512(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 63) == 0); + XXH_STATIC_ASSERT(XXH_STRIPE_LEN == sizeof(__m512i)); + { XXH_ALIGN(64) __m512i* const xacc = (__m512i*) acc; + const __m512i prime32 = _mm512_set1_epi32((int)XXH_PRIME32_1); + + /* xacc[0] ^= (xacc[0] >> 47) */ + __m512i const acc_vec = *xacc; + __m512i const shifted = _mm512_srli_epi64 (acc_vec, 47); + __m512i const data_vec = _mm512_xor_si512 (acc_vec, shifted); + /* xacc[0] ^= secret; */ + __m512i const key_vec = _mm512_loadu_si512 (secret); + __m512i const data_key = _mm512_xor_si512 (data_vec, key_vec); + + /* xacc[0] *= XXH_PRIME32_1; */ + __m512i const data_key_hi = _mm512_shuffle_epi32 (data_key, (_MM_PERM_ENUM)_MM_SHUFFLE(0, 3, 0, 1)); + __m512i const prod_lo = _mm512_mul_epu32 (data_key, prime32); + __m512i const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32); + *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32)); + } +} + +XXH_FORCE_INLINE XXH_TARGET_AVX512 void +XXH3_initCustomSecret_avx512(void* XXH_RESTRICT customSecret, xxh_u64 seed64) +{ + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 63) == 0); + XXH_STATIC_ASSERT(XXH_SEC_ALIGN == 64); + XXH_ASSERT(((size_t)customSecret & 63) == 0); + (void)(&XXH_writeLE64); + { int const nbRounds = XXH_SECRET_DEFAULT_SIZE / sizeof(__m512i); + __m512i const seed = _mm512_mask_set1_epi64(_mm512_set1_epi64((xxh_i64)seed64), 0xAA, -(xxh_i64)seed64); + + XXH_ALIGN(64) const __m512i* const src = (const __m512i*) XXH3_kSecret; + XXH_ALIGN(64) __m512i* const dest = ( __m512i*) customSecret; + int i; + for (i=0; i < nbRounds; ++i) { + /* GCC has a bug, _mm512_stream_load_si512 accepts 'void*', not 'void const*', + * this will warn "discards ‘const’ qualifier". */ + union { + XXH_ALIGN(64) const __m512i* cp; + XXH_ALIGN(64) void* p; + } remote_const_void; + remote_const_void.cp = src + i; + dest[i] = _mm512_add_epi64(_mm512_stream_load_si512(remote_const_void.p), seed); + } } +} + +#endif + +#if (XXH_VECTOR == XXH_AVX2) \ + || (defined(XXH_DISPATCH_AVX2) && XXH_DISPATCH_AVX2 != 0) + +#ifndef XXH_TARGET_AVX2 +# define XXH_TARGET_AVX2 /* disable attribute target */ +#endif + +XXH_FORCE_INLINE XXH_TARGET_AVX2 void +XXH3_accumulate_512_avx2( void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 31) == 0); + { XXH_ALIGN(32) __m256i* const xacc = (__m256i *) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xinput = (const __m256i *) input; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xsecret = (const __m256i *) secret; + + size_t i; + for (i=0; i < XXH_STRIPE_LEN/sizeof(__m256i); i++) { + /* data_vec = xinput[i]; */ + __m256i const data_vec = _mm256_loadu_si256 (xinput+i); + /* key_vec = xsecret[i]; */ + __m256i const key_vec = _mm256_loadu_si256 (xsecret+i); + /* data_key = data_vec ^ key_vec; */ + __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m256i const data_key_lo = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m256i const product = _mm256_mul_epu32 (data_key, data_key_lo); + /* xacc[i] += swap(data_vec); */ + __m256i const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2)); + __m256i const sum = _mm256_add_epi64(xacc[i], data_swap); + /* xacc[i] += product; */ + xacc[i] = _mm256_add_epi64(product, sum); + } } +} + +XXH_FORCE_INLINE XXH_TARGET_AVX2 void +XXH3_scrambleAcc_avx2(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 31) == 0); + { XXH_ALIGN(32) __m256i* const xacc = (__m256i*) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xsecret = (const __m256i *) secret; + const __m256i prime32 = _mm256_set1_epi32((int)XXH_PRIME32_1); + + size_t i; + for (i=0; i < XXH_STRIPE_LEN/sizeof(__m256i); i++) { + /* xacc[i] ^= (xacc[i] >> 47) */ + __m256i const acc_vec = xacc[i]; + __m256i const shifted = _mm256_srli_epi64 (acc_vec, 47); + __m256i const data_vec = _mm256_xor_si256 (acc_vec, shifted); + /* xacc[i] ^= xsecret; */ + __m256i const key_vec = _mm256_loadu_si256 (xsecret+i); + __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec); + + /* xacc[i] *= XXH_PRIME32_1; */ + __m256i const data_key_hi = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + __m256i const prod_lo = _mm256_mul_epu32 (data_key, prime32); + __m256i const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32); + xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32)); + } + } +} + +XXH_FORCE_INLINE XXH_TARGET_AVX2 void XXH3_initCustomSecret_avx2(void* XXH_RESTRICT customSecret, xxh_u64 seed64) +{ + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 31) == 0); + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE / sizeof(__m256i)) == 6); + XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64); + (void)(&XXH_writeLE64); + XXH_PREFETCH(customSecret); + { __m256i const seed = _mm256_set_epi64x(-(xxh_i64)seed64, (xxh_i64)seed64, -(xxh_i64)seed64, (xxh_i64)seed64); + + XXH_ALIGN(64) const __m256i* const src = (const __m256i*) XXH3_kSecret; + XXH_ALIGN(64) __m256i* dest = ( __m256i*) customSecret; + +# if defined(__GNUC__) || defined(__clang__) + /* + * On GCC & Clang, marking 'dest' as modified will cause the compiler: + * - do not extract the secret from sse registers in the internal loop + * - use less common registers, and avoid pushing these reg into stack + * The asm hack causes Clang to assume that XXH3_kSecretPtr aliases with + * customSecret, and on aarch64, this prevented LDP from merging two + * loads together for free. Putting the loads together before the stores + * properly generates LDP. + */ + __asm__("" : "+r" (dest)); +# endif + + /* GCC -O2 need unroll loop manually */ + dest[0] = _mm256_add_epi64(_mm256_stream_load_si256(src+0), seed); + dest[1] = _mm256_add_epi64(_mm256_stream_load_si256(src+1), seed); + dest[2] = _mm256_add_epi64(_mm256_stream_load_si256(src+2), seed); + dest[3] = _mm256_add_epi64(_mm256_stream_load_si256(src+3), seed); + dest[4] = _mm256_add_epi64(_mm256_stream_load_si256(src+4), seed); + dest[5] = _mm256_add_epi64(_mm256_stream_load_si256(src+5), seed); + } +} + +#endif + +/* x86dispatch always generates SSE2 */ +#if (XXH_VECTOR == XXH_SSE2) || defined(XXH_X86DISPATCH) + +#ifndef XXH_TARGET_SSE2 +# define XXH_TARGET_SSE2 /* disable attribute target */ +#endif + +XXH_FORCE_INLINE XXH_TARGET_SSE2 void +XXH3_accumulate_512_sse2( void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + /* SSE2 is just a half-scale version of the AVX2 version. */ + XXH_ASSERT((((size_t)acc) & 15) == 0); + { XXH_ALIGN(16) __m128i* const xacc = (__m128i *) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xinput = (const __m128i *) input; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xsecret = (const __m128i *) secret; + + size_t i; + for (i=0; i < XXH_STRIPE_LEN/sizeof(__m128i); i++) { + /* data_vec = xinput[i]; */ + __m128i const data_vec = _mm_loadu_si128 (xinput+i); + /* key_vec = xsecret[i]; */ + __m128i const key_vec = _mm_loadu_si128 (xsecret+i); + /* data_key = data_vec ^ key_vec; */ + __m128i const data_key = _mm_xor_si128 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m128i const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m128i const product = _mm_mul_epu32 (data_key, data_key_lo); + /* xacc[i] += swap(data_vec); */ + __m128i const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2)); + __m128i const sum = _mm_add_epi64(xacc[i], data_swap); + /* xacc[i] += product; */ + xacc[i] = _mm_add_epi64(product, sum); + } } +} + +XXH_FORCE_INLINE XXH_TARGET_SSE2 void +XXH3_scrambleAcc_sse2(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 15) == 0); + { XXH_ALIGN(16) __m128i* const xacc = (__m128i*) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xsecret = (const __m128i *) secret; + const __m128i prime32 = _mm_set1_epi32((int)XXH_PRIME32_1); + + size_t i; + for (i=0; i < XXH_STRIPE_LEN/sizeof(__m128i); i++) { + /* xacc[i] ^= (xacc[i] >> 47) */ + __m128i const acc_vec = xacc[i]; + __m128i const shifted = _mm_srli_epi64 (acc_vec, 47); + __m128i const data_vec = _mm_xor_si128 (acc_vec, shifted); + /* xacc[i] ^= xsecret[i]; */ + __m128i const key_vec = _mm_loadu_si128 (xsecret+i); + __m128i const data_key = _mm_xor_si128 (data_vec, key_vec); + + /* xacc[i] *= XXH_PRIME32_1; */ + __m128i const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + __m128i const prod_lo = _mm_mul_epu32 (data_key, prime32); + __m128i const prod_hi = _mm_mul_epu32 (data_key_hi, prime32); + xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32)); + } + } +} + +XXH_FORCE_INLINE XXH_TARGET_SSE2 void XXH3_initCustomSecret_sse2(void* XXH_RESTRICT customSecret, xxh_u64 seed64) +{ + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0); + (void)(&XXH_writeLE64); + { int const nbRounds = XXH_SECRET_DEFAULT_SIZE / sizeof(__m128i); + +# if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER < 1900 + // MSVC 32bit mode does not support _mm_set_epi64x before 2015 + XXH_ALIGN(16) const xxh_i64 seed64x2[2] = { (xxh_i64)seed64, -(xxh_i64)seed64 }; + __m128i const seed = _mm_load_si128((__m128i const*)seed64x2); +# else + __m128i const seed = _mm_set_epi64x(-(xxh_i64)seed64, (xxh_i64)seed64); +# endif + int i; + + XXH_ALIGN(64) const float* const src = (float const*) XXH3_kSecret; + XXH_ALIGN(XXH_SEC_ALIGN) __m128i* dest = (__m128i*) customSecret; +# if defined(__GNUC__) || defined(__clang__) + /* + * On GCC & Clang, marking 'dest' as modified will cause the compiler: + * - do not extract the secret from sse registers in the internal loop + * - use less common registers, and avoid pushing these reg into stack + */ + __asm__("" : "+r" (dest)); +# endif + + for (i=0; i < nbRounds; ++i) { + dest[i] = _mm_add_epi64(_mm_castps_si128(_mm_load_ps(src+i*4)), seed); + } } +} + +#endif + +#if (XXH_VECTOR == XXH_NEON) + +XXH_FORCE_INLINE void +XXH3_accumulate_512_neon( void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 15) == 0); + { + XXH_ALIGN(16) uint64x2_t* const xacc = (uint64x2_t *) acc; + /* We don't use a uint32x4_t pointer because it causes bus errors on ARMv7. */ + uint8_t const* const xinput = (const uint8_t *) input; + uint8_t const* const xsecret = (const uint8_t *) secret; + + size_t i; + for (i=0; i < XXH_STRIPE_LEN / sizeof(uint64x2_t); i++) { + /* data_vec = xinput[i]; */ + uint8x16_t data_vec = vld1q_u8(xinput + (i * 16)); + /* key_vec = xsecret[i]; */ + uint8x16_t key_vec = vld1q_u8(xsecret + (i * 16)); + uint64x2_t data_key; + uint32x2_t data_key_lo, data_key_hi; + /* xacc[i] += swap(data_vec); */ + uint64x2_t const data64 = vreinterpretq_u64_u8(data_vec); + uint64x2_t const swapped = vextq_u64(data64, data64, 1); + xacc[i] = vaddq_u64 (xacc[i], swapped); + /* data_key = data_vec ^ key_vec; */ + data_key = vreinterpretq_u64_u8(veorq_u8(data_vec, key_vec)); + /* data_key_lo = (uint32x2_t) (data_key & 0xFFFFFFFF); + * data_key_hi = (uint32x2_t) (data_key >> 32); + * data_key = UNDEFINED; */ + XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi); + /* xacc[i] += (uint64x2_t) data_key_lo * (uint64x2_t) data_key_hi; */ + xacc[i] = vmlal_u32 (xacc[i], data_key_lo, data_key_hi); + + } + } +} + +XXH_FORCE_INLINE void +XXH3_scrambleAcc_neon(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 15) == 0); + + { uint64x2_t* xacc = (uint64x2_t*) acc; + uint8_t const* xsecret = (uint8_t const*) secret; + uint32x2_t prime = vdup_n_u32 (XXH_PRIME32_1); + + size_t i; + for (i=0; i < XXH_STRIPE_LEN/sizeof(uint64x2_t); i++) { + /* xacc[i] ^= (xacc[i] >> 47); */ + uint64x2_t acc_vec = xacc[i]; + uint64x2_t shifted = vshrq_n_u64 (acc_vec, 47); + uint64x2_t data_vec = veorq_u64 (acc_vec, shifted); + + /* xacc[i] ^= xsecret[i]; */ + uint8x16_t key_vec = vld1q_u8(xsecret + (i * 16)); + uint64x2_t data_key = veorq_u64(data_vec, vreinterpretq_u64_u8(key_vec)); + + /* xacc[i] *= XXH_PRIME32_1 */ + uint32x2_t data_key_lo, data_key_hi; + /* data_key_lo = (uint32x2_t) (xacc[i] & 0xFFFFFFFF); + * data_key_hi = (uint32x2_t) (xacc[i] >> 32); + * xacc[i] = UNDEFINED; */ + XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi); + { /* + * prod_hi = (data_key >> 32) * XXH_PRIME32_1; + * + * Avoid vmul_u32 + vshll_n_u32 since Clang 6 and 7 will + * incorrectly "optimize" this: + * tmp = vmul_u32(vmovn_u64(a), vmovn_u64(b)); + * shifted = vshll_n_u32(tmp, 32); + * to this: + * tmp = "vmulq_u64"(a, b); // no such thing! + * shifted = vshlq_n_u64(tmp, 32); + * + * However, unlike SSE, Clang lacks a 64-bit multiply routine + * for NEON, and it scalarizes two 64-bit multiplies instead. + * + * vmull_u32 has the same timing as vmul_u32, and it avoids + * this bug completely. + * See https://bugs.llvm.org/show_bug.cgi?id=39967 + */ + uint64x2_t prod_hi = vmull_u32 (data_key_hi, prime); + /* xacc[i] = prod_hi << 32; */ + xacc[i] = vshlq_n_u64(prod_hi, 32); + /* xacc[i] += (prod_hi & 0xFFFFFFFF) * XXH_PRIME32_1; */ + xacc[i] = vmlal_u32(xacc[i], data_key_lo, prime); + } + } } +} + +#endif + +#if (XXH_VECTOR == XXH_VSX) + +XXH_FORCE_INLINE void +XXH3_accumulate_512_vsx( void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + xxh_u64x2* const xacc = (xxh_u64x2*) acc; /* presumed aligned */ + xxh_u64x2 const* const xinput = (xxh_u64x2 const*) input; /* no alignment restriction */ + xxh_u64x2 const* const xsecret = (xxh_u64x2 const*) secret; /* no alignment restriction */ + xxh_u64x2 const v32 = { 32, 32 }; + size_t i; + for (i = 0; i < XXH_STRIPE_LEN / sizeof(xxh_u64x2); i++) { + /* data_vec = xinput[i]; */ + xxh_u64x2 const data_vec = XXH_vec_loadu(xinput + i); + /* key_vec = xsecret[i]; */ + xxh_u64x2 const key_vec = XXH_vec_loadu(xsecret + i); + xxh_u64x2 const data_key = data_vec ^ key_vec; + /* shuffled = (data_key << 32) | (data_key >> 32); */ + xxh_u32x4 const shuffled = (xxh_u32x4)vec_rl(data_key, v32); + /* product = ((xxh_u64x2)data_key & 0xFFFFFFFF) * ((xxh_u64x2)shuffled & 0xFFFFFFFF); */ + xxh_u64x2 const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled); + xacc[i] += product; + + /* swap high and low halves */ +#ifdef __s390x__ + xacc[i] += vec_permi(data_vec, data_vec, 2); +#else + xacc[i] += vec_xxpermdi(data_vec, data_vec, 2); +#endif + } +} + +XXH_FORCE_INLINE void +XXH3_scrambleAcc_vsx(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ASSERT((((size_t)acc) & 15) == 0); + + { xxh_u64x2* const xacc = (xxh_u64x2*) acc; + const xxh_u64x2* const xsecret = (const xxh_u64x2*) secret; + /* constants */ + xxh_u64x2 const v32 = { 32, 32 }; + xxh_u64x2 const v47 = { 47, 47 }; + xxh_u32x4 const prime = { XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1 }; + size_t i; + for (i = 0; i < XXH_STRIPE_LEN / sizeof(xxh_u64x2); i++) { + /* xacc[i] ^= (xacc[i] >> 47); */ + xxh_u64x2 const acc_vec = xacc[i]; + xxh_u64x2 const data_vec = acc_vec ^ (acc_vec >> v47); + + /* xacc[i] ^= xsecret[i]; */ + xxh_u64x2 const key_vec = XXH_vec_loadu(xsecret + i); + xxh_u64x2 const data_key = data_vec ^ key_vec; + + /* xacc[i] *= XXH_PRIME32_1 */ + /* prod_lo = ((xxh_u64x2)data_key & 0xFFFFFFFF) * ((xxh_u64x2)prime & 0xFFFFFFFF); */ + xxh_u64x2 const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime); + /* prod_hi = ((xxh_u64x2)data_key >> 32) * ((xxh_u64x2)prime >> 32); */ + xxh_u64x2 const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime); + xacc[i] = prod_odd + (prod_even << v32); + } } +} + +#endif + +/* scalar variants - universal */ + +XXH_FORCE_INLINE void +XXH3_accumulate_512_scalar(void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned */ + const xxh_u8* const xinput = (const xxh_u8*) input; /* no alignment restriction */ + const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */ + size_t i; + XXH_ASSERT(((size_t)acc & (XXH_ACC_ALIGN-1)) == 0); + for (i=0; i < XXH_ACC_NB; i++) { + xxh_u64 const data_val = XXH_readLE64(xinput + 8*i); + xxh_u64 const data_key = data_val ^ XXH_readLE64(xsecret + i*8); + xacc[i ^ 1] += data_val; /* swap adjacent lanes */ + xacc[i] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32); + } +} + +XXH_FORCE_INLINE void +XXH3_scrambleAcc_scalar(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned */ + const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */ + size_t i; + XXH_ASSERT((((size_t)acc) & (XXH_ACC_ALIGN-1)) == 0); + for (i=0; i < XXH_ACC_NB; i++) { + xxh_u64 const key64 = XXH_readLE64(xsecret + 8*i); + xxh_u64 acc64 = xacc[i]; + acc64 = XXH_xorshift64(acc64, 47); + acc64 ^= key64; + acc64 *= XXH_PRIME32_1; + xacc[i] = acc64; + } +} + +XXH_FORCE_INLINE void +XXH3_initCustomSecret_scalar(void* XXH_RESTRICT customSecret, xxh_u64 seed64) +{ + /* + * We need a separate pointer for the hack below, + * which requires a non-const pointer. + * Any decent compiler will optimize this out otherwise. + */ + const xxh_u8* kSecretPtr = XXH3_kSecret; + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0); + +#if defined(__clang__) && defined(__aarch64__) + /* + * UGLY HACK: + * Clang generates a bunch of MOV/MOVK pairs for aarch64, and they are + * placed sequentially, in order, at the top of the unrolled loop. + * + * While MOVK is great for generating constants (2 cycles for a 64-bit + * constant compared to 4 cycles for LDR), long MOVK chains stall the + * integer pipelines: + * I L S + * MOVK + * MOVK + * MOVK + * MOVK + * ADD + * SUB STR + * STR + * By forcing loads from memory (as the asm line causes Clang to assume + * that XXH3_kSecretPtr has been changed), the pipelines are used more + * efficiently: + * I L S + * LDR + * ADD LDR + * SUB STR + * STR + * XXH3_64bits_withSeed, len == 256, Snapdragon 835 + * without hack: 2654.4 MB/s + * with hack: 3202.9 MB/s + */ + __asm__("" : "+r" (kSecretPtr)); +#endif + /* + * Note: in debug mode, this overrides the asm optimization + * and Clang will emit MOVK chains again. + */ + XXH_ASSERT(kSecretPtr == XXH3_kSecret); + + { int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16; + int i; + for (i=0; i < nbRounds; i++) { + /* + * The asm hack causes Clang to assume that kSecretPtr aliases with + * customSecret, and on aarch64, this prevented LDP from merging two + * loads together for free. Putting the loads together before the stores + * properly generates LDP. + */ + xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64; + xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64; + XXH_writeLE64((xxh_u8*)customSecret + 16*i, lo); + XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi); + } } +} + + +typedef void (*XXH3_f_accumulate_512)(void* XXH_RESTRICT, const void*, const void*); +typedef void (*XXH3_f_scrambleAcc)(void* XXH_RESTRICT, const void*); +typedef void (*XXH3_f_initCustomSecret)(void* XXH_RESTRICT, xxh_u64); + + +#if (XXH_VECTOR == XXH_AVX512) + +#define XXH3_accumulate_512 XXH3_accumulate_512_avx512 +#define XXH3_scrambleAcc XXH3_scrambleAcc_avx512 +#define XXH3_initCustomSecret XXH3_initCustomSecret_avx512 + +#elif (XXH_VECTOR == XXH_AVX2) + +#define XXH3_accumulate_512 XXH3_accumulate_512_avx2 +#define XXH3_scrambleAcc XXH3_scrambleAcc_avx2 +#define XXH3_initCustomSecret XXH3_initCustomSecret_avx2 + +#elif (XXH_VECTOR == XXH_SSE2) + +#define XXH3_accumulate_512 XXH3_accumulate_512_sse2 +#define XXH3_scrambleAcc XXH3_scrambleAcc_sse2 +#define XXH3_initCustomSecret XXH3_initCustomSecret_sse2 + +#elif (XXH_VECTOR == XXH_NEON) + +#define XXH3_accumulate_512 XXH3_accumulate_512_neon +#define XXH3_scrambleAcc XXH3_scrambleAcc_neon +#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar + +#elif (XXH_VECTOR == XXH_VSX) + +#define XXH3_accumulate_512 XXH3_accumulate_512_vsx +#define XXH3_scrambleAcc XXH3_scrambleAcc_vsx +#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar + +#else /* scalar */ + +#define XXH3_accumulate_512 XXH3_accumulate_512_scalar +#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar +#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar + +#endif + + + +#ifndef XXH_PREFETCH_DIST +# ifdef __clang__ +# define XXH_PREFETCH_DIST 320 +# else +# if (XXH_VECTOR == XXH_AVX512) +# define XXH_PREFETCH_DIST 512 +# else +# define XXH_PREFETCH_DIST 384 +# endif +# endif /* __clang__ */ +#endif /* XXH_PREFETCH_DIST */ + +/* + * XXH3_accumulate() + * Loops over XXH3_accumulate_512(). + * Assumption: nbStripes will not overflow the secret size + */ +XXH_FORCE_INLINE void +XXH3_accumulate( xxh_u64* XXH_RESTRICT acc, + const xxh_u8* XXH_RESTRICT input, + const xxh_u8* XXH_RESTRICT secret, + size_t nbStripes, + XXH3_f_accumulate_512 f_acc512) +{ + size_t n; + for (n = 0; n < nbStripes; n++ ) { + const xxh_u8* const in = input + n*XXH_STRIPE_LEN; + XXH_PREFETCH(in + XXH_PREFETCH_DIST); + f_acc512(acc, + in, + secret + n*XXH_SECRET_CONSUME_RATE); + } +} + +XXH_FORCE_INLINE void +XXH3_hashLong_internal_loop(xxh_u64* XXH_RESTRICT acc, + const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble) +{ + size_t const nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE; + size_t const block_len = XXH_STRIPE_LEN * nbStripesPerBlock; + size_t const nb_blocks = (len - 1) / block_len; + + size_t n; + + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + + for (n = 0; n < nb_blocks; n++) { + XXH3_accumulate(acc, input + n*block_len, secret, nbStripesPerBlock, f_acc512); + f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN); + } + + /* last partial block */ + XXH_ASSERT(len > XXH_STRIPE_LEN); + { size_t const nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN; + XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE)); + XXH3_accumulate(acc, input + nb_blocks*block_len, secret, nbStripes, f_acc512); + + /* last stripe */ + { const xxh_u8* const p = input + len - XXH_STRIPE_LEN; +#define XXH_SECRET_LASTACC_START 7 /* not aligned on 8, last secret is different from acc & scrambler */ + f_acc512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START); + } } +} + +XXH_FORCE_INLINE xxh_u64 +XXH3_mix2Accs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret) +{ + return XXH3_mul128_fold64( + acc[0] ^ XXH_readLE64(secret), + acc[1] ^ XXH_readLE64(secret+8) ); +} + +static XXH64_hash_t +XXH3_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 start) +{ + xxh_u64 result64 = start; + size_t i = 0; + + for (i = 0; i < 4; i++) { + result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i); +#if defined(__clang__) /* Clang */ \ + && (defined(__arm__) || defined(__thumb__)) /* ARMv7 */ \ + && (defined(__ARM_NEON) || defined(__ARM_NEON__)) /* NEON */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable */ + /* + * UGLY HACK: + * Prevent autovectorization on Clang ARMv7-a. Exact same problem as + * the one in XXH3_len_129to240_64b. Speeds up shorter keys > 240b. + * XXH3_64bits, len == 256, Snapdragon 835: + * without hack: 2063.7 MB/s + * with hack: 2560.7 MB/s + */ + __asm__("" : "+r" (result64)); +#endif + } + + return XXH3_avalanche(result64); +} + +#define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \ + XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 } + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_hashLong_64b_internal(const void* XXH_RESTRICT input, size_t len, + const void* XXH_RESTRICT secret, size_t secretSize, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC; + + XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, f_acc512, f_scramble); + + /* converge into final hash */ + XXH_STATIC_ASSERT(sizeof(acc) == 64); + /* do not align on 8, so that the secret is different from the accumulator */ +#define XXH_SECRET_MERGEACCS_START 11 + XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + return XXH3_mergeAccs(acc, (const xxh_u8*)secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * XXH_PRIME64_1); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_withSecret(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen) +{ + (void)seed64; + return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate_512, XXH3_scrambleAcc); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + * Since the function is not inlined, the compiler may not be able to understand that, + * in some scenarios, its `secret` argument is actually a compile time constant. + * This variant enforces that the compiler can detect that, + * and uses this opportunity to streamline the generated code for better performance. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_default(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen) +{ + (void)seed64; (void)secret; (void)secretLen; + return XXH3_hashLong_64b_internal(input, len, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_accumulate_512, XXH3_scrambleAcc); +} + +/* + * XXH3_hashLong_64b_withSeed(): + * Generate a custom key based on alteration of default XXH3_kSecret with the seed, + * and then use this key for long mode hashing. + * + * This operation is decently fast but nonetheless costs a little bit of time. + * Try to avoid it whenever possible (typically when seed==0). + * + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_FORCE_INLINE XXH64_hash_t +XXH3_hashLong_64b_withSeed_internal(const void* input, size_t len, + XXH64_hash_t seed, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble, + XXH3_f_initCustomSecret f_initSec) +{ + if (seed == 0) + return XXH3_hashLong_64b_internal(input, len, + XXH3_kSecret, sizeof(XXH3_kSecret), + f_acc512, f_scramble); + { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE]; + f_initSec(secret, seed); + return XXH3_hashLong_64b_internal(input, len, secret, sizeof(secret), + f_acc512, f_scramble); + } +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_withSeed(const void* input, size_t len, + XXH64_hash_t seed, const xxh_u8* secret, size_t secretLen) +{ + (void)secret; (void)secretLen; + return XXH3_hashLong_64b_withSeed_internal(input, len, seed, + XXH3_accumulate_512, XXH3_scrambleAcc, XXH3_initCustomSecret); +} + + +typedef XXH64_hash_t (*XXH3_hashLong64_f)(const void* XXH_RESTRICT, size_t, + XXH64_hash_t, const xxh_u8* XXH_RESTRICT, size_t); + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_64bits_internal(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen, + XXH3_hashLong64_f f_hashLong) +{ + XXH_ASSERT(secretLen >= XXH3_SECRET_SIZE_MIN); + /* + * If an action is to be taken if `secretLen` condition is not respected, + * it should be done here. + * For now, it's a contract pre-condition. + * Adding a check and a branch here would cost performance at every hash. + * Also, note that function signature doesn't offer room to return an error. + */ + if (len <= 16) + return XXH3_len_0to16_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, seed64); + if (len <= 128) + return XXH3_len_17to128_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64); + return f_hashLong(input, len, seed64, (const xxh_u8*)secret, secretLen); +} + + +/* === Public entry point === */ + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits(const void* input, size_t len) +{ + return XXH3_64bits_internal(input, len, 0, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_64b_default); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH64_hash_t +XXH3_64bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize) +{ + return XXH3_64bits_internal(input, len, 0, secret, secretSize, XXH3_hashLong_64b_withSecret); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH64_hash_t +XXH3_64bits_withSeed(const void* input, size_t len, XXH64_hash_t seed) +{ + return XXH3_64bits_internal(input, len, seed, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed); +} + + +/* === XXH3 streaming === */ + +/* + * Malloc's a pointer that is always aligned to align. + * + * This must be freed with `XXH_alignedFree()`. + * + * malloc typically guarantees 16 byte alignment on 64-bit systems and 8 byte + * alignment on 32-bit. This isn't enough for the 32 byte aligned loads in AVX2 + * or on 32-bit, the 16 byte aligned loads in SSE2 and NEON. + * + * This underalignment previously caused a rather obvious crash which went + * completely unnoticed due to XXH3_createState() not actually being tested. + * Credit to RedSpah for noticing this bug. + * + * The alignment is done manually: Functions like posix_memalign or _mm_malloc + * are avoided: To maintain portability, we would have to write a fallback + * like this anyways, and besides, testing for the existence of library + * functions without relying on external build tools is impossible. + * + * The method is simple: Overallocate, manually align, and store the offset + * to the original behind the returned pointer. + * + * Align must be a power of 2 and 8 <= align <= 128. + */ +static void* XXH_alignedMalloc(size_t s, size_t align) +{ + XXH_ASSERT(align <= 128 && align >= 8); /* range check */ + XXH_ASSERT((align & (align-1)) == 0); /* power of 2 */ + XXH_ASSERT(s != 0 && s < (s + align)); /* empty/overflow */ + { /* Overallocate to make room for manual realignment and an offset byte */ + xxh_u8* base = (xxh_u8*)XXH_malloc(s + align); + if (base != NULL) { + /* + * Get the offset needed to align this pointer. + * + * Even if the returned pointer is aligned, there will always be + * at least one byte to store the offset to the original pointer. + */ + size_t offset = align - ((size_t)base & (align - 1)); /* base % align */ + /* Add the offset for the now-aligned pointer */ + xxh_u8* ptr = base + offset; + + XXH_ASSERT((size_t)ptr % align == 0); + + /* Store the offset immediately before the returned pointer. */ + ptr[-1] = (xxh_u8)offset; + return ptr; + } + return NULL; + } +} +/* + * Frees an aligned pointer allocated by XXH_alignedMalloc(). Don't pass + * normal malloc'd pointers, XXH_alignedMalloc has a specific data layout. + */ +static void XXH_alignedFree(void* p) +{ + if (p != NULL) { + xxh_u8* ptr = (xxh_u8*)p; + /* Get the offset byte we added in XXH_malloc. */ + xxh_u8 offset = ptr[-1]; + /* Free the original malloc'd pointer */ + xxh_u8* base = ptr - offset; + XXH_free(base); + } +} +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH3_state_t* XXH3_createState(void) +{ + XXH3_state_t* const state = (XXH3_state_t*)XXH_alignedMalloc(sizeof(XXH3_state_t), 64); + if (state==NULL) return NULL; + XXH3_INITSTATE(state); + return state; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode XXH3_freeState(XXH3_state_t* statePtr) +{ + XXH_alignedFree(statePtr); + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API void +XXH3_copyState(XXH3_state_t* dst_state, const XXH3_state_t* src_state) +{ + memcpy(dst_state, src_state, sizeof(*dst_state)); +} + +static void +XXH3_reset_internal(XXH3_state_t* statePtr, + XXH64_hash_t seed, + const void* secret, size_t secretSize) +{ + size_t const initStart = offsetof(XXH3_state_t, bufferedSize); + size_t const initLength = offsetof(XXH3_state_t, nbStripesPerBlock) - initStart; + XXH_ASSERT(offsetof(XXH3_state_t, nbStripesPerBlock) > initStart); + XXH_ASSERT(statePtr != NULL); + /* set members from bufferedSize to nbStripesPerBlock (excluded) to 0 */ + memset((char*)statePtr + initStart, 0, initLength); + statePtr->acc[0] = XXH_PRIME32_3; + statePtr->acc[1] = XXH_PRIME64_1; + statePtr->acc[2] = XXH_PRIME64_2; + statePtr->acc[3] = XXH_PRIME64_3; + statePtr->acc[4] = XXH_PRIME64_4; + statePtr->acc[5] = XXH_PRIME32_2; + statePtr->acc[6] = XXH_PRIME64_5; + statePtr->acc[7] = XXH_PRIME32_1; + statePtr->seed = seed; + statePtr->extSecret = (const unsigned char*)secret; + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + statePtr->secretLimit = secretSize - XXH_STRIPE_LEN; + statePtr->nbStripesPerBlock = statePtr->secretLimit / XXH_SECRET_CONSUME_RATE; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset(XXH3_state_t* statePtr) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_reset_internal(statePtr, 0, secret, secretSize); + if (secret == NULL) return XXH_ERROR; + if (secretSize < XXH3_SECRET_SIZE_MIN) return XXH_ERROR; + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed) +{ + if (statePtr == NULL) return XXH_ERROR; + if (seed==0) return XXH3_64bits_reset(statePtr); + if (seed != statePtr->seed) XXH3_initCustomSecret(statePtr->customSecret, seed); + XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +/* Note : when XXH3_consumeStripes() is invoked, + * there must be a guarantee that at least one more byte must be consumed from input + * so that the function can blindly consume all stripes using the "normal" secret segment */ +XXH_FORCE_INLINE void +XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc, + size_t* XXH_RESTRICT nbStripesSoFarPtr, size_t nbStripesPerBlock, + const xxh_u8* XXH_RESTRICT input, size_t nbStripes, + const xxh_u8* XXH_RESTRICT secret, size_t secretLimit, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble) +{ + XXH_ASSERT(nbStripes <= nbStripesPerBlock); /* can handle max 1 scramble per invocation */ + XXH_ASSERT(*nbStripesSoFarPtr < nbStripesPerBlock); + if (nbStripesPerBlock - *nbStripesSoFarPtr <= nbStripes) { + /* need a scrambling operation */ + size_t const nbStripesToEndofBlock = nbStripesPerBlock - *nbStripesSoFarPtr; + size_t const nbStripesAfterBlock = nbStripes - nbStripesToEndofBlock; + XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripesToEndofBlock, f_acc512); + f_scramble(acc, secret + secretLimit); + XXH3_accumulate(acc, input + nbStripesToEndofBlock * XXH_STRIPE_LEN, secret, nbStripesAfterBlock, f_acc512); + *nbStripesSoFarPtr = nbStripesAfterBlock; + } else { + XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, f_acc512); + *nbStripesSoFarPtr += nbStripes; + } +} + +/* + * Both XXH3_64bits_update and XXH3_128bits_update use this routine. + */ +XXH_FORCE_INLINE XXH_errorcode +XXH3_update(XXH3_state_t* state, + const xxh_u8* input, size_t len, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* const bEnd = input + len; + const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret; + + state->totalLen += len; + XXH_ASSERT(state->bufferedSize <= XXH3_INTERNALBUFFER_SIZE); + + if (state->bufferedSize + len <= XXH3_INTERNALBUFFER_SIZE) { /* fill in tmp buffer */ + XXH_memcpy(state->buffer + state->bufferedSize, input, len); + state->bufferedSize += (XXH32_hash_t)len; + return XXH_OK; + } + /* total input is now > XXH3_INTERNALBUFFER_SIZE */ + + #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN) + XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % XXH_STRIPE_LEN == 0); /* clean multiple */ + + /* + * Internal buffer is partially filled (always, except at beginning) + * Complete it, then consume it. + */ + if (state->bufferedSize) { + size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize; + XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize); + input += loadSize; + XXH3_consumeStripes(state->acc, + &state->nbStripesSoFar, state->nbStripesPerBlock, + state->buffer, XXH3_INTERNALBUFFER_STRIPES, + secret, state->secretLimit, + f_acc512, f_scramble); + state->bufferedSize = 0; + } + XXH_ASSERT(input < bEnd); + + /* Consume input by a multiple of internal buffer size */ + if (input+XXH3_INTERNALBUFFER_SIZE < bEnd) { + const xxh_u8* const limit = bEnd - XXH3_INTERNALBUFFER_SIZE; + do { + XXH3_consumeStripes(state->acc, + &state->nbStripesSoFar, state->nbStripesPerBlock, + input, XXH3_INTERNALBUFFER_STRIPES, + secret, state->secretLimit, + f_acc512, f_scramble); + input += XXH3_INTERNALBUFFER_SIZE; + } while (inputbuffer + sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN); + } + XXH_ASSERT(input < bEnd); + + /* Some remaining input (always) : buffer it */ + XXH_memcpy(state->buffer, input, (size_t)(bEnd-input)); + state->bufferedSize = (XXH32_hash_t)(bEnd-input); + } + + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_update(XXH3_state_t* state, const void* input, size_t len) +{ + return XXH3_update(state, (const xxh_u8*)input, len, + XXH3_accumulate_512, XXH3_scrambleAcc); +} + + +XXH_FORCE_INLINE void +XXH3_digest_long (XXH64_hash_t* acc, + const XXH3_state_t* state, + const unsigned char* secret) +{ + /* + * Digest on a local copy. This way, the state remains unaltered, and it can + * continue ingesting more input afterwards. + */ + memcpy(acc, state->acc, sizeof(state->acc)); + if (state->bufferedSize >= XXH_STRIPE_LEN) { + size_t const nbStripes = (state->bufferedSize - 1) / XXH_STRIPE_LEN; + size_t nbStripesSoFar = state->nbStripesSoFar; + XXH3_consumeStripes(acc, + &nbStripesSoFar, state->nbStripesPerBlock, + state->buffer, nbStripes, + secret, state->secretLimit, + XXH3_accumulate_512, XXH3_scrambleAcc); + /* last stripe */ + XXH3_accumulate_512(acc, + state->buffer + state->bufferedSize - XXH_STRIPE_LEN, + secret + state->secretLimit - XXH_SECRET_LASTACC_START); + } else { /* bufferedSize < XXH_STRIPE_LEN */ + xxh_u8 lastStripe[XXH_STRIPE_LEN]; + size_t const catchupSize = XXH_STRIPE_LEN - state->bufferedSize; + XXH_ASSERT(state->bufferedSize > 0); /* there is always some input buffered */ + memcpy(lastStripe, state->buffer + sizeof(state->buffer) - catchupSize, catchupSize); + memcpy(lastStripe + catchupSize, state->buffer, state->bufferedSize); + XXH3_accumulate_512(acc, + lastStripe, + secret + state->secretLimit - XXH_SECRET_LASTACC_START); + } +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_digest (const XXH3_state_t* state) +{ + const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret; + if (state->totalLen > XXH3_MIDSIZE_MAX) { + XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB]; + XXH3_digest_long(acc, state, secret); + return XXH3_mergeAccs(acc, + secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)state->totalLen * XXH_PRIME64_1); + } + /* totalLen <= XXH3_MIDSIZE_MAX: digesting a short input */ + if (state->seed) + return XXH3_64bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed); + return XXH3_64bits_withSecret(state->buffer, (size_t)(state->totalLen), + secret, state->secretLimit + XXH_STRIPE_LEN); +} + + +#define XXH_MIN(x, y) (((x) > (y)) ? (y) : (x)) + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API void +XXH3_generateSecret(void* secretBuffer, const void* customSeed, size_t customSeedSize) +{ + XXH_ASSERT(secretBuffer != NULL); + if (customSeedSize == 0) { + memcpy(secretBuffer, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE); + return; + } + XXH_ASSERT(customSeed != NULL); + + { size_t const segmentSize = sizeof(XXH128_hash_t); + size_t const nbSegments = XXH_SECRET_DEFAULT_SIZE / segmentSize; + XXH128_canonical_t scrambler; + XXH64_hash_t seeds[12]; + size_t segnb; + XXH_ASSERT(nbSegments == 12); + XXH_ASSERT(segmentSize * nbSegments == XXH_SECRET_DEFAULT_SIZE); /* exact multiple */ + XXH128_canonicalFromHash(&scrambler, XXH128(customSeed, customSeedSize, 0)); + + /* + * Copy customSeed to seeds[], truncating or repeating as necessary. + */ + { size_t toFill = XXH_MIN(customSeedSize, sizeof(seeds)); + size_t filled = toFill; + memcpy(seeds, customSeed, toFill); + while (filled < sizeof(seeds)) { + toFill = XXH_MIN(filled, sizeof(seeds) - filled); + memcpy((char*)seeds + filled, seeds, toFill); + filled += toFill; + } } + + /* generate secret */ + memcpy(secretBuffer, &scrambler, sizeof(scrambler)); + for (segnb=1; segnb < nbSegments; segnb++) { + size_t const segmentStart = segnb * segmentSize; + XXH128_canonical_t segment; + XXH128_canonicalFromHash(&segment, + XXH128(&scrambler, sizeof(scrambler), XXH_readLE64(seeds + segnb) + segnb) ); + memcpy((char*)secretBuffer + segmentStart, &segment, sizeof(segment)); + } } +} + + +/* ========================================== + * XXH3 128 bits (a.k.a XXH128) + * ========================================== + * XXH3's 128-bit variant has better mixing and strength than the 64-bit variant, + * even without counting the significantly larger output size. + * + * For example, extra steps are taken to avoid the seed-dependent collisions + * in 17-240 byte inputs (See XXH3_mix16B and XXH128_mix32B). + * + * This strength naturally comes at the cost of some speed, especially on short + * lengths. Note that longer hashes are about as fast as the 64-bit version + * due to it using only a slight modification of the 64-bit loop. + * + * XXH128 is also more oriented towards 64-bit machines. It is still extremely + * fast for a _128-bit_ hash on 32-bit (it usually clears XXH64). + */ + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_1to3_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + /* A doubled version of 1to3_64b with different constants. */ + XXH_ASSERT(input != NULL); + XXH_ASSERT(1 <= len && len <= 3); + XXH_ASSERT(secret != NULL); + /* + * len = 1: combinedl = { input[0], 0x01, input[0], input[0] } + * len = 2: combinedl = { input[1], 0x02, input[0], input[1] } + * len = 3: combinedl = { input[2], 0x03, input[0], input[1] } + */ + { xxh_u8 const c1 = input[0]; + xxh_u8 const c2 = input[len >> 1]; + xxh_u8 const c3 = input[len - 1]; + xxh_u32 const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24) + | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8); + xxh_u32 const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13); + xxh_u64 const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed; + xxh_u64 const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed; + xxh_u64 const keyed_lo = (xxh_u64)combinedl ^ bitflipl; + xxh_u64 const keyed_hi = (xxh_u64)combinedh ^ bitfliph; + XXH128_hash_t h128; + h128.low64 = XXH64_avalanche(keyed_lo); + h128.high64 = XXH64_avalanche(keyed_hi); + return h128; + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_4to8_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(4 <= len && len <= 8); + seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32; + { xxh_u32 const input_lo = XXH_readLE32(input); + xxh_u32 const input_hi = XXH_readLE32(input + len - 4); + xxh_u64 const input_64 = input_lo + ((xxh_u64)input_hi << 32); + xxh_u64 const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed; + xxh_u64 const keyed = input_64 ^ bitflip; + + /* Shift len to the left to ensure it is even, this avoids even multiplies. */ + XXH128_hash_t m128 = XXH_mult64to128(keyed, XXH_PRIME64_1 + (len << 2)); + + m128.high64 += (m128.low64 << 1); + m128.low64 ^= (m128.high64 >> 3); + + m128.low64 = XXH_xorshift64(m128.low64, 35); + m128.low64 *= 0x9FB21C651E98DF25ULL; + m128.low64 = XXH_xorshift64(m128.low64, 28); + m128.high64 = XXH3_avalanche(m128.high64); + return m128; + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_9to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(9 <= len && len <= 16); + { xxh_u64 const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed; + xxh_u64 const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed; + xxh_u64 const input_lo = XXH_readLE64(input); + xxh_u64 input_hi = XXH_readLE64(input + len - 8); + XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, XXH_PRIME64_1); + /* + * Put len in the middle of m128 to ensure that the length gets mixed to + * both the low and high bits in the 128x64 multiply below. + */ + m128.low64 += (xxh_u64)(len - 1) << 54; + input_hi ^= bitfliph; + /* + * Add the high 32 bits of input_hi to the high 32 bits of m128, then + * add the long product of the low 32 bits of input_hi and XXH_PRIME32_2 to + * the high 64 bits of m128. + * + * The best approach to this operation is different on 32-bit and 64-bit. + */ + if (sizeof(void *) < sizeof(xxh_u64)) { /* 32-bit */ + /* + * 32-bit optimized version, which is more readable. + * + * On 32-bit, it removes an ADC and delays a dependency between the two + * halves of m128.high64, but it generates an extra mask on 64-bit. + */ + m128.high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2); + } else { + /* + * 64-bit optimized (albeit more confusing) version. + * + * Uses some properties of addition and multiplication to remove the mask: + * + * Let: + * a = input_hi.lo = (input_hi & 0x00000000FFFFFFFF) + * b = input_hi.hi = (input_hi & 0xFFFFFFFF00000000) + * c = XXH_PRIME32_2 + * + * a + (b * c) + * Inverse Property: x + y - x == y + * a + (b * (1 + c - 1)) + * Distributive Property: x * (y + z) == (x * y) + (x * z) + * a + (b * 1) + (b * (c - 1)) + * Identity Property: x * 1 == x + * a + b + (b * (c - 1)) + * + * Substitute a, b, and c: + * input_hi.hi + input_hi.lo + ((xxh_u64)input_hi.lo * (XXH_PRIME32_2 - 1)) + * + * Since input_hi.hi + input_hi.lo == input_hi, we get this: + * input_hi + ((xxh_u64)input_hi.lo * (XXH_PRIME32_2 - 1)) + */ + m128.high64 += input_hi + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2 - 1); + } + /* m128 ^= XXH_swap64(m128 >> 64); */ + m128.low64 ^= XXH_swap64(m128.high64); + + { /* 128x64 multiply: h128 = m128 * XXH_PRIME64_2; */ + XXH128_hash_t h128 = XXH_mult64to128(m128.low64, XXH_PRIME64_2); + h128.high64 += m128.high64 * XXH_PRIME64_2; + + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = XXH3_avalanche(h128.high64); + return h128; + } } +} + +/* + * Assumption: `secret` size is >= XXH3_SECRET_SIZE_MIN + */ +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_0to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(len <= 16); + { if (len > 8) return XXH3_len_9to16_128b(input, len, secret, seed); + if (len >= 4) return XXH3_len_4to8_128b(input, len, secret, seed); + if (len) return XXH3_len_1to3_128b(input, len, secret, seed); + { XXH128_hash_t h128; + xxh_u64 const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72); + xxh_u64 const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88); + h128.low64 = XXH64_avalanche(seed ^ bitflipl); + h128.high64 = XXH64_avalanche( seed ^ bitfliph); + return h128; + } } +} + +/* + * A bit slower than XXH3_mix16B, but handles multiply by zero better. + */ +XXH_FORCE_INLINE XXH128_hash_t +XXH128_mix32B(XXH128_hash_t acc, const xxh_u8* input_1, const xxh_u8* input_2, + const xxh_u8* secret, XXH64_hash_t seed) +{ + acc.low64 += XXH3_mix16B (input_1, secret+0, seed); + acc.low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8); + acc.high64 += XXH3_mix16B (input_2, secret+16, seed); + acc.high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8); + return acc; +} + + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_17to128_128b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(16 < len && len <= 128); + + { XXH128_hash_t acc; + acc.low64 = len * XXH_PRIME64_1; + acc.high64 = 0; + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed); + } + acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed); + } + acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed); + } + acc = XXH128_mix32B(acc, input, input+len-16, secret, seed); + { XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * XXH_PRIME64_1) + + (acc.high64 * XXH_PRIME64_4) + + ((len - seed) * XXH_PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (XXH64_hash_t)0 - XXH3_avalanche(h128.high64); + return h128; + } + } +} + +XXH_NO_INLINE XXH128_hash_t +XXH3_len_129to240_128b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX); + + { XXH128_hash_t acc; + int const nbRounds = (int)len / 32; + int i; + acc.low64 = len * XXH_PRIME64_1; + acc.high64 = 0; + for (i=0; i<4; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + (32 * i), + seed); + } + acc.low64 = XXH3_avalanche(acc.low64); + acc.high64 = XXH3_avalanche(acc.high64); + XXH_ASSERT(nbRounds >= 4); + for (i=4 ; i < nbRounds; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + XXH3_MIDSIZE_STARTOFFSET + (32 * (i - 4)), + seed); + } + /* last bytes */ + acc = XXH128_mix32B(acc, + input + len - 16, + input + len - 32, + secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, + 0ULL - seed); + + { XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * XXH_PRIME64_1) + + (acc.high64 * XXH_PRIME64_4) + + ((len - seed) * XXH_PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (XXH64_hash_t)0 - XXH3_avalanche(h128.high64); + return h128; + } + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_hashLong_128b_internal(const void* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC; + + XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, secret, secretSize, f_acc512, f_scramble); + + /* converge into final hash */ + XXH_STATIC_ASSERT(sizeof(acc) == 64); + XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + { XXH128_hash_t h128; + h128.low64 = XXH3_mergeAccs(acc, + secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)len * XXH_PRIME64_1); + h128.high64 = XXH3_mergeAccs(acc, + secret + secretSize + - sizeof(acc) - XXH_SECRET_MERGEACCS_START, + ~((xxh_u64)len * XXH_PRIME64_2)); + return h128; + } +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_default(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, + const void* XXH_RESTRICT secret, size_t secretLen) +{ + (void)seed64; (void)secret; (void)secretLen; + return XXH3_hashLong_128b_internal(input, len, XXH3_kSecret, sizeof(XXH3_kSecret), + XXH3_accumulate_512, XXH3_scrambleAcc); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_withSecret(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, + const void* XXH_RESTRICT secret, size_t secretLen) +{ + (void)seed64; + return XXH3_hashLong_128b_internal(input, len, (const xxh_u8*)secret, secretLen, + XXH3_accumulate_512, XXH3_scrambleAcc); +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_hashLong_128b_withSeed_internal(const void* XXH_RESTRICT input, size_t len, + XXH64_hash_t seed64, + XXH3_f_accumulate_512 f_acc512, + XXH3_f_scrambleAcc f_scramble, + XXH3_f_initCustomSecret f_initSec) +{ + if (seed64 == 0) + return XXH3_hashLong_128b_internal(input, len, + XXH3_kSecret, sizeof(XXH3_kSecret), + f_acc512, f_scramble); + { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE]; + f_initSec(secret, seed64); + return XXH3_hashLong_128b_internal(input, len, (const xxh_u8*)secret, sizeof(secret), + f_acc512, f_scramble); + } +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_withSeed(const void* input, size_t len, + XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen) +{ + (void)secret; (void)secretLen; + return XXH3_hashLong_128b_withSeed_internal(input, len, seed64, + XXH3_accumulate_512, XXH3_scrambleAcc, XXH3_initCustomSecret); +} + +typedef XXH128_hash_t (*XXH3_hashLong128_f)(const void* XXH_RESTRICT, size_t, + XXH64_hash_t, const void* XXH_RESTRICT, size_t); + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_128bits_internal(const void* input, size_t len, + XXH64_hash_t seed64, const void* XXH_RESTRICT secret, size_t secretLen, + XXH3_hashLong128_f f_hl128) +{ + XXH_ASSERT(secretLen >= XXH3_SECRET_SIZE_MIN); + /* + * If an action is to be taken if `secret` conditions are not respected, + * it should be done here. + * For now, it's a contract pre-condition. + * Adding a check and a branch here would cost performance at every hash. + */ + if (len <= 16) + return XXH3_len_0to16_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, seed64); + if (len <= 128) + return XXH3_len_17to128_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretLen, seed64); + return f_hl128(input, len, seed64, secret, secretLen); +} + + +/* === Public XXH128 API === */ + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits(const void* input, size_t len) +{ + return XXH3_128bits_internal(input, len, 0, + XXH3_kSecret, sizeof(XXH3_kSecret), + XXH3_hashLong_128b_default); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t +XXH3_128bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize) +{ + return XXH3_128bits_internal(input, len, 0, + (const xxh_u8*)secret, secretSize, + XXH3_hashLong_128b_withSecret); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t +XXH3_128bits_withSeed(const void* input, size_t len, XXH64_hash_t seed) +{ + return XXH3_128bits_internal(input, len, seed, + XXH3_kSecret, sizeof(XXH3_kSecret), + XXH3_hashLong_128b_withSeed); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t +XXH128(const void* input, size_t len, XXH64_hash_t seed) +{ + return XXH3_128bits_withSeed(input, len, seed); +} + + +/* === XXH3 128-bit streaming === */ + +/* + * All the functions are actually the same as for 64-bit streaming variant. + * The only difference is the finalization routine. + */ + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset(XXH3_state_t* statePtr) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_reset_internal(statePtr, 0, secret, secretSize); + if (secret == NULL) return XXH_ERROR; + if (secretSize < XXH3_SECRET_SIZE_MIN) return XXH_ERROR; + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed) +{ + if (statePtr == NULL) return XXH_ERROR; + if (seed==0) return XXH3_128bits_reset(statePtr); + if (seed != statePtr->seed) XXH3_initCustomSecret(statePtr->customSecret, seed); + XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_update(XXH3_state_t* state, const void* input, size_t len) +{ + return XXH3_update(state, (const xxh_u8*)input, len, + XXH3_accumulate_512, XXH3_scrambleAcc); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (const XXH3_state_t* state) +{ + const unsigned char* const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret; + if (state->totalLen > XXH3_MIDSIZE_MAX) { + XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB]; + XXH3_digest_long(acc, state, secret); + XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + { XXH128_hash_t h128; + h128.low64 = XXH3_mergeAccs(acc, + secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)state->totalLen * XXH_PRIME64_1); + h128.high64 = XXH3_mergeAccs(acc, + secret + state->secretLimit + XXH_STRIPE_LEN + - sizeof(acc) - XXH_SECRET_MERGEACCS_START, + ~((xxh_u64)state->totalLen * XXH_PRIME64_2)); + return h128; + } + } + /* len <= XXH3_MIDSIZE_MAX : short code */ + if (state->seed) + return XXH3_128bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed); + return XXH3_128bits_withSecret(state->buffer, (size_t)(state->totalLen), + secret, state->secretLimit + XXH_STRIPE_LEN); +} + +/* 128-bit utility functions */ + +#include /* memcmp, memcpy */ + +/* return : 1 is equal, 0 if different */ +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2) +{ + /* note : XXH128_hash_t is compact, it has no padding byte */ + return !(memcmp(&h1, &h2, sizeof(h1))); +} + +/* This prototype is compatible with stdlib's qsort(). + * return : >0 if *h128_1 > *h128_2 + * <0 if *h128_1 < *h128_2 + * =0 if *h128_1 == *h128_2 */ +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API int XXH128_cmp(const void* h128_1, const void* h128_2) +{ + XXH128_hash_t const h1 = *(const XXH128_hash_t*)h128_1; + XXH128_hash_t const h2 = *(const XXH128_hash_t*)h128_2; + int const hcmp = (h1.high64 > h2.high64) - (h2.high64 > h1.high64); + /* note : bets that, in most cases, hash values are different */ + if (hcmp) return hcmp; + return (h1.low64 > h2.low64) - (h2.low64 > h1.low64); +} + + +/*====== Canonical representation ======*/ +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API void +XXH128_canonicalFromHash(XXH128_canonical_t* dst, XXH128_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH128_canonical_t) == sizeof(XXH128_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) { + hash.high64 = XXH_swap64(hash.high64); + hash.low64 = XXH_swap64(hash.low64); + } + memcpy(dst, &hash.high64, sizeof(hash.high64)); + memcpy((char*)dst + sizeof(hash.high64), &hash.low64, sizeof(hash.low64)); +} + +/*! @ingroup xxh3_family */ +XXH_PUBLIC_API XXH128_hash_t +XXH128_hashFromCanonical(const XXH128_canonical_t* src) +{ + XXH128_hash_t h; + h.high64 = XXH_readBE64(src); + h.low64 = XXH_readBE64(src->digest + 8); + return h; +} + +/* Pop our optimization override from above */ +#if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \ + && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) /* respect -O0 and -Os */ +# pragma GCC pop_options +#endif + +#endif /* XXH_NO_LONG_LONG */ + +/*! + * @} + */ +#endif /* XXH_IMPLEMENTATION */ + + +#if defined (__cplusplus) +} +#endif \ No newline at end of file diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..4bffdfe --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,2 @@ +-I c +-I c/vendor diff --git a/docs/analysis.md b/docs/analysis.md deleted file mode 100644 index d00cfbc..0000000 --- a/docs/analysis.md +++ /dev/null @@ -1,67 +0,0 @@ -# Codebase Analysis — Undocumented Findings - -> Items discovered during development that need attention. Ordered roughly by impact. - -## ✅ 6. No `String()` / debug printing for AST nodes - -**Status: Fixed** — Generator now emits `str()` for all 276 message types, `UnrecognizedNode`, and `Node` sum type. - -Every generated struct has a `pub fn (m TypeName) str() string` method that shows non-zero fields as `TypeName{field1: val1, field2: val2}`. Zero-valued primitives, empty strings, nil pointers, and empty repeated fields are omitted. Sub-messages and enums are always included (their `str()` shows `TypeName{}` when all zero). - -Node sum type dispatches to the variant's `str()`. `println(stmt.stmt)` now works on any AST node. - ---- - -## ✅ 7. `parse_json_ast()` panics on unknown node types - -**Status: Fixed** — `decode_node_json` now returns `Node` (not `!Node`) and returns `UnrecognizedNode{field_num: 0, data: []u8{}}` when no known JSON field matches, instead of `error("unknown node type")`. - -The JSON path cannot fully preserve unknown data (no raw JSON capture) but no longer panics/errors on future PG node types. - ---- - -## ✅ 8. Repeated primitives use non-packed encoding - -**Status: Fixed** — Encoder now uses packed encoding for repeated scalar fields (int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, float, double, bool) and enum types. Instead of individual `tag + value` pairs, writes `tag(2) + length + concatenated values`. String/bytes/Node/submessage repeats remain non-packed. - ---- - -## ✅ 9. `parse_ast()` is a dead-end codepath - -**Status: Fixed** — Added deprecation comment: "Deprecated: use parse_protobuf_ast() instead (~3x faster, pure V decode)." The function remains for backward compatibility. - ---- - -## ✅ 10. Encoded zero-value variants still get a tag - -**Status: Verified as intentional** — Only `Alias` (the zero-value default for the `Node` sum type) is skipped when all fields are zero. All other variants are explicitly constructed by the user and should always encode. The check now uses `vname == 'Alias'` instead of relying on field ordering. - ---- - -## ✅ 11. No public wrappers for `encode_scan_result` / `encode_summary_result` - -**Status: Fixed** — All generated encode functions are now `pub fn`. Added `encode_scan(ScanResult) Protobuf` and `encode_summary(SummaryResult) Protobuf` wrappers in `pgquery.v`. - ---- - -## ✅ 12. Hardcoded version strings in tests - -**Status: Fixed** — Version tests are now self-validating. Instead of asserting `pg_version() == '17.7'`, `test_version()` checks internal consistency: version string matches major version, numeric version equals major × 10000. This survives `libpg_query` upgrades without modification. - ---- - -## ✅ 13. `PostgresDeparseOpts` struct layout is implicitly coupled - -**Status: Fixed** — The V-side `C.PostgresDeparseOpts` struct has been removed entirely. All field access goes through C bridge setters in `c_bridge.c` with `void*` parameters (the V-side type is `voidptr`). The struct layout is known only to the C code; V has zero ABI coupling with the struct. Adding/removing fields requires changes only to `c_bridge.c`/`.h`. - ---- - -## ✅ 14. `valid_enum_int` silently coerces invalid values to 0 - -**Status: Fixed** — Added `valid_enum_int_strict(valid_values []int, v u64) !int` that returns an error on out-of-range values. The original `valid_enum_int` remains as the decode default (security hardening). - ---- - -## 15. No tree-manipulation utilities - -**Status: Unchanged** — `deep_copy()`, `walk()`, and convenience constructors are valuable but require generator-level support for all 276 variants. These should be implemented as generated functions in `gen_ast.v` in a future pass. For now, V's value-type struct semantics make simple `copy := original` sufficient for most use cases (maps and `&T` pointers are the exceptions). diff --git a/docs/design.md b/docs/design.md index e59bd60..44e7744 100644 --- a/docs/design.md +++ b/docs/design.md @@ -10,30 +10,32 @@ use cases. | Function | Returns | Use Case | Speed | |---|---|---|---| -| `normalize()` | `string` | Anonymize query literals for logging | ~4 us/op | -| `fingerprint()` | `u64` | Consistent hash for query structure | ~9 us/op | -| `parse()` | JSON `string` | Full tree inspection, debugging | ~7 us/op | -| `parse_protobuf_ast()` | typed V AST structs | Shard key / table extraction | ~33 us/op | -| `parse_json_ast()` | typed V AST structs | JSON → typed AST (external JSON) | ~94 us/op | +| `normalize()` | `string` | Anonymize query literals for logging | ~3 us/op | +| `fingerprint()` | `u64` | Consistent hash for query structure | ~6 us/op | +| `parse()` | JSON `string` | Full tree inspection, debugging | ~4 us/op | +| `parse_protobuf_ast()` | typed V AST structs | Shard key / table extraction | ~19 us/op | +| `parse_json_ast()` | typed V AST structs | JSON → typed AST (external JSON) | ~54 us/op | | `encode_parse_result()` | `[]u8` protobuf | Serialize AST back to wire format | 111 µs | | `deparse_ast()` | `!string` | Query rewrite pipeline | encode + C deparse (160 µs) | -## Benchmark (2026-05-16) +## Benchmark (2026-05-25) ``` -normalize() → anonymized SQL 7.5 us/op -parse() → JSON string 13.1 us/op -fingerprint() → hash 16.4 us/op -parse_protobuf_ast() → typed AST 62.3 us/op -parse_json_ast() → typed AST 166.4 us/op +normalize() → anonymized SQL 2.6 us/op +parse() → JSON string 3.2 us/op +fingerprint() → hash 5.6 us/op +parse_protobuf_ast() → typed AST 18.6 us/op +parse_json_ast() → typed AST 53.7 us/op encode_parse_result() → protobuf 111.0 us/op deparse_ast() → SQL (encode+deparse) 159.7 us/op ``` -**Conditions**: 6 queries × 1000 iterations = 6000 ops per path, M2 MacBook Air. -**Note**: All `parse_*` numbers doubled versus earlier runs due to macOS scheduler variance. -Encode is ~1.8× slower than decode because it dynamically grows output arrays and walks -the sum-type dispatch table. Deparse overhead over encode is ~49 µs (C library call). +**Conditions**: 2 queries × 10000 iterations = 20000 ops per path, M2 MacBook Air. +(encode & deparse from 6q × 1000i bench.v — unchanged). +**Note**: Parse-path numbers halved versus prior run (scheduler variance resolved). +Bridge elimination reduced C call overhead for parse paths. Encode is ~1.8× slower than +decode because it dynamically grows output arrays and walks the sum-type dispatch table. +Deparse overhead over encode is ~49 µs (C library call). ## Concurrency Stress Test @@ -67,7 +69,7 @@ the sum-type dispatch table. Deparse overhead over encode is ~49 µs (C library - [x] Forward-compatible decode (`UnrecognizedNode` fallback) - [x] Packed encoding for repeated scalar/enum fields - [x] `parse_ast()` deprecated in favor of `parse_protobuf_ast()` (~3× faster) -- [x] `PostgresDeparseOpts` ABI decoupled (opaque voidptr via C bridge setters) +- [x] `PostgresDeparseOpts` ABI decoupled (opaque voidptr, bridge layer eliminated) - [x] `valid_enum_int_strict()` for rejecting invalid enum values - [x] Self-validating version tests (no hardcoded PG version strings) - [x] Example: `examples/parse_sql.v` — all paths + typed AST traversal + rewriting + concurrency @@ -93,11 +95,11 @@ the sum-type dispatch table. Deparse overhead over encode is ~49 µs (C library | Use Case | Path | Ready? | |---|---|---| -| Fingerprint routing | `fingerprint()` | ✅ ~9 us/op | -| Normalize for logging | `normalize()` | ✅ ~4 us/op | +| Fingerprint routing | `fingerprint()` | ✅ ~6 us/op | +| Normalize for logging | `normalize()` | ✅ ~3 us/op | | Statement splitting | `split_with_scanner()` | ✅ | | DDL detection | `is_utility_stmt()` | ✅ | -| Shard key extraction | `parse_protobuf_ast()` | ✅ ~33 us/op | +| Shard key extraction | `parse_protobuf_ast()` | ✅ ~19 us/op | | Query rewriting | `deparse_ast()` | ✅ parse → modify V AST → reserialize | ## Key Decisions diff --git a/examples/bench.v b/examples/bench.v index 1b71a48..9b04603 100644 --- a/examples/bench.v +++ b/examples/bench.v @@ -1,13 +1,112 @@ import pg_query import time +// Heavy, multi-nested, complex queries exercising all parser/AST paths const queries = [ - 'SELECT id, name FROM users WHERE age > 21', - 'SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE c.status = \'active\' ORDER BY o.created_at DESC LIMIT 10', - 'INSERT INTO users (name, email, age) VALUES (\'Alice\', \'alice@example.com\', 30)', - 'UPDATE users SET name = \'Bob\' WHERE id = 42', - 'DELETE FROM sessions WHERE expires_at < NOW()', - 'CREATE TABLE t (id serial PRIMARY KEY, name text NOT NULL, created_at timestamptz DEFAULT NOW())', + // 1. 4-level nested SELECT with LATERAL, window functions, FILTER aggregates, CASE + 'SELECT sub3.region, sub3.product_category, sub3.total_revenue, sub3.rank_in_region, ' + + "CASE WHEN sub3.rank_in_region <= 3 THEN 'top_3' " + + "WHEN sub3.rank_in_region <= 10 THEN 'top_10' ELSE 'other' END AS tier, " + + "COALESCE(lat.top_product, 'none') AS top_product_in_region " + + 'FROM (SELECT sub2.region, sub2.product_category, sub2.total_revenue, ' + + 'ROW_NUMBER() OVER (PARTITION BY sub2.region ORDER BY sub2.total_revenue DESC) AS rank_in_region ' + + 'FROM (SELECT r.name AS region, pc.name AS product_category, SUM(s.amount) AS total_revenue, ' + + "COUNT(*) FILTER (WHERE s.status = 'completed') AS completed_count " + + 'FROM sales s JOIN products p ON s.product_id = p.id ' + + 'JOIN product_categories pc ON p.category_id = pc.id ' + + 'JOIN stores st ON s.store_id = st.id JOIN regions r ON st.region_id = r.id ' + + "WHERE s.sale_date >= '2024-01-01'::date AND s.sale_date < '2025-01-01'::date " + + "AND s.amount > 0 AND s.status IN ('completed', 'refunded') " + + 'GROUP BY r.id, r.name, pc.id, pc.name HAVING SUM(s.amount) > 10000) sub2) sub3 ' + + 'LEFT JOIN LATERAL (SELECT p2.name AS top_product FROM sales s2 ' + + 'JOIN products p2 ON s2.product_id = p2.id JOIN stores st2 ON s2.store_id = st2.id ' + + 'WHERE st2.region_id = (SELECT id FROM regions WHERE name = sub3.region) ' + + "AND s2.sale_date >= '2024-01-01'::date " + + 'GROUP BY p2.id, p2.name ORDER BY SUM(s2.amount) DESC LIMIT 1) lat ON true ' + + 'ORDER BY sub3.region, sub3.rank_in_region', + // 2. Complex analytical with JSON aggregation, window functions, FILTER, correlated subqueries + 'SELECT d.name AS department, e.role, ' + + 'COUNT(DISTINCT e.id) AS emp_count, ROUND(AVG(e.salary), 2) AS avg_salary, ' + + 'SUM(e.salary) AS total_salary_cost, ' + + "COUNT(*) FILTER (WHERE e.status = 'active') AS active_count, " + + "COUNT(*) FILTER (WHERE e.status = 'on_leave') AS on_leave_count, " + + "COUNT(*) FILTER (WHERE e.status = 'terminated') AS terminated_count, " + + "ROUND(AVG(e.salary) FILTER (WHERE e.status = 'active'), 2) AS avg_active_salary, " + + "json_build_array(json_build_object('status', 'active', 'count', " + + "COUNT(*) FILTER (WHERE e.status = 'active')), " + + "json_build_object('status', 'on_leave', 'count', " + + "COUNT(*) FILTER (WHERE e.status = 'on_leave')), " + + "json_build_object('status', 'terminated', 'count', " + + "COUNT(*) FILTER (WHERE e.status = 'terminated'))) AS status_breakdown, " + + '(SELECT json_agg(sub) FROM (SELECT e2.name, e2.salary, e2.status FROM employees e2 ' + + 'WHERE e2.dept_id = d.id AND e2.salary > AVG(e.salary) ' + + 'ORDER BY e2.salary DESC LIMIT 5) sub) AS top_above_avg, ' + + 'DENSE_RANK() OVER (ORDER BY SUM(e.salary) DESC) AS cost_rank, ' + + 'SUM(COUNT(*)) OVER (ORDER BY d.name ' + + 'ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_emp_count, ' + + 'FIRST_VALUE(e.role) OVER (PARTITION BY d.id ORDER BY e.salary DESC) AS highest_paid_role ' + + 'FROM departments d JOIN employees e ON e.dept_id = d.id ' + + 'WHERE d.active = true GROUP BY d.id, d.name, e.role ORDER BY d.name, cost_rank', + // 3. Multi-table UPDATE with CASE expressions, correlated subquery, RETURNING + 'UPDATE employees e SET salary = CASE ' + + "WHEN e.performance_rating >= 4 AND e.status = 'active' THEN e.salary * 1.15 + 2000 " + + "WHEN e.performance_rating >= 3 AND e.status = 'active' THEN e.salary * 1.08 + 1000 " + + "WHEN e.performance_rating >= 2 AND e.status = 'active' THEN e.salary * 1.03 " + + 'ELSE e.salary END, updated_at = NOW(), ' + + 'status = CASE WHEN e.performance_rating < 2 AND EXISTS ' + + '(SELECT 1 FROM performance_reviews pr WHERE pr.employee_id = e.id AND pr.score < 2 ' + + "AND pr.review_date >= NOW() - INTERVAL '90 days') " + + "THEN 'at_risk' ELSE e.status END, version = e.version + 1 " + + 'FROM departments d WHERE e.dept_id = d.id ' + + "AND d.name = ANY (ARRAY['Engineering', 'Product', 'Design']) " + + "AND e.hire_date < '2023-01-01'::date " + + 'AND e.id NOT IN (SELECT employee_id FROM exit_interviews WHERE scheduled = true) ' + + 'RETURNING e.id, e.name, e.salary AS new_salary, e.status, e.version', + // 4. Complex INSERT with LATERAL, multi-level subqueries, CASE, RETURNING + 'INSERT INTO order_summary (customer_id, customer_name, order_count, total_spent, ' + + 'avg_order_value, last_order_date, categories) ' + + 'SELECT c.id, c.name, COALESCE(ord.order_count, 0), COALESCE(ord.total_spent, 0.00), ' + + 'CASE WHEN ord.order_count > 0 THEN ROUND(ord.total_spent / ord.order_count, 2) ' + + 'ELSE 0.00 END, COALESCE(ord.last_order_date, NOW()), ' + + "COALESCE(lat.categories, '[]'::json) FROM customers c " + + 'LEFT JOIN LATERAL (SELECT COUNT(o.id) AS order_count, SUM(o.total) AS total_spent, ' + + 'MAX(o.created_at) AS last_order_date FROM orders o ' + + "WHERE o.customer_id = c.id AND o.status != 'cancelled' " + + "AND o.created_at >= NOW() - INTERVAL '365 days') ord ON true " + + 'LEFT JOIN LATERAL (SELECT json_agg(DISTINCT p.category) AS categories ' + + 'FROM orders o2 JOIN order_items oi ON o2.id = oi.order_id ' + + 'JOIN products p ON oi.product_id = p.id ' + + "WHERE o2.customer_id = c.id AND o2.created_at >= NOW() - INTERVAL '365 days') lat ON true " + + "WHERE c.status = 'active' AND ord.order_count IS NOT NULL AND ord.order_count > 0 " + + 'ORDER BY ord.total_spent DESC LIMIT 100 ' + + 'RETURNING id, customer_id, order_count, total_spent', + // 5. Complex DELETE with multi-level EXISTS, NOT IN, boolean OR, RETURNING + "DELETE FROM sessions s WHERE s.expires_at < NOW() - INTERVAL '30 days' " + + 'AND s.id NOT IN (SELECT session_id FROM active_connections ' + + "WHERE last_heartbeat > NOW() - INTERVAL '5 minutes') " + + "AND (s.user_id NOT IN (SELECT id FROM users WHERE status = 'locked') " + + "OR s.created_at < NOW() - INTERVAL '90 days') " + + 'AND EXISTS (SELECT 1 FROM session_logs sl ' + + "WHERE sl.session_id = s.id AND sl.event = 'expire_warning') " + + 'RETURNING s.id, s.user_id, s.created_at, s.expires_at', + // 6. Complex SELECT with DISTINCT ON, window functions, JSON, nested CASE, multi-level subqueries + 'SELECT DISTINCT ON (e.department_id) e.id, e.name, e.salary, e.department_id, ' + + 'd.name AS department_name, ' + + 'ROUND(AVG(e.salary) OVER (PARTITION BY e.department_id), 2) AS dept_avg_salary, ' + + 'ROW_NUMBER() OVER (PARTITION BY e.department_id ORDER BY e.salary DESC) AS rank_in_dept, ' + + 'CASE WHEN e.salary > AVG(e.salary) OVER (PARTITION BY e.department_id) * 1.5 ' + + "THEN 'overpaid' " + + 'WHEN e.salary < AVG(e.salary) OVER (PARTITION BY e.department_id) * 0.5 ' + + "THEN 'underpaid' ELSE 'market_rate' END AS comp_analysis, " + + "json_build_object('id', e.id, 'name', e.name, 'department', d.name, " + + "'peers', (SELECT json_agg(peer.name) FROM employees peer " + + 'WHERE peer.department_id = e.department_id AND peer.id != e.id ' + + 'AND ABS(peer.salary - e.salary) < e.salary * 0.1 ' + + 'ORDER BY peer.name)) AS employee_json, ' + + "(SELECT COUNT(*) FROM tasks t WHERE t.assignee_id = e.id AND t.status = 'open') AS open_tasks, " + + "(SELECT COUNT(*) FROM tasks t WHERE t.assignee_id = e.id AND t.status = 'overdue') AS overdue_tasks " + + 'FROM employees e JOIN departments d ON e.department_id = d.id ' + + "WHERE e.status = 'active' AND e.salary > 0 " + 'ORDER BY e.department_id, e.salary DESC', ] fn main() { @@ -32,7 +131,7 @@ fn main() { } } mut elapsed := time.since(start) - println(' parse() → JSON string ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' parse() JSON string ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- Protobuf path --- start = time.now() @@ -42,7 +141,7 @@ fn main() { } } elapsed = time.since(start) - println(' parse_protobuf() → raw bytes ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' parse_protobuf() raw bytes ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- Typed AST path (V-native protobuf decode) --- start = time.now() @@ -52,7 +151,7 @@ fn main() { } } elapsed = time.since(start) - println(' parse_protobuf_ast() → typed AST ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' parse_protobuf_ast() typed AST ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- JSON-to-AST path (JSON decode + sum-type conversion) --- start = time.now() @@ -63,7 +162,7 @@ fn main() { } } elapsed = time.since(start) - println(' parse_json_ast() → typed AST ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' parse_json_ast() typed AST ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- Fingerprint (fastest path) --- start = time.now() @@ -73,7 +172,7 @@ fn main() { } } elapsed = time.since(start) - println(' fingerprint() → hash ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' fingerprint() hash ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- Normalize --- start = time.now() @@ -83,7 +182,7 @@ fn main() { } } elapsed = time.since(start) - println(' normalize() → anonymized SQL ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' normalize() anonymized SQL ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- V-native protobuf encode (pure V, no C) --- start = time.now() @@ -95,18 +194,20 @@ fn main() { } } elapsed = time.since(start) - println(' encode_parse_result() → protobuf ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' encode_parse_result() protobuf ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') // --- Deparse roundtrip (V encode + C deparse) --- start = time.now() for _ in 0 .. n { for q in queries { - s := pg_query.deparse_ast(pg_query.parse_protobuf_ast(q) or { panic(err) }) or { panic(err) } + s := pg_query.deparse_ast(pg_query.parse_protobuf_ast(q) or { panic(err) }) or { + panic(err) + } _ = s } } elapsed = time.since(start) - println(' deparse_ast() → SQL (encode+deparse) ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') + println(' deparse_ast() SQL (encode+deparse) ${f64(elapsed.microseconds()) / f64(total_ops):8.2f} us/op (${elapsed.milliseconds()} ms)') println('') println('Note: deparse_ast() calls encode_parse_result() internally,') diff --git a/examples/parse_sql.v b/examples/parse_sql.v index a22bc6f..bdc9427 100644 --- a/examples/parse_sql.v +++ b/examples/parse_sql.v @@ -51,21 +51,119 @@ fn print_select(s pg_query.SelectStmt) { } } println(' where: ${parts.join(' ')}') + } else { + println(' where: (complex expression)') + } + if s.distinct_clause.len > 0 { + println(' distinct_on: true') } } fn parse_single(input string) string { res := pg_query.parse_protobuf_ast(input) or { return 'ERROR: ${err}' } - return '${input} -> ${res.stmts.len} statement(s)' + mut preview := input + if preview.len > 50 { preview = preview[..50] } + return '${preview}... -> ${res.stmts.len} statement(s)' } +// Heavy, multi-nested, complex queries +const heavy_select = 'SELECT DISTINCT ON (e.department_id) e.id, e.name, e.salary, ' + + 'e.department_id, d.name AS department_name, ' + + 'ROUND(AVG(e.salary) OVER (PARTITION BY e.department_id), 2) AS dept_avg_salary, ' + + 'ROW_NUMBER() OVER (PARTITION BY e.department_id ORDER BY e.salary DESC) AS rank_in_dept, ' + + 'CASE WHEN e.salary > AVG(e.salary) OVER (PARTITION BY e.department_id) * 1.5 ' + + 'THEN \'overpaid\' WHEN e.salary < AVG(e.salary) OVER (PARTITION BY e.department_id) * 0.5 ' + + 'THEN \'underpaid\' ELSE \'market_rate\' END AS comp_analysis, ' + + 'json_build_object(\'id\', e.id, \'name\', e.name, \'department\', d.name, ' + + '\'peers\', (SELECT json_agg(peer.name) FROM employees peer ' + + 'WHERE peer.department_id = e.department_id AND peer.id != e.id ' + + 'AND ABS(peer.salary - e.salary) < e.salary * 0.1 ORDER BY peer.name)) AS employee_json, ' + + '(SELECT COUNT(*) FROM tasks t WHERE t.assignee_id = e.id AND t.status = \'open\') AS open_tasks, ' + + '(SELECT COUNT(*) FROM tasks t WHERE t.assignee_id = e.id AND t.status = \'overdue\') AS overdue_tasks ' + + 'FROM employees e JOIN departments d ON e.department_id = d.id ' + + 'WHERE e.status = \'active\' AND e.salary > 0 ORDER BY e.department_id, e.salary DESC' + +const heavy_analytical = 'SELECT d.name AS department, e.role, ' + + 'COUNT(DISTINCT e.id) AS emp_count, ROUND(AVG(e.salary), 2) AS avg_salary, ' + + 'SUM(e.salary) AS total_salary_cost, ' + + 'COUNT(*) FILTER (WHERE e.status = \'active\') AS active_count, ' + + 'COUNT(*) FILTER (WHERE e.status = \'on_leave\') AS on_leave_count, ' + + 'json_build_array(json_build_object(\'status\', \'active\', \'count\', ' + + 'COUNT(*) FILTER (WHERE e.status = \'active\'))) AS status_breakdown, ' + + 'DENSE_RANK() OVER (ORDER BY SUM(e.salary) DESC) AS cost_rank, ' + + 'SUM(COUNT(*)) OVER (ORDER BY d.name ' + + 'ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_emp_count ' + + 'FROM departments d JOIN employees e ON e.dept_id = d.id ' + + 'WHERE d.active = true GROUP BY d.id, d.name, e.role ORDER BY d.name, cost_rank' + +const heavy_update = 'UPDATE employees e SET salary = CASE ' + + 'WHEN e.performance_rating >= 4 AND e.status = \'active\' THEN e.salary * 1.15 + 2000 ' + + 'WHEN e.performance_rating >= 3 AND e.status = \'active\' THEN e.salary * 1.08 + 1000 ' + + 'WHEN e.performance_rating >= 2 AND e.status = \'active\' THEN e.salary * 1.03 ' + + 'ELSE e.salary END, updated_at = NOW(), ' + + 'status = CASE WHEN e.performance_rating < 2 AND EXISTS ' + + '(SELECT 1 FROM performance_reviews pr WHERE pr.employee_id = e.id AND pr.score < 2 ' + + 'AND pr.review_date >= NOW() - INTERVAL \'90 days\') ' + + 'THEN \'at_risk\' ELSE e.status END, version = e.version + 1 ' + + 'FROM departments d WHERE e.dept_id = d.id ' + + 'AND d.name = ANY (ARRAY[\'Engineering\', \'Product\', \'Design\']) ' + + 'AND e.hire_date < \'2023-01-01\'::date ' + + 'AND e.id NOT IN (SELECT employee_id FROM exit_interviews WHERE scheduled = true) ' + + 'RETURNING e.id, e.name, e.salary AS new_salary, e.status, e.version' + +const heavy_insert = 'INSERT INTO order_summary (customer_id, customer_name, ' + + 'order_count, total_spent, avg_order_value, last_order_date, categories) ' + + 'SELECT c.id, c.name, COALESCE(ord.order_count, 0), COALESCE(ord.total_spent, 0.00), ' + + 'CASE WHEN ord.order_count > 0 THEN ROUND(ord.total_spent / ord.order_count, 2) ELSE 0.00 END, ' + + 'COALESCE(ord.last_order_date, NOW()), COALESCE(lat.categories, \'[]\'::json) ' + + 'FROM customers c LEFT JOIN LATERAL (SELECT COUNT(o.id) AS order_count, ' + + 'SUM(o.total) AS total_spent, MAX(o.created_at) AS last_order_date ' + + 'FROM orders o WHERE o.customer_id = c.id AND o.status != \'cancelled\' ' + + 'AND o.created_at >= NOW() - INTERVAL \'365 days\') ord ON true ' + + 'LEFT JOIN LATERAL (SELECT json_agg(DISTINCT p.category) AS categories ' + + 'FROM orders o2 JOIN order_items oi ON o2.id = oi.order_id ' + + 'JOIN products p ON oi.product_id = p.id ' + + 'WHERE o2.customer_id = c.id AND o2.created_at >= NOW() - INTERVAL \'365 days\') lat ON true ' + + 'WHERE c.status = \'active\' AND ord.order_count IS NOT NULL AND ord.order_count > 0 ' + + 'ORDER BY ord.total_spent DESC LIMIT 100 RETURNING id, customer_id, order_count, total_spent' + +const heavy_delete = 'DELETE FROM sessions s WHERE s.expires_at < NOW() - INTERVAL \'30 days\' ' + + 'AND s.id NOT IN (SELECT session_id FROM active_connections ' + + 'WHERE last_heartbeat > NOW() - INTERVAL \'5 minutes\') ' + + 'AND (s.user_id NOT IN (SELECT id FROM users WHERE status = \'locked\') ' + + 'OR s.created_at < NOW() - INTERVAL \'90 days\') ' + + 'AND EXISTS (SELECT 1 FROM session_logs sl ' + + 'WHERE sl.session_id = s.id AND sl.event = \'expire_warning\') ' + + 'RETURNING s.id, s.user_id, s.created_at, s.expires_at' + +const heavy_nested = 'SELECT sub3.region, sub3.product_category, sub3.total_revenue, ' + + 'sub3.rank_in_region, CASE WHEN sub3.rank_in_region <= 3 THEN \'top_3\' ' + + 'WHEN sub3.rank_in_region <= 10 THEN \'top_10\' ELSE \'other\' END AS tier, ' + + 'COALESCE(lat.top_product, \'none\') AS top_product_in_region FROM ' + + '(SELECT sub2.region, sub2.product_category, sub2.total_revenue, ' + + 'ROW_NUMBER() OVER (PARTITION BY sub2.region ORDER BY sub2.total_revenue DESC) AS rank_in_region ' + + 'FROM (SELECT r.name AS region, pc.name AS product_category, SUM(s.amount) AS total_revenue, ' + + 'COUNT(*) FILTER (WHERE s.status = \'completed\') AS completed_count ' + + 'FROM sales s JOIN products p ON s.product_id = p.id ' + + 'JOIN product_categories pc ON p.category_id = pc.id ' + + 'JOIN stores st ON s.store_id = st.id JOIN regions r ON st.region_id = r.id ' + + 'WHERE s.sale_date >= \'2024-01-01\'::date AND s.sale_date < \'2025-01-01\'::date ' + + 'AND s.amount > 0 AND s.status IN (\'completed\', \'refunded\') ' + + 'GROUP BY r.id, r.name, pc.id, pc.name HAVING SUM(s.amount) > 10000) sub2) sub3 ' + + 'LEFT JOIN LATERAL (SELECT p2.name AS top_product FROM sales s2 ' + + 'JOIN products p2 ON s2.product_id = p2.id JOIN stores st2 ON s2.store_id = st2.id ' + + 'WHERE st2.region_id = (SELECT id FROM regions WHERE name = sub3.region) ' + + 'AND s2.sale_date >= \'2024-01-01\'::date ' + + 'GROUP BY p2.id, p2.name ORDER BY SUM(s2.amount) DESC LIMIT 1) lat ON true ' + + 'ORDER BY sub3.region, sub3.rank_in_region' + fn main() { - // ── 1. Typed AST with tree traversal ── - result := pg_query.parse_protobuf_ast('SELECT id, name FROM users WHERE age > 21') or { + // ── 1. Typed AST with tree traversal (heavy SELECT) ── + result := pg_query.parse_protobuf_ast(heavy_select) or { eprintln('Parse error: ${err}') return } - println('=== Typed AST (traversed) ===') + println('=== Typed AST (traversed): ${heavy_select[..60]}... ===') for stmt in result.stmts { match stmt.stmt { pg_query.SelectStmt { print_select(stmt.stmt) } @@ -73,54 +171,61 @@ fn main() { } } - // ── 2. Parse SQL to JSON ── - json_res := pg_query.parse('SELECT id, name FROM users WHERE age > 21') or { + // ── 2. Parse heavy SELECT to JSON ── + json_res := pg_query.parse(heavy_nested) or { eprintln('Parse error: ${err}') return } - println('\n=== Parse tree (JSON) ===') - println(json_res.parse_tree) + println('\n=== Parse tree (JSON): 4-level nested SELECT ===') + mut tree := json_res.parse_tree + if tree.len > 500 { tree = tree[..500] } + println('${tree}...') + println(' (${json_res.parse_tree.len} chars total)') - // ── 3. Normalize (anonymize literals) ── - norm := pg_query.normalize('SELECT * FROM users WHERE id = 42') or { + // ── 3. Normalize (anonymize literals) heavy query ── + norm := pg_query.normalize(heavy_update) or { eprintln('Normalize error: ${err}') return } - println('\n=== Normalized ===') + println('\n=== Normalized (heavy UPDATE with CASE) ===') println(norm.normalized_query) // ── 4. Fingerprint (consistent hash for same query structure) ── - fp := pg_query.fingerprint('SELECT 1') or { + fp := pg_query.fingerprint(heavy_analytical) or { eprintln('Fingerprint error: ${err}') return } - println('\n=== Fingerprint ===') + println('\n=== Fingerprint (analytical query) ===') println(' hex: ${fp.fingerprint_str}') println(' int: ${fp.fingerprint}') // ── 5. Check if DDL ── - util := pg_query.is_utility_stmt('CREATE TABLE t (id int)') or { + util := pg_query.is_utility_stmt('CREATE TABLE IF NOT EXISTS measurements_y2024m12 (' + + 'CHECK (measured_at >= \'2024-12-01\'::date AND measured_at < \'2025-01-01\'::date), ' + + 'FOREIGN KEY (device_id) REFERENCES devices(id) ON DELETE CASCADE' + + ') INHERITS (measurements)') or { eprintln('IsUtility error: ${err}') return } - println('\n=== Utility check ===') - println(' CREATE TABLE is utility: ${util.items[0]}') + println('\n=== Utility check (CREATE TABLE ... INHERITS) ===') + println(' is utility: ${util.items[0]}') - // ── 6. Parse to protobuf (compact binary) ── - pb := pg_query.parse_protobuf('SELECT 1') or { + // ── 6. Parse to protobuf (compact binary) heavy query ── + pb := pg_query.parse_protobuf(heavy_delete) or { eprintln('Protobuf error: ${err}') return } - println('\n=== Protobuf ===') + println('\n=== Protobuf (heavy DELETE with EXISTS) ===') println(' bytes: ${pb.parse_tree.len}') - println(' hex: ${pb.parse_tree.hex()}') + println(' hex: ${pb.parse_tree.hex().substr(0, 80)}...') - // ── 7. Split multi-statement SQL ── - split := pg_query.split_with_scanner('SELECT 1; SELECT 2; SELECT 3') or { + // ── 7. Split multi-statement SQL (heavy queries) ── + multi_sql := heavy_select + '; ' + heavy_analytical + '; ' + heavy_nested + split := pg_query.split_with_scanner(multi_sql) or { eprintln('Split error: ${err}') return } - println('\n=== Split statements ===') + println('\n=== Split statements (3 heavy queries) ===') for i, stmt in split.stmts { println(' ${i + 1}. location=${stmt.stmt_location}, len=${stmt.stmt_len}') } @@ -130,11 +235,13 @@ fn main() { eprintln('Deparse error: ${err}') return } - println('\n=== Deparse roundtrip ===') - println(' ${deparsed.query}') + println('\n=== Deparse roundtrip (heavy DELETE) ===') + mut dq := deparsed.query + if dq.len > 200 { dq = dq[..200] } + println(' ${dq}...') // ── 9. Pure-V AST roundtrip: parse -> typed AST -> encode -> deparse ── - ast := pg_query.parse_protobuf_ast('SELECT id, name FROM users') or { + ast := pg_query.parse_protobuf_ast(heavy_insert) or { eprintln('Parse error: ${err}') return } @@ -143,18 +250,23 @@ fn main() { eprintln('Deparse error: ${err}') return } - println('\n=== Pure-V AST roundtrip ===') - println(' input: SELECT id, name FROM users') - println(' output: ${deparsed2.query}') + println('\n=== Pure-V AST roundtrip (heavy INSERT + LATERAL) ===') + mut dq2 := deparsed2.query + if dq2.len > 200 { dq2 = dq2[..200] } + println(' input: ${heavy_insert[..60]}...') + println(' output: ${dq2}...') println(' V decode + V encode + C deparse') - // ── 10. Query rewrite: modify AST in pure V ── - mut sel := ast.stmts[0].stmt as pg_query.SelectStmt + // ── 10. Query rewrite: modify AST in pure V (rename table in a heavy query) ── + ast2 := pg_query.parse_protobuf_ast(heavy_select) or { panic(err) } + mut sel := ast2.stmts[0].stmt as pg_query.SelectStmt mut new_from := []pg_query.Node{} for n in sel.from_clause { if n is pg_query.RangeVar { mut rv := n - rv.relname = 'users_v2' + if rv.relname == 'employees' { + rv.relname = 'employees_v2' + } new_from << rv } else { new_from << n @@ -162,24 +274,23 @@ fn main() { } sel.from_clause = new_from rewritten := pg_query.deparse_ast(pg_query.ParseAstResult{ - version: ast.version + version: ast2.version stmts: [pg_query.AstRawStmt{ - stmt_location: ast.stmts[0].stmt_location - stmt_len: ast.stmts[0].stmt_len + stmt_location: ast2.stmts[0].stmt_location + stmt_len: ast2.stmts[0].stmt_len stmt: sel }] }) or { eprintln('Rewrite deparse error: ${err}'); return } - println('\n=== Query rewrite (users → users_v2) ===') - println(' ${rewritten}') - - // ── 11. Concurrent parsing ── - // The C parser uses thread-local memory contexts and is safe to - // call from multiple OS threads simultaneously. Do NOT call exit() - // while other threads may be actively parsing. - println('\n=== Concurrent parsing ===') - queries := ['SELECT 1', 'SELECT 2; SELECT 3', 'CREATE TABLE t (id int)', - 'DELETE FROM t WHERE id = 0', 'UPDATE t SET x = 1', 'SELECT count(*) FROM t', 'DROP TABLE t', - 'INSERT INTO t VALUES (1)'] + println('\n=== Query rewrite (employees -> employees_v2) ===') + mut rw := rewritten + if rw.len > 200 { rw = rw[..200] } + println(' ${rw}...') + + // ── 11. Concurrent parsing (heavy queries) ── + println('\n=== Concurrent parsing (heavy queries) ===') + queries := [heavy_select, heavy_analytical + '; ' + heavy_nested, + heavy_delete, heavy_update, heavy_insert, + 'DROP TABLE IF EXISTS measurements_y2024m12'] mut threads := []thread string{} for q in queries { threads << spawn parse_single(q) @@ -188,4 +299,47 @@ fn main() { for r in results { println(' ${r}') } + + // ── 12. Comment extraction and roundtrip ── + commented_sql := 'SELECT 1; -- first statement\nSELECT 2 /* block */; SELECT 3 -- trailing' + comments_res := pg_query.deparse_comments_for_query(commented_sql) or { + eprintln('Comment extraction error: ${err}') + return + } + println('\n=== Comment extraction ===') + println(' SQL: ${commented_sql.replace('\n', '\\n')}') + println(' Comments found: ${comments_res.comments.len}') + for i, c in comments_res.comments { + println(' ${i + 1}. loc=${c.match_location} before=${c.newlines_before_comment} after=${c.newlines_after_comment}') + println(' text: ${c.str.replace('\n', '\\n')}') + } + + // Roundtrip: parse a query with inline comment, then deparse with comments preserved. + // Note: comments between AST nodes are preserved; trailing end-of-statement comments + // are not preserved (C library limitation). + comment_roundtrip_sql := 'SELECT a, /* my comment */ b FROM t' + pb_com := pg_query.parse_protobuf(comment_roundtrip_sql) or { + eprintln('Parse error: ${err}') + return + } + com_res := pg_query.deparse_comments_for_query(comment_roundtrip_sql) or { + eprintln('Comment extraction error: ${err}') + return + } + dep_with_comments := pg_query.deparse_protobuf_opts(pb_com.parse_tree, pg_query.DeparseOpts{ + comments: com_res.comments + }) or { + eprintln('Deparse error: ${err}') + return + } + println('\n=== Comment roundtrip (parse → deparse with comments) ===') + println(' input: ${comment_roundtrip_sql}') + println(' output: ${dep_with_comments.query}') + + // Without comments (default deparse — comment is stripped) + dep_no_comments := pg_query.deparse_protobuf(pb_com.parse_tree) or { + eprintln('Deparse error: ${err}') + return + } + println(' default: ${dep_no_comments.query}') } diff --git a/examples/throughput.v b/examples/throughput.v new file mode 100644 index 0000000..ca47b96 --- /dev/null +++ b/examples/throughput.v @@ -0,0 +1,190 @@ +import pg_query +import time +import runtime + +#include + +// ru_maxrss offset within struct rusage on macOS arm64. +// timeval = 16 bytes × 2 (ru_utime, ru_stime) = 32 bytes. +const ru_maxrss_offset = 32 + +fn C.getrusage(who int, usage voidptr) int + +const rusage_self = 0 + +const perf_iter = 5000 + +// Mixed query workload mimicking a real database proxy/router. +const workload = [ + 'SELECT id, name, email FROM users WHERE id = $1', + 'INSERT INTO orders (user_id, total) VALUES ($1, $2) RETURNING id', + 'UPDATE users SET last_login = NOW() WHERE id = $1', + 'SELECT * FROM products WHERE sku = $1', + 'DELETE FROM sessions WHERE expires_at < NOW()', + 'SELECT d.name, COUNT(e.id) AS emp_count, ROUND(AVG(e.salary), 2) AS avg_salary ' + + 'FROM departments d JOIN employees e ON e.dept_id = d.id GROUP BY d.id, d.name ORDER BY avg_salary DESC', + 'SELECT DATE_TRUNC(\'month\', created_at) AS month, COUNT(*) AS signups ' + + 'FROM users WHERE created_at >= NOW() - INTERVAL \'6 months\' GROUP BY 1 ORDER BY 1', + 'CREATE TABLE IF NOT EXISTS archive_2025 (LIKE orders INCLUDING ALL)', + 'ALTER TABLE users ADD COLUMN IF NOT EXISTS phone VARCHAR(20)', + 'VACUUM ANALYZE orders', + 'EXPLAIN ANALYZE SELECT * FROM users JOIN orders ON users.id = orders.user_id WHERE users.id = $1', + 'SELECT DISTINCT ON (e.department_id) e.id, e.name, e.salary, ' + + 'ROUND(AVG(e.salary) OVER (PARTITION BY e.department_id), 2) AS dept_avg, ' + + 'ROW_NUMBER() OVER (PARTITION BY e.department_id ORDER BY e.salary DESC) AS rank ' + + 'FROM employees e JOIN departments d ON e.department_id = d.id WHERE e.status = \'active\'', +] + +fn main() { + ncores := runtime.nr_cpus() + println('=== pg_query.v — Real-World Throughput ===') + println(' cpus: ${ncores}') + println('') + + // Warmup + print('Warming up (1s) ... ') + mut warm_count := 0 + mut t := time.now() + for time.since(t) < time.second { + for q in workload { + pg_query.parse_protobuf_ast(q) or { continue } + warm_count++ + } + } + we := time.since(t) + println('${warm_count} parse-only = ${f64(warm_count) / we.seconds():.0f} qps') + println('') + + // Pooler: fingerprint + parse + normalize per query + println('=== Pooler Workload (3s) ===') + println(' fingerprint() + parse_protobuf_ast() + normalize() per query') + println('') + + mut fprints := []u64{} + mut total := 0 + + r0_buf := []u8{len: 200} + C.getrusage(rusage_self, r0_buf.data) + + wall_start := time.now() + for time.since(wall_start) < 3 * time.second { + for q in workload { + fp := pg_query.fingerprint(q) or { continue } + fprints << fp.fingerprint + ast := pg_query.parse_protobuf_ast(q) or { continue } + _ = ast + n := pg_query.normalize(q) or { continue } + _ = n.normalized_query.len + total++ + } + } + wall_us := f64(time.since(wall_start).microseconds()) + qps := f64(total) / (wall_us / 1_000_000.0) + + r1_buf := []u8{len: 200} + C.getrusage(rusage_self, r1_buf.data) + + maxrss1 := unsafe { *(&i64(&r1_buf[ru_maxrss_offset])) } + cpu_us := cpu_delta(r0_buf, r1_buf) + + println(' queries: ${total}') + println(' throughput: ${qps:10.0f} qps') + println(' per query: ${wall_us / f64(total):7.2f} us') + println(' cpu time: ${cpu_us / 1000.0:8.0f} ms (${cpu_us / wall_us * 100.0:5.1f}%)') + println(' max RSS: ${format_mem(u64(maxrss1))}') + println(' fingerprints: ${unique_count(fprints)} unique') + println('') + + // Per-path microbenchmarks + total_ops := perf_iter * workload.len + println('=== Per-Path (${workload.len} queries × ${perf_iter} iterations = ${total_ops} ops) ===') + println('') + + microbench('fingerprint ', perf_iter, total_ops, fn () { + for _ in 0 .. perf_iter { + for q in workload { + pg_query.fingerprint(q) or { panic(err) } + } + } + }) + microbench('normalize ', perf_iter, total_ops, fn () { + for _ in 0 .. perf_iter { + for q in workload { + pg_query.normalize(q) or { panic(err) } + } + } + }) + microbench('parse() JSON ', perf_iter, total_ops, fn () { + for _ in 0 .. perf_iter { + for q in workload { + pg_query.parse(q) or { panic(err) } + } + } + }) + microbench('parse_protobuf_ast ', perf_iter, total_ops, fn () { + for _ in 0 .. perf_iter { + for q in workload { + pg_query.parse_protobuf_ast(q) or { panic(err) } + } + } + }) + microbench('deparse_ast ', perf_iter, total_ops, fn () { + for _ in 0 .. perf_iter { + for q in workload { + s := pg_query.deparse_ast(pg_query.parse_protobuf_ast(q) or { + panic(err) + }) or { panic(err) } + _ = s + } + } + }) +} + +fn microbench(label string, n int, total_ops int, cb fn ()) { + b0 := []u8{len: 200} + C.getrusage(rusage_self, b0.data) + start := time.now() + cb() + b1 := []u8{len: 200} + C.getrusage(rusage_self, b1.data) + + wall_us := f64(time.since(start).microseconds()) + us_per := wall_us / f64(total_ops) + qps_core := if us_per > 0 { 1_000_000.0 / us_per } else { 0.0 } + cpu := cpu_delta(b0, b1) + rss := unsafe { *(&i64(&b1[ru_maxrss_offset])) } + println(' ${label} ${us_per:7.2f} us/op ${qps_core:9.0f} qps/core cpu:${f64(cpu) / wall_us * 100.0:4.0f}% rss:${format_mem(u64(rss))}') +} + +fn cpu_delta(b0 []u8, b1 []u8) f64 { + utime0 := unsafe { *(&i64(&b0[0])) } + utime1 := unsafe { *(&i64(&b1[0])) } + utime_usec0 := unsafe { *(&i32(&b0[8])) } + utime_usec1 := unsafe { *(&i32(&b1[8])) } + stime0 := unsafe { *(&i64(&b0[16])) } + stime1 := unsafe { *(&i64(&b1[16])) } + stime_usec0 := unsafe { *(&i32(&b0[24])) } + stime_usec1 := unsafe { *(&i32(&b1[24])) } + return f64((utime1 - utime0) * 1_000_000 + (utime_usec1 - utime_usec0) + + (stime1 - stime0) * 1_000_000 + (stime_usec1 - stime_usec0)) +} + +fn unique_count(arr []u64) int { + mut seen := map[u64]bool{} + for v in arr { + seen[v] = true + } + return seen.len +} + +fn format_mem(b u64) string { + if b >= 1_000_000_000 { + return '${f64(b) / 1_000_000_000.0:.2f} GB' + } else if b >= 1_000_000 { + return '${f64(b) / 1_000_000.0:.2f} MB' + } else if b >= 1_000 { + return '${f64(b) / 1_000.0:.2f} KB' + } else { + return '${b} B' + } +} diff --git a/pg_query/c_bridge.c b/pg_query/c_bridge.c deleted file mode 100644 index aee2cc5..0000000 --- a/pg_query/c_bridge.c +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include "pg_query.h" - -/* - * Bridge setters for PostgresDeparseOpts fields. - * V code must never access C.PostgresDeparseOpts fields directly — - * all field access goes through these bridge functions. This decouples - * the V declaration from the C struct layout entirely. - */ -void pg_query_bridge_deparse_opts_set_pretty_print(void *opts, int val) { - ((PostgresDeparseOpts*)opts)->pretty_print = val; -} - -void pg_query_bridge_deparse_opts_set_indent_size(void *opts, int val) { - ((PostgresDeparseOpts*)opts)->indent_size = val; -} - -void pg_query_bridge_deparse_opts_set_max_line_length(void *opts, int val) { - ((PostgresDeparseOpts*)opts)->max_line_length = val; -} - -void pg_query_bridge_deparse_opts_set_trailing_newline(void *opts, int val) { - ((PostgresDeparseOpts*)opts)->trailing_newline = val; -} - -void pg_query_bridge_deparse_opts_set_commas_start_of_line(void *opts, int val) { - ((PostgresDeparseOpts*)opts)->commas_start_of_line = val; -} - -void pg_query_bridge_deparse_opts_set_comment_count(void *opts, size_t val) { - ((PostgresDeparseOpts*)opts)->comment_count = val; -} - -void* pg_query_bridge_split_stmts_get(void *stmts, int index) { - return ((void**)stmts)[index]; -} - -void* pg_query_bridge_deparse_comments_get(void *comments, size_t index) { - return ((void**)comments)[index]; -} - -const char* pg_query_bridge_pg_version(void) { - return PG_VERSION; -} - -const char* pg_query_bridge_pg_major_version(void) { - return PG_MAJORVERSION; -} - -void* pg_query_bridge_deparse_opts_new(void) { - return calloc(1, sizeof(PostgresDeparseOpts)); -} - -void pg_query_bridge_deparse_opts_init_comments(void *opts, size_t count) { - ((PostgresDeparseOpts*)opts)->comments = calloc(count, sizeof(PostgresDeparseComment*)); - ((PostgresDeparseOpts*)opts)->comment_count = count; -} - -void pg_query_bridge_deparse_opts_set_comment(void *opts, size_t index, - int location, int newlines_before, int newlines_after, const char *str) -{ - PostgresDeparseOpts *o = (PostgresDeparseOpts*)opts; - o->comments[index] = calloc(1, sizeof(PostgresDeparseComment)); - o->comments[index]->match_location = location; - o->comments[index]->newlines_before_comment = newlines_before; - o->comments[index]->newlines_after_comment = newlines_after; - o->comments[index]->str = str ? strdup(str) : NULL; -} - -void pg_query_bridge_deparse_opts_free(void *opts) { - if (!opts) return; - PostgresDeparseOpts *o = (PostgresDeparseOpts*)opts; - if (o->comments) { - for (size_t i = 0; i < o->comment_count; i++) { - if (o->comments[i]) { - free(o->comments[i]->str); - free(o->comments[i]); - } - } - free(o->comments); - } - free(o); -} - -PgQueryDeparseResult pg_query_bridge_deparse_protobuf_opts(PgQueryProtobuf parse_tree, void *opts) { - return pg_query_deparse_protobuf_opts(parse_tree, *(PostgresDeparseOpts*)opts); -} diff --git a/pg_query/c_bridge.h b/pg_query/c_bridge.h deleted file mode 100644 index ac8c1e0..0000000 --- a/pg_query/c_bridge.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "pg_query.h" - -void* pg_query_bridge_split_stmts_get(void *stmts, int index); -void* pg_query_bridge_deparse_comments_get(void *comments, size_t index); - -const char* pg_query_bridge_pg_version(void); -const char* pg_query_bridge_pg_major_version(void); - -void* pg_query_bridge_deparse_opts_new(void); -void pg_query_bridge_deparse_opts_set_pretty_print(void *opts, int val); -void pg_query_bridge_deparse_opts_set_indent_size(void *opts, int val); -void pg_query_bridge_deparse_opts_set_max_line_length(void *opts, int val); -void pg_query_bridge_deparse_opts_set_trailing_newline(void *opts, int val); -void pg_query_bridge_deparse_opts_set_commas_start_of_line(void *opts, int val); -void pg_query_bridge_deparse_opts_set_comment_count(void *opts, size_t count); -void pg_query_bridge_deparse_opts_init_comments(void *opts, size_t count); -void pg_query_bridge_deparse_opts_set_comment(void *opts, size_t index, - int location, int newlines_before, int newlines_after, const char *str); -void pg_query_bridge_deparse_opts_free(void *opts); -PgQueryDeparseResult pg_query_bridge_deparse_protobuf_opts(PgQueryProtobuf parse_tree, void *opts); diff --git a/pg_query/compile_flags.txt b/pg_query/compile_flags.txt deleted file mode 100644 index a01d6d8..0000000 --- a/pg_query/compile_flags.txt +++ /dev/null @@ -1,2 +0,0 @@ --I../libpg_query --I../libpg_query/vendor diff --git a/pg_query/pg_query_encode.v b/pg_query/pg_query_encode.v deleted file mode 100644 index fa4949e..0000000 --- a/pg_query/pg_query_encode.v +++ /dev/null @@ -1,10850 +0,0 @@ -// Code generated by tools/gen_ast.v from libpg_query/protobuf/pg_query.proto -// DO NOT EDIT. -module pg_query - -pub fn encode_scan_result(val ScanResult) []u8 { - mut buf := []u8{} - if val.version != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.version)) - } - if val.tokens.len > 0 { - for v in val.tokens { - sub_enc_ := encode_scan_token(v) - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - } - return buf -} - -pub fn encode_integer(val Integer) []u8 { - mut buf := []u8{} - if val.ival != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.ival)) - } - return buf -} - -pub fn encode_float(val Float) []u8 { - mut buf := []u8{} - if val.fval != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.fval) - } - return buf -} - -pub fn encode_boolean(val Boolean) []u8 { - mut buf := []u8{} - if val.boolval { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.boolval) - } - return buf -} - -pub fn encode_string(val String) []u8 { - mut buf := []u8{} - if val.sval != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.sval) - } - return buf -} - -pub fn encode_bit_string(val BitString) []u8 { - mut buf := []u8{} - if val.bsval != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.bsval) - } - return buf -} - -pub fn encode_list(val List) []u8 { - mut buf := []u8{} - if val.items.len > 0 { - for v in val.items { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_oid_list(val OidList) []u8 { - mut buf := []u8{} - if val.items.len > 0 { - for v in val.items { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_int_list(val IntList) []u8 { - mut buf := []u8{} - if val.items.len > 0 { - for v in val.items { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_a_const(val AConst) []u8 { - mut buf := []u8{} - if v := val.ival { - sub_enc_ := encode_integer(v) - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - if v := val.fval { - sub_enc_ := encode_float(v) - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - if v := val.boolval { - sub_enc_ := encode_boolean(v) - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - if v := val.sval { - sub_enc_ := encode_string(v) - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - if v := val.bsval { - sub_enc_ := encode_bit_string(v) - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - if val.isnull { - write_tag_into(mut buf, 10, 0) - write_bool_into(mut buf, val.isnull) - } - if val.location != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_alias(val Alias) []u8 { - mut buf := []u8{} - if val.aliasname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.aliasname) - } - if val.colnames.len > 0 { - for v in val.colnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_table_func(val TableFunc) []u8 { - mut buf := []u8{} - if u64(val.functype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.functype)) - } - if val.ns_uris.len > 0 { - for v in val.ns_uris { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.ns_names.len > 0 { - for v in val.ns_names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_docexpr := encode_node(val.docexpr) - if n_docexpr.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_docexpr) - } - n_rowexpr := encode_node(val.rowexpr) - if n_rowexpr.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_rowexpr) - } - if val.colnames.len > 0 { - for v in val.colnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.coltypes.len > 0 { - for v in val.coltypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.coltypmods.len > 0 { - for v in val.coltypmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.colcollations.len > 0 { - for v in val.colcollations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.colexprs.len > 0 { - for v in val.colexprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.coldefexprs.len > 0 { - for v in val.coldefexprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.colvalexprs.len > 0 { - for v in val.colvalexprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 12, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.passingvalexprs.len > 0 { - for v in val.passingvalexprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.notnulls.len > 0 { - mut packed_ := []u8{} - for v in val.notnulls { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 14, 2) - write_length_delimited_into(mut buf, packed_) - } - n_plan := encode_node(val.plan) - if n_plan.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, n_plan) - } - if val.ordinalitycol != 0 { - write_tag_into(mut buf, 16, 0) - write_varint_into(mut buf, u64(val.ordinalitycol)) - } - if val.location != 0 { - write_tag_into(mut buf, 17, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_var(val Var) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.varno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.varno)) - } - if val.varattno != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.varattno)) - } - if val.vartype != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.vartype)) - } - if val.vartypmod != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.vartypmod)) - } - if val.varcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.varcollid)) - } - if val.varnullingrels.len > 0 { - mut packed_ := []u8{} - for v in val.varnullingrels { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, packed_) - } - if val.varlevelsup != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.varlevelsup)) - } - if val.location != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_param(val Param) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.paramkind) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.paramkind)) - } - if val.paramid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.paramid)) - } - if val.paramtype != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.paramtype)) - } - if val.paramtypmod != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.paramtypmod)) - } - if val.paramcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.paramcollid)) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_aggref(val Aggref) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.aggfnoid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.aggfnoid)) - } - if val.aggtype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.aggtype)) - } - if val.aggcollid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.aggcollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.aggargtypes.len > 0 { - for v in val.aggargtypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.aggdirectargs.len > 0 { - for v in val.aggdirectargs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.aggorder.len > 0 { - for v in val.aggorder { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.aggdistinct.len > 0 { - for v in val.aggdistinct { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_aggfilter := encode_node(val.aggfilter) - if n_aggfilter.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, n_aggfilter) - } - if val.aggstar { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.aggstar) - } - if val.aggvariadic { - write_tag_into(mut buf, 13, 0) - write_bool_into(mut buf, val.aggvariadic) - } - if val.aggkind != '' { - write_tag_into(mut buf, 14, 2) - write_string_into(mut buf, val.aggkind) - } - if val.agglevelsup != 0 { - write_tag_into(mut buf, 15, 0) - write_varint_into(mut buf, u64(val.agglevelsup)) - } - if u64(val.aggsplit) != 0 { - write_tag_into(mut buf, 16, 0) - write_varint_into(mut buf, u64(val.aggsplit)) - } - if val.aggno != 0 { - write_tag_into(mut buf, 17, 0) - write_varint_into(mut buf, u64(val.aggno)) - } - if val.aggtransno != 0 { - write_tag_into(mut buf, 18, 0) - write_varint_into(mut buf, u64(val.aggtransno)) - } - if val.location != 0 { - write_tag_into(mut buf, 19, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_grouping_func(val GroupingFunc) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.refs.len > 0 { - for v in val.refs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.agglevelsup != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.agglevelsup)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_window_func(val WindowFunc) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.winfnoid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.winfnoid)) - } - if val.wintype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.wintype)) - } - if val.wincollid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.wincollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_aggfilter := encode_node(val.aggfilter) - if n_aggfilter.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_aggfilter) - } - if val.run_condition.len > 0 { - for v in val.run_condition { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.winref != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.winref)) - } - if val.winstar { - write_tag_into(mut buf, 10, 0) - write_bool_into(mut buf, val.winstar) - } - if val.winagg { - write_tag_into(mut buf, 11, 0) - write_bool_into(mut buf, val.winagg) - } - if val.location != 0 { - write_tag_into(mut buf, 12, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_window_func_run_condition(val WindowFuncRunCondition) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.opno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.opno)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.wfunc_left { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.wfunc_left) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_arg) - } - return buf -} - -pub fn encode_merge_support_func(val MergeSupportFunc) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.msftype != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.msftype)) - } - if val.msfcollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.msfcollid)) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_subscripting_ref(val SubscriptingRef) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.refcontainertype != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.refcontainertype)) - } - if val.refelemtype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.refelemtype)) - } - if val.refrestype != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.refrestype)) - } - if val.reftypmod != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.reftypmod)) - } - if val.refcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.refcollid)) - } - if val.refupperindexpr.len > 0 { - for v in val.refupperindexpr { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.reflowerindexpr.len > 0 { - for v in val.reflowerindexpr { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_refexpr := encode_node(val.refexpr) - if n_refexpr.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, n_refexpr) - } - n_refassgnexpr := encode_node(val.refassgnexpr) - if n_refassgnexpr.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, n_refassgnexpr) - } - return buf -} - -pub fn encode_func_expr(val FuncExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.funcid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.funcid)) - } - if val.funcresulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.funcresulttype)) - } - if val.funcretset { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.funcretset) - } - if val.funcvariadic { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.funcvariadic) - } - if u64(val.funcformat) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.funcformat)) - } - if val.funccollid != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.funccollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_named_arg_expr(val NamedArgExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.name) - } - if val.argnumber != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.argnumber)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_op_expr(val OpExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.opno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.opno)) - } - if val.opresulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.opresulttype)) - } - if val.opretset { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.opretset) - } - if val.opcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.opcollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_distinct_expr(val DistinctExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.opno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.opno)) - } - if val.opresulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.opresulttype)) - } - if val.opretset { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.opretset) - } - if val.opcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.opcollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_null_if_expr(val NullIfExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.opno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.opno)) - } - if val.opresulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.opresulttype)) - } - if val.opretset { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.opretset) - } - if val.opcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.opcollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_scalar_array_op_expr(val ScalarArrayOpExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.opno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.opno)) - } - if val.use_or { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.use_or) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_bool_expr(val BoolExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.boolop) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.boolop)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_sub_link(val SubLink) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.sub_link_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.sub_link_type)) - } - if val.sub_link_id != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.sub_link_id)) - } - n_testexpr := encode_node(val.testexpr) - if n_testexpr.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_testexpr) - } - if val.oper_name.len > 0 { - for v in val.oper_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_subselect := encode_node(val.subselect) - if n_subselect.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_subselect) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_sub_plan(val SubPlan) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.sub_link_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.sub_link_type)) - } - n_testexpr := encode_node(val.testexpr) - if n_testexpr.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_testexpr) - } - if val.param_ids.len > 0 { - for v in val.param_ids { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.plan_id != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.plan_id)) - } - if val.plan_name != '' { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, val.plan_name) - } - if val.first_col_type != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.first_col_type)) - } - if val.first_col_typmod != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.first_col_typmod)) - } - if val.first_col_collation != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.first_col_collation)) - } - if val.use_hash_table { - write_tag_into(mut buf, 10, 0) - write_bool_into(mut buf, val.use_hash_table) - } - if val.unknown_eq_false { - write_tag_into(mut buf, 11, 0) - write_bool_into(mut buf, val.unknown_eq_false) - } - if val.parallel_safe { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.parallel_safe) - } - if val.set_param.len > 0 { - for v in val.set_param { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.par_param.len > 0 { - for v in val.par_param { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 14, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.startup_cost != 0.0 { - write_tag_into(mut buf, 16, 1) - write_double_into(mut buf, val.startup_cost) - } - if val.per_call_cost != 0.0 { - write_tag_into(mut buf, 17, 1) - write_double_into(mut buf, val.per_call_cost) - } - return buf -} - -pub fn encode_alternative_sub_plan(val AlternativeSubPlan) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.subplans.len > 0 { - for v in val.subplans { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_field_select(val FieldSelect) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.fieldnum != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.fieldnum)) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if val.resulttypmod != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.resulttypmod)) - } - if val.resultcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.resultcollid)) - } - return buf -} - -pub fn encode_field_store(val FieldStore) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.newvals.len > 0 { - for v in val.newvals { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.fieldnums.len > 0 { - for v in val.fieldnums { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.resulttype != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - return buf -} - -pub fn encode_relabel_type(val RelabelType) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if val.resulttypmod != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.resulttypmod)) - } - if val.resultcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.resultcollid)) - } - if u64(val.relabelformat) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.relabelformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_coerce_via_i_o(val CoerceViaIO) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if val.resultcollid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.resultcollid)) - } - if u64(val.coerceformat) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.coerceformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_array_coerce_expr(val ArrayCoerceExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - n_elemexpr := encode_node(val.elemexpr) - if n_elemexpr.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_elemexpr) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if val.resulttypmod != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.resulttypmod)) - } - if val.resultcollid != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.resultcollid)) - } - if u64(val.coerceformat) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.coerceformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_convert_rowtype_expr(val ConvertRowtypeExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if u64(val.convertformat) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.convertformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_collate_expr(val CollateExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.coll_oid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.coll_oid)) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_case_expr(val CaseExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.casetype != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.casetype)) - } - if val.casecollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.casecollid)) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_defresult := encode_node(val.defresult) - if n_defresult.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_defresult) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_case_when(val CaseWhen) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - n_result := encode_node(val.result) - if n_result.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_result) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_case_test_expr(val CaseTestExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.type_id != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.type_id)) - } - if val.type_mod != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.type_mod)) - } - if val.collation != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.collation)) - } - return buf -} - -pub fn encode_array_expr(val ArrayExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.array_typeid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.array_typeid)) - } - if val.array_collid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.array_collid)) - } - if val.element_typeid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.element_typeid)) - } - if val.elements.len > 0 { - for v in val.elements { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.multidims { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.multidims) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_row_expr(val RowExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.row_typeid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.row_typeid)) - } - if u64(val.row_format) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.row_format)) - } - if val.colnames.len > 0 { - for v in val.colnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_row_compare_expr(val RowCompareExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.rctype) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.rctype)) - } - if val.opnos.len > 0 { - for v in val.opnos { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.opfamilies.len > 0 { - for v in val.opfamilies { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.inputcollids.len > 0 { - for v in val.inputcollids { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.largs.len > 0 { - for v in val.largs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.rargs.len > 0 { - for v in val.rargs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_coalesce_expr(val CoalesceExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.coalescetype != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.coalescetype)) - } - if val.coalescecollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.coalescecollid)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_min_max_expr(val MinMaxExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.minmaxtype != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.minmaxtype)) - } - if val.minmaxcollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.minmaxcollid)) - } - if val.inputcollid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.inputcollid)) - } - if u64(val.op) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_s_q_l_value_function(val SQLValueFunction) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.op) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.type != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.type)) - } - if val.typmod != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.typmod)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_xml_expr(val XmlExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.op) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.name) - } - if val.named_args.len > 0 { - for v in val.named_args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.arg_names.len > 0 { - for v in val.arg_names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.xmloption) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.xmloption)) - } - if val.indent { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.indent) - } - if val.type != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.type)) - } - if val.typmod != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.typmod)) - } - if val.location != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_format(val JsonFormat) []u8 { - mut buf := []u8{} - if u64(val.format_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.format_type)) - } - if u64(val.encoding) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.encoding)) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_behavior(val JsonBehavior) []u8 { - mut buf := []u8{} - if u64(val.btype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.btype)) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - if val.coerce { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.coerce) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_table_path(val JsonTablePath) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - return buf -} - -pub fn encode_json_table_sibling_join(val JsonTableSiblingJoin) []u8 { - mut buf := []u8{} - n_plan := encode_node(val.plan) - if n_plan.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_plan) - } - n_lplan := encode_node(val.lplan) - if n_lplan.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_lplan) - } - n_rplan := encode_node(val.rplan) - if n_rplan.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_rplan) - } - return buf -} - -pub fn encode_null_test(val NullTest) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if u64(val.nulltesttype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.nulltesttype)) - } - if val.argisrow { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.argisrow) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_boolean_test(val BooleanTest) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if u64(val.booltesttype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.booltesttype)) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_merge_action(val MergeAction) []u8 { - mut buf := []u8{} - if u64(val.match_kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.match_kind)) - } - if u64(val.command_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.command_type)) - } - if u64(val.override) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.override)) - } - n_qual := encode_node(val.qual) - if n_qual.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_qual) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.update_colnos.len > 0 { - for v in val.update_colnos { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_coerce_to_domain(val CoerceToDomain) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.resulttype != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.resulttype)) - } - if val.resulttypmod != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.resulttypmod)) - } - if val.resultcollid != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.resultcollid)) - } - if u64(val.coercionformat) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.coercionformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_coerce_to_domain_value(val CoerceToDomainValue) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.type_id != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.type_id)) - } - if val.type_mod != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.type_mod)) - } - if val.collation != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.collation)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_set_to_default(val SetToDefault) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.type_id != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.type_id)) - } - if val.type_mod != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.type_mod)) - } - if val.collation != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.collation)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_current_of_expr(val CurrentOfExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.cvarno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.cvarno)) - } - if val.cursor_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.cursor_name) - } - if val.cursor_param != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.cursor_param)) - } - return buf -} - -pub fn encode_next_value_expr(val NextValueExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if val.seqid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.seqid)) - } - if val.type_id != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.type_id)) - } - return buf -} - -pub fn encode_inference_elem(val InferenceElem) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - if val.infercollid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.infercollid)) - } - if val.inferopclass != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.inferopclass)) - } - return buf -} - -pub fn encode_target_entry(val TargetEntry) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - if val.resno != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.resno)) - } - if val.resname != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.resname) - } - if val.ressortgroupref != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.ressortgroupref)) - } - if val.resorigtbl != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.resorigtbl)) - } - if val.resorigcol != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.resorigcol)) - } - if val.resjunk { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.resjunk) - } - return buf -} - -pub fn encode_range_tbl_ref(val RangeTblRef) []u8 { - mut buf := []u8{} - if val.rtindex != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.rtindex)) - } - return buf -} - -pub fn encode_from_expr(val FromExpr) []u8 { - mut buf := []u8{} - if val.fromlist.len > 0 { - for v in val.fromlist { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_quals := encode_node(val.quals) - if n_quals.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_quals) - } - return buf -} - -pub fn encode_on_conflict_expr(val OnConflictExpr) []u8 { - mut buf := []u8{} - if u64(val.action) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.action)) - } - if val.arbiter_elems.len > 0 { - for v in val.arbiter_elems { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_arbiter_where := encode_node(val.arbiter_where) - if n_arbiter_where.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_arbiter_where) - } - if val.constraint != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.constraint)) - } - if val.on_conflict_set.len > 0 { - for v in val.on_conflict_set { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_on_conflict_where := encode_node(val.on_conflict_where) - if n_on_conflict_where.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_on_conflict_where) - } - if val.excl_rel_index != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.excl_rel_index)) - } - if val.excl_rel_tlist.len > 0 { - for v in val.excl_rel_tlist { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_type_name(val TypeName) []u8 { - mut buf := []u8{} - if val.names.len > 0 { - for v in val.names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.type_oid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.type_oid)) - } - if val.setof { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.setof) - } - if val.pct_type { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.pct_type) - } - if val.typmods.len > 0 { - for v in val.typmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.typemod != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.typemod)) - } - if val.array_bounds.len > 0 { - for v in val.array_bounds { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_column_ref(val ColumnRef) []u8 { - mut buf := []u8{} - if val.fields.len > 0 { - for v in val.fields { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_param_ref(val ParamRef) []u8 { - mut buf := []u8{} - if val.number != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.number)) - } - if val.location != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_a_expr(val AExpr) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.name.len > 0 { - for v in val.name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_lexpr := encode_node(val.lexpr) - if n_lexpr.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_lexpr) - } - n_rexpr := encode_node(val.rexpr) - if n_rexpr.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_rexpr) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_collate_clause(val CollateClause) []u8 { - mut buf := []u8{} - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.collname.len > 0 { - for v in val.collname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_role_spec(val RoleSpec) []u8 { - mut buf := []u8{} - if u64(val.roletype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.roletype)) - } - if val.rolename != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.rolename) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_a_star(val AStar) []u8 { - mut buf := []u8{} - return buf -} - -pub fn encode_a_indices(val AIndices) []u8 { - mut buf := []u8{} - if val.is_slice { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.is_slice) - } - n_lidx := encode_node(val.lidx) - if n_lidx.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_lidx) - } - n_uidx := encode_node(val.uidx) - if n_uidx.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_uidx) - } - return buf -} - -pub fn encode_a_indirection(val AIndirection) []u8 { - mut buf := []u8{} - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_arg) - } - if val.indirection.len > 0 { - for v in val.indirection { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_a_array_expr(val AArrayExpr) []u8 { - mut buf := []u8{} - if val.elements.len > 0 { - for v in val.elements { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_res_target(val ResTarget) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.indirection.len > 0 { - for v in val.indirection { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_val := encode_node(val.val) - if n_val.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_val) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_multi_assign_ref(val MultiAssignRef) []u8 { - mut buf := []u8{} - n_source := encode_node(val.source) - if n_source.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_source) - } - if val.colno != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.colno)) - } - if val.ncolumns != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.ncolumns)) - } - return buf -} - -pub fn encode_sort_by(val SortBy) []u8 { - mut buf := []u8{} - n_node := encode_node(val.node) - if n_node.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_node) - } - if u64(val.sortby_dir) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.sortby_dir)) - } - if u64(val.sortby_nulls) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.sortby_nulls)) - } - if val.use_op.len > 0 { - for v in val.use_op { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_window_def(val WindowDef) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.refname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.refname) - } - if val.partition_clause.len > 0 { - for v in val.partition_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.order_clause.len > 0 { - for v in val.order_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.frame_options != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.frame_options)) - } - n_start_offset := encode_node(val.start_offset) - if n_start_offset.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_start_offset) - } - n_end_offset := encode_node(val.end_offset) - if n_end_offset.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_end_offset) - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_range_table_sample(val RangeTableSample) []u8 { - mut buf := []u8{} - n_relation := encode_node(val.relation) - if n_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_relation) - } - if val.method.len > 0 { - for v in val.method { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_repeatable := encode_node(val.repeatable) - if n_repeatable.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_repeatable) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_index_elem(val IndexElem) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - if val.indexcolname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.indexcolname) - } - if val.collation.len > 0 { - for v in val.collation { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.opclass.len > 0 { - for v in val.opclass { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.opclassopts.len > 0 { - for v in val.opclassopts { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.ordering) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.ordering)) - } - if u64(val.nulls_ordering) != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.nulls_ordering)) - } - return buf -} - -pub fn encode_def_elem(val DefElem) []u8 { - mut buf := []u8{} - if val.defnamespace != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.defnamespace) - } - if val.defname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.defname) - } - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_arg) - } - if u64(val.defaction) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.defaction)) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_locking_clause(val LockingClause) []u8 { - mut buf := []u8{} - if val.locked_rels.len > 0 { - for v in val.locked_rels { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.strength) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.strength)) - } - if u64(val.wait_policy) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.wait_policy)) - } - return buf -} - -pub fn encode_partition_elem(val PartitionElem) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - if val.collation.len > 0 { - for v in val.collation { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.opclass.len > 0 { - for v in val.opclass { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_partition_spec(val PartitionSpec) []u8 { - mut buf := []u8{} - if u64(val.strategy) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.strategy)) - } - if val.part_params.len > 0 { - for v in val.part_params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_partition_bound_spec(val PartitionBoundSpec) []u8 { - mut buf := []u8{} - if val.strategy != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.strategy) - } - if val.is_default { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.is_default) - } - if val.modulus != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.modulus)) - } - if val.remainder != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.remainder)) - } - if val.listdatums.len > 0 { - for v in val.listdatums { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.lowerdatums.len > 0 { - for v in val.lowerdatums { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.upperdatums.len > 0 { - for v in val.upperdatums { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_partition_range_datum(val PartitionRangeDatum) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - n_value := encode_node(val.value) - if n_value.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_value) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_single_partition_spec(val SinglePartitionSpec) []u8 { - mut buf := []u8{} - return buf -} - -pub fn encode_r_t_e_permission_info(val RTEPermissionInfo) []u8 { - mut buf := []u8{} - if val.relid != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.relid)) - } - if val.inh { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.inh) - } - if val.required_perms != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, val.required_perms) - } - if val.check_as_user != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.check_as_user)) - } - if val.selected_cols.len > 0 { - mut packed_ := []u8{} - for v in val.selected_cols { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, packed_) - } - if val.inserted_cols.len > 0 { - mut packed_ := []u8{} - for v in val.inserted_cols { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, packed_) - } - if val.updated_cols.len > 0 { - mut packed_ := []u8{} - for v in val.updated_cols { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, packed_) - } - return buf -} - -pub fn encode_range_tbl_function(val RangeTblFunction) []u8 { - mut buf := []u8{} - n_funcexpr := encode_node(val.funcexpr) - if n_funcexpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_funcexpr) - } - if val.funccolcount != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.funccolcount)) - } - if val.funccolnames.len > 0 { - for v in val.funccolnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funccoltypes.len > 0 { - for v in val.funccoltypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funccoltypmods.len > 0 { - for v in val.funccoltypmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funccolcollations.len > 0 { - for v in val.funccolcollations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funcparams.len > 0 { - mut packed_ := []u8{} - for v in val.funcparams { - write_varint_into(mut packed_, v) - } - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, packed_) - } - return buf -} - -pub fn encode_table_sample_clause(val TableSampleClause) []u8 { - mut buf := []u8{} - if val.tsmhandler != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.tsmhandler)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_repeatable := encode_node(val.repeatable) - if n_repeatable.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_repeatable) - } - return buf -} - -pub fn encode_with_check_option(val WithCheckOption) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.relname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.relname) - } - if val.polname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.polname) - } - n_qual := encode_node(val.qual) - if n_qual.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_qual) - } - if val.cascaded { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.cascaded) - } - return buf -} - -pub fn encode_sort_group_clause(val SortGroupClause) []u8 { - mut buf := []u8{} - if val.tle_sort_group_ref != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.tle_sort_group_ref)) - } - if val.eqop != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.eqop)) - } - if val.sortop != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.sortop)) - } - if val.nulls_first { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.nulls_first) - } - if val.hashable { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.hashable) - } - return buf -} - -pub fn encode_grouping_set(val GroupingSet) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.content.len > 0 { - for v in val.content { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_window_clause(val WindowClause) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.refname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.refname) - } - if val.partition_clause.len > 0 { - for v in val.partition_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.order_clause.len > 0 { - for v in val.order_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.frame_options != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.frame_options)) - } - n_start_offset := encode_node(val.start_offset) - if n_start_offset.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_start_offset) - } - n_end_offset := encode_node(val.end_offset) - if n_end_offset.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_end_offset) - } - if val.start_in_range_func != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.start_in_range_func)) - } - if val.end_in_range_func != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.end_in_range_func)) - } - if val.in_range_coll != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.in_range_coll)) - } - if val.in_range_asc { - write_tag_into(mut buf, 11, 0) - write_bool_into(mut buf, val.in_range_asc) - } - if val.in_range_nulls_first { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.in_range_nulls_first) - } - if val.winref != 0 { - write_tag_into(mut buf, 13, 0) - write_varint_into(mut buf, u64(val.winref)) - } - if val.copied_order { - write_tag_into(mut buf, 14, 0) - write_bool_into(mut buf, val.copied_order) - } - return buf -} - -pub fn encode_row_mark_clause(val RowMarkClause) []u8 { - mut buf := []u8{} - if val.rti != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.rti)) - } - if u64(val.strength) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.strength)) - } - if u64(val.wait_policy) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.wait_policy)) - } - if val.pushed_down { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.pushed_down) - } - return buf -} - -pub fn encode_with_clause(val WithClause) []u8 { - mut buf := []u8{} - if val.ctes.len > 0 { - for v in val.ctes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.recursive { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.recursive) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_infer_clause(val InferClause) []u8 { - mut buf := []u8{} - if val.index_elems.len > 0 { - for v in val.index_elems { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.conname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.conname) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_c_t_e_search_clause(val CTESearchClause) []u8 { - mut buf := []u8{} - if val.search_col_list.len > 0 { - for v in val.search_col_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.search_breadth_first { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.search_breadth_first) - } - if val.search_seq_column != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.search_seq_column) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_c_t_e_cycle_clause(val CTECycleClause) []u8 { - mut buf := []u8{} - if val.cycle_col_list.len > 0 { - for v in val.cycle_col_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.cycle_mark_column != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.cycle_mark_column) - } - n_cycle_mark_value := encode_node(val.cycle_mark_value) - if n_cycle_mark_value.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_cycle_mark_value) - } - n_cycle_mark_default := encode_node(val.cycle_mark_default) - if n_cycle_mark_default.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_cycle_mark_default) - } - if val.cycle_path_column != '' { - write_tag_into(mut buf, 5, 2) - write_string_into(mut buf, val.cycle_path_column) - } - if val.location != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.location)) - } - if val.cycle_mark_type != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.cycle_mark_type)) - } - if val.cycle_mark_typmod != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.cycle_mark_typmod)) - } - if val.cycle_mark_collation != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.cycle_mark_collation)) - } - if val.cycle_mark_neop != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.cycle_mark_neop)) - } - return buf -} - -pub fn encode_merge_when_clause(val MergeWhenClause) []u8 { - mut buf := []u8{} - if u64(val.match_kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.match_kind)) - } - if u64(val.command_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.command_type)) - } - if u64(val.override) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.override)) - } - n_condition := encode_node(val.condition) - if n_condition.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_condition) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.values.len > 0 { - for v in val.values { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_trigger_transition(val TriggerTransition) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.is_new { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.is_new) - } - if val.is_table { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_table) - } - return buf -} - -pub fn encode_json_table_path_spec(val JsonTablePathSpec) []u8 { - mut buf := []u8{} - n_string := encode_node(val.string) - if n_string.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_string) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - if val.name_location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.name_location)) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_raw_stmt(val RawStmt) []u8 { - mut buf := []u8{} - n_stmt := encode_node(val.stmt) - if n_stmt.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_stmt) - } - if val.stmt_location != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.stmt_location)) - } - if val.stmt_len != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.stmt_len)) - } - return buf -} - -pub fn encode_set_operation_stmt(val SetOperationStmt) []u8 { - mut buf := []u8{} - if u64(val.op) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.all { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.all) - } - n_larg := encode_node(val.larg) - if n_larg.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_larg) - } - n_rarg := encode_node(val.rarg) - if n_rarg.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_rarg) - } - if val.col_types.len > 0 { - for v in val.col_types { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.col_typmods.len > 0 { - for v in val.col_typmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.col_collations.len > 0 { - for v in val.col_collations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.group_clauses.len > 0 { - for v in val.group_clauses { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_return_stmt(val ReturnStmt) []u8 { - mut buf := []u8{} - n_returnval := encode_node(val.returnval) - if n_returnval.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_returnval) - } - return buf -} - -pub fn encode_replica_identity_stmt(val ReplicaIdentityStmt) []u8 { - mut buf := []u8{} - if val.identity_type != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.identity_type) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - return buf -} - -pub fn encode_alter_collation_stmt(val AlterCollationStmt) []u8 { - mut buf := []u8{} - if val.collname.len > 0 { - for v in val.collname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_domain_stmt(val AlterDomainStmt) []u8 { - mut buf := []u8{} - if val.subtype != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.subtype) - } - if val.type_name.len > 0 { - for v in val.type_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.name) - } - n_def := encode_node(val.def) - if n_def.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_def) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - if val.missing_ok { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_object_with_args(val ObjectWithArgs) []u8 { - mut buf := []u8{} - if val.objname.len > 0 { - for v in val.objname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.objargs.len > 0 { - for v in val.objargs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.objfuncargs.len > 0 { - for v in val.objfuncargs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args_unspecified { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.args_unspecified) - } - return buf -} - -pub fn encode_access_priv(val AccessPriv) []u8 { - mut buf := []u8{} - if val.priv_name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.priv_name) - } - if val.cols.len > 0 { - for v in val.cols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_variable_set_stmt(val VariableSetStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_local { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.is_local) - } - return buf -} - -pub fn encode_variable_show_stmt(val VariableShowStmt) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - return buf -} - -pub fn encode_drop_table_space_stmt(val DropTableSpaceStmt) []u8 { - mut buf := []u8{} - if val.tablespacename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.tablespacename) - } - if val.missing_ok { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_alter_table_space_options_stmt(val AlterTableSpaceOptionsStmt) []u8 { - mut buf := []u8{} - if val.tablespacename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.tablespacename) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_reset { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_reset) - } - return buf -} - -pub fn encode_alter_table_move_all_stmt(val AlterTableMoveAllStmt) []u8 { - mut buf := []u8{} - if val.orig_tablespacename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.orig_tablespacename) - } - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.new_tablespacename != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.new_tablespacename) - } - if val.nowait { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.nowait) - } - return buf -} - -pub fn encode_create_extension_stmt(val CreateExtensionStmt) []u8 { - mut buf := []u8{} - if val.extname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.extname) - } - if val.if_not_exists { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.if_not_exists) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_extension_stmt(val AlterExtensionStmt) []u8 { - mut buf := []u8{} - if val.extname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.extname) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_extension_contents_stmt(val AlterExtensionContentsStmt) []u8 { - mut buf := []u8{} - if val.extname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.extname) - } - if val.action != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.action)) - } - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_object) - } - return buf -} - -pub fn encode_create_fdw_stmt(val CreateFdwStmt) []u8 { - mut buf := []u8{} - if val.fdwname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.fdwname) - } - if val.func_options.len > 0 { - for v in val.func_options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_fdw_stmt(val AlterFdwStmt) []u8 { - mut buf := []u8{} - if val.fdwname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.fdwname) - } - if val.func_options.len > 0 { - for v in val.func_options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_foreign_server_stmt(val CreateForeignServerStmt) []u8 { - mut buf := []u8{} - if val.servername != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.servername) - } - if val.servertype != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.servertype) - } - if val.version != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.version) - } - if val.fdwname != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.fdwname) - } - if val.if_not_exists { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.if_not_exists) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_foreign_server_stmt(val AlterForeignServerStmt) []u8 { - mut buf := []u8{} - if val.servername != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.servername) - } - if val.version != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.version) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.has_version { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.has_version) - } - return buf -} - -pub fn encode_import_foreign_schema_stmt(val ImportForeignSchemaStmt) []u8 { - mut buf := []u8{} - if val.server_name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.server_name) - } - if val.remote_schema != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.remote_schema) - } - if val.local_schema != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.local_schema) - } - if u64(val.list_type) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.list_type)) - } - if val.table_list.len > 0 { - for v in val.table_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_am_stmt(val CreateAmStmt) []u8 { - mut buf := []u8{} - if val.amname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.amname) - } - if val.handler_name.len > 0 { - for v in val.handler_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.amtype != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.amtype) - } - return buf -} - -pub fn encode_create_event_trig_stmt(val CreateEventTrigStmt) []u8 { - mut buf := []u8{} - if val.trigname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.trigname) - } - if val.eventname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.eventname) - } - if val.whenclause.len > 0 { - for v in val.whenclause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funcname.len > 0 { - for v in val.funcname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_event_trig_stmt(val AlterEventTrigStmt) []u8 { - mut buf := []u8{} - if val.trigname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.trigname) - } - if val.tgenabled != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.tgenabled) - } - return buf -} - -pub fn encode_create_p_lang_stmt(val CreatePLangStmt) []u8 { - mut buf := []u8{} - if val.replace { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.replace) - } - if val.plname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.plname) - } - if val.plhandler.len > 0 { - for v in val.plhandler { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.plinline.len > 0 { - for v in val.plinline { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.plvalidator.len > 0 { - for v in val.plvalidator { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.pltrusted { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.pltrusted) - } - return buf -} - -pub fn encode_create_role_stmt(val CreateRoleStmt) []u8 { - mut buf := []u8{} - if u64(val.stmt_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.stmt_type)) - } - if val.role != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.role) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_drop_role_stmt(val DropRoleStmt) []u8 { - mut buf := []u8{} - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.missing_ok { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_define_stmt(val DefineStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.oldstyle { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.oldstyle) - } - if val.defnames.len > 0 { - for v in val.defnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.definition.len > 0 { - for v in val.definition { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.if_not_exists { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.if_not_exists) - } - if val.replace { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.replace) - } - return buf -} - -pub fn encode_create_op_family_stmt(val CreateOpFamilyStmt) []u8 { - mut buf := []u8{} - if val.opfamilyname.len > 0 { - for v in val.opfamilyname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.amname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.amname) - } - return buf -} - -pub fn encode_alter_op_family_stmt(val AlterOpFamilyStmt) []u8 { - mut buf := []u8{} - if val.opfamilyname.len > 0 { - for v in val.opfamilyname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.amname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.amname) - } - if val.is_drop { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_drop) - } - if val.items.len > 0 { - for v in val.items { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_drop_stmt(val DropStmt) []u8 { - mut buf := []u8{} - if val.objects.len > 0 { - for v in val.objects { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.remove_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.remove_type)) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - if val.missing_ok { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.missing_ok) - } - if val.concurrent { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.concurrent) - } - return buf -} - -pub fn encode_truncate_stmt(val TruncateStmt) []u8 { - mut buf := []u8{} - if val.relations.len > 0 { - for v in val.relations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.restart_seqs { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.restart_seqs) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - return buf -} - -pub fn encode_comment_stmt(val CommentStmt) []u8 { - mut buf := []u8{} - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_object) - } - if val.comment != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.comment) - } - return buf -} - -pub fn encode_sec_label_stmt(val SecLabelStmt) []u8 { - mut buf := []u8{} - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_object) - } - if val.provider != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.provider) - } - if val.label != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.label) - } - return buf -} - -pub fn encode_declare_cursor_stmt(val DeclareCursorStmt) []u8 { - mut buf := []u8{} - if val.portalname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.portalname) - } - if val.options != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.options)) - } - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_query) - } - return buf -} - -pub fn encode_close_portal_stmt(val ClosePortalStmt) []u8 { - mut buf := []u8{} - if val.portalname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.portalname) - } - return buf -} - -pub fn encode_fetch_stmt(val FetchStmt) []u8 { - mut buf := []u8{} - if u64(val.direction) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.direction)) - } - if val.how_many != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.how_many)) - } - if val.portalname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.portalname) - } - if val.ismove { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.ismove) - } - return buf -} - -pub fn encode_create_stats_stmt(val CreateStatsStmt) []u8 { - mut buf := []u8{} - if val.defnames.len > 0 { - for v in val.defnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.stat_types.len > 0 { - for v in val.stat_types { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.exprs.len > 0 { - for v in val.exprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.relations.len > 0 { - for v in val.relations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.stxcomment != '' { - write_tag_into(mut buf, 5, 2) - write_string_into(mut buf, val.stxcomment) - } - if val.transformed { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.transformed) - } - if val.if_not_exists { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.if_not_exists) - } - return buf -} - -pub fn encode_stats_elem(val StatsElem) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - return buf -} - -pub fn encode_alter_stats_stmt(val AlterStatsStmt) []u8 { - mut buf := []u8{} - if val.defnames.len > 0 { - for v in val.defnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_stxstattarget := encode_node(val.stxstattarget) - if n_stxstattarget.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_stxstattarget) - } - if val.missing_ok { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_do_stmt(val DoStmt) []u8 { - mut buf := []u8{} - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_inline_code_block(val InlineCodeBlock) []u8 { - mut buf := []u8{} - if val.source_text != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.source_text) - } - if val.lang_oid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.lang_oid)) - } - if val.lang_is_trusted { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.lang_is_trusted) - } - if val.atomic { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.atomic) - } - return buf -} - -pub fn encode_call_context(val CallContext) []u8 { - mut buf := []u8{} - if val.atomic { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.atomic) - } - return buf -} - -pub fn encode_alter_type_stmt(val AlterTypeStmt) []u8 { - mut buf := []u8{} - if val.type_name.len > 0 { - for v in val.type_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_notify_stmt(val NotifyStmt) []u8 { - mut buf := []u8{} - if val.conditionname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.conditionname) - } - if val.payload != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.payload) - } - return buf -} - -pub fn encode_listen_stmt(val ListenStmt) []u8 { - mut buf := []u8{} - if val.conditionname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.conditionname) - } - return buf -} - -pub fn encode_unlisten_stmt(val UnlistenStmt) []u8 { - mut buf := []u8{} - if val.conditionname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.conditionname) - } - return buf -} - -pub fn encode_transaction_stmt(val TransactionStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.savepoint_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.savepoint_name) - } - if val.gid != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.gid) - } - if val.chain { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.chain) - } - if val.location != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_create_enum_stmt(val CreateEnumStmt) []u8 { - mut buf := []u8{} - if val.type_name.len > 0 { - for v in val.type_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.vals.len > 0 { - for v in val.vals { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_range_stmt(val CreateRangeStmt) []u8 { - mut buf := []u8{} - if val.type_name.len > 0 { - for v in val.type_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.params.len > 0 { - for v in val.params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_enum_stmt(val AlterEnumStmt) []u8 { - mut buf := []u8{} - if val.type_name.len > 0 { - for v in val.type_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.old_val != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.old_val) - } - if val.new_val != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.new_val) - } - if val.new_val_neighbor != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.new_val_neighbor) - } - if val.new_val_is_after { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.new_val_is_after) - } - if val.skip_if_new_val_exists { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.skip_if_new_val_exists) - } - return buf -} - -pub fn encode_load_stmt(val LoadStmt) []u8 { - mut buf := []u8{} - if val.filename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.filename) - } - return buf -} - -pub fn encode_createdb_stmt(val CreatedbStmt) []u8 { - mut buf := []u8{} - if val.dbname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.dbname) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_database_stmt(val AlterDatabaseStmt) []u8 { - mut buf := []u8{} - if val.dbname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.dbname) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_database_refresh_coll_stmt(val AlterDatabaseRefreshCollStmt) []u8 { - mut buf := []u8{} - if val.dbname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.dbname) - } - return buf -} - -pub fn encode_dropdb_stmt(val DropdbStmt) []u8 { - mut buf := []u8{} - if val.dbname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.dbname) - } - if val.missing_ok { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.missing_ok) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_vacuum_stmt(val VacuumStmt) []u8 { - mut buf := []u8{} - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.rels.len > 0 { - for v in val.rels { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_vacuumcmd { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_vacuumcmd) - } - return buf -} - -pub fn encode_explain_stmt(val ExplainStmt) []u8 { - mut buf := []u8{} - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_query) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_check_point_stmt(val CheckPointStmt) []u8 { - mut buf := []u8{} - return buf -} - -pub fn encode_discard_stmt(val DiscardStmt) []u8 { - mut buf := []u8{} - if u64(val.target) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.target)) - } - return buf -} - -pub fn encode_lock_stmt(val LockStmt) []u8 { - mut buf := []u8{} - if val.relations.len > 0 { - for v in val.relations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.mode != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.mode)) - } - if val.nowait { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.nowait) - } - return buf -} - -pub fn encode_constraints_set_stmt(val ConstraintsSetStmt) []u8 { - mut buf := []u8{} - if val.constraints.len > 0 { - for v in val.constraints { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.deferred { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.deferred) - } - return buf -} - -pub fn encode_create_conversion_stmt(val CreateConversionStmt) []u8 { - mut buf := []u8{} - if val.conversion_name.len > 0 { - for v in val.conversion_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.for_encoding_name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.for_encoding_name) - } - if val.to_encoding_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.to_encoding_name) - } - if val.func_name.len > 0 { - for v in val.func_name { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.def { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.def) - } - return buf -} - -pub fn encode_prepare_stmt(val PrepareStmt) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.argtypes.len > 0 { - for v in val.argtypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_query) - } - return buf -} - -pub fn encode_execute_stmt(val ExecuteStmt) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.params.len > 0 { - for v in val.params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_deallocate_stmt(val DeallocateStmt) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.isall { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.isall) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_drop_owned_stmt(val DropOwnedStmt) []u8 { - mut buf := []u8{} - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - return buf -} - -pub fn encode_alter_t_s_dictionary_stmt(val AlterTSDictionaryStmt) []u8 { - mut buf := []u8{} - if val.dictname.len > 0 { - for v in val.dictname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_t_s_configuration_stmt(val AlterTSConfigurationStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.cfgname.len > 0 { - for v in val.cfgname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.tokentype.len > 0 { - for v in val.tokentype { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.dicts.len > 0 { - for v in val.dicts { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.override { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.override) - } - if val.replace { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.replace) - } - if val.missing_ok { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_create_publication_stmt(val CreatePublicationStmt) []u8 { - mut buf := []u8{} - if val.pubname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.pubname) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.pubobjects.len > 0 { - for v in val.pubobjects { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.for_all_tables { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.for_all_tables) - } - return buf -} - -pub fn encode_alter_publication_stmt(val AlterPublicationStmt) []u8 { - mut buf := []u8{} - if val.pubname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.pubname) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.pubobjects.len > 0 { - for v in val.pubobjects { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.for_all_tables { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.for_all_tables) - } - if u64(val.action) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.action)) - } - return buf -} - -pub fn encode_create_subscription_stmt(val CreateSubscriptionStmt) []u8 { - mut buf := []u8{} - if val.subname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.subname) - } - if val.conninfo != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.conninfo) - } - if val.publication.len > 0 { - for v in val.publication { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_subscription_stmt(val AlterSubscriptionStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - if val.subname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.subname) - } - if val.conninfo != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.conninfo) - } - if val.publication.len > 0 { - for v in val.publication { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_drop_subscription_stmt(val DropSubscriptionStmt) []u8 { - mut buf := []u8{} - if val.subname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.subname) - } - if val.missing_ok { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.missing_ok) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - return buf -} - -pub fn encode_scan_token(val ScanToken) []u8 { - mut buf := []u8{} - if val.start != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.start)) - } - if val.end != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.end)) - } - if u64(val.token) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.token)) - } - if u64(val.keyword_kind) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.keyword_kind)) - } - return buf -} - -pub fn encode_summary_result_table(val SummaryResultTable) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.schema_name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.schema_name) - } - if val.table_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.table_name) - } - if u64(val.context) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.context)) - } - return buf -} - -pub fn encode_summary_result_function(val SummaryResultFunction) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.function_name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.function_name) - } - if val.schema_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.schema_name) - } - if u64(val.context) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.context)) - } - return buf -} - -pub fn encode_summary_result_filter_column(val SummaryResultFilterColumn) []u8 { - mut buf := []u8{} - if val.schema_name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.schema_name) - } - if val.table_name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.table_name) - } - if val.column != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.column) - } - return buf -} - -pub fn encode_range_var(val RangeVar) []u8 { - mut buf := []u8{} - if val.catalogname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.catalogname) - } - if val.schemaname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.schemaname) - } - if val.relname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.relname) - } - if val.inh { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.inh) - } - if val.relpersistence != '' { - write_tag_into(mut buf, 5, 2) - write_string_into(mut buf, val.relpersistence) - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_alias) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_join_expr(val JoinExpr) []u8 { - mut buf := []u8{} - if u64(val.jointype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.jointype)) - } - if val.is_natural { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.is_natural) - } - n_larg := encode_node(val.larg) - if n_larg.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_larg) - } - n_rarg := encode_node(val.rarg) - if n_rarg.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_rarg) - } - if val.using_clause.len > 0 { - for v in val.using_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_join_using_alias := encode_alias(val.join_using_alias) - if in_join_using_alias.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_join_using_alias) - } - n_quals := encode_node(val.quals) - if n_quals.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_quals) - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, in_alias) - } - if val.rtindex != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.rtindex)) - } - return buf -} - -pub fn encode_range_subselect(val RangeSubselect) []u8 { - mut buf := []u8{} - if val.lateral { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.lateral) - } - n_subquery := encode_node(val.subquery) - if n_subquery.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_subquery) - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_alias) - } - return buf -} - -pub fn encode_range_function(val RangeFunction) []u8 { - mut buf := []u8{} - if val.lateral { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.lateral) - } - if val.ordinality { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.ordinality) - } - if val.is_rowsfrom { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_rowsfrom) - } - if val.functions.len > 0 { - for v in val.functions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_alias) - } - if val.coldeflist.len > 0 { - for v in val.coldeflist { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_range_table_func(val RangeTableFunc) []u8 { - mut buf := []u8{} - if val.lateral { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.lateral) - } - n_docexpr := encode_node(val.docexpr) - if n_docexpr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_docexpr) - } - n_rowexpr := encode_node(val.rowexpr) - if n_rowexpr.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_rowexpr) - } - if val.namespaces.len > 0 { - for v in val.namespaces { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.columns.len > 0 { - for v in val.columns { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_alias) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_returning(val JsonReturning) []u8 { - mut buf := []u8{} - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_format) - } - if val.typid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.typid)) - } - if val.typmod != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.typmod)) - } - return buf -} - -pub fn encode_json_value_expr(val JsonValueExpr) []u8 { - mut buf := []u8{} - n_raw_expr := encode_node(val.raw_expr) - if n_raw_expr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_raw_expr) - } - n_formatted_expr := encode_node(val.formatted_expr) - if n_formatted_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_formatted_expr) - } - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_format) - } - return buf -} - -pub fn encode_json_is_predicate(val JsonIsPredicate) []u8 { - mut buf := []u8{} - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_expr) - } - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_format) - } - if u64(val.item_type) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.item_type)) - } - if val.unique_keys { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.unique_keys) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_table_path_scan(val JsonTablePathScan) []u8 { - mut buf := []u8{} - n_plan := encode_node(val.plan) - if n_plan.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_plan) - } - in_path := encode_json_table_path(val.path) - if in_path.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_path) - } - if val.error_on_error { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.error_on_error) - } - n_child := encode_node(val.child) - if n_child.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_child) - } - if val.col_min != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.col_min)) - } - if val.col_max != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.col_max)) - } - return buf -} - -pub fn encode_query(val Query) []u8 { - mut buf := []u8{} - if u64(val.command_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.command_type)) - } - if u64(val.query_source) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.query_source)) - } - if val.can_set_tag { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.can_set_tag) - } - n_utility_stmt := encode_node(val.utility_stmt) - if n_utility_stmt.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_utility_stmt) - } - if val.result_relation != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.result_relation)) - } - if val.has_aggs { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.has_aggs) - } - if val.has_window_funcs { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.has_window_funcs) - } - if val.has_target_srfs { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.has_target_srfs) - } - if val.has_sub_links { - write_tag_into(mut buf, 9, 0) - write_bool_into(mut buf, val.has_sub_links) - } - if val.has_distinct_on { - write_tag_into(mut buf, 10, 0) - write_bool_into(mut buf, val.has_distinct_on) - } - if val.has_recursive { - write_tag_into(mut buf, 11, 0) - write_bool_into(mut buf, val.has_recursive) - } - if val.has_modifying_cte { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.has_modifying_cte) - } - if val.has_for_update { - write_tag_into(mut buf, 13, 0) - write_bool_into(mut buf, val.has_for_update) - } - if val.has_row_security { - write_tag_into(mut buf, 14, 0) - write_bool_into(mut buf, val.has_row_security) - } - if val.is_return { - write_tag_into(mut buf, 15, 0) - write_bool_into(mut buf, val.is_return) - } - if val.cte_list.len > 0 { - for v in val.cte_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 16, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.rtable.len > 0 { - for v in val.rtable { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 17, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.rteperminfos.len > 0 { - for v in val.rteperminfos { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 18, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_jointree := encode_from_expr(val.jointree) - if in_jointree.len > 0 { - write_tag_into(mut buf, 19, 2) - write_length_delimited_into(mut buf, in_jointree) - } - if val.merge_action_list.len > 0 { - for v in val.merge_action_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 20, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.merge_target_relation != 0 { - write_tag_into(mut buf, 21, 0) - write_varint_into(mut buf, u64(val.merge_target_relation)) - } - n_merge_join_condition := encode_node(val.merge_join_condition) - if n_merge_join_condition.len > 0 { - write_tag_into(mut buf, 22, 2) - write_length_delimited_into(mut buf, n_merge_join_condition) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 23, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.override) != 0 { - write_tag_into(mut buf, 24, 0) - write_varint_into(mut buf, u64(val.override)) - } - in_on_conflict := encode_on_conflict_expr(val.on_conflict) - if in_on_conflict.len > 0 { - write_tag_into(mut buf, 25, 2) - write_length_delimited_into(mut buf, in_on_conflict) - } - if val.returning_list.len > 0 { - for v in val.returning_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 26, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.group_clause.len > 0 { - for v in val.group_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 27, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.group_distinct { - write_tag_into(mut buf, 28, 0) - write_bool_into(mut buf, val.group_distinct) - } - if val.grouping_sets.len > 0 { - for v in val.grouping_sets { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 29, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_having_qual := encode_node(val.having_qual) - if n_having_qual.len > 0 { - write_tag_into(mut buf, 30, 2) - write_length_delimited_into(mut buf, n_having_qual) - } - if val.window_clause.len > 0 { - for v in val.window_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 31, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.distinct_clause.len > 0 { - for v in val.distinct_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 32, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.sort_clause.len > 0 { - for v in val.sort_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 33, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_limit_offset := encode_node(val.limit_offset) - if n_limit_offset.len > 0 { - write_tag_into(mut buf, 34, 2) - write_length_delimited_into(mut buf, n_limit_offset) - } - n_limit_count := encode_node(val.limit_count) - if n_limit_count.len > 0 { - write_tag_into(mut buf, 35, 2) - write_length_delimited_into(mut buf, n_limit_count) - } - if u64(val.limit_option) != 0 { - write_tag_into(mut buf, 36, 0) - write_varint_into(mut buf, u64(val.limit_option)) - } - if val.row_marks.len > 0 { - for v in val.row_marks { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 37, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_set_operations := encode_node(val.set_operations) - if n_set_operations.len > 0 { - write_tag_into(mut buf, 38, 2) - write_length_delimited_into(mut buf, n_set_operations) - } - if val.constraint_deps.len > 0 { - for v in val.constraint_deps { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 39, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.with_check_options.len > 0 { - for v in val.with_check_options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 40, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.stmt_location != 0 { - write_tag_into(mut buf, 41, 0) - write_varint_into(mut buf, u64(val.stmt_location)) - } - if val.stmt_len != 0 { - write_tag_into(mut buf, 42, 0) - write_varint_into(mut buf, u64(val.stmt_len)) - } - return buf -} - -pub fn encode_type_cast(val TypeCast) []u8 { - mut buf := []u8{} - n_arg := encode_node(val.arg) - if n_arg.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_arg) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_type_name) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_range_table_func_col(val RangeTableFuncCol) []u8 { - mut buf := []u8{} - if val.colname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.colname) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_type_name) - } - if val.for_ordinality { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.for_ordinality) - } - if val.is_not_null { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.is_not_null) - } - n_colexpr := encode_node(val.colexpr) - if n_colexpr.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_colexpr) - } - n_coldefexpr := encode_node(val.coldefexpr) - if n_coldefexpr.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_coldefexpr) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_xml_serialize(val XmlSerialize) []u8 { - mut buf := []u8{} - if u64(val.xmloption) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.xmloption)) - } - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_expr) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_type_name) - } - if val.indent { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.indent) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_create_op_class_stmt(val CreateOpClassStmt) []u8 { - mut buf := []u8{} - if val.opclassname.len > 0 { - for v in val.opclassname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.opfamilyname.len > 0 { - for v in val.opfamilyname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.amname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.amname) - } - in_datatype := encode_type_name(val.datatype) - if in_datatype.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_datatype) - } - if val.items.len > 0 { - for v in val.items { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_default { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.is_default) - } - return buf -} - -pub fn encode_create_function_stmt(val CreateFunctionStmt) []u8 { - mut buf := []u8{} - if val.is_procedure { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.is_procedure) - } - if val.replace { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.replace) - } - if val.funcname.len > 0 { - for v in val.funcname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.parameters.len > 0 { - for v in val.parameters { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_return_type := encode_type_name(val.return_type) - if in_return_type.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_return_type) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_sql_body := encode_node(val.sql_body) - if n_sql_body.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_sql_body) - } - return buf -} - -pub fn encode_function_parameter(val FunctionParameter) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - in_arg_type := encode_type_name(val.arg_type) - if in_arg_type.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_arg_type) - } - if u64(val.mode) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.mode)) - } - n_defexpr := encode_node(val.defexpr) - if n_defexpr.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_defexpr) - } - return buf -} - -pub fn encode_create_domain_stmt(val CreateDomainStmt) []u8 { - mut buf := []u8{} - if val.domainname.len > 0 { - for v in val.domainname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_type_name) - } - in_coll_clause := encode_collate_clause(val.coll_clause) - if in_coll_clause.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_coll_clause) - } - if val.constraints.len > 0 { - for v in val.constraints { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_schema_stmt(val CreateSchemaStmt) []u8 { - mut buf := []u8{} - if val.schemaname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.schemaname) - } - in_authrole := encode_role_spec(val.authrole) - if in_authrole.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_authrole) - } - if val.schema_elts.len > 0 { - for v in val.schema_elts { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.if_not_exists { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.if_not_exists) - } - return buf -} - -pub fn encode_alter_table_cmd(val AlterTableCmd) []u8 { - mut buf := []u8{} - if u64(val.subtype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.subtype)) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - if val.num != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.num)) - } - in_newowner := encode_role_spec(val.newowner) - if in_newowner.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_newowner) - } - n_def := encode_node(val.def) - if n_def.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_def) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - if val.missing_ok { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.missing_ok) - } - if val.recurse { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.recurse) - } - return buf -} - -pub fn encode_grant_stmt(val GrantStmt) []u8 { - mut buf := []u8{} - if val.is_grant { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.is_grant) - } - if u64(val.targtype) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.targtype)) - } - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - if val.objects.len > 0 { - for v in val.objects { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.privileges.len > 0 { - for v in val.privileges { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.grantees.len > 0 { - for v in val.grantees { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.grant_option { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.grant_option) - } - in_grantor := encode_role_spec(val.grantor) - if in_grantor.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, in_grantor) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - return buf -} - -pub fn encode_grant_role_stmt(val GrantRoleStmt) []u8 { - mut buf := []u8{} - if val.granted_roles.len > 0 { - for v in val.granted_roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.grantee_roles.len > 0 { - for v in val.grantee_roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_grant { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.is_grant) - } - if val.opt.len > 0 { - for v in val.opt { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_grantor := encode_role_spec(val.grantor) - if in_grantor.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_grantor) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - return buf -} - -pub fn encode_create_table_space_stmt(val CreateTableSpaceStmt) []u8 { - mut buf := []u8{} - if val.tablespacename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.tablespacename) - } - in_owner := encode_role_spec(val.owner) - if in_owner.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_owner) - } - if val.location != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.location) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_user_mapping_stmt(val CreateUserMappingStmt) []u8 { - mut buf := []u8{} - in_user := encode_role_spec(val.user) - if in_user.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_user) - } - if val.servername != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.servername) - } - if val.if_not_exists { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.if_not_exists) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_user_mapping_stmt(val AlterUserMappingStmt) []u8 { - mut buf := []u8{} - in_user := encode_role_spec(val.user) - if in_user.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_user) - } - if val.servername != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.servername) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_drop_user_mapping_stmt(val DropUserMappingStmt) []u8 { - mut buf := []u8{} - in_user := encode_role_spec(val.user) - if in_user.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_user) - } - if val.servername != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.servername) - } - if val.missing_ok { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_alter_role_stmt(val AlterRoleStmt) []u8 { - mut buf := []u8{} - in_role := encode_role_spec(val.role) - if in_role.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_role) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.action != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.action)) - } - return buf -} - -pub fn encode_reassign_owned_stmt(val ReassignOwnedStmt) []u8 { - mut buf := []u8{} - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_newrole := encode_role_spec(val.newrole) - if in_newrole.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_newrole) - } - return buf -} - -pub fn encode_func_call(val FuncCall) []u8 { - mut buf := []u8{} - if val.funcname.len > 0 { - for v in val.funcname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.agg_order.len > 0 { - for v in val.agg_order { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_agg_filter := encode_node(val.agg_filter) - if n_agg_filter.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_agg_filter) - } - in_over := encode_window_def(val.over) - if in_over.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_over) - } - if val.agg_within_group { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.agg_within_group) - } - if val.agg_star { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.agg_star) - } - if val.agg_distinct { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.agg_distinct) - } - if val.func_variadic { - write_tag_into(mut buf, 9, 0) - write_bool_into(mut buf, val.func_variadic) - } - if u64(val.funcformat) != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.funcformat)) - } - if val.location != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_on_conflict_clause(val OnConflictClause) []u8 { - mut buf := []u8{} - if u64(val.action) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.action)) - } - in_infer := encode_infer_clause(val.infer) - if in_infer.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_infer) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_common_table_expr(val CommonTableExpr) []u8 { - mut buf := []u8{} - if val.ctename != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.ctename) - } - if val.aliascolnames.len > 0 { - for v in val.aliascolnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.ctematerialized) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.ctematerialized)) - } - n_ctequery := encode_node(val.ctequery) - if n_ctequery.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_ctequery) - } - in_search_clause := encode_c_t_e_search_clause(val.search_clause) - if in_search_clause.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_search_clause) - } - in_cycle_clause := encode_c_t_e_cycle_clause(val.cycle_clause) - if in_cycle_clause.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_cycle_clause) - } - if val.location != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.location)) - } - if val.cterecursive { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.cterecursive) - } - if val.cterefcount != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.cterefcount)) - } - if val.ctecolnames.len > 0 { - for v in val.ctecolnames { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.ctecoltypes.len > 0 { - for v in val.ctecoltypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.ctecoltypmods.len > 0 { - for v in val.ctecoltypmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 12, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.ctecolcollations.len > 0 { - for v in val.ctecolcollations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_json_table_column(val JsonTableColumn) []u8 { - mut buf := []u8{} - if u64(val.coltype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.coltype)) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_type_name) - } - in_pathspec := encode_json_table_path_spec(val.pathspec) - if in_pathspec.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_pathspec) - } - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_format) - } - if u64(val.wrapper) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.wrapper)) - } - if u64(val.quotes) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.quotes)) - } - if val.columns.len > 0 { - for v in val.columns { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_on_empty := encode_json_behavior(val.on_empty) - if in_on_empty.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, in_on_empty) - } - in_on_error := encode_json_behavior(val.on_error) - if in_on_error.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, in_on_error) - } - if val.location != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_create_op_class_item(val CreateOpClassItem) []u8 { - mut buf := []u8{} - if val.itemtype != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.itemtype)) - } - in_name := encode_object_with_args(val.name) - if in_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_name) - } - if val.number != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.number)) - } - if val.order_family.len > 0 { - for v in val.order_family { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.class_args.len > 0 { - for v in val.class_args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_storedtype := encode_type_name(val.storedtype) - if in_storedtype.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_storedtype) - } - return buf -} - -pub fn encode_alter_function_stmt(val AlterFunctionStmt) []u8 { - mut buf := []u8{} - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - in_func := encode_object_with_args(val.func) - if in_func.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_func) - } - if val.actions.len > 0 { - for v in val.actions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_operator_stmt(val AlterOperatorStmt) []u8 { - mut buf := []u8{} - in_opername := encode_object_with_args(val.opername) - if in_opername.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_opername) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_create_cast_stmt(val CreateCastStmt) []u8 { - mut buf := []u8{} - in_sourcetype := encode_type_name(val.sourcetype) - if in_sourcetype.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_sourcetype) - } - in_targettype := encode_type_name(val.targettype) - if in_targettype.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_targettype) - } - in_func := encode_object_with_args(val.func) - if in_func.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_func) - } - if u64(val.context) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.context)) - } - if val.inout { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.inout) - } - return buf -} - -pub fn encode_create_transform_stmt(val CreateTransformStmt) []u8 { - mut buf := []u8{} - if val.replace { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.replace) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_type_name) - } - if val.lang != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.lang) - } - in_fromsql := encode_object_with_args(val.fromsql) - if in_fromsql.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_fromsql) - } - in_tosql := encode_object_with_args(val.tosql) - if in_tosql.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_tosql) - } - return buf -} - -pub fn encode_alter_role_set_stmt(val AlterRoleSetStmt) []u8 { - mut buf := []u8{} - in_role := encode_role_spec(val.role) - if in_role.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_role) - } - if val.database != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.database) - } - in_setstmt := encode_variable_set_stmt(val.setstmt) - if in_setstmt.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_setstmt) - } - return buf -} - -pub fn encode_alter_database_set_stmt(val AlterDatabaseSetStmt) []u8 { - mut buf := []u8{} - if val.dbname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.dbname) - } - in_setstmt := encode_variable_set_stmt(val.setstmt) - if in_setstmt.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_setstmt) - } - return buf -} - -pub fn encode_alter_system_stmt(val AlterSystemStmt) []u8 { - mut buf := []u8{} - in_setstmt := encode_variable_set_stmt(val.setstmt) - if in_setstmt.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_setstmt) - } - return buf -} - -pub fn encode_into_clause(val IntoClause) []u8 { - mut buf := []u8{} - in_rel := encode_range_var(val.rel) - if in_rel.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_rel) - } - if val.col_names.len > 0 { - for v in val.col_names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.access_method != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.access_method) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.on_commit) != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.on_commit)) - } - if val.table_space_name != '' { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, val.table_space_name) - } - n_view_query := encode_node(val.view_query) - if n_view_query.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_view_query) - } - if val.skip_data { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.skip_data) - } - return buf -} - -pub fn encode_column_def(val ColumnDef) []u8 { - mut buf := []u8{} - if val.colname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.colname) - } - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_type_name) - } - if val.compression != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.compression) - } - if val.inhcount != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.inhcount)) - } - if val.is_local { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.is_local) - } - if val.is_not_null { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.is_not_null) - } - if val.is_from_type { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.is_from_type) - } - if val.storage != '' { - write_tag_into(mut buf, 8, 2) - write_string_into(mut buf, val.storage) - } - if val.storage_name != '' { - write_tag_into(mut buf, 9, 2) - write_string_into(mut buf, val.storage_name) - } - n_raw_default := encode_node(val.raw_default) - if n_raw_default.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, n_raw_default) - } - n_cooked_default := encode_node(val.cooked_default) - if n_cooked_default.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, n_cooked_default) - } - if val.identity != '' { - write_tag_into(mut buf, 12, 2) - write_string_into(mut buf, val.identity) - } - in_identity_sequence := encode_range_var(val.identity_sequence) - if in_identity_sequence.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, in_identity_sequence) - } - if val.generated != '' { - write_tag_into(mut buf, 14, 2) - write_string_into(mut buf, val.generated) - } - in_coll_clause := encode_collate_clause(val.coll_clause) - if in_coll_clause.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, in_coll_clause) - } - if val.coll_oid != 0 { - write_tag_into(mut buf, 16, 0) - write_varint_into(mut buf, u64(val.coll_oid)) - } - if val.constraints.len > 0 { - for v in val.constraints { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 17, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.fdwoptions.len > 0 { - for v in val.fdwoptions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 18, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.location != 0 { - write_tag_into(mut buf, 19, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_table_like_clause(val TableLikeClause) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.options != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.options)) - } - if val.relation_oid != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.relation_oid)) - } - return buf -} - -pub fn encode_partition_cmd(val PartitionCmd) []u8 { - mut buf := []u8{} - in_name := encode_range_var(val.name) - if in_name.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_name) - } - in_bound := encode_partition_bound_spec(val.bound) - if in_bound.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_bound) - } - if val.concurrent { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.concurrent) - } - return buf -} - -pub fn encode_delete_stmt(val DeleteStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.using_clause.len > 0 { - for v in val.using_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.returning_list.len > 0 { - for v in val.returning_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_with_clause := encode_with_clause(val.with_clause) - if in_with_clause.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_with_clause) - } - return buf -} - -pub fn encode_update_stmt(val UpdateStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.from_clause.len > 0 { - for v in val.from_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.returning_list.len > 0 { - for v in val.returning_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_with_clause := encode_with_clause(val.with_clause) - if in_with_clause.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_with_clause) - } - return buf -} - -pub fn encode_merge_stmt(val MergeStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_source_relation := encode_node(val.source_relation) - if n_source_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_source_relation) - } - n_join_condition := encode_node(val.join_condition) - if n_join_condition.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_join_condition) - } - if val.merge_when_clauses.len > 0 { - for v in val.merge_when_clauses { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.returning_list.len > 0 { - for v in val.returning_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_with_clause := encode_with_clause(val.with_clause) - if in_with_clause.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_with_clause) - } - return buf -} - -pub fn encode_alter_table_stmt(val AlterTableStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.cmds.len > 0 { - for v in val.cmds { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - if val.missing_ok { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_copy_stmt(val CopyStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_query) - } - if val.attlist.len > 0 { - for v in val.attlist { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.is_from { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.is_from) - } - if val.is_program { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.is_program) - } - if val.filename != '' { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, val.filename) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - return buf -} - -pub fn encode_create_stmt(val CreateStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.table_elts.len > 0 { - for v in val.table_elts { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.inh_relations.len > 0 { - for v in val.inh_relations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_partbound := encode_partition_bound_spec(val.partbound) - if in_partbound.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_partbound) - } - in_partspec := encode_partition_spec(val.partspec) - if in_partspec.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_partspec) - } - in_of_typename := encode_type_name(val.of_typename) - if in_of_typename.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_of_typename) - } - if val.constraints.len > 0 { - for v in val.constraints { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.oncommit) != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.oncommit)) - } - if val.tablespacename != '' { - write_tag_into(mut buf, 10, 2) - write_string_into(mut buf, val.tablespacename) - } - if val.access_method != '' { - write_tag_into(mut buf, 11, 2) - write_string_into(mut buf, val.access_method) - } - if val.if_not_exists { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.if_not_exists) - } - return buf -} - -pub fn encode_constraint(val Constraint) []u8 { - mut buf := []u8{} - if u64(val.contype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.contype)) - } - if val.conname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.conname) - } - if val.deferrable { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.deferrable) - } - if val.initdeferred { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.initdeferred) - } - if val.skip_validation { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.skip_validation) - } - if val.initially_valid { - write_tag_into(mut buf, 6, 0) - write_bool_into(mut buf, val.initially_valid) - } - if val.is_no_inherit { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.is_no_inherit) - } - n_raw_expr := encode_node(val.raw_expr) - if n_raw_expr.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, n_raw_expr) - } - if val.cooked_expr != '' { - write_tag_into(mut buf, 9, 2) - write_string_into(mut buf, val.cooked_expr) - } - if val.generated_when != '' { - write_tag_into(mut buf, 10, 2) - write_string_into(mut buf, val.generated_when) - } - if val.inhcount != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.inhcount)) - } - if val.nulls_not_distinct { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.nulls_not_distinct) - } - if val.keys.len > 0 { - for v in val.keys { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.including.len > 0 { - for v in val.including { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 14, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.exclusions.len > 0 { - for v in val.exclusions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 16, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.indexname != '' { - write_tag_into(mut buf, 17, 2) - write_string_into(mut buf, val.indexname) - } - if val.indexspace != '' { - write_tag_into(mut buf, 18, 2) - write_string_into(mut buf, val.indexspace) - } - if val.reset_default_tblspc { - write_tag_into(mut buf, 19, 0) - write_bool_into(mut buf, val.reset_default_tblspc) - } - if val.access_method != '' { - write_tag_into(mut buf, 20, 2) - write_string_into(mut buf, val.access_method) - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 21, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - in_pktable := encode_range_var(val.pktable) - if in_pktable.len > 0 { - write_tag_into(mut buf, 22, 2) - write_length_delimited_into(mut buf, in_pktable) - } - if val.fk_attrs.len > 0 { - for v in val.fk_attrs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 23, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.pk_attrs.len > 0 { - for v in val.pk_attrs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 24, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.fk_matchtype != '' { - write_tag_into(mut buf, 25, 2) - write_string_into(mut buf, val.fk_matchtype) - } - if val.fk_upd_action != '' { - write_tag_into(mut buf, 26, 2) - write_string_into(mut buf, val.fk_upd_action) - } - if val.fk_del_action != '' { - write_tag_into(mut buf, 27, 2) - write_string_into(mut buf, val.fk_del_action) - } - if val.fk_del_set_cols.len > 0 { - for v in val.fk_del_set_cols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 28, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.old_conpfeqop.len > 0 { - for v in val.old_conpfeqop { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 29, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.old_pktable_oid != 0 { - write_tag_into(mut buf, 30, 0) - write_varint_into(mut buf, u64(val.old_pktable_oid)) - } - if val.location != 0 { - write_tag_into(mut buf, 31, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_create_policy_stmt(val CreatePolicyStmt) []u8 { - mut buf := []u8{} - if val.policy_name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.policy_name) - } - in_table := encode_range_var(val.table) - if in_table.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_table) - } - if val.cmd_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.cmd_name) - } - if val.permissive { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.permissive) - } - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_qual := encode_node(val.qual) - if n_qual.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_qual) - } - n_with_check := encode_node(val.with_check) - if n_with_check.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, n_with_check) - } - return buf -} - -pub fn encode_alter_policy_stmt(val AlterPolicyStmt) []u8 { - mut buf := []u8{} - if val.policy_name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.policy_name) - } - in_table := encode_range_var(val.table) - if in_table.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_table) - } - if val.roles.len > 0 { - for v in val.roles { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_qual := encode_node(val.qual) - if n_qual.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_qual) - } - n_with_check := encode_node(val.with_check) - if n_with_check.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_with_check) - } - return buf -} - -pub fn encode_create_trig_stmt(val CreateTrigStmt) []u8 { - mut buf := []u8{} - if val.replace { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.replace) - } - if val.isconstraint { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.isconstraint) - } - if val.trigname != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.trigname) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.funcname.len > 0 { - for v in val.funcname { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.row { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.row) - } - if val.timing != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.timing)) - } - if val.events != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.events)) - } - if val.columns.len > 0 { - for v in val.columns { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_when_clause := encode_node(val.when_clause) - if n_when_clause.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, n_when_clause) - } - if val.transition_rels.len > 0 { - for v in val.transition_rels { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 12, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.deferrable { - write_tag_into(mut buf, 13, 0) - write_bool_into(mut buf, val.deferrable) - } - if val.initdeferred { - write_tag_into(mut buf, 14, 0) - write_bool_into(mut buf, val.initdeferred) - } - in_constrrel := encode_range_var(val.constrrel) - if in_constrrel.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, in_constrrel) - } - return buf -} - -pub fn encode_create_seq_stmt(val CreateSeqStmt) []u8 { - mut buf := []u8{} - in_sequence := encode_range_var(val.sequence) - if in_sequence.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_sequence) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.owner_id != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.owner_id)) - } - if val.for_identity { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.for_identity) - } - if val.if_not_exists { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.if_not_exists) - } - return buf -} - -pub fn encode_alter_seq_stmt(val AlterSeqStmt) []u8 { - mut buf := []u8{} - in_sequence := encode_range_var(val.sequence) - if in_sequence.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_sequence) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.for_identity { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.for_identity) - } - if val.missing_ok { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_index_stmt(val IndexStmt) []u8 { - mut buf := []u8{} - if val.idxname != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.idxname) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.access_method != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.access_method) - } - if val.table_space != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.table_space) - } - if val.index_params.len > 0 { - for v in val.index_params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.index_including_params.len > 0 { - for v in val.index_including_params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.exclude_op_names.len > 0 { - for v in val.exclude_op_names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.idxcomment != '' { - write_tag_into(mut buf, 10, 2) - write_string_into(mut buf, val.idxcomment) - } - if val.index_oid != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.index_oid)) - } - if val.old_number != 0 { - write_tag_into(mut buf, 12, 0) - write_varint_into(mut buf, u64(val.old_number)) - } - if val.old_create_subid != 0 { - write_tag_into(mut buf, 13, 0) - write_varint_into(mut buf, u64(val.old_create_subid)) - } - if val.old_first_relfilelocator_subid != 0 { - write_tag_into(mut buf, 14, 0) - write_varint_into(mut buf, u64(val.old_first_relfilelocator_subid)) - } - if val.unique { - write_tag_into(mut buf, 15, 0) - write_bool_into(mut buf, val.unique) - } - if val.nulls_not_distinct { - write_tag_into(mut buf, 16, 0) - write_bool_into(mut buf, val.nulls_not_distinct) - } - if val.primary { - write_tag_into(mut buf, 17, 0) - write_bool_into(mut buf, val.primary) - } - if val.isconstraint { - write_tag_into(mut buf, 18, 0) - write_bool_into(mut buf, val.isconstraint) - } - if val.deferrable { - write_tag_into(mut buf, 19, 0) - write_bool_into(mut buf, val.deferrable) - } - if val.initdeferred { - write_tag_into(mut buf, 20, 0) - write_bool_into(mut buf, val.initdeferred) - } - if val.transformed { - write_tag_into(mut buf, 21, 0) - write_bool_into(mut buf, val.transformed) - } - if val.concurrent { - write_tag_into(mut buf, 22, 0) - write_bool_into(mut buf, val.concurrent) - } - if val.if_not_exists { - write_tag_into(mut buf, 23, 0) - write_bool_into(mut buf, val.if_not_exists) - } - if val.reset_default_tblspc { - write_tag_into(mut buf, 24, 0) - write_bool_into(mut buf, val.reset_default_tblspc) - } - return buf -} - -pub fn encode_rename_stmt(val RenameStmt) []u8 { - mut buf := []u8{} - if u64(val.rename_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.rename_type)) - } - if u64(val.relation_type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.relation_type)) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_object) - } - if val.subname != '' { - write_tag_into(mut buf, 5, 2) - write_string_into(mut buf, val.subname) - } - if val.newname != '' { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, val.newname) - } - if u64(val.behavior) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.behavior)) - } - if val.missing_ok { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_alter_object_depends_stmt(val AlterObjectDependsStmt) []u8 { - mut buf := []u8{} - if u64(val.object_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.object_type)) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_object) - } - in_extname := encode_string(val.extname) - if in_extname.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_extname) - } - if val.remove { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.remove) - } - return buf -} - -pub fn encode_alter_object_schema_stmt(val AlterObjectSchemaStmt) []u8 { - mut buf := []u8{} - if u64(val.object_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.object_type)) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_object) - } - if val.newschema != '' { - write_tag_into(mut buf, 4, 2) - write_string_into(mut buf, val.newschema) - } - if val.missing_ok { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.missing_ok) - } - return buf -} - -pub fn encode_alter_owner_stmt(val AlterOwnerStmt) []u8 { - mut buf := []u8{} - if u64(val.object_type) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.object_type)) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_object := encode_node(val.object) - if n_object.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_object) - } - in_newowner := encode_role_spec(val.newowner) - if in_newowner.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_newowner) - } - return buf -} - -pub fn encode_rule_stmt(val RuleStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.rulename != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.rulename) - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if u64(val.event) != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.event)) - } - if val.instead { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.instead) - } - if val.actions.len > 0 { - for v in val.actions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.replace { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.replace) - } - return buf -} - -pub fn encode_composite_type_stmt(val CompositeTypeStmt) []u8 { - mut buf := []u8{} - in_typevar := encode_range_var(val.typevar) - if in_typevar.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_typevar) - } - if val.coldeflist.len > 0 { - for v in val.coldeflist { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_view_stmt(val ViewStmt) []u8 { - mut buf := []u8{} - in_view := encode_range_var(val.view) - if in_view.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_view) - } - if val.aliases.len > 0 { - for v in val.aliases { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_query) - } - if val.replace { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.replace) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if u64(val.with_check_option) != 0 { - write_tag_into(mut buf, 6, 0) - write_varint_into(mut buf, u64(val.with_check_option)) - } - return buf -} - -pub fn encode_cluster_stmt(val ClusterStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.indexname != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.indexname) - } - if val.params.len > 0 { - for v in val.params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_vacuum_relation(val VacuumRelation) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.oid != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.oid)) - } - if val.va_cols.len > 0 { - for v in val.va_cols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_refresh_mat_view_stmt(val RefreshMatViewStmt) []u8 { - mut buf := []u8{} - if val.concurrent { - write_tag_into(mut buf, 1, 0) - write_bool_into(mut buf, val.concurrent) - } - if val.skip_data { - write_tag_into(mut buf, 2, 0) - write_bool_into(mut buf, val.skip_data) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_relation) - } - return buf -} - -pub fn encode_reindex_stmt(val ReindexStmt) []u8 { - mut buf := []u8{} - if u64(val.kind) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.kind)) - } - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.name) - } - if val.params.len > 0 { - for v in val.params { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_publication_table(val PublicationTable) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.columns.len > 0 { - for v in val.columns { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_json_constructor_expr(val JsonConstructorExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.type) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.type)) - } - if val.args.len > 0 { - for v in val.args { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_func := encode_node(val.func) - if n_func.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_func) - } - n_coercion := encode_node(val.coercion) - if n_coercion.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_coercion) - } - in_returning := encode_json_returning(val.returning) - if in_returning.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_returning) - } - if val.absent_on_null { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.absent_on_null) - } - if val.unique { - write_tag_into(mut buf, 8, 0) - write_bool_into(mut buf, val.unique) - } - if val.location != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_expr(val JsonExpr) []u8 { - mut buf := []u8{} - n_xpr := encode_node(val.xpr) - if n_xpr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_xpr) - } - if u64(val.op) != 0 { - write_tag_into(mut buf, 2, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.column_name != '' { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, val.column_name) - } - n_formatted_expr := encode_node(val.formatted_expr) - if n_formatted_expr.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_formatted_expr) - } - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_format) - } - n_path_spec := encode_node(val.path_spec) - if n_path_spec.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, n_path_spec) - } - in_returning := encode_json_returning(val.returning) - if in_returning.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, in_returning) - } - if val.passing_names.len > 0 { - for v in val.passing_names { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.passing_values.len > 0 { - for v in val.passing_values { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_on_empty := encode_json_behavior(val.on_empty) - if in_on_empty.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, in_on_empty) - } - in_on_error := encode_json_behavior(val.on_error) - if in_on_error.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, in_on_error) - } - if val.use_io_coercion { - write_tag_into(mut buf, 12, 0) - write_bool_into(mut buf, val.use_io_coercion) - } - if val.use_json_coercion { - write_tag_into(mut buf, 13, 0) - write_bool_into(mut buf, val.use_json_coercion) - } - if u64(val.wrapper) != 0 { - write_tag_into(mut buf, 14, 0) - write_varint_into(mut buf, u64(val.wrapper)) - } - if val.omit_quotes { - write_tag_into(mut buf, 15, 0) - write_bool_into(mut buf, val.omit_quotes) - } - if val.collation != 0 { - write_tag_into(mut buf, 16, 0) - write_varint_into(mut buf, u64(val.collation)) - } - if val.location != 0 { - write_tag_into(mut buf, 17, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_output(val JsonOutput) []u8 { - mut buf := []u8{} - in_type_name := encode_type_name(val.type_name) - if in_type_name.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_type_name) - } - in_returning := encode_json_returning(val.returning) - if in_returning.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_returning) - } - return buf -} - -pub fn encode_json_argument(val JsonArgument) []u8 { - mut buf := []u8{} - in_val := encode_json_value_expr(val.val) - if in_val.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_val) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - return buf -} - -pub fn encode_json_table(val JsonTable) []u8 { - mut buf := []u8{} - in_context_item := encode_json_value_expr(val.context_item) - if in_context_item.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_context_item) - } - in_pathspec := encode_json_table_path_spec(val.pathspec) - if in_pathspec.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_pathspec) - } - if val.passing.len > 0 { - for v in val.passing { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.columns.len > 0 { - for v in val.columns { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_on_error := encode_json_behavior(val.on_error) - if in_on_error.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, in_on_error) - } - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_alias) - } - if val.lateral { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.lateral) - } - if val.location != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_key_value(val JsonKeyValue) []u8 { - mut buf := []u8{} - n_key := encode_node(val.key) - if n_key.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_key) - } - in_value := encode_json_value_expr(val.value) - if in_value.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_value) - } - return buf -} - -pub fn encode_range_tbl_entry(val RangeTblEntry) []u8 { - mut buf := []u8{} - in_alias := encode_alias(val.alias) - if in_alias.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_alias) - } - in_eref := encode_alias(val.eref) - if in_eref.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_eref) - } - if u64(val.rtekind) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.rtekind)) - } - if val.relid != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.relid)) - } - if val.inh { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.inh) - } - if val.relkind != '' { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, val.relkind) - } - if val.rellockmode != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.rellockmode)) - } - if val.perminfoindex != 0 { - write_tag_into(mut buf, 8, 0) - write_varint_into(mut buf, u64(val.perminfoindex)) - } - in_tablesample := encode_table_sample_clause(val.tablesample) - if in_tablesample.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, in_tablesample) - } - in_subquery := encode_query(val.subquery) - if in_subquery.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, in_subquery) - } - if val.security_barrier { - write_tag_into(mut buf, 11, 0) - write_bool_into(mut buf, val.security_barrier) - } - if u64(val.jointype) != 0 { - write_tag_into(mut buf, 12, 0) - write_varint_into(mut buf, u64(val.jointype)) - } - if val.joinmergedcols != 0 { - write_tag_into(mut buf, 13, 0) - write_varint_into(mut buf, u64(val.joinmergedcols)) - } - if val.joinaliasvars.len > 0 { - for v in val.joinaliasvars { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 14, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.joinleftcols.len > 0 { - for v in val.joinleftcols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.joinrightcols.len > 0 { - for v in val.joinrightcols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 16, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_join_using_alias := encode_alias(val.join_using_alias) - if in_join_using_alias.len > 0 { - write_tag_into(mut buf, 17, 2) - write_length_delimited_into(mut buf, in_join_using_alias) - } - if val.functions.len > 0 { - for v in val.functions { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 18, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.funcordinality { - write_tag_into(mut buf, 19, 0) - write_bool_into(mut buf, val.funcordinality) - } - in_tablefunc := encode_table_func(val.tablefunc) - if in_tablefunc.len > 0 { - write_tag_into(mut buf, 20, 2) - write_length_delimited_into(mut buf, in_tablefunc) - } - if val.values_lists.len > 0 { - for v in val.values_lists { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 21, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.ctename != '' { - write_tag_into(mut buf, 22, 2) - write_string_into(mut buf, val.ctename) - } - if val.ctelevelsup != 0 { - write_tag_into(mut buf, 23, 0) - write_varint_into(mut buf, u64(val.ctelevelsup)) - } - if val.self_reference { - write_tag_into(mut buf, 24, 0) - write_bool_into(mut buf, val.self_reference) - } - if val.coltypes.len > 0 { - for v in val.coltypes { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 25, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.coltypmods.len > 0 { - for v in val.coltypmods { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 26, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.colcollations.len > 0 { - for v in val.colcollations { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 27, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.enrname != '' { - write_tag_into(mut buf, 28, 2) - write_string_into(mut buf, val.enrname) - } - if val.enrtuples != 0.0 { - write_tag_into(mut buf, 29, 1) - write_double_into(mut buf, val.enrtuples) - } - if val.lateral { - write_tag_into(mut buf, 30, 0) - write_bool_into(mut buf, val.lateral) - } - if val.in_from_cl { - write_tag_into(mut buf, 31, 0) - write_bool_into(mut buf, val.in_from_cl) - } - if val.security_quals.len > 0 { - for v in val.security_quals { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 32, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_alter_default_privileges_stmt(val AlterDefaultPrivilegesStmt) []u8 { - mut buf := []u8{} - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_action := encode_grant_stmt(val.action) - if in_action.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_action) - } - return buf -} - -pub fn encode_call_stmt(val CallStmt) []u8 { - mut buf := []u8{} - in_funccall := encode_func_call(val.funccall) - if in_funccall.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_funccall) - } - in_funcexpr := encode_func_expr(val.funcexpr) - if in_funcexpr.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_funcexpr) - } - if val.outargs.len > 0 { - for v in val.outargs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_insert_stmt(val InsertStmt) []u8 { - mut buf := []u8{} - in_relation := encode_range_var(val.relation) - if in_relation.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_relation) - } - if val.cols.len > 0 { - for v in val.cols { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_select_stmt := encode_node(val.select_stmt) - if n_select_stmt.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, n_select_stmt) - } - in_on_conflict_clause := encode_on_conflict_clause(val.on_conflict_clause) - if in_on_conflict_clause.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_on_conflict_clause) - } - if val.returning_list.len > 0 { - for v in val.returning_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_with_clause := encode_with_clause(val.with_clause) - if in_with_clause.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_with_clause) - } - if u64(val.override) != 0 { - write_tag_into(mut buf, 7, 0) - write_varint_into(mut buf, u64(val.override)) - } - return buf -} - -pub fn encode_select_stmt(val SelectStmt) []u8 { - mut buf := []u8{} - if val.distinct_clause.len > 0 { - for v in val.distinct_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_into_clause := encode_into_clause(val.into_clause) - if in_into_clause.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_into_clause) - } - if val.target_list.len > 0 { - for v in val.target_list { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.from_clause.len > 0 { - for v in val.from_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_where_clause := encode_node(val.where_clause) - if n_where_clause.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, n_where_clause) - } - if val.group_clause.len > 0 { - for v in val.group_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.group_distinct { - write_tag_into(mut buf, 7, 0) - write_bool_into(mut buf, val.group_distinct) - } - n_having_clause := encode_node(val.having_clause) - if n_having_clause.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, n_having_clause) - } - if val.window_clause.len > 0 { - for v in val.window_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.values_lists.len > 0 { - for v in val.values_lists { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.sort_clause.len > 0 { - for v in val.sort_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - n_limit_offset := encode_node(val.limit_offset) - if n_limit_offset.len > 0 { - write_tag_into(mut buf, 12, 2) - write_length_delimited_into(mut buf, n_limit_offset) - } - n_limit_count := encode_node(val.limit_count) - if n_limit_count.len > 0 { - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, n_limit_count) - } - if u64(val.limit_option) != 0 { - write_tag_into(mut buf, 14, 0) - write_varint_into(mut buf, u64(val.limit_option)) - } - if val.locking_clause.len > 0 { - for v in val.locking_clause { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_with_clause := encode_with_clause(val.with_clause) - if in_with_clause.len > 0 { - write_tag_into(mut buf, 16, 2) - write_length_delimited_into(mut buf, in_with_clause) - } - if u64(val.op) != 0 { - write_tag_into(mut buf, 17, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.all { - write_tag_into(mut buf, 18, 0) - write_bool_into(mut buf, val.all) - } - if val.larg != unsafe { nil } { - sr_larg := encode_select_stmt(*val.larg) - write_tag_into(mut buf, 19, 2) - write_length_delimited_into(mut buf, sr_larg) - } - if val.rarg != unsafe { nil } { - sr_rarg := encode_select_stmt(*val.rarg) - write_tag_into(mut buf, 20, 2) - write_length_delimited_into(mut buf, sr_rarg) - } - return buf -} - -pub fn encode_create_table_as_stmt(val CreateTableAsStmt) []u8 { - mut buf := []u8{} - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_query) - } - in_into := encode_into_clause(val.into) - if in_into.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_into) - } - if u64(val.objtype) != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.objtype)) - } - if val.is_select_into { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.is_select_into) - } - if val.if_not_exists { - write_tag_into(mut buf, 5, 0) - write_bool_into(mut buf, val.if_not_exists) - } - return buf -} - -pub fn encode_create_foreign_table_stmt(val CreateForeignTableStmt) []u8 { - mut buf := []u8{} - in_base_stmt := encode_create_stmt(val.base_stmt) - if in_base_stmt.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_base_stmt) - } - if val.servername != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.servername) - } - if val.options.len > 0 { - for v in val.options { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - return buf -} - -pub fn encode_publication_obj_spec(val PublicationObjSpec) []u8 { - mut buf := []u8{} - if u64(val.pubobjtype) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.pubobjtype)) - } - if val.name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.name) - } - in_pubtable := encode_publication_table(val.pubtable) - if in_pubtable.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_pubtable) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_func_expr(val JsonFuncExpr) []u8 { - mut buf := []u8{} - if u64(val.op) != 0 { - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.op)) - } - if val.column_name != '' { - write_tag_into(mut buf, 2, 2) - write_string_into(mut buf, val.column_name) - } - in_context_item := encode_json_value_expr(val.context_item) - if in_context_item.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_context_item) - } - n_pathspec := encode_node(val.pathspec) - if n_pathspec.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, n_pathspec) - } - if val.passing.len > 0 { - for v in val.passing { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, in_output) - } - in_on_empty := encode_json_behavior(val.on_empty) - if in_on_empty.len > 0 { - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, in_on_empty) - } - in_on_error := encode_json_behavior(val.on_error) - if in_on_error.len > 0 { - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, in_on_error) - } - if u64(val.wrapper) != 0 { - write_tag_into(mut buf, 9, 0) - write_varint_into(mut buf, u64(val.wrapper)) - } - if u64(val.quotes) != 0 { - write_tag_into(mut buf, 10, 0) - write_varint_into(mut buf, u64(val.quotes)) - } - if val.location != 0 { - write_tag_into(mut buf, 11, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_parse_expr(val JsonParseExpr) []u8 { - mut buf := []u8{} - in_expr := encode_json_value_expr(val.expr) - if in_expr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_expr) - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - if val.unique_keys { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.unique_keys) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_scalar_expr(val JsonScalarExpr) []u8 { - mut buf := []u8{} - n_expr := encode_node(val.expr) - if n_expr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_expr) - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_serialize_expr(val JsonSerializeExpr) []u8 { - mut buf := []u8{} - in_expr := encode_json_value_expr(val.expr) - if in_expr.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_expr) - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - if val.location != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_object_constructor(val JsonObjectConstructor) []u8 { - mut buf := []u8{} - if val.exprs.len > 0 { - for v in val.exprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - if val.absent_on_null { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.absent_on_null) - } - if val.unique { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.unique) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_array_constructor(val JsonArrayConstructor) []u8 { - mut buf := []u8{} - if val.exprs.len > 0 { - for v in val.exprs { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - if val.absent_on_null { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.absent_on_null) - } - if val.location != 0 { - write_tag_into(mut buf, 4, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_array_query_constructor(val JsonArrayQueryConstructor) []u8 { - mut buf := []u8{} - n_query := encode_node(val.query) - if n_query.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, n_query) - } - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_output) - } - in_format := encode_json_format(val.format) - if in_format.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, in_format) - } - if val.absent_on_null { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.absent_on_null) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_agg_constructor(val JsonAggConstructor) []u8 { - mut buf := []u8{} - in_output := encode_json_output(val.output) - if in_output.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_output) - } - n_agg_filter := encode_node(val.agg_filter) - if n_agg_filter.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, n_agg_filter) - } - if val.agg_order.len > 0 { - for v in val.agg_order { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - in_over := encode_window_def(val.over) - if in_over.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_over) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_p_l_assign_stmt(val PLAssignStmt) []u8 { - mut buf := []u8{} - if val.name != '' { - write_tag_into(mut buf, 1, 2) - write_string_into(mut buf, val.name) - } - if val.indirection.len > 0 { - for v in val.indirection { - inner_ := encode_node(v) - if inner_.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner_) - } - } - } - if val.nnames != 0 { - write_tag_into(mut buf, 3, 0) - write_varint_into(mut buf, u64(val.nnames)) - } - in_val := encode_select_stmt(val.val) - if in_val.len > 0 { - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, in_val) - } - if val.location != 0 { - write_tag_into(mut buf, 5, 0) - write_varint_into(mut buf, u64(val.location)) - } - return buf -} - -pub fn encode_json_object_agg(val JsonObjectAgg) []u8 { - mut buf := []u8{} - in_constructor := encode_json_agg_constructor(val.constructor) - if in_constructor.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_constructor) - } - in_arg := encode_json_key_value(val.arg) - if in_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_arg) - } - if val.absent_on_null { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.absent_on_null) - } - if val.unique { - write_tag_into(mut buf, 4, 0) - write_bool_into(mut buf, val.unique) - } - return buf -} - -pub fn encode_json_array_agg(val JsonArrayAgg) []u8 { - mut buf := []u8{} - in_constructor := encode_json_agg_constructor(val.constructor) - if in_constructor.len > 0 { - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, in_constructor) - } - in_arg := encode_json_value_expr(val.arg) - if in_arg.len > 0 { - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, in_arg) - } - if val.absent_on_null { - write_tag_into(mut buf, 3, 0) - write_bool_into(mut buf, val.absent_on_null) - } - return buf -} - -pub fn encode_summary_result(val SummaryResult) []u8 { - mut buf := []u8{} - if val.tables.len > 0 { - for v in val.tables { - sub_enc_ := encode_summary_result_table(v) - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - } - if val.aliases.len > 0 { - for k, v in val.aliases { - map_enc_ := write_map_string_entry(k, v) - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, map_enc_) - } - } - if val.cte_names.len > 0 { - for v in val.cte_names { - write_tag_into(mut buf, 3, 2) - write_string_into(mut buf, v) - } - } - if val.functions.len > 0 { - for v in val.functions { - sub_enc_ := encode_summary_result_function(v) - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - } - if val.filter_columns.len > 0 { - for v in val.filter_columns { - sub_enc_ := encode_summary_result_filter_column(v) - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, sub_enc_) - } - } - if val.statement_types.len > 0 { - for v in val.statement_types { - write_tag_into(mut buf, 6, 2) - write_string_into(mut buf, v) - } - } - if val.truncated_query != '' { - write_tag_into(mut buf, 7, 2) - write_string_into(mut buf, val.truncated_query) - } - return buf -} - -fn encode_node(val_ Node) []u8 { - match val_ { - Alias { - inner := encode_alias(val_) - if inner.len == 0 { return []u8{} } - mut buf := []u8{} - write_tag_into(mut buf, 1, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeVar { - inner := encode_range_var(val_) - mut buf := []u8{} - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TableFunc { - inner := encode_table_func(val_) - mut buf := []u8{} - write_tag_into(mut buf, 3, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - IntoClause { - inner := encode_into_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 4, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Var { - inner := encode_var(val_) - mut buf := []u8{} - write_tag_into(mut buf, 5, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Param { - inner := encode_param(val_) - mut buf := []u8{} - write_tag_into(mut buf, 6, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Aggref { - inner := encode_aggref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 7, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - GroupingFunc { - inner := encode_grouping_func(val_) - mut buf := []u8{} - write_tag_into(mut buf, 8, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WindowFunc { - inner := encode_window_func(val_) - mut buf := []u8{} - write_tag_into(mut buf, 9, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WindowFuncRunCondition { - inner := encode_window_func_run_condition(val_) - mut buf := []u8{} - write_tag_into(mut buf, 10, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MergeSupportFunc { - inner := encode_merge_support_func(val_) - mut buf := []u8{} - write_tag_into(mut buf, 11, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SubscriptingRef { - inner := encode_subscripting_ref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 12, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FuncExpr { - inner := encode_func_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 13, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - NamedArgExpr { - inner := encode_named_arg_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 14, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - OpExpr { - inner := encode_op_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 15, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DistinctExpr { - inner := encode_distinct_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 16, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - NullIfExpr { - inner := encode_null_if_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 17, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ScalarArrayOpExpr { - inner := encode_scalar_array_op_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 18, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - BoolExpr { - inner := encode_bool_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 19, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SubLink { - inner := encode_sub_link(val_) - mut buf := []u8{} - write_tag_into(mut buf, 20, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SubPlan { - inner := encode_sub_plan(val_) - mut buf := []u8{} - write_tag_into(mut buf, 21, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlternativeSubPlan { - inner := encode_alternative_sub_plan(val_) - mut buf := []u8{} - write_tag_into(mut buf, 22, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FieldSelect { - inner := encode_field_select(val_) - mut buf := []u8{} - write_tag_into(mut buf, 23, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FieldStore { - inner := encode_field_store(val_) - mut buf := []u8{} - write_tag_into(mut buf, 24, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RelabelType { - inner := encode_relabel_type(val_) - mut buf := []u8{} - write_tag_into(mut buf, 25, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CoerceViaIO { - inner := encode_coerce_via_i_o(val_) - mut buf := []u8{} - write_tag_into(mut buf, 26, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ArrayCoerceExpr { - inner := encode_array_coerce_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 27, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ConvertRowtypeExpr { - inner := encode_convert_rowtype_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 28, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CollateExpr { - inner := encode_collate_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 29, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CaseExpr { - inner := encode_case_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 30, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CaseWhen { - inner := encode_case_when(val_) - mut buf := []u8{} - write_tag_into(mut buf, 31, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CaseTestExpr { - inner := encode_case_test_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 32, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ArrayExpr { - inner := encode_array_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 33, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RowExpr { - inner := encode_row_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 34, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RowCompareExpr { - inner := encode_row_compare_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 35, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CoalesceExpr { - inner := encode_coalesce_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 36, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MinMaxExpr { - inner := encode_min_max_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 37, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SQLValueFunction { - inner := encode_s_q_l_value_function(val_) - mut buf := []u8{} - write_tag_into(mut buf, 38, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - XmlExpr { - inner := encode_xml_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 39, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonFormat { - inner := encode_json_format(val_) - mut buf := []u8{} - write_tag_into(mut buf, 40, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonReturning { - inner := encode_json_returning(val_) - mut buf := []u8{} - write_tag_into(mut buf, 41, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonValueExpr { - inner := encode_json_value_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 42, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonConstructorExpr { - inner := encode_json_constructor_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 43, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonIsPredicate { - inner := encode_json_is_predicate(val_) - mut buf := []u8{} - write_tag_into(mut buf, 44, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonBehavior { - inner := encode_json_behavior(val_) - mut buf := []u8{} - write_tag_into(mut buf, 45, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonExpr { - inner := encode_json_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 46, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTablePath { - inner := encode_json_table_path(val_) - mut buf := []u8{} - write_tag_into(mut buf, 47, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTablePathScan { - inner := encode_json_table_path_scan(val_) - mut buf := []u8{} - write_tag_into(mut buf, 48, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTableSiblingJoin { - inner := encode_json_table_sibling_join(val_) - mut buf := []u8{} - write_tag_into(mut buf, 49, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - NullTest { - inner := encode_null_test(val_) - mut buf := []u8{} - write_tag_into(mut buf, 50, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - BooleanTest { - inner := encode_boolean_test(val_) - mut buf := []u8{} - write_tag_into(mut buf, 51, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MergeAction { - inner := encode_merge_action(val_) - mut buf := []u8{} - write_tag_into(mut buf, 52, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CoerceToDomain { - inner := encode_coerce_to_domain(val_) - mut buf := []u8{} - write_tag_into(mut buf, 53, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CoerceToDomainValue { - inner := encode_coerce_to_domain_value(val_) - mut buf := []u8{} - write_tag_into(mut buf, 54, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SetToDefault { - inner := encode_set_to_default(val_) - mut buf := []u8{} - write_tag_into(mut buf, 55, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CurrentOfExpr { - inner := encode_current_of_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 56, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - NextValueExpr { - inner := encode_next_value_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 57, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - InferenceElem { - inner := encode_inference_elem(val_) - mut buf := []u8{} - write_tag_into(mut buf, 58, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TargetEntry { - inner := encode_target_entry(val_) - mut buf := []u8{} - write_tag_into(mut buf, 59, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTblRef { - inner := encode_range_tbl_ref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 60, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JoinExpr { - inner := encode_join_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 61, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FromExpr { - inner := encode_from_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 62, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - OnConflictExpr { - inner := encode_on_conflict_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 63, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Query { - inner := encode_query(val_) - mut buf := []u8{} - write_tag_into(mut buf, 64, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TypeName { - inner := encode_type_name(val_) - mut buf := []u8{} - write_tag_into(mut buf, 65, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ColumnRef { - inner := encode_column_ref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 66, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ParamRef { - inner := encode_param_ref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 67, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AExpr { - inner := encode_a_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 68, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TypeCast { - inner := encode_type_cast(val_) - mut buf := []u8{} - write_tag_into(mut buf, 69, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CollateClause { - inner := encode_collate_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 70, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RoleSpec { - inner := encode_role_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 71, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FuncCall { - inner := encode_func_call(val_) - mut buf := []u8{} - write_tag_into(mut buf, 72, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AStar { - inner := encode_a_star(val_) - mut buf := []u8{} - write_tag_into(mut buf, 73, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AIndices { - inner := encode_a_indices(val_) - mut buf := []u8{} - write_tag_into(mut buf, 74, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AIndirection { - inner := encode_a_indirection(val_) - mut buf := []u8{} - write_tag_into(mut buf, 75, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AArrayExpr { - inner := encode_a_array_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 76, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ResTarget { - inner := encode_res_target(val_) - mut buf := []u8{} - write_tag_into(mut buf, 77, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MultiAssignRef { - inner := encode_multi_assign_ref(val_) - mut buf := []u8{} - write_tag_into(mut buf, 78, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SortBy { - inner := encode_sort_by(val_) - mut buf := []u8{} - write_tag_into(mut buf, 79, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WindowDef { - inner := encode_window_def(val_) - mut buf := []u8{} - write_tag_into(mut buf, 80, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeSubselect { - inner := encode_range_subselect(val_) - mut buf := []u8{} - write_tag_into(mut buf, 81, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeFunction { - inner := encode_range_function(val_) - mut buf := []u8{} - write_tag_into(mut buf, 82, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTableFunc { - inner := encode_range_table_func(val_) - mut buf := []u8{} - write_tag_into(mut buf, 83, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTableFuncCol { - inner := encode_range_table_func_col(val_) - mut buf := []u8{} - write_tag_into(mut buf, 84, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTableSample { - inner := encode_range_table_sample(val_) - mut buf := []u8{} - write_tag_into(mut buf, 85, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ColumnDef { - inner := encode_column_def(val_) - mut buf := []u8{} - write_tag_into(mut buf, 86, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TableLikeClause { - inner := encode_table_like_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 87, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - IndexElem { - inner := encode_index_elem(val_) - mut buf := []u8{} - write_tag_into(mut buf, 88, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DefElem { - inner := encode_def_elem(val_) - mut buf := []u8{} - write_tag_into(mut buf, 89, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - LockingClause { - inner := encode_locking_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 90, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - XmlSerialize { - inner := encode_xml_serialize(val_) - mut buf := []u8{} - write_tag_into(mut buf, 91, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PartitionElem { - inner := encode_partition_elem(val_) - mut buf := []u8{} - write_tag_into(mut buf, 92, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PartitionSpec { - inner := encode_partition_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 93, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PartitionBoundSpec { - inner := encode_partition_bound_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 94, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PartitionRangeDatum { - inner := encode_partition_range_datum(val_) - mut buf := []u8{} - write_tag_into(mut buf, 95, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SinglePartitionSpec { - inner := encode_single_partition_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 96, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PartitionCmd { - inner := encode_partition_cmd(val_) - mut buf := []u8{} - write_tag_into(mut buf, 97, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTblEntry { - inner := encode_range_tbl_entry(val_) - mut buf := []u8{} - write_tag_into(mut buf, 98, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RTEPermissionInfo { - inner := encode_r_t_e_permission_info(val_) - mut buf := []u8{} - write_tag_into(mut buf, 99, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RangeTblFunction { - inner := encode_range_tbl_function(val_) - mut buf := []u8{} - write_tag_into(mut buf, 100, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TableSampleClause { - inner := encode_table_sample_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 101, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WithCheckOption { - inner := encode_with_check_option(val_) - mut buf := []u8{} - write_tag_into(mut buf, 102, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SortGroupClause { - inner := encode_sort_group_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 103, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - GroupingSet { - inner := encode_grouping_set(val_) - mut buf := []u8{} - write_tag_into(mut buf, 104, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WindowClause { - inner := encode_window_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 105, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RowMarkClause { - inner := encode_row_mark_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 106, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - WithClause { - inner := encode_with_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 107, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - InferClause { - inner := encode_infer_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 108, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - OnConflictClause { - inner := encode_on_conflict_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 109, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CTESearchClause { - inner := encode_c_t_e_search_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 110, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CTECycleClause { - inner := encode_c_t_e_cycle_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 111, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CommonTableExpr { - inner := encode_common_table_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 112, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MergeWhenClause { - inner := encode_merge_when_clause(val_) - mut buf := []u8{} - write_tag_into(mut buf, 113, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TriggerTransition { - inner := encode_trigger_transition(val_) - mut buf := []u8{} - write_tag_into(mut buf, 114, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonOutput { - inner := encode_json_output(val_) - mut buf := []u8{} - write_tag_into(mut buf, 115, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonArgument { - inner := encode_json_argument(val_) - mut buf := []u8{} - write_tag_into(mut buf, 116, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonFuncExpr { - inner := encode_json_func_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 117, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTablePathSpec { - inner := encode_json_table_path_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 118, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTable { - inner := encode_json_table(val_) - mut buf := []u8{} - write_tag_into(mut buf, 119, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonTableColumn { - inner := encode_json_table_column(val_) - mut buf := []u8{} - write_tag_into(mut buf, 120, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonKeyValue { - inner := encode_json_key_value(val_) - mut buf := []u8{} - write_tag_into(mut buf, 121, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonParseExpr { - inner := encode_json_parse_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 122, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonScalarExpr { - inner := encode_json_scalar_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 123, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonSerializeExpr { - inner := encode_json_serialize_expr(val_) - mut buf := []u8{} - write_tag_into(mut buf, 124, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonObjectConstructor { - inner := encode_json_object_constructor(val_) - mut buf := []u8{} - write_tag_into(mut buf, 125, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonArrayConstructor { - inner := encode_json_array_constructor(val_) - mut buf := []u8{} - write_tag_into(mut buf, 126, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonArrayQueryConstructor { - inner := encode_json_array_query_constructor(val_) - mut buf := []u8{} - write_tag_into(mut buf, 127, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonAggConstructor { - inner := encode_json_agg_constructor(val_) - mut buf := []u8{} - write_tag_into(mut buf, 128, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonObjectAgg { - inner := encode_json_object_agg(val_) - mut buf := []u8{} - write_tag_into(mut buf, 129, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - JsonArrayAgg { - inner := encode_json_array_agg(val_) - mut buf := []u8{} - write_tag_into(mut buf, 130, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RawStmt { - inner := encode_raw_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 131, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - InsertStmt { - inner := encode_insert_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 132, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DeleteStmt { - inner := encode_delete_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 133, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - UpdateStmt { - inner := encode_update_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 134, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - MergeStmt { - inner := encode_merge_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 135, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SelectStmt { - inner := encode_select_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 136, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SetOperationStmt { - inner := encode_set_operation_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 137, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ReturnStmt { - inner := encode_return_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 138, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PLAssignStmt { - inner := encode_p_l_assign_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 139, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateSchemaStmt { - inner := encode_create_schema_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 140, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTableStmt { - inner := encode_alter_table_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 141, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ReplicaIdentityStmt { - inner := encode_replica_identity_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 142, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTableCmd { - inner := encode_alter_table_cmd(val_) - mut buf := []u8{} - write_tag_into(mut buf, 143, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterCollationStmt { - inner := encode_alter_collation_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 144, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterDomainStmt { - inner := encode_alter_domain_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 145, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - GrantStmt { - inner := encode_grant_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 146, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ObjectWithArgs { - inner := encode_object_with_args(val_) - mut buf := []u8{} - write_tag_into(mut buf, 147, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AccessPriv { - inner := encode_access_priv(val_) - mut buf := []u8{} - write_tag_into(mut buf, 148, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - GrantRoleStmt { - inner := encode_grant_role_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 149, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterDefaultPrivilegesStmt { - inner := encode_alter_default_privileges_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 150, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CopyStmt { - inner := encode_copy_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 151, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - VariableSetStmt { - inner := encode_variable_set_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 152, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - VariableShowStmt { - inner := encode_variable_show_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 153, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateStmt { - inner := encode_create_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 154, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Constraint { - inner := encode_constraint(val_) - mut buf := []u8{} - write_tag_into(mut buf, 155, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateTableSpaceStmt { - inner := encode_create_table_space_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 156, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropTableSpaceStmt { - inner := encode_drop_table_space_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 157, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTableSpaceOptionsStmt { - inner := encode_alter_table_space_options_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 158, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTableMoveAllStmt { - inner := encode_alter_table_move_all_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 159, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateExtensionStmt { - inner := encode_create_extension_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 160, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterExtensionStmt { - inner := encode_alter_extension_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 161, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterExtensionContentsStmt { - inner := encode_alter_extension_contents_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 162, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateFdwStmt { - inner := encode_create_fdw_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 163, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterFdwStmt { - inner := encode_alter_fdw_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 164, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateForeignServerStmt { - inner := encode_create_foreign_server_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 165, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterForeignServerStmt { - inner := encode_alter_foreign_server_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 166, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateForeignTableStmt { - inner := encode_create_foreign_table_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 167, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateUserMappingStmt { - inner := encode_create_user_mapping_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 168, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterUserMappingStmt { - inner := encode_alter_user_mapping_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 169, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropUserMappingStmt { - inner := encode_drop_user_mapping_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 170, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ImportForeignSchemaStmt { - inner := encode_import_foreign_schema_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 171, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreatePolicyStmt { - inner := encode_create_policy_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 172, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterPolicyStmt { - inner := encode_alter_policy_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 173, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateAmStmt { - inner := encode_create_am_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 174, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateTrigStmt { - inner := encode_create_trig_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 175, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateEventTrigStmt { - inner := encode_create_event_trig_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 176, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterEventTrigStmt { - inner := encode_alter_event_trig_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 177, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreatePLangStmt { - inner := encode_create_p_lang_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 178, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateRoleStmt { - inner := encode_create_role_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 179, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterRoleStmt { - inner := encode_alter_role_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 180, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterRoleSetStmt { - inner := encode_alter_role_set_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 181, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropRoleStmt { - inner := encode_drop_role_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 182, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateSeqStmt { - inner := encode_create_seq_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 183, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterSeqStmt { - inner := encode_alter_seq_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 184, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DefineStmt { - inner := encode_define_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 185, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateDomainStmt { - inner := encode_create_domain_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 186, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateOpClassStmt { - inner := encode_create_op_class_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 187, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateOpClassItem { - inner := encode_create_op_class_item(val_) - mut buf := []u8{} - write_tag_into(mut buf, 188, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateOpFamilyStmt { - inner := encode_create_op_family_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 189, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterOpFamilyStmt { - inner := encode_alter_op_family_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 190, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropStmt { - inner := encode_drop_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 191, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TruncateStmt { - inner := encode_truncate_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 192, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CommentStmt { - inner := encode_comment_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 193, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - SecLabelStmt { - inner := encode_sec_label_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 194, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DeclareCursorStmt { - inner := encode_declare_cursor_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 195, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ClosePortalStmt { - inner := encode_close_portal_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 196, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FetchStmt { - inner := encode_fetch_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 197, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - IndexStmt { - inner := encode_index_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 198, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateStatsStmt { - inner := encode_create_stats_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 199, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - StatsElem { - inner := encode_stats_elem(val_) - mut buf := []u8{} - write_tag_into(mut buf, 200, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterStatsStmt { - inner := encode_alter_stats_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 201, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateFunctionStmt { - inner := encode_create_function_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 202, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - FunctionParameter { - inner := encode_function_parameter(val_) - mut buf := []u8{} - write_tag_into(mut buf, 203, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterFunctionStmt { - inner := encode_alter_function_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 204, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DoStmt { - inner := encode_do_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 205, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - InlineCodeBlock { - inner := encode_inline_code_block(val_) - mut buf := []u8{} - write_tag_into(mut buf, 206, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CallStmt { - inner := encode_call_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 207, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CallContext { - inner := encode_call_context(val_) - mut buf := []u8{} - write_tag_into(mut buf, 208, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RenameStmt { - inner := encode_rename_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 209, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterObjectDependsStmt { - inner := encode_alter_object_depends_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 210, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterObjectSchemaStmt { - inner := encode_alter_object_schema_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 211, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterOwnerStmt { - inner := encode_alter_owner_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 212, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterOperatorStmt { - inner := encode_alter_operator_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 213, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTypeStmt { - inner := encode_alter_type_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 214, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RuleStmt { - inner := encode_rule_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 215, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - NotifyStmt { - inner := encode_notify_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 216, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ListenStmt { - inner := encode_listen_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 217, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - UnlistenStmt { - inner := encode_unlisten_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 218, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - TransactionStmt { - inner := encode_transaction_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 219, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CompositeTypeStmt { - inner := encode_composite_type_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 220, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateEnumStmt { - inner := encode_create_enum_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 221, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateRangeStmt { - inner := encode_create_range_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 222, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterEnumStmt { - inner := encode_alter_enum_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 223, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ViewStmt { - inner := encode_view_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 224, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - LoadStmt { - inner := encode_load_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 225, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreatedbStmt { - inner := encode_createdb_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 226, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterDatabaseStmt { - inner := encode_alter_database_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 227, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterDatabaseRefreshCollStmt { - inner := encode_alter_database_refresh_coll_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 228, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterDatabaseSetStmt { - inner := encode_alter_database_set_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 229, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropdbStmt { - inner := encode_dropdb_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 230, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterSystemStmt { - inner := encode_alter_system_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 231, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ClusterStmt { - inner := encode_cluster_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 232, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - VacuumStmt { - inner := encode_vacuum_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 233, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - VacuumRelation { - inner := encode_vacuum_relation(val_) - mut buf := []u8{} - write_tag_into(mut buf, 234, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ExplainStmt { - inner := encode_explain_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 235, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateTableAsStmt { - inner := encode_create_table_as_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 236, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - RefreshMatViewStmt { - inner := encode_refresh_mat_view_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 237, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CheckPointStmt { - inner := encode_check_point_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 238, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DiscardStmt { - inner := encode_discard_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 239, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - LockStmt { - inner := encode_lock_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 240, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ConstraintsSetStmt { - inner := encode_constraints_set_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 241, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ReindexStmt { - inner := encode_reindex_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 242, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateConversionStmt { - inner := encode_create_conversion_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 243, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateCastStmt { - inner := encode_create_cast_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 244, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateTransformStmt { - inner := encode_create_transform_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 245, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PrepareStmt { - inner := encode_prepare_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 246, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ExecuteStmt { - inner := encode_execute_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 247, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DeallocateStmt { - inner := encode_deallocate_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 248, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropOwnedStmt { - inner := encode_drop_owned_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 249, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - ReassignOwnedStmt { - inner := encode_reassign_owned_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 250, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTSDictionaryStmt { - inner := encode_alter_t_s_dictionary_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 251, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterTSConfigurationStmt { - inner := encode_alter_t_s_configuration_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 252, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PublicationTable { - inner := encode_publication_table(val_) - mut buf := []u8{} - write_tag_into(mut buf, 253, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - PublicationObjSpec { - inner := encode_publication_obj_spec(val_) - mut buf := []u8{} - write_tag_into(mut buf, 254, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreatePublicationStmt { - inner := encode_create_publication_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 255, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterPublicationStmt { - inner := encode_alter_publication_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 256, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - CreateSubscriptionStmt { - inner := encode_create_subscription_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 257, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AlterSubscriptionStmt { - inner := encode_alter_subscription_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 258, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - DropSubscriptionStmt { - inner := encode_drop_subscription_stmt(val_) - mut buf := []u8{} - write_tag_into(mut buf, 259, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Integer { - inner := encode_integer(val_) - mut buf := []u8{} - write_tag_into(mut buf, 260, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Float { - inner := encode_float(val_) - mut buf := []u8{} - write_tag_into(mut buf, 261, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - Boolean { - inner := encode_boolean(val_) - mut buf := []u8{} - write_tag_into(mut buf, 262, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - String { - inner := encode_string(val_) - mut buf := []u8{} - write_tag_into(mut buf, 263, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - BitString { - inner := encode_bit_string(val_) - mut buf := []u8{} - write_tag_into(mut buf, 264, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - List { - inner := encode_list(val_) - mut buf := []u8{} - write_tag_into(mut buf, 265, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - IntList { - inner := encode_int_list(val_) - mut buf := []u8{} - write_tag_into(mut buf, 266, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - OidList { - inner := encode_oid_list(val_) - mut buf := []u8{} - write_tag_into(mut buf, 267, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - AConst { - inner := encode_a_const(val_) - mut buf := []u8{} - write_tag_into(mut buf, 268, 2) - write_length_delimited_into(mut buf, inner) - return buf - } - UnrecognizedNode { - mut buf := []u8{} - write_tag_into(mut buf, val_.field_num, 2) - write_length_delimited_into(mut buf, val_.data) - return buf - } - } -} - -pub fn encode_parse_result(val ParseAstResult) []u8 { - mut buf := []u8{} - write_tag_into(mut buf, 1, 0) - write_varint_into(mut buf, u64(val.version)) - for s in val.stmts { - mut inner := []u8{} - write_tag_into(mut inner, 1, 2) - write_length_delimited_into(mut inner, encode_node(s.stmt)) - write_tag_into(mut inner, 2, 0) - write_varint_into(mut inner, u64(s.stmt_location)) - write_tag_into(mut inner, 3, 0) - write_varint_into(mut inner, u64(s.stmt_len)) - write_tag_into(mut buf, 2, 2) - write_length_delimited_into(mut buf, inner) - } - return buf -} - diff --git a/pg_query/pg_query_ast.v b/pg_query_ast.v similarity index 99% rename from pg_query/pg_query_ast.v rename to pg_query_ast.v index e50ada3..f0a6550 100644 --- a/pg_query/pg_query_ast.v +++ b/pg_query_ast.v @@ -4183,8 +4183,8 @@ pub mut: with_clause WithClause op SetOperation all bool - larg &SelectStmt - rarg &SelectStmt + larg ?&SelectStmt + rarg ?&SelectStmt } pub fn (m SelectStmt) str() string { mut parts := []string{} @@ -4206,8 +4206,8 @@ pub fn (m SelectStmt) str() string { parts << "with_clause: ${m.with_clause}" parts << "op: ${m.op}" if m.all { parts << "all: true" } - if !isnil(m.larg) { parts << "larg: ${m.larg}" } - if !isnil(m.rarg) { parts << "rarg: ${m.rarg}" } + if m.larg != none { parts << "larg: ${m.larg}" } + if m.rarg != none { parts << "rarg: ${m.rarg}" } return 'SelectStmt{' + parts.join(', ') + '}' } diff --git a/pg_query/pg_query_decode.v b/pg_query_decode.v similarity index 99% rename from pg_query/pg_query_decode.v rename to pg_query_decode.v index e58078b..2173c1a 100644 --- a/pg_query/pg_query_decode.v +++ b/pg_query_decode.v @@ -11376,12 +11376,12 @@ fn decode_insert_stmt(buf []u8, depth int) (InsertStmt, int) { fn decode_select_stmt(buf []u8, depth int) (SelectStmt, int) { if depth <= 0 { return SelectStmt{ - larg: unsafe { nil } - rarg: unsafe { nil } + larg: none + rarg: none }, 0 } mut r := SelectStmt{ - larg: unsafe { nil } - rarg: unsafe { nil } + larg: none + rarg: none } mut off := 0 for off < buf.len { @@ -11979,14 +11979,14 @@ fn decode_json_agg_constructor(buf []u8, depth int) (JsonAggConstructor, int) { fn decode_p_l_assign_stmt(buf []u8, depth int) (PLAssignStmt, int) { if depth <= 0 { return PLAssignStmt{ val: SelectStmt{ - larg: unsafe { nil } - rarg: unsafe { nil } + larg: none + rarg: none } }, 0 } mut r := PLAssignStmt{ val: SelectStmt{ - larg: unsafe { nil } - rarg: unsafe { nil } + larg: none + rarg: none } } mut off := 0 diff --git a/pg_query_encode.v b/pg_query_encode.v new file mode 100644 index 0000000..e8374ce --- /dev/null +++ b/pg_query_encode.v @@ -0,0 +1,14204 @@ +// Code generated by tools/gen_ast.v from libpg_query/protobuf/pg_query.proto +// DO NOT EDIT. +module pg_query + +fn encode_scan_result_into(mut buf []u8, val ScanResult) { + if val.version != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.version)) + } + if val.tokens.len > 0 { + for v in val.tokens { + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_scan_token_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + } +} + +pub fn encode_scan_result(val ScanResult) []u8 { + mut buf := []u8{} + encode_scan_result_into(mut buf, val) + return buf +} + +fn encode_integer_into(mut buf []u8, val Integer) { + if val.ival != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.ival)) + } +} + +pub fn encode_integer(val Integer) []u8 { + mut buf := []u8{} + encode_integer_into(mut buf, val) + return buf +} + +fn encode_float_into(mut buf []u8, val Float) { + if val.fval != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.fval) + } +} + +pub fn encode_float(val Float) []u8 { + mut buf := []u8{} + encode_float_into(mut buf, val) + return buf +} + +fn encode_boolean_into(mut buf []u8, val Boolean) { + if val.boolval { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.boolval) + } +} + +pub fn encode_boolean(val Boolean) []u8 { + mut buf := []u8{} + encode_boolean_into(mut buf, val) + return buf +} + +fn encode_string_into(mut buf []u8, val String) { + if val.sval != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.sval) + } +} + +pub fn encode_string(val String) []u8 { + mut buf := []u8{} + encode_string_into(mut buf, val) + return buf +} + +fn encode_bit_string_into(mut buf []u8, val BitString) { + if val.bsval != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.bsval) + } +} + +pub fn encode_bit_string(val BitString) []u8 { + mut buf := []u8{} + encode_bit_string_into(mut buf, val) + return buf +} + +fn encode_list_into(mut buf []u8, val List) { + if val.items.len > 0 { + for v in val.items { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_list(val List) []u8 { + mut buf := []u8{} + encode_list_into(mut buf, val) + return buf +} + +fn encode_oid_list_into(mut buf []u8, val OidList) { + if val.items.len > 0 { + for v in val.items { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_oid_list(val OidList) []u8 { + mut buf := []u8{} + encode_oid_list_into(mut buf, val) + return buf +} + +fn encode_int_list_into(mut buf []u8, val IntList) { + if val.items.len > 0 { + for v in val.items { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_int_list(val IntList) []u8 { + mut buf := []u8{} + encode_int_list_into(mut buf, val) + return buf +} + +fn encode_a_const_into(mut buf []u8, val AConst) { + if v := val.ival { + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_integer_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if v := val.fval { + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_float_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if v := val.boolval { + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_boolean_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if v := val.sval { + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_string_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if v := val.bsval { + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_bit_string_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if val.isnull { + write_tag_into(mut buf, 10, 0) + write_bool_into(mut buf, val.isnull) + } + if val.location != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_a_const(val AConst) []u8 { + mut buf := []u8{} + encode_a_const_into(mut buf, val) + return buf +} + +fn encode_alias_into(mut buf []u8, val Alias) { + if val.aliasname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.aliasname) + } + if val.colnames.len > 0 { + for v in val.colnames { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alias(val Alias) []u8 { + mut buf := []u8{} + encode_alias_into(mut buf, val) + return buf +} + +fn encode_table_func_into(mut buf []u8, val TableFunc) { + if u64(val.functype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.functype)) + } + if val.ns_uris.len > 0 { + for v in val.ns_uris { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.ns_names.len > 0 { + for v in val.ns_names { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.docexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rowexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.colnames.len > 0 { + for v in val.colnames { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.coltypes.len > 0 { + for v in val.coltypes { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.coltypmods.len > 0 { + for v in val.coltypmods { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.colcollations.len > 0 { + for v in val.colcollations { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.colexprs.len > 0 { + for v in val.colexprs { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.coldefexprs.len > 0 { + for v in val.coldefexprs { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.colvalexprs.len > 0 { + for v in val.colvalexprs { + tag_start_ := buf.len + write_tag_into(mut buf, 12, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.passingvalexprs.len > 0 { + for v in val.passingvalexprs { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.notnulls.len > 0 { + mut packed_ := []u8{} + for v in val.notnulls { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 14, 2) + write_length_delimited_into(mut buf, packed_) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.plan) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.ordinalitycol != 0 { + write_tag_into(mut buf, 16, 0) + write_varint_into(mut buf, u64(val.ordinalitycol)) + } + if val.location != 0 { + write_tag_into(mut buf, 17, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_table_func(val TableFunc) []u8 { + mut buf := []u8{} + encode_table_func_into(mut buf, val) + return buf +} + +fn encode_var_into(mut buf []u8, val Var) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.varno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.varno)) + } + if val.varattno != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.varattno)) + } + if val.vartype != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.vartype)) + } + if val.vartypmod != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.vartypmod)) + } + if val.varcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.varcollid)) + } + if val.varnullingrels.len > 0 { + mut packed_ := []u8{} + for v in val.varnullingrels { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 7, 2) + write_length_delimited_into(mut buf, packed_) + } + if val.varlevelsup != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.varlevelsup)) + } + if val.location != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_var(val Var) []u8 { + mut buf := []u8{} + encode_var_into(mut buf, val) + return buf +} + +fn encode_param_into(mut buf []u8, val Param) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.paramkind) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.paramkind)) + } + if val.paramid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.paramid)) + } + if val.paramtype != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.paramtype)) + } + if val.paramtypmod != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.paramtypmod)) + } + if val.paramcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.paramcollid)) + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_param(val Param) []u8 { + mut buf := []u8{} + encode_param_into(mut buf, val) + return buf +} + +fn encode_aggref_into(mut buf []u8, val Aggref) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.aggfnoid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.aggfnoid)) + } + if val.aggtype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.aggtype)) + } + if val.aggcollid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.aggcollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.aggargtypes.len > 0 { + for v in val.aggargtypes { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.aggdirectargs.len > 0 { + for v in val.aggdirectargs { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.aggorder.len > 0 { + for v in val.aggorder { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.aggdistinct.len > 0 { + for v in val.aggdistinct { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.aggfilter) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.aggstar { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.aggstar) + } + if val.aggvariadic { + write_tag_into(mut buf, 13, 0) + write_bool_into(mut buf, val.aggvariadic) + } + if val.aggkind != '' { + write_tag_into(mut buf, 14, 2) + write_string_into(mut buf, val.aggkind) + } + if val.agglevelsup != 0 { + write_tag_into(mut buf, 15, 0) + write_varint_into(mut buf, u64(val.agglevelsup)) + } + if u64(val.aggsplit) != 0 { + write_tag_into(mut buf, 16, 0) + write_varint_into(mut buf, u64(val.aggsplit)) + } + if val.aggno != 0 { + write_tag_into(mut buf, 17, 0) + write_varint_into(mut buf, u64(val.aggno)) + } + if val.aggtransno != 0 { + write_tag_into(mut buf, 18, 0) + write_varint_into(mut buf, u64(val.aggtransno)) + } + if val.location != 0 { + write_tag_into(mut buf, 19, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_aggref(val Aggref) []u8 { + mut buf := []u8{} + encode_aggref_into(mut buf, val) + return buf +} + +fn encode_grouping_func_into(mut buf []u8, val GroupingFunc) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.refs.len > 0 { + for v in val.refs { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.agglevelsup != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.agglevelsup)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_grouping_func(val GroupingFunc) []u8 { + mut buf := []u8{} + encode_grouping_func_into(mut buf, val) + return buf +} + +fn encode_window_func_into(mut buf []u8, val WindowFunc) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.winfnoid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.winfnoid)) + } + if val.wintype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.wintype)) + } + if val.wincollid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.wincollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.aggfilter) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.run_condition.len > 0 { + for v in val.run_condition { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.winref != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.winref)) + } + if val.winstar { + write_tag_into(mut buf, 10, 0) + write_bool_into(mut buf, val.winstar) + } + if val.winagg { + write_tag_into(mut buf, 11, 0) + write_bool_into(mut buf, val.winagg) + } + if val.location != 0 { + write_tag_into(mut buf, 12, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_window_func(val WindowFunc) []u8 { + mut buf := []u8{} + encode_window_func_into(mut buf, val) + return buf +} + +fn encode_window_func_run_condition_into(mut buf []u8, val WindowFuncRunCondition) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.opno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.opno)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.wfunc_left { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.wfunc_left) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_window_func_run_condition(val WindowFuncRunCondition) []u8 { + mut buf := []u8{} + encode_window_func_run_condition_into(mut buf, val) + return buf +} + +fn encode_merge_support_func_into(mut buf []u8, val MergeSupportFunc) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.msftype != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.msftype)) + } + if val.msfcollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.msfcollid)) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_merge_support_func(val MergeSupportFunc) []u8 { + mut buf := []u8{} + encode_merge_support_func_into(mut buf, val) + return buf +} + +fn encode_subscripting_ref_into(mut buf []u8, val SubscriptingRef) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.refcontainertype != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.refcontainertype)) + } + if val.refelemtype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.refelemtype)) + } + if val.refrestype != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.refrestype)) + } + if val.reftypmod != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.reftypmod)) + } + if val.refcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.refcollid)) + } + if val.refupperindexpr.len > 0 { + for v in val.refupperindexpr { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.reflowerindexpr.len > 0 { + for v in val.reflowerindexpr { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.refexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.refassgnexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_subscripting_ref(val SubscriptingRef) []u8 { + mut buf := []u8{} + encode_subscripting_ref_into(mut buf, val) + return buf +} + +fn encode_func_expr_into(mut buf []u8, val FuncExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.funcid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.funcid)) + } + if val.funcresulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.funcresulttype)) + } + if val.funcretset { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.funcretset) + } + if val.funcvariadic { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.funcvariadic) + } + if u64(val.funcformat) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.funcformat)) + } + if val.funccollid != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.funccollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_func_expr(val FuncExpr) []u8 { + mut buf := []u8{} + encode_func_expr_into(mut buf, val) + return buf +} + +fn encode_named_arg_expr_into(mut buf []u8, val NamedArgExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.name) + } + if val.argnumber != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.argnumber)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_named_arg_expr(val NamedArgExpr) []u8 { + mut buf := []u8{} + encode_named_arg_expr_into(mut buf, val) + return buf +} + +fn encode_op_expr_into(mut buf []u8, val OpExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.opno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.opno)) + } + if val.opresulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.opresulttype)) + } + if val.opretset { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.opretset) + } + if val.opcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.opcollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_op_expr(val OpExpr) []u8 { + mut buf := []u8{} + encode_op_expr_into(mut buf, val) + return buf +} + +fn encode_distinct_expr_into(mut buf []u8, val DistinctExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.opno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.opno)) + } + if val.opresulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.opresulttype)) + } + if val.opretset { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.opretset) + } + if val.opcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.opcollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_distinct_expr(val DistinctExpr) []u8 { + mut buf := []u8{} + encode_distinct_expr_into(mut buf, val) + return buf +} + +fn encode_null_if_expr_into(mut buf []u8, val NullIfExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.opno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.opno)) + } + if val.opresulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.opresulttype)) + } + if val.opretset { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.opretset) + } + if val.opcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.opcollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_null_if_expr(val NullIfExpr) []u8 { + mut buf := []u8{} + encode_null_if_expr_into(mut buf, val) + return buf +} + +fn encode_scalar_array_op_expr_into(mut buf []u8, val ScalarArrayOpExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.opno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.opno)) + } + if val.use_or { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.use_or) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_scalar_array_op_expr(val ScalarArrayOpExpr) []u8 { + mut buf := []u8{} + encode_scalar_array_op_expr_into(mut buf, val) + return buf +} + +fn encode_bool_expr_into(mut buf []u8, val BoolExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.boolop) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.boolop)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_bool_expr(val BoolExpr) []u8 { + mut buf := []u8{} + encode_bool_expr_into(mut buf, val) + return buf +} + +fn encode_sub_link_into(mut buf []u8, val SubLink) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.sub_link_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.sub_link_type)) + } + if val.sub_link_id != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.sub_link_id)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.testexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.oper_name.len > 0 { + for v in val.oper_name { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.subselect) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_sub_link(val SubLink) []u8 { + mut buf := []u8{} + encode_sub_link_into(mut buf, val) + return buf +} + +fn encode_sub_plan_into(mut buf []u8, val SubPlan) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.sub_link_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.sub_link_type)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.testexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.param_ids.len > 0 { + for v in val.param_ids { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.plan_id != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.plan_id)) + } + if val.plan_name != '' { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, val.plan_name) + } + if val.first_col_type != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.first_col_type)) + } + if val.first_col_typmod != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.first_col_typmod)) + } + if val.first_col_collation != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.first_col_collation)) + } + if val.use_hash_table { + write_tag_into(mut buf, 10, 0) + write_bool_into(mut buf, val.use_hash_table) + } + if val.unknown_eq_false { + write_tag_into(mut buf, 11, 0) + write_bool_into(mut buf, val.unknown_eq_false) + } + if val.parallel_safe { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.parallel_safe) + } + if val.set_param.len > 0 { + for v in val.set_param { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.par_param.len > 0 { + for v in val.par_param { + tag_start_ := buf.len + write_tag_into(mut buf, 14, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.startup_cost != 0.0 { + write_tag_into(mut buf, 16, 1) + write_double_into(mut buf, val.startup_cost) + } + if val.per_call_cost != 0.0 { + write_tag_into(mut buf, 17, 1) + write_double_into(mut buf, val.per_call_cost) + } +} + +pub fn encode_sub_plan(val SubPlan) []u8 { + mut buf := []u8{} + encode_sub_plan_into(mut buf, val) + return buf +} + +fn encode_alternative_sub_plan_into(mut buf []u8, val AlternativeSubPlan) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.subplans.len > 0 { + for v in val.subplans { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alternative_sub_plan(val AlternativeSubPlan) []u8 { + mut buf := []u8{} + encode_alternative_sub_plan_into(mut buf, val) + return buf +} + +fn encode_field_select_into(mut buf []u8, val FieldSelect) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.fieldnum != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.fieldnum)) + } + if val.resulttype != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if val.resulttypmod != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.resulttypmod)) + } + if val.resultcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.resultcollid)) + } +} + +pub fn encode_field_select(val FieldSelect) []u8 { + mut buf := []u8{} + encode_field_select_into(mut buf, val) + return buf +} + +fn encode_field_store_into(mut buf []u8, val FieldStore) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.newvals.len > 0 { + for v in val.newvals { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.fieldnums.len > 0 { + for v in val.fieldnums { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } +} + +pub fn encode_field_store(val FieldStore) []u8 { + mut buf := []u8{} + encode_field_store_into(mut buf, val) + return buf +} + +fn encode_relabel_type_into(mut buf []u8, val RelabelType) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if val.resulttypmod != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.resulttypmod)) + } + if val.resultcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.resultcollid)) + } + if u64(val.relabelformat) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.relabelformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_relabel_type(val RelabelType) []u8 { + mut buf := []u8{} + encode_relabel_type_into(mut buf, val) + return buf +} + +fn encode_coerce_via_i_o_into(mut buf []u8, val CoerceViaIO) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if val.resultcollid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.resultcollid)) + } + if u64(val.coerceformat) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.coerceformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_coerce_via_i_o(val CoerceViaIO) []u8 { + mut buf := []u8{} + encode_coerce_via_i_o_into(mut buf, val) + return buf +} + +fn encode_array_coerce_expr_into(mut buf []u8, val ArrayCoerceExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.elemexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if val.resulttypmod != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.resulttypmod)) + } + if val.resultcollid != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.resultcollid)) + } + if u64(val.coerceformat) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.coerceformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_array_coerce_expr(val ArrayCoerceExpr) []u8 { + mut buf := []u8{} + encode_array_coerce_expr_into(mut buf, val) + return buf +} + +fn encode_convert_rowtype_expr_into(mut buf []u8, val ConvertRowtypeExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if u64(val.convertformat) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.convertformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_convert_rowtype_expr(val ConvertRowtypeExpr) []u8 { + mut buf := []u8{} + encode_convert_rowtype_expr_into(mut buf, val) + return buf +} + +fn encode_collate_expr_into(mut buf []u8, val CollateExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coll_oid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.coll_oid)) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_collate_expr(val CollateExpr) []u8 { + mut buf := []u8{} + encode_collate_expr_into(mut buf, val) + return buf +} + +fn encode_case_expr_into(mut buf []u8, val CaseExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.casetype != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.casetype)) + } + if val.casecollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.casecollid)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.defresult) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_case_expr(val CaseExpr) []u8 { + mut buf := []u8{} + encode_case_expr_into(mut buf, val) + return buf +} + +fn encode_case_when_into(mut buf []u8, val CaseWhen) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.result) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_case_when(val CaseWhen) []u8 { + mut buf := []u8{} + encode_case_when_into(mut buf, val) + return buf +} + +fn encode_case_test_expr_into(mut buf []u8, val CaseTestExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.type_id != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.type_id)) + } + if val.type_mod != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.type_mod)) + } + if val.collation != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.collation)) + } +} + +pub fn encode_case_test_expr(val CaseTestExpr) []u8 { + mut buf := []u8{} + encode_case_test_expr_into(mut buf, val) + return buf +} + +fn encode_array_expr_into(mut buf []u8, val ArrayExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.array_typeid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.array_typeid)) + } + if val.array_collid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.array_collid)) + } + if val.element_typeid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.element_typeid)) + } + if val.elements.len > 0 { + for v in val.elements { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.multidims { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.multidims) + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_array_expr(val ArrayExpr) []u8 { + mut buf := []u8{} + encode_array_expr_into(mut buf, val) + return buf +} + +fn encode_row_expr_into(mut buf []u8, val RowExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.row_typeid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.row_typeid)) + } + if u64(val.row_format) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.row_format)) + } + if val.colnames.len > 0 { + for v in val.colnames { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_row_expr(val RowExpr) []u8 { + mut buf := []u8{} + encode_row_expr_into(mut buf, val) + return buf +} + +fn encode_row_compare_expr_into(mut buf []u8, val RowCompareExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.rctype) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.rctype)) + } + if val.opnos.len > 0 { + for v in val.opnos { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.opfamilies.len > 0 { + for v in val.opfamilies { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.inputcollids.len > 0 { + for v in val.inputcollids { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.largs.len > 0 { + for v in val.largs { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.rargs.len > 0 { + for v in val.rargs { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_row_compare_expr(val RowCompareExpr) []u8 { + mut buf := []u8{} + encode_row_compare_expr_into(mut buf, val) + return buf +} + +fn encode_coalesce_expr_into(mut buf []u8, val CoalesceExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coalescetype != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.coalescetype)) + } + if val.coalescecollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.coalescecollid)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_coalesce_expr(val CoalesceExpr) []u8 { + mut buf := []u8{} + encode_coalesce_expr_into(mut buf, val) + return buf +} + +fn encode_min_max_expr_into(mut buf []u8, val MinMaxExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.minmaxtype != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.minmaxtype)) + } + if val.minmaxcollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.minmaxcollid)) + } + if val.inputcollid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.inputcollid)) + } + if u64(val.op) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_min_max_expr(val MinMaxExpr) []u8 { + mut buf := []u8{} + encode_min_max_expr_into(mut buf, val) + return buf +} + +fn encode_s_q_l_value_function_into(mut buf []u8, val SQLValueFunction) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.op) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.type != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.type)) + } + if val.typmod != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.typmod)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_s_q_l_value_function(val SQLValueFunction) []u8 { + mut buf := []u8{} + encode_s_q_l_value_function_into(mut buf, val) + return buf +} + +fn encode_xml_expr_into(mut buf []u8, val XmlExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.op) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.name) + } + if val.named_args.len > 0 { + for v in val.named_args { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.arg_names.len > 0 { + for v in val.arg_names { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.xmloption) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.xmloption)) + } + if val.indent { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.indent) + } + if val.type != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.type)) + } + if val.typmod != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.typmod)) + } + if val.location != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_xml_expr(val XmlExpr) []u8 { + mut buf := []u8{} + encode_xml_expr_into(mut buf, val) + return buf +} + +fn encode_json_format_into(mut buf []u8, val JsonFormat) { + if u64(val.format_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.format_type)) + } + if u64(val.encoding) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.encoding)) + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_format(val JsonFormat) []u8 { + mut buf := []u8{} + encode_json_format_into(mut buf, val) + return buf +} + +fn encode_json_behavior_into(mut buf []u8, val JsonBehavior) { + if u64(val.btype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.btype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coerce { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.coerce) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_behavior(val JsonBehavior) []u8 { + mut buf := []u8{} + encode_json_behavior_into(mut buf, val) + return buf +} + +fn encode_json_table_path_into(mut buf []u8, val JsonTablePath) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } +} + +pub fn encode_json_table_path(val JsonTablePath) []u8 { + mut buf := []u8{} + encode_json_table_path_into(mut buf, val) + return buf +} + +fn encode_json_table_sibling_join_into(mut buf []u8, val JsonTableSiblingJoin) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.plan) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.lplan) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rplan) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_json_table_sibling_join(val JsonTableSiblingJoin) []u8 { + mut buf := []u8{} + encode_json_table_sibling_join_into(mut buf, val) + return buf +} + +fn encode_null_test_into(mut buf []u8, val NullTest) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.nulltesttype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.nulltesttype)) + } + if val.argisrow { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.argisrow) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_null_test(val NullTest) []u8 { + mut buf := []u8{} + encode_null_test_into(mut buf, val) + return buf +} + +fn encode_boolean_test_into(mut buf []u8, val BooleanTest) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.booltesttype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.booltesttype)) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_boolean_test(val BooleanTest) []u8 { + mut buf := []u8{} + encode_boolean_test_into(mut buf, val) + return buf +} + +fn encode_merge_action_into(mut buf []u8, val MergeAction) { + if u64(val.match_kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.match_kind)) + } + if u64(val.command_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.command_type)) + } + if u64(val.override) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.override)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.qual) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.update_colnos.len > 0 { + for v in val.update_colnos { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_merge_action(val MergeAction) []u8 { + mut buf := []u8{} + encode_merge_action_into(mut buf, val) + return buf +} + +fn encode_coerce_to_domain_into(mut buf []u8, val CoerceToDomain) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resulttype != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.resulttype)) + } + if val.resulttypmod != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.resulttypmod)) + } + if val.resultcollid != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.resultcollid)) + } + if u64(val.coercionformat) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.coercionformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_coerce_to_domain(val CoerceToDomain) []u8 { + mut buf := []u8{} + encode_coerce_to_domain_into(mut buf, val) + return buf +} + +fn encode_coerce_to_domain_value_into(mut buf []u8, val CoerceToDomainValue) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.type_id != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.type_id)) + } + if val.type_mod != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.type_mod)) + } + if val.collation != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.collation)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_coerce_to_domain_value(val CoerceToDomainValue) []u8 { + mut buf := []u8{} + encode_coerce_to_domain_value_into(mut buf, val) + return buf +} + +fn encode_set_to_default_into(mut buf []u8, val SetToDefault) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.type_id != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.type_id)) + } + if val.type_mod != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.type_mod)) + } + if val.collation != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.collation)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_set_to_default(val SetToDefault) []u8 { + mut buf := []u8{} + encode_set_to_default_into(mut buf, val) + return buf +} + +fn encode_current_of_expr_into(mut buf []u8, val CurrentOfExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cvarno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.cvarno)) + } + if val.cursor_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.cursor_name) + } + if val.cursor_param != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.cursor_param)) + } +} + +pub fn encode_current_of_expr(val CurrentOfExpr) []u8 { + mut buf := []u8{} + encode_current_of_expr_into(mut buf, val) + return buf +} + +fn encode_next_value_expr_into(mut buf []u8, val NextValueExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.seqid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.seqid)) + } + if val.type_id != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.type_id)) + } +} + +pub fn encode_next_value_expr(val NextValueExpr) []u8 { + mut buf := []u8{} + encode_next_value_expr_into(mut buf, val) + return buf +} + +fn encode_inference_elem_into(mut buf []u8, val InferenceElem) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.infercollid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.infercollid)) + } + if val.inferopclass != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.inferopclass)) + } +} + +pub fn encode_inference_elem(val InferenceElem) []u8 { + mut buf := []u8{} + encode_inference_elem_into(mut buf, val) + return buf +} + +fn encode_target_entry_into(mut buf []u8, val TargetEntry) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.resno != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.resno)) + } + if val.resname != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.resname) + } + if val.ressortgroupref != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.ressortgroupref)) + } + if val.resorigtbl != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.resorigtbl)) + } + if val.resorigcol != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.resorigcol)) + } + if val.resjunk { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.resjunk) + } +} + +pub fn encode_target_entry(val TargetEntry) []u8 { + mut buf := []u8{} + encode_target_entry_into(mut buf, val) + return buf +} + +fn encode_range_tbl_ref_into(mut buf []u8, val RangeTblRef) { + if val.rtindex != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.rtindex)) + } +} + +pub fn encode_range_tbl_ref(val RangeTblRef) []u8 { + mut buf := []u8{} + encode_range_tbl_ref_into(mut buf, val) + return buf +} + +fn encode_from_expr_into(mut buf []u8, val FromExpr) { + if val.fromlist.len > 0 { + for v in val.fromlist { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.quals) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_from_expr(val FromExpr) []u8 { + mut buf := []u8{} + encode_from_expr_into(mut buf, val) + return buf +} + +fn encode_on_conflict_expr_into(mut buf []u8, val OnConflictExpr) { + if u64(val.action) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.action)) + } + if val.arbiter_elems.len > 0 { + for v in val.arbiter_elems { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arbiter_where) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.constraint != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.constraint)) + } + if val.on_conflict_set.len > 0 { + for v in val.on_conflict_set { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.on_conflict_where) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.excl_rel_index != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.excl_rel_index)) + } + if val.excl_rel_tlist.len > 0 { + for v in val.excl_rel_tlist { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_on_conflict_expr(val OnConflictExpr) []u8 { + mut buf := []u8{} + encode_on_conflict_expr_into(mut buf, val) + return buf +} + +fn encode_type_name_into(mut buf []u8, val TypeName) { + if val.names.len > 0 { + for v in val.names { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.type_oid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.type_oid)) + } + if val.setof { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.setof) + } + if val.pct_type { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.pct_type) + } + if val.typmods.len > 0 { + for v in val.typmods { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.typemod != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.typemod)) + } + if val.array_bounds.len > 0 { + for v in val.array_bounds { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_type_name(val TypeName) []u8 { + mut buf := []u8{} + encode_type_name_into(mut buf, val) + return buf +} + +fn encode_column_ref_into(mut buf []u8, val ColumnRef) { + if val.fields.len > 0 { + for v in val.fields { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_column_ref(val ColumnRef) []u8 { + mut buf := []u8{} + encode_column_ref_into(mut buf, val) + return buf +} + +fn encode_param_ref_into(mut buf []u8, val ParamRef) { + if val.number != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.number)) + } + if val.location != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_param_ref(val ParamRef) []u8 { + mut buf := []u8{} + encode_param_ref_into(mut buf, val) + return buf +} + +fn encode_a_expr_into(mut buf []u8, val AExpr) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.name.len > 0 { + for v in val.name { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.lexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_a_expr(val AExpr) []u8 { + mut buf := []u8{} + encode_a_expr_into(mut buf, val) + return buf +} + +fn encode_collate_clause_into(mut buf []u8, val CollateClause) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.collname.len > 0 { + for v in val.collname { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_collate_clause(val CollateClause) []u8 { + mut buf := []u8{} + encode_collate_clause_into(mut buf, val) + return buf +} + +fn encode_role_spec_into(mut buf []u8, val RoleSpec) { + if u64(val.roletype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.roletype)) + } + if val.rolename != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.rolename) + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_role_spec(val RoleSpec) []u8 { + mut buf := []u8{} + encode_role_spec_into(mut buf, val) + return buf +} + +fn encode_a_star_into(mut buf []u8, val AStar) { +} + +pub fn encode_a_star(val AStar) []u8 { + mut buf := []u8{} + encode_a_star_into(mut buf, val) + return buf +} + +fn encode_a_indices_into(mut buf []u8, val AIndices) { + if val.is_slice { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.is_slice) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.lidx) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.uidx) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_a_indices(val AIndices) []u8 { + mut buf := []u8{} + encode_a_indices_into(mut buf, val) + return buf +} + +fn encode_a_indirection_into(mut buf []u8, val AIndirection) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.indirection.len > 0 { + for v in val.indirection { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_a_indirection(val AIndirection) []u8 { + mut buf := []u8{} + encode_a_indirection_into(mut buf, val) + return buf +} + +fn encode_a_array_expr_into(mut buf []u8, val AArrayExpr) { + if val.elements.len > 0 { + for v in val.elements { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_a_array_expr(val AArrayExpr) []u8 { + mut buf := []u8{} + encode_a_array_expr_into(mut buf, val) + return buf +} + +fn encode_res_target_into(mut buf []u8, val ResTarget) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.indirection.len > 0 { + for v in val.indirection { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.val) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_res_target(val ResTarget) []u8 { + mut buf := []u8{} + encode_res_target_into(mut buf, val) + return buf +} + +fn encode_multi_assign_ref_into(mut buf []u8, val MultiAssignRef) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.source) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.colno != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.colno)) + } + if val.ncolumns != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.ncolumns)) + } +} + +pub fn encode_multi_assign_ref(val MultiAssignRef) []u8 { + mut buf := []u8{} + encode_multi_assign_ref_into(mut buf, val) + return buf +} + +fn encode_sort_by_into(mut buf []u8, val SortBy) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.node) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.sortby_dir) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.sortby_dir)) + } + if u64(val.sortby_nulls) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.sortby_nulls)) + } + if val.use_op.len > 0 { + for v in val.use_op { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_sort_by(val SortBy) []u8 { + mut buf := []u8{} + encode_sort_by_into(mut buf, val) + return buf +} + +fn encode_window_def_into(mut buf []u8, val WindowDef) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.refname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.refname) + } + if val.partition_clause.len > 0 { + for v in val.partition_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.order_clause.len > 0 { + for v in val.order_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.frame_options != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.frame_options)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.start_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.end_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_window_def(val WindowDef) []u8 { + mut buf := []u8{} + encode_window_def_into(mut buf, val) + return buf +} + +fn encode_range_table_sample_into(mut buf []u8, val RangeTableSample) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.method.len > 0 { + for v in val.method { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.repeatable) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_range_table_sample(val RangeTableSample) []u8 { + mut buf := []u8{} + encode_range_table_sample_into(mut buf, val) + return buf +} + +fn encode_index_elem_into(mut buf []u8, val IndexElem) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.indexcolname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.indexcolname) + } + if val.collation.len > 0 { + for v in val.collation { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.opclass.len > 0 { + for v in val.opclass { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.opclassopts.len > 0 { + for v in val.opclassopts { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.ordering) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.ordering)) + } + if u64(val.nulls_ordering) != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.nulls_ordering)) + } +} + +pub fn encode_index_elem(val IndexElem) []u8 { + mut buf := []u8{} + encode_index_elem_into(mut buf, val) + return buf +} + +fn encode_def_elem_into(mut buf []u8, val DefElem) { + if val.defnamespace != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.defnamespace) + } + if val.defname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.defname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.defaction) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.defaction)) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_def_elem(val DefElem) []u8 { + mut buf := []u8{} + encode_def_elem_into(mut buf, val) + return buf +} + +fn encode_locking_clause_into(mut buf []u8, val LockingClause) { + if val.locked_rels.len > 0 { + for v in val.locked_rels { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.strength) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.strength)) + } + if u64(val.wait_policy) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.wait_policy)) + } +} + +pub fn encode_locking_clause(val LockingClause) []u8 { + mut buf := []u8{} + encode_locking_clause_into(mut buf, val) + return buf +} + +fn encode_partition_elem_into(mut buf []u8, val PartitionElem) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.collation.len > 0 { + for v in val.collation { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.opclass.len > 0 { + for v in val.opclass { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_partition_elem(val PartitionElem) []u8 { + mut buf := []u8{} + encode_partition_elem_into(mut buf, val) + return buf +} + +fn encode_partition_spec_into(mut buf []u8, val PartitionSpec) { + if u64(val.strategy) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.strategy)) + } + if val.part_params.len > 0 { + for v in val.part_params { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_partition_spec(val PartitionSpec) []u8 { + mut buf := []u8{} + encode_partition_spec_into(mut buf, val) + return buf +} + +fn encode_partition_bound_spec_into(mut buf []u8, val PartitionBoundSpec) { + if val.strategy != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.strategy) + } + if val.is_default { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.is_default) + } + if val.modulus != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.modulus)) + } + if val.remainder != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.remainder)) + } + if val.listdatums.len > 0 { + for v in val.listdatums { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.lowerdatums.len > 0 { + for v in val.lowerdatums { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.upperdatums.len > 0 { + for v in val.upperdatums { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_partition_bound_spec(val PartitionBoundSpec) []u8 { + mut buf := []u8{} + encode_partition_bound_spec_into(mut buf, val) + return buf +} + +fn encode_partition_range_datum_into(mut buf []u8, val PartitionRangeDatum) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.value) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_partition_range_datum(val PartitionRangeDatum) []u8 { + mut buf := []u8{} + encode_partition_range_datum_into(mut buf, val) + return buf +} + +fn encode_single_partition_spec_into(mut buf []u8, val SinglePartitionSpec) { +} + +pub fn encode_single_partition_spec(val SinglePartitionSpec) []u8 { + mut buf := []u8{} + encode_single_partition_spec_into(mut buf, val) + return buf +} + +fn encode_r_t_e_permission_info_into(mut buf []u8, val RTEPermissionInfo) { + if val.relid != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.relid)) + } + if val.inh { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.inh) + } + if val.required_perms != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, val.required_perms) + } + if val.check_as_user != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.check_as_user)) + } + if val.selected_cols.len > 0 { + mut packed_ := []u8{} + for v in val.selected_cols { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 5, 2) + write_length_delimited_into(mut buf, packed_) + } + if val.inserted_cols.len > 0 { + mut packed_ := []u8{} + for v in val.inserted_cols { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 6, 2) + write_length_delimited_into(mut buf, packed_) + } + if val.updated_cols.len > 0 { + mut packed_ := []u8{} + for v in val.updated_cols { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 7, 2) + write_length_delimited_into(mut buf, packed_) + } +} + +pub fn encode_r_t_e_permission_info(val RTEPermissionInfo) []u8 { + mut buf := []u8{} + encode_r_t_e_permission_info_into(mut buf, val) + return buf +} + +fn encode_range_tbl_function_into(mut buf []u8, val RangeTblFunction) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.funcexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.funccolcount != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.funccolcount)) + } + if val.funccolnames.len > 0 { + for v in val.funccolnames { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funccoltypes.len > 0 { + for v in val.funccoltypes { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funccoltypmods.len > 0 { + for v in val.funccoltypmods { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funccolcollations.len > 0 { + for v in val.funccolcollations { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funcparams.len > 0 { + mut packed_ := []u8{} + for v in val.funcparams { + write_varint_into(mut packed_, v) + } + write_tag_into(mut buf, 7, 2) + write_length_delimited_into(mut buf, packed_) + } +} + +pub fn encode_range_tbl_function(val RangeTblFunction) []u8 { + mut buf := []u8{} + encode_range_tbl_function_into(mut buf, val) + return buf +} + +fn encode_table_sample_clause_into(mut buf []u8, val TableSampleClause) { + if val.tsmhandler != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.tsmhandler)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.repeatable) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_table_sample_clause(val TableSampleClause) []u8 { + mut buf := []u8{} + encode_table_sample_clause_into(mut buf, val) + return buf +} + +fn encode_with_check_option_into(mut buf []u8, val WithCheckOption) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.relname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.relname) + } + if val.polname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.polname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.qual) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cascaded { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.cascaded) + } +} + +pub fn encode_with_check_option(val WithCheckOption) []u8 { + mut buf := []u8{} + encode_with_check_option_into(mut buf, val) + return buf +} + +fn encode_sort_group_clause_into(mut buf []u8, val SortGroupClause) { + if val.tle_sort_group_ref != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.tle_sort_group_ref)) + } + if val.eqop != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.eqop)) + } + if val.sortop != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.sortop)) + } + if val.nulls_first { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.nulls_first) + } + if val.hashable { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.hashable) + } +} + +pub fn encode_sort_group_clause(val SortGroupClause) []u8 { + mut buf := []u8{} + encode_sort_group_clause_into(mut buf, val) + return buf +} + +fn encode_grouping_set_into(mut buf []u8, val GroupingSet) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.content.len > 0 { + for v in val.content { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_grouping_set(val GroupingSet) []u8 { + mut buf := []u8{} + encode_grouping_set_into(mut buf, val) + return buf +} + +fn encode_window_clause_into(mut buf []u8, val WindowClause) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.refname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.refname) + } + if val.partition_clause.len > 0 { + for v in val.partition_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.order_clause.len > 0 { + for v in val.order_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.frame_options != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.frame_options)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.start_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.end_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.start_in_range_func != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.start_in_range_func)) + } + if val.end_in_range_func != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.end_in_range_func)) + } + if val.in_range_coll != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.in_range_coll)) + } + if val.in_range_asc { + write_tag_into(mut buf, 11, 0) + write_bool_into(mut buf, val.in_range_asc) + } + if val.in_range_nulls_first { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.in_range_nulls_first) + } + if val.winref != 0 { + write_tag_into(mut buf, 13, 0) + write_varint_into(mut buf, u64(val.winref)) + } + if val.copied_order { + write_tag_into(mut buf, 14, 0) + write_bool_into(mut buf, val.copied_order) + } +} + +pub fn encode_window_clause(val WindowClause) []u8 { + mut buf := []u8{} + encode_window_clause_into(mut buf, val) + return buf +} + +fn encode_row_mark_clause_into(mut buf []u8, val RowMarkClause) { + if val.rti != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.rti)) + } + if u64(val.strength) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.strength)) + } + if u64(val.wait_policy) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.wait_policy)) + } + if val.pushed_down { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.pushed_down) + } +} + +pub fn encode_row_mark_clause(val RowMarkClause) []u8 { + mut buf := []u8{} + encode_row_mark_clause_into(mut buf, val) + return buf +} + +fn encode_with_clause_into(mut buf []u8, val WithClause) { + if val.ctes.len > 0 { + for v in val.ctes { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.recursive { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.recursive) + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_with_clause(val WithClause) []u8 { + mut buf := []u8{} + encode_with_clause_into(mut buf, val) + return buf +} + +fn encode_infer_clause_into(mut buf []u8, val InferClause) { + if val.index_elems.len > 0 { + for v in val.index_elems { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.conname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.conname) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_infer_clause(val InferClause) []u8 { + mut buf := []u8{} + encode_infer_clause_into(mut buf, val) + return buf +} + +fn encode_c_t_e_search_clause_into(mut buf []u8, val CTESearchClause) { + if val.search_col_list.len > 0 { + for v in val.search_col_list { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.search_breadth_first { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.search_breadth_first) + } + if val.search_seq_column != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.search_seq_column) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_c_t_e_search_clause(val CTESearchClause) []u8 { + mut buf := []u8{} + encode_c_t_e_search_clause_into(mut buf, val) + return buf +} + +fn encode_c_t_e_cycle_clause_into(mut buf []u8, val CTECycleClause) { + if val.cycle_col_list.len > 0 { + for v in val.cycle_col_list { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.cycle_mark_column != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.cycle_mark_column) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.cycle_mark_value) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.cycle_mark_default) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cycle_path_column != '' { + write_tag_into(mut buf, 5, 2) + write_string_into(mut buf, val.cycle_path_column) + } + if val.location != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.location)) + } + if val.cycle_mark_type != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.cycle_mark_type)) + } + if val.cycle_mark_typmod != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.cycle_mark_typmod)) + } + if val.cycle_mark_collation != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.cycle_mark_collation)) + } + if val.cycle_mark_neop != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.cycle_mark_neop)) + } +} + +pub fn encode_c_t_e_cycle_clause(val CTECycleClause) []u8 { + mut buf := []u8{} + encode_c_t_e_cycle_clause_into(mut buf, val) + return buf +} + +fn encode_merge_when_clause_into(mut buf []u8, val MergeWhenClause) { + if u64(val.match_kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.match_kind)) + } + if u64(val.command_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.command_type)) + } + if u64(val.override) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.override)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.condition) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.values.len > 0 { + for v in val.values { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_merge_when_clause(val MergeWhenClause) []u8 { + mut buf := []u8{} + encode_merge_when_clause_into(mut buf, val) + return buf +} + +fn encode_trigger_transition_into(mut buf []u8, val TriggerTransition) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.is_new { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.is_new) + } + if val.is_table { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_table) + } +} + +pub fn encode_trigger_transition(val TriggerTransition) []u8 { + mut buf := []u8{} + encode_trigger_transition_into(mut buf, val) + return buf +} + +fn encode_json_table_path_spec_into(mut buf []u8, val JsonTablePathSpec) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.string) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } + if val.name_location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.name_location)) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_table_path_spec(val JsonTablePathSpec) []u8 { + mut buf := []u8{} + encode_json_table_path_spec_into(mut buf, val) + return buf +} + +fn encode_raw_stmt_into(mut buf []u8, val RawStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.stmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.stmt_location != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.stmt_location)) + } + if val.stmt_len != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.stmt_len)) + } +} + +pub fn encode_raw_stmt(val RawStmt) []u8 { + mut buf := []u8{} + encode_raw_stmt_into(mut buf, val) + return buf +} + +fn encode_set_operation_stmt_into(mut buf []u8, val SetOperationStmt) { + if u64(val.op) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.all { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.all) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.larg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rarg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.col_types.len > 0 { + for v in val.col_types { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.col_typmods.len > 0 { + for v in val.col_typmods { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.col_collations.len > 0 { + for v in val.col_collations { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.group_clauses.len > 0 { + for v in val.group_clauses { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_set_operation_stmt(val SetOperationStmt) []u8 { + mut buf := []u8{} + encode_set_operation_stmt_into(mut buf, val) + return buf +} + +fn encode_return_stmt_into(mut buf []u8, val ReturnStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.returnval) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_return_stmt(val ReturnStmt) []u8 { + mut buf := []u8{} + encode_return_stmt_into(mut buf, val) + return buf +} + +fn encode_replica_identity_stmt_into(mut buf []u8, val ReplicaIdentityStmt) { + if val.identity_type != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.identity_type) + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } +} + +pub fn encode_replica_identity_stmt(val ReplicaIdentityStmt) []u8 { + mut buf := []u8{} + encode_replica_identity_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_collation_stmt_into(mut buf []u8, val AlterCollationStmt) { + if val.collname.len > 0 { + for v in val.collname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_collation_stmt(val AlterCollationStmt) []u8 { + mut buf := []u8{} + encode_alter_collation_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_domain_stmt_into(mut buf []u8, val AlterDomainStmt) { + if val.subtype != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.subtype) + } + if val.type_name.len > 0 { + for v in val.type_name { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.def) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.behavior)) + } + if val.missing_ok { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_domain_stmt(val AlterDomainStmt) []u8 { + mut buf := []u8{} + encode_alter_domain_stmt_into(mut buf, val) + return buf +} + +fn encode_object_with_args_into(mut buf []u8, val ObjectWithArgs) { + if val.objname.len > 0 { + for v in val.objname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.objargs.len > 0 { + for v in val.objargs { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.objfuncargs.len > 0 { + for v in val.objfuncargs { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args_unspecified { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.args_unspecified) + } +} + +pub fn encode_object_with_args(val ObjectWithArgs) []u8 { + mut buf := []u8{} + encode_object_with_args_into(mut buf, val) + return buf +} + +fn encode_access_priv_into(mut buf []u8, val AccessPriv) { + if val.priv_name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.priv_name) + } + if val.cols.len > 0 { + for v in val.cols { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_access_priv(val AccessPriv) []u8 { + mut buf := []u8{} + encode_access_priv_into(mut buf, val) + return buf +} + +fn encode_variable_set_stmt_into(mut buf []u8, val VariableSetStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_local { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.is_local) + } +} + +pub fn encode_variable_set_stmt(val VariableSetStmt) []u8 { + mut buf := []u8{} + encode_variable_set_stmt_into(mut buf, val) + return buf +} + +fn encode_variable_show_stmt_into(mut buf []u8, val VariableShowStmt) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } +} + +pub fn encode_variable_show_stmt(val VariableShowStmt) []u8 { + mut buf := []u8{} + encode_variable_show_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_table_space_stmt_into(mut buf []u8, val DropTableSpaceStmt) { + if val.tablespacename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.tablespacename) + } + if val.missing_ok { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_drop_table_space_stmt(val DropTableSpaceStmt) []u8 { + mut buf := []u8{} + encode_drop_table_space_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_table_space_options_stmt_into(mut buf []u8, val AlterTableSpaceOptionsStmt) { + if val.tablespacename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.tablespacename) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_reset { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_reset) + } +} + +pub fn encode_alter_table_space_options_stmt(val AlterTableSpaceOptionsStmt) []u8 { + mut buf := []u8{} + encode_alter_table_space_options_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_table_move_all_stmt_into(mut buf []u8, val AlterTableMoveAllStmt) { + if val.orig_tablespacename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.orig_tablespacename) + } + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.new_tablespacename != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.new_tablespacename) + } + if val.nowait { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.nowait) + } +} + +pub fn encode_alter_table_move_all_stmt(val AlterTableMoveAllStmt) []u8 { + mut buf := []u8{} + encode_alter_table_move_all_stmt_into(mut buf, val) + return buf +} + +fn encode_create_extension_stmt_into(mut buf []u8, val CreateExtensionStmt) { + if val.extname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.extname) + } + if val.if_not_exists { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.if_not_exists) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_extension_stmt(val CreateExtensionStmt) []u8 { + mut buf := []u8{} + encode_create_extension_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_extension_stmt_into(mut buf []u8, val AlterExtensionStmt) { + if val.extname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.extname) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_extension_stmt(val AlterExtensionStmt) []u8 { + mut buf := []u8{} + encode_alter_extension_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_extension_contents_stmt_into(mut buf []u8, val AlterExtensionContentsStmt) { + if val.extname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.extname) + } + if val.action != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.action)) + } + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_extension_contents_stmt(val AlterExtensionContentsStmt) []u8 { + mut buf := []u8{} + encode_alter_extension_contents_stmt_into(mut buf, val) + return buf +} + +fn encode_create_fdw_stmt_into(mut buf []u8, val CreateFdwStmt) { + if val.fdwname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.fdwname) + } + if val.func_options.len > 0 { + for v in val.func_options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_fdw_stmt(val CreateFdwStmt) []u8 { + mut buf := []u8{} + encode_create_fdw_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_fdw_stmt_into(mut buf []u8, val AlterFdwStmt) { + if val.fdwname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.fdwname) + } + if val.func_options.len > 0 { + for v in val.func_options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_fdw_stmt(val AlterFdwStmt) []u8 { + mut buf := []u8{} + encode_alter_fdw_stmt_into(mut buf, val) + return buf +} + +fn encode_create_foreign_server_stmt_into(mut buf []u8, val CreateForeignServerStmt) { + if val.servername != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.servername) + } + if val.servertype != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.servertype) + } + if val.version != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.version) + } + if val.fdwname != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.fdwname) + } + if val.if_not_exists { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.if_not_exists) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_foreign_server_stmt(val CreateForeignServerStmt) []u8 { + mut buf := []u8{} + encode_create_foreign_server_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_foreign_server_stmt_into(mut buf []u8, val AlterForeignServerStmt) { + if val.servername != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.servername) + } + if val.version != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.version) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.has_version { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.has_version) + } +} + +pub fn encode_alter_foreign_server_stmt(val AlterForeignServerStmt) []u8 { + mut buf := []u8{} + encode_alter_foreign_server_stmt_into(mut buf, val) + return buf +} + +fn encode_import_foreign_schema_stmt_into(mut buf []u8, val ImportForeignSchemaStmt) { + if val.server_name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.server_name) + } + if val.remote_schema != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.remote_schema) + } + if val.local_schema != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.local_schema) + } + if u64(val.list_type) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.list_type)) + } + if val.table_list.len > 0 { + for v in val.table_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_import_foreign_schema_stmt(val ImportForeignSchemaStmt) []u8 { + mut buf := []u8{} + encode_import_foreign_schema_stmt_into(mut buf, val) + return buf +} + +fn encode_create_am_stmt_into(mut buf []u8, val CreateAmStmt) { + if val.amname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.amname) + } + if val.handler_name.len > 0 { + for v in val.handler_name { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.amtype != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.amtype) + } +} + +pub fn encode_create_am_stmt(val CreateAmStmt) []u8 { + mut buf := []u8{} + encode_create_am_stmt_into(mut buf, val) + return buf +} + +fn encode_create_event_trig_stmt_into(mut buf []u8, val CreateEventTrigStmt) { + if val.trigname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.trigname) + } + if val.eventname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.eventname) + } + if val.whenclause.len > 0 { + for v in val.whenclause { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funcname.len > 0 { + for v in val.funcname { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_event_trig_stmt(val CreateEventTrigStmt) []u8 { + mut buf := []u8{} + encode_create_event_trig_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_event_trig_stmt_into(mut buf []u8, val AlterEventTrigStmt) { + if val.trigname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.trigname) + } + if val.tgenabled != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.tgenabled) + } +} + +pub fn encode_alter_event_trig_stmt(val AlterEventTrigStmt) []u8 { + mut buf := []u8{} + encode_alter_event_trig_stmt_into(mut buf, val) + return buf +} + +fn encode_create_p_lang_stmt_into(mut buf []u8, val CreatePLangStmt) { + if val.replace { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.replace) + } + if val.plname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.plname) + } + if val.plhandler.len > 0 { + for v in val.plhandler { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.plinline.len > 0 { + for v in val.plinline { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.plvalidator.len > 0 { + for v in val.plvalidator { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.pltrusted { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.pltrusted) + } +} + +pub fn encode_create_p_lang_stmt(val CreatePLangStmt) []u8 { + mut buf := []u8{} + encode_create_p_lang_stmt_into(mut buf, val) + return buf +} + +fn encode_create_role_stmt_into(mut buf []u8, val CreateRoleStmt) { + if u64(val.stmt_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.stmt_type)) + } + if val.role != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.role) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_role_stmt(val CreateRoleStmt) []u8 { + mut buf := []u8{} + encode_create_role_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_role_stmt_into(mut buf []u8, val DropRoleStmt) { + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.missing_ok { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_drop_role_stmt(val DropRoleStmt) []u8 { + mut buf := []u8{} + encode_drop_role_stmt_into(mut buf, val) + return buf +} + +fn encode_define_stmt_into(mut buf []u8, val DefineStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.oldstyle { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.oldstyle) + } + if val.defnames.len > 0 { + for v in val.defnames { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.definition.len > 0 { + for v in val.definition { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.if_not_exists { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.if_not_exists) + } + if val.replace { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.replace) + } +} + +pub fn encode_define_stmt(val DefineStmt) []u8 { + mut buf := []u8{} + encode_define_stmt_into(mut buf, val) + return buf +} + +fn encode_create_op_family_stmt_into(mut buf []u8, val CreateOpFamilyStmt) { + if val.opfamilyname.len > 0 { + for v in val.opfamilyname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.amname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.amname) + } +} + +pub fn encode_create_op_family_stmt(val CreateOpFamilyStmt) []u8 { + mut buf := []u8{} + encode_create_op_family_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_op_family_stmt_into(mut buf []u8, val AlterOpFamilyStmt) { + if val.opfamilyname.len > 0 { + for v in val.opfamilyname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.amname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.amname) + } + if val.is_drop { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_drop) + } + if val.items.len > 0 { + for v in val.items { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_op_family_stmt(val AlterOpFamilyStmt) []u8 { + mut buf := []u8{} + encode_alter_op_family_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_stmt_into(mut buf []u8, val DropStmt) { + if val.objects.len > 0 { + for v in val.objects { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.remove_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.remove_type)) + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.behavior)) + } + if val.missing_ok { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.missing_ok) + } + if val.concurrent { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.concurrent) + } +} + +pub fn encode_drop_stmt(val DropStmt) []u8 { + mut buf := []u8{} + encode_drop_stmt_into(mut buf, val) + return buf +} + +fn encode_truncate_stmt_into(mut buf []u8, val TruncateStmt) { + if val.relations.len > 0 { + for v in val.relations { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.restart_seqs { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.restart_seqs) + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.behavior)) + } +} + +pub fn encode_truncate_stmt(val TruncateStmt) []u8 { + mut buf := []u8{} + encode_truncate_stmt_into(mut buf, val) + return buf +} + +fn encode_comment_stmt_into(mut buf []u8, val CommentStmt) { + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.comment != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.comment) + } +} + +pub fn encode_comment_stmt(val CommentStmt) []u8 { + mut buf := []u8{} + encode_comment_stmt_into(mut buf, val) + return buf +} + +fn encode_sec_label_stmt_into(mut buf []u8, val SecLabelStmt) { + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.provider != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.provider) + } + if val.label != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.label) + } +} + +pub fn encode_sec_label_stmt(val SecLabelStmt) []u8 { + mut buf := []u8{} + encode_sec_label_stmt_into(mut buf, val) + return buf +} + +fn encode_declare_cursor_stmt_into(mut buf []u8, val DeclareCursorStmt) { + if val.portalname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.portalname) + } + if val.options != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.options)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_declare_cursor_stmt(val DeclareCursorStmt) []u8 { + mut buf := []u8{} + encode_declare_cursor_stmt_into(mut buf, val) + return buf +} + +fn encode_close_portal_stmt_into(mut buf []u8, val ClosePortalStmt) { + if val.portalname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.portalname) + } +} + +pub fn encode_close_portal_stmt(val ClosePortalStmt) []u8 { + mut buf := []u8{} + encode_close_portal_stmt_into(mut buf, val) + return buf +} + +fn encode_fetch_stmt_into(mut buf []u8, val FetchStmt) { + if u64(val.direction) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.direction)) + } + if val.how_many != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.how_many)) + } + if val.portalname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.portalname) + } + if val.ismove { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.ismove) + } +} + +pub fn encode_fetch_stmt(val FetchStmt) []u8 { + mut buf := []u8{} + encode_fetch_stmt_into(mut buf, val) + return buf +} + +fn encode_create_stats_stmt_into(mut buf []u8, val CreateStatsStmt) { + if val.defnames.len > 0 { + for v in val.defnames { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.stat_types.len > 0 { + for v in val.stat_types { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.exprs.len > 0 { + for v in val.exprs { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.relations.len > 0 { + for v in val.relations { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.stxcomment != '' { + write_tag_into(mut buf, 5, 2) + write_string_into(mut buf, val.stxcomment) + } + if val.transformed { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.transformed) + } + if val.if_not_exists { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.if_not_exists) + } +} + +pub fn encode_create_stats_stmt(val CreateStatsStmt) []u8 { + mut buf := []u8{} + encode_create_stats_stmt_into(mut buf, val) + return buf +} + +fn encode_stats_elem_into(mut buf []u8, val StatsElem) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_stats_elem(val StatsElem) []u8 { + mut buf := []u8{} + encode_stats_elem_into(mut buf, val) + return buf +} + +fn encode_alter_stats_stmt_into(mut buf []u8, val AlterStatsStmt) { + if val.defnames.len > 0 { + for v in val.defnames { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.stxstattarget) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.missing_ok { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_stats_stmt(val AlterStatsStmt) []u8 { + mut buf := []u8{} + encode_alter_stats_stmt_into(mut buf, val) + return buf +} + +fn encode_do_stmt_into(mut buf []u8, val DoStmt) { + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_do_stmt(val DoStmt) []u8 { + mut buf := []u8{} + encode_do_stmt_into(mut buf, val) + return buf +} + +fn encode_inline_code_block_into(mut buf []u8, val InlineCodeBlock) { + if val.source_text != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.source_text) + } + if val.lang_oid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.lang_oid)) + } + if val.lang_is_trusted { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.lang_is_trusted) + } + if val.atomic { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.atomic) + } +} + +pub fn encode_inline_code_block(val InlineCodeBlock) []u8 { + mut buf := []u8{} + encode_inline_code_block_into(mut buf, val) + return buf +} + +fn encode_call_context_into(mut buf []u8, val CallContext) { + if val.atomic { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.atomic) + } +} + +pub fn encode_call_context(val CallContext) []u8 { + mut buf := []u8{} + encode_call_context_into(mut buf, val) + return buf +} + +fn encode_alter_type_stmt_into(mut buf []u8, val AlterTypeStmt) { + if val.type_name.len > 0 { + for v in val.type_name { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_type_stmt(val AlterTypeStmt) []u8 { + mut buf := []u8{} + encode_alter_type_stmt_into(mut buf, val) + return buf +} + +fn encode_notify_stmt_into(mut buf []u8, val NotifyStmt) { + if val.conditionname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.conditionname) + } + if val.payload != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.payload) + } +} + +pub fn encode_notify_stmt(val NotifyStmt) []u8 { + mut buf := []u8{} + encode_notify_stmt_into(mut buf, val) + return buf +} + +fn encode_listen_stmt_into(mut buf []u8, val ListenStmt) { + if val.conditionname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.conditionname) + } +} + +pub fn encode_listen_stmt(val ListenStmt) []u8 { + mut buf := []u8{} + encode_listen_stmt_into(mut buf, val) + return buf +} + +fn encode_unlisten_stmt_into(mut buf []u8, val UnlistenStmt) { + if val.conditionname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.conditionname) + } +} + +pub fn encode_unlisten_stmt(val UnlistenStmt) []u8 { + mut buf := []u8{} + encode_unlisten_stmt_into(mut buf, val) + return buf +} + +fn encode_transaction_stmt_into(mut buf []u8, val TransactionStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.savepoint_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.savepoint_name) + } + if val.gid != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.gid) + } + if val.chain { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.chain) + } + if val.location != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_transaction_stmt(val TransactionStmt) []u8 { + mut buf := []u8{} + encode_transaction_stmt_into(mut buf, val) + return buf +} + +fn encode_create_enum_stmt_into(mut buf []u8, val CreateEnumStmt) { + if val.type_name.len > 0 { + for v in val.type_name { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.vals.len > 0 { + for v in val.vals { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_enum_stmt(val CreateEnumStmt) []u8 { + mut buf := []u8{} + encode_create_enum_stmt_into(mut buf, val) + return buf +} + +fn encode_create_range_stmt_into(mut buf []u8, val CreateRangeStmt) { + if val.type_name.len > 0 { + for v in val.type_name { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.params.len > 0 { + for v in val.params { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_range_stmt(val CreateRangeStmt) []u8 { + mut buf := []u8{} + encode_create_range_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_enum_stmt_into(mut buf []u8, val AlterEnumStmt) { + if val.type_name.len > 0 { + for v in val.type_name { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.old_val != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.old_val) + } + if val.new_val != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.new_val) + } + if val.new_val_neighbor != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.new_val_neighbor) + } + if val.new_val_is_after { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.new_val_is_after) + } + if val.skip_if_new_val_exists { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.skip_if_new_val_exists) + } +} + +pub fn encode_alter_enum_stmt(val AlterEnumStmt) []u8 { + mut buf := []u8{} + encode_alter_enum_stmt_into(mut buf, val) + return buf +} + +fn encode_load_stmt_into(mut buf []u8, val LoadStmt) { + if val.filename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.filename) + } +} + +pub fn encode_load_stmt(val LoadStmt) []u8 { + mut buf := []u8{} + encode_load_stmt_into(mut buf, val) + return buf +} + +fn encode_createdb_stmt_into(mut buf []u8, val CreatedbStmt) { + if val.dbname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.dbname) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_createdb_stmt(val CreatedbStmt) []u8 { + mut buf := []u8{} + encode_createdb_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_database_stmt_into(mut buf []u8, val AlterDatabaseStmt) { + if val.dbname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.dbname) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_database_stmt(val AlterDatabaseStmt) []u8 { + mut buf := []u8{} + encode_alter_database_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_database_refresh_coll_stmt_into(mut buf []u8, val AlterDatabaseRefreshCollStmt) { + if val.dbname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.dbname) + } +} + +pub fn encode_alter_database_refresh_coll_stmt(val AlterDatabaseRefreshCollStmt) []u8 { + mut buf := []u8{} + encode_alter_database_refresh_coll_stmt_into(mut buf, val) + return buf +} + +fn encode_dropdb_stmt_into(mut buf []u8, val DropdbStmt) { + if val.dbname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.dbname) + } + if val.missing_ok { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.missing_ok) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_dropdb_stmt(val DropdbStmt) []u8 { + mut buf := []u8{} + encode_dropdb_stmt_into(mut buf, val) + return buf +} + +fn encode_vacuum_stmt_into(mut buf []u8, val VacuumStmt) { + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.rels.len > 0 { + for v in val.rels { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_vacuumcmd { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_vacuumcmd) + } +} + +pub fn encode_vacuum_stmt(val VacuumStmt) []u8 { + mut buf := []u8{} + encode_vacuum_stmt_into(mut buf, val) + return buf +} + +fn encode_explain_stmt_into(mut buf []u8, val ExplainStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_explain_stmt(val ExplainStmt) []u8 { + mut buf := []u8{} + encode_explain_stmt_into(mut buf, val) + return buf +} + +fn encode_check_point_stmt_into(mut buf []u8, val CheckPointStmt) { +} + +pub fn encode_check_point_stmt(val CheckPointStmt) []u8 { + mut buf := []u8{} + encode_check_point_stmt_into(mut buf, val) + return buf +} + +fn encode_discard_stmt_into(mut buf []u8, val DiscardStmt) { + if u64(val.target) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.target)) + } +} + +pub fn encode_discard_stmt(val DiscardStmt) []u8 { + mut buf := []u8{} + encode_discard_stmt_into(mut buf, val) + return buf +} + +fn encode_lock_stmt_into(mut buf []u8, val LockStmt) { + if val.relations.len > 0 { + for v in val.relations { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.mode != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.mode)) + } + if val.nowait { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.nowait) + } +} + +pub fn encode_lock_stmt(val LockStmt) []u8 { + mut buf := []u8{} + encode_lock_stmt_into(mut buf, val) + return buf +} + +fn encode_constraints_set_stmt_into(mut buf []u8, val ConstraintsSetStmt) { + if val.constraints.len > 0 { + for v in val.constraints { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.deferred { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.deferred) + } +} + +pub fn encode_constraints_set_stmt(val ConstraintsSetStmt) []u8 { + mut buf := []u8{} + encode_constraints_set_stmt_into(mut buf, val) + return buf +} + +fn encode_create_conversion_stmt_into(mut buf []u8, val CreateConversionStmt) { + if val.conversion_name.len > 0 { + for v in val.conversion_name { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.for_encoding_name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.for_encoding_name) + } + if val.to_encoding_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.to_encoding_name) + } + if val.func_name.len > 0 { + for v in val.func_name { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.def { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.def) + } +} + +pub fn encode_create_conversion_stmt(val CreateConversionStmt) []u8 { + mut buf := []u8{} + encode_create_conversion_stmt_into(mut buf, val) + return buf +} + +fn encode_prepare_stmt_into(mut buf []u8, val PrepareStmt) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.argtypes.len > 0 { + for v in val.argtypes { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_prepare_stmt(val PrepareStmt) []u8 { + mut buf := []u8{} + encode_prepare_stmt_into(mut buf, val) + return buf +} + +fn encode_execute_stmt_into(mut buf []u8, val ExecuteStmt) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.params.len > 0 { + for v in val.params { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_execute_stmt(val ExecuteStmt) []u8 { + mut buf := []u8{} + encode_execute_stmt_into(mut buf, val) + return buf +} + +fn encode_deallocate_stmt_into(mut buf []u8, val DeallocateStmt) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.isall { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.isall) + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_deallocate_stmt(val DeallocateStmt) []u8 { + mut buf := []u8{} + encode_deallocate_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_owned_stmt_into(mut buf []u8, val DropOwnedStmt) { + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.behavior)) + } +} + +pub fn encode_drop_owned_stmt(val DropOwnedStmt) []u8 { + mut buf := []u8{} + encode_drop_owned_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_t_s_dictionary_stmt_into(mut buf []u8, val AlterTSDictionaryStmt) { + if val.dictname.len > 0 { + for v in val.dictname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_t_s_dictionary_stmt(val AlterTSDictionaryStmt) []u8 { + mut buf := []u8{} + encode_alter_t_s_dictionary_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_t_s_configuration_stmt_into(mut buf []u8, val AlterTSConfigurationStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.cfgname.len > 0 { + for v in val.cfgname { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.tokentype.len > 0 { + for v in val.tokentype { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.dicts.len > 0 { + for v in val.dicts { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.override { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.override) + } + if val.replace { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.replace) + } + if val.missing_ok { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_t_s_configuration_stmt(val AlterTSConfigurationStmt) []u8 { + mut buf := []u8{} + encode_alter_t_s_configuration_stmt_into(mut buf, val) + return buf +} + +fn encode_create_publication_stmt_into(mut buf []u8, val CreatePublicationStmt) { + if val.pubname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.pubname) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.pubobjects.len > 0 { + for v in val.pubobjects { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.for_all_tables { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.for_all_tables) + } +} + +pub fn encode_create_publication_stmt(val CreatePublicationStmt) []u8 { + mut buf := []u8{} + encode_create_publication_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_publication_stmt_into(mut buf []u8, val AlterPublicationStmt) { + if val.pubname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.pubname) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.pubobjects.len > 0 { + for v in val.pubobjects { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.for_all_tables { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.for_all_tables) + } + if u64(val.action) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.action)) + } +} + +pub fn encode_alter_publication_stmt(val AlterPublicationStmt) []u8 { + mut buf := []u8{} + encode_alter_publication_stmt_into(mut buf, val) + return buf +} + +fn encode_create_subscription_stmt_into(mut buf []u8, val CreateSubscriptionStmt) { + if val.subname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.subname) + } + if val.conninfo != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.conninfo) + } + if val.publication.len > 0 { + for v in val.publication { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_subscription_stmt(val CreateSubscriptionStmt) []u8 { + mut buf := []u8{} + encode_create_subscription_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_subscription_stmt_into(mut buf []u8, val AlterSubscriptionStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + if val.subname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.subname) + } + if val.conninfo != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.conninfo) + } + if val.publication.len > 0 { + for v in val.publication { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_subscription_stmt(val AlterSubscriptionStmt) []u8 { + mut buf := []u8{} + encode_alter_subscription_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_subscription_stmt_into(mut buf []u8, val DropSubscriptionStmt) { + if val.subname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.subname) + } + if val.missing_ok { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.missing_ok) + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.behavior)) + } +} + +pub fn encode_drop_subscription_stmt(val DropSubscriptionStmt) []u8 { + mut buf := []u8{} + encode_drop_subscription_stmt_into(mut buf, val) + return buf +} + +fn encode_scan_token_into(mut buf []u8, val ScanToken) { + if val.start != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.start)) + } + if val.end != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.end)) + } + if u64(val.token) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.token)) + } + if u64(val.keyword_kind) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.keyword_kind)) + } +} + +pub fn encode_scan_token(val ScanToken) []u8 { + mut buf := []u8{} + encode_scan_token_into(mut buf, val) + return buf +} + +fn encode_summary_result_table_into(mut buf []u8, val SummaryResultTable) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.schema_name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.schema_name) + } + if val.table_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.table_name) + } + if u64(val.context) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.context)) + } +} + +pub fn encode_summary_result_table(val SummaryResultTable) []u8 { + mut buf := []u8{} + encode_summary_result_table_into(mut buf, val) + return buf +} + +fn encode_summary_result_function_into(mut buf []u8, val SummaryResultFunction) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.function_name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.function_name) + } + if val.schema_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.schema_name) + } + if u64(val.context) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.context)) + } +} + +pub fn encode_summary_result_function(val SummaryResultFunction) []u8 { + mut buf := []u8{} + encode_summary_result_function_into(mut buf, val) + return buf +} + +fn encode_summary_result_filter_column_into(mut buf []u8, val SummaryResultFilterColumn) { + if val.schema_name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.schema_name) + } + if val.table_name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.table_name) + } + if val.column != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.column) + } +} + +pub fn encode_summary_result_filter_column(val SummaryResultFilterColumn) []u8 { + mut buf := []u8{} + encode_summary_result_filter_column_into(mut buf, val) + return buf +} + +fn encode_range_var_into(mut buf []u8, val RangeVar) { + if val.catalogname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.catalogname) + } + if val.schemaname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.schemaname) + } + if val.relname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.relname) + } + if val.inh { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.inh) + } + if val.relpersistence != '' { + write_tag_into(mut buf, 5, 2) + write_string_into(mut buf, val.relpersistence) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_range_var(val RangeVar) []u8 { + mut buf := []u8{} + encode_range_var_into(mut buf, val) + return buf +} + +fn encode_join_expr_into(mut buf []u8, val JoinExpr) { + if u64(val.jointype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.jointype)) + } + if val.is_natural { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.is_natural) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.larg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rarg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.using_clause.len > 0 { + for v in val.using_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.join_using_alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.quals) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.rtindex != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.rtindex)) + } +} + +pub fn encode_join_expr(val JoinExpr) []u8 { + mut buf := []u8{} + encode_join_expr_into(mut buf, val) + return buf +} + +fn encode_range_subselect_into(mut buf []u8, val RangeSubselect) { + if val.lateral { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.lateral) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.subquery) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_range_subselect(val RangeSubselect) []u8 { + mut buf := []u8{} + encode_range_subselect_into(mut buf, val) + return buf +} + +fn encode_range_function_into(mut buf []u8, val RangeFunction) { + if val.lateral { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.lateral) + } + if val.ordinality { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.ordinality) + } + if val.is_rowsfrom { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_rowsfrom) + } + if val.functions.len > 0 { + for v in val.functions { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coldeflist.len > 0 { + for v in val.coldeflist { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_range_function(val RangeFunction) []u8 { + mut buf := []u8{} + encode_range_function_into(mut buf, val) + return buf +} + +fn encode_range_table_func_into(mut buf []u8, val RangeTableFunc) { + if val.lateral { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.lateral) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.docexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.rowexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.namespaces.len > 0 { + for v in val.namespaces { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.columns.len > 0 { + for v in val.columns { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_range_table_func(val RangeTableFunc) []u8 { + mut buf := []u8{} + encode_range_table_func_into(mut buf, val) + return buf +} + +fn encode_json_returning_into(mut buf []u8, val JsonReturning) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.typid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.typid)) + } + if val.typmod != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.typmod)) + } +} + +pub fn encode_json_returning(val JsonReturning) []u8 { + mut buf := []u8{} + encode_json_returning_into(mut buf, val) + return buf +} + +fn encode_json_value_expr_into(mut buf []u8, val JsonValueExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.raw_expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.formatted_expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_json_value_expr(val JsonValueExpr) []u8 { + mut buf := []u8{} + encode_json_value_expr_into(mut buf, val) + return buf +} + +fn encode_json_is_predicate_into(mut buf []u8, val JsonIsPredicate) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.item_type) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.item_type)) + } + if val.unique_keys { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.unique_keys) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_is_predicate(val JsonIsPredicate) []u8 { + mut buf := []u8{} + encode_json_is_predicate_into(mut buf, val) + return buf +} + +fn encode_json_table_path_scan_into(mut buf []u8, val JsonTablePathScan) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.plan) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_into(mut buf, val.path) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.error_on_error { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.error_on_error) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.child) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.col_min != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.col_min)) + } + if val.col_max != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.col_max)) + } +} + +pub fn encode_json_table_path_scan(val JsonTablePathScan) []u8 { + mut buf := []u8{} + encode_json_table_path_scan_into(mut buf, val) + return buf +} + +fn encode_query_into(mut buf []u8, val Query) { + if u64(val.command_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.command_type)) + } + if u64(val.query_source) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.query_source)) + } + if val.can_set_tag { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.can_set_tag) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.utility_stmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.result_relation != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.result_relation)) + } + if val.has_aggs { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.has_aggs) + } + if val.has_window_funcs { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.has_window_funcs) + } + if val.has_target_srfs { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.has_target_srfs) + } + if val.has_sub_links { + write_tag_into(mut buf, 9, 0) + write_bool_into(mut buf, val.has_sub_links) + } + if val.has_distinct_on { + write_tag_into(mut buf, 10, 0) + write_bool_into(mut buf, val.has_distinct_on) + } + if val.has_recursive { + write_tag_into(mut buf, 11, 0) + write_bool_into(mut buf, val.has_recursive) + } + if val.has_modifying_cte { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.has_modifying_cte) + } + if val.has_for_update { + write_tag_into(mut buf, 13, 0) + write_bool_into(mut buf, val.has_for_update) + } + if val.has_row_security { + write_tag_into(mut buf, 14, 0) + write_bool_into(mut buf, val.has_row_security) + } + if val.is_return { + write_tag_into(mut buf, 15, 0) + write_bool_into(mut buf, val.is_return) + } + if val.cte_list.len > 0 { + for v in val.cte_list { + tag_start_ := buf.len + write_tag_into(mut buf, 16, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.rtable.len > 0 { + for v in val.rtable { + tag_start_ := buf.len + write_tag_into(mut buf, 17, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.rteperminfos.len > 0 { + for v in val.rteperminfos { + tag_start_ := buf.len + write_tag_into(mut buf, 18, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 19, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_from_expr_into(mut buf, val.jointree) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.merge_action_list.len > 0 { + for v in val.merge_action_list { + tag_start_ := buf.len + write_tag_into(mut buf, 20, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.merge_target_relation != 0 { + write_tag_into(mut buf, 21, 0) + write_varint_into(mut buf, u64(val.merge_target_relation)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 22, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.merge_join_condition) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 23, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.override) != 0 { + write_tag_into(mut buf, 24, 0) + write_varint_into(mut buf, u64(val.override)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 25, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_on_conflict_expr_into(mut buf, val.on_conflict) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.returning_list.len > 0 { + for v in val.returning_list { + tag_start_ := buf.len + write_tag_into(mut buf, 26, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.group_clause.len > 0 { + for v in val.group_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 27, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.group_distinct { + write_tag_into(mut buf, 28, 0) + write_bool_into(mut buf, val.group_distinct) + } + if val.grouping_sets.len > 0 { + for v in val.grouping_sets { + tag_start_ := buf.len + write_tag_into(mut buf, 29, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 30, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.having_qual) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.window_clause.len > 0 { + for v in val.window_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 31, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.distinct_clause.len > 0 { + for v in val.distinct_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 32, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.sort_clause.len > 0 { + for v in val.sort_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 33, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 34, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.limit_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 35, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.limit_count) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.limit_option) != 0 { + write_tag_into(mut buf, 36, 0) + write_varint_into(mut buf, u64(val.limit_option)) + } + if val.row_marks.len > 0 { + for v in val.row_marks { + tag_start_ := buf.len + write_tag_into(mut buf, 37, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 38, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.set_operations) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.constraint_deps.len > 0 { + for v in val.constraint_deps { + tag_start_ := buf.len + write_tag_into(mut buf, 39, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.with_check_options.len > 0 { + for v in val.with_check_options { + tag_start_ := buf.len + write_tag_into(mut buf, 40, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.stmt_location != 0 { + write_tag_into(mut buf, 41, 0) + write_varint_into(mut buf, u64(val.stmt_location)) + } + if val.stmt_len != 0 { + write_tag_into(mut buf, 42, 0) + write_varint_into(mut buf, u64(val.stmt_len)) + } +} + +pub fn encode_query(val Query) []u8 { + mut buf := []u8{} + encode_query_into(mut buf, val) + return buf +} + +fn encode_type_cast_into(mut buf []u8, val TypeCast) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_type_cast(val TypeCast) []u8 { + mut buf := []u8{} + encode_type_cast_into(mut buf, val) + return buf +} + +fn encode_range_table_func_col_into(mut buf []u8, val RangeTableFuncCol) { + if val.colname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.colname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.for_ordinality { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.for_ordinality) + } + if val.is_not_null { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.is_not_null) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.colexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.coldefexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_range_table_func_col(val RangeTableFuncCol) []u8 { + mut buf := []u8{} + encode_range_table_func_col_into(mut buf, val) + return buf +} + +fn encode_xml_serialize_into(mut buf []u8, val XmlSerialize) { + if u64(val.xmloption) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.xmloption)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.indent { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.indent) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_xml_serialize(val XmlSerialize) []u8 { + mut buf := []u8{} + encode_xml_serialize_into(mut buf, val) + return buf +} + +fn encode_create_op_class_stmt_into(mut buf []u8, val CreateOpClassStmt) { + if val.opclassname.len > 0 { + for v in val.opclassname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.opfamilyname.len > 0 { + for v in val.opfamilyname { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.amname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.amname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.datatype) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.items.len > 0 { + for v in val.items { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_default { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.is_default) + } +} + +pub fn encode_create_op_class_stmt(val CreateOpClassStmt) []u8 { + mut buf := []u8{} + encode_create_op_class_stmt_into(mut buf, val) + return buf +} + +fn encode_create_function_stmt_into(mut buf []u8, val CreateFunctionStmt) { + if val.is_procedure { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.is_procedure) + } + if val.replace { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.replace) + } + if val.funcname.len > 0 { + for v in val.funcname { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.parameters.len > 0 { + for v in val.parameters { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.return_type) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.sql_body) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_create_function_stmt(val CreateFunctionStmt) []u8 { + mut buf := []u8{} + encode_create_function_stmt_into(mut buf, val) + return buf +} + +fn encode_function_parameter_into(mut buf []u8, val FunctionParameter) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.arg_type) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.mode) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.mode)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.defexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_function_parameter(val FunctionParameter) []u8 { + mut buf := []u8{} + encode_function_parameter_into(mut buf, val) + return buf +} + +fn encode_create_domain_stmt_into(mut buf []u8, val CreateDomainStmt) { + if val.domainname.len > 0 { + for v in val.domainname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_collate_clause_into(mut buf, val.coll_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.constraints.len > 0 { + for v in val.constraints { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_domain_stmt(val CreateDomainStmt) []u8 { + mut buf := []u8{} + encode_create_domain_stmt_into(mut buf, val) + return buf +} + +fn encode_create_schema_stmt_into(mut buf []u8, val CreateSchemaStmt) { + if val.schemaname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.schemaname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.authrole) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.schema_elts.len > 0 { + for v in val.schema_elts { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.if_not_exists { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.if_not_exists) + } +} + +pub fn encode_create_schema_stmt(val CreateSchemaStmt) []u8 { + mut buf := []u8{} + encode_create_schema_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_table_cmd_into(mut buf []u8, val AlterTableCmd) { + if u64(val.subtype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.subtype)) + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } + if val.num != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.num)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.newowner) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.def) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.behavior)) + } + if val.missing_ok { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.missing_ok) + } + if val.recurse { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.recurse) + } +} + +pub fn encode_alter_table_cmd(val AlterTableCmd) []u8 { + mut buf := []u8{} + encode_alter_table_cmd_into(mut buf, val) + return buf +} + +fn encode_grant_stmt_into(mut buf []u8, val GrantStmt) { + if val.is_grant { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.is_grant) + } + if u64(val.targtype) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.targtype)) + } + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + if val.objects.len > 0 { + for v in val.objects { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.privileges.len > 0 { + for v in val.privileges { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.grantees.len > 0 { + for v in val.grantees { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.grant_option { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.grant_option) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.grantor) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.behavior)) + } +} + +pub fn encode_grant_stmt(val GrantStmt) []u8 { + mut buf := []u8{} + encode_grant_stmt_into(mut buf, val) + return buf +} + +fn encode_grant_role_stmt_into(mut buf []u8, val GrantRoleStmt) { + if val.granted_roles.len > 0 { + for v in val.granted_roles { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.grantee_roles.len > 0 { + for v in val.grantee_roles { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_grant { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.is_grant) + } + if val.opt.len > 0 { + for v in val.opt { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.grantor) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.behavior)) + } +} + +pub fn encode_grant_role_stmt(val GrantRoleStmt) []u8 { + mut buf := []u8{} + encode_grant_role_stmt_into(mut buf, val) + return buf +} + +fn encode_create_table_space_stmt_into(mut buf []u8, val CreateTableSpaceStmt) { + if val.tablespacename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.tablespacename) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.owner) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.location) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_table_space_stmt(val CreateTableSpaceStmt) []u8 { + mut buf := []u8{} + encode_create_table_space_stmt_into(mut buf, val) + return buf +} + +fn encode_create_user_mapping_stmt_into(mut buf []u8, val CreateUserMappingStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.user) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.servername != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.servername) + } + if val.if_not_exists { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.if_not_exists) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_user_mapping_stmt(val CreateUserMappingStmt) []u8 { + mut buf := []u8{} + encode_create_user_mapping_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_user_mapping_stmt_into(mut buf []u8, val AlterUserMappingStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.user) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.servername != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.servername) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_user_mapping_stmt(val AlterUserMappingStmt) []u8 { + mut buf := []u8{} + encode_alter_user_mapping_stmt_into(mut buf, val) + return buf +} + +fn encode_drop_user_mapping_stmt_into(mut buf []u8, val DropUserMappingStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.user) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.servername != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.servername) + } + if val.missing_ok { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_drop_user_mapping_stmt(val DropUserMappingStmt) []u8 { + mut buf := []u8{} + encode_drop_user_mapping_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_role_stmt_into(mut buf []u8, val AlterRoleStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.role) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.action != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.action)) + } +} + +pub fn encode_alter_role_stmt(val AlterRoleStmt) []u8 { + mut buf := []u8{} + encode_alter_role_stmt_into(mut buf, val) + return buf +} + +fn encode_reassign_owned_stmt_into(mut buf []u8, val ReassignOwnedStmt) { + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.newrole) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_reassign_owned_stmt(val ReassignOwnedStmt) []u8 { + mut buf := []u8{} + encode_reassign_owned_stmt_into(mut buf, val) + return buf +} + +fn encode_func_call_into(mut buf []u8, val FuncCall) { + if val.funcname.len > 0 { + for v in val.funcname { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.agg_order.len > 0 { + for v in val.agg_order { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.agg_filter) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_def_into(mut buf, val.over) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.agg_within_group { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.agg_within_group) + } + if val.agg_star { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.agg_star) + } + if val.agg_distinct { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.agg_distinct) + } + if val.func_variadic { + write_tag_into(mut buf, 9, 0) + write_bool_into(mut buf, val.func_variadic) + } + if u64(val.funcformat) != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.funcformat)) + } + if val.location != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_func_call(val FuncCall) []u8 { + mut buf := []u8{} + encode_func_call_into(mut buf, val) + return buf +} + +fn encode_on_conflict_clause_into(mut buf []u8, val OnConflictClause) { + if u64(val.action) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.action)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_infer_clause_into(mut buf, val.infer) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_on_conflict_clause(val OnConflictClause) []u8 { + mut buf := []u8{} + encode_on_conflict_clause_into(mut buf, val) + return buf +} + +fn encode_common_table_expr_into(mut buf []u8, val CommonTableExpr) { + if val.ctename != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.ctename) + } + if val.aliascolnames.len > 0 { + for v in val.aliascolnames { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.ctematerialized) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.ctematerialized)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.ctequery) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_c_t_e_search_clause_into(mut buf, val.search_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_c_t_e_cycle_clause_into(mut buf, val.cycle_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.location)) + } + if val.cterecursive { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.cterecursive) + } + if val.cterefcount != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.cterefcount)) + } + if val.ctecolnames.len > 0 { + for v in val.ctecolnames { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.ctecoltypes.len > 0 { + for v in val.ctecoltypes { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.ctecoltypmods.len > 0 { + for v in val.ctecoltypmods { + tag_start_ := buf.len + write_tag_into(mut buf, 12, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.ctecolcollations.len > 0 { + for v in val.ctecolcollations { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_common_table_expr(val CommonTableExpr) []u8 { + mut buf := []u8{} + encode_common_table_expr_into(mut buf, val) + return buf +} + +fn encode_json_table_column_into(mut buf []u8, val JsonTableColumn) { + if u64(val.coltype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.coltype)) + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_spec_into(mut buf, val.pathspec) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.wrapper) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.wrapper)) + } + if u64(val.quotes) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.quotes)) + } + if val.columns.len > 0 { + for v in val.columns { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_empty) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_error) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_table_column(val JsonTableColumn) []u8 { + mut buf := []u8{} + encode_json_table_column_into(mut buf, val) + return buf +} + +fn encode_create_op_class_item_into(mut buf []u8, val CreateOpClassItem) { + if val.itemtype != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.itemtype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.number != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.number)) + } + if val.order_family.len > 0 { + for v in val.order_family { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.class_args.len > 0 { + for v in val.class_args { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.storedtype) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_create_op_class_item(val CreateOpClassItem) []u8 { + mut buf := []u8{} + encode_create_op_class_item_into(mut buf, val) + return buf +} + +fn encode_alter_function_stmt_into(mut buf []u8, val AlterFunctionStmt) { + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.func) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.actions.len > 0 { + for v in val.actions { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_function_stmt(val AlterFunctionStmt) []u8 { + mut buf := []u8{} + encode_alter_function_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_operator_stmt_into(mut buf []u8, val AlterOperatorStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.opername) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_alter_operator_stmt(val AlterOperatorStmt) []u8 { + mut buf := []u8{} + encode_alter_operator_stmt_into(mut buf, val) + return buf +} + +fn encode_create_cast_stmt_into(mut buf []u8, val CreateCastStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.sourcetype) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.targettype) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.func) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.context) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.context)) + } + if val.inout { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.inout) + } +} + +pub fn encode_create_cast_stmt(val CreateCastStmt) []u8 { + mut buf := []u8{} + encode_create_cast_stmt_into(mut buf, val) + return buf +} + +fn encode_create_transform_stmt_into(mut buf []u8, val CreateTransformStmt) { + if val.replace { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.replace) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.lang != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.lang) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.fromsql) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val.tosql) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_create_transform_stmt(val CreateTransformStmt) []u8 { + mut buf := []u8{} + encode_create_transform_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_role_set_stmt_into(mut buf []u8, val AlterRoleSetStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.role) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.database != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.database) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_variable_set_stmt_into(mut buf, val.setstmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_role_set_stmt(val AlterRoleSetStmt) []u8 { + mut buf := []u8{} + encode_alter_role_set_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_database_set_stmt_into(mut buf []u8, val AlterDatabaseSetStmt) { + if val.dbname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.dbname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_variable_set_stmt_into(mut buf, val.setstmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_database_set_stmt(val AlterDatabaseSetStmt) []u8 { + mut buf := []u8{} + encode_alter_database_set_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_system_stmt_into(mut buf []u8, val AlterSystemStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_variable_set_stmt_into(mut buf, val.setstmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_system_stmt(val AlterSystemStmt) []u8 { + mut buf := []u8{} + encode_alter_system_stmt_into(mut buf, val) + return buf +} + +fn encode_into_clause_into(mut buf []u8, val IntoClause) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.rel) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.col_names.len > 0 { + for v in val.col_names { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.access_method != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.access_method) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.on_commit) != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.on_commit)) + } + if val.table_space_name != '' { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, val.table_space_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.view_query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.skip_data { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.skip_data) + } +} + +pub fn encode_into_clause(val IntoClause) []u8 { + mut buf := []u8{} + encode_into_clause_into(mut buf, val) + return buf +} + +fn encode_column_def_into(mut buf []u8, val ColumnDef) { + if val.colname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.colname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.compression != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.compression) + } + if val.inhcount != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.inhcount)) + } + if val.is_local { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.is_local) + } + if val.is_not_null { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.is_not_null) + } + if val.is_from_type { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.is_from_type) + } + if val.storage != '' { + write_tag_into(mut buf, 8, 2) + write_string_into(mut buf, val.storage) + } + if val.storage_name != '' { + write_tag_into(mut buf, 9, 2) + write_string_into(mut buf, val.storage_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.raw_default) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.cooked_default) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.identity != '' { + write_tag_into(mut buf, 12, 2) + write_string_into(mut buf, val.identity) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.identity_sequence) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.generated != '' { + write_tag_into(mut buf, 14, 2) + write_string_into(mut buf, val.generated) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_collate_clause_into(mut buf, val.coll_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coll_oid != 0 { + write_tag_into(mut buf, 16, 0) + write_varint_into(mut buf, u64(val.coll_oid)) + } + if val.constraints.len > 0 { + for v in val.constraints { + tag_start_ := buf.len + write_tag_into(mut buf, 17, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.fdwoptions.len > 0 { + for v in val.fdwoptions { + tag_start_ := buf.len + write_tag_into(mut buf, 18, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.location != 0 { + write_tag_into(mut buf, 19, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_column_def(val ColumnDef) []u8 { + mut buf := []u8{} + encode_column_def_into(mut buf, val) + return buf +} + +fn encode_table_like_clause_into(mut buf []u8, val TableLikeClause) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.options)) + } + if val.relation_oid != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.relation_oid)) + } +} + +pub fn encode_table_like_clause(val TableLikeClause) []u8 { + mut buf := []u8{} + encode_table_like_clause_into(mut buf, val) + return buf +} + +fn encode_partition_cmd_into(mut buf []u8, val PartitionCmd) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_bound_spec_into(mut buf, val.bound) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.concurrent { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.concurrent) + } +} + +pub fn encode_partition_cmd(val PartitionCmd) []u8 { + mut buf := []u8{} + encode_partition_cmd_into(mut buf, val) + return buf +} + +fn encode_delete_stmt_into(mut buf []u8, val DeleteStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.using_clause.len > 0 { + for v in val.using_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.returning_list.len > 0 { + for v in val.returning_list { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val.with_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_delete_stmt(val DeleteStmt) []u8 { + mut buf := []u8{} + encode_delete_stmt_into(mut buf, val) + return buf +} + +fn encode_update_stmt_into(mut buf []u8, val UpdateStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.from_clause.len > 0 { + for v in val.from_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.returning_list.len > 0 { + for v in val.returning_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val.with_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_update_stmt(val UpdateStmt) []u8 { + mut buf := []u8{} + encode_update_stmt_into(mut buf, val) + return buf +} + +fn encode_merge_stmt_into(mut buf []u8, val MergeStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.source_relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.join_condition) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.merge_when_clauses.len > 0 { + for v in val.merge_when_clauses { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.returning_list.len > 0 { + for v in val.returning_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val.with_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_merge_stmt(val MergeStmt) []u8 { + mut buf := []u8{} + encode_merge_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_table_stmt_into(mut buf []u8, val AlterTableStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cmds.len > 0 { + for v in val.cmds { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + if val.missing_ok { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_table_stmt(val AlterTableStmt) []u8 { + mut buf := []u8{} + encode_alter_table_stmt_into(mut buf, val) + return buf +} + +fn encode_copy_stmt_into(mut buf []u8, val CopyStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.attlist.len > 0 { + for v in val.attlist { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.is_from { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.is_from) + } + if val.is_program { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.is_program) + } + if val.filename != '' { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, val.filename) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_copy_stmt(val CopyStmt) []u8 { + mut buf := []u8{} + encode_copy_stmt_into(mut buf, val) + return buf +} + +fn encode_create_stmt_into(mut buf []u8, val CreateStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.table_elts.len > 0 { + for v in val.table_elts { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.inh_relations.len > 0 { + for v in val.inh_relations { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_bound_spec_into(mut buf, val.partbound) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_spec_into(mut buf, val.partspec) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.of_typename) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.constraints.len > 0 { + for v in val.constraints { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.oncommit) != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.oncommit)) + } + if val.tablespacename != '' { + write_tag_into(mut buf, 10, 2) + write_string_into(mut buf, val.tablespacename) + } + if val.access_method != '' { + write_tag_into(mut buf, 11, 2) + write_string_into(mut buf, val.access_method) + } + if val.if_not_exists { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.if_not_exists) + } +} + +pub fn encode_create_stmt(val CreateStmt) []u8 { + mut buf := []u8{} + encode_create_stmt_into(mut buf, val) + return buf +} + +fn encode_constraint_into(mut buf []u8, val Constraint) { + if u64(val.contype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.contype)) + } + if val.conname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.conname) + } + if val.deferrable { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.deferrable) + } + if val.initdeferred { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.initdeferred) + } + if val.skip_validation { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.skip_validation) + } + if val.initially_valid { + write_tag_into(mut buf, 6, 0) + write_bool_into(mut buf, val.initially_valid) + } + if val.is_no_inherit { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.is_no_inherit) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.raw_expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cooked_expr != '' { + write_tag_into(mut buf, 9, 2) + write_string_into(mut buf, val.cooked_expr) + } + if val.generated_when != '' { + write_tag_into(mut buf, 10, 2) + write_string_into(mut buf, val.generated_when) + } + if val.inhcount != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.inhcount)) + } + if val.nulls_not_distinct { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.nulls_not_distinct) + } + if val.keys.len > 0 { + for v in val.keys { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.including.len > 0 { + for v in val.including { + tag_start_ := buf.len + write_tag_into(mut buf, 14, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.exclusions.len > 0 { + for v in val.exclusions { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 16, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.indexname != '' { + write_tag_into(mut buf, 17, 2) + write_string_into(mut buf, val.indexname) + } + if val.indexspace != '' { + write_tag_into(mut buf, 18, 2) + write_string_into(mut buf, val.indexspace) + } + if val.reset_default_tblspc { + write_tag_into(mut buf, 19, 0) + write_bool_into(mut buf, val.reset_default_tblspc) + } + if val.access_method != '' { + write_tag_into(mut buf, 20, 2) + write_string_into(mut buf, val.access_method) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 21, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 22, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.pktable) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.fk_attrs.len > 0 { + for v in val.fk_attrs { + tag_start_ := buf.len + write_tag_into(mut buf, 23, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.pk_attrs.len > 0 { + for v in val.pk_attrs { + tag_start_ := buf.len + write_tag_into(mut buf, 24, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.fk_matchtype != '' { + write_tag_into(mut buf, 25, 2) + write_string_into(mut buf, val.fk_matchtype) + } + if val.fk_upd_action != '' { + write_tag_into(mut buf, 26, 2) + write_string_into(mut buf, val.fk_upd_action) + } + if val.fk_del_action != '' { + write_tag_into(mut buf, 27, 2) + write_string_into(mut buf, val.fk_del_action) + } + if val.fk_del_set_cols.len > 0 { + for v in val.fk_del_set_cols { + tag_start_ := buf.len + write_tag_into(mut buf, 28, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.old_conpfeqop.len > 0 { + for v in val.old_conpfeqop { + tag_start_ := buf.len + write_tag_into(mut buf, 29, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.old_pktable_oid != 0 { + write_tag_into(mut buf, 30, 0) + write_varint_into(mut buf, u64(val.old_pktable_oid)) + } + if val.location != 0 { + write_tag_into(mut buf, 31, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_constraint(val Constraint) []u8 { + mut buf := []u8{} + encode_constraint_into(mut buf, val) + return buf +} + +fn encode_create_policy_stmt_into(mut buf []u8, val CreatePolicyStmt) { + if val.policy_name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.policy_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.table) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cmd_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.cmd_name) + } + if val.permissive { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.permissive) + } + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.qual) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.with_check) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_create_policy_stmt(val CreatePolicyStmt) []u8 { + mut buf := []u8{} + encode_create_policy_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_policy_stmt_into(mut buf []u8, val AlterPolicyStmt) { + if val.policy_name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.policy_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.table) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.roles.len > 0 { + for v in val.roles { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.qual) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.with_check) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_policy_stmt(val AlterPolicyStmt) []u8 { + mut buf := []u8{} + encode_alter_policy_stmt_into(mut buf, val) + return buf +} + +fn encode_create_trig_stmt_into(mut buf []u8, val CreateTrigStmt) { + if val.replace { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.replace) + } + if val.isconstraint { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.isconstraint) + } + if val.trigname != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.trigname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.funcname.len > 0 { + for v in val.funcname { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.row { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.row) + } + if val.timing != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.timing)) + } + if val.events != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.events)) + } + if val.columns.len > 0 { + for v in val.columns { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.when_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.transition_rels.len > 0 { + for v in val.transition_rels { + tag_start_ := buf.len + write_tag_into(mut buf, 12, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.deferrable { + write_tag_into(mut buf, 13, 0) + write_bool_into(mut buf, val.deferrable) + } + if val.initdeferred { + write_tag_into(mut buf, 14, 0) + write_bool_into(mut buf, val.initdeferred) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.constrrel) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_create_trig_stmt(val CreateTrigStmt) []u8 { + mut buf := []u8{} + encode_create_trig_stmt_into(mut buf, val) + return buf +} + +fn encode_create_seq_stmt_into(mut buf []u8, val CreateSeqStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.sequence) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.owner_id != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.owner_id)) + } + if val.for_identity { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.for_identity) + } + if val.if_not_exists { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.if_not_exists) + } +} + +pub fn encode_create_seq_stmt(val CreateSeqStmt) []u8 { + mut buf := []u8{} + encode_create_seq_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_seq_stmt_into(mut buf []u8, val AlterSeqStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.sequence) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.for_identity { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.for_identity) + } + if val.missing_ok { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_seq_stmt(val AlterSeqStmt) []u8 { + mut buf := []u8{} + encode_alter_seq_stmt_into(mut buf, val) + return buf +} + +fn encode_index_stmt_into(mut buf []u8, val IndexStmt) { + if val.idxname != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.idxname) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.access_method != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.access_method) + } + if val.table_space != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.table_space) + } + if val.index_params.len > 0 { + for v in val.index_params { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.index_including_params.len > 0 { + for v in val.index_including_params { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.exclude_op_names.len > 0 { + for v in val.exclude_op_names { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.idxcomment != '' { + write_tag_into(mut buf, 10, 2) + write_string_into(mut buf, val.idxcomment) + } + if val.index_oid != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.index_oid)) + } + if val.old_number != 0 { + write_tag_into(mut buf, 12, 0) + write_varint_into(mut buf, u64(val.old_number)) + } + if val.old_create_subid != 0 { + write_tag_into(mut buf, 13, 0) + write_varint_into(mut buf, u64(val.old_create_subid)) + } + if val.old_first_relfilelocator_subid != 0 { + write_tag_into(mut buf, 14, 0) + write_varint_into(mut buf, u64(val.old_first_relfilelocator_subid)) + } + if val.unique { + write_tag_into(mut buf, 15, 0) + write_bool_into(mut buf, val.unique) + } + if val.nulls_not_distinct { + write_tag_into(mut buf, 16, 0) + write_bool_into(mut buf, val.nulls_not_distinct) + } + if val.primary { + write_tag_into(mut buf, 17, 0) + write_bool_into(mut buf, val.primary) + } + if val.isconstraint { + write_tag_into(mut buf, 18, 0) + write_bool_into(mut buf, val.isconstraint) + } + if val.deferrable { + write_tag_into(mut buf, 19, 0) + write_bool_into(mut buf, val.deferrable) + } + if val.initdeferred { + write_tag_into(mut buf, 20, 0) + write_bool_into(mut buf, val.initdeferred) + } + if val.transformed { + write_tag_into(mut buf, 21, 0) + write_bool_into(mut buf, val.transformed) + } + if val.concurrent { + write_tag_into(mut buf, 22, 0) + write_bool_into(mut buf, val.concurrent) + } + if val.if_not_exists { + write_tag_into(mut buf, 23, 0) + write_bool_into(mut buf, val.if_not_exists) + } + if val.reset_default_tblspc { + write_tag_into(mut buf, 24, 0) + write_bool_into(mut buf, val.reset_default_tblspc) + } +} + +pub fn encode_index_stmt(val IndexStmt) []u8 { + mut buf := []u8{} + encode_index_stmt_into(mut buf, val) + return buf +} + +fn encode_rename_stmt_into(mut buf []u8, val RenameStmt) { + if u64(val.rename_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.rename_type)) + } + if u64(val.relation_type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.relation_type)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.subname != '' { + write_tag_into(mut buf, 5, 2) + write_string_into(mut buf, val.subname) + } + if val.newname != '' { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, val.newname) + } + if u64(val.behavior) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.behavior)) + } + if val.missing_ok { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_rename_stmt(val RenameStmt) []u8 { + mut buf := []u8{} + encode_rename_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_object_depends_stmt_into(mut buf []u8, val AlterObjectDependsStmt) { + if u64(val.object_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.object_type)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_string_into(mut buf, val.extname) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.remove { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.remove) + } +} + +pub fn encode_alter_object_depends_stmt(val AlterObjectDependsStmt) []u8 { + mut buf := []u8{} + encode_alter_object_depends_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_object_schema_stmt_into(mut buf []u8, val AlterObjectSchemaStmt) { + if u64(val.object_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.object_type)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.newschema != '' { + write_tag_into(mut buf, 4, 2) + write_string_into(mut buf, val.newschema) + } + if val.missing_ok { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.missing_ok) + } +} + +pub fn encode_alter_object_schema_stmt(val AlterObjectSchemaStmt) []u8 { + mut buf := []u8{} + encode_alter_object_schema_stmt_into(mut buf, val) + return buf +} + +fn encode_alter_owner_stmt_into(mut buf []u8, val AlterOwnerStmt) { + if u64(val.object_type) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.object_type)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.object) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val.newowner) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_owner_stmt(val AlterOwnerStmt) []u8 { + mut buf := []u8{} + encode_alter_owner_stmt_into(mut buf, val) + return buf +} + +fn encode_rule_stmt_into(mut buf []u8, val RuleStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.rulename != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.rulename) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.event) != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.event)) + } + if val.instead { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.instead) + } + if val.actions.len > 0 { + for v in val.actions { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.replace { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.replace) + } +} + +pub fn encode_rule_stmt(val RuleStmt) []u8 { + mut buf := []u8{} + encode_rule_stmt_into(mut buf, val) + return buf +} + +fn encode_composite_type_stmt_into(mut buf []u8, val CompositeTypeStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.typevar) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.coldeflist.len > 0 { + for v in val.coldeflist { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_composite_type_stmt(val CompositeTypeStmt) []u8 { + mut buf := []u8{} + encode_composite_type_stmt_into(mut buf, val) + return buf +} + +fn encode_view_stmt_into(mut buf []u8, val ViewStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.view) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.aliases.len > 0 { + for v in val.aliases { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.replace { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.replace) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if u64(val.with_check_option) != 0 { + write_tag_into(mut buf, 6, 0) + write_varint_into(mut buf, u64(val.with_check_option)) + } +} + +pub fn encode_view_stmt(val ViewStmt) []u8 { + mut buf := []u8{} + encode_view_stmt_into(mut buf, val) + return buf +} + +fn encode_cluster_stmt_into(mut buf []u8, val ClusterStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.indexname != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.indexname) + } + if val.params.len > 0 { + for v in val.params { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_cluster_stmt(val ClusterStmt) []u8 { + mut buf := []u8{} + encode_cluster_stmt_into(mut buf, val) + return buf +} + +fn encode_vacuum_relation_into(mut buf []u8, val VacuumRelation) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.oid != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.oid)) + } + if val.va_cols.len > 0 { + for v in val.va_cols { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_vacuum_relation(val VacuumRelation) []u8 { + mut buf := []u8{} + encode_vacuum_relation_into(mut buf, val) + return buf +} + +fn encode_refresh_mat_view_stmt_into(mut buf []u8, val RefreshMatViewStmt) { + if val.concurrent { + write_tag_into(mut buf, 1, 0) + write_bool_into(mut buf, val.concurrent) + } + if val.skip_data { + write_tag_into(mut buf, 2, 0) + write_bool_into(mut buf, val.skip_data) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_refresh_mat_view_stmt(val RefreshMatViewStmt) []u8 { + mut buf := []u8{} + encode_refresh_mat_view_stmt_into(mut buf, val) + return buf +} + +fn encode_reindex_stmt_into(mut buf []u8, val ReindexStmt) { + if u64(val.kind) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.kind)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.name) + } + if val.params.len > 0 { + for v in val.params { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_reindex_stmt(val ReindexStmt) []u8 { + mut buf := []u8{} + encode_reindex_stmt_into(mut buf, val) + return buf +} + +fn encode_publication_table_into(mut buf []u8, val PublicationTable) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.columns.len > 0 { + for v in val.columns { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_publication_table(val PublicationTable) []u8 { + mut buf := []u8{} + encode_publication_table_into(mut buf, val) + return buf +} + +fn encode_json_constructor_expr_into(mut buf []u8, val JsonConstructorExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.type) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.type)) + } + if val.args.len > 0 { + for v in val.args { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.func) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.coercion) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_returning_into(mut buf, val.returning) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.absent_on_null) + } + if val.unique { + write_tag_into(mut buf, 8, 0) + write_bool_into(mut buf, val.unique) + } + if val.location != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_constructor_expr(val JsonConstructorExpr) []u8 { + mut buf := []u8{} + encode_json_constructor_expr_into(mut buf, val) + return buf +} + +fn encode_json_expr_into(mut buf []u8, val JsonExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.xpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.op) != 0 { + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.column_name != '' { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, val.column_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.formatted_expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.path_spec) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_returning_into(mut buf, val.returning) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.passing_names.len > 0 { + for v in val.passing_names { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.passing_values.len > 0 { + for v in val.passing_values { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_empty) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_error) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.use_io_coercion { + write_tag_into(mut buf, 12, 0) + write_bool_into(mut buf, val.use_io_coercion) + } + if val.use_json_coercion { + write_tag_into(mut buf, 13, 0) + write_bool_into(mut buf, val.use_json_coercion) + } + if u64(val.wrapper) != 0 { + write_tag_into(mut buf, 14, 0) + write_varint_into(mut buf, u64(val.wrapper)) + } + if val.omit_quotes { + write_tag_into(mut buf, 15, 0) + write_bool_into(mut buf, val.omit_quotes) + } + if val.collation != 0 { + write_tag_into(mut buf, 16, 0) + write_varint_into(mut buf, u64(val.collation)) + } + if val.location != 0 { + write_tag_into(mut buf, 17, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_expr(val JsonExpr) []u8 { + mut buf := []u8{} + encode_json_expr_into(mut buf, val) + return buf +} + +fn encode_json_output_into(mut buf []u8, val JsonOutput) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val.type_name) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_returning_into(mut buf, val.returning) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_json_output(val JsonOutput) []u8 { + mut buf := []u8{} + encode_json_output_into(mut buf, val) + return buf +} + +fn encode_json_argument_into(mut buf []u8, val JsonArgument) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.val) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } +} + +pub fn encode_json_argument(val JsonArgument) []u8 { + mut buf := []u8{} + encode_json_argument_into(mut buf, val) + return buf +} + +fn encode_json_table_into(mut buf []u8, val JsonTable) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.context_item) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_spec_into(mut buf, val.pathspec) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.passing.len > 0 { + for v in val.passing { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.columns.len > 0 { + for v in val.columns { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_error) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.lateral { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.lateral) + } + if val.location != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_table(val JsonTable) []u8 { + mut buf := []u8{} + encode_json_table_into(mut buf, val) + return buf +} + +fn encode_json_key_value_into(mut buf []u8, val JsonKeyValue) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.key) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.value) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_json_key_value(val JsonKeyValue) []u8 { + mut buf := []u8{} + encode_json_key_value_into(mut buf, val) + return buf +} + +fn encode_range_tbl_entry_into(mut buf []u8, val RangeTblEntry) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.eref) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.rtekind) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.rtekind)) + } + if val.relid != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.relid)) + } + if val.inh { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.inh) + } + if val.relkind != '' { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, val.relkind) + } + if val.rellockmode != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.rellockmode)) + } + if val.perminfoindex != 0 { + write_tag_into(mut buf, 8, 0) + write_varint_into(mut buf, u64(val.perminfoindex)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_table_sample_clause_into(mut buf, val.tablesample) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_query_into(mut buf, val.subquery) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.security_barrier { + write_tag_into(mut buf, 11, 0) + write_bool_into(mut buf, val.security_barrier) + } + if u64(val.jointype) != 0 { + write_tag_into(mut buf, 12, 0) + write_varint_into(mut buf, u64(val.jointype)) + } + if val.joinmergedcols != 0 { + write_tag_into(mut buf, 13, 0) + write_varint_into(mut buf, u64(val.joinmergedcols)) + } + if val.joinaliasvars.len > 0 { + for v in val.joinaliasvars { + tag_start_ := buf.len + write_tag_into(mut buf, 14, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.joinleftcols.len > 0 { + for v in val.joinleftcols { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.joinrightcols.len > 0 { + for v in val.joinrightcols { + tag_start_ := buf.len + write_tag_into(mut buf, 16, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 17, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val.join_using_alias) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.functions.len > 0 { + for v in val.functions { + tag_start_ := buf.len + write_tag_into(mut buf, 18, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.funcordinality { + write_tag_into(mut buf, 19, 0) + write_bool_into(mut buf, val.funcordinality) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 20, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_table_func_into(mut buf, val.tablefunc) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.values_lists.len > 0 { + for v in val.values_lists { + tag_start_ := buf.len + write_tag_into(mut buf, 21, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.ctename != '' { + write_tag_into(mut buf, 22, 2) + write_string_into(mut buf, val.ctename) + } + if val.ctelevelsup != 0 { + write_tag_into(mut buf, 23, 0) + write_varint_into(mut buf, u64(val.ctelevelsup)) + } + if val.self_reference { + write_tag_into(mut buf, 24, 0) + write_bool_into(mut buf, val.self_reference) + } + if val.coltypes.len > 0 { + for v in val.coltypes { + tag_start_ := buf.len + write_tag_into(mut buf, 25, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.coltypmods.len > 0 { + for v in val.coltypmods { + tag_start_ := buf.len + write_tag_into(mut buf, 26, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.colcollations.len > 0 { + for v in val.colcollations { + tag_start_ := buf.len + write_tag_into(mut buf, 27, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.enrname != '' { + write_tag_into(mut buf, 28, 2) + write_string_into(mut buf, val.enrname) + } + if val.enrtuples != 0.0 { + write_tag_into(mut buf, 29, 1) + write_double_into(mut buf, val.enrtuples) + } + if val.lateral { + write_tag_into(mut buf, 30, 0) + write_bool_into(mut buf, val.lateral) + } + if val.in_from_cl { + write_tag_into(mut buf, 31, 0) + write_bool_into(mut buf, val.in_from_cl) + } + if val.security_quals.len > 0 { + for v in val.security_quals { + tag_start_ := buf.len + write_tag_into(mut buf, 32, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_range_tbl_entry(val RangeTblEntry) []u8 { + mut buf := []u8{} + encode_range_tbl_entry_into(mut buf, val) + return buf +} + +fn encode_alter_default_privileges_stmt_into(mut buf []u8, val AlterDefaultPrivilegesStmt) { + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_grant_stmt_into(mut buf, val.action) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } +} + +pub fn encode_alter_default_privileges_stmt(val AlterDefaultPrivilegesStmt) []u8 { + mut buf := []u8{} + encode_alter_default_privileges_stmt_into(mut buf, val) + return buf +} + +fn encode_call_stmt_into(mut buf []u8, val CallStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_func_call_into(mut buf, val.funccall) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_func_expr_into(mut buf, val.funcexpr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.outargs.len > 0 { + for v in val.outargs { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_call_stmt(val CallStmt) []u8 { + mut buf := []u8{} + encode_call_stmt_into(mut buf, val) + return buf +} + +fn encode_insert_stmt_into(mut buf []u8, val InsertStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val.relation) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.cols.len > 0 { + for v in val.cols { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.select_stmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_on_conflict_clause_into(mut buf, val.on_conflict_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.returning_list.len > 0 { + for v in val.returning_list { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val.with_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.override) != 0 { + write_tag_into(mut buf, 7, 0) + write_varint_into(mut buf, u64(val.override)) + } +} + +pub fn encode_insert_stmt(val InsertStmt) []u8 { + mut buf := []u8{} + encode_insert_stmt_into(mut buf, val) + return buf +} + +fn encode_select_stmt_into(mut buf []u8, val SelectStmt) { + if val.distinct_clause.len > 0 { + for v in val.distinct_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_into_clause_into(mut buf, val.into_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.target_list.len > 0 { + for v in val.target_list { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.from_clause.len > 0 { + for v in val.from_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.where_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.group_clause.len > 0 { + for v in val.group_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.group_distinct { + write_tag_into(mut buf, 7, 0) + write_bool_into(mut buf, val.group_distinct) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.having_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.window_clause.len > 0 { + for v in val.window_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.values_lists.len > 0 { + for v in val.values_lists { + tag_start_ := buf.len + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.sort_clause.len > 0 { + for v in val.sort_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 12, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.limit_offset) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.limit_count) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.limit_option) != 0 { + write_tag_into(mut buf, 14, 0) + write_varint_into(mut buf, u64(val.limit_option)) + } + if val.locking_clause.len > 0 { + for v in val.locking_clause { + tag_start_ := buf.len + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 16, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val.with_clause) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.op) != 0 { + write_tag_into(mut buf, 17, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.all { + write_tag_into(mut buf, 18, 0) + write_bool_into(mut buf, val.all) + } + if larg_ := val.larg { + write_tag_into(mut buf, 19, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_select_stmt_into(mut buf, larg_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + if rarg_ := val.rarg { + write_tag_into(mut buf, 20, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_select_stmt_into(mut buf, rarg_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } +} + +pub fn encode_select_stmt(val SelectStmt) []u8 { + mut buf := []u8{} + encode_select_stmt_into(mut buf, val) + return buf +} + +fn encode_create_table_as_stmt_into(mut buf []u8, val CreateTableAsStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_into_clause_into(mut buf, val.into) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.objtype) != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.objtype)) + } + if val.is_select_into { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.is_select_into) + } + if val.if_not_exists { + write_tag_into(mut buf, 5, 0) + write_bool_into(mut buf, val.if_not_exists) + } +} + +pub fn encode_create_table_as_stmt(val CreateTableAsStmt) []u8 { + mut buf := []u8{} + encode_create_table_as_stmt_into(mut buf, val) + return buf +} + +fn encode_create_foreign_table_stmt_into(mut buf []u8, val CreateForeignTableStmt) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_stmt_into(mut buf, val.base_stmt) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.servername != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.servername) + } + if val.options.len > 0 { + for v in val.options { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } +} + +pub fn encode_create_foreign_table_stmt(val CreateForeignTableStmt) []u8 { + mut buf := []u8{} + encode_create_foreign_table_stmt_into(mut buf, val) + return buf +} + +fn encode_publication_obj_spec_into(mut buf []u8, val PublicationObjSpec) { + if u64(val.pubobjtype) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.pubobjtype)) + } + if val.name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_publication_table_into(mut buf, val.pubtable) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_publication_obj_spec(val PublicationObjSpec) []u8 { + mut buf := []u8{} + encode_publication_obj_spec_into(mut buf, val) + return buf +} + +fn encode_json_func_expr_into(mut buf []u8, val JsonFuncExpr) { + if u64(val.op) != 0 { + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.op)) + } + if val.column_name != '' { + write_tag_into(mut buf, 2, 2) + write_string_into(mut buf, val.column_name) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.context_item) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.pathspec) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.passing.len > 0 { + for v in val.passing { + tag_start_ := buf.len + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_empty) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val.on_error) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if u64(val.wrapper) != 0 { + write_tag_into(mut buf, 9, 0) + write_varint_into(mut buf, u64(val.wrapper)) + } + if u64(val.quotes) != 0 { + write_tag_into(mut buf, 10, 0) + write_varint_into(mut buf, u64(val.quotes)) + } + if val.location != 0 { + write_tag_into(mut buf, 11, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_func_expr(val JsonFuncExpr) []u8 { + mut buf := []u8{} + encode_json_func_expr_into(mut buf, val) + return buf +} + +fn encode_json_parse_expr_into(mut buf []u8, val JsonParseExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.unique_keys { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.unique_keys) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_parse_expr(val JsonParseExpr) []u8 { + mut buf := []u8{} + encode_json_parse_expr_into(mut buf, val) + return buf +} + +fn encode_json_scalar_expr_into(mut buf []u8, val JsonScalarExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_scalar_expr(val JsonScalarExpr) []u8 { + mut buf := []u8{} + encode_json_scalar_expr_into(mut buf, val) + return buf +} + +fn encode_json_serialize_expr_into(mut buf []u8, val JsonSerializeExpr) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.expr) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_serialize_expr(val JsonSerializeExpr) []u8 { + mut buf := []u8{} + encode_json_serialize_expr_into(mut buf, val) + return buf +} + +fn encode_json_object_constructor_into(mut buf []u8, val JsonObjectConstructor) { + if val.exprs.len > 0 { + for v in val.exprs { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.absent_on_null) + } + if val.unique { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.unique) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_object_constructor(val JsonObjectConstructor) []u8 { + mut buf := []u8{} + encode_json_object_constructor_into(mut buf, val) + return buf +} + +fn encode_json_array_constructor_into(mut buf []u8, val JsonArrayConstructor) { + if val.exprs.len > 0 { + for v in val.exprs { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.absent_on_null) + } + if val.location != 0 { + write_tag_into(mut buf, 4, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_array_constructor(val JsonArrayConstructor) []u8 { + mut buf := []u8{} + encode_json_array_constructor_into(mut buf, val) + return buf +} + +fn encode_json_array_query_constructor_into(mut buf []u8, val JsonArrayQueryConstructor) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.query) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val.format) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.absent_on_null) + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_array_query_constructor(val JsonArrayQueryConstructor) []u8 { + mut buf := []u8{} + encode_json_array_query_constructor_into(mut buf, val) + return buf +} + +fn encode_json_agg_constructor_into(mut buf []u8, val JsonAggConstructor) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val.output) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, val.agg_filter) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.agg_order.len > 0 { + for v in val.agg_order { + tag_start_ := buf.len + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_def_into(mut buf, val.over) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_json_agg_constructor(val JsonAggConstructor) []u8 { + mut buf := []u8{} + encode_json_agg_constructor_into(mut buf, val) + return buf +} + +fn encode_p_l_assign_stmt_into(mut buf []u8, val PLAssignStmt) { + if val.name != '' { + write_tag_into(mut buf, 1, 2) + write_string_into(mut buf, val.name) + } + if val.indirection.len > 0 { + for v in val.indirection { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_node_into(mut buf, v) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + } + if val.nnames != 0 { + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(val.nnames)) + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_select_stmt_into(mut buf, val.val) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.location != 0 { + write_tag_into(mut buf, 5, 0) + write_varint_into(mut buf, u64(val.location)) + } +} + +pub fn encode_p_l_assign_stmt(val PLAssignStmt) []u8 { + mut buf := []u8{} + encode_p_l_assign_stmt_into(mut buf, val) + return buf +} + +fn encode_json_object_agg_into(mut buf []u8, val JsonObjectAgg) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_agg_constructor_into(mut buf, val.constructor) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_key_value_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.absent_on_null) + } + if val.unique { + write_tag_into(mut buf, 4, 0) + write_bool_into(mut buf, val.unique) + } +} + +pub fn encode_json_object_agg(val JsonObjectAgg) []u8 { + mut buf := []u8{} + encode_json_object_agg_into(mut buf, val) + return buf +} + +fn encode_json_array_agg_into(mut buf []u8, val JsonArrayAgg) { + { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_agg_constructor_into(mut buf, val.constructor) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + { + tag_start_ := buf.len + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val.arg) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + if val.absent_on_null { + write_tag_into(mut buf, 3, 0) + write_bool_into(mut buf, val.absent_on_null) + } +} + +pub fn encode_json_array_agg(val JsonArrayAgg) []u8 { + mut buf := []u8{} + encode_json_array_agg_into(mut buf, val) + return buf +} + +fn encode_summary_result_into(mut buf []u8, val SummaryResult) { + if val.tables.len > 0 { + for v in val.tables { + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_summary_result_table_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + } + if val.aliases.len > 0 { + for k, v in val.aliases { + map_enc_ := write_map_string_entry(k, v) + write_tag_into(mut buf, 2, 2) + write_length_delimited_into(mut buf, map_enc_) + } + } + if val.cte_names.len > 0 { + for v in val.cte_names { + write_tag_into(mut buf, 3, 2) + write_string_into(mut buf, v) + } + } + if val.functions.len > 0 { + for v in val.functions { + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_summary_result_function_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + } + if val.filter_columns.len > 0 { + for v in val.filter_columns { + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_summary_result_filter_column_into(mut buf, v) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + } + if val.statement_types.len > 0 { + for v in val.statement_types { + write_tag_into(mut buf, 6, 2) + write_string_into(mut buf, v) + } + } + if val.truncated_query != '' { + write_tag_into(mut buf, 7, 2) + write_string_into(mut buf, val.truncated_query) + } +} + +pub fn encode_summary_result(val SummaryResult) []u8 { + mut buf := []u8{} + encode_summary_result_into(mut buf, val) + return buf +} + +fn encode_node_into(mut buf []u8, val_ Node) { + match val_ { + Alias { + tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alias_into(mut buf, val_) + if buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) } + } + RangeVar { + write_tag_into(mut buf, 2, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_var_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TableFunc { + write_tag_into(mut buf, 3, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_table_func_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + IntoClause { + write_tag_into(mut buf, 4, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_into_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Var { + write_tag_into(mut buf, 5, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_var_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Param { + write_tag_into(mut buf, 6, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_param_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Aggref { + write_tag_into(mut buf, 7, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_aggref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + GroupingFunc { + write_tag_into(mut buf, 8, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_grouping_func_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WindowFunc { + write_tag_into(mut buf, 9, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_func_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WindowFuncRunCondition { + write_tag_into(mut buf, 10, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_func_run_condition_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MergeSupportFunc { + write_tag_into(mut buf, 11, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_merge_support_func_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SubscriptingRef { + write_tag_into(mut buf, 12, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_subscripting_ref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FuncExpr { + write_tag_into(mut buf, 13, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_func_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + NamedArgExpr { + write_tag_into(mut buf, 14, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_named_arg_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + OpExpr { + write_tag_into(mut buf, 15, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_op_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DistinctExpr { + write_tag_into(mut buf, 16, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_distinct_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + NullIfExpr { + write_tag_into(mut buf, 17, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_null_if_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ScalarArrayOpExpr { + write_tag_into(mut buf, 18, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_scalar_array_op_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + BoolExpr { + write_tag_into(mut buf, 19, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_bool_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SubLink { + write_tag_into(mut buf, 20, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_sub_link_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SubPlan { + write_tag_into(mut buf, 21, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_sub_plan_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlternativeSubPlan { + write_tag_into(mut buf, 22, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alternative_sub_plan_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FieldSelect { + write_tag_into(mut buf, 23, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_field_select_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FieldStore { + write_tag_into(mut buf, 24, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_field_store_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RelabelType { + write_tag_into(mut buf, 25, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_relabel_type_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CoerceViaIO { + write_tag_into(mut buf, 26, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_coerce_via_i_o_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ArrayCoerceExpr { + write_tag_into(mut buf, 27, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_array_coerce_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ConvertRowtypeExpr { + write_tag_into(mut buf, 28, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_convert_rowtype_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CollateExpr { + write_tag_into(mut buf, 29, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_collate_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CaseExpr { + write_tag_into(mut buf, 30, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_case_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CaseWhen { + write_tag_into(mut buf, 31, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_case_when_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CaseTestExpr { + write_tag_into(mut buf, 32, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_case_test_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ArrayExpr { + write_tag_into(mut buf, 33, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_array_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RowExpr { + write_tag_into(mut buf, 34, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_row_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RowCompareExpr { + write_tag_into(mut buf, 35, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_row_compare_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CoalesceExpr { + write_tag_into(mut buf, 36, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_coalesce_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MinMaxExpr { + write_tag_into(mut buf, 37, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_min_max_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SQLValueFunction { + write_tag_into(mut buf, 38, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_s_q_l_value_function_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + XmlExpr { + write_tag_into(mut buf, 39, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_xml_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonFormat { + write_tag_into(mut buf, 40, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_format_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonReturning { + write_tag_into(mut buf, 41, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_returning_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonValueExpr { + write_tag_into(mut buf, 42, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_value_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonConstructorExpr { + write_tag_into(mut buf, 43, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_constructor_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonIsPredicate { + write_tag_into(mut buf, 44, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_is_predicate_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonBehavior { + write_tag_into(mut buf, 45, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_behavior_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonExpr { + write_tag_into(mut buf, 46, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTablePath { + write_tag_into(mut buf, 47, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTablePathScan { + write_tag_into(mut buf, 48, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_scan_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTableSiblingJoin { + write_tag_into(mut buf, 49, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_sibling_join_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + NullTest { + write_tag_into(mut buf, 50, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_null_test_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + BooleanTest { + write_tag_into(mut buf, 51, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_boolean_test_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MergeAction { + write_tag_into(mut buf, 52, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_merge_action_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CoerceToDomain { + write_tag_into(mut buf, 53, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_coerce_to_domain_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CoerceToDomainValue { + write_tag_into(mut buf, 54, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_coerce_to_domain_value_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SetToDefault { + write_tag_into(mut buf, 55, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_set_to_default_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CurrentOfExpr { + write_tag_into(mut buf, 56, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_current_of_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + NextValueExpr { + write_tag_into(mut buf, 57, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_next_value_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + InferenceElem { + write_tag_into(mut buf, 58, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_inference_elem_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TargetEntry { + write_tag_into(mut buf, 59, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_target_entry_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTblRef { + write_tag_into(mut buf, 60, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_tbl_ref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JoinExpr { + write_tag_into(mut buf, 61, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_join_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FromExpr { + write_tag_into(mut buf, 62, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_from_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + OnConflictExpr { + write_tag_into(mut buf, 63, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_on_conflict_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Query { + write_tag_into(mut buf, 64, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_query_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TypeName { + write_tag_into(mut buf, 65, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_name_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ColumnRef { + write_tag_into(mut buf, 66, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_column_ref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ParamRef { + write_tag_into(mut buf, 67, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_param_ref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AExpr { + write_tag_into(mut buf, 68, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TypeCast { + write_tag_into(mut buf, 69, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_type_cast_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CollateClause { + write_tag_into(mut buf, 70, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_collate_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RoleSpec { + write_tag_into(mut buf, 71, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_role_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FuncCall { + write_tag_into(mut buf, 72, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_func_call_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AStar { + write_tag_into(mut buf, 73, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_star_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AIndices { + write_tag_into(mut buf, 74, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_indices_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AIndirection { + write_tag_into(mut buf, 75, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_indirection_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AArrayExpr { + write_tag_into(mut buf, 76, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_array_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ResTarget { + write_tag_into(mut buf, 77, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_res_target_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MultiAssignRef { + write_tag_into(mut buf, 78, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_multi_assign_ref_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SortBy { + write_tag_into(mut buf, 79, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_sort_by_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WindowDef { + write_tag_into(mut buf, 80, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_def_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeSubselect { + write_tag_into(mut buf, 81, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_subselect_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeFunction { + write_tag_into(mut buf, 82, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_function_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTableFunc { + write_tag_into(mut buf, 83, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_table_func_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTableFuncCol { + write_tag_into(mut buf, 84, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_table_func_col_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTableSample { + write_tag_into(mut buf, 85, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_table_sample_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ColumnDef { + write_tag_into(mut buf, 86, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_column_def_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TableLikeClause { + write_tag_into(mut buf, 87, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_table_like_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + IndexElem { + write_tag_into(mut buf, 88, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_index_elem_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DefElem { + write_tag_into(mut buf, 89, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_def_elem_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + LockingClause { + write_tag_into(mut buf, 90, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_locking_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + XmlSerialize { + write_tag_into(mut buf, 91, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_xml_serialize_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PartitionElem { + write_tag_into(mut buf, 92, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_elem_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PartitionSpec { + write_tag_into(mut buf, 93, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PartitionBoundSpec { + write_tag_into(mut buf, 94, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_bound_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PartitionRangeDatum { + write_tag_into(mut buf, 95, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_range_datum_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SinglePartitionSpec { + write_tag_into(mut buf, 96, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_single_partition_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PartitionCmd { + write_tag_into(mut buf, 97, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_partition_cmd_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTblEntry { + write_tag_into(mut buf, 98, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_tbl_entry_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RTEPermissionInfo { + write_tag_into(mut buf, 99, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_r_t_e_permission_info_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RangeTblFunction { + write_tag_into(mut buf, 100, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_range_tbl_function_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TableSampleClause { + write_tag_into(mut buf, 101, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_table_sample_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WithCheckOption { + write_tag_into(mut buf, 102, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_check_option_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SortGroupClause { + write_tag_into(mut buf, 103, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_sort_group_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + GroupingSet { + write_tag_into(mut buf, 104, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_grouping_set_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WindowClause { + write_tag_into(mut buf, 105, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_window_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RowMarkClause { + write_tag_into(mut buf, 106, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_row_mark_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + WithClause { + write_tag_into(mut buf, 107, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_with_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + InferClause { + write_tag_into(mut buf, 108, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_infer_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + OnConflictClause { + write_tag_into(mut buf, 109, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_on_conflict_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CTESearchClause { + write_tag_into(mut buf, 110, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_c_t_e_search_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CTECycleClause { + write_tag_into(mut buf, 111, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_c_t_e_cycle_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CommonTableExpr { + write_tag_into(mut buf, 112, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_common_table_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MergeWhenClause { + write_tag_into(mut buf, 113, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_merge_when_clause_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TriggerTransition { + write_tag_into(mut buf, 114, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_trigger_transition_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonOutput { + write_tag_into(mut buf, 115, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_output_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonArgument { + write_tag_into(mut buf, 116, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_argument_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonFuncExpr { + write_tag_into(mut buf, 117, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_func_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTablePathSpec { + write_tag_into(mut buf, 118, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_path_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTable { + write_tag_into(mut buf, 119, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonTableColumn { + write_tag_into(mut buf, 120, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_table_column_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonKeyValue { + write_tag_into(mut buf, 121, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_key_value_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonParseExpr { + write_tag_into(mut buf, 122, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_parse_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonScalarExpr { + write_tag_into(mut buf, 123, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_scalar_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonSerializeExpr { + write_tag_into(mut buf, 124, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_serialize_expr_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonObjectConstructor { + write_tag_into(mut buf, 125, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_object_constructor_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonArrayConstructor { + write_tag_into(mut buf, 126, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_array_constructor_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonArrayQueryConstructor { + write_tag_into(mut buf, 127, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_array_query_constructor_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonAggConstructor { + write_tag_into(mut buf, 128, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_agg_constructor_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonObjectAgg { + write_tag_into(mut buf, 129, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_object_agg_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + JsonArrayAgg { + write_tag_into(mut buf, 130, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_json_array_agg_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RawStmt { + write_tag_into(mut buf, 131, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_raw_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + InsertStmt { + write_tag_into(mut buf, 132, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_insert_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DeleteStmt { + write_tag_into(mut buf, 133, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_delete_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + UpdateStmt { + write_tag_into(mut buf, 134, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_update_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + MergeStmt { + write_tag_into(mut buf, 135, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_merge_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SelectStmt { + write_tag_into(mut buf, 136, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_select_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SetOperationStmt { + write_tag_into(mut buf, 137, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_set_operation_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ReturnStmt { + write_tag_into(mut buf, 138, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_return_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PLAssignStmt { + write_tag_into(mut buf, 139, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_p_l_assign_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateSchemaStmt { + write_tag_into(mut buf, 140, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_schema_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTableStmt { + write_tag_into(mut buf, 141, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_table_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ReplicaIdentityStmt { + write_tag_into(mut buf, 142, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_replica_identity_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTableCmd { + write_tag_into(mut buf, 143, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_table_cmd_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterCollationStmt { + write_tag_into(mut buf, 144, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_collation_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterDomainStmt { + write_tag_into(mut buf, 145, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_domain_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + GrantStmt { + write_tag_into(mut buf, 146, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_grant_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ObjectWithArgs { + write_tag_into(mut buf, 147, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_object_with_args_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AccessPriv { + write_tag_into(mut buf, 148, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_access_priv_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + GrantRoleStmt { + write_tag_into(mut buf, 149, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_grant_role_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterDefaultPrivilegesStmt { + write_tag_into(mut buf, 150, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_default_privileges_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CopyStmt { + write_tag_into(mut buf, 151, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_copy_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + VariableSetStmt { + write_tag_into(mut buf, 152, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_variable_set_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + VariableShowStmt { + write_tag_into(mut buf, 153, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_variable_show_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateStmt { + write_tag_into(mut buf, 154, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Constraint { + write_tag_into(mut buf, 155, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_constraint_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateTableSpaceStmt { + write_tag_into(mut buf, 156, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_table_space_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropTableSpaceStmt { + write_tag_into(mut buf, 157, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_table_space_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTableSpaceOptionsStmt { + write_tag_into(mut buf, 158, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_table_space_options_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTableMoveAllStmt { + write_tag_into(mut buf, 159, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_table_move_all_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateExtensionStmt { + write_tag_into(mut buf, 160, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_extension_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterExtensionStmt { + write_tag_into(mut buf, 161, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_extension_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterExtensionContentsStmt { + write_tag_into(mut buf, 162, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_extension_contents_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateFdwStmt { + write_tag_into(mut buf, 163, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_fdw_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterFdwStmt { + write_tag_into(mut buf, 164, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_fdw_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateForeignServerStmt { + write_tag_into(mut buf, 165, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_foreign_server_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterForeignServerStmt { + write_tag_into(mut buf, 166, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_foreign_server_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateForeignTableStmt { + write_tag_into(mut buf, 167, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_foreign_table_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateUserMappingStmt { + write_tag_into(mut buf, 168, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_user_mapping_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterUserMappingStmt { + write_tag_into(mut buf, 169, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_user_mapping_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropUserMappingStmt { + write_tag_into(mut buf, 170, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_user_mapping_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ImportForeignSchemaStmt { + write_tag_into(mut buf, 171, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_import_foreign_schema_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreatePolicyStmt { + write_tag_into(mut buf, 172, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_policy_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterPolicyStmt { + write_tag_into(mut buf, 173, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_policy_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateAmStmt { + write_tag_into(mut buf, 174, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_am_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateTrigStmt { + write_tag_into(mut buf, 175, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_trig_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateEventTrigStmt { + write_tag_into(mut buf, 176, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_event_trig_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterEventTrigStmt { + write_tag_into(mut buf, 177, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_event_trig_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreatePLangStmt { + write_tag_into(mut buf, 178, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_p_lang_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateRoleStmt { + write_tag_into(mut buf, 179, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_role_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterRoleStmt { + write_tag_into(mut buf, 180, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_role_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterRoleSetStmt { + write_tag_into(mut buf, 181, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_role_set_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropRoleStmt { + write_tag_into(mut buf, 182, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_role_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateSeqStmt { + write_tag_into(mut buf, 183, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_seq_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterSeqStmt { + write_tag_into(mut buf, 184, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_seq_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DefineStmt { + write_tag_into(mut buf, 185, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_define_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateDomainStmt { + write_tag_into(mut buf, 186, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_domain_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateOpClassStmt { + write_tag_into(mut buf, 187, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_op_class_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateOpClassItem { + write_tag_into(mut buf, 188, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_op_class_item_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateOpFamilyStmt { + write_tag_into(mut buf, 189, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_op_family_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterOpFamilyStmt { + write_tag_into(mut buf, 190, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_op_family_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropStmt { + write_tag_into(mut buf, 191, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TruncateStmt { + write_tag_into(mut buf, 192, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_truncate_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CommentStmt { + write_tag_into(mut buf, 193, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_comment_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + SecLabelStmt { + write_tag_into(mut buf, 194, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_sec_label_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DeclareCursorStmt { + write_tag_into(mut buf, 195, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_declare_cursor_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ClosePortalStmt { + write_tag_into(mut buf, 196, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_close_portal_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FetchStmt { + write_tag_into(mut buf, 197, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_fetch_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + IndexStmt { + write_tag_into(mut buf, 198, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_index_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateStatsStmt { + write_tag_into(mut buf, 199, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_stats_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + StatsElem { + write_tag_into(mut buf, 200, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_stats_elem_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterStatsStmt { + write_tag_into(mut buf, 201, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_stats_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateFunctionStmt { + write_tag_into(mut buf, 202, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_function_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + FunctionParameter { + write_tag_into(mut buf, 203, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_function_parameter_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterFunctionStmt { + write_tag_into(mut buf, 204, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_function_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DoStmt { + write_tag_into(mut buf, 205, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_do_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + InlineCodeBlock { + write_tag_into(mut buf, 206, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_inline_code_block_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CallStmt { + write_tag_into(mut buf, 207, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_call_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CallContext { + write_tag_into(mut buf, 208, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_call_context_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RenameStmt { + write_tag_into(mut buf, 209, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_rename_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterObjectDependsStmt { + write_tag_into(mut buf, 210, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_object_depends_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterObjectSchemaStmt { + write_tag_into(mut buf, 211, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_object_schema_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterOwnerStmt { + write_tag_into(mut buf, 212, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_owner_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterOperatorStmt { + write_tag_into(mut buf, 213, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_operator_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTypeStmt { + write_tag_into(mut buf, 214, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_type_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RuleStmt { + write_tag_into(mut buf, 215, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_rule_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + NotifyStmt { + write_tag_into(mut buf, 216, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_notify_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ListenStmt { + write_tag_into(mut buf, 217, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_listen_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + UnlistenStmt { + write_tag_into(mut buf, 218, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_unlisten_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + TransactionStmt { + write_tag_into(mut buf, 219, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_transaction_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CompositeTypeStmt { + write_tag_into(mut buf, 220, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_composite_type_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateEnumStmt { + write_tag_into(mut buf, 221, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_enum_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateRangeStmt { + write_tag_into(mut buf, 222, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_range_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterEnumStmt { + write_tag_into(mut buf, 223, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_enum_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ViewStmt { + write_tag_into(mut buf, 224, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_view_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + LoadStmt { + write_tag_into(mut buf, 225, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_load_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreatedbStmt { + write_tag_into(mut buf, 226, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_createdb_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterDatabaseStmt { + write_tag_into(mut buf, 227, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_database_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterDatabaseRefreshCollStmt { + write_tag_into(mut buf, 228, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_database_refresh_coll_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterDatabaseSetStmt { + write_tag_into(mut buf, 229, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_database_set_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropdbStmt { + write_tag_into(mut buf, 230, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_dropdb_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterSystemStmt { + write_tag_into(mut buf, 231, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_system_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ClusterStmt { + write_tag_into(mut buf, 232, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_cluster_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + VacuumStmt { + write_tag_into(mut buf, 233, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_vacuum_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + VacuumRelation { + write_tag_into(mut buf, 234, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_vacuum_relation_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ExplainStmt { + write_tag_into(mut buf, 235, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_explain_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateTableAsStmt { + write_tag_into(mut buf, 236, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_table_as_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + RefreshMatViewStmt { + write_tag_into(mut buf, 237, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_refresh_mat_view_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CheckPointStmt { + write_tag_into(mut buf, 238, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_check_point_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DiscardStmt { + write_tag_into(mut buf, 239, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_discard_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + LockStmt { + write_tag_into(mut buf, 240, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_lock_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ConstraintsSetStmt { + write_tag_into(mut buf, 241, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_constraints_set_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ReindexStmt { + write_tag_into(mut buf, 242, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_reindex_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateConversionStmt { + write_tag_into(mut buf, 243, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_conversion_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateCastStmt { + write_tag_into(mut buf, 244, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_cast_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateTransformStmt { + write_tag_into(mut buf, 245, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_transform_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PrepareStmt { + write_tag_into(mut buf, 246, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_prepare_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ExecuteStmt { + write_tag_into(mut buf, 247, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_execute_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DeallocateStmt { + write_tag_into(mut buf, 248, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_deallocate_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropOwnedStmt { + write_tag_into(mut buf, 249, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_owned_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + ReassignOwnedStmt { + write_tag_into(mut buf, 250, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_reassign_owned_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTSDictionaryStmt { + write_tag_into(mut buf, 251, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_t_s_dictionary_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterTSConfigurationStmt { + write_tag_into(mut buf, 252, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_t_s_configuration_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PublicationTable { + write_tag_into(mut buf, 253, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_publication_table_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + PublicationObjSpec { + write_tag_into(mut buf, 254, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_publication_obj_spec_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreatePublicationStmt { + write_tag_into(mut buf, 255, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_publication_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterPublicationStmt { + write_tag_into(mut buf, 256, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_publication_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + CreateSubscriptionStmt { + write_tag_into(mut buf, 257, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_create_subscription_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AlterSubscriptionStmt { + write_tag_into(mut buf, 258, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_alter_subscription_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + DropSubscriptionStmt { + write_tag_into(mut buf, 259, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_drop_subscription_stmt_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Integer { + write_tag_into(mut buf, 260, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_integer_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Float { + write_tag_into(mut buf, 261, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_float_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + Boolean { + write_tag_into(mut buf, 262, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_boolean_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + String { + write_tag_into(mut buf, 263, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_string_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + BitString { + write_tag_into(mut buf, 264, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_bit_string_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + List { + write_tag_into(mut buf, 265, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_list_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + IntList { + write_tag_into(mut buf, 266, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_int_list_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + OidList { + write_tag_into(mut buf, 267, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_oid_list_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + AConst { + write_tag_into(mut buf, 268, 2) + len_pos_ := buf.len + write_u32_placeholder(mut buf) + cs_ := buf.len + encode_a_const_into(mut buf, val_) + backpatch_varint4(mut buf, len_pos_, buf.len - cs_) + } + UnrecognizedNode { + write_tag_into(mut buf, val_.field_num, 2) + write_length_delimited_into(mut buf, val_.data) + } + } +} + +fn encode_node(val_ Node) []u8 { + mut buf := []u8{} + encode_node_into(mut buf, val_) + return buf +} + +pub fn encode_parse_result(val ParseAstResult) []u8 { + mut buf := []u8{cap: 2048} + write_tag_into(mut buf, 1, 0) + write_varint_into(mut buf, u64(val.version)) + for s in val.stmts { + write_tag_into(mut buf, 2, 2) + outer_len_pos_ := buf.len + write_u32_placeholder(mut buf) + outer_cs_ := buf.len + stmt_tag_start_ := buf.len + write_tag_into(mut buf, 1, 2) + stmt_len_pos_ := buf.len + write_u32_placeholder(mut buf) + stmt_cs_ := buf.len + encode_node_into(mut buf, s.stmt) + if buf.len == stmt_cs_ { unsafe { buf = buf[..stmt_tag_start_] } } else { backpatch_varint4(mut buf, stmt_len_pos_, buf.len - stmt_cs_) } + write_tag_into(mut buf, 2, 0) + write_varint_into(mut buf, u64(s.stmt_location)) + write_tag_into(mut buf, 3, 0) + write_varint_into(mut buf, u64(s.stmt_len)) + backpatch_varint4(mut buf, outer_len_pos_, buf.len - outer_cs_) + } + return buf +} + diff --git a/pg_query/pg_query_protobuf.v b/pg_query_protobuf.v similarity index 92% rename from pg_query/pg_query_protobuf.v rename to pg_query_protobuf.v index 5146b47..4ff47f0 100644 --- a/pg_query/pg_query_protobuf.v +++ b/pg_query_protobuf.v @@ -261,8 +261,8 @@ fn write_bool(val bool) []u8 { // write_string encodes a string as length-delimited bytes. fn write_string(s string) []u8 { mut buf := write_varint(u64(s.len)) - for c in s { - buf << c + if s.len > 0 { + buf << unsafe { (&u8(s.str)).vbytes(s.len) } } return buf } @@ -320,6 +320,7 @@ fn write_map_string_entry(key string, val string) []u8 { // Used by generated pg_query_encode.v to avoid per-field heap allocations. // --------------------------------------------------------------------------- +@[inline] fn write_varint_into(mut buf []u8, v u64) { mut val := v for { @@ -339,6 +340,7 @@ fn write_svarint_into(mut buf []u8, v i64) { write_varint_into(mut buf, (u64(v) << 1) ^ u64(v >> 63)) } +@[inline] fn write_tag_into(mut buf []u8, field_num int, wire_type int) { write_varint_into(mut buf, (u64(field_num) << 3) | u64(wire_type)) } @@ -347,10 +349,11 @@ fn write_bool_into(mut buf []u8, val bool) { buf << if val { u8(1) } else { u8(0) } } +@[inline] fn write_string_into(mut buf []u8, s string) { write_varint_into(mut buf, u64(s.len)) - for c in s { - buf << c + if s.len > 0 { + buf << unsafe { (&u8(s.str)).vbytes(s.len) } } } @@ -394,6 +397,27 @@ fn write_length_delimited_into(mut buf []u8, sub []u8) { buf << sub } +// write_u32_placeholder appends 4 zero bytes as a length placeholder. +// The caller must later call backpatch_varint4 at the returned position. +fn write_u32_placeholder(mut buf []u8) { + buf << u8(0) + buf << u8(0) + buf << u8(0) + buf << u8(0) +} + +// backpatch_varint4 writes a padded 4-byte protobuf varint for `length` at +// buf[pos..pos+4]. Padded varints are valid wire format — all standard decoders +// accept multi-byte encodings of any value. Constraint: length < 2^28 (~268 MB). +@[direct_array_access] +fn backpatch_varint4(mut buf []u8, pos int, length int) { + v := u32(length) + buf[pos] = u8(v & 0x7F) | 0x80 + buf[pos + 1] = u8((v >> 7) & 0x7F) | 0x80 + buf[pos + 2] = u8((v >> 14) & 0x7F) | 0x80 + buf[pos + 3] = u8((v >> 21) & 0x7F) +} + // read_map_string_entry decodes a single protobuf map entry submessage // for map. Returns (key, value) strings. fn read_map_string_entry(buf []u8) (string, string) { diff --git a/pg_query/pg_query_test.v b/pg_query_test.v similarity index 80% rename from pg_query/pg_query_test.v rename to pg_query_test.v index dc22696..26d1e7c 100644 --- a/pg_query/pg_query_test.v +++ b/pg_query_test.v @@ -343,3 +343,75 @@ fn test_parse_protobuf_ast_invalid_sql_handled() { parse_protobuf_ast('SELECT $$$') or { return } // If no error, verify result is empty } + +fn test_deparse_comments_extract_single_line() { + result := deparse_comments_for_query('SELECT 1 -- a single-line comment') or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert result.comments.len == 1 + assert result.comments[0].str.contains('--') + assert result.comments[0].str.contains('a single-line comment') +} + +fn test_deparse_comments_extract_block() { + result := deparse_comments_for_query('SELECT 1 /* a block comment */') or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert result.comments.len == 1 + assert result.comments[0].str.contains('/*') + assert result.comments[0].str.contains('a block comment') +} + +fn test_deparse_comments_extract_mixed() { + result := deparse_comments_for_query('SELECT 1; -- line comment\nSELECT 2 /* block */') or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert result.comments.len >= 2 +} + +fn test_deparse_comments_no_comments() { + result := deparse_comments_for_query('SELECT 1') or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert result.comments.len == 0 +} + +fn test_deparse_comments_roundtrip() { + // Inline comments between AST nodes are preserved. + // Trailing comments at the end of a statement are not (C lib limitation). + query := 'SELECT a, /* my comment */ b FROM t' + pb := parse_protobuf(query) or { + assert false, 'parse_protobuf failed: ${err}' + return + } + comments_res := deparse_comments_for_query(query) or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert comments_res.comments.len == 1 + opts := DeparseOpts{ + comments: comments_res.comments + } + result := deparse_protobuf_opts(pb.parse_tree, opts) or { + assert false, 'deparse_protobuf_opts failed: ${err}' + return + } + assert result.query.contains('/* my comment */') + assert result.query.contains('SELECT') + assert result.query.contains('FROM') +} + +fn test_deparse_comments_multiline_block() { + query := 'SELECT 1 /*\nmulti\nline\n*/' + result := deparse_comments_for_query(query) or { + assert false, 'deparse_comments_for_query failed: ${err}' + return + } + assert result.comments.len == 1 + assert result.comments[0].str.contains('multi') + assert result.comments[0].str.contains('line') +} diff --git a/pg_query/pgquery.c.v b/pgquery.c.v similarity index 60% rename from pg_query/pgquery.c.v rename to pgquery.c.v index dae66fa..5d7a58b 100644 --- a/pg_query/pgquery.c.v +++ b/pgquery.c.v @@ -1,14 +1,10 @@ module pg_query -#flag -I @VMODROOT/libpg_query -#flag -I @VMODROOT/pg_query -#flag -I @VMODROOT/libpg_query/vendor -#flag @VMODROOT/libpg_query/libpg_query.a -#flag @VMODROOT/pg_query/c_bridge.o +#flag -I @VMODROOT/c +#flag -I @VMODROOT/c/vendor +#flag @VMODROOT/c/libpg_query.a #flag linux -pthread #include "pg_query.h" -#include "c_bridge.h" - @[typedef] pub struct C.PgQueryError { message &char @@ -68,7 +64,7 @@ pub struct C.PgQuerySplitStmt { @[typedef] pub struct C.PgQuerySplitResult { - stmts voidptr + stmts &&C.PgQuerySplitStmt n_stmts int stderr_buffer &char error &C.PgQueryError @@ -88,13 +84,22 @@ pub struct C.PostgresDeparseComment { str &char } -// C.PostgresDeparseOpts is intentionally opaque — all field access -// goes through C bridge setters in c_bridge.c to avoid ABI coupling. -// If you need to add/remove fields, update c_bridge.c bridge functions only. +// PostgresDeparseOpts is fully visible now — constructed directly in V. +// comments is voidptr to avoid V `&&T` cast issues; binary layout is identical. +@[typedef] +pub struct C.PostgresDeparseOpts { + comments voidptr + comment_count usize + pretty_print bool + indent_size int + max_line_length int + trailing_newline bool + commas_start_of_line bool +} @[typedef] pub struct C.PgQueryDeparseCommentsResult { - comments voidptr + comments &&C.PostgresDeparseComment comment_count usize error &C.PgQueryError } @@ -108,7 +113,7 @@ pub struct C.PgQueryPlpgsqlParseResult { @[typedef] pub struct C.PgQueryIsUtilityResult { length int - items voidptr + items &bool error &C.PgQueryError } @@ -119,18 +124,19 @@ pub struct C.PgQuerySummaryParseResult { error &C.PgQueryError } -// Parse mode enum -pub const pg_query_parse_default = C.PG_QUERY_PARSE_DEFAULT -pub const pg_query_parse_type_name = C.PG_QUERY_PARSE_TYPE_NAME -pub const pg_query_parse_plpgsql_expr = C.PG_QUERY_PARSE_PLPGSQL_EXPR -pub const pg_query_parse_plpgsql_assign1 = C.PG_QUERY_PARSE_PLPGSQL_ASSIGN1 -pub const pg_query_parse_plpgsql_assign2 = C.PG_QUERY_PARSE_PLPGSQL_ASSIGN2 -pub const pg_query_parse_plpgsql_assign3 = C.PG_QUERY_PARSE_PLPGSQL_ASSIGN3 - -// Parse option flags -pub const pg_query_disable_backslash_quote = C.PG_QUERY_DISABLE_BACKSLASH_QUOTE -pub const pg_query_disable_standard_conforming_strings = C.PG_QUERY_DISABLE_STANDARD_CONFORMING_STRINGS -pub const pg_query_disable_escape_string_warning = C.PG_QUERY_DISABLE_ESCAPE_STRING_WARNING +// C macros hardcoded as V consts (only change on PG version bumps) +pub const pg_query_parse_default = 0 +pub const pg_query_parse_type_name = 1 +pub const pg_query_parse_plpgsql_expr = 2 +pub const pg_query_parse_plpgsql_assign1 = 3 +pub const pg_query_parse_plpgsql_assign2 = 4 +pub const pg_query_parse_plpgsql_assign3 = 5 +pub const pg_query_disable_backslash_quote = 16 +pub const pg_query_disable_standard_conforming_strings = 32 +pub const pg_query_disable_escape_string_warning = 64 +pub const pg_version_num = 170007 +pub const pg_version_str = '17.7' +pub const pg_major_version_str = '17' // Parse functions fn C.pg_query_parse(const_input &char) C.PgQueryParseResult @@ -156,8 +162,8 @@ fn C.pg_query_split_with_parser(const_input &char) C.PgQuerySplitResult // Deparse functions fn C.pg_query_deparse_protobuf(parse_tree C.PgQueryProtobuf) C.PgQueryDeparseResult -fn C.pg_query_deparse_protobuf_opts(parse_tree C.PgQueryProtobuf, opts voidptr) C.PgQueryDeparseResult -fn C.pg_query_is_utility_stmt(const_input &char) C.PgQueryIsUtilityResult +fn C.pg_query_deparse_protobuf_opts(parse_tree C.PgQueryProtobuf, opts C.PostgresDeparseOpts) C.PgQueryDeparseResult +fn C.pg_query_is_utility_stmt(const_query &char) C.PgQueryIsUtilityResult fn C.pg_query_deparse_comments_for_query(const_query &char) C.PgQueryDeparseCommentsResult // Summary @@ -179,23 +185,4 @@ fn C.pg_query_free_summary_parse_result(result C.PgQuerySummaryParseResult) // Lifecycle fn C.pg_query_exit() -// Bridge helpers (c_bridge.c) — all PostgresDeparseOpts access via voidptr -fn C.pg_query_bridge_split_stmts_get(stmts voidptr, index int) voidptr -fn C.pg_query_bridge_deparse_comments_get(comments voidptr, index usize) voidptr -fn C.pg_query_bridge_pg_version() &char -fn C.pg_query_bridge_pg_major_version() &char -fn C.pg_query_bridge_deparse_opts_new() voidptr -fn C.pg_query_bridge_deparse_opts_set_pretty_print(opts voidptr, val int) -fn C.pg_query_bridge_deparse_opts_set_indent_size(opts voidptr, val int) -fn C.pg_query_bridge_deparse_opts_set_max_line_length(opts voidptr, val int) -fn C.pg_query_bridge_deparse_opts_set_trailing_newline(opts voidptr, val int) -fn C.pg_query_bridge_deparse_opts_set_commas_start_of_line(opts voidptr, val int) -fn C.pg_query_bridge_deparse_opts_set_comment_count(opts voidptr, count usize) -fn C.pg_query_bridge_deparse_opts_init_comments(opts voidptr, count usize) -fn C.pg_query_bridge_deparse_opts_set_comment(opts voidptr, index usize, location int, newlines_before int, newlines_after int, const_str &char) -fn C.pg_query_bridge_deparse_opts_free(opts voidptr) -fn C.pg_query_bridge_deparse_protobuf_opts(parse_tree C.PgQueryProtobuf, opts voidptr) C.PgQueryDeparseResult - -// Protobuf bridge functions -fn C.pg_query_bridge_parse_ast_direct(const_input &char, parser_options int) voidptr -fn C.pg_query_bridge_free_ast_result(ptr voidptr) + diff --git a/pg_query/pgquery.v b/pgquery.v similarity index 85% rename from pg_query/pgquery.v rename to pgquery.v index 5f7cbef..743d9d2 100644 --- a/pg_query/pgquery.v +++ b/pgquery.v @@ -62,7 +62,7 @@ pub fn deparse_ast(result ParseAstResult) !string { fn protobuf_from_bytes(buf []u8) Protobuf { return Protobuf{ - len: usize(buf.len) + len: usize(buf.len) data: buf.bytestr() } } @@ -79,8 +79,6 @@ pub: stderr_buffer string } - - pub struct SplitStmt { pub: stmt_location int @@ -108,6 +106,7 @@ pub: } pub struct DeparseOpts { +pub: comments []DeparseComment pretty_print bool indent_size int @@ -134,12 +133,12 @@ pub: pub struct PgError { pub: - message string - funcname string - filename string - lineno int - cursorpos int - context string + message string + funcname string + filename string + lineno int + cursorpos int + context string } pub fn (e PgError) msg() string { @@ -161,13 +160,13 @@ fn pg_error_from(err &C.PgQueryError) ?PgError { if err == unsafe { nil } { return none } - return PgError{ - message: cstring(err.message) - funcname: cstring(err.funcname) - filename: cstring(err.filename) - lineno: err.lineno - cursorpos: err.cursorpos - context: cstring(err.context) + return PgError{ + message: cstring(err.message) + funcname: cstring(err.funcname) + filename: cstring(err.filename) + lineno: err.lineno + cursorpos: err.cursorpos + context: cstring(err.context) } } @@ -228,13 +227,13 @@ pub fn parse_json_ast(json_string string) !ParseAstResult { for s in json_res.stmts { stmts << AstRawStmt{ stmt_location: s.stmt_location - stmt_len: s.stmt_len - stmt: decode_node_json(s.stmt) + stmt_len: s.stmt_len + stmt: decode_node_json(s.stmt) } } return ParseAstResult{ version: json_res.version - stmts: stmts + stmts: stmts } } @@ -425,9 +424,18 @@ pub fn deparse_protobuf_opts(pb Protobuf, opts DeparseOpts) !DeparseResult { c_pb := protobuf_to_c(pb) c_opts := deparse_opts_to_c(opts) defer { - C.pg_query_bridge_deparse_opts_free(c_opts) + if c_opts.comment_count > 0 { + unsafe { + n := int(c_opts.comment_count) + arr := &voidptr(c_opts.comments) + for i in 0 .. n { + C.free(arr[i]) + } + C.free(c_opts.comments) + } + } } - res := C.pg_query_bridge_deparse_protobuf_opts(c_pb, c_opts) + res := C.pg_query_deparse_protobuf_opts(c_pb, c_opts) if pe := pg_error_from(res.error) { C.pg_query_free_deparse_result(res) return pe @@ -493,11 +501,11 @@ pub fn exit() { // Postgres version information. pub fn pg_version() string { - return cstring(C.pg_query_bridge_pg_version()) + return pg_version_str } pub fn pg_major_version() string { - return cstring(C.pg_query_bridge_pg_major_version()) + return pg_major_version_str } pub fn pg_version_num() int { @@ -548,30 +556,43 @@ fn split_stmts_from_c(res C.PgQuerySplitResult) []SplitStmt { return [] } mut stmts := []SplitStmt{len: res.n_stmts} - for i in 0 .. res.n_stmts { - stmt_ptr := C.pg_query_bridge_split_stmts_get(res.stmts, i) - c_stmt := unsafe { &C.PgQuerySplitStmt(stmt_ptr) } - stmts[i] = SplitStmt{ - stmt_location: c_stmt.stmt_location - stmt_len: c_stmt.stmt_len + unsafe { + for i in 0 .. res.n_stmts { + c_stmt := res.stmts[i] + stmts[i] = SplitStmt{ + stmt_location: c_stmt.stmt_location + stmt_len: c_stmt.stmt_len + } } } return stmts } -fn deparse_opts_to_c(opts DeparseOpts) voidptr { - mut c_opts := C.pg_query_bridge_deparse_opts_new() - C.pg_query_bridge_deparse_opts_set_comment_count(c_opts, usize(opts.comments.len)) - C.pg_query_bridge_deparse_opts_set_pretty_print(c_opts, opts.pretty_print) - C.pg_query_bridge_deparse_opts_set_indent_size(c_opts, opts.indent_size) - C.pg_query_bridge_deparse_opts_set_max_line_length(c_opts, opts.max_line_length) - C.pg_query_bridge_deparse_opts_set_trailing_newline(c_opts, opts.trailing_newline) - C.pg_query_bridge_deparse_opts_set_commas_start_of_line(c_opts, opts.commas_start_of_line) +fn deparse_opts_to_c(opts DeparseOpts) C.PostgresDeparseOpts { + mut c_opts := C.PostgresDeparseOpts{ + comments: unsafe { nil } + comment_count: usize(0) + pretty_print: opts.pretty_print + indent_size: opts.indent_size + max_line_length: opts.max_line_length + trailing_newline: opts.trailing_newline + commas_start_of_line: opts.commas_start_of_line + } if opts.comments.len > 0 { - C.pg_query_bridge_deparse_opts_init_comments(c_opts, usize(opts.comments.len)) - for i, comment in opts.comments { - C.pg_query_bridge_deparse_opts_set_comment(c_opts, usize(i), comment.match_location, - comment.newlines_before_comment, comment.newlines_after_comment, comment.str.str) + unsafe { + n := opts.comments.len + raw := C.calloc(usize(n), usize(8)) + arr := &voidptr(raw) + for i in 0 .. n { + c := &C.PostgresDeparseComment(C.calloc(1, usize(sizeof(C.PostgresDeparseComment)))) + c.match_location = opts.comments[i].match_location + c.newlines_before_comment = opts.comments[i].newlines_before_comment + c.newlines_after_comment = opts.comments[i].newlines_after_comment + c.str = opts.comments[i].str.str + arr[i] = voidptr(c) + } + c_opts.comments = raw + c_opts.comment_count = usize(n) } } return c_opts @@ -582,14 +603,15 @@ fn deparse_comments_from_c(res C.PgQueryDeparseCommentsResult) []DeparseComment return [] } mut comments := []DeparseComment{len: int(res.comment_count)} - for i in 0 .. res.comment_count { - comment_ptr := C.pg_query_bridge_deparse_comments_get(res.comments, i) - c := unsafe { &C.PostgresDeparseComment(comment_ptr) } - comments[i] = DeparseComment{ - match_location: c.match_location - newlines_before_comment: c.newlines_before_comment - newlines_after_comment: c.newlines_after_comment - str: cstring(c.str) + unsafe { + for i in 0 .. res.comment_count { + c := res.comments[i] + comments[i] = DeparseComment{ + match_location: c.match_location + newlines_before_comment: c.newlines_before_comment + newlines_after_comment: c.newlines_after_comment + str: cstring(c.str) + } } } return comments @@ -600,7 +622,7 @@ fn is_utility_items_from_c(res C.PgQueryIsUtilityResult) []bool { return [] } mut items := []bool{len: res.length} - ptr := unsafe { &u8(res.items) } + ptr := unsafe { &u8(voidptr(res.items)) } for i in 0 .. res.length { items[i] = unsafe { ptr[i] } != 0 } diff --git a/tools/gen_ast.v b/tools/gen_ast.v index 8584d02..3d7bd4f 100644 --- a/tools/gen_ast.v +++ b/tools/gen_ast.v @@ -1,8 +1,8 @@ // pg_query.v AST generator // Reads protobuf/pg_query.proto and generates: -// pg_query/pg_query_ast.v - V AST struct definitions (JSON decode path) -// pg_query/pg_query_ast_c.h - C header with V-compatible structs (direct bridge) -// pg_query/protobuf_bridge.c - C bridge with converter functions +// pg_query_ast.v - V AST struct definitions +// pg_query_decode.v - V-native protobuf decode +// pg_query_encode.v - V-native protobuf encode import os @@ -532,7 +532,7 @@ fn generate_code(pf ProtoFile) { } // ============================================================ -// Generate pg_query/pg_query_ast.v (V struct definitions) +// Generate pg_query_ast.v (V struct definitions) // ============================================================ fn generate_str_method(m ProtoMessage, pf ProtoFile) string { @@ -553,7 +553,7 @@ fn generate_str_method(m ProtoMessage, pf ProtoFile) string { } else if f.is_map { out += '\tif m.${vfname}.len > 0 { parts << "${vfname}: \${m.${vfname}}" }\n' } else if is_recursive { - out += '\tif !isnil(m.${vfname}) { parts << "${vfname}: \${m.${vfname}}" }\n' + out += '\tif m.${vfname} != none { parts << "${vfname}: \${m.${vfname}}" }\n' } else if is_primitive_proto(f.typ) { if f.typ == 'bool' { out += '\tif m.${vfname} { parts << "${vfname}: true" }\n' @@ -623,7 +623,7 @@ fn generate_v_ast(pf ProtoFile, node_oneof_fields []ProtoField) { is_recursive := f.typ == m.name mut v_field_type := vtype if is_recursive { - v_field_type = '&${vtype}' + v_field_type = '?&${vtype}' } if f.repeated { v_field_type = '[]${v_field_type}' @@ -789,11 +789,11 @@ fn generate_v_ast(pf ProtoFile, node_oneof_fields []ProtoField) { out += '\t}\n' out += '}\n\n' - os.write_file('pg_query/pg_query_ast.v', out) or { + os.write_file('pg_query_ast.v', out) or { eprintln('Failed to write pg_query_ast.v: ${err}') return } - println('Generated pg_query/pg_query_ast.v (${out.len} bytes, ${pf.messages.len} messages, ${pf.enums.len} enums)') + println('Generated pg_query_ast.v (${out.len} bytes, ${pf.messages.len} messages, ${pf.enums.len} enums)') } // Topological sort messages so dependencies are defined before dependents @@ -818,7 +818,7 @@ fn topological_sort_messages(pf ProtoFile) []ProtoMessage { for f in m.fields { if f.is_oneof { continue } if f.repeated { continue } - if f.typ == m.name { continue } // self-ref uses pointer + if f.typ == m.name { continue } // self-ref uses optional pointer if f.typ == 'Node' { continue } // VNode already defined if f.typ == 'Context' { continue } if is_primitive_proto(f.typ) { continue } @@ -892,7 +892,7 @@ fn topological_sort_messages(pf ProtoFile) []ProtoMessage { } // ============================================================ -// Generate pg_query/pg_query_decode.v (V-native protobuf decode) +// Generate pg_query_decode.v (V-native protobuf decode) // ============================================================ fn generate_v_protobuf_decode(pf ProtoFile, node_oneof_fields []ProtoField) { mut out := '' @@ -942,7 +942,7 @@ fn generate_v_protobuf_decode(pf ProtoFile, node_oneof_fields []ProtoField) { mut inner := '' for irfn in direct_ref_types[f.typ] { if inner.len > 0 { inner += '\n' } - inner += '\t\t\t${irfn}: unsafe { nil }' + inner += '\t\t\t${irfn}: none' } transitive_init << '\t\t${vfname}: ${vftype}{\n${inner}\n\t\t}' } @@ -960,7 +960,7 @@ fn generate_v_protobuf_decode(pf ProtoFile, node_oneof_fields []ProtoField) { if needs_unsafe_init || has_maps { out += '\tif depth <= 0 { return ${vname}{\n' for rfn in ref_field_names { - out += '\t\t${rfn}: unsafe { nil }\n' + out += '\t\t${rfn}: none\n' } for ti in transitive_init { out += '\t\t' + ti.trim_left('\t') + '\n' @@ -971,7 +971,7 @@ fn generate_v_protobuf_decode(pf ProtoFile, node_oneof_fields []ProtoField) { out += '\t}, 0 }\n' out += '\tmut r := ${vname}{\n' for rfn in ref_field_names { - out += '\t\t${rfn}: unsafe { nil }\n' + out += '\t\t${rfn}: none\n' } for ti in transitive_init { out += '\t' + ti + '\n' @@ -1068,11 +1068,11 @@ fn generate_v_protobuf_decode(pf ProtoFile, node_oneof_fields []ProtoField) { out += '\t}\n' out += '}\n\n' - os.write_file('pg_query/pg_query_decode.v', out) or { + os.write_file('pg_query_decode.v', out) or { eprintln('Failed to write pg_query_decode.v: ${err}') return } - println('Generated pg_query/pg_query_decode.v (${out.len} bytes)') + println('Generated pg_query_decode.v (${out.len} bytes)') } fn proto_decode_field_case(f ProtoField, vname string, msg_name string, pf ProtoFile) string { @@ -1409,7 +1409,7 @@ fn proto_decode_oneof_field_case(f ProtoField, vname string, pf ProtoFile) strin } // ============================================================ -// Generate pg_query/pg_query_encode.v (V-native protobuf encode) +// Generate pg_query_encode.v (V-native protobuf encode) // ============================================================ fn generate_v_protobuf_encode(pf ProtoFile, node_oneof_fields []ProtoField) { mut out := '' @@ -1426,81 +1426,107 @@ fn generate_v_protobuf_encode(pf ProtoFile, node_oneof_fields []ProtoField) { if m.name in skip_names { continue } vname := proto_field_to_v_type(m.name) dfn := snake_case(vname) - out += 'pub fn encode_${dfn}(val ${vname}) []u8 {\n' - out += '\tmut buf := []u8{}\n' - // Sort fields by field number + // Sort fields by field number once mut sorted_fields := m.fields.clone() sorted_fields.sort(a.field_num < b.field_num) + + // Zero-alloc _into variant: writes directly into caller's buffer. + out += 'fn encode_${dfn}_into(mut buf []u8, val ${vname}) {\n' for f in sorted_fields { vfname := snake_case(f.name) if f.is_oneof { - out += proto_encode_oneof_field(f, vfname, pf, node_oneof_fields, m.name) + out += proto_encode_oneof_field_into(f, vfname, pf, node_oneof_fields, m.name) } else if f.repeated { - out += proto_encode_repeated_field(f, vfname, pf, node_oneof_fields) + out += proto_encode_repeated_field_into(f, vfname, pf, node_oneof_fields) } else if f.is_map { - out += proto_encode_map_field(f, vfname) + out += proto_encode_map_field(f, vfname) // maps are rare; keep as-is } else { - out += proto_encode_singular_field(f, vfname, pf, node_oneof_fields, m.name) + out += proto_encode_singular_field_into(f, vfname, pf, node_oneof_fields, m.name) } } + out += '}\n\n' + + // Public wrapper kept for external callers. + out += 'pub fn encode_${dfn}(val ${vname}) []u8 {\n' + out += '\tmut buf := []u8{}\n' + out += '\tencode_${dfn}_into(mut buf, val)\n' out += '\treturn buf\n' out += '}\n\n' } - // encode_node dispatcher - // Alias is the zero-value default for the Node sum type (first variant). - // When an Alias with no non-zero fields is encoded, we skip the tag + - // submessage wrapper to avoid creating a spurious empty node. - // All other variants are always encoded (they were explicitly constructed). - out += 'fn encode_node(val_ Node) []u8 {\n' + // encode_node_into: zero-alloc Node dispatcher using backpatch varint. + // Writes tag + padded-4-byte-len + content directly into caller's buf. + // Alias is the zero-value default — backtrack if it encodes to nothing. + out += 'fn encode_node_into(mut buf []u8, val_ Node) {\n' out += '\tmatch val_ {\n' for f in node_oneof_fields { vname := proto_field_to_v_type(f.typ) out += '\t\t${vname} {\n' - out += '\t\t\tinner := encode_${snake_case(vname)}(val_)\n' if vname == 'Alias' { - out += '\t\t\tif inner.len == 0 { return []u8{} }\n' + // Alias may be zero-value default; backtrack if empty. + out += '\t\t\ttag_start_ := buf.len\n' + out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\t\tlen_pos_ := buf.len\n' + out += '\t\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\t\tcs_ := buf.len\n' + out += '\t\t\tencode_${snake_case(vname)}_into(mut buf, val_)\n' + out += '\t\t\tif buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) }\n' + } else { + out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\t\tlen_pos_ := buf.len\n' + out += '\t\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\t\tcs_ := buf.len\n' + out += '\t\t\tencode_${snake_case(vname)}_into(mut buf, val_)\n' + out += '\t\t\tbackpatch_varint4(mut buf, len_pos_, buf.len - cs_)\n' } - out += '\t\t\tmut buf := []u8{}\n' - out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' - out += '\t\t\twrite_length_delimited_into(mut buf, inner)\n' - out += '\t\t\treturn buf\n' out += '\t\t}\n' } out += '\t\tUnrecognizedNode {\n' - out += '\t\t\tmut buf := []u8{}\n' out += '\t\t\twrite_tag_into(mut buf, val_.field_num, 2)\n' out += '\t\t\twrite_length_delimited_into(mut buf, val_.data)\n' - out += '\t\t\treturn buf\n' out += '\t\t}\n' out += '\t}\n' out += '}\n\n' - // encode_parse_result entry point + // encode_node: public wrapper calling encode_node_into. + out += 'fn encode_node(val_ Node) []u8 {\n' + out += '\tmut buf := []u8{}\n' + out += '\tencode_node_into(mut buf, val_)\n' + out += '\treturn buf\n' + out += '}\n\n' + + // encode_parse_result: zero-alloc entry point using backpatch. // RawStmt fields: stmt=1 (Node), stmt_location=2 (int32), stmt_len=3 (int32) out += 'pub fn encode_parse_result(val ParseAstResult) []u8 {\n' - out += '\tmut buf := []u8{}\n' + out += '\tmut buf := []u8{cap: 2048}\n' out += '\twrite_tag_into(mut buf, 1, 0)\n' out += '\twrite_varint_into(mut buf, u64(val.version))\n' out += '\tfor s in val.stmts {\n' - out += '\t\tmut inner := []u8{}\n' - out += '\t\twrite_tag_into(mut inner, 1, 2)\n' - out += '\t\twrite_length_delimited_into(mut inner, encode_node(s.stmt))\n' - out += '\t\twrite_tag_into(mut inner, 2, 0)\n' - out += '\t\twrite_varint_into(mut inner, u64(s.stmt_location))\n' - out += '\t\twrite_tag_into(mut inner, 3, 0)\n' - out += '\t\twrite_varint_into(mut inner, u64(s.stmt_len))\n' out += '\t\twrite_tag_into(mut buf, 2, 2)\n' - out += '\t\twrite_length_delimited_into(mut buf, inner)\n' + out += '\t\touter_len_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\touter_cs_ := buf.len\n' + out += '\t\tstmt_tag_start_ := buf.len\n' + out += '\t\twrite_tag_into(mut buf, 1, 2)\n' + out += '\t\tstmt_len_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tstmt_cs_ := buf.len\n' + out += '\t\tencode_node_into(mut buf, s.stmt)\n' + out += '\t\tif buf.len == stmt_cs_ { unsafe { buf = buf[..stmt_tag_start_] } } else { backpatch_varint4(mut buf, stmt_len_pos_, buf.len - stmt_cs_) }\n' + out += '\t\twrite_tag_into(mut buf, 2, 0)\n' + out += '\t\twrite_varint_into(mut buf, u64(s.stmt_location))\n' + out += '\t\twrite_tag_into(mut buf, 3, 0)\n' + out += '\t\twrite_varint_into(mut buf, u64(s.stmt_len))\n' + out += '\t\tbackpatch_varint4(mut buf, outer_len_pos_, buf.len - outer_cs_)\n' out += '\t}\n' out += '\treturn buf\n' out += '}\n\n' - os.write_file('pg_query/pg_query_encode.v', out) or { + os.write_file('pg_query_encode.v', out) or { eprintln('Failed to write pg_query_encode.v: ${err}') return } - println('Generated pg_query/pg_query_encode.v (${out.len} bytes)') + println('Generated pg_query_encode.v (${out.len} bytes)') } fn proto_type_write_expr(typ string, val_expr string) (int, string) { @@ -1561,8 +1587,9 @@ fn proto_encode_singular_field(f ProtoField, vfname string, pf ProtoFile, node_o out += '\t}\n' } else if is_self_ref(f, msg_name) { sr_inner := 'sr_${f.name}' - out += '\tif val.${vfname} != unsafe { nil } {\n' - out += '\t\t${sr_inner} := encode_${snake_case(proto_field_to_v_type(f.typ))}(*val.${vfname})\n' + sr_val := 'sr_val_${f.name}' + out += '\tif ${sr_val} := val.${vfname} {\n' + out += '\t\t${sr_inner} := encode_${snake_case(proto_field_to_v_type(f.typ))}(${sr_val})\n' out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' out += '\t\twrite_length_delimited_into(mut buf, ${sr_inner})\n' out += '\t}\n' @@ -1691,3 +1718,142 @@ fn proto_encode_map_field(f ProtoField, vfname string) string { out += '\t}\n' return out } + +// --------------------------------------------------------------------------- +// _into variants: emit code that writes directly into a caller-provided buf, +// using the backpatch-varint technique for submessage length prefixes. +// --------------------------------------------------------------------------- + +fn proto_encode_singular_field_into(f ProtoField, vfname string, pf ProtoFile, node_oneof_fields []ProtoField, msg_name string) string { + mut out := '' + if f.typ == 'Node' { + out += '\t{\n' + out += '\t\ttag_start_ := buf.len\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\tlen_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tcs_ := buf.len\n' + out += '\t\tencode_node_into(mut buf, val.${vfname})\n' + out += '\t\tif buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) }\n' + out += '\t}\n' + } else if is_self_ref(f, msg_name) { + sub_dfn := snake_case(proto_field_to_v_type(f.typ)) + out += '\tif ${vfname}_ := val.${vfname} {\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\tlen_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tcs_ := buf.len\n' + out += '\t\tencode_${sub_dfn}_into(mut buf, ${vfname}_)\n' + out += '\t\tbackpatch_varint4(mut buf, len_pos_, buf.len - cs_)\n' + out += '\t}\n' + } else if f.typ == 'Context' { + out += '\tif u64(val.${vfname}) != 0 {\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 0)\n' + out += '\t\twrite_varint_into(mut buf, u64(val.${vfname}))\n' + out += '\t}\n' + } else if is_primitive_proto(f.typ) || f.typ == 'string' || f.typ == 'bytes' { + wt, into_expr := proto_type_write_into(f.typ, 'val.${vfname}', 'buf') + cond := proto_zero_check(f.typ, 'val.${vfname}') + out += '\tif ${cond} {\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, ${wt})\n' + out += '\t\t${into_expr}\n' + out += '\t}\n' + } else if is_enum_type(pf, f.typ) { + out += '\tif u64(val.${vfname}) != 0 {\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 0)\n' + out += '\t\twrite_varint_into(mut buf, u64(val.${vfname}))\n' + out += '\t}\n' + } else { + subtype := proto_field_to_v_type(f.typ) + sub_dfn := snake_case(subtype) + out += '\t{\n' + out += '\t\ttag_start_ := buf.len\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\tlen_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tcs_ := buf.len\n' + out += '\t\tencode_${sub_dfn}_into(mut buf, val.${vfname})\n' + out += '\t\tif buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) }\n' + out += '\t}\n' + } + return out +} + +fn proto_encode_repeated_field_into(f ProtoField, vfname string, pf ProtoFile, node_oneof_fields []ProtoField) string { + mut out := '' + out += '\tif val.${vfname}.len > 0 {\n' + if f.typ == 'Node' { + out += '\t\tfor v in val.${vfname} {\n' + out += '\t\t\ttag_start_ := buf.len\n' + out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\t\tlen_pos_ := buf.len\n' + out += '\t\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\t\tcs_ := buf.len\n' + out += '\t\t\tencode_node_into(mut buf, v)\n' + out += '\t\t\tif buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) }\n' + out += '\t\t}\n' + } else if f.typ == 'string' || f.typ == 'bytes' { + wt, into_expr := proto_type_write_into(f.typ, 'v', 'buf') + out += '\t\tfor v in val.${vfname} {\n' + out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, ${wt})\n' + out += '\t\t\t${into_expr}\n' + out += '\t\t}\n' + } else if is_primitive_proto(f.typ) || is_enum_type(pf, f.typ) { + _, into_expr := proto_type_write_into(f.typ, 'v', 'packed_') + mut iexpr := into_expr + if is_enum_type(pf, f.typ) { + iexpr = 'write_varint_into(mut packed_, u64(v))' + } + out += '\t\tmut packed_ := []u8{}\n' + out += '\t\tfor v in val.${vfname} {\n' + out += '\t\t\t${iexpr}\n' + out += '\t\t}\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\twrite_length_delimited_into(mut buf, packed_)\n' + } else { + subtype := proto_field_to_v_type(f.typ) + sub_dfn := snake_case(subtype) + out += '\t\tfor v in val.${vfname} {\n' + out += '\t\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\t\tlen_pos_ := buf.len\n' + out += '\t\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\t\tcs_ := buf.len\n' + out += '\t\t\tencode_${sub_dfn}_into(mut buf, v)\n' + out += '\t\t\tbackpatch_varint4(mut buf, len_pos_, buf.len - cs_)\n' + out += '\t\t}\n' + } + out += '\t}\n' + return out +} + +fn proto_encode_oneof_field_into(f ProtoField, vfname string, pf ProtoFile, node_oneof_fields []ProtoField, msg_name string) string { + mut out := '' + out += '\tif v := val.${vfname} {\n' + if f.typ == 'Node' { + out += '\t\ttag_start_ := buf.len\n' + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\tlen_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tcs_ := buf.len\n' + out += '\t\tencode_node_into(mut buf, v)\n' + out += '\t\tif buf.len == cs_ { unsafe { buf = buf[..tag_start_] } } else { backpatch_varint4(mut buf, len_pos_, buf.len - cs_) }\n' + } else if is_primitive_proto(f.typ) || f.typ == 'string' || f.typ == 'bytes' { + wt, into_expr := proto_type_write_into(f.typ, 'v', 'buf') + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, ${wt})\n' + out += '\t\t${into_expr}\n' + } else if is_enum_type(pf, f.typ) { + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 0)\n' + out += '\t\twrite_varint_into(mut buf, u64(v))\n' + } else { + subtype := proto_field_to_v_type(f.typ) + sub_dfn := snake_case(subtype) + out += '\t\twrite_tag_into(mut buf, ${f.field_num}, 2)\n' + out += '\t\tlen_pos_ := buf.len\n' + out += '\t\twrite_u32_placeholder(mut buf)\n' + out += '\t\tcs_ := buf.len\n' + out += '\t\tencode_${sub_dfn}_into(mut buf, v)\n' + out += '\t\tbackpatch_varint4(mut buf, len_pos_, buf.len - cs_)\n' + } + out += '\t}\n' + return out +} diff --git a/v-and-c-integration.md b/v-and-c-integration.md deleted file mode 100644 index 566e10e..0000000 --- a/v-and-c-integration.md +++ /dev/null @@ -1,395 +0,0 @@ -# V and C - -The basic mapping between C and V types is described in [C and V Type Interoperability](https://github.com/vlang/v/blob/master/doc/c_and_v_type_interoperability.md). - -## Calling C from V - -V currently does not have a parser for C code. That means that even though it allows you to `#include` existing C header and source files, it will not know anything about the declarations in them. The `#include` statement will only appear in the generated C code, to be used by the C compiler backend itself. - -**Example of #include** - -```v -#include -``` - -After this statement, V will *not* know anything about the functions and structs declared in `stdio.h`, but if you try to compile the .v file, it will add the include in the generated C code, so that if that header file is missing, you will get a C error (you will not in this specific case, if you have a proper C compiler setup, since `` is part of the standard C library). - -To overcome that limitation (that V does not have a C parser), V needs you to redeclare the C functions and structs, on the V side, in your `.c.v` files. Note that such redeclarations only need to have enough details about the functions/structs that you want to use. Note also that they *do not have* to be complete, unlike the ones in the .h files. - -**C struct redeclarations** For example, if a struct has 3 fields on the C side, but you want to only refer to 1 of them, you can declare it like this: - -```v -struct C.NameOfTheStruct { a_field int } -``` - -Another feature, that is very frequently needed for C interoperability, is the `@[typedef]` attribute. It is used for marking `C.` structs, that are defined with `typedef struct SomeName { ..... } TypeName;` in the C headers. - -For that case, you will have to write something like this in your .c.v file: - -```v -@[typedef] pub struct C.TypeName { } -``` - -Note that the name of the `C.` struct in V, is the one *after* the `struct SomeName {...}`. - -**C function redeclarations** The situation is similar for `C.` functions. If you are going to call just 1 function in a library, but its .h header declares dozens of them, you will only need to declare that single function, for example: - -```v -fn C.name_of_the_C_function(param1 int, const_param2 &char, param3 f32) f64 -``` - -... and then later, you will be able to call the same way you would V function: - -```v -f := C.name_of_the_C_function(123, c'here is some C style string', 1.23) -dump(f) -``` - -**Example of using a C function from stdio, by redeclaring it on the V side** - -```v -#include // int dprintf(int fd, const char *format, ...) - -fn C.dprintf(fd int, const_format &char, ...voidptr) int - -value := 12345 -x := C.dprintf(0, c'Hello world, value: %d\n', value) -dump(x) -``` - -If your C backend compiler is properly setup, you should see something like this, when you try to run it: - -```console -#0 10:42:32 /v/examples> v run a.v -Hello world, value: 12345 -[a.v:8] x: 26 -#0 10:42:33 /v/examples> -``` - -Note, that the C function redeclarations look very similar to the V ones, with some differences: - -1. They lack a body (they are defined on the C side). -2. Their names start with `C.`. -3. Their names can have capital letters (unlike V ones, that are required to use snake_case). - -Note also the second parameter `const char *format`, which was redeclared as `const_format &char`. The `const_` prefix in that redeclaration may seem arbitrary, but it is important, if you want to compile your code with `-cstrict` or thirdparty C static analysis tools. V currently does not have another way to express that this parameter is a const (this will probably change in V 1.0). - -For some C functions, that use variadics (`...`) as parameters, V supports a special syntax for the parameters - `...voidptr`, that is not available for ordinary V functions (V's variadics are *required* to have the same exact type). Usually those are functions of the printf/scanf family i.e for `printf`, `fprintf`, `scanf`, `sscanf`, etc, and other formatting/parsing/logging functions. - -**Example: SQLite integration** - -```v -#flag freebsd -I/usr/local/include -L/usr/local/lib -#flag -lsqlite3 -#include "sqlite3.h" -// See also the example from https://www.sqlite.org/quickstart.html -pub struct C.sqlite3 { -} -pub struct C.sqlite3_stmt { -} -type FnSqlite3Callback = fn (voidptr, int, &&char, &&char) int - -fn C.sqlite3_open(&char, &&C.sqlite3) int -fn C.sqlite3_close(&C.sqlite3) int -fn C.sqlite3_column_int(stmt &C.sqlite3_stmt, n int) int -// ... you can also just define the type of parameter and leave out the C. prefix -fn C.sqlite3_prepare_v2(&C.sqlite3, &char, int, &&C.sqlite3_stmt, &&char) int -fn C.sqlite3_step(&C.sqlite3_stmt) -fn C.sqlite3_finalize(&C.sqlite3_stmt) -fn C.sqlite3_exec(db &C.sqlite3, sql &char, cb FnSqlite3Callback, cb_arg voidptr, emsg &&char) int -fn C.sqlite3_free(voidptr) - -fn my_callback(arg voidptr, howmany int, cvalues &&char, cnames &&char) int { - unsafe { - for i in 0 .. howmany { - print('| ${cstring_to_vstring(cnames[i])}: ${cstring_to_vstring(cvalues[i]):20} ') - } - } - println('|') - return 0 -} - -fn main() { - db := &C.sqlite3(unsafe { nil }) // this means `sqlite3* db = 0` - // passing a string literal to a C function call results in a C string, not a V string - C.sqlite3_open(c'users.db', &db) - // C.sqlite3_open(db_path.str, &db) - - query := 'select count(*) from users' - stmt := &C.sqlite3_stmt(unsafe { nil }) - - // Note: You can also use the `.str` field of a V string, - // to get its C style zero terminated representation - C.sqlite3_prepare_v2(db, &char(query.str), -1, &stmt, 0) - C.sqlite3_step(stmt) - nr_users := C.sqlite3_column_int(stmt, 0) - C.sqlite3_finalize(stmt) - println('There are ${nr_users} users in the database.') - - error_msg := &char(unsafe { nil }) - query_all_users := 'select * from users' - rc := C.sqlite3_exec(db, &char(query_all_users.str), my_callback, voidptr(7), &error_msg) - if rc != C.SQLITE_OK { - eprintln(unsafe { cstring_to_vstring(error_msg) }) - C.sqlite3_free(error_msg) - } - C.sqlite3_close(db) -} -``` - -## Calling V from C - -Since V can compile to C, calling V code from C is very easy, once you know how. - -Use `v -o file.c your_file.v` to generate a C file, corresponding to the V code. - -More details in [call_v_from_c example](https://github.com/vlang/v/blob/master/doc/../examples/call_v_from_c). - -## Passing C compilation flags - -Add `#flag` directives to the top of your V files to provide C compilation flags like: - -- `-I` for adding C include files search paths -- `-l` for adding C library names that you want to get linked -- `-L` for adding C library files search paths -- `-D` for setting compile time variables - -You can also use `#flag` directives, to link to static C libraries, which will be added last (note the .a suffix): - -```v -#flag /path/to/ffi.a -``` - -If you need to reverse the order (prepend the static library in the libs section of the C compilation line, before other libs), use: - -```v -#flag /path/to/ffi.a@START_LIBS -``` - -You can (optionally) use different flags for different targets. Every OS listed in [Compile time code](conditional-compilation.html#compile-time-code) is supported as flags. - -> **NOTE:** Each flag must go on its own line (for now) - -```v -#flag linux -lsdl2 -#flag linux -Ivig -#flag linux -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1 -#flag linux -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1 -#flag linux -DIMGUI_IMPL_API= -``` - -In the console build command, you can use: - -- `-cc` to change the default C backend compiler. -- `-cflags` to pass custom flags to the backend C compiler (passed before other C options). -- `-ldflags` to pass custom flags to the backend C linker (passed after every other C option). -- For example: `-cc gcc-9 -cflags -fsanitize=thread`. - -You can define a `VFLAGS` environment variable in your terminal to store your `-cc` and `-cflags` settings, rather than including them in the build command each time. - -## #pkgconfig - -Add `#pkgconfig` directives to tell the compiler which modules should be used for compiling and linking using the pkg-config files provided by the respective dependencies. - -As long as backticks can't be used in `#flag` and spawning processes is not desirable for security and portability reasons, V uses its own pkgconfig library that is compatible with the standard freedesktop one. - -If no flags are passed it will add `--cflags` and `--libs` to pkgconfig (not to V). In other words, both lines below do the same: - -```v -#pkgconfig r_core -#pkgconfig --cflags --libs r_core -``` - -The `.pc` files are looked up into a hardcoded list of default pkg-config paths, the user can add extra paths by using the `PKG_CONFIG_PATH` environment variable. Multiple modules can be passed. - -To check the existence of a pkg-config use `$pkgconfig('pkg')` as a compile time "if" condition to check if a pkg-config exists. If it exists the branch will be created. Use `$else` or `$else $if` to handle other cases. - -```v -$if $pkgconfig('mysqlclient') { - #pkgconfig mysqlclient -} $else $if $pkgconfig('mariadb') { - #pkgconfig mariadb -} -``` - -## Including C code - -You can also include C code directly in your V module. For example, let's say that your C code is located in a folder named 'c' inside your module folder. Then: - -1. Put a v.mod file inside the toplevel folder of your module (if you created your module with `v new` you already have v.mod file). For example: - -``` -Module { - name: 'mymodule', - description: 'My nice module wraps a simple C library.', - version: '0.0.1' - dependencies: [] -} -``` - -2. Add these lines to the top of your module: - -```v -#flag -I @VMODROOT/c -#flag @VMODROOT/c/implementation.o -#include "header.h" -``` - -> **NOTE:** `@VMODROOT` will be replaced by V with the *nearest parent folder, where there is a v.mod file*. Any .v file beside or below the folder where the v.mod file is, can use `#flag @VMODROOT/abc` to refer to this folder. The `@VMODROOT` folder is also *prepended* to the module lookup path, so you can *import* other modules under your `@VMODROOT`, by just naming them. - -The instructions above will make V look for an compiled .o file in your module `folder/c/implementation.o`. If V finds it, the .o file will get linked to the main executable, that used the module. If it does not find it, V assumes that there is a `@VMODROOT/c/implementation.c` file, and tries to compile it to a .o file, then will use that. - -This allows you to have C code, that is contained in a V module, so that its distribution is easier. You can see a complete minimal example for using C code in a V wrapper module here: [project_with_c_code](https://github.com/vlang/v/tree/master/vlib/v/tests/project_with_c_code). Another example, demonstrating passing structs from C to V and back again: [interoperate between C to V to C](https://github.com/vlang/v/tree/master/vlib/v/tests/project_with_c_code_2). - -## C types - -Ordinary zero terminated C strings can be converted to V strings with `unsafe { &char(cstring).vstring() }` or if you know their length already with `unsafe { &char(cstring).vstring_with_len(len) }`. - -> **NOTE:** The `.vstring()` and `.vstring_with_len()` methods do NOT create a copy of the `cstring`, so you should NOT free it after calling the method `.vstring()`. If you need to make a copy of the C string (some libc APIs like `getenv` pretty much require that, since they return pointers to internal libc memory), you can use `cstring_to_vstring(cstring)`. - -On Windows, C APIs often return so called `wide` strings (UTF-16 encoding). These can be converted to V strings with `string_from_wide(&u16(cwidestring))`. - -V has these types for easier interoperability with C: - -- `voidptr` for C's `void*` -- `&u8` for C's `byte*` -- `&char` for C's `char*` -- `&&char` for C's `char**` - -To cast a `voidptr` to a V reference, use `user := &User(user_void_ptr)`. - -`voidptr` can also be dereferenced into a V struct through casting: `user := User(user_void_ptr)`. - -[An example of a module that calls C code from V](https://github.com/vlang/v/blob/master/vlib/v/tests/project_with_c_code/mod1/wrapper.c.v) - -## C Declarations - -C identifiers are accessed with the `C` prefix similarly to how module-specific identifiers are accessed. Functions must be redeclared in V before they can be used. Any C types may be used behind the `C` prefix, but types must be redeclared in V in order to access type members. - -To redeclare complex types, such as in the following C code: - -```c -struct SomeCStruct { - uint8_t implTraits; - uint16_t memPoolData; - union { - struct { - void* data; - size_t size; - }; - DataView view; - }; -}; -``` - -Members of sub-data-structures may be directly declared in the containing struct as below: - -```v -pub struct C.SomeCStruct { - implTraits u8 - memPoolData u16 - // These members are part of sub data structures that can't currently be represented in V. - // Declaring them directly like this is sufficient for access. - // union { - // struct { - data voidptr - size usize - // } - // view C.DataView - // } -} -``` - -The existence of the data members is made known to V, and they may be used without re-creating the original structure exactly. - -Alternatively, you may [embed](structs.html#embedded-structs) the sub-data-structures to maintain a parallel code structure. - -## Export to shared library - -By default all V functions have the following naming scheme in C: `[module name]__[fn_name]`. - -For example, `fn foo() {}` in module `bar` will result in `bar__foo()`. - -To use a custom export name, use the `@[export]` attribute: - -```v -@[export: 'my_custom_c_name'] -fn foo() { -} -``` - -## Translating C to V - -V can translate your C code to human readable V code, and generating V wrappers on top of C libraries. - -C2V currently uses Clang's AST to generate V, so to translate a C file to V you need to have Clang installed on your machine. - -Let's create a simple program `test.c` first: - -```c -#include "stdio.h" -int main() { - for (int i = 0; i < 10; i++) { - printf("hello world\n"); - } - return 0; -} -``` - -Run `v translate test.c`, and V will generate `test.v`: - -```v -fn main() { - for i := 0; i < 10; i++ { - println('hello world') - } -} -``` - -To generate a wrapper on top of a C library use this command: - -```bash -v translate wrapper c_code/libsodium/src/libsodium -``` - -This will generate a directory `libsodium` with a V module. - -Example of a C2V generated libsodium wrapper: [https://github.com/vlang/libsodium](https://github.com/vlang/libsodium) - -**When should you translate C code and when should you simply call C code from V?** - -If you have well-written, well-tested C code, then of course you can always simply call this C code from V. - -Translating it to V gives you several advantages: - -- If you plan to develop that code base, you now have everything in one language, which is much safer and easier to develop in than C. -- Cross-compilation becomes a lot easier. You don't have to worry about it at all. -- No more build flags and include files either. - -## Working around C issues - -In some cases, C interop can be extremely difficult. One of these such cases is when headers conflict with each other. For example, V needs to include the Windows header libraries in order for your V binaries to work seamlessly across all platforms. - -However, since the Windows header libraries use extremely generic names such as `Rectangle`, this will cause a conflict if you wish to use C code that also has a name defined as `Rectangle`. - -For very specific cases like this, V has `#preinclude` and `#postinclude` directives. - -These directives allow things to be configured *before* V adds in its built in libraries, and *after* all of the V code generation has completed (and thus all of the prototypes, declarations and definitions are already present). - -Example usage: - -```v -// This will include before built in libraries are used. -#preinclude "pre_include.h" -// This will include after built in libraries are used. -#include "include.h" -// This will include after all of the V code generation is complete, -// including the one for the main function of the project -#postinclude "post_include.h" -``` - -An example of what might be included in `pre_include.h` can be [found here](https://github.com/irishgreencitrus/raylib.v/blob/main/include/pre.h). - -The `#postinclude` directive on the other hand is useful for allowing the integration of frameworks like SDL3 or Sokol, that insist on having callbacks in your code, instead of behaving like ordinary libraries, and allowing you to decide when to call them. - -> **NOTE:** These are advanced features, and will not be necessary outside of very specific cases with C interop. Other than those, using them could cause more issues than it solves. Consider using them as a last resort! diff --git a/v.mod b/v.mod index dd7da5d..6d72005 100644 --- a/v.mod +++ b/v.mod @@ -1,5 +1,5 @@ Module{ - name: 'pg_query.v' + name: 'pg_query' description: 'V library to parse and normalize SQL queries using the PostgreSQL query parser' version: '0.0.0' license: 'MIT'