RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
reda_buffer.h
1 /*
2  * FILE: reda_buffer.h - Buffer API
3  *
4  * (c) Copyright, Real-Time Innovations, 2008-2014
5  *
6  * All rights reserved.
7  *
8  * No duplications, whole or partial, manual or electronic, may be made
9  * without express written permission. Any such copies, or
10  * revisions thereof, must display this notice unaltered.
11  * This code contains trade secrets of Real-Time Innovations, Inc.
12  *
13  * Modification History
14  * --------------------
15  * 22sep2008,tk Created
16  *
17  */
18 /*ci
19  * \file
20  * \defgroup REDABufferClass REDA Buffer
21  * \ingroup REDAModule
22  * \brief Buffer API
23  *
24  * \details
25  * A REDA Buffer encapsulates a pointer to a character array and a length.
26  * No assumptions are made regarding the content of the octet array
27  */
28 /*ci \addtogroup REDABufferClass
29  * @{
30  */
31 #ifndef reda_buffer_h
32 #define reda_buffer_h
33 
34 #ifndef reda_dll_h
35 #include "reda/reda_dll.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 /*ci
44  * \brief Generic buffer to hold data, described by a pointer to the data, as
45  * well as the length of the data.
46  */
47 struct REDA_Buffer
48 {
49  /*ci
50  * \brief Length of the buffer pointed to by pointer.
51  */
52  RTI_UINT32 length;
53 
54  /*ci
55  * \brief Pre-allocated (by the caller) buffer.
56  */
57  char *pointer;
58 };
59 
60 /*ci
61  * \brief Set the elements of a REDA_Buffer.
62  *
63  * \details
64  *
65  * Initialize a REDA buffer with a pre-allocated buffer. It is safer and
66  * more portable than setting the individual fields.
67  *
68  * @param[in] me REDA_Buffer structure to initialize
69  * @param[in] pointer Underlying memory for the buffer, pre-allocated by the
70  * caller
71  * @param[in] length The length of the underlying memory for the buffer
72  *
73  * \sa \ref REDA_Buffer_get
74 */
75 REDADllExport void
76 REDA_Buffer_set(struct REDA_Buffer *me,char *pointer,RTI_UINT32 length);
77 
78 #define REDA_Buffer_set(buf, ptr, len) \
79 { \
80  (buf)->length = (len); \
81  (buf)->pointer = (ptr); \
82 }
83 
84 /*ci
85  * \brief Get the elements of a REDA_Buffer.
86  *
87  * \details
88  *
89  * Retrieve the individual elements of a REDA buffer.
90  * It is safer and more portable than getting the individual fields.
91  *
92  * @param[in] me REDA buffer to retrieve fields from
93  * @param[out] pointer The underlying buffer
94  * @param[out] length The length of the underlying memory for the buffer
95  *
96  * \sa \ref REDA_Buffer_set
97 */
98 REDADllExport void
99 REDA_Buffer_get(struct REDA_Buffer *me,char **pointer, RTI_UINT32 *length);
100 
101 #define REDA_Buffer_get(buf, ptr, len) \
102 { \
103  *len = (buf)->length; \
104  *ptr = (buf)->pointer; \
105 }
106 
107 /*ci
108  * \brief Reset the elements of a REDA_Buffer.
109  *
110  * \details
111  *
112  * Reset the elements of a REDA buffer to an empty buffer.
113  * It is safer and more portable than setting the individual fields.
114  *
115  * @param[in] me REDA buffer to reset
116  *
117  * \sa \ref REDA_Buffer_set
118  */
119 REDADllExport void
120 REDA_Buffer_reset(struct REDA_Buffer *me);
121 
122 #define REDA_Buffer_reset(buf) REDA_Buffer_set(buf, NULL, 0)
123 
124 
125 /*ci
126  * \brief REDA_Buffer initializer
127  *
128  * \details
129  *
130  * REDA_Buffer initializer useful for initialization as indicated by
131  * the usage:
132  *
133  * \code
134  * struct REDA_Buffer buf = REDA_BUFFER_INVALID;
135  * \endcode
136 */
137 #define REDA_BUFFER_INVALID {0, NULL}
138 
139 #ifdef __cplusplus
140 } /* extern "C" */
141 #endif
142 
143 #endif /* reda_buffer_h */
144 
145 /*ci
146  * @}
147  */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc