Compare commits
No commits in common. "8594f4cbb0d34c2f9d4ac624c180ba0b765eb304" and "ab920a114bb8aa9b5ca1ea88dade6b58d0144684" have entirely different histories.
8594f4cbb0
...
ab920a114b
|
@ -15,59 +15,22 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct ErrorOr {
|
struct ErrorOr {
|
||||||
bool isError;
|
bool isError;
|
||||||
uint8_t errorCode;
|
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
ErrorOr<T>();
|
ErrorOr<T>();
|
||||||
ErrorOr<T>(T);
|
ErrorOr<T>(T);
|
||||||
ErrorOr<T>(bool);
|
|
||||||
ErrorOr<T>(bool, uint8_t);
|
|
||||||
ErrorOr<T>(bool, uint8_t, T);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ErrorOr<T>::ErrorOr() {
|
ErrorOr<T>::ErrorOr() {
|
||||||
this->isError = false;
|
this->isError = false;
|
||||||
this->errorCode = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ErrorOr<T>::ErrorOr(T value) {
|
ErrorOr<T>::ErrorOr(T value) {
|
||||||
this->isError = false;
|
this->isError = false;
|
||||||
this->errorCode = 0;
|
|
||||||
this->value = value;
|
this->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ErrorOr<T>::ErrorOr(bool isError) {
|
|
||||||
this->isError = isError;
|
|
||||||
this->errorCode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ErrorOr<T>::ErrorOr(bool isError, uint8_t errorCode) {
|
|
||||||
this->isError = isError;
|
|
||||||
this->errorCode = errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ErrorOr<T>::ErrorOr(bool isError, uint8_t errorCode, T value) {
|
|
||||||
this->isError = isError;
|
|
||||||
this->errorCode = errorCode;
|
|
||||||
this->value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ErrorCodes {
|
|
||||||
// These are all arbitrary values used to assign error codes to different
|
|
||||||
// kinds of errors.
|
|
||||||
// Using them is optional as ErrorOr<> accepts any uint8_t value as
|
|
||||||
// error code, but they are useful for readability.
|
|
||||||
|
|
||||||
// IndexOutOfRangeException equivalent
|
|
||||||
const uint8_t RANGE_ERROR = 1;
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,25 +42,25 @@ int endianness_example() {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace NBT {
|
namespace NBT {
|
||||||
namespace helper {
|
namespace helpers {
|
||||||
ErrorOr<int8_t> readInt8(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
ErrorOr<int8_t> readInt8(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return ErrorOr<int8_t>((int8_t) 0);
|
return ErrorOr<int8_t>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int16_t> readInt16(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
ErrorOr<int16_t> readInt16(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return ErrorOr<int16_t>((int16_t) 0);
|
return ErrorOr<int16_t>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int32_t> readInt32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
ErrorOr<int32_t> readInt32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return ErrorOr<int32_t>((int32_t) 0);
|
return ErrorOr<int32_t>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int64_t> readInt64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
ErrorOr<int64_t> readInt64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition) {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return ErrorOr<int64_t>((int64_t) 0);
|
return ErrorOr<int64_t>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: we just assume that float is a single-precision IEEE754
|
//FIXME: we just assume that float is a single-precision IEEE754
|
||||||
|
|
|
@ -40,31 +40,5 @@
|
||||||
#include "error.h++"
|
#include "error.h++"
|
||||||
|
|
||||||
namespace NBT {
|
namespace NBT {
|
||||||
namespace helper {
|
|
||||||
ErrorOr<int8_t> readInt8(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
ErrorOr<int16_t> readInt16(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
ErrorOr<int32_t> readInt32(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
ErrorOr<int64_t> readInt64(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
ErrorOr<std::vector<int8_t>> readInt8Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
//ErrorOr<> readString(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
ErrorOr<std::vector<int32_t>> readInt32Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
|
|
||||||
ErrorOr<std::vector<int64_t>> readInt64Array(uint8_t* data[], uint64_t dataSize, uint64_t currentPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validateRawNBTData(uint8_t* data[], int length);
|
bool validateRawNBTData(uint8_t* data[], int length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue