Compare commits
3 Commits
ab920a114b
...
8594f4cbb0
Author | SHA1 | Date |
---|---|---|
BodgeMaster | 8594f4cbb0 | |
BodgeMaster | 83d606a2c7 | |
BodgeMaster | 081035db32 |
|
@ -15,22 +15,59 @@
|
||||||
|
|
||||||
#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 helpers {
|
namespace helper {
|
||||||
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>(0);
|
return ErrorOr<int8_t>((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>(0);
|
return ErrorOr<int16_t>((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>(0);
|
return ErrorOr<int32_t>((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>(0);
|
return ErrorOr<int64_t>((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,5 +40,31 @@
|
||||||
#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