This repository has been archived on 2021-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
baseven/src/baseven.h

59 lines
1.7 KiB
C

/*
* This file is part of corelibs. (https://git.redxen.eu/corelibs)
* Copyright (c) 2021 Alex-David Denes
*
* corelibs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* corelibs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with corelibs. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdbool.h> // bool
#include <stddef.h> // size_t
#include <stdint.h> // uintmax_t
#ifndef CORELIBS_GUARD_BASEVEN
#define CORELIBS_GUARD_BASEVEN
typedef signed short int cl_baseven_err;
typedef struct cl_baseven_t cl_baseven_t;
struct corelibs_baseven_interface {
cl_baseven_err (*const encode) (const uint8_t *src, size_t len, uint8_t *dest, size_t cap);
cl_baseven_err (*const decode) (const uint8_t *src, size_t len, uint8_t *dest, size_t cap);
const struct {
uintmax_t (*const decoded) (uintmax_t enc_size);
uintmax_t (*const encoded) (uintmax_t dec_size);
} size;
// Errors - functions return them on run-time problems
const struct {
const cl_baseven_err ok, // No error
unknown; // Unknown error
const struct {
const cl_baseven_err overflow; // Not enough memory to run
} mem;
const struct {
const cl_baseven_err inval; // Invalid variable
} var;
} err;
};
extern const struct corelibs_baseven_interface cl_baseven;
#endif /* CORELIBS_GUARD_BASEVEN */