NDJSON
include/ndjson.h View source View on GitHubStructs
Section titled “Structs”ndjson_field
Section titled “ndjson_field”struct ndjson_field {
const char *name;
enum ndjson_type type;
uint16_t offset;
}; ndjson_record
Section titled “ndjson_record”struct ndjson_record {
const char *section;
const char *kind;
uint16_t version;
uint16_t nfields;
const struct ndjson_field *fields;
}; ndjson_type
Section titled “ndjson_type”enum ndjson_type : uint8_t {
NDJSON_TYPE_U64,
NDJSON_TYPE_I64,
NDJSON_TYPE_BOOL,
NDJSON_TYPE_STR,
NDJSON_TYPE_HEX,
}; Functions
Section titled “Functions”ndjson_emit_impl
Section titled “ndjson_emit_impl”void ndjson_emit_impl(const struct ndjson_record *rec, const void *args); ndjson_bye
Section titled “ndjson_bye”void ndjson_bye(uint64_t code, const char *reason); ndjson_early_init
Section titled “ndjson_early_init”void ndjson_early_init(void); ndjson_init
Section titled “ndjson_init”void ndjson_init(void); ndjson_carrier_online
Section titled “ndjson_carrier_online”bool ndjson_carrier_online(void); ndjson_carrier_init
Section titled “ndjson_carrier_init”void ndjson_carrier_init(uint16_t port); ndjson_carrier_disable
Section titled “ndjson_carrier_disable”void ndjson_carrier_disable(void); ndjson_enter_panic
Section titled “ndjson_enter_panic”void ndjson_enter_panic(void); Macros
Section titled “Macros”NDJSON_KEY_SECTION
Section titled “NDJSON_KEY_SECTION”#define NDJSON_KEY_SECTION "s" NDJSON_KEY_KIND
Section titled “NDJSON_KEY_KIND”#define NDJSON_KEY_KIND "k" NDJSON_KEY_VERSION
Section titled “NDJSON_KEY_VERSION”#define NDJSON_KEY_VERSION "v" NDJSON_KEY_TIME
Section titled “NDJSON_KEY_TIME”#define NDJSON_KEY_TIME "t" NDJSON_KEY_CPU
Section titled “NDJSON_KEY_CPU”#define NDJSON_KEY_CPU "c" NDJSON_KEY_TRUNCATED
Section titled “NDJSON_KEY_TRUNCATED”#define NDJSON_KEY_TRUNCATED "_trunc" NDJSON_SECTION_NDJSON
Section titled “NDJSON_SECTION_NDJSON”#define NDJSON_SECTION_NDJSON "ndjson" NDJSON_SECTION_TEST
Section titled “NDJSON_SECTION_TEST”#define NDJSON_SECTION_TEST "test" NDJSON_SECTION_PANIC
Section titled “NDJSON_SECTION_PANIC”#define NDJSON_SECTION_PANIC "panic" NDJSON_SECTION_ASAN
Section titled “NDJSON_SECTION_ASAN”#define NDJSON_SECTION_ASAN "asan" NDJSON_SECTION_SELFTEST
Section titled “NDJSON_SECTION_SELFTEST”#define NDJSON_SECTION_SELFTEST "selftest" NDJSON_SECTION_NIGHTMARE
Section titled “NDJSON_SECTION_NIGHTMARE”#define NDJSON_SECTION_NIGHTMARE "nightmare" NDJSON_SECTION_LOCK_CHK
Section titled “NDJSON_SECTION_LOCK_CHK”#define NDJSON_SECTION_LOCK_CHK "lock_chk" NDJSON_SECTION_LOG
Section titled “NDJSON_SECTION_LOG”#define NDJSON_SECTION_LOG "log" NDJSON_KIND_SCHEMA
Section titled “NDJSON_KIND_SCHEMA”#define NDJSON_KIND_SCHEMA "schema" NDJSON_KIND_BYE
Section titled “NDJSON_KIND_BYE”#define NDJSON_KIND_BYE "bye" NDJSON_KIND_BEGIN
Section titled “NDJSON_KIND_BEGIN”#define NDJSON_KIND_BEGIN "begin" NDJSON_KIND_RESULT
Section titled “NDJSON_KIND_RESULT”#define NDJSON_KIND_RESULT "result" NDJSON_KIND_GROUP_START
Section titled “NDJSON_KIND_GROUP_START”#define NDJSON_KIND_GROUP_START "group_start" NDJSON_KIND_GROUP_END
Section titled “NDJSON_KIND_GROUP_END”#define NDJSON_KIND_GROUP_END "group_end" NDJSON_KIND_TOTALS
Section titled “NDJSON_KIND_TOTALS”#define NDJSON_KIND_TOTALS "totals" NDJSON_KIND_VERDICT
Section titled “NDJSON_KIND_VERDICT”#define NDJSON_KIND_VERDICT "verdict" NDJSON_KIND_EXIT
Section titled “NDJSON_KIND_EXIT”#define NDJSON_KIND_EXIT "exit" NDJSON_KIND_AT
Section titled “NDJSON_KIND_AT”#define NDJSON_KIND_AT "at" NDJSON_KIND_FAULT
Section titled “NDJSON_KIND_FAULT”#define NDJSON_KIND_FAULT "fault" NDJSON_KIND_FRAME
Section titled “NDJSON_KIND_FRAME”#define NDJSON_KIND_FRAME "frame" NDJSON_KIND_PEER
Section titled “NDJSON_KIND_PEER”#define NDJSON_KIND_PEER "peer" NDJSON_KIND_OWNER
Section titled “NDJSON_KIND_OWNER”#define NDJSON_KIND_OWNER "owner" NDJSON_KIND_BOOT
Section titled “NDJSON_KIND_BOOT”#define NDJSON_KIND_BOOT "boot" NDJSON_KIND_STAT
Section titled “NDJSON_KIND_STAT”#define NDJSON_KIND_STAT "stat" NDJSON_KIND_QUIESCE
Section titled “NDJSON_KIND_QUIESCE”#define NDJSON_KIND_QUIESCE "quiesce" NDJSON_KIND_FINDING
Section titled “NDJSON_KIND_FINDING”#define NDJSON_KIND_FINDING "finding" NDJSON_KIND_MESSAGE
Section titled “NDJSON_KIND_MESSAGE”#define NDJSON_KIND_MESSAGE "msg" NDJSON_TYPE_NAME_U64
Section titled “NDJSON_TYPE_NAME_U64”#define NDJSON_TYPE_NAME_U64 "u64" NDJSON_TYPE_NAME_I64
Section titled “NDJSON_TYPE_NAME_I64”#define NDJSON_TYPE_NAME_I64 "i64" NDJSON_TYPE_NAME_BOOL
Section titled “NDJSON_TYPE_NAME_BOOL”#define NDJSON_TYPE_NAME_BOOL "bool" NDJSON_TYPE_NAME_STR
Section titled “NDJSON_TYPE_NAME_STR”#define NDJSON_TYPE_NAME_STR "str" NDJSON_TYPE_NAME_HEX
Section titled “NDJSON_TYPE_NAME_HEX”#define NDJSON_TYPE_NAME_HEX "hex" NDJSON_CTYPE_U64
Section titled “NDJSON_CTYPE_U64”#define NDJSON_CTYPE_U64 uint64_t NDJSON_CTYPE_I64
Section titled “NDJSON_CTYPE_I64”#define NDJSON_CTYPE_I64 int64_t NDJSON_CTYPE_BOOL
Section titled “NDJSON_CTYPE_BOOL”#define NDJSON_CTYPE_BOOL bool NDJSON_CTYPE_STR
Section titled “NDJSON_CTYPE_STR”#define NDJSON_CTYPE_STR const char * NDJSON_CTYPE_HEX
Section titled “NDJSON_CTYPE_HEX”#define NDJSON_CTYPE_HEX uint64_t NDJSON_U64
Section titled “NDJSON_U64”#define NDJSON_U64(n) (U64, n) NDJSON_I64
Section titled “NDJSON_I64”#define NDJSON_I64(n) (I64, n) NDJSON_BOOL
Section titled “NDJSON_BOOL”#define NDJSON_BOOL(n) (BOOL, n) NDJSON_STR
Section titled “NDJSON_STR”#define NDJSON_STR(n) (STR, n) NDJSON_HEX
Section titled “NDJSON_HEX”#define NDJSON_HEX(n) (HEX, n) NDJSON_UNTUPLE
Section titled “NDJSON_UNTUPLE”#define NDJSON_UNTUPLE(...) __VA_ARGS__ NDJSON_MEMBER
Section titled “NDJSON_MEMBER”#define NDJSON_MEMBER(id, spec) NDJSON_MEMBER_(id, NDJSON_UNTUPLE spec) NDJSON_MEMBER_
Section titled “NDJSON_MEMBER_”#define NDJSON_MEMBER_(id, ...) NDJSON_MEMBER__(id, __VA_ARGS__) NDJSON_MEMBER__
Section titled “NDJSON_MEMBER__”#define NDJSON_MEMBER__(id, t, n) NDJSON_CTYPE_##t n; NDJSON_DESC
Section titled “NDJSON_DESC”#define NDJSON_DESC(id, spec) NDJSON_DESC_(id, NDJSON_UNTUPLE spec) NDJSON_DESC_
Section titled “NDJSON_DESC_”#define NDJSON_DESC_(id, ...) NDJSON_DESC__(id, __VA_ARGS__) NDJSON_DESC__
Section titled “NDJSON_DESC__”#define NDJSON_DESC__(id, t, n) \
{.name = #n, \
.type = NDJSON_TYPE_##t, \
.offset = (uint16_t) __builtin_offsetof(struct __ndjson_args_##id, n)}, NDJSON_MAP_1
Section titled “NDJSON_MAP_1”#define NDJSON_MAP_1(f, a, x) f(a, x) NDJSON_MAP_2
Section titled “NDJSON_MAP_2”#define NDJSON_MAP_2(f, a, x, ...) f(a, x) NDJSON_MAP_1(f, a, __VA_ARGS__) NDJSON_MAP_3
Section titled “NDJSON_MAP_3”#define NDJSON_MAP_3(f, a, x, ...) f(a, x) NDJSON_MAP_2(f, a, __VA_ARGS__) NDJSON_MAP_4
Section titled “NDJSON_MAP_4”#define NDJSON_MAP_4(f, a, x, ...) f(a, x) NDJSON_MAP_3(f, a, __VA_ARGS__) NDJSON_MAP_5
Section titled “NDJSON_MAP_5”#define NDJSON_MAP_5(f, a, x, ...) f(a, x) NDJSON_MAP_4(f, a, __VA_ARGS__) NDJSON_MAP_6
Section titled “NDJSON_MAP_6”#define NDJSON_MAP_6(f, a, x, ...) f(a, x) NDJSON_MAP_5(f, a, __VA_ARGS__) NDJSON_MAP_7
Section titled “NDJSON_MAP_7”#define NDJSON_MAP_7(f, a, x, ...) f(a, x) NDJSON_MAP_6(f, a, __VA_ARGS__) NDJSON_MAP_8
Section titled “NDJSON_MAP_8”#define NDJSON_MAP_8(f, a, x, ...) f(a, x) NDJSON_MAP_7(f, a, __VA_ARGS__) NDJSON_MAP_9
Section titled “NDJSON_MAP_9”#define NDJSON_MAP_9(f, a, x, ...) f(a, x) NDJSON_MAP_8(f, a, __VA_ARGS__) NDJSON_MAP_10
Section titled “NDJSON_MAP_10”#define NDJSON_MAP_10(f, a, x, ...) f(a, x) NDJSON_MAP_9(f, a, __VA_ARGS__) NDJSON_MAP_11
Section titled “NDJSON_MAP_11”#define NDJSON_MAP_11(f, a, x, ...) f(a, x) NDJSON_MAP_10(f, a, __VA_ARGS__) NDJSON_MAP_12
Section titled “NDJSON_MAP_12”#define NDJSON_MAP_12(f, a, x, ...) f(a, x) NDJSON_MAP_11(f, a, __VA_ARGS__) NDJSON_MAP_13
Section titled “NDJSON_MAP_13”#define NDJSON_MAP_13(f, a, x, ...) f(a, x) NDJSON_MAP_12(f, a, __VA_ARGS__) NDJSON_MAP_14
Section titled “NDJSON_MAP_14”#define NDJSON_MAP_14(f, a, x, ...) f(a, x) NDJSON_MAP_13(f, a, __VA_ARGS__) NDJSON_MAP_15
Section titled “NDJSON_MAP_15”#define NDJSON_MAP_15(f, a, x, ...) f(a, x) NDJSON_MAP_14(f, a, __VA_ARGS__) NDJSON_MAP_16
Section titled “NDJSON_MAP_16”#define NDJSON_MAP_16(f, a, x, ...) f(a, x) NDJSON_MAP_15(f, a, __VA_ARGS__) NDJSON_MAP
Section titled “NDJSON_MAP”#define NDJSON_MAP(f, a, ...) \
_DISPATCH(NDJSON_MAP, PP_NARG(__VA_ARGS__))(f, a, __VA_ARGS__) NDJSON_MAX_FIELDS
Section titled “NDJSON_MAX_FIELDS”#define NDJSON_MAX_FIELDS 16 NDJSON_DECLARE
Section titled “NDJSON_DECLARE”#define NDJSON_DECLARE(id, section_, kind_, version_, ...) \
struct __ndjson_args_##id { \
NDJSON_MAP(NDJSON_MEMBER, id, __VA_ARGS__) \
}; \
static const struct ndjson_field __ndjson_fields_##id[] = { \
NDJSON_MAP(NDJSON_DESC, id, __VA_ARGS__)}; \
LINKER_SECTION_OBJECT(struct ndjson_record, ndjson_records) \
__ndjson_rec_##id = {.section = (section_), \
.kind = (kind_), \
.version = (version_), \
.nfields = PP_NARG(__VA_ARGS__), \
.fields = __ndjson_fields_##id}; \
static_assert(PP_NARG(__VA_ARGS__) <= NDJSON_MAX_FIELDS, \
"ndjson record " #id " has too many fields") NDJSON
Section titled “NDJSON”#define NDJSON(id) (&__ndjson_rec_##id) NDJSON_EXTERN
Section titled “NDJSON_EXTERN”#define NDJSON_EXTERN(id) extern struct ndjson_record __ndjson_rec_##id ndjson_emit
Section titled “ndjson_emit”#define ndjson_emit(id, ...) \
ndjson_emit_impl(NDJSON(id), \
&(const struct __ndjson_args_##id) {__VA_ARGS__}) NDJSON_STR_MAX
Section titled “NDJSON_STR_MAX”#define NDJSON_STR_MAX 512