Go to the documentation of this file. 1 #ifndef RTABMAP_SERIALIZATION_H_
2 #define RTABMAP_SERIALIZATION_H_
26 namespace serialization
31 template<
typename Archive,
typename T>
39 template<
typename Archive,
typename T>
48 template<
typename InputArchive>
53 template<
typename OutputArchive>
60 #define BASIC_TYPE_SERIALIZER(type)\
62 struct Serializer<type> \
64 template<typename InputArchive>\
65 static inline void load(InputArchive& ar, type& val)\
69 template<typename OutputArchive>\
70 static inline void save(OutputArchive& ar, const type& val)\
76 #define ENUM_SERIALIZER(type)\
78 struct Serializer<type>\
80 template<typename InputArchive>\
81 static inline void load(InputArchive& ar, type& val)\
85 val = (type) int_val;\
87 template<typename OutputArchive>\
88 static inline void save(OutputArchive& ar, const type& val)\
90 int int_val = (int)val;\
122 template<
typename InputArchive>
133 template<
typename OutputArchive>
137 for (
size_t i=0;
i<val.size();++
i) {
144 template<
typename K,
typename V>
147 template<
typename InputArchive>
152 for (
size_t i = 0;
i <
size; ++
i)
162 template<
typename OutputArchive>
166 for (
typename std::map<K,V>::const_iterator
i=map_val.begin();
i!=map_val.end(); ++
i) {
176 template<
typename InputArchive>
182 template<
typename OutputArchive>
189 template<
typename T,
int N>
192 template<
typename InputArchive>
198 template<
typename OutputArchive>
236 template<
typename InputArchive>
239 ar.load_binary(
const_cast<void *
>(
b.ptr_),
b.size_);
242 template<
typename OutputArchive>
245 ar.save_binary(
b.ptr_,
b.size_);
252 template<
typename InputArchive>
255 ar.load_binary(
const_cast<void *
>(
b.ptr_),
b.size_);
258 template<
typename OutputArchive>
261 ar.save_binary(
b.ptr_,
b.size_);
286 template<
typename Archive>
299 return *
static_cast<Archive*
>(
this);
304 template<
typename Archive>
317 return *
static_cast<Archive*
>(
this);
335 size_ +=
sizeof(val);
374 #define BLOCK_BYTES (1024 * 64)
421 assert(
head->compression == 0);
422 head->compression = 1;
434 head->first_block_size = compSz;
440 size_t headSz =
sizeof(compSz);
574 fseek(
stream, 0, SEEK_END);
580 char *compBuffer = (
char *)malloc(fileSize);
581 if (compBuffer ==
NULL) {
584 if (fread(compBuffer, fileSize, 1,
stream) != 1) {
586 throw FLANNException(
"Invalid index file, cannot read from disk (compressed)");
593 size_t compressedSz = fileSize-headSz;
594 size_t uncompressedSz =
head->first_block_size-headSz;
597 if (
head->compression != 1) {
603 ptr_ =
buffer_ = (
char *)malloc(uncompressedSz+headSz);
606 throw FLANNException(
"Error (re)allocating decompression buffer");
616 if (usedSz != uncompressedSz) {
622 memcpy(
buffer_, compBuffer, headSz);
626 if (compressedSz+headSz+
pos != fileSize)
627 fseek(
stream, compressedSz+headSz+
pos, SEEK_SET);
646 throw FLANNException(
"Invalid index file, cannot read from disk (header)");
650 if (
head->signature[13] ==
'1' &&
head->signature[15] ==
'0') {
685 throw FLANNException(
"Invalid index file, cannot read from disk (block)");
692 throw FLANNException(
"Invalid index file, cannot decompress block");
711 size_t readCnt = fread(&cmpSz,
sizeof(cmpSz), 1,
stream_);
712 if(cmpSz <= 0 || readCnt != 1) {
713 throw FLANNException(
"Requested to read next block past end of file");
728 throw FLANNException(
"Invalid index file, cannot read from disk (end)");
731 throw FLANNException(
"Invalid index file, last block not zero length");
777 memcpy(&val,
ptr_,
sizeof(val));
813 #endif // SERIALIZATION_H_
binary_object(void *const ptr, size_t size)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< N >::Type head(Index n=N)
BASIC_TYPE_SERIALIZER(char)
LZ4_streamDecode_t * lz4StreamDecode
void load_binary(T *ptr, size_t size)
static void load(InputArchive &ar, T(&val)[N])
SaveArchive(const char *filename)
char * compressed_buffer_
int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
LoadArchive(const char *filename)
static void load(InputArchive &ar, std::map< K, V > &map_val)
LZ4_streamHC_t * lz4Stream
int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int compressedSize, int maxOutputSize)
#define LZ4_COMPRESSBOUND(isize)
void save_binary(T *ptr, size_t size)
LoadArchive(FILE *stream)
void setObject(void *object)
void initBlock(FILE *stream)
void preparePtr(size_t size)
binary_object(const binary_object &rhs)
static void serialize(Archive &ar, T &type)
static void load(InputArchive &ar, T *&val)
static void save(OutputArchive &ar, T *const &val)
int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
void loadBlock(char *buffer_, size_t compSz, FILE *stream)
SaveArchive(FILE *stream)
LZ4_streamHC_t lz4Stream_body
static void load(InputArchive &ar, binary_object &b)
bool_< false > is_loading
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *source, char *dest, int inputSize, int maxOutputSize)
static void save(OutputArchive &ar, const binary_object &b)
static void load(InputArchive &ar, const binary_object &b)
LZ4_streamDecode_t lz4StreamDecode_body
static void load(InputArchive &ar, T &val)
static void save(OutputArchive &ar, const std::map< K, V > &map_val)
const gtsam::Symbol key( 'X', 0)
Archive & operator&(const T &val)
void LZ4_resetStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
EIGEN_DONT_INLINE Scalar zero()
const binary_object make_binary_object(void *t, size_t size)
static void load(InputArchive &ar, std::vector< T > &val)
void decompressAndLoadV10(FILE *stream)
static void save(OutputArchive &ar, const std::vector< T > &val)
void serialize(Archive &ar, T &type)
static void save(OutputArchive &ar, T const (&val)[N])
binary_object & operator=(const binary_object &rhs)
static void save(OutputArchive &ar, const binary_object &b)
char * compressed_buffer_
static void save(OutputArchive &ar, const T &val)
void save_binary(T *ptr, size_t size)
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:16