| 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 WRITER_H |
| 10 | #define WRITER_H |
| 11 | |
| 12 | #include "basics.h" |
| 13 | #include "block.h" |
| 14 | #include "tree.h" |
| 15 | #include "reftable-writer.h" |
| 16 | |
| 17 | struct reftable_writer { |
| 18 | ssize_t (*write)(void *, const void *, size_t); |
| 19 | int (*flush)(void *); |
| 20 | void *write_arg; |
| 21 | int pending_padding; |
| 22 | struct reftable_buf last_key; |
| 23 | /* Scratch buffer used to avoid allocations. */ |
| 24 | struct reftable_buf scratch; |
| 25 | |
| 26 | /* offset of next block to write. */ |
| 27 | uint64_t next; |
| 28 | uint64_t min_update_index, max_update_index; |
| 29 | struct reftable_write_options opts; |
| 30 | enum reftable_hash hash_id; |
| 31 | |
| 32 | /* memory buffer for writing */ |
| 33 | uint8_t *block; |
| 34 | |
| 35 | /* writer for the current section. NULL or points to |
| 36 | * block_writer_data */ |
| 37 | struct block_writer *block_writer; |
| 38 | |
| 39 | struct block_writer block_writer_data; |
| 40 | |
| 41 | /* pending index records for the current section */ |
| 42 | struct reftable_index_record *index; |
| 43 | size_t index_len; |
| 44 | size_t index_cap; |
| 45 | |
| 46 | /* |
| 47 | * tree for use with tsearch; used to populate the 'o' inverse OID |
| 48 | * map */ |
| 49 | struct tree_node *obj_index_tree; |
| 50 | |
| 51 | struct reftable_stats stats; |
| 52 | }; |
| 53 | |
| 54 | #endif |