lib/nbt: Add NBT::Tag::List::getContainedType()
Supid oversight, easily work-aroundable, but it doesn’t hurt and was easy to implementSoda
parent
36dcf0a0f5
commit
df35243ee9
|
@ -867,6 +867,10 @@ namespace NBT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t List::getContainedType() {
|
||||||
|
return this->containedType;
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOrVoid List::serializeWithoutHeader(std::vector<uint8_t>* rawData) {
|
ErrorOrVoid List::serializeWithoutHeader(std::vector<uint8_t>* rawData) {
|
||||||
if (this->containedType == TagType::INVALID) {
|
if (this->containedType == TagType::INVALID) {
|
||||||
return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE);
|
return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE);
|
||||||
|
|
|
@ -234,6 +234,7 @@ namespace NBT {
|
||||||
|
|
||||||
ErrorOrVoid serializeWithoutHeader(std::vector<uint8_t>* rawData) override;
|
ErrorOrVoid serializeWithoutHeader(std::vector<uint8_t>* rawData) override;
|
||||||
|
|
||||||
|
uint8_t getContainedType();
|
||||||
ErrorOr<Generic*> getElementPointer(uint64_t position);
|
ErrorOr<Generic*> getElementPointer(uint64_t position);
|
||||||
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
|
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
|
||||||
ErrorOrVoid appendPointer(Generic* pointer);
|
ErrorOrVoid appendPointer(Generic* pointer);
|
||||||
|
|
|
@ -784,6 +784,7 @@ int main(){
|
||||||
ASSERT(list_0.serialize(&vector).errorCode == ErrorCodes::INVALID_TYPE);
|
ASSERT(list_0.serialize(&vector).errorCode == ErrorCodes::INVALID_TYPE);
|
||||||
vector.clear();
|
vector.clear();
|
||||||
NBT::Tag::List list_1 = NBT::Tag::List("list_1", NBT::TagType::INT8);
|
NBT::Tag::List list_1 = NBT::Tag::List("list_1", NBT::TagType::INT8);
|
||||||
|
ASSERT(list_1.getContainedType() == NBT::TagType::INT8);
|
||||||
ASSERT(!list_1.appendPointer(pointer_1_0).isError);
|
ASSERT(!list_1.appendPointer(pointer_1_0).isError);
|
||||||
ASSERT(!list_1.appendPointer(pointer_1_1).isError);
|
ASSERT(!list_1.appendPointer(pointer_1_1).isError);
|
||||||
ASSERT(!list_1.appendPointer(pointer_1_2).isError);
|
ASSERT(!list_1.appendPointer(pointer_1_2).isError);
|
||||||
|
@ -794,6 +795,7 @@ int main(){
|
||||||
//TODO: Check that constructing with a vector of mixed tags
|
//TODO: Check that constructing with a vector of mixed tags
|
||||||
// results in a clearly defined failure mode (issue #60)
|
// results in a clearly defined failure mode (issue #60)
|
||||||
NBT::Tag::List list_2 = NBT::Tag::List("list_2", listDataVector);
|
NBT::Tag::List list_2 = NBT::Tag::List("list_2", listDataVector);
|
||||||
|
ASSERT(list_2.getContainedType() == NBT::TagType::INT8);
|
||||||
ASSERT(list_1.length() == 4 && list_2.length() == 4);
|
ASSERT(list_1.length() == 4 && list_2.length() == 4);
|
||||||
ASSERT(!list_2.deleteElement(1).isError);
|
ASSERT(!list_2.deleteElement(1).isError);
|
||||||
ASSERT(list_2.deleteElement(3).isError && list_2.deleteElement(3).errorCode == ErrorCodes::OUT_OF_RANGE);
|
ASSERT(list_2.deleteElement(3).isError && list_2.deleteElement(3).errorCode == ErrorCodes::OUT_OF_RANGE);
|
||||||
|
|
Loading…
Reference in New Issue