]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/tests/regression/data.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / zstd / tests / regression / data.h
1 /*
2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
9 */
10
11 #ifndef DATA_H
12 #define DATA_H
13
14 #include <stddef.h>
15 #include <stdint.h>
16
17 typedef enum {
18 data_type_file = 1, /**< This data is a file. *.zst */
19 data_type_dir = 2, /**< This data is a directory. *.tar.zst */
20 } data_type_t;
21
22 typedef struct {
23 char const* url; /**< Where to get this resource. */
24 uint64_t xxhash64; /**< Hash of the url contents. */
25 char const* path; /**< The path of the unpacked resource (derived). */
26 } data_resource_t;
27
28 typedef struct {
29 data_resource_t data;
30 data_resource_t dict;
31 data_type_t type; /**< The type of the data. */
32 char const* name; /**< The logical name of the data (no extension). */
33 } data_t;
34
35 /**
36 * The NULL-terminated list of data objects.
37 */
38 extern data_t const* const* data;
39
40
41 int data_has_dict(data_t const* data);
42
43 /**
44 * Initializes the data module and downloads the data necessary.
45 * Caches the downloads in dir. We add a stamp file in the directory after
46 * a successful download. If a stamp file already exists, and matches our
47 * current data stamp, we will use the cached data without downloading.
48 *
49 * @param dir The directory to cache the downloaded data into.
50 *
51 * @returns 0 on success.
52 */
53 int data_init(char const* dir);
54
55 /**
56 * Must be called at exit to free resources allocated by data_init().
57 */
58 void data_finish(void);
59
60 typedef struct {
61 uint8_t* data;
62 size_t size;
63 size_t capacity;
64 } data_buffer_t;
65
66 /**
67 * Read the file that data points to into a buffer.
68 * NOTE: data must be a file, not a directory.
69 *
70 * @returns The buffer, which is NULL on failure.
71 */
72 data_buffer_t data_buffer_get_data(data_t const* data);
73
74 /**
75 * Read the dictionary that the data points to into a buffer.
76 *
77 * @returns The buffer, which is NULL on failure.
78 */
79 data_buffer_t data_buffer_get_dict(data_t const* data);
80
81 /**
82 * Read the contents of filename into a buffer.
83 *
84 * @returns The buffer, which is NULL on failure.
85 */
86 data_buffer_t data_buffer_read(char const* filename);
87
88 /**
89 * Create a buffer with the specified capacity.
90 *
91 * @returns The buffer, which is NULL on failure.
92 */
93 data_buffer_t data_buffer_create(size_t capacity);
94
95 /**
96 * Calls memcmp() on the contents [0, size) of both buffers.
97 */
98 int data_buffer_compare(data_buffer_t buffer1, data_buffer_t buffer2);
99
100 /**
101 * Frees an allocated buffer.
102 */
103 void data_buffer_free(data_buffer_t buffer);
104
105 typedef struct {
106 char* buffer;
107 char const** filenames;
108 unsigned size;
109 } data_filenames_t;
110
111 /**
112 * Get a recursive list of filenames in the data object. If it is a file, it
113 * will only contain one entry. If it is a directory, it will recursively walk
114 * the directory.
115 *
116 * @returns The list of filenames, which has size 0 and NULL pointers on error.
117 */
118 data_filenames_t data_filenames_get(data_t const* data);
119
120 /**
121 * Frees the filenames table.
122 */
123 void data_filenames_free(data_filenames_t filenames);
124
125 typedef struct {
126 data_buffer_t const* buffers;
127 size_t size;
128 } data_buffers_t;
129
130 /**
131 * @returns a list of buffers for every file in data. It is zero sized on error.
132 */
133 data_buffers_t data_buffers_get(data_t const* data);
134
135 /**
136 * Frees the data buffers.
137 */
138 void data_buffers_free(data_buffers_t buffers);
139
140 #endif