-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Network): Add packed.hpp for network structs
- Loading branch information
1 parent
b4d5dab
commit d983ae7
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |