Skip to content

Commit

Permalink
Refs #4438. Modified the configuration of machine endianness. (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm authored and julionce committed Jan 24, 2019
1 parent 7a76880 commit 62d95c8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
19 changes: 6 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,17 @@ else()
set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses")
endif()

# Endianness configuration
include(${PROJECT_SOURCE_DIR}/cmake/common/check_configuration.cmake)

option(CHECK_ENDIANNESS "Enable/disable endiannes checking" ON)
if(__BIG_ENDIAN__)
set(CHECK_ENDIANNESS OFF)
message(STATUS "micro-CDR without check endianness using provided endianness")
elseif(CHECK_ENDIANNESS)
check_endianness()
# Config.h
set(CONFIG_BIG_ENDIANNESS OFF CACHE BOOL "Set the machine endianness to big endianness (by default is little endianness)")
if(CONFIG_BIG_ENDIANNESS)
set(CONFIG_MACHINE_ENDIANNESS 0) #big
else()
set(__BIG_ENDIAN__ 0)
message(STATUS "micro-CDR without check endianness")
set(CONFIG_MACHINE_ENDIANNESS 1) #little
endif()

# Config.h
configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in
${PROJECT_BINARY_DIR}/include/ucdr/config.h
)
)

###############################################################################
# Compile settings
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eProsima Micro CDR
# 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)
Expand Down Expand Up @@ -163,12 +163,12 @@ Adding to this, there is a big set of functions for deserialize and deserialize

### Endianness
*MicroCDR* supports little and big endianness.
The configuration can be done by cmake with the cmake `__BIG_ENDIAN__` variable.
A `0` value implies that the serialization will performed into a little endian machine, and `1` into a big endian machine.
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 default endianness serialization can be choosen by setting the `endianness` parameter of a `ucdrBuffer` to `UCDR_BIG_ENDIANNESS` or `UCDR_LITTLE_ENDIANNESS`.
Also, there are a functions that allow to force an endianness in their serialization/deserialization.
These functions contains the name `endiannness` in their signature.
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.
Expand Down
6 changes: 2 additions & 4 deletions include/ucdr/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ extern "C" {
#include <stddef.h>

typedef enum ucdrEndianness {
UCDR_BIG_ENDIANNESS,
UCDR_LITTLE_ENDIANNESS
UCDR_BIG_ENDIANNESS = 0,
UCDR_LITTLE_ENDIANNESS = 1

} ucdrEndianness;

Expand All @@ -45,8 +45,6 @@ typedef struct ucdrBuffer

} ucdrBuffer;

UCDRDLLAPI extern const ucdrEndianness UCDR_MACHINE_ENDIANNESS;

// ------------------------------------------------
// Main library functions
// ------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions include/ucdr/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#define MICROCDR_VERSION_STR "@PROJECT_VERSION@"

// ucdrEndianness defines
#ifndef __BIG_ENDIAN__
#define __BIG_ENDIAN__ @__BIG_ENDIAN__@
#endif
#define UCDR_MACHINE_ENDIANNESS @CONFIG_MACHINE_ENDIANNESS@

#endif // _MICROCDR_CONFIG_H_
6 changes: 0 additions & 6 deletions src/c/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

#include <string.h>

#if __BIG_ENDIAN__
const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_BIG_ENDIANNESS;
#else
const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_LITTLE_ENDIANNESS;
#endif

// -------------------------------------------------------------------
// INTERNAL UTIL IMPLEMENTATIONS
// -------------------------------------------------------------------
Expand Down

0 comments on commit 62d95c8

Please sign in to comment.