lib/nbt: Various minor fixes to get the program to compile properly
parent
68fbf3ae20
commit
396b9673fd
|
@ -463,7 +463,7 @@ namespace NBT {
|
||||||
case TagType::DOUBLE:
|
case TagType::DOUBLE:
|
||||||
// type byte + name size + 8 data bytes -> 11 bytes
|
// type byte + name size + 8 data bytes -> 11 bytes
|
||||||
return ErrorOr<uint64_t>((uint64_t) nameSize.value+11);
|
return ErrorOr<uint64_t>((uint64_t) nameSize.value+11);
|
||||||
case TagType::INT8_ARRAY:
|
case TagType::INT8_ARRAY: {
|
||||||
// type byte + name size + 4 size bytes -> 7 bytes
|
// type byte + name size + 4 size bytes -> 7 bytes
|
||||||
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
||||||
|
|
||||||
|
@ -475,7 +475,8 @@ namespace NBT {
|
||||||
totalSize += (uint64_t) arraySize.value;
|
totalSize += (uint64_t) arraySize.value;
|
||||||
|
|
||||||
return ErrorOr<uint64_t>(totalSize);
|
return ErrorOr<uint64_t>(totalSize);
|
||||||
case TagType::STRING:
|
}
|
||||||
|
case TagType::STRING: {
|
||||||
// type byte + name size + 2 size bytes -> 5 bytes
|
// type byte + name size + 2 size bytes -> 5 bytes
|
||||||
uint64_t totalSize = (uint64_t) nameSize.value+5;
|
uint64_t totalSize = (uint64_t) nameSize.value+5;
|
||||||
|
|
||||||
|
@ -487,7 +488,8 @@ namespace NBT {
|
||||||
totalSize += (uint64_t) stringSize.value;
|
totalSize += (uint64_t) stringSize.value;
|
||||||
|
|
||||||
return ErrorOr<uint64_t>(totalSize);
|
return ErrorOr<uint64_t>(totalSize);
|
||||||
case TagType::LIST:
|
}
|
||||||
|
case TagType::LIST: {
|
||||||
// type byte + name size + type prefix + 4 size bytes -> 8 bytes
|
// type byte + name size + type prefix + 4 size bytes -> 8 bytes
|
||||||
uint64_t totalSize = (uint64_t) nameSize.value+8;
|
uint64_t totalSize = (uint64_t) nameSize.value+8;
|
||||||
|
|
||||||
|
@ -506,23 +508,30 @@ namespace NBT {
|
||||||
switch (containedType.value) {
|
switch (containedType.value) {
|
||||||
case TagType::END:
|
case TagType::END:
|
||||||
factor = 1;
|
factor = 1;
|
||||||
|
break;
|
||||||
case TagType::INT8:
|
case TagType::INT8:
|
||||||
factor = 1;
|
factor = 1;
|
||||||
|
break;
|
||||||
case TagType::INT16:
|
case TagType::INT16:
|
||||||
factor = 2;
|
factor = 2;
|
||||||
|
break;
|
||||||
case TagType::INT32:
|
case TagType::INT32:
|
||||||
factor = 4;
|
factor = 4;
|
||||||
|
break;
|
||||||
case TagType::INT64:
|
case TagType::INT64:
|
||||||
factor = 8;
|
factor = 8;
|
||||||
|
break;
|
||||||
case TagType::FLOAT:
|
case TagType::FLOAT:
|
||||||
factor = 4;
|
factor = 4;
|
||||||
|
break;
|
||||||
case TagType::DOUBLE:
|
case TagType::DOUBLE:
|
||||||
factor = 8;
|
factor = 8;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// How would you even get here?
|
// How would you even get here?
|
||||||
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
||||||
}
|
}
|
||||||
totalSize += listSize*factor;
|
totalSize += listSize.value*factor;
|
||||||
return ErrorOr<uint64_t>(totalSize);
|
return ErrorOr<uint64_t>(totalSize);
|
||||||
} else {
|
} else {
|
||||||
if (containedType.value == TagType::COMPOUND || containedType.value == TagType::LIST) return ErrorOr<uint64_t>(false, ErrorCodes::NOT_YET_KNOWN);
|
if (containedType.value == TagType::COMPOUND || containedType.value == TagType::LIST) return ErrorOr<uint64_t>(false, ErrorCodes::NOT_YET_KNOWN);
|
||||||
|
@ -530,7 +539,8 @@ namespace NBT {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
||||||
case TagType::INT32_ARRAY:
|
}
|
||||||
|
case TagType::INT32_ARRAY: {
|
||||||
// type byte + name size + 4 size bytes -> 7 bytes
|
// type byte + name size + 4 size bytes -> 7 bytes
|
||||||
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
||||||
|
|
||||||
|
@ -542,7 +552,8 @@ namespace NBT {
|
||||||
totalSize += (uint64_t) arraySize.value*4;
|
totalSize += (uint64_t) arraySize.value*4;
|
||||||
|
|
||||||
return ErrorOr<uint64_t>(totalSize);
|
return ErrorOr<uint64_t>(totalSize);
|
||||||
case TagType::INT64_ARRAY:
|
}
|
||||||
|
case TagType::INT64_ARRAY: {
|
||||||
// type byte + name size + 4 size bytes -> 7 bytes
|
// type byte + name size + 4 size bytes -> 7 bytes
|
||||||
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
uint64_t totalSize = (uint64_t) nameSize.value+7;
|
||||||
|
|
||||||
|
@ -554,6 +565,7 @@ namespace NBT {
|
||||||
totalSize += (uint64_t) arraySize.value*8;
|
totalSize += (uint64_t) arraySize.value*8;
|
||||||
|
|
||||||
return ErrorOr<uint64_t>(totalSize);
|
return ErrorOr<uint64_t>(totalSize);
|
||||||
|
}
|
||||||
// fall-through in case of unknown tag or parsing error
|
// fall-through in case of unknown tag or parsing error
|
||||||
default:
|
default:
|
||||||
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
return ErrorOr<uint64_t>(true, ErrorCodes::UNKNOWN);
|
||||||
|
|
Loading…
Reference in New Issue