diff --git a/CMakeLists.txt b/CMakeLists.txt index 210ac7b2..ed4275e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(SOURCES set(HEADERS Flakkari/Logger/Logger.hpp + Flakkari/Network/packed.hpp Flakkari/Network/Address.hpp Flakkari/Network/Buffer.hpp Flakkari/Network/Socket.hpp @@ -52,6 +53,7 @@ set(HEADER_LIB_LOGGER ) set(HEADER_LIB_NETWORK + Flakkari/Network/packed.hpp Flakkari/Network/Address.hpp Flakkari/Network/Buffer.hpp Flakkari/Network/Socket.hpp @@ -146,6 +148,7 @@ include(CPack) # Create a dynamic library for the Network components set(SOURCES_LIB_NETWORK Flakkari/Logger/Logger.cpp + Flakkari/Network/packed.hpp Flakkari/Network/Address.cpp Flakkari/Network/Buffer.cpp Flakkari/Network/Socket.cpp diff --git a/Flakkari/Network/packed.hpp b/Flakkari/Network/packed.hpp new file mode 100644 index 00000000..3415b523 --- /dev/null +++ b/Flakkari/Network/packed.hpp @@ -0,0 +1,54 @@ +/************************************************************************** + * Flakkari Library v0.2.0 + * + * Flakkari Library is a C++ Library for Network. + * @file packed.hpp + * @brief packed header. Contains PACKED macros. + * (PACKED_START, PACKED_END, PACKED) + * + * @details PACKED_START and PACKED_END macros are used to pack structs: + * PACKED_<_> macros are used to pack structs: + * PACKED_START struct _ {}; PACKED_END + * PACKED macros are used to pack structs: + * struct _ {} PACKED; + * + * Flakkari Library is under MIT License. + * https://opensource.org/licenses/MIT + * © 2023 @MasterLaplace + * @version 0.2.0 + * @date 2023-01-10 + **************************************************************************/ + + +#ifndef PACKED_HPP_ + #define PACKED_HPP_ + +#ifdef _MSC_VER +#define PACKED_START __pragma(pack(push, 1)) +#define PACKED_END __pragma(pack(pop)) +#else +#define PACKED_START _Pragma("pack(1)") +#define PACKED_END _Pragma("pack()") +#endif + +#if __GNUC__ +#define __PACKED __attribute__((packed)) + +#define PACKED(name, body) \ +do { \ + struct name body __PACKED; \ +} while (0) + +#else + +#define PACKED(name, body) \ +do { \ + PACKED_START \ + struct name \ + body; \ + PACKED_END \ +} while (0) + +#endif + +#endif /* !PACKED_HPP_ */