0b50f7882f910abd3c46a55de4f4d0f509c12b73
[strongswan.git] / src / libstrongswan / bio / bio_writer.h
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup bio_writer bio_writer
18 * @{ @ingroup bio
19 */
20
21 #ifndef BIO_WRITER_H_
22 #define BIO_WRITER_H_
23
24 typedef struct bio_writer_t bio_writer_t;
25
26 #include <library.h>
27
28 /**
29 * Buffered output generator.
30 */
31 struct bio_writer_t {
32
33 /**
34 * Append a 8-bit integer to the buffer.
35 *
36 * @param value value to append
37 */
38 void (*write_uint8)(bio_writer_t *this, u_int8_t value);
39
40 /**
41 * Append a 16-bit integer to the buffer.
42 *
43 * @param value value to append
44 */
45 void (*write_uint16)(bio_writer_t *this, u_int16_t value);
46
47 /**
48 * Append a 24-bit integer to the buffer.
49 *
50 * @param value value to append
51 */
52 void (*write_uint24)(bio_writer_t *this, u_int32_t value);
53
54 /**
55 * Append a 32-bit integer to the buffer.
56 *
57 * @param value value to append
58 */
59 void (*write_uint32)(bio_writer_t *this, u_int32_t value);
60
61 /**
62 * Append a 64-bit integer to the buffer.
63 *
64 * @param value value to append
65 */
66 void (*write_uint64)(bio_writer_t *this, u_int64_t value);
67
68 /**
69 * Append a chunk of data without a length header.
70 *
71 * @param value value to append
72 */
73 void (*write_data)(bio_writer_t *this, chunk_t value);
74
75 /**
76 * Append a chunk of data with a 8-bit length header.
77 *
78 * @param value value to append
79 */
80 void (*write_data8)(bio_writer_t *this, chunk_t value);
81
82 /**
83 * Append a chunk of data with a 16-bit length header.
84 *
85 * @param value value to append
86 */
87 void (*write_data16)(bio_writer_t *this, chunk_t value);
88
89 /**
90 * Append a chunk of data with a 24-bit length header.
91 *
92 * @param value value to append
93 */
94 void (*write_data24)(bio_writer_t *this, chunk_t value);
95
96 /**
97 * Append a chunk of data with a 32-bit length header.
98 *
99 * @param value value to append
100 */
101 void (*write_data32)(bio_writer_t *this, chunk_t value);
102
103 /**
104 * Prepend a 8-bit length header to existing data.
105 */
106 void (*wrap8)(bio_writer_t *this);
107
108 /**
109 * Prepend a 16-bit length header to existing data.
110 */
111 void (*wrap16)(bio_writer_t *this);
112
113 /**
114 * Prepend a 24-bit length header to existing data.
115 */
116 void (*wrap24)(bio_writer_t *this);
117
118 /**
119 * Prepend a 32-bit length header to existing data.
120 */
121 void (*wrap32)(bio_writer_t *this);
122
123 /**
124 * Get the encoded data buffer.
125 *
126 * @return chunk to internal buffer
127 */
128 chunk_t (*get_buf)(bio_writer_t *this);
129
130 /**
131 * Destroy a bio_writer_t.
132 */
133 void (*destroy)(bio_writer_t *this);
134 };
135
136 /**
137 * Create a bio_writer instance.
138 *
139 * @param bufsize initially allocated buffer size
140 */
141 bio_writer_t *bio_writer_create(u_int32_t bufsize);
142
143 #endif /** BIO_WRITER_H_ @}*/