nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit fcbcb9034719a24090641d3ed4a2a620ce72d0c8
parent 014658db7a1be4ae9aa5521431a234424316a0ac
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 10 Aug 2023 21:16:42 -0700

schemas: add event metadata schema

not sure if I need this yet, but can be used for storing receivedAt, etc

Diffstat:
MMakefile | 9+++++++--
Abindings/c/meta_builder.h | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Abindings/c/meta_json_parser.h | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abindings/c/meta_reader.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Abindings/c/meta_verifier.h | 42++++++++++++++++++++++++++++++++++++++++++
Aschemas/meta.fbs | 6++++++
6 files changed, 276 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -9,8 +9,9 @@ FLATCC_VER=0.6.1 PREFIX ?= /usr/local SUBMODULES = deps/secp256k1 C_BINDINGS_PROFILE=bindings/c/profile_builder.h bindings/c/profile_reader.h bindings/c/profile_verifier.h bindings/c/profile_json_parser.h -C_BINDINGS_COMMON=bindings/c/flatbuffers_common_builder.h bindings/c/flatbuffers_common_reader.h -C_BINDINGS=$(C_BINDINGS_COMMON) $(C_BINDINGS_PROFILE) +C_BINDINGS_META=bindings/c/meta_builder.h bindings/c/meta_reader.h bindings/c/meta_verifier.h bindings/c/meta_json_parser.h +C_BINDINGS_COMMON=bindings/c/flatbuffers_common_builder.h bindings/c/flatbuffers_common_reader.h +C_BINDINGS=$(C_BINDINGS_COMMON) $(C_BINDINGS_PROFILE) $(C_BINDINGS_META) BINDINGS=bindings lib: benches test @@ -67,6 +68,10 @@ bindings/swift/NdbProfile.swift: schemas/profile.fbs bindings/swift flatc --swift $< @mv profile_generated.swift $@ +bindings/swift/NdbMeta.swift: schemas/meta.fbs bindings/swift + flatc --swift $< + @mv meta_generated.swift $@ + deps/.dir: @mkdir -p deps touch deps/.dir diff --git a/bindings/c/meta_builder.h b/bindings/c/meta_builder.h @@ -0,0 +1,52 @@ +#ifndef META_BUILDER_H +#define META_BUILDER_H + +/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef META_READER_H +#include "meta_reader.h" +#endif +#ifndef FLATBUFFERS_COMMON_BUILDER_H +#include "flatbuffers_common_builder.h" +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + +static const flatbuffers_voffset_t __NdbEventMeta_required[] = { 0 }; +typedef flatbuffers_ref_t NdbEventMeta_ref_t; +static NdbEventMeta_ref_t NdbEventMeta_clone(flatbuffers_builder_t *B, NdbEventMeta_table_t t); +__flatbuffers_build_table(flatbuffers_, NdbEventMeta, 1) + +#define __NdbEventMeta_formal_args , int32_t v0 +#define __NdbEventMeta_call_args , v0 +static inline NdbEventMeta_ref_t NdbEventMeta_create(flatbuffers_builder_t *B __NdbEventMeta_formal_args); +__flatbuffers_build_table_prolog(flatbuffers_, NdbEventMeta, NdbEventMeta_file_identifier, NdbEventMeta_type_identifier) + +__flatbuffers_build_scalar_field(0, flatbuffers_, NdbEventMeta_received_at, flatbuffers_int32, int32_t, 4, 4, INT32_C(0), NdbEventMeta) + +static inline NdbEventMeta_ref_t NdbEventMeta_create(flatbuffers_builder_t *B __NdbEventMeta_formal_args) +{ + if (NdbEventMeta_start(B) + || NdbEventMeta_received_at_add(B, v0)) { + return 0; + } + return NdbEventMeta_end(B); +} + +static NdbEventMeta_ref_t NdbEventMeta_clone(flatbuffers_builder_t *B, NdbEventMeta_table_t t) +{ + __flatbuffers_memoize_begin(B, t); + if (NdbEventMeta_start(B) + || NdbEventMeta_received_at_pick(B, t)) { + return 0; + } + __flatbuffers_memoize_end(B, t, NdbEventMeta_end(B)); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* META_BUILDER_H */ diff --git a/bindings/c/meta_json_parser.h b/bindings/c/meta_json_parser.h @@ -0,0 +1,116 @@ +#ifndef META_JSON_PARSER_H +#define META_JSON_PARSER_H + +/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */ + +#include "flatcc/flatcc_json_parser.h" +#include "flatcc/flatcc_prologue.h" + +/* + * Parses the default root table or struct of the schema and constructs a FlatBuffer. + * + * Builder `B` must be initialized. `ctx` can be null but will hold + * hold detailed error info on return when available. + * Returns 0 on success, or error code. + * `flags` : 0 by default, `flatcc_json_parser_f_skip_unknown` silently + * ignores unknown table and structs fields, and union types. + */ +static int meta_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx, + const char *buf, size_t bufsiz, int flags); + +static const char *NdbEventMeta_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result); +static const char *meta_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, +int *value_type, uint64_t *value, int *aggregate); +static const char *meta_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, + int *value_type, uint64_t *value, int *aggregate); + +static const char *NdbEventMeta_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result) +{ + int more; + void *pval; + flatcc_builder_ref_t ref, *pref; + const char *mark; + uint64_t w; + + *result = 0; + if (flatcc_builder_start_table(ctx->ctx, 1)) goto failed; + buf = flatcc_json_parser_object_start(ctx, buf, end, &more); + while (more) { + buf = flatcc_json_parser_symbol_start(ctx, buf, end); + w = flatcc_json_parser_symbol_part(buf, end); + if (w == 0x7265636569766564) { /* descend "received" */ + buf += 8; + w = flatcc_json_parser_symbol_part(buf, end); + if ((w & 0xffffff0000000000) == 0x5f61740000000000) { /* "_at" */ + buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3); + if (mark != buf) { + int32_t val = 0; + static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { + meta_local_json_parser_enum, + meta_global_json_parser_enum, 0 }; + buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); + if (mark == buf) { + buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); + if (buf == mark || buf == end) goto failed; + } + if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { + if (!(pval = flatcc_builder_table_add(ctx->ctx, 0, 4, 4))) goto failed; + flatbuffers_int32_write_to_pe(pval, val); + } + } else { + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } + } else { /* "_at" */ + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } /* "_at" */ + } else { /* descend "received" */ + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } /* descend "received" */ + buf = flatcc_json_parser_object_end(ctx, buf, end, &more); + } + if (ctx->error) goto failed; + if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed; + return buf; +failed: + return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime); +} + +static inline int NdbEventMeta_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid) +{ + return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, NdbEventMeta_parse_json_table); +} + +static const char *meta_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, + int *value_type, uint64_t *value, int *aggregate) +{ + /* Scope has no enum / union types to look up. */ + return buf; /* unmatched; */ +} + +static const char *meta_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, + int *value_type, uint64_t *value, int *aggregate) +{ + /* Global scope has no enum / union types to look up. */ + return buf; /* unmatched; */ +} + +static int meta_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx, + const char *buf, size_t bufsiz, int flags) +{ + flatcc_json_parser_t parser; + flatcc_builder_ref_t root; + + ctx = ctx ? ctx : &parser; + flatcc_json_parser_init(ctx, B, buf, buf + bufsiz, flags); + if (flatcc_builder_start_buffer(B, 0, 0, 0)) return -1; + NdbEventMeta_parse_json_table(ctx, buf, buf + bufsiz, &root); + if (ctx->error) { + return ctx->error; + } + if (!flatcc_builder_end_buffer(B, root)) return -1; + ctx->end_loc = buf; + return 0; +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* META_JSON_PARSER_H */ diff --git a/bindings/c/meta_reader.h b/bindings/c/meta_reader.h @@ -0,0 +1,53 @@ +#ifndef META_READER_H +#define META_READER_H + +/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef FLATBUFFERS_COMMON_READER_H +#include "flatbuffers_common_reader.h" +#endif +#include "flatcc/flatcc_flatbuffers.h" +#ifndef __alignas_is_defined +#include <stdalign.h> +#endif +#include "flatcc/flatcc_prologue.h" +#ifndef flatbuffers_identifier +#define flatbuffers_identifier 0 +#endif +#ifndef flatbuffers_extension +#define flatbuffers_extension "bin" +#endif + + +typedef const struct NdbEventMeta_table *NdbEventMeta_table_t; +typedef struct NdbEventMeta_table *NdbEventMeta_mutable_table_t; +typedef const flatbuffers_uoffset_t *NdbEventMeta_vec_t; +typedef flatbuffers_uoffset_t *NdbEventMeta_mutable_vec_t; +#ifndef NdbEventMeta_file_identifier +#define NdbEventMeta_file_identifier 0 +#endif +/* deprecated, use NdbEventMeta_file_identifier */ +#ifndef NdbEventMeta_identifier +#define NdbEventMeta_identifier 0 +#endif +#define NdbEventMeta_type_hash ((flatbuffers_thash_t)0xa8c23be8) +#define NdbEventMeta_type_identifier "\xe8\x3b\xc2\xa8" +#ifndef NdbEventMeta_file_extension +#define NdbEventMeta_file_extension "bin" +#endif + + + +struct NdbEventMeta_table { uint8_t unused__; }; + +static inline size_t NdbEventMeta_vec_len(NdbEventMeta_vec_t vec) +__flatbuffers_vec_len(vec) +static inline NdbEventMeta_table_t NdbEventMeta_vec_at(NdbEventMeta_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(NdbEventMeta_table_t, vec, i, 0) +__flatbuffers_table_as_root(NdbEventMeta) + +__flatbuffers_define_scalar_field(0, NdbEventMeta, received_at, flatbuffers_int32, int32_t, INT32_C(0)) + + +#include "flatcc/flatcc_epilogue.h" +#endif /* META_READER_H */ diff --git a/bindings/c/meta_verifier.h b/bindings/c/meta_verifier.h @@ -0,0 +1,42 @@ +#ifndef META_VERIFIER_H +#define META_VERIFIER_H + +/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */ + +#ifndef META_READER_H +#include "meta_reader.h" +#endif +#include "flatcc/flatcc_verifier.h" +#include "flatcc/flatcc_prologue.h" + +static int NdbEventMeta_verify_table(flatcc_table_verifier_descriptor_t *td); + +static int NdbEventMeta_verify_table(flatcc_table_verifier_descriptor_t *td) +{ + int ret; + if ((ret = flatcc_verify_field(td, 0, 4, 4) /* received_at */)) return ret; + return flatcc_verify_ok; +} + +static inline int NdbEventMeta_verify_as_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, NdbEventMeta_identifier, &NdbEventMeta_verify_table); +} + +static inline int NdbEventMeta_verify_as_typed_root(const void *buf, size_t bufsiz) +{ + return flatcc_verify_table_as_root(buf, bufsiz, NdbEventMeta_type_identifier, &NdbEventMeta_verify_table); +} + +static inline int NdbEventMeta_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid) +{ + return flatcc_verify_table_as_root(buf, bufsiz, fid, &NdbEventMeta_verify_table); +} + +static inline int NdbEventMeta_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash) +{ + return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbEventMeta_verify_table); +} + +#include "flatcc/flatcc_epilogue.h" +#endif /* META_VERIFIER_H */ diff --git a/schemas/meta.fbs b/schemas/meta.fbs @@ -0,0 +1,6 @@ + +table NdbEventMeta { + received_at:int; +} + +root_type NdbEventMeta;