| 1 |
#ifndef AWS_IO_STREAM_H |
| 2 |
#define AWS_IO_STREAM_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <aws/common/ref_count.h> |
| 10 |
#include <aws/io/io.h> |
| 11 |
|
| 12 |
AWS_PUSH_SANE_WARNING_LEVEL |
| 13 |
|
| 14 |
struct aws_input_stream; |
| 15 |
struct aws_byte_buf; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
enum aws_stream_seek_basis { AWS_SSB_BEGIN = 0, AWS_SSB_END = 2 }; |
| 23 |
|
| 24 |
struct aws_stream_status { |
| 25 |
bool is_end_of_stream; |
| 26 |
bool is_valid; |
| 27 |
}; |
| 28 |
|
| 29 |
struct aws_input_stream_vtable { |
| 30 |
int (*seek)(struct aws_input_stream *stream, int64_t offset, enum aws_stream_seek_basis basis); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
int (*read)(struct aws_input_stream *stream, struct aws_byte_buf *dest); |
| 42 |
int (*get_status)(struct aws_input_stream *stream, struct aws_stream_status *status); |
| 43 |
int (*get_length)(struct aws_input_stream *stream, int64_t *out_length); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
void (*acquire)(struct aws_input_stream *stream); |
| 53 |
void (*release)(struct aws_input_stream *stream); |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
struct aws_input_stream { |
| 62 |
|
| 63 |
void *impl; |
| 64 |
const struct aws_input_stream_vtable *vtable; |
| 65 |
struct aws_ref_count ref_count; |
| 66 |
}; |
| 67 |
|
| 68 |
AWS_EXTERN_C_BEGIN |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
AWS_IO_API struct aws_input_stream *aws_input_stream_acquire(struct aws_input_stream *stream); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
AWS_IO_API struct aws_input_stream *aws_input_stream_release(struct aws_input_stream *stream); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
AWS_IO_API int aws_input_stream_seek(struct aws_input_stream *stream, int64_t offset, enum aws_stream_seek_basis basis); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
AWS_IO_API int aws_input_stream_read(struct aws_input_stream *stream, struct aws_byte_buf *dest); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
AWS_IO_API int aws_input_stream_get_status(struct aws_input_stream *stream, struct aws_stream_status *status); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
AWS_IO_API int aws_input_stream_get_length(struct aws_input_stream *stream, int64_t *out_length); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
AWS_IO_API void aws_input_stream_destroy(struct aws_input_stream *stream); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
AWS_IO_API struct aws_input_stream *aws_input_stream_new_from_cursor( |
| 116 |
struct aws_allocator *allocator, |
| 117 |
const struct aws_byte_cursor *cursor); |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
AWS_IO_API struct aws_input_stream *aws_input_stream_new_from_file( |
| 124 |
struct aws_allocator *allocator, |
| 125 |
const char *file_name); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
AWS_IO_API struct aws_input_stream *aws_input_stream_new_from_open_file(struct aws_allocator *allocator, FILE *file); |
| 132 |
|
| 133 |
AWS_EXTERN_C_END |
| 134 |
AWS_POP_SANE_WARNING_LEVEL |
| 135 |
|
| 136 |
#endif |