{"id":27301501,"url":"https://github.com/eprosima/micro-cdr","last_synced_at":"2026-03-04T12:31:52.788Z","repository":{"id":39613389,"uuid":"83652011","full_name":"eProsima/Micro-CDR","owner":"eProsima","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-14T09:30:03.000Z","size":733,"stargazers_count":47,"open_issues_count":2,"forks_count":76,"subscribers_count":10,"default_branch":"master","last_synced_at":"2026-02-13T09:04:34.986Z","etag":null,"topics":["c","cdr","dds","dds-xrce","serialization"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eProsima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-03-02T08:10:56.000Z","updated_at":"2025-11-26T03:04:53.000Z","dependencies_parsed_at":"2025-10-02T12:17:40.301Z","dependency_job_id":null,"html_url":"https://github.com/eProsima/Micro-CDR","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/eProsima/Micro-CDR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eProsima%2FMicro-CDR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eProsima%2FMicro-CDR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eProsima%2FMicro-CDR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eProsima%2FMicro-CDR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eProsima","download_url":"https://codeload.github.com/eProsima/Micro-CDR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eProsima%2FMicro-CDR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30079737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T12:28:08.313Z","status":"ssl_error","status_checked_at":"2026-03-04T12:27:28.210Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cdr","dds","dds-xrce","serialization"],"created_at":"2025-04-12T01:46:31.250Z","updated_at":"2026-03-04T12:31:52.753Z","avatar_url":"https://github.com/eProsima.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eProsima Micro CDR\n\n[![Releases](https://img.shields.io/github/release/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/releases)\n[![License](https://img.shields.io/github/license/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/blob/master/LICENSE)\n[![Issues](https://img.shields.io/github/issues/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/issues)\n[![Forks](https://img.shields.io/github/forks/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/network/members)\n[![Stars](https://img.shields.io/github/stars/eProsima/Micro-CDR.svg)](https://github.com/eProsima/Micro-CDR/stargazers)\n\n\u003ca href=\"http://www.eprosima.com\"\u003e\u003cimg src=\"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSd0PDlVz1U_7MgdTe0FRIWD0Jc9_YH-gGi0ZpLkr-qgCI6ZEoJZ5GBqQ\" align=\"left\" hspace=\"8\" vspace=\"2\" width=\"100\" height=\"100\" \u003e\u003c/a\u003e\n\n*eProsima Micro CDR* is a *C* library implementing the *CDR* standard serialization methods.\nThis library is focused on embedded and resource-limited systems.\n\n*Micro CDR* uses a static buffer, and allow to serialize and deserialize in both, big endianness and little endianness.\n\n## Commercial support\n\nLooking for commercial support? Write us to info@eprosima.com\n\nFind more about us at [eProsima’s webpage](https://eprosima.com/).\n\n## Usage examples\nThis is a code example showing the serialization and deserialization of a string.\nAs *Micro CDR* uses a static buffer, the user has to provide a defined buffer and its size during the *ucdrBuffer* creation.\n\n```c\n    #include \u003cucdr/microcdr.h\u003e\n    #include \u003cstdio.h\u003e\n\n    #define BUFFER_LENGTH 256\n\n    int main(int argc, char** args)\n    {\n        // Data buffer\n        uint8_t buffer[BUFFER_LENGTH];\n\n        // Structs for handle the buffer.\n        ucdrBuffer writer;\n        ucdrBuffer reader;\n\n        // Initialize the MicroBuffers for working with an user-managed buffer.\n        ucdr_init_buffer(\u0026writer, buffer, BUFFER_LENGTH);\n        ucdr_init_buffer(\u0026reader, buffer, BUFFER_LENGTH);\n\n        // Serialize data\n        char input[16] = \"Hello Micro CDR!\"; //16 characters\n        ucdr_serialize_array_char(\u0026writer, input, 16);\n\n        // Deserialize data\n        char output[16];\n        ucdr_deserialize_array_char(\u0026reader, output, 16);\n\n        printf(\"Input: %s\\n\", input);\n        printf(\"Output: %s\\n\", output);\n\n        return 0;\n    }\n```\n\n## API functions\n\n```c\nvoid ucdr_init_buffer                       (ucdrBuffer* ub, uint8_t* data, size_t size);\nvoid ucdr_init_buffer_origin                (ucdrBuffer* ub, uint8_t* data, size_t size, size_t origin);\nvoid ucdr_init_buffer_origin_offset         (ucdrBuffer* ub, uint8_t* data, size_t size, size_t origin, size_t offset);\nvoid ucdr_init_buffer_origin_offset_endian  (ucdrBuffer* ub, uint8_t* data, size_t size, size_t origin, size_t offset, ucdrEndianness endianness);\n```\nInitialize a `ucdrBuffer` structure, the main struct of *Micro CDR*.\n- `ub`: the `ucdrBuffer` struct.\n- `data`: the buffer that the `ucdrBuffer` will use.\n- `size`: the size of the buffer that the `ucdrBuffer` will use.\n- `origin`: the origin of the XCDR stream.\n- `offset`: where the serialization/deserialization will start.\n- `endianness`: the endianness of the XCDR stream.\nInitially, the serialization/deserialization starts at the beginning of the buffer.\n\n---\n\n```c\nvoid ucdr_copy_buffer (ucdrBuffer* ub_dest, const ucdrBuffer* ub_source);\n```\nCopy a `ucdrBuffer` structure data to another `ucdrBuffer` structure.\n- `ub_dest`: the destination `ucdrBuffer` struct.\n- `ub_source`: the origin initialized `ucdrBuffer` struct.\n\n---\n\n```c\nvoid ucdr_set_on_full_buffer_callback (ucdrBuffer* ub, OnFullBuffer on_full_buffer, void* args);\n```\nSets the `on_full_buffer` callback which will be called each time the buffer arises its end.\n- `ub`: the `ucdrBuffer` struct.\n- `on_full_buffer`: the callcack.\n- `args`: the argument passes to the callback.\n\n---\n\n```c\nvoid ucdr_reset_buffer       (ucdrBuffer* ub);\nvoid ucdr_reset_buffer_offset(ucdrBuffer* ub, size_t offset);\n```\nReset the `ucdrBuffer` as the same state that it was created.\n- `ub`: the `ucdrBuffer` struct.\n- `offset`: where the serialization/deserialization will start.\nInitially, the serialization/deserialization starts at the beginning of the buffer.\n\n---\n\n```c\nvoid ucdr_align_to (ucdrBuffer* ub, size_t size);\n```\nAlign the ucdrBuffer to the size `size`.\nAfter call this function, the serialization pointer will be moved only if the current `ucdrBuffer` was not alignment to the passed value.\n\n- `ub`: the `ucdrBuffer` struct\n- `size`: the target size alignment.\n\n---\n\n```c\nsize_t ucdr_alignment(size_t buffer_position, size_t data_size);\n```\nReturns the alignment necessary to serialize/deserialize a type with `data_size` size.\n\n- `buffer_position`: the current serialization/deserialization position of the `ucdrBuffer`. (Typically  `ub-\u003eiterator - ub-\u003einit`).\n- `data_size`: the bytes of the data that you are asking for.\n\n---\n\n```c\nsize_t ucdr_buffer_alignment(const ucdrBuffer* ub, size_t data_size);\n```\nReturns the alignment necessary to serialize/deserialize a type with `data_size` size into the `ucdrBuffer` given.\n\n- `ub`: the `ucdrBuffer` struct to ask the alignment.\n- `data_size`: the bytes of the data that you are asking for.\n---\n\n```c\nvoid ucdr_advance_buffer(const ucdrBuffer* ub, size_t size);\n```\nAdvances the XCDR stream `size` bytes without de/serialization involved.\n\n- `ub`: the `ucdrBuffer` struct to ask the alignment.\n- `size`: the bytes to advance.\n---\n\n```c\nsize_t ucdr_buffer_size(const ucdrBuffer* ub);\n```\nReturns the memory size of the buffer.\n- `ub`: the `ucdrBuffer` struct\n\n---\n\n```c\nsize_t ucdr_buffer_length(const ucdrBuffer* ub);\n```\nReturns the size of the serialized/deserialized data.\n- `ub`: the `ucdrBuffer` struct\n\n---\n\n```c\nsize_t ucdr_buffer_remaining(const ucdrBuffer* ub);\n```\nReturns the remaining size for the serializing/deserializing.\n- `ub`: the `ucdrBuffer` struct\n\n---\n\n```c\nucdrEndianness ucdr_buffer_endianness(const ucdrBuffer* ub);\n```\nReturns the serialization/deserialization endianness.\n- `ub`: the `ucdrBuffer` struct\n\n---\n\n```c\nbool ucdr_buffer_error(const ucdrBuffer* ub);\n```\nReturns the status error of the `ucdrBuffer`.\n- `ub`: the `ucdrBuffer` struct\n\n### Serialization/deserialization functions\nAdding to this, there is a big set of functions for deserialize and deserialize different kind of types:\n- Basics: `bool`, `char`, `int8_t`, `uint8_t`,`int16_t`, `uint16_t`,`int32_t`, `uint32_t`,`int64_t`, `uint64_t`,`float`, `double`.\n- Arrays: Any fixed size of basics types.\n- Sequence: Similar to arrays, but the information about the size is serialized along with the data.\n- String: Wrapper of char sequence.\n\n### Endianness\n*Micro CDR* supports little and big endianness.\nThe **machine endianness** can be set by the cmake variable: `CONFIG_BIG_ENDIANNESS`.\nBy default, if this varible is `OFF` which means that the machine endianness is little endianness.\n\nThe `ucdrBuffer` endianness can be set by the `endianness` parameter of the structure to `UCDR_BIG_ENDIANNESS` or `UCDR_LITTLE_ENDIANNESS`.\nAlso, there are a functions that allow to force an endianness independiently of the `ucdrBuffer` endianness in their serialization/deserialization.\nThese functions contains the name `endianness` in their signature.\n\n### Error\nAll serialization/deserialization functions return a boolean indicating the result of their operations.\nWhen a serialization/deserialization could not be possible (the type can not be serialized, or the capacity of the destination buffer is not enough),\nan status error is setted into the `ucdrBuffer`.\nIf a `ucdrBuffer` has an error state, the next serialization/deserialization operations will not works and will return `false` in their execution.\nA buffer marked with an error can be used, but any serialization/deserialization operation over it will not produce any effect.\n\nIf is kwown that an operation can fails over a `ucdrBuffer`, and its necessary to continue with the serialization/deserialization if it happens,\nthe `ucdrBuffer` state can be saved using the `ucdr_copy_buffer` function.\nAfter the application of the wrong serialization/deserialization, only the `ucdrBuffer` that performed the operation will have a dirty state.\n\n## Serialization/deserialization list\nThe available modes of serialization/deserializations in *Micro CDR* are shown in the following table.\n\n| Type                 | Endianness |\n| -------------------- | ---------- |\n| bool                 |            |\n| char                 |            |\n| int8                 |            |\n| uint8                |            |\n| int16                |            |\n| int16                | endianness |\n| uint16               |            |\n| uint16               | endianness |\n| int32                |            |\n| int32                | endianness |\n| uint32               |            |\n| uint32               | endianness |\n| int64                |            |\n| int64                | endianness |\n| uint64               |            |\n| uint64               | endianness |\n| float                |            |\n| float                | endianness |\n| double               |            |\n| double               | endianness |\n| string               |            |\n| string               | endianness |\n| bool array           |            |\n| char array           |            |\n| int8 array           |            |\n| uint8 array          |            |\n| int16 array          |            |\n| int16 array          | endianness |\n| uint16 array         |            |\n| uint16 array         | endianness |\n| int32 array          |            |\n| int32 array          | endianness |\n| uint32 array         |            |\n| uint32 array         | endianness |\n| int64 array          |            |\n| int64 array          | endianness |\n| uint64 array         |            |\n| uint64 array         | endianness |\n| float array          |            |\n| float array          | endianness |\n| double array         |            |\n| double array         | endianness |\n| bool sequence        |            |\n| bool sequence        | endianness |\n| char sequence        |            |\n| char sequence        | endianness |\n| int8 sequence        |            |\n| int8 sequence        | endianness |\n| uint8 sequence       |            |\n| uint8 sequence       | endianness |\n| int16 sequence       |            |\n| int16 sequence       | endianness |\n| uint16 sequence      |            |\n| uint16 sequence      | endianness |\n| int32 sequence       |            |\n| int32 sequence       | endianness |\n| uint32 sequence      |            |\n| uint32 sequence      | endianness |\n| int64 sequence       |            |\n| int64 sequence       | endianness |\n| uint64 sequence      |            |\n| uint64 sequence      | endianness |\n| float sequence       |            |\n| float sequence       | endianness |\n| double sequence      |            |\n| double sequence      | endianness |\n\n## Additional features\n### Endianness\n*Micro CDR* supports little and big endianness.\nThe configuration can be done by cmake with the cmake `__BIG_ENDIAN__` variable.\nA `0` value implies that the serialization will performed into a little endian machine, and `1` into a big endian machine.\n\nThe default endianness serialization can be choosen by setting the `endianness` parameter of a `ucdrBuffer`  to `UCDR_BIG_ENDIANNESS` or `UCDR_LITTLE_ENDIANNESS`.\nAlso, there are a functions that allow to force an endianness in their serialization/deserialization.\nThese functions contains the name `endiannness` in their signature.\n\n### Error\nAll serialization/deserialization functions return a boolean indicating the result of their operations.\nWhen a serialization/deserialization could not be possible (the type can not be serialized, or the capacity of the destination buffer is not enough),\nan status error is setted into the `ucdrBuffer`.\nIf a `ucdrBuffer` has an error state, the next serialization/deserialization operations will not works and will return `false` in their execution.\nA buffer marked with an error can be used, but any serialization/deserialization operation over it will not produce any effect.\n\nIf is kwown that an operation can fails over a `ucdrBuffer`, and its necessary to continue with the serialization/deserialization if it happens,\nthe `ucdrBuffer` state can be saved using the `ucdr_copy_buffer` function.\nAfter the application of the wrong serialization/deserialization, only the `ucdrBuffer` that performed the operation will have a dirty state.\n\n### Full buffer callback\nMicro CDR provides a callback that the user can set in order to control the behavior when the `ucdrBuffer` can not serialize/deserialize anymore because the buffer is full.\nThis allows to create a better management error and/or modify the buffer location of the `ucdrBuffer`.\nThe last possibility gives the user the capacity to use several small buffers for a big serialization (see the *fragmentation* example).\n\n## Quality Declaration\n\n**eProsima Micro CDR** claims to be in the **Quality Level 1** category based on the guidelines provided by [ROS 2](https://ros.org/reps/rep-2004.html).\nSee the [Quality Declaration](QUALITY.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feprosima%2Fmicro-cdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feprosima%2Fmicro-cdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feprosima%2Fmicro-cdr/lists"}