Compare commits
5 Commits
cad04d8e12
...
f80a33ddb0
Author | SHA1 | Date |
---|---|---|
BodgeMaster | f80a33ddb0 | |
BodgeMaster | d0464d4a8f | |
BodgeMaster | 82773f3429 | |
BodgeMaster | 5ea835dbb5 | |
BodgeMaster | 89e7a89e88 |
18
build.sh
18
build.sh
|
@ -13,7 +13,7 @@ CXX_WITH_FLAGS="$CXX $CXXFLAGS"
|
||||||
echo "Building libs..."
|
echo "Building libs..."
|
||||||
mkdir -pv bin/lib
|
mkdir -pv bin/lib
|
||||||
for lib in $(find ./src/lib -name "*.cpp"); do
|
for lib in $(find ./src/lib -name "*.cpp"); do
|
||||||
COMPILE_COMMAND="$CXX_WITH_FLAGS -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib"
|
COMPILE_COMMAND="$CXX_WITH_FLAGS -fPIC -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib"
|
||||||
echo $COMPILE_COMMAND
|
echo $COMPILE_COMMAND
|
||||||
$COMPILE_COMMAND &
|
$COMPILE_COMMAND &
|
||||||
done
|
done
|
||||||
|
@ -33,9 +33,13 @@ wait
|
||||||
# Example: LD_LIBRARY_PATH=bin/lib bin/tools/dumpnbt
|
# Example: LD_LIBRARY_PATH=bin/lib bin/tools/dumpnbt
|
||||||
echo "Building tools..."
|
echo "Building tools..."
|
||||||
mkdir -pv bin/tools
|
mkdir -pv bin/tools
|
||||||
# add compile commands to this variable
|
# add compile commands to this array
|
||||||
COMPILE_COMMANDS="
|
COMPILE_COMMANDS=(
|
||||||
set -v
|
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -l:nbt.so -o bin/tools/dumpnbt"
|
||||||
$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -l:nbt.so -o bin/tools/dumpnbt &
|
)
|
||||||
"
|
for command in ${!COMPILE_COMMANDS[@]}; do
|
||||||
sh <<< $COMPILE_COMMANDS
|
echo "${COMPILE_COMMANDS[command]}"
|
||||||
|
${COMPILE_COMMANDS[command]} &
|
||||||
|
done
|
||||||
|
|
||||||
|
wait
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
#include "error.h++"
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct ErrorOr {
|
||||||
|
bool isError;
|
||||||
|
T value;
|
||||||
|
|
||||||
|
ErrorOr<T>();
|
||||||
|
ErrorOr<T>(T);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
ErrorOr<T>::ErrorOr() {
|
||||||
|
this->isError = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
ErrorOr<T>::ErrorOr(T value) {
|
||||||
|
this->isError = false;
|
||||||
|
this->value = value;
|
||||||
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
#include <bit>
|
#include <bit>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
// 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() {
|
int endianness_example() {
|
||||||
if constexpr (std::endian::native == std::endian::big)
|
if constexpr (std::endian::native == std::endian::big)
|
||||||
{
|
{
|
||||||
|
@ -20,3 +26,74 @@ int endianness_example() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace NBT {
|
||||||
|
namespace helpers {
|
||||||
|
ErrorOr<int8_t> readByte(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<int8_t>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<int16_t> readInt16(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<int16_t>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<int32_t> readInt32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<int32_t>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<int64_t> readInt64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<int64_t>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: we just assume that float is a single-precision IEEE754
|
||||||
|
// floating point number
|
||||||
|
ErrorOr<float> 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<float>(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: we just assume that double is a double-precision IEEE754
|
||||||
|
// floating point number
|
||||||
|
ErrorOr<double> 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<double>(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<std::vector<int8_t>> readByteArray(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<std::vector<int8_t>>({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<std::vector<int32_t>> readInt32Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<std::vector<int32_t>>({0});
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<std::vector<int64_t>> readInt64Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
|
//TODO: implement
|
||||||
|
return ErrorOr<std::vector<int64_t>>({0});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateRawNBTData(uint8_t* data[], uint64_t dataSize){
|
||||||
|
//state machine?
|
||||||
|
//TODO: implement
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,15 +6,24 @@
|
||||||
// All tag types:
|
// All tag types:
|
||||||
// generic representation: Tag(Byte:tag_type, String:name, uint16:name_size, byte[]:content, int32:size)
|
// generic representation: Tag(Byte:tag_type, String:name, uint16:name_size, byte[]:content, int32:size)
|
||||||
// None (compound end): Tag( 0, "", 0, None, 0) => used to determine the end of a compound tag, only the type gets stored
|
// None (compound end): Tag( 0, "", 0, None, 0) => used to determine the end of a compound tag, only the type gets stored
|
||||||
// byte: Tag( 1, String:name, uint16:name_size, byte:content, 1) => a single signed byte, size and content type not stored
|
// byte: Tag( 1, String:name, uint16:name_size, byte:content, 1) => a single signed byte, size not stored
|
||||||
// int16: Tag( 2, String:name, uint16:name_size, int16:content, 2) => 16 bit signed integer, size and content type not stored
|
// int16: Tag( 2, String:name, uint16:name_size, int16:content, 2) => 16 bit signed integer, size not stored
|
||||||
// int32: Tag( 3, String:name, uint16:name_size, int32:content, 4) => 32 bit signed integer, size and content type not stored
|
// int32: Tag( 3, String:name, uint16:name_size, int32:content, 4) => 32 bit signed integer, size not stored
|
||||||
// int64: Tag( 4, String:name, uint16:name_size, int64:content, 8) => 64 bit signed integer, size and content type not stored
|
// int64: Tag( 4, String:name, uint16:name_size, int64:content, 8) => 64 bit signed integer, size not stored
|
||||||
// float32: Tag( 5, String:name, uint16:name_size, float32:content,4) => 32 bit IEEE754 floating point number, size and content type not stored
|
// float32: Tag( 5, String:name, uint16:name_size, float32:content,4) => 32 bit IEEE754 floating point number, size not stored
|
||||||
// float64: Tag( 6, String:name, uint16:name_size, float64:content,8) => 64 bit IEEE754 floating point number, size and content type not stored
|
// float64: Tag( 6, String:name, uint16:name_size, float64:content,8) => 64 bit IEEE754 floating point number, size not stored
|
||||||
// byte[]: Tag( 7, String:name, uint16:name_size, byte[]:content, int32:size) => content stored prefixed with size, content type not stored
|
// byte[]: Tag( 7, String:name, uint16:name_size, byte[]:content, int32:size) => content stored prefixed with size
|
||||||
// String: Tag( 8, String:name, uint16:name_size, byte[]:content, uint16:size) => Java style modified UTF-8 string, content stored prefixed with size, content type not stored
|
// String: Tag( 8, String:name, uint16:name_size, byte[]:content, uint16:size) => Java style modified UTF-8 string, content stored prefixed with size
|
||||||
// Tag[] (list): Tag<Tag:type>( 9, String:name, uint16:name_size, Tag[]:content, int32:size) => list of tags of the same type with tag type and name information omitted prefixed by (in order) content type and size
|
// Tag[] (list): Tag<Tag:type>( 9, String:name, uint16:name_size, Tag[]:content, int32:size) => list of tags of the same type with tag type and name information omitted prefixed by (in order) content type and size
|
||||||
// Tag[] (compound): Tag(10, String:name, uint16:name_size, Tag[]:content, int32:size) => list of tags, last tag is always an end tag, size and content type not stored
|
// 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, content type not stored, endianness unknown at this point
|
// 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, content type not stored, endianness unknown 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 <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
#include "error.h++"
|
||||||
|
|
||||||
|
namespace NBT {
|
||||||
|
bool validateRawNBTData(uint8_t* data[], int length);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue