move nbt_strlen to nbt.h, and rename to nbt_namelen

This commit is contained in:
2025-07-24 14:53:11 +02:00
parent 4005163d61
commit 58d0dd01e2
2 changed files with 21 additions and 17 deletions

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -39,6 +40,16 @@ struct nbt_path {
i16 len; // specifies the length of the NBT elements
};
/* returns the name length of a specific tag. `buf` is the pointer to start of the tag */
atrb_pure atrb_nonnull(1) static inline u16 nbt_namelen(const u8 *restrict buf) {
assert(*buf != NBT_END);
return be16toh(*(u16 *)(buf + 1));
}
/* returns the (expected) pointer of the tag following this one.
* `NULL` is returned if anything went wrong. */
atrb_pure atrb_nonnull(1) const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml);
/* 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);