|
| 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 <stdint.h> |
| 13 | + |
| 14 | +#include "reftable-basics.h" |
| 15 | +#include "reftable-blocksource.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 | + |
| 60 | +/* Release resources allocated by the block. */ |
| 61 | +void reftable_block_release(struct reftable_block *b); |
| 62 | + |
| 63 | +/* Returns the block type (eg. 'r' for refs). */ |
| 64 | +uint8_t reftable_block_type(const struct reftable_block *b); |
| 65 | + |
| 66 | +/* Decodes the first key in the block. */ |
| 67 | +int reftable_block_first_key(const struct reftable_block *b, struct reftable_buf *key); |
| 68 | + |
| 69 | +#endif /* REFTABLE_BLOCK_H */ |
0 commit comments