]> git.ipfire.org Git - thirdparty/git.git/blob - reftable/reftable-blocksource.h
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / reftable / reftable-blocksource.h
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_BLOCKSOURCE_H
10 #define REFTABLE_BLOCKSOURCE_H
11
12 #include <stdint.h>
13
14 /* block_source is a generic wrapper for a seekable readable file.
15 */
16 struct reftable_block_source {
17 struct reftable_block_source_vtable *ops;
18 void *arg;
19 };
20
21 /* a contiguous segment of bytes. It keeps track of its generating block_source
22 * so it can return itself into the pool. */
23 struct reftable_block {
24 uint8_t *data;
25 int len;
26 struct reftable_block_source source;
27 };
28
29 /* block_source_vtable are the operations that make up block_source */
30 struct reftable_block_source_vtable {
31 /* returns the size of a block source */
32 uint64_t (*size)(void *source);
33
34 /* reads a segment from the block source. It is an error to read
35 beyond the end of the block */
36 int (*read_block)(void *source, struct reftable_block *dest,
37 uint64_t off, uint32_t size);
38 /* mark the block as read; may return the data back to malloc */
39 void (*return_block)(void *source, struct reftable_block *blockp);
40
41 /* release all resources associated with the block source */
42 void (*close)(void *source);
43 };
44
45 /* opens a file on the file system as a block_source */
46 int reftable_block_source_from_file(struct reftable_block_source *block_src,
47 const char *name);
48
49 #endif