29 #include "eng3d/serializer.hpp"
30 #include "eng3d/utils.hpp"
31 #include "eng3d/log.hpp"
32 #include "eng3d/compress.hpp"
36 #define MAX_CHUNK_SIZE (65536 * 128)
37 #define MAX_ARCHIVE_SIZE (65536 * 10000)
38 #define MIN_FILE_SIZE 4096
45 std::unique_ptr<FILE, decltype(&std::fclose)> fp(::fopen(path.c_str(),
"wb"), ::fclose);
49 std::fwrite(signbuf, 1,
sizeof(signbuf), fp.get());
50 uint32_t inf_len =
buffer.size();
51 std::fwrite(&inf_len, 1,
sizeof(inf_len), fp.get());
54 dest_buffer.resize(r);
55 uint32_t def_len = dest_buffer.size();
56 std::fwrite(&def_len, 1,
sizeof(def_len), fp.get());
57 std::fwrite(dest_buffer.data(), 1, dest_buffer.size(), fp.get());
64 std::unique_ptr<FILE, decltype(&std::fclose)> fp(::fopen(path.c_str(),
"rb"), ::fclose);
67 std::vector<uint8_t> src_buffer(buffer.size());
70 std::fread(signbuf, 1,
sizeof(signbuf), fp.get());
72 CXX_THROW(std::runtime_error,
"Invalid archive");
74 std::fread(&inf_len, 1,
sizeof(inf_len), fp.get());
76 std::fread(&def_len, 1,
sizeof(def_len), fp.get());
78 src_buffer.resize(def_len);
79 std::fread(src_buffer.data(), 1, src_buffer.size(), fp.get());
81 buffer.resize(inf_len);
84 buffer.shrink_to_fit();
88 if(size > buffer.size() - this->ptr)
90 std::memcpy(to_ptr, &buffer[this->ptr], size);
96 if(size > buffer.size() - this->ptr)
98 std::memcpy(&buffer[this->ptr], from_ptr, size);
The purpouse of the serializer is to serialize objects onto a byte stream that can be transfered onto...
std::string translate(const std::string_view str)
void debug(const std::string_view category, const std::string_view msg)
size_t decompress(const void *src, size_t src_len, void *dest, size_t dest_len)
size_t compress(const void *src, size_t src_len, void *dest, size_t dest_len)
std::string string_format(const std::string_view format, Args &&... args)
String formatter.
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
constexpr char archive_signature[4]
::std::vector< uint8_t > buffer
void to_file(const ::std::string &path)
void from_file(const ::std::string &path)
void copy_from(const void *ptr, size_t size)
void copy_to(void *ptr, size_t size)
#define CXX_THROW(class,...)