mirror of
https://github.com/thepigeongenerator/mcaselector-lite
synced 2026-02-08 07:33:35 +01:00
move nbt_prim_tagsize to header, since it's a pretty useful funciton.
This commit is contained in:
@@ -29,19 +29,6 @@ static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) {
|
|||||||
return strncmp(str, matstr, len);
|
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.
|
/* 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.
|
* `NBT_COMPOUND` and `NBT_END` tags are not valid for this function and should be handled separately.
|
||||||
* `NULL` is returned if anything went wrong. */
|
* `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
|
// TODO: finish function
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../util/atrb.h"
|
||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
|
|
||||||
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
|
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
|
||||||
@@ -34,3 +35,6 @@ enum nbt_tagid {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len);
|
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len);
|
||||||
|
|
||||||
|
/* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */
|
||||||
|
atrb_const int nbt_prim_tagsize(u8 tag);
|
||||||
|
|||||||
Reference in New Issue
Block a user