# eProsima Micro CDR
[![Releases](https://img.shields.io/github/release/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/releases)
[![License](https://img.shields.io/github/license/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/blob/master/LICENSE)
[![Issues](https://img.shields.io/github/issues/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/issues)
[![Forks](https://img.shields.io/github/forks/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/network/members)
[![Stars](https://img.shields.io/github/stars/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/stargazers)
<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>
*eProsima MicroCDR* is a *C* library implementing the *CDR* standard serialization methods.
This library is focused on embedded and resource-limited systems.
*MicroCDR* uses a static buffer, and allow to serialize and deserialize in both, big endianness and little endianness.
## Usage examples
This is a code example showing the serialization and deserialization of a string.
As *MicroCDR* uses a static buffer, that means the user has to provide a defined buffer and its size during the *ucdrBuffer* creation.
```c
#include <ucdr/microcdr.h>
#include <stdio.h>
#define BUFFER_LENGTH 256
int main(int argc, char** args)
{
// Data buffer
uint8_t buffer[BUFFER_LENGTH];
// Structs for handle the buffer.
ucdrBuffer writer;
ucdrBuffer reader;
// Initialize the MicroBuffers for working with an user-managed buffer.
ucdr_init_buffer(&writer, buffer, BUFFER_LENGTH);
ucdr_init_buffer(&reader, buffer, BUFFER_LENGTH);
// Serialize data
char input[16] = "Hello MicroCDR!"; //16 characters
ucdr_serialize_array_char(&writer, input, 16);
// Deserialize data
char output[16];
ucdr_deserialize_array_char(&reader, output, 16);
printf("Input: %s\n", input);
printf("Output: %s\n", output);
return 0;
}
```
## API functions
```c
void ucdr_init_buffer (ucdrBuffer* ub, uint8_t* data, size_t size);
void ucdr_init_buffer_offset (ucdrBuffer* ub, uint8_t* data, size_t size, size_t offset);
```
Initialize a `ucdrBuffer` structure, the main struct of *MicroCDR*.
- `ub`: the `ucdrBuffer` struct
- `data`: the buffer that the `ucdrBuffer` will use.
- `size`: the size of the buffer that the `ucdrBuffer` will use.
- `offset`: where the serialization/deserialization will start.
Initially, the serialization/deserialization starts at the beginning of the buffer.
---
```c
void ucdr_copy_buffer (ucdrBuffer* ub_dest, const ucdrBuffer* ub_source);
```
Copy a `ucdrBuffer` structure data to another `ucdrBuffer` structure.
- `ub_dest`: the destination `ucdrBuffer` struct.
- `ub_source`: the origin initialized `ucdrBuffer` struct.
---
```c
void ucdr_reset_buffer (ucdrBuffer* ub);
void ucdr_reset_buffer_offset(ucdrBuffer* ub, size_t offset);
```
Reset the `ucdrBuffer` as the same state that it was created.
- `ub`: the `ucdrBuffer` struct.
- `offset`: where the serialization/deserialization will start.
Initially, the serialization/deserialization starts at the beginning of the buffer.
---
```c
void ucdr_align_to (ucdrBuffer* ub, size_t size);
```
Align the ucdrBuffer to the size `size`.
After call this function, the serialization pointer will be moved only if the current `ucdrBuffer` was not alignment to the passed value.
- `ub`: the `ucdrBuffer` struct
- `size`: the target size alignment.
---
```c
size_t ucdr_alignment(size_t buffer_position, size_t data_size);
```
Returns the alignment necessary to serialize/deserialize a type with `data_size` size.
- `buffer_position`: the current serialization/deserialization position of the `ucdrBuffer`. (Typically `ub->iterator - ub->init`).
- `data_size`: the bytes of the data that you are asking for.
---
```c
size_t ucdr_buffer_alignment(const ucdrBuffer* ub, size_t data_size);
```
Returns the alignment necessary to serialize/deserialize a type with `data_size` size into the `ucdrBuffer` given.
- `ub`: the `ucdrBuffer` struct to ask the alignment.
- `data_size`: the bytes of the data that you are asking for.
---
```c
size_t ucdr_buffer_size(const ucdrBuffer* ub);
```
Returns the memory size of the buffer.
- `ub`: the `ucdrBuffer` struct
---
```c
size_t ucdr_buffer_length(const ucdrBuffer* ub);
```
Returns the size of the serialized/deserialized data.
- `ub`: the `ucdrBuffer` struct
---
```c
size_t ucdr_buffer_remaining(const ucdrBuffer* ub);
```
Returns the remaining size for the serializing/deserializing.
- `ub`: the `ucdrBuffer` struct
---
```c
ucdrEndianness ucdr_buffer_endianness(const ucdrBuffer* ub);
```
Returns the serialization/deserialization endianness.
- `ub`: the `ucdrBuffer` struct
---
```c
bool ucdr_buffer_error(const ucdrBuffer* ub);
```
Returns the status error of the `ucdrBuffer`.
- `ub`: the `ucdrBuffer` struct
### Serialization/deserialization functions
Adding to this, there is a big set of functions for deserialize and deserialize different kind of types:
- Basics: `bool`, `char`, `int8_t`, `uint8_t`,`int16_t`, `uint16_t`,`int32_t`, `uint32_t`,`int64_t`, `uint64_t`,`float`, `double`.
- Arrays: Any fixed size of basics types.
- Sequence: Similar to arrays, but the information about the size is serialized along with the data.
- String: Wrapper of char sequence, but easily to use.
### Endianness
*MicroCDR* supports little and big endianness.
The **machine endianness** can be set by the cmake variable: `CONFIG_BIG_ENDIANNESS`.
By default, if this varible is `OFF` which means that the machine endianness is little endianness.
The `ucdrBuffer` endianness can be set by the `endianness` parameter of the structure to `UCDR_BIG_ENDIANNESS` or `UCDR_LITTLE_ENDIANNESS`.
Also, there are a functions that allow to force an endianness independiently of the `ucdrBuffer` endianness in their serialization/deserialization.
These functions contains the name `endianness` in their signature.
### Error
All serialization/deserialization functions return a boolean indicating the result of their operations.
When a serialization/deserialization could not be possible (the type can not be serialized, or the capacity of the destination buffer is not enough),
an status error is setted into the `ucdrBuffer`.
If a `ucdrBuffer` has an error state, the next serialization/deserialization operations will not works and will return `false` in their execution.
A buffer marked with an error can be used, but any serialization/deserialization operation over it will not produce any effect.
If is kwown that an operation can fails over a `ucdrBuffer`, and its necessary to continue with the serialization/deserialization if it happens,
the `ucdrBuffer` state can be saved using the `ucdr_copy_buffer` function.
After the application of the wrong serialization/deserialization, only the `ucdrBuffer` that performed the operation will have a dirty state.
## Serialization/deserialization list
The available modes of serialization/deserializations in *MicroCDR* are shown in the following table.
| Type | Endianness |
| -------------------- | ---------- |
| bool | |
| char | |
| int8 | |
| uint8 | |
| int16 | |
| int16 | endianness |
| uint16 | |
| uint16 | endianness |
| int32 | |
| int32 | endianness |
| uint32 | |
| uint32 | endianness |
| int64 | |
| int64 | endianness |
| uint64 | |
| uint64
没有合适的资源?快使用搜索试试~ 我知道了~
PX4固件源码,亲测可编译
共2000个文件
c:6589个
h:4537个
cpp:882个
5星 · 超过95%的资源 需积分: 31 27 下载量 92 浏览量
2022-07-25
19:41:05
上传
评论 1
收藏 51.02MB ZIP 举报
温馨提示
PX4固件源码,亲测可编译
资源详情
资源评论
资源推荐
收起资源包目录
PX4固件源码,亲测可编译 (2000个子文件)
img_bubble_pattern.c 5.93MB
stm32_wlan_firmware.c 1.24MB
nximage_bitmap.c 312KB
sam_gf1024.c 267KB
imxrt106x_daisy.c 213KB
imxrt105x_daisy.c 179KB
stm32_otgdev.c 175KB
lpc31_ehci.c 175KB
stm32l4_otgfsdev.c 174KB
imxrt_ehci.c 170KB
efm32_usbdev.c 170KB
stm32_otgfsdev.c 170KB
stm32_otgdev.c 169KB
bas_token.c 169KB
lpc43_ehci.c 168KB
stm32_otghsdev.c 167KB
efm32_usbhost.c 165KB
smart.c 164KB
stm32l4_otgfshost.c 164KB
sam_ehci.c 162KB
stm32_otghshost.c 162KB
stm32_otghost.c 162KB
stm32_otgfshost.c 162KB
stm32_otghost.c 161KB
sam_usbdevhs.c 153KB
vi.c 152KB
stm32_hrtim.c 152KB
usbhost_max3421e.c 151KB
bas_statement.c 148KB
sam_emac.c 146KB
sam_udphs.c 139KB
imxrt102x_daisy.c 136KB
cxd56_sdhci.c 136KB
sam_gf512.c 135KB
kinetis_usbdev.c 133KB
pic32mx-usbdev.c 133KB
spirit_radio.c 129KB
stm32_adc.c 129KB
tm4c_ethernet.c 126KB
stm32_ethernet.c 126KB
sam_ohci.c 124KB
sam_emacb.c 124KB
sam_mcan.c 123KB
ft80x_coprocessor.c 123KB
rx65n_eth.c 122KB
sam_udp.c 122KB
stm32_ethernet.c 121KB
sam_usb.c 120KB
lpc54_usb0_ohci.c 120KB
sam_usb.c 119KB
lpc17_40_usbhost.c 119KB
stm32_eth.c 119KB
sx127x.c 118KB
stm32_pwm.c 118KB
stm32_usbdev.c 118KB
stm32l4_usbdev.c 117KB
ftpd.c 116KB
stm32_usbdev.c 115KB
spiffs_core.c 114KB
mmcsd_sdio.c 113KB
isx012.c 113KB
lpc43_ethernet.c 111KB
stm32_sdmmc.c 110KB
stm32_pwm.c 108KB
stm32_sdmmc.c 106KB
stm32_serial.c 105KB
tiva_timerlib.c 105KB
lpc17_40_usbdev.c 104KB
sam_gmac.c 104KB
sam_hsmci.c 103KB
sam_emaca.c 103KB
sam_hsmci.c 103KB
sam_emac.c 102KB
pic32mz-ethernet.c 101KB
lpc214x_usbdev.c 100KB
pic32mx-ethernet.c 99KB
stm32l4_sdmmc.c 99KB
cxd56_usbdev.c 99KB
lpc17_40_ethernet.c 96KB
sam_ssc.c 96KB
sam_ssc.c 95KB
stm32_sdio.c 95KB
imxrt_usdhc.c 94KB
cdcacm.c 93KB
stm32l4_i2c.c 93KB
usbmsc_scsi.c 92KB
kinetis_sdhc.c 91KB
libhttpd.c 91KB
lpc54_ethernet.c 90KB
imxrt_usbdev.c 89KB
sam_lcd.c 88KB
stm32_ltdc.c 88KB
stm32_ltdc.c 88KB
lpc17_40_sdcard.c 87KB
stm32_i2c.c 87KB
stm32l4_serial.c 87KB
termios_test_imp.c 86KB
stm32_i2c.c 86KB
stm32_i2c_v2.c 86KB
stm32_i2c.c 86KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
求上进的小怪兽
- 粉丝: 101
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论10