| 1 |
/* |
| 2 |
* FCML - Free Code Manipulation Library. |
| 3 |
* Copyright (C) 2010-2020 Slawomir Wojtasiak |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef FCML_STREAMING_H_ |
| 21 |
#define FCML_STREAMING_H_ |
| 22 |
|
| 23 |
#include <fcml_types.h> |
| 24 |
|
| 25 |
/* Structures used to store information about memory. */ |
| 26 |
|
| 27 |
typedef struct fcml_st_memory_stream { |
| 28 |
void *base_address; /* Base address of memory. */ |
| 29 |
fcml_int32_t offset; /* Offset. */ |
| 30 |
fcml_int32_t size; /* Size. */ |
| 31 |
} fcml_st_memory_stream; |
| 32 |
|
| 33 |
typedef fcml_uint32_t fcml_stream_pointer; |
| 34 |
|
| 35 |
/* Methods used for streaming. */ |
| 36 |
|
| 37 |
typedef enum fcml_en_stream_seek_type { |
| 38 |
FCML_EN_ST_START = 0, FCML_EN_ST_END, FCML_EN_ST_CURRENT |
| 39 |
} fcml_en_stream_seek_type; |
| 40 |
|
| 41 |
static inline fcml_st_memory_stream fcml_fn_stream_init(void *base_address, |
| 42 |
fcml_int32_t offset, fcml_int32_t size) { |
| 43 |
fcml_st_memory_stream stream; |
| 44 |
stream.base_address = base_address; |
| 45 |
stream.offset = offset; |
| 46 |
stream.size = size; |
| 47 |
return stream; |
| 48 |
} |
| 49 |
|
| 50 |
void fcml_fn_stream_seek(fcml_st_memory_stream *stream, fcml_int32_t offset, |
| 51 |
fcml_en_stream_seek_type type); |
| 52 |
|
| 53 |
fcml_uint8_t fcml_fn_stream_read(fcml_st_memory_stream *stream, |
| 54 |
fcml_bool *result); |
| 55 |
|
| 56 |
fcml_bool fcml_fn_stream_write(fcml_st_memory_stream *stream, |
| 57 |
fcml_uint8_t data); |
| 58 |
|
| 59 |
fcml_uint8_t fcml_fn_stream_peek(fcml_st_memory_stream *stream, |
| 60 |
fcml_bool *result); |
| 61 |
|
| 62 |
fcml_int32_t fcml_fn_stream_size(const fcml_st_memory_stream *stream); |
| 63 |
|
| 64 |
int fcml_fn_stream_read_bytes(fcml_st_memory_stream *stream, fcml_ptr buffer, |
| 65 |
fcml_usize size); |
| 66 |
|
| 67 |
int fcml_fn_stream_write_bytes(fcml_st_memory_stream *stream, fcml_ptr buffer, |
| 68 |
fcml_usize size); |
| 69 |
|
| 70 |
fcml_uint16_t fcml_fn_stream_read_word(fcml_st_memory_stream *stream, |
| 71 |
fcml_bool *result); |
| 72 |
|
| 73 |
fcml_uint32_t fcml_fn_stream_read_dword(fcml_st_memory_stream *stream, |
| 74 |
fcml_bool *result); |
| 75 |
|
| 76 |
fcml_uint64_t fcml_fn_stream_read_qword(fcml_st_memory_stream *stream, |
| 77 |
fcml_bool *result); |
| 78 |
|
| 79 |
fcml_bool fcml_fn_stream_write_word(fcml_st_memory_stream *stream, |
| 80 |
fcml_uint16_t data); |
| 81 |
|
| 82 |
fcml_bool fcml_fn_stream_write_dword(fcml_st_memory_stream *stream, |
| 83 |
fcml_uint32_t data); |
| 84 |
|
| 85 |
fcml_bool fcml_fn_stream_write_qword(fcml_st_memory_stream *stream, |
| 86 |
fcml_uint64_t data); |
| 87 |
|
| 88 |
fcml_stream_pointer fcml_fn_stream_save_point( |
| 89 |
const fcml_st_memory_stream *stream); |
| 90 |
|
| 91 |
void fcml_fn_stream_restore_point(fcml_st_memory_stream *stream, |
| 92 |
const fcml_stream_pointer stream_pointer); |
| 93 |
|
| 94 |
void fcml_fn_stream_clean(fcml_st_memory_stream *stream); |
| 95 |
|
| 96 |
fcml_st_memory_stream fcml_fn_stream_wrap( fcml_string buffer, |
| 97 |
fcml_usize length); |
| 98 |
|
| 99 |
#endif /* FCML_STREAMING_H_ */ |