mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 07:35:45 +01:00
add basic function signature for processing the NBT data
This commit is contained in:
32
src/dat/nbt.c
Normal file
32
src/dat/nbt.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "nbt.h"
|
||||||
|
|
||||||
|
#include <endian.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "../util/types.h"
|
||||||
|
|
||||||
|
/* the data structure that functions passes between functions, so it can communicate with the central function */
|
||||||
|
struct nbt_procdat {
|
||||||
|
u32 ncomp; // the number of compound tags we've encountered
|
||||||
|
};
|
||||||
|
|
||||||
|
/* returns the string length from a specific location in the buffer */
|
||||||
|
static inline u16 nbt_strlen(u8 const *restrict buf) {
|
||||||
|
return be16toh(*(u16 *)(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) {
|
||||||
|
struct nbt_procdat procdat = {0};
|
||||||
|
|
||||||
|
// first byte should be a compound tag
|
||||||
|
if (*buf != NBT_COMPOUND) return 1;
|
||||||
|
|
||||||
|
// ignore the first tag + its name, so we start with the juicy data
|
||||||
|
uint tmp = nbt_strlen(buf + 1) + 3;
|
||||||
|
buf += tmp;
|
||||||
|
len -= tmp;
|
||||||
|
procdat.ncomp++;
|
||||||
|
|
||||||
|
// TODO: finish function
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -2,6 +2,11 @@
|
|||||||
// Licensed under the MIT Licence. See LICENSE for details
|
// Licensed under the MIT Licence. See LICENSE for details
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.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.
|
||||||
* NBT files are a compressed `compound` tag. GZip is the compression used in most cases,
|
* NBT files are a compressed `compound` tag. GZip is the compression used in most cases,
|
||||||
* in some (rare) cases it's stored uncompressed.
|
* in some (rare) cases it's stored uncompressed.
|
||||||
@@ -27,3 +32,5 @@ enum nbt_tagid {
|
|||||||
NBT_ARR_I32 = 0x0B, // starts with a i32, denoting size, followed by the i32 data
|
NBT_ARR_I32 = 0x0B, // starts with a i32, denoting size, followed by the i32 data
|
||||||
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
|
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len);
|
||||||
|
|||||||
Reference in New Issue
Block a user