move nbt_prim_tagsize to header, since it's a pretty useful funciton.

This commit is contained in:
2025-07-23 12:12:36 +02:00
parent 8102dd6a71
commit 9fd920908e
2 changed files with 16 additions and 13 deletions

View File

@@ -29,19 +29,6 @@ static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) {
return strncmp(str, matstr, len);
}
/* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */
int nbt_prim_tagsize(u8 tag) {
switch (tag) {
case NBT_I8: return 1;
case NBT_I16: return 2;
case NBT_I32: return 4;
case NBT_I64: return 8;
case NBT_F32: return 4;
case NBT_F64: return 8;
default: return -1;
}
}
/* returns the (expected) pointer of the tag following this one.
* `NBT_COMPOUND` and `NBT_END` tags are not valid for this function and should be handled separately.
* `NULL` is returned if anything went wrong. */
@@ -99,3 +86,15 @@ int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) {
// TODO: finish function
return 0;
}
int nbt_prim_tagsize(u8 tag) {
switch (tag) {
case NBT_I8: return 1;
case NBT_I16: return 2;
case NBT_I32: return 4;
case NBT_I64: return 8;
case NBT_F32: return 4;
case NBT_F64: return 8;
default: return -1;
}
}