From 65ee7c5b55ea96b0ed5c414162f29f3f607c4009 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 23 Jul 2025 12:18:55 +0200 Subject: [PATCH] add a function for checking whether a tag is primitive or not mainly for niche uses --- src/dat/nbt.c | 14 ++++++++++++++ src/dat/nbt.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/dat/nbt.c b/src/dat/nbt.c index 668de65..2ca6d5f 100644 --- a/src/dat/nbt.c +++ b/src/dat/nbt.c @@ -98,3 +98,17 @@ int nbt_prim_tagsize(u8 tag) { default: return -1; } } + +int nbt_isprim(u8 tag) { + switch (tag) { + case NBT_I8: + case NBT_I16: + case NBT_I32: + case NBT_F32: + case NBT_I64: + case NBT_F64: + return 1; + default: + return 0; + } +} diff --git a/src/dat/nbt.h b/src/dat/nbt.h index 0295f40..be32a77 100644 --- a/src/dat/nbt.h +++ b/src/dat/nbt.h @@ -36,5 +36,10 @@ enum nbt_tagid { int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len); +/* checks whether the tag is a primitive data tag. (not recommended for filtering tags, use a `switch`) + * returns a boolean value. */ +atrb_const int nbt_isprim(u8 tag); + + /* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */ atrb_const int nbt_prim_tagsize(u8 tag);