-
Notifications
You must be signed in to change notification settings - Fork 28
/
binaryUtils.h
57 lines (47 loc) · 1.09 KB
/
binaryUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#ifdef SUPPORT_ZSTD_TRACE
#include "../generalReader/zstdReader.h"
#endif
#include "../../include/libCacheSim/reader.h"
#ifdef __cplusplus
extern "C" {
#endif
/* read decompressed data file */
static inline char *_read_bytes(reader_t *reader) {
if (reader->mmap_offset >= reader->file_size) {
return NULL;
}
char *start = (reader->mapped_file + reader->mmap_offset);
reader->mmap_offset += reader->item_size;
return start;
}
#ifdef SUPPORT_ZSTD_TRACE
/* read zstd compressed data */
static inline char *_read_bytes_zstd(reader_t *reader) {
char *start;
size_t sz =
zstd_reader_read_bytes(reader->zstd_reader_p, reader->item_size, &start);
if (sz == 0) {
if (reader->zstd_reader_p->status != MY_EOF) {
ERROR("fail to read zstd trace\n");
}
return NULL;
}
return start;
}
#endif
static inline char *read_bytes(reader_t *reader) {
char *start = NULL;
#ifdef SUPPORT_ZSTD_TRACE
if (reader->is_zstd_file) {
start = _read_bytes_zstd(reader);
} else
#endif
{
start = _read_bytes(reader);
}
return start;
}
#ifdef __cplusplus
}
#endif