isomorfeus-ferret 0.17.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,198 @@
1
+ #ifndef FRT_OUT_STREAM_H
2
+ #define FRT_OUT_STREAM_H
3
+
4
+ #include "frt_global.h"
5
+ #include "frt_ram_store.h"
6
+
7
+ typedef struct FrtStore FrtStore;
8
+ typedef struct FrtOutStream FrtOutStream;
9
+
10
+ struct FrtOutStreamMethods {
11
+ /* internal functions for the FrtInStream */
12
+ /**
13
+ * Flush +len+ characters from +src+ to the output stream +os+
14
+ *
15
+ * @param os self
16
+ * @param src the characters to write to the output stream
17
+ * @param len the number of characters to write
18
+ * @raise FRT_IO_ERROR if there is an error writing the characters
19
+ */
20
+ void (*flush_i)(struct FrtOutStream *os, const frt_uchar *buf, int len);
21
+
22
+ /**
23
+ * Seek +pos+ in the output stream
24
+ *
25
+ * @param os self
26
+ * @param pos the position to seek in the stream
27
+ * @raise FRT_IO_ERROR if there is an error seeking in the output stream
28
+ */
29
+ void (*seek_i)(struct FrtOutStream *os, frt_off_t pos);
30
+
31
+ /**
32
+ * Close any resources used by the output stream +os+
33
+ *
34
+ * @param os self
35
+ * @raise FRT_IO_ERROR if there is an error closing the file
36
+ */
37
+ void (*close_i)(struct FrtOutStream *os);
38
+ };
39
+
40
+ struct FrtOutStream {
41
+ FrtBuffer buf;
42
+ frt_off_t pointer; /* only used by RAMOut */
43
+ FrtStore *store;
44
+ union {
45
+ int fd;
46
+ FrtRAMFile *rf;
47
+ } file;
48
+ const struct FrtOutStreamMethods *m;
49
+ };
50
+
51
+
52
+ /**
53
+ * Flush the buffered contents of the FrtOutStream to the store.
54
+ *
55
+ * @param os the FrtOutStream to flush
56
+ */
57
+ extern void frt_os_flush(FrtOutStream *os);
58
+
59
+ /**
60
+ * Close the FrtOutStream after flushing the buffers, also freeing all allocated
61
+ * resources.
62
+ *
63
+ * @param os the FrtOutStream to close
64
+ */
65
+ extern void frt_os_close(FrtOutStream *os);
66
+
67
+ /**
68
+ * Return the current position of FrtOutStream +os+.
69
+ *
70
+ * @param os the FrtOutStream to get the position from
71
+ * @return the current position in FrtOutStream +os+
72
+ */
73
+ extern frt_off_t frt_os_pos(FrtOutStream *os);
74
+
75
+
76
+ /**
77
+ * Set the current position in FrtOutStream +os+.
78
+ *
79
+ * @param os the FrtOutStream to set the position in
80
+ * @param pos the new position in the FrtOutStream
81
+ * @raise FRT_IO_ERROR if there is a file-system IO error seeking the file
82
+ */
83
+ extern void frt_os_seek(FrtOutStream *os, frt_off_t new_pos);
84
+
85
+ /**
86
+ * Write a single byte +b+ to the FrtOutStream +os+
87
+ *
88
+ * @param os the FrtOutStream to write to @param b the byte to write @raise
89
+ * FRT_IO_ERROR if there is an IO error writing to the file-system
90
+ */
91
+ extern void frt_os_write_byte(FrtOutStream *os, frt_uchar b);
92
+ /**
93
+ * Write +len+ bytes from buffer +buf+ to the FrtOutStream +os+.
94
+ *
95
+ * @param os the FrtOutStream to write to
96
+ * @param len the number of bytes to write
97
+ * @param buf the buffer from which to get the bytes to write.
98
+ * @raise FRT_IO_ERROR if there is an IO error writing to the file-system
99
+ */
100
+ extern void frt_os_write_bytes(FrtOutStream *os, const frt_uchar *buf, int len);
101
+
102
+
103
+ /**
104
+ * Write a 32-bit signed integer to the FrtOutStream
105
+ *
106
+ * @param os FrtOutStream to write to
107
+ * @param num the 32-bit signed integer to write
108
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
109
+ */
110
+ extern void frt_os_write_i32(FrtOutStream *os, frt_i32 num);
111
+
112
+ /**
113
+ * Write a 64-bit signed integer to the FrtOutStream
114
+ *
115
+ *
116
+ * @param os FrtOutStream to write to
117
+ * @param num the 64-bit signed integer to write
118
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
119
+ */
120
+ extern void frt_os_write_i64(FrtOutStream *os, frt_i64 num);
121
+
122
+ /**
123
+ * Write a 32-bit unsigned integer to the FrtOutStream
124
+ *
125
+ * @param os FrtOutStream to write to
126
+ * @param num the 32-bit unsigned integer to write
127
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
128
+ */
129
+ extern void frt_os_write_u32(FrtOutStream *os, frt_u32 num);
130
+
131
+ /**
132
+ * Write a 64-bit unsigned integer to the FrtOutStream
133
+ *
134
+ * @param os FrtOutStream to write to
135
+ * @param num the 64-bit unsigned integer to write
136
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
137
+ */
138
+ extern void frt_os_write_u64(FrtOutStream *os, frt_u64 num);
139
+
140
+ /**
141
+ * Write an unsigned integer to FrtOutStream in compressed VINT format.
142
+ * TODO: describe VINT format
143
+ *
144
+ * @param os FrtOutStream to write to
145
+ * @param num the integer to write
146
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
147
+ */
148
+ extern void frt_os_write_vint(FrtOutStream *os, register unsigned int num);
149
+
150
+
151
+ /**
152
+ * Write an unsigned frt_off_t to FrtOutStream in compressed VINT format.
153
+ * TODO: describe VINT format
154
+ *
155
+ * @param os FrtOutStream to write to
156
+ * @param num the frt_off_t to write
157
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
158
+ */
159
+ extern void frt_os_write_voff_t(FrtOutStream *os, register frt_off_t num);
160
+
161
+ /**
162
+ * Write an unsigned 64bit int to FrtOutStream in compressed VINT format.
163
+ * TODO: describe VINT format
164
+ *
165
+ * @param os FrtOutStream to write to
166
+ * @param num the 64bit int to write
167
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
168
+ */
169
+ extern void frt_os_write_vll(FrtOutStream *os, register frt_u64 num);
170
+
171
+ /**
172
+ * Write a string with known length to the FrtOutStream. A string is an
173
+ * integer +length+ in VINT format (see frt_os_write_vint) followed by
174
+ * +length+ bytes. The string can then be read using frt_is_read_string.
175
+ *
176
+ * @param os FrtOutStream to write to
177
+ * @param str the string to write
178
+ * @param len the length of the string to write
179
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
180
+ */
181
+ extern void frt_os_write_string_len(FrtOutStream *os,
182
+ const char *str,
183
+ int len);
184
+
185
+ /**
186
+ * Write a string to the FrtOutStream. A string is an integer +length+ in VINT
187
+ * format (see frt_os_write_vint) followed by +length+ bytes. The string can then
188
+ * be read using frt_is_read_string.
189
+ *
190
+ * @param os FrtOutStream to write to
191
+ * @param str the string to write
192
+ * @raise FRT_IO_ERROR if there is an error writing to the file-system
193
+ */
194
+ extern void frt_os_write_string(FrtOutStream *os, const char *str);
195
+
196
+ extern int frt_os_write_compressed_bytes(FrtOutStream* out_stream, frt_uchar *data, int length, FrtCompressionType compression);
197
+
198
+ #endif
@@ -0,0 +1,12 @@
1
+ #ifndef FRT_RAM_STORE_H
2
+ #define FRT_RAM_STORE_H
3
+
4
+ typedef struct FrtRAMFile {
5
+ char *name;
6
+ frt_uchar **buffers;
7
+ int bufcnt;
8
+ frt_off_t len;
9
+ _Atomic unsigned int ref_cnt;
10
+ } FrtRAMFile;
11
+
12
+ #endif