godot_voxel/streams/voxel_block_serializer.h

45 lines
1.3 KiB
C
Raw Normal View History

#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>
#include <vector>
2020-07-25 13:56:23 -07:00
class StreamPeer;
class FileAccess;
namespace zylann::voxel {
2022-01-08 14:49:48 -08:00
class VoxelBufferInternal;
2022-01-15 20:01:22 -08:00
namespace BlockSerializer {
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;
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) {}
};
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);
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);
bool decompress_and_deserialize(FileAccess &f, unsigned int size_to_read, VoxelBufferInternal &out_voxel_buffer);
2020-07-25 13:56:23 -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
#endif // VOXEL_BLOCK_SERIALIZER_H