Skip to content

Commit

Permalink
Fixed binary compatibility (#90)
Browse files Browse the repository at this point in the history
Made named parameter optional
  • Loading branch information
gentlegiantJGC authored Oct 14, 2024
1 parent 0d921f5 commit fd4f246
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
13 changes: 4 additions & 9 deletions src/amulet_nbt/cpp/nbt_encoding/binary/read_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,19 @@ namespace AmuletNBT {
}

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

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

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

// Read count (un)named tags from the string at position offset.
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, bool named, size_t& offset, size_t count){
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, size_t& offset, size_t count, bool named){
AmuletNBT::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<AmuletNBT::NamedTag> out;
for (size_t i = 0; i < count; i++){
Expand All @@ -198,7 +193,7 @@ namespace AmuletNBT {
}

// Read all (un)named tags from the string at position offset.
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, bool named, size_t& offset){
std::vector<AmuletNBT::NamedTag> read_nbt_array(const std::string& raw, std::endian endianness, AmuletNBT::StringDecode string_decode, size_t& offset, bool named){
AmuletNBT::BinaryReader reader(raw, offset, endianness, string_decode);
std::vector<AmuletNBT::NamedTag> out;
while (reader.has_more_data()){
Expand Down
11 changes: 5 additions & 6 deletions src/amulet_nbt/include/amulet_nbt/nbt_encoding/binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
#include <amulet_nbt/string_encoding.hpp>

namespace AmuletNBT {
NamedTag read_nbt(BinaryReader& reader, bool named);
NamedTag read_nbt(const std::string&, std::endian, StringDecode, bool named, size_t& offset);
NamedTag read_nbt(const std::string&, std::endian, StringDecode, bool named);
NamedTag read_nbt(const std::string&, std::endian, StringDecode);
std::vector<NamedTag> read_nbt_array(const std::string&, std::endian, StringDecode, bool named, size_t& offset);
std::vector<NamedTag> read_nbt_array(const std::string&, std::endian, StringDecode, bool named, size_t& offset, size_t count);
NamedTag read_nbt(BinaryReader& reader, bool named = true);
NamedTag read_nbt(const std::string&, std::endian, StringDecode, size_t& offset, bool named = true);
NamedTag read_nbt(const std::string&, std::endian, StringDecode, bool named = true);
std::vector<NamedTag> read_nbt_array(const std::string&, std::endian, StringDecode, size_t& offset, bool named = true);
std::vector<NamedTag> read_nbt_array(const std::string&, std::endian, StringDecode, size_t& offset, size_t count, bool named);

void write_nbt(BinaryWriter&, const std::optional<std::string>& name, const ByteTag&);
void write_nbt(BinaryWriter&, const std::optional<std::string>& name, const ShortTag&);
Expand Down
20 changes: 10 additions & 10 deletions src/amulet_nbt/pybind/bnbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ void init_bnbt(py::module& m) {
buffer,
endianness,
string_decoder,
named,
read_offset.offset
read_offset.offset,
named
);
} else if (read_offset_py.is(py::none())){
return AmuletNBT::read_nbt(
Expand Down Expand Up @@ -203,17 +203,17 @@ void init_bnbt(py::module& m) {
buffer,
endianness,
string_decoder,
named,
read_offset.offset
read_offset.offset,
named
);
} else {
return AmuletNBT::read_nbt_array(
buffer,
endianness,
string_decoder,
named,
read_offset.offset,
count
count,
named
);
}
} else if (read_offset_py.is(py::none())){
Expand All @@ -223,17 +223,17 @@ void init_bnbt(py::module& m) {
buffer,
endianness,
string_decoder,
named,
offset
offset,
named
);
} else {
return AmuletNBT::read_nbt_array(
buffer,
endianness,
string_decoder,
named,
offset,
count
count,
named
);
}
} else {
Expand Down

0 comments on commit fd4f246

Please sign in to comment.