NBT working!!
parent
ff1765c52e
commit
126faa0b03
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "blt/std/format.h"
|
#include "blt/std/format.h"
|
||||||
#include "blt/std/filesystem.h"
|
#include "blt/std/filesystem.h"
|
||||||
|
#include "blt/std/logging.h"
|
||||||
|
|
||||||
namespace blt::nbt {
|
namespace blt::nbt {
|
||||||
#ifndef HASHMAP
|
#ifndef HASHMAP
|
||||||
|
@ -273,6 +274,8 @@ namespace blt::nbt {
|
||||||
case nbt_tag::LONG_ARRAY:
|
case nbt_tag::LONG_ARRAY:
|
||||||
return new blt::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){
|
static HASHMAP<std::string, tag_t*> toHashmap(const std::vector<tag_t*>& v){
|
||||||
HASHMAP<std::string, tag_t*> tags;
|
HASHMAP<std::string, tag_t*> tags;
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace blt::fs {
|
||||||
char* m_buffer;
|
char* m_buffer;
|
||||||
size_t readIndex = 0;
|
size_t readIndex = 0;
|
||||||
public:
|
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]) {}
|
block_reader(bufferSize), m_stream(stream), m_buffer(new char[bufferSize]) {}
|
||||||
|
|
||||||
explicit fstream_block_reader(fstream_block_reader& copy) = delete;
|
explicit fstream_block_reader(fstream_block_reader& copy) = delete;
|
||||||
|
@ -101,8 +101,9 @@ namespace blt::fs {
|
||||||
std::fstream& m_stream;
|
std::fstream& m_stream;
|
||||||
char* m_buffer;
|
char* m_buffer;
|
||||||
size_t writeIndex = 0;
|
size_t writeIndex = 0;
|
||||||
|
void flush_internal();
|
||||||
public:
|
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]) {}
|
block_writer(bufferSize), m_stream(stream), m_buffer(new char[bufferSize]) {}
|
||||||
|
|
||||||
explicit fstream_block_writer(fstream_block_writer& copy) = delete;
|
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;
|
fstream_block_writer& operator=(const fstream_block_writer&& move) = delete;
|
||||||
|
|
||||||
int write(char* buffer, size_t bytes) override;
|
int write(char* buffer, size_t bytes) override;
|
||||||
void flush() override;
|
inline void flush() override {
|
||||||
|
flush_internal();
|
||||||
|
}
|
||||||
|
|
||||||
~fstream_block_writer() {
|
~fstream_block_writer() {
|
||||||
|
flush_internal();
|
||||||
delete[] m_buffer;
|
delete[] m_buffer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -86,8 +86,8 @@ namespace blt::string {
|
||||||
chars.characters = new char[chars.size];
|
chars.characters = new char[chars.size];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
chars.characters[count++] = (char) ((utflen >> 0) & 0xFF);
|
|
||||||
chars.characters[count++] = (char) ((utflen >> 8) & 0xFF);
|
chars.characters[count++] = (char) ((utflen >> 8) & 0xFF);
|
||||||
|
chars.characters[count++] = (char) ((utflen >> 0) & 0xFF);
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
|
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) {
|
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{};
|
blt::string::utf8_string str{};
|
||||||
str.size = utflen;
|
str.size = utflen;
|
||||||
|
|
|
@ -40,7 +40,7 @@ int blt::fs::fstream_block_writer::write(char* buffer, size_t bytes) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blt::fs::fstream_block_writer::flush() {
|
void blt::fs::fstream_block_writer::flush_internal() {
|
||||||
m_stream.write(m_buffer, (long) writeIndex);
|
m_stream.write(m_buffer, (long) writeIndex);
|
||||||
writeIndex = 0;
|
writeIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ int main(int argc, char** argv) {
|
||||||
auto* funy = new class_func;
|
auto* funy = new class_func;
|
||||||
super_func* virtual_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 num_of_tests = 10000;
|
||||||
int acc = 1;
|
int acc = 1;
|
||||||
BLT_START_INTERVAL("Functions Test", "std::function (lambda)");
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue