Raw
1 /*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://developers.google.com/open-source/licenses/bsd
7 */
8
9 #ifndef REFTABLE_BLOCK_H
10 #define REFTABLE_BLOCK_H
11
12 #include "reftable-system.h"
13 #include "reftable-basics.h"
14 #include "reftable-blocksource.h"
15 #include "reftable-iterator.h"
16
17 struct z_stream_s;
18
19 /*
20 * A block part of a reftable. Contains records as well as some metadata
21 * describing them.
22 */
23 struct reftable_block {
24 /*
25 * Offset of the block header; nonzero for the first block in a
26 * reftable.
27 */
28 uint32_t header_off;
29
30 /* The memory block. */
31 struct reftable_block_data block_data;
32 uint32_t hash_size;
33
34 /* Uncompressed data for log entries. */
35 struct z_stream_s *zstream;
36 unsigned char *uncompressed_data;
37 size_t uncompressed_cap;
38
39 /*
40 * Restart point data. Restart points are located after the block's
41 * record data.
42 */
43 uint16_t restart_count;
44 uint32_t restart_off;
45
46 /*
47 * Size of the data in the file. For log blocks, this is the compressed
48 * size.
49 */
50 uint32_t full_block_size;
51 uint8_t block_type;
52 };
53
54 /* Initialize a reftable block from the given block source. */
55 int reftable_block_init(struct reftable_block *b,
56 struct reftable_block_source *source,
57 uint32_t offset, uint32_t header_size,
58 uint32_t table_block_size, uint32_t hash_size,
59 uint8_t want_type);
60
61 /* Release resources allocated by the block. */
62 void reftable_block_release(struct reftable_block *b);
63
64 /* Initialize a generic record iterator from the given block. */
65 int reftable_block_init_iterator(const struct reftable_block *b,
66 struct reftable_iterator *it);
67
68 /* Returns the block type (eg. 'r' for refs). */
69 uint8_t reftable_block_type(const struct reftable_block *b);
70
71 /* Decodes the first key in the block. */
72 int reftable_block_first_key(const struct reftable_block *b, struct reftable_buf *key);
73
74 #endif /* REFTABLE_BLOCK_H */