Compare commits

..

13 Commits

View File

@@ -24,18 +24,18 @@ static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {
// integral types // integral types
case NBT_I8: *dat = *ptr; return ptr; case NBT_I8: *dat = *ptr; return ptr;
case NBT_I16: *(u16 *)dat = be16toh(*(u16 *)ptr); return ptr + 2; case NBT_I16: *(u16 *)dat = be16toh(*(u16 *)ptr); return ptr + 2;
case NBT_I32: // fall through case NBT_I32: __attribute__((fallthrough));
case NBT_F32: *(u32 *)dat = be16toh(*(u32 *)ptr); return ptr + 4; case NBT_F32: *(u32 *)dat = be16toh(*(u32 *)ptr); return ptr + 4;
case NBT_I64: // fall through case NBT_I64: __attribute__((fallthrough));
case NBT_F64: *(u64 *)dat = be16toh(*(u64 *)ptr); return ptr + 8; case NBT_F64: *(u64 *)dat = be16toh(*(u64 *)ptr); return ptr + 8;
// arrays, handled differently // arrays, handled differently
case NBT_LIST: case NBT_LIST: __attribute__((fallthrough));
case NBT_ARR_I8: case NBT_ARR_I8: __attribute__((fallthrough));
case NBT_STR: case NBT_STR: __attribute__((fallthrough));
case NBT_ARR_I32: case NBT_ARR_I32: __attribute__((fallthrough));
case NBT_ARR_I64: case NBT_ARR_I64:
// TODO: arrlen = nbt_arrbsize(ptr); // arrlen = nbt_arrbsize(ptr);
break; break;
default: return NULL; default: return NULL;
@@ -100,26 +100,24 @@ int nbt_primsize(u8 tag) {
switch (tag) { switch (tag) {
case NBT_I8: return 1; case NBT_I8: return 1;
case NBT_I16: return 2; case NBT_I16: return 2;
case NBT_I32: // fall through case NBT_I32: __attribute__((fallthrough));
case NBT_F32: return 4; case NBT_F32: return 4;
case NBT_I64: // fall through case NBT_I64: __attribute__((fallthrough));
case NBT_F64: return 8; case NBT_F64: return 8;
default: return -1; default: return -1;
} }
} }
size_t nbt_tagdatlen(const u8 *restrict buf) { size_t nbt_tagdatlen(const u8 *restrict buf) {
size_t mems = 0; i32 mems = 0;
switch (*buf) { switch (*buf) {
case NBT_I8: case NBT_I8: __attribute__((fallthrough));
case NBT_I16: case NBT_I16: __attribute__((fallthrough));
case NBT_I32: case NBT_I32: __attribute__((fallthrough));
case NBT_F32: case NBT_F32: __attribute__((fallthrough));
case NBT_I64: case NBT_I64: __attribute__((fallthrough));
case NBT_F64: case NBT_F64: __attribute__((fallthrough));
mems = nbt_primsize(*buf);
return -(mems >= 0) & mems;
case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough)); case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough));
case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough)); case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough));
@@ -137,11 +135,11 @@ size_t nbt_tagdatlen(const u8 *restrict buf) {
int nbt_isprim(u8 tag) { int nbt_isprim(u8 tag) {
switch (tag) { switch (tag) {
case NBT_I8: case NBT_I8: __attribute__((fallthrough));
case NBT_I16: case NBT_I16: __attribute__((fallthrough));
case NBT_I32: case NBT_I32: __attribute__((fallthrough));
case NBT_F32: case NBT_F32: __attribute__((fallthrough));
case NBT_I64: case NBT_I64: __attribute__((fallthrough));
case NBT_F64: case NBT_F64:
return 1; return 1;
default: default: