diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-03 10:25:53 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-03 10:25:53 +0800 |
commit | 669cca494fd456dbfcf42801c791796c286c18ad (patch) | |
tree | 274301c8d2623725d68a027b3ca7312629344022 /git2d/bare.h | |
parent | README: Remove the note about the Hare implementation (diff) | |
download | forge-669cca494fd456dbfcf42801c791796c286c18ad.tar.gz forge-669cca494fd456dbfcf42801c791796c286c18ad.tar.zst forge-669cca494fd456dbfcf42801c791796c286c18ad.zip |
git2d: Import BARE and UTF-8 utilities
Diffstat (limited to 'git2d/bare.h')
-rw-r--r-- | git2d/bare.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/git2d/bare.h b/git2d/bare.h new file mode 100644 index 0000000..389017f --- /dev/null +++ b/git2d/bare.h @@ -0,0 +1,70 @@ +/*- + * SPDX-License-Identifier: MIT + * SPDX-FileCopyrightText: Copyright (c) 2022 Frank Smit <https://61924.nl/> + */ + +#ifndef BARE_H +#define BARE_H + +#include <stdint.h> +#include <stdbool.h> + +typedef enum { + BARE_ERROR_NONE, + BARE_ERROR_WRITE_FAILED, + BARE_ERROR_READ_FAILED, + BARE_ERROR_BUFFER_TOO_SMALL, + BARE_ERROR_INVALID_UTF8, +} bare_error; + +typedef bare_error (*bare_write_func)(void *buffer, void *src, uint64_t sz); +typedef bare_error (*bare_read_func)(void *buffer, void *dst, uint64_t sz); + +struct bare_writer { + void *buffer; + bare_write_func write; +}; + +struct bare_reader { + void *buffer; + bare_read_func read; +}; + +bare_error bare_put_uint(struct bare_writer *ctx, uint64_t x); /* varuint */ +bare_error bare_get_uint(struct bare_reader *ctx, uint64_t *x); /* varuint */ +bare_error bare_put_u8(struct bare_writer *ctx, uint8_t x); +bare_error bare_get_u8(struct bare_reader *ctx, uint8_t *x); +bare_error bare_put_u16(struct bare_writer *ctx, uint16_t x); +bare_error bare_get_u16(struct bare_reader *ctx, uint16_t *x); +bare_error bare_put_u32(struct bare_writer *ctx, uint32_t x); +bare_error bare_get_u32(struct bare_reader *ctx, uint32_t *x); +bare_error bare_put_u64(struct bare_writer *ctx, uint64_t x); +bare_error bare_get_u64(struct bare_reader *ctx, uint64_t *x); + +bare_error bare_put_int(struct bare_writer *ctx, int64_t x); /* varint */ +bare_error bare_get_int(struct bare_reader *ctx, int64_t *x); /* varint */ +bare_error bare_put_i8(struct bare_writer *ctx, int8_t x); +bare_error bare_get_i8(struct bare_reader *ctx, int8_t *x); +bare_error bare_put_i16(struct bare_writer *ctx, int16_t x); +bare_error bare_get_i16(struct bare_reader *ctx, int16_t *x); +bare_error bare_put_i32(struct bare_writer *ctx, int32_t x); +bare_error bare_get_i32(struct bare_reader *ctx, int32_t *x); +bare_error bare_put_i64(struct bare_writer *ctx, int64_t x); +bare_error bare_get_i64(struct bare_reader *ctx, int64_t *x); + +bare_error bare_put_f32(struct bare_writer *ctx, float x); +bare_error bare_get_f32(struct bare_reader *ctx, float *x); +bare_error bare_put_f64(struct bare_writer *ctx, double x); +bare_error bare_get_f64(struct bare_reader *ctx, double *x); + +bare_error bare_put_bool(struct bare_writer *ctx, bool x); +bare_error bare_get_bool(struct bare_reader *ctx, bool *x); + +bare_error bare_put_fixed_data(struct bare_writer *ctx, uint8_t *src, uint64_t sz); +bare_error bare_get_fixed_data(struct bare_reader *ctx, uint8_t *dst, uint64_t sz); +bare_error bare_put_data(struct bare_writer *ctx, uint8_t *src, uint64_t sz); +bare_error bare_get_data(struct bare_reader *ctx, uint8_t *dst, uint64_t sz); +bare_error bare_put_str(struct bare_writer *ctx, char *src, uint64_t sz); +bare_error bare_get_str(struct bare_reader *ctx, char *dst, uint64_t sz); + +#endif /* BARE_H */ |