NBT working!!
parent
ff1765c52e
commit
126faa0b03
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "blt/std/format.h"
|
||||
#include "blt/std/filesystem.h"
|
||||
#include "blt/std/logging.h"
|
||||
|
||||
namespace blt::nbt {
|
||||
#ifndef HASHMAP
|
||||
|
@ -273,6 +274,8 @@ namespace blt::nbt {
|
|||
case nbt_tag::LONG_ARRAY:
|
||||
return new blt::nbt::tag_long_array;
|
||||
}
|
||||
BLT_WARN("Tag Type not found!");
|
||||
return nullptr;
|
||||
}
|
||||
static HASHMAP<std::string, tag_t*> toHashmap(const std::vector<tag_t*>& v){
|
||||
HASHMAP<std::string, tag_t*> tags;
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace blt::fs {
|
|||
char* m_buffer;
|
||||
size_t readIndex = 0;
|
||||
public:
|
||||
explicit fstream_block_reader(std::fstream& stream, size_t bufferSize):
|
||||
explicit fstream_block_reader(std::fstream& stream, size_t bufferSize = 131072):
|
||||
block_reader(bufferSize), m_stream(stream), m_buffer(new char[bufferSize]) {}
|
||||
|
||||
explicit fstream_block_reader(fstream_block_reader& copy) = delete;
|
||||
|
@ -101,8 +101,9 @@ namespace blt::fs {
|
|||
std::fstream& m_stream;
|
||||
char* m_buffer;
|
||||
size_t writeIndex = 0;
|
||||
void flush_internal();
|
||||
public:
|
||||
explicit fstream_block_writer(std::fstream& stream, size_t bufferSize):
|
||||
explicit fstream_block_writer(std::fstream& stream, size_t bufferSize = 131072):
|
||||
block_writer(bufferSize), m_stream(stream), m_buffer(new char[bufferSize]) {}
|
||||
|
||||
explicit fstream_block_writer(fstream_block_writer& copy) = delete;
|
||||
|
@ -114,9 +115,12 @@ namespace blt::fs {
|
|||
fstream_block_writer& operator=(const fstream_block_writer&& move) = delete;
|
||||
|
||||
int write(char* buffer, size_t bytes) override;
|
||||
void flush() override;
|
||||
inline void flush() override {
|
||||
flush_internal();
|
||||
}
|
||||
|
||||
~fstream_block_writer() {
|
||||
flush_internal();
|
||||
delete[] m_buffer;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -86,8 +86,8 @@ namespace blt::string {
|
|||
chars.characters = new char[chars.size];
|
||||
|
||||
int count = 0;
|
||||
chars.characters[count++] = (char) ((utflen >> 0) & 0xFF);
|
||||
chars.characters[count++] = (char) ((utflen >> 8) & 0xFF);
|
||||
chars.characters[count++] = (char) ((utflen >> 0) & 0xFF);
|
||||
|
||||
unsigned int i = 0;
|
||||
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
|
||||
|
|
|
@ -16,9 +16,9 @@ namespace blt::nbt {
|
|||
}
|
||||
|
||||
std::string readUTF8String(blt::fs::block_reader& stream) {
|
||||
unsigned short utflen;
|
||||
int16_t utflen;
|
||||
|
||||
stream.read(reinterpret_cast<char*>(&utflen), sizeof(utflen));
|
||||
readData(stream, utflen);
|
||||
|
||||
blt::string::utf8_string str{};
|
||||
str.size = utflen;
|
||||
|
|
|
@ -40,7 +40,7 @@ int blt::fs::fstream_block_writer::write(char* buffer, size_t bytes) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void blt::fs::fstream_block_writer::flush() {
|
||||
void blt::fs::fstream_block_writer::flush_internal() {
|
||||
m_stream.write(m_buffer, (long) writeIndex);
|
||||
writeIndex = 0;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ int main(int argc, char** argv) {
|
|||
auto* funy = new class_func;
|
||||
super_func* virtual_funy = new class_func;
|
||||
|
||||
for (int _ = 0; _ < 100; _++ ) {
|
||||
for (int _ = 0; _ < 10; _++ ) {
|
||||
int num_of_tests = 10000;
|
||||
int acc = 1;
|
||||
BLT_START_INTERVAL("Functions Test", "std::function (lambda)");
|
||||
|
@ -222,5 +222,13 @@ int main(int argc, char** argv) {
|
|||
|
||||
BLT_INFO("STDDEV of # random values: %f", stdev);
|
||||
|
||||
std::fstream nbtFile("super_file.nbt", std::ios::out | std::ios::binary);
|
||||
blt::fs::fstream_block_writer blockWriter(nbtFile);
|
||||
blt::nbt::NBTWriter nbtWriter(blockWriter);
|
||||
nbtWriter.write(new blt::nbt::tag_compound("root", {
|
||||
new blt::nbt::tag_byte("super_byte", 8),
|
||||
new blt::nbt::tag_short("shortTest", 32767),
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue