Skip to content

Commit f10f78b

Browse files
lemunozmrichiware
authored andcommitted
Release 1.0.0 (#15)
* Modified the project strucure and updated the README with more info about the lib. (#7) * Ref #3327. Added, documented and tested type: int8. * #3328 Refactor headers * Ref #3328. Refactor sources. * #3328. Added documentation. * Changes for accepting Pull Request #7 * Changes (2) for accepting Pull Request #7 * Added native string serialization (#8) * Refs #3327. Added string serialization * Added security and refactor/added tests (#9) * Refs #3390. Modify error checker, refactor project layout. Refactor serialization test. Refs #3389 Fix issue: now a serialization will be perform after any serialization error. * Template tests * Refs #3397. Refactored and improved tests. * Refs #3397 #3389. API security changes. Added endianness tests. * Added data_size checks. Added Sequence overflow test. * Refs #3397. Change var name max_size -> array_size * Refs #3397. Added functions to manage error/endianness * Refs #3397. Moved check_buffer function to a common file * Refs #3397. Modify array_capacity parameter position. * Refs #3397. Refactor define names in test. * Updated README with the new types. * Refs #3397. Removed MicroState. Added a copy MicroBuffer function. * Refs #3397. Updated README. Removed set_valid function. * Refs #3397. Added error description to README.md * Refs #3408. Modified DLL exports (#10) * Added mc prefix to MicroCDR (#11) * Refs #3436. MicroBuffer => mcMicroBuffer * Refs #3436. Added -mc at deserialization functions. * Refs #3436. Added -mc at serialization functions. * Recovered internal functions names. * Refs #3436. Rename common functions. * Refs #3436. Added mc preffix to endianness. * Refs #3436. Added mc to README and example. * Refs #3436. Modify mcMicroBuffer to mcBuffer * Refs #3436. micro_buffer to buffer function names * Refs #3436. Fix error. * Refs #3436. Fix mc prefix at mrEndianness. Minor correction * Fix windows warning * Fix warnings * Fix warnings * Feature/prefix change (#13) * Refs #3451. mc_ prefix to ucdr_ prefix * Refs #3451. Modified dll export name * Refs #3458. Updated internal symbols with prefix. * #3451. Updated include path (#14) * #3451. Updated include path * Fixed cmake install
1 parent f325c4f commit f10f78b

40 files changed

+3605
-3388
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
build
22
examples/performance_cmp_versions
33
.vscode
4+
.color_coded
5+
.ycm_extra_conf.py

CMakeLists.txt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ endif()
6868
###############################################################################
6969

7070
# Library
71-
add_library(${PROJECT_NAME} src/c/microcdr.c)
71+
add_library(${PROJECT_NAME}
72+
src/c/common.c
73+
src/c/types/basic.c
74+
src/c/types/string.c
75+
src/c/types/array.c
76+
src/c/types/sequence.c
77+
)
78+
7279
set_common_compile_options(${PROJECT_NAME})
7380
set_target_properties(${PROJECT_NAME} PROPERTIES
7481
VERSION ${PROJECT_VERSION}
@@ -114,8 +121,8 @@ else()
114121
endif()
115122

116123
# Config.h
117-
configure_file(${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/config.h.in
118-
${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/config.h
124+
configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in
125+
${PROJECT_BINARY_DIR}/include/ucdr/config.h
119126
)
120127

121128
###############################################################################
@@ -154,22 +161,22 @@ install(TARGETS ${PROJECT_NAME}
154161
)
155162

156163
# Install includes
157-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/
158-
DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}
164+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ucdr/
165+
DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr
159166
FILES_MATCHING PATTERN "*.h"
160167
)
161168

162169
# Install config.h
163-
install(FILES ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/config.h
164-
DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}
170+
install(FILES ${PROJECT_BINARY_DIR}/include/ucdr/config.h
171+
DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr
165172
)
166173

167174
# Export library
168175
install(EXPORT ${PROJECT_NAME}Targets
169176
DESTINATION ${LIB_INSTALL_DIR}/${PROJECT_NAME}/cmake
170177
)
171178

172-
# Package configuration
179+
# Package configuration
173180
include(CMakePackageConfigHelpers)
174181
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in
175182
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake

README.md

Lines changed: 148 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
<a href="http://www.eprosima.com"><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSd0PDlVz1U_7MgdTe0FRIWD0Jc9_YH-gGi0ZpLkr-qgCI6ZEoJZ5GBqQ" align="left" hspace="8" vspace="2" width="100" height="100" ></a>
44

5-
*eProsima microCDR* is a C library implementing the CDR standard serialization methods.
5+
*eProsima MicroCDR* is a *C* library implementing the *CDR* standard serialization methods.
66
This library is focused on embedded and resource-limited systems.
77

8-
*microCDR* uses a static buffer, is always aligned, and allow to serialize and deserialize in both, big endianness and little endianness.
9-
For more information about the API of *microCDR* check ...?
8+
*MicroCDR* uses a static buffer, and allow to serialize and deserialize in both, big endianness and little endianness.
109

1110
## Usage examples
1211
This is a code example showing the serialization and deserialization of a string.
13-
As *microCDR* uses a static buffer, that means the user has to provide a defined buffer and its size during the *MicroBuffer* creation.
12+
As *MicroCDR* uses a static buffer, that means the user has to provide a defined buffer and its size during the *ucdrBuffer* creation.
1413

1514
```c
16-
#include <microcdr/microcdr.h>
15+
#include <ucdr/microcdr.h>
1716
#include <stdio.h>
1817

1918
#define BUFFER_LENGTH 256
@@ -24,20 +23,20 @@ As *microCDR* uses a static buffer, that means the user has to provide a defined
2423
uint8_t buffer[BUFFER_LENGTH];
2524

2625
// Structs for handle the buffer.
27-
MicroBuffer writer;
28-
MicroBuffer reader;
26+
ucdrBuffer writer;
27+
ucdrBuffer reader;
2928

3029
// Initialize the MicroBuffers for working with an user-managed buffer.
31-
init_micro_buffer(&writer, buffer, BUFFER_LENGTH);
32-
init_micro_buffer(&reader, buffer, BUFFER_LENGTH);
30+
ucdr_init_buffer(&writer, buffer, BUFFER_LENGTH);
31+
ucdr_init_buffer(&reader, buffer, BUFFER_LENGTH);
3332

3433
// Serialize data
35-
char input[16] = "Hello microCDR!"; //16 characters
36-
serialize_array_char(&writer, input, 16);
34+
char input[16] = "Hello MicroCDR!"; //16 characters
35+
ucdr_serialize_array_char(&writer, input, 16);
3736

3837
// Deserialize data
3938
char output[16];
40-
deserialize_array_char(&reader, output, 16);
39+
ucdr_deserialize_array_char(&reader, output, 16);
4140

4241
printf("Input: %s\n", input);
4342
printf("Output: %s\n", output);
@@ -46,11 +45,138 @@ As *microCDR* uses a static buffer, that means the user has to provide a defined
4645
}
4746
```
4847
49-
Note: to change the default endianness of functions without the *endian* tag, use the *endianness* member of the *Microbuffer* structure.
48+
## API functions
5049
50+
```c
51+
void ucdr_init_buffer (ucdrBuffer* mb, uint8_t* data, const uint32_t size);
52+
void ucdr_init_buffer_offset (ucdrBuffer* mb, uint8_t* data, const uint32_t size, uint32_t offset);
53+
```
54+
Initialize a `ucdrBuffer` structure, the main struct of *MicroCDR*.
55+
- `mb`: the `ucdrBuffer` struct
56+
- `data`: the buffer that the `ucdrBuffer` will use.
57+
- `size`: the size of the buffer that the `ucdrBuffer` will use.
58+
- `offset`: where the serialization/deserialization will start.
59+
Initially, the serialization/deserialization starts at the beginning of the buffer.
60+
61+
---
62+
63+
```c
64+
void ucdr_copy_buffer (ucdrBuffer* mb_dest, const ucdrBuffer* mb_source);
65+
```
66+
Copy a `ucdrBuffer` structure data to another `ucdrBuffer` structure.
67+
- `mb_dest`: the destination `ucdrBuffer` struct.
68+
- `mb_source`: the origin initialized `ucdrBuffer` struct.
69+
70+
---
71+
72+
```c
73+
void ucdr_reset_buffer (ucdrBuffer* mb);
74+
void ucdr_reset_buffer_offset(ucdrBuffer* mb, const uint32_t offset);
75+
```
76+
Reset the `ucdrBuffer` as the same state that it was created.
77+
- `mb`: the `ucdrBuffer` struct.
78+
- `offset`: where the serialization/deserialization will start.
79+
Initially, the serialization/deserialization starts at the beginning of the buffer.
80+
81+
---
82+
83+
```c
84+
void ucdr_align_to (ucdrBuffer* mb, const uint32_t alignment);
85+
```
86+
Align the ucdrBuffer to an `alignment` position.
87+
After call this function, the serialization pointer will be moved only if the current `ucdrBuffer` was not aligment to the passed value.
88+
89+
- `mb`: the `ucdrBuffer` struct
90+
- `alignment`: the alignment value used.
91+
92+
---
93+
94+
```c
95+
uint32_t ucdr_aligment(uint32_t buffer_position, const uint32_t data_size);
96+
```
97+
Returns the aligment necessary to serialize/deserialize a type with `data_size` size.
98+
99+
- `buffer_position`: the current serialization/deserialization position of the `ucdrBuffer`. (Typically `mb->iterator - mb->init`).
100+
- `data_size`: the bytes of the data that you are asking for.
51101

52-
## Supported types
53-
The types supported in *microCDR* are presented in the following table. For each of them exists a serialization and a deserialization function.
102+
---
103+
104+
```c
105+
uint32_t ucdr_buffer_alignment(const ucdrBuffer* mb, const uint32_t data_size);
106+
```
107+
Returns the aligment necessary to serialize/deserialize a type with `data_size` size into the `ucdrBuffer` given.
108+
109+
- `mb`: the `ucdrBuffer` struct to ask the alignment.
110+
- `data_size`: the bytes of the data that you are asking for.
111+
---
112+
113+
```c
114+
size_t ucdr_buffer_size(const ucdrBuffer* mb);
115+
```
116+
Returns the memory size of the buffer.
117+
- `mb`: the `ucdrBuffer` struct
118+
119+
---
120+
121+
```c
122+
size_t ucdr_buffer_length(const ucdrBuffer* mb);
123+
```
124+
Returns the size of the serialized/deserialized data.
125+
- `mb`: the `ucdrBuffer` struct
126+
127+
---
128+
129+
```c
130+
size_t ucdr_buffer_remaining(const ucdrBuffer* mb);
131+
```
132+
Returns the remaining size for the serializing/deserializing.
133+
- `mb`: the `ucdrBuffer` struct
134+
135+
---
136+
137+
```c
138+
ucdrEndianness ucdr_buffer_endianness(const ucdrBuffer* mb);
139+
```
140+
Returns the serialization/deserialization endianness.
141+
- `mb`: the `ucdrBuffer` struct
142+
143+
---
144+
145+
```c
146+
bool ucdr_buffer_error(const ucdrBuffer* mb);
147+
```
148+
Returns the status error of the `ucdrBuffer`.
149+
- `mb`: the `ucdrBuffer` struct
150+
151+
152+
### Serialization/deserialization functions
153+
Adding to this, there is a big set of functions for deserialize and deserialize different kind of types:
154+
- Basics: `bool`, `char`, `int8_t`, `uint8_t`,`int16_t`, `uint16_t`,`int32_t`, `uint32_t`,`int64_t`, `uint64_t`,`float`, `double`.
155+
- Arrays: Any fixed size of basics types.
156+
- Sequence: Similar to arrays, but the information about the size is serialized along with the data.
157+
158+
### Endianness
159+
*MicroCDR* supports little and big endianness.
160+
The configuration can be done by cmake with the cmake `__BIG_ENDIAN__` variable.
161+
A `0` value implies that the serialization will performed into a little endian machine, and `1` into a big endian machine.
162+
163+
The default endianness serialization can be choosen by setting the `endianness` parameter of a `ucdrBuffer` to `UCDR_BIG_ENDIANNESS` or `UCDR_LITTLE_ENDIANNESS`.
164+
Also, there are a functions that allow to force an endianness in their serialization/deserialization.
165+
These functions contains the name `endiannness` in their signature.
166+
167+
### Error
168+
All serialization/deserialization functions return a boolean indicating the result of their operations.
169+
When a serialization/deserialization could not be possible (the type can not be serialized, or the capacity of the destination buffer is not enough),
170+
an status error is setted into the `ucdrBuffer`.
171+
If a `ucdrBuffer` has an error state, the next serialization/deserialization operations will not works and will return `false` in their execution.
172+
A buffer marked with an error can be used, but any serialization/deserialization operation over it will not produce any effect.
173+
174+
If is kwown that an operation can fails over a `ucdrBuffer`, and its necessary to continue with the serialization/deserialization if it happens,
175+
the `ucdrBuffer` state can be saved using the `ucdr_copy_buffer` function.
176+
After the application of the wrong serialization/deserialization, only the `ucdrBuffer` that performed the operation will have a dirty state.
177+
178+
## Serialization/deserialization list
179+
The available modes of serialization/deserializations in *MicroCDR* are shown in the following table.
54180

55181

56182
| Type | Endianness |
@@ -75,6 +201,8 @@ The types supported in *microCDR* are presented in the following table. For each
75201
| float | endianness |
76202
| double | |
77203
| double | endianness |
204+
| string | |
205+
| string | endianness |
78206
| bool array | |
79207
| char array | |
80208
| int8 array | |
@@ -96,9 +224,13 @@ The types supported in *microCDR* are presented in the following table. For each
96224
| double array | |
97225
| double array | endianness |
98226
| bool sequence | |
227+
| bool sequence | endianness |
99228
| char sequence | |
229+
| char sequence | endianness |
100230
| int8 sequence | |
231+
| int8 sequence | endianness |
101232
| uint8 sequence | |
233+
| uint8 sequence | endianness |
102234
| int16 sequence | |
103235
| int16 sequence | endianness |
104236
| uint16 sequence | |
@@ -115,3 +247,4 @@ The types supported in *microCDR* are presented in the following table. For each
115247
| float sequence | endianness |
116248
| double sequence | |
117249
| double sequence | endianness |
250+

examples/basic.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <microcdr/microcdr.h>
15+
#include <ucdr/microcdr.h>
1616
#include <stdio.h>
1717

1818
#define BUFFER_LENGTH 256
@@ -23,20 +23,20 @@ int main()
2323
uint8_t buffer[BUFFER_LENGTH];
2424

2525
// Structs for handle the buffer.
26-
MicroBuffer writer;
27-
MicroBuffer reader;
26+
ucdrBuffer writer;
27+
ucdrBuffer reader;
2828

2929
// Initialize the MicroBuffers for working with an user-managed buffer.
30-
init_micro_buffer(&writer, buffer, BUFFER_LENGTH);
31-
init_micro_buffer(&reader, buffer, BUFFER_LENGTH);
30+
ucdr_init_buffer(&writer, buffer, BUFFER_LENGTH);
31+
ucdr_init_buffer(&reader, buffer, BUFFER_LENGTH);
3232

3333
// Serialize data
34-
char input[16] = "Hello microCDR!"; //16 characters
35-
serialize_array_char(&writer, input, 16);
34+
char input[16] = "Hello MicroCDR!"; //16 characters
35+
ucdr_serialize_array_char(&writer, input, 16);
3636

3737
// Deserialize data
3838
char output[16];
39-
deserialize_array_char(&reader, output, 16);
39+
ucdr_deserialize_array_char(&reader, output, 16);
4040

4141
printf("Input: %s\n", input);
4242
printf("Output: %s\n", output);

0 commit comments

Comments
 (0)