2019-08-17 10:15:16 -07:00
|
|
|
#ifndef VOXEL_BLOCK_SERIALIZER_H
|
|
|
|
#define VOXEL_BLOCK_SERIALIZER_H
|
|
|
|
|
2021-10-02 17:32:01 -07:00
|
|
|
#include "../util/span.h"
|
|
|
|
|
2022-04-15 16:15:50 -07:00
|
|
|
#include <cstdint>
|
2019-08-17 10:15:16 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2020-07-25 13:56:23 -07:00
|
|
|
class StreamPeer;
|
2022-04-15 15:13:31 -07:00
|
|
|
class FileAccess;
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2022-01-02 18:52:06 -08:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2022-01-08 14:49:48 -08:00
|
|
|
class VoxelBufferInternal;
|
|
|
|
|
2022-01-15 20:01:22 -08:00
|
|
|
namespace BlockSerializer {
|
2021-01-29 17:36:37 -08:00
|
|
|
|
2022-04-22 14:20:48 -07:00
|
|
|
// Latest version, used when serializing
|
|
|
|
static const uint8_t BLOCK_FORMAT_VERSION = 4;
|
|
|
|
|
2022-01-15 20:01:22 -08:00
|
|
|
struct SerializeResult {
|
|
|
|
// The lifetime of the pointed object is only valid in the calling thread,
|
|
|
|
// until another serialization or deserialization call is made
|
|
|
|
const std::vector<uint8_t> &data;
|
|
|
|
bool success;
|
2021-01-29 17:36:37 -08:00
|
|
|
|
2022-01-15 20:01:22 -08:00
|
|
|
inline SerializeResult(const std::vector<uint8_t> &p_data, bool p_success) : data(p_data), success(p_success) {}
|
|
|
|
};
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2022-01-15 20:01:22 -08:00
|
|
|
SerializeResult serialize(const VoxelBufferInternal &voxel_buffer);
|
|
|
|
bool deserialize(Span<const uint8_t> p_data, VoxelBufferInternal &out_voxel_buffer);
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2022-01-15 20:01:22 -08:00
|
|
|
SerializeResult serialize_and_compress(const VoxelBufferInternal &voxel_buffer);
|
|
|
|
bool decompress_and_deserialize(Span<const uint8_t> p_data, VoxelBufferInternal &out_voxel_buffer);
|
2022-04-15 15:13:31 -07:00
|
|
|
bool decompress_and_deserialize(FileAccess &f, unsigned int size_to_read, VoxelBufferInternal &out_voxel_buffer);
|
2020-07-25 13:56:23 -07:00
|
|
|
|
2022-04-18 12:40:25 -07:00
|
|
|
// Temporary thread-local buffers for internal use
|
|
|
|
std::vector<uint8_t> &get_tls_data();
|
|
|
|
std::vector<uint8_t> &get_tls_compressed_data();
|
2022-01-15 20:01:22 -08:00
|
|
|
|
|
|
|
} // namespace BlockSerializer
|
2022-01-09 14:13:10 -08:00
|
|
|
} // namespace zylann::voxel
|
|
|
|
|
2019-08-17 10:15:16 -07:00
|
|
|
#endif // VOXEL_BLOCK_SERIALIZER_H
|