51 lines
2.1 KiB
C
51 lines
2.1 KiB
C
/* *****************************************************************************
|
|
* libg1m/buffer.h -- the libg1m buffer interface.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libg1m.
|
|
* libg1m is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 3.0 of the License,
|
|
* or (at your option) any later version.
|
|
*
|
|
* libg1m 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with libg1m; if not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* This interface is there so you can use a custom buffer for the library
|
|
* to read. There are two use cases:
|
|
* - you want to read data: the `size` of the element to read should be set,
|
|
* and the `read` callback will be used;
|
|
* - you want to receive data: if the `announce` callback is set, it will be
|
|
* called with the size of the file to write, in order to prepare space for
|
|
* it. If the `announce` callback returns an error, then the file will not
|
|
* be written. If the announcement is successful, then the `write` callback
|
|
* is used.
|
|
*
|
|
* In each case, the `cookie` is sent as the first argument to your callbacks.
|
|
* ************************************************************************** */
|
|
#ifndef LIBG1M_BUFFER_H
|
|
# define LIBG1M_BUFFER_H
|
|
# include <stdlib.h>
|
|
# include <stdint.h>
|
|
|
|
/* The callbacks types... */
|
|
typedef int (*g1m_buffer_read_t)(void*, unsigned char*, size_t);
|
|
typedef int (*g1m_buffer_write_t)(void*, const unsigned char*, size_t);
|
|
typedef int (*g1m_buffer_announce_t)(void*, uint_fast32_t size);
|
|
|
|
/* ... and the structure of a buffer. */
|
|
typedef struct {
|
|
void *cookie;
|
|
|
|
g1m_buffer_read_t read;
|
|
g1m_buffer_write_t write;
|
|
g1m_buffer_announce_t announce;
|
|
} g1m_buffer_t;
|
|
|
|
#endif /* LIBG1M_BUFFER_H */
|