Skip to content

Commit

Permalink
feat(Network): Add packed.hpp for network structs
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterLaplace committed Jan 11, 2024
1 parent b4d5dab commit d983ae7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions Flakkari/Network/packed.hpp
Original file line number Diff line number Diff line change
@@ -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_ */

0 comments on commit d983ae7

Please sign in to comment.