Ported messages from gear racing controller
[apps/native/gear-racing-car.git] / inc / messages / writer.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef WRITER_H
18 #define WRITER_H
19
20 #include <stdlib.h>
21 #include <stdbool.h>
22
23 typedef struct _writer writer_t;
24
25 /**
26  * @brief writer object
27  */
28 struct _writer
29 {
30         char *data;
31         size_t length;
32         size_t cap;
33 };
34
35 /**
36  * @brief Initializes writer object
37  *
38  * @param[in] writer writer object.
39  * @param[in] length the initial lenght of data buffer.
40  *
41  * @return 0 on success, other value on error
42  */
43 int writer_init_sized(writer_t *writer, size_t length);
44
45 /**
46  * @brief Shutdowns writer object
47  *
48  * @param[in] writer writer object.
49  */
50 void writer_shutdown(writer_t *writer);
51
52 /**
53  * @brief Resets writer object
54  *
55  * Resetting means that next call to write_write_* functions
56  * will write content from the begining of the buffer, overwriting
57  * any previously stored data.
58  *
59  * @param[in] writer writer object.
60  * @param[in] the position in the buffer after which next
61  *            write data will be placed.
62  */
63 void writer_reset(writer_t *buf, size_t position);
64
65 /**
66  * @brief Writes value into writer's buffer
67  *
68  * @param[in] writer writer object
69  * @param[in] value value to write into the writer's buffer
70  *
71  * @return 0 on success, other value on error.
72  */
73 int writer_write_int32(writer_t *writer, int32_t value);
74
75 /**
76  * @brief Writes value into writer's buffer
77  *
78  * @param[in] writer writer object
79  * @param[in] value value to write into the writer's buffer
80  *
81  * @return 0 on success, other value on error.
82  */
83 int writer_write_int64(writer_t *writer, int64_t value);
84
85 /**
86  * @brief Writes value into writer's buffer
87  *
88  * @param[in] writer writer object
89  * @param[in] value value to write into the writer's buffer
90  *
91  * @return 0 on success, other value on error.
92  */
93 int writer_write_bool(writer_t *writer, bool value);
94
95 /**
96  * @brief Writes value into writer's buffer
97  *
98  * @param[in] writer writer object
99  * @param[in] value value to write into the writer's buffer
100  *
101  * @return 0 on success, other value on error.
102  */
103 int writer_write_char(writer_t *writer, char value);
104
105 /**
106  * @brief Writes value into writer's buffer
107  *
108  * @param[in] writer writer object
109  * @param[in] value value to write into the writer's buffer
110  *
111  * @return 0 on success, other value on error.
112  */
113 int writer_write_string(writer_t *writer, const char *value);
114
115 #endif /* end of include guard: WRITER_H */