Skip to content
This repository
tree: 363e5ecfce
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (41 sloc) 1.773 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program 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 (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Writer_H
#define Writer_H

/* size_t */
#include <stdlib.h>
/* uint64_t */
#include <stdint.h>

/**
* Writer interface which writes data to a destination and fails safe rather than overflowing.
*/
struct Writer {
    /** The internal state of the Writer. */
    void* const context;

    /**
* Write some content from a buffer or other source.
*
* @param toWrite a pointer to a memory location where content will be sourced from.
* @param length the number of bytes to write.
* @param this the Writer which is being called. Use: writer->write(X, Y, writer);
* @return 0 if write went well, -1 if there is no more space to write.
* if a write fails then all subsequent writes will fail with the same error
* so writing a large piece of content then a small footer does not require
* checking if the content wrote correctly before writing the footer.
*/
    int (* const write)(const void* toWrite, size_t length, const struct Writer* this);

    uint64_t (* const bytesWritten)(const struct Writer* writer);
};

#endif
Something went wrong with that request. Please try again.