pretty: clear signature check
[git/gitster.git] / reftable / reftable-blocksource.h
blob5aa3990a5732f69d65ddecb222238b1d5a6a618f
1 /*
2 Copyright 2020 Google LLC
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 */
9 #ifndef REFTABLE_BLOCKSOURCE_H
10 #define REFTABLE_BLOCKSOURCE_H
12 #include <stdint.h>
14 /* block_source is a generic wrapper for a seekable readable file.
16 struct reftable_block_source {
17 struct reftable_block_source_vtable *ops;
18 void *arg;
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;
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);
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);
41 /* release all resources associated with the block source */
42 void (*close)(void *source);
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);
49 #endif