]> git.sesse.net Git - fjl/blob - bytesource.h
byte_source_read_marker() needs to refill.
[fjl] / bytesource.h
1 #ifndef _BYTESOURCE_H
2 #define _BYTESOURCE_H 1
3
4 #include <stdint.h>
5 #include <sys/types.h>
6
7 #include "input.h"
8
9 static const unsigned BYTESOURCE_CHUNK_SIZE = 4096;
10
11 // A data source taking in a byte stream and returning unstuffed bytes until
12 // there's a marker. When there's a marker, it artificially returns EOF until
13 // byte_source_read_marker() is called.
14 struct byte_source {
15         uint8_t* bytes;
16         unsigned bytes_available;
17
18         raw_input_func_t* input_func;
19         void* userdata;
20 };
21 void init_byte_source(struct byte_source* source, raw_input_func_t* input_func, void* userdata);
22
23 // Returns 0x00 if no marker was available (ie. error).
24 uint8_t byte_source_read_marker(struct byte_source* source);
25
26 ssize_t byte_source_input_func(void* source, uint8_t* buf, size_t len);
27
28 #endif /* !defined(_BYTESOURCE_H) */