diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index dc3ceac..743ef63 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -1,6 +1,12 @@ #include +#include +#include -// This is just an example for how to find out if the system is big endian or little endian. Do not use this. +#include "nbt.h++" +#include "error.h++" + +// This is just an example for how to find out if the system is big endian +// or little endian. Do not use this. int endianness_example() { if constexpr (std::endian::native == std::endian::big) { @@ -20,3 +26,74 @@ int endianness_example() { } } +namespace NBT { + namespace helpers { + ErrorOr readByte(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr(0); + } + + ErrorOr readInt16(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr(0); + } + + ErrorOr readInt32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr(0); + } + + ErrorOr readInt64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr(0); + } + + //FIXME: we just assume that float is a single-precision IEEE754 + // floating point number + ErrorOr readFloat32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement assuming standard single-precision IEEE754 float + // Alternatively, maybe calculate a floating point number by using + // the stored value as math instructions? + return ErrorOr(0.0f); + } + + //FIXME: we just assume that double is a double-precision IEEE754 + // floating point number + ErrorOr readFloat64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement assuming standard double-precision IEEE754 float + // Alternatively, maybe calculate a floating point number by using + // the stored value as math instructions? + return ErrorOr(0.0); + } + + ErrorOr> readByteArray(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr>({0}); + } + + //TODO: find suitable string type + // Maybe use a struct that holds decoded (de-Java-fied) string + // data, decoded size, and original size? Original size is needed + // so the parser knows where to continue. + //ErrorOr<> readString(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + // return ErrorOr<>(""); + //} + + ErrorOr> readInt32Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr>({0}); + } + + ErrorOr> readInt64Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) { + //TODO: implement + return ErrorOr>({0}); + } + } + + bool validateRawNBTData(uint8_t* data[], uint64_t dataSize){ + //state machine? + //TODO: implement + return false; + } +} diff --git a/src/lib/nbt.h++ b/src/lib/nbt.h++ index bee457b..ab1f937 100644 --- a/src/lib/nbt.h++ +++ b/src/lib/nbt.h++ @@ -18,3 +18,12 @@ // Tag[] (compound): Tag(10, String:name, uint16:name_size, Tag[]:content, int32:size) => list of tags, last tag is always an end tag, size not stored // int32[]: Tag(11, String:name, uint16:name_size, int32[]:content,int32:size) => list of 32 bit signed integers prefixed with its size, endianness not verified at this point // int64[]: Tag(12, String:name, uint16:name_size, int64[]:content,int32:size) => list of 64 bit signed integers prefixed with its size, endianness not verified at this point + +#pragma once +#include +#include +#include "error.h++" + +namespace NBT { + bool validateRawNBTData(uint8_t* data[], int length); +}