2022-02-18 22:53:46 +03:00
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-05-06 16:37:10 +03:00
|
|
|
#define STREAM_CACHE_SIZE 512u
|
2022-02-18 22:53:46 +03:00
|
|
|
|
|
|
|
typedef struct StreamVTable StreamVTable;
|
|
|
|
|
|
|
|
typedef void (*StreamFreeFn)(Stream* stream);
|
|
|
|
typedef bool (*StreamEOFFn)(Stream* stream);
|
|
|
|
typedef void (*StreamCleanFn)(Stream* stream);
|
|
|
|
typedef bool (*StreamSeekFn)(Stream* stream, int32_t offset, StreamOffset offset_type);
|
|
|
|
typedef size_t (*StreamTellFn)(Stream* stream);
|
|
|
|
typedef size_t (*StreamSizeFn)(Stream* stream);
|
|
|
|
typedef size_t (*StreamWriteFn)(Stream* stream, const uint8_t* data, size_t size);
|
|
|
|
typedef size_t (*StreamReadFn)(Stream* stream, uint8_t* data, size_t count);
|
|
|
|
typedef bool (*StreamDeleteAndInsertFn)(
|
|
|
|
Stream* stream,
|
|
|
|
size_t delete_size,
|
|
|
|
StreamWriteCB write_cb,
|
|
|
|
const void* ctx);
|
|
|
|
|
|
|
|
struct StreamVTable {
|
|
|
|
const StreamFreeFn free;
|
|
|
|
const StreamEOFFn eof;
|
|
|
|
const StreamCleanFn clean;
|
|
|
|
const StreamSeekFn seek;
|
|
|
|
const StreamTellFn tell;
|
|
|
|
const StreamSizeFn size;
|
|
|
|
const StreamWriteFn write;
|
|
|
|
const StreamReadFn read;
|
|
|
|
const StreamDeleteAndInsertFn delete_and_insert;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Stream {
|
|
|
|
const StreamVTable* vtable;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|