Skip to content

Commit

Permalink
Changed namespace
Browse files Browse the repository at this point in the history
Changed Amulet namespace to AmuletNBT.
This should help avoid conflicts
  • Loading branch information
gentlegiantJGC committed Jul 17, 2024
1 parent 7d9f184 commit 5cfbd41
Show file tree
Hide file tree
Showing 35 changed files with 777 additions and 777 deletions.
104 changes: 52 additions & 52 deletions src/amulet_nbt/cpp/nbt_encoding/binary/read_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@

#include <amulet_nbt/nbt_encoding/binary.hpp>

Amulet::StringTag read_string_tag(Amulet::BinaryReader& reader){
AmuletNBT::StringTag read_string_tag(AmuletNBT::BinaryReader& reader){
std::uint16_t length = reader.readNumeric<std::uint16_t>();
return reader.readString(length);
};


Amulet::TagNode read_node(Amulet::BinaryReader& reader, std::uint8_t tag_id);
AmuletNBT::TagNode read_node(AmuletNBT::BinaryReader& reader, std::uint8_t tag_id);


Amulet::CompoundTagPtr read_compound_tag(Amulet::BinaryReader& reader){
Amulet::CompoundTagPtr tag = std::make_shared<Amulet::CompoundTag>();
AmuletNBT::CompoundTagPtr read_compound_tag(AmuletNBT::BinaryReader& reader){
AmuletNBT::CompoundTagPtr tag = std::make_shared<AmuletNBT::CompoundTag>();
while (true){
std::uint8_t tag_id = reader.readNumeric<std::uint8_t>();
if (tag_id == 0){
break;
}
Amulet::StringTag name = read_string_tag(reader);
Amulet::TagNode node = read_node(reader, tag_id);
AmuletNBT::StringTag name = read_string_tag(reader);
AmuletNBT::TagNode node = read_node(reader, tag_id);
(*tag)[name] = node;
}
return tag;
};


template <typename T>
std::shared_ptr<Amulet::ArrayTag<T>> read_array_tag(Amulet::BinaryReader& reader){
std::shared_ptr<AmuletNBT::ArrayTag<T>> read_array_tag(AmuletNBT::BinaryReader& reader){
std::int32_t length = reader.readNumeric<std::int32_t>();
if (length < 0){length = 0;}
std::shared_ptr<Amulet::ArrayTag<T>> tag = std::make_shared<Amulet::ArrayTag<T>>(length);
std::shared_ptr<AmuletNBT::ArrayTag<T>> tag = std::make_shared<AmuletNBT::ArrayTag<T>>(length);
for (std::int32_t i = 0; i < length; i++){
reader.readNumericInto((*tag)[i]);
}
Expand All @@ -45,10 +45,10 @@ std::shared_ptr<Amulet::ArrayTag<T>> read_array_tag(Amulet::BinaryReader& reader


template <typename T>
Amulet::ListTagPtr read_numeric_list_tag(Amulet::BinaryReader& reader){
AmuletNBT::ListTagPtr read_numeric_list_tag(AmuletNBT::BinaryReader& reader){
std::int32_t length = reader.readNumeric<std::int32_t>();
if (length < 0){length = 0;}
Amulet::ListTagPtr tag = std::make_shared<Amulet::ListTag>(std::vector<T>(length));
AmuletNBT::ListTagPtr tag = std::make_shared<AmuletNBT::ListTag>(std::vector<T>(length));
std::vector<T>& list = std::get<std::vector<T>>(*tag);
for (std::int32_t i = 0; i < length; i++){
reader.readNumericInto<T>(list[i]);
Expand All @@ -57,11 +57,11 @@ Amulet::ListTagPtr read_numeric_list_tag(Amulet::BinaryReader& reader){
}


template <typename T, T (*readTag)(Amulet::BinaryReader&)>
Amulet::ListTagPtr read_template_list_tag(Amulet::BinaryReader& reader){
template <typename T, T (*readTag)(AmuletNBT::BinaryReader&)>
AmuletNBT::ListTagPtr read_template_list_tag(AmuletNBT::BinaryReader& reader){
std::int32_t length = reader.readNumeric<std::int32_t>();
if (length < 0){length = 0;}
Amulet::ListTagPtr tag = std::make_shared<Amulet::ListTag>(std::vector<T>(length));
AmuletNBT::ListTagPtr tag = std::make_shared<AmuletNBT::ListTag>(std::vector<T>(length));
std::vector<T>& list = std::get<std::vector<T>>(*tag);
for (std::int32_t i = 0; i < length; i++){
list[i] = readTag(reader);
Expand All @@ -70,69 +70,69 @@ Amulet::ListTagPtr read_template_list_tag(Amulet::BinaryReader& reader){
}


Amulet::ListTagPtr read_void_list_tag(Amulet::BinaryReader& reader){
AmuletNBT::ListTagPtr read_void_list_tag(AmuletNBT::BinaryReader& reader){
std::int32_t length = reader.readNumeric<std::int32_t>();
if (length < 0){length = 0;}
if (length != 0){throw std::runtime_error("Void list tag must have a length of 0");}
return std::make_shared<Amulet::ListTag>();
return std::make_shared<AmuletNBT::ListTag>();
}


Amulet::ListTagPtr read_list_tag(Amulet::BinaryReader& reader){
AmuletNBT::ListTagPtr read_list_tag(AmuletNBT::BinaryReader& reader){
std::uint8_t tag_type = reader.readNumeric<std::uint8_t>();
switch(tag_type){
case 0:
return read_void_list_tag(reader);
case 1:
return read_numeric_list_tag<Amulet::ByteTag>(reader);
return read_numeric_list_tag<AmuletNBT::ByteTag>(reader);
case 2:
return read_numeric_list_tag<Amulet::ShortTag>(reader);
return read_numeric_list_tag<AmuletNBT::ShortTag>(reader);
case 3:
return read_numeric_list_tag<Amulet::IntTag>(reader);
return read_numeric_list_tag<AmuletNBT::IntTag>(reader);
case 4:
return read_numeric_list_tag<Amulet::LongTag>(reader);
return read_numeric_list_tag<AmuletNBT::LongTag>(reader);
case 5:
return read_numeric_list_tag<Amulet::FloatTag>(reader);
return read_numeric_list_tag<AmuletNBT::FloatTag>(reader);
case 6:
return read_numeric_list_tag<Amulet::DoubleTag>(reader);
return read_numeric_list_tag<AmuletNBT::DoubleTag>(reader);
case 7:
return read_template_list_tag<Amulet::ByteArrayTagPtr, read_array_tag<Amulet::ByteTag>>(reader);
return read_template_list_tag<AmuletNBT::ByteArrayTagPtr, read_array_tag<AmuletNBT::ByteTag>>(reader);
case 8:
return read_template_list_tag<Amulet::StringTag, read_string_tag>(reader);
return read_template_list_tag<AmuletNBT::StringTag, read_string_tag>(reader);
case 9:
return read_template_list_tag<Amulet::ListTagPtr, read_list_tag>(reader);
return read_template_list_tag<AmuletNBT::ListTagPtr, read_list_tag>(reader);
case 10:
return read_template_list_tag<Amulet::CompoundTagPtr, read_compound_tag>(reader);
return read_template_list_tag<AmuletNBT::CompoundTagPtr, read_compound_tag>(reader);
case 11:
return read_template_list_tag<Amulet::IntArrayTagPtr, read_array_tag<Amulet::IntTag>>(reader);
return read_template_list_tag<AmuletNBT::IntArrayTagPtr, read_array_tag<AmuletNBT::IntTag>>(reader);
case 12:
return read_template_list_tag<Amulet::LongArrayTagPtr, read_array_tag<Amulet::LongTag>>(reader);
return read_template_list_tag<AmuletNBT::LongArrayTagPtr, read_array_tag<AmuletNBT::LongTag>>(reader);
default:
throw std::runtime_error("This shouldn't happen");
}
};


Amulet::TagNode read_node(Amulet::BinaryReader& reader, std::uint8_t tag_id){
Amulet::TagNode node;
AmuletNBT::TagNode read_node(AmuletNBT::BinaryReader& reader, std::uint8_t tag_id){
AmuletNBT::TagNode node;
switch(tag_id){
case 1:
node = reader.readNumeric<Amulet::ByteTag>();
node = reader.readNumeric<AmuletNBT::ByteTag>();
break;
case 2:
node = reader.readNumeric<Amulet::ShortTag>();
node = reader.readNumeric<AmuletNBT::ShortTag>();
break;
case 3:
node = reader.readNumeric<Amulet::IntTag>();
node = reader.readNumeric<AmuletNBT::IntTag>();
break;
case 4:
node = reader.readNumeric<Amulet::LongTag>();
node = reader.readNumeric<AmuletNBT::LongTag>();
break;
case 5:
node = reader.readNumeric<Amulet::FloatTag>();
node = reader.readNumeric<AmuletNBT::FloatTag>();
break;
case 6:
node = reader.readNumeric<Amulet::DoubleTag>();
node = reader.readNumeric<AmuletNBT::DoubleTag>();
break;
case 8:
node = read_string_tag(reader);
Expand All @@ -144,13 +144,13 @@ Amulet::TagNode read_node(Amulet::BinaryReader& reader, std::uint8_t tag_id){
node = read_compound_tag(reader);
break;
case 7:
node = read_array_tag<Amulet::ByteTag>(reader);
node = read_array_tag<AmuletNBT::ByteTag>(reader);
break;
case 11:
node = read_array_tag<Amulet::IntTag>(reader);
node = read_array_tag<AmuletNBT::IntTag>(reader);
break;
case 12:
node = read_array_tag<Amulet::LongTag>(reader);
node = read_array_tag<AmuletNBT::LongTag>(reader);
break;
default:
throw std::runtime_error("Unsupported tag type");
Expand All @@ -159,40 +159,40 @@ Amulet::TagNode read_node(Amulet::BinaryReader& reader, std::uint8_t tag_id){
};


namespace Amulet {
Amulet::NamedTag read_nbt(Amulet::BinaryReader& reader){
namespace AmuletNBT {
AmuletNBT::NamedTag read_nbt(AmuletNBT::BinaryReader& reader){
std::uint8_t tag_id = reader.readNumeric<std::uint8_t>();
std::string name = read_string_tag(reader);
Amulet::TagNode node = read_node(reader, tag_id);
return Amulet::NamedTag(name, node);
AmuletNBT::TagNode node = read_node(reader, tag_id);
return AmuletNBT::NamedTag(name, node);
}

// Read one named tag from the string at position offset.
Amulet::NamedTag read_nbt(const std::string& raw, std::endian endianness, Amulet::StringDecode string_decode, size_t& offset){
Amulet::BinaryReader reader(raw, offset, endianness, string_decode);
AmuletNBT::NamedTag read_nbt(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, size_t& offset){
AmuletNBT::BinaryReader reader(raw, offset, endianness, string_decode);
return read_nbt(reader);
}

// Read one named tag from the string.
Amulet::NamedTag read_nbt(const std::string& raw, std::endian endianness, Amulet::StringDecode string_decode){
AmuletNBT::NamedTag read_nbt(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode){
size_t offset = 0;
return read_nbt(raw, endianness, string_decode, offset);
}

// Read count named tags from the string at position offset.
std::vector<Amulet::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, Amulet::StringDecode string_decode, size_t& offset, size_t count){
Amulet::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<Amulet::NamedTag> out;
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, size_t& offset, size_t count){
AmuletNBT::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<AmuletNBT::NamedTag> out;
for (size_t i = 0; i < count; i++){
out.push_back(read_nbt(reader));
}
return out;
}

// Read all named tags from the string at position offset.
std::vector<Amulet::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, Amulet::StringDecode string_decode, size_t& offset){
Amulet::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<Amulet::NamedTag> out;
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, size_t& offset){
AmuletNBT::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<AmuletNBT::NamedTag> out;
while (reader.has_more_data()){
out.push_back(read_nbt(reader));
}
Expand Down
Loading

0 comments on commit 5cfbd41

Please sign in to comment.