@@ -30,12 +30,12 @@ namespace NBT {
3030 std::is_same_v<T, ByteTag> || std::is_same_v<T, ShortTag> || std::is_same_v<T, IntTag> || std::is_same_v<T, LongTag> || std::is_same_v<T, FloatTag> || std::is_same_v<T, DoubleTag>,
3131 bool >
3232 = true >
33- inline void write_payload (BinaryWriter & writer, const T& value)
33+ inline void write_payload (BaseBinaryWriter & writer, const T& value)
3434 {
3535 writer.write_numeric <typename T::native_type>(value);
3636 };
3737
38- inline void write_string (BinaryWriter & writer, const std::string& value)
38+ inline void write_string (BaseBinaryWriter & writer, const std::string& value)
3939 {
4040 std::string encoded_string = writer.encode_string (value);
4141 if (encoded_string.size () > static_cast <size_t >(std::numeric_limits<std::uint16_t >::max ())) {
@@ -51,7 +51,7 @@ namespace NBT {
5151 std::is_same_v<T, StringTag>,
5252 bool >
5353 = true >
54- inline void write_payload (BinaryWriter & writer, const T& value)
54+ inline void write_payload (BaseBinaryWriter & writer, const T& value)
5555 {
5656 write_string (writer, value);
5757 };
@@ -62,7 +62,7 @@ namespace NBT {
6262 std::is_same_v<T, ByteArrayTag> || std::is_same_v<T, IntArrayTag> || std::is_same_v<T, LongArrayTag>,
6363 bool >
6464 = true >
65- inline void write_payload (BinaryWriter & writer, const T& value)
65+ inline void write_payload (BaseBinaryWriter & writer, const T& value)
6666 {
6767 if (value.size () > static_cast <size_t >(std::numeric_limits<std::int32_t >::max ())) {
6868 throw std::overflow_error (" Array of length " + std::to_string (value.size ()) + " is too long." );
@@ -77,20 +77,20 @@ namespace NBT {
7777 template <
7878 class T ,
7979 std::enable_if_t <std::is_same_v<T, ListTag>, bool > = true >
80- inline void write_payload (BinaryWriter & writer, const T& value);
80+ inline void write_payload (BaseBinaryWriter & writer, const T& value);
8181
8282 template <
8383 class T ,
8484 std::enable_if_t <std::is_same_v<T, CompoundTag>, bool > = true >
85- inline void write_payload (BinaryWriter & writer, const T& value);
85+ inline void write_payload (BaseBinaryWriter & writer, const T& value);
8686
8787 template <
8888 class T ,
8989 std::enable_if_t <
9090 std::is_same_v<T, ListTagPtr> || std::is_same_v<T, CompoundTagPtr> || std::is_same_v<T, ByteArrayTagPtr> || std::is_same_v<T, IntArrayTagPtr> || std::is_same_v<T, LongArrayTagPtr>,
9191 bool >
9292 = true >
93- inline void write_payload (BinaryWriter & writer, const T value)
93+ inline void write_payload (BaseBinaryWriter & writer, const T value)
9494 {
9595 write_payload (writer, *value);
9696 }
@@ -101,7 +101,7 @@ namespace NBT {
101101 std::is_same_v<T, ByteTag> || std::is_same_v<T, ShortTag> || std::is_same_v<T, IntTag> || std::is_same_v<T, LongTag> || std::is_same_v<T, FloatTag> || std::is_same_v<T, DoubleTag> || std::is_same_v<T, ByteArrayTagPtr> || std::is_same_v<T, StringTag> || std::is_same_v<T, ListTagPtr> || std::is_same_v<T, CompoundTagPtr> || std::is_same_v<T, IntArrayTagPtr> || std::is_same_v<T, LongArrayTagPtr>,
102102 bool >
103103 = true >
104- inline void write_list_tag_payload (BinaryWriter & writer, const std::vector<T>& list)
104+ inline void write_list_tag_payload (BaseBinaryWriter & writer, const std::vector<T>& list)
105105 {
106106 if (list.size () > static_cast <size_t >(std::numeric_limits<std::int32_t >::max ())) {
107107 throw std::overflow_error (" List of length " + std::to_string (list.size ()) + " is too long." );
@@ -114,7 +114,7 @@ namespace NBT {
114114 }
115115
116116 template <>
117- inline void write_payload<ListTag>(BinaryWriter & writer, const ListTag& value)
117+ inline void write_payload<ListTag>(BaseBinaryWriter & writer, const ListTag& value)
118118 {
119119 std::visit ([&writer](auto && tag) {
120120 using T = std::decay_t <decltype (tag)>;
@@ -134,7 +134,7 @@ namespace NBT {
134134 std::is_same_v<T, ByteTag> || std::is_same_v<T, ShortTag> || std::is_same_v<T, IntTag> || std::is_same_v<T, LongTag> || std::is_same_v<T, FloatTag> || std::is_same_v<T, DoubleTag> || std::is_same_v<T, ByteArrayTag> || std::is_same_v<T, StringTag> || std::is_same_v<T, ListTag> || std::is_same_v<T, CompoundTag> || std::is_same_v<T, IntArrayTag> || std::is_same_v<T, LongArrayTag>,
135135 bool >
136136 = true >
137- inline void write_name_and_tag (BinaryWriter & writer, const std::optional<std::string>& name, const T& tag)
137+ inline void write_name_and_tag (BaseBinaryWriter & writer, const std::optional<std::string>& name, const T& tag)
138138 {
139139 writer.write_numeric <std::uint8_t >(tag_id_v<T>);
140140 if (name)
@@ -148,15 +148,15 @@ namespace NBT {
148148 std::is_same_v<T, ByteArrayTagPtr> || std::is_same_v<T, ListTagPtr> || std::is_same_v<T, CompoundTagPtr> || std::is_same_v<T, IntArrayTagPtr> || std::is_same_v<T, LongArrayTagPtr>,
149149 bool >
150150 = true >
151- inline void write_name_and_tag (BinaryWriter & writer, const std::optional<std::string>& name, const T tag)
151+ inline void write_name_and_tag (BaseBinaryWriter & writer, const std::optional<std::string>& name, const T tag)
152152 {
153153 write_name_and_tag<typename T::element_type>(writer, name, *tag);
154154 }
155155
156156 template <
157157 typename T,
158158 std::enable_if_t <std::is_same_v<T, TagNode>, bool > = true >
159- inline void write_name_and_tag (BinaryWriter & writer, const std::optional<std::string>& name, const TagNode& node)
159+ inline void write_name_and_tag (BaseBinaryWriter & writer, const std::optional<std::string>& name, const TagNode& node)
160160 {
161161 std::visit ([&writer, &name](auto && tag) {
162162 using tagT = std::decay_t <decltype (tag)>;
@@ -166,7 +166,7 @@ namespace NBT {
166166 }
167167
168168 template <>
169- inline void write_payload<CompoundTag>(BinaryWriter & writer, const CompoundTag& value)
169+ inline void write_payload<CompoundTag>(BaseBinaryWriter & writer, const CompoundTag& value)
170170 {
171171 for (auto it = value.begin (); it != value.end (); it++) {
172172 write_name_and_tag<TagNode>(writer, it->first , it->second );
@@ -177,64 +177,65 @@ namespace NBT {
177177 template <typename T>
178178 inline std::string _encode_nbt (const std::optional<std::string>& name, const T& tag, std::endian endianness, Amulet::StringEncoder string_encode)
179179 {
180- BinaryWriter writer (endianness, string_encode);
180+ std::string buffer;
181+ BaseBinaryWriter writer (buffer, endianness, string_encode);
181182 write_name_and_tag<T>(writer, name, tag);
182- return writer. get_buffer () ;
183+ return buffer ;
183184 }
184185
185- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const ByteTag& tag)
186+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const ByteTag& tag)
186187 {
187188 write_name_and_tag<ByteTag>(writer, name, tag);
188189 }
189- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const ShortTag& tag)
190+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const ShortTag& tag)
190191 {
191192 write_name_and_tag<ShortTag>(writer, name, tag);
192193 }
193- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const IntTag& tag)
194+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const IntTag& tag)
194195 {
195196 write_name_and_tag<IntTag>(writer, name, tag);
196197 }
197- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const LongTag& tag)
198+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const LongTag& tag)
198199 {
199200 write_name_and_tag<LongTag>(writer, name, tag);
200201 }
201- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const FloatTag& tag)
202+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const FloatTag& tag)
202203 {
203204 write_name_and_tag<FloatTag>(writer, name, tag);
204205 }
205- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const DoubleTag& tag)
206+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const DoubleTag& tag)
206207 {
207208 write_name_and_tag<DoubleTag>(writer, name, tag);
208209 }
209- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const ByteArrayTag& tag)
210+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const ByteArrayTag& tag)
210211 {
211212 write_name_and_tag<ByteArrayTag>(writer, name, tag);
212213 }
213- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const StringTag& tag)
214+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const StringTag& tag)
214215 {
215216 write_name_and_tag<StringTag>(writer, name, tag);
216217 }
217- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const ListTag& tag)
218+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const ListTag& tag)
218219 {
219220 write_name_and_tag<ListTag>(writer, name, tag);
220221 }
221- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const CompoundTag& tag)
222+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const CompoundTag& tag)
222223 {
223224 write_name_and_tag<CompoundTag>(writer, name, tag);
224225 }
225- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const IntArrayTag& tag)
226+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const IntArrayTag& tag)
226227 {
227228 write_name_and_tag<IntArrayTag>(writer, name, tag);
228229 }
229- void encode_nbt (BinaryWriter & writer, const std::optional<std::string>& name, const LongArrayTag& tag)
230+ void encode_nbt (BaseBinaryWriter & writer, const std::optional<std::string>& name, const LongArrayTag& tag)
230231 {
231232 write_name_and_tag<LongArrayTag>(writer, name, tag);
232233 }
233- void encode_nbt (BinaryWriter & writer, const std::string& name, const TagNode& tag)
234+ void encode_nbt (BaseBinaryWriter & writer, const std::string& name, const TagNode& tag)
234235 {
235236 write_name_and_tag<TagNode>(writer, name, tag);
236237 }
237- void encode_nbt (BinaryWriter & writer, const NamedTag& tag)
238+ void encode_nbt (BaseBinaryWriter & writer, const NamedTag& tag)
238239 {
239240 write_name_and_tag<TagNode>(writer, tag.name , tag.tag_node );
240241 }
0 commit comments