Finishing the total time counters
[lwes-journaller.git] / src / marshal.h
blob071f68f24b96285020af4a7e9c6676140c1ed14d
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
21 #ifndef MARSHAL_DOT_H
22 #define MARSHAL_DOT_H
24 #include <netinet/in.h>
26 #define marshal_short(cp, x) { \
27 uint16_t tmp = htons(x); \
28 memcpy((uint16_t*)cp, &tmp, sizeof(tmp)); \
29 cp = (unsigned char*)((uint16_t*)cp + 1); \
32 #define marshal_long(cp, x) { \
33 uint32_t tmp = htonl(x); \
34 memcpy((uint16_t*)cp, &tmp, sizeof(tmp)); \
35 cp = (unsigned char*)((uint32_t*)cp + 1); \
38 #define marshal_long_long(cp, x) { \
39 uint32_t tmp = htonl((unsigned long long)((x >> 32) & 0xFFFFFFFF)); \
40 memcpy((uint32_t*)cp + 0, &tmp, sizeof(tmp)); \
41 tmp = htonl((unsigned long long)(x & 0xFFFFFFFF)); \
42 memcpy((uint32_t*)cp + 1, &tmp, sizeof(tmp)); \
43 cp = (unsigned char*)((uint32_t*)cp + 2); \
46 #define marshal_ulong_long(cp, x) { \
47 uint32_t tmp = htonl((unsigned long long)((x >> 32) & 0xFFFFFFFF)); \
48 memcpy((uint32_t*)cp + 0, &tmp, sizeof(tmp)); \
49 tmp = htonl((unsigned long long)(x & 0xFFFFFFFF)); \
50 memcpy((uint32_t*)cp + 1, &tmp, sizeof(tmp)); \
51 cp = (unsigned char*)((uint32_t*)cp + 2); \
54 #define unmarshal_short(cp, x) { \
55 uint16_t tmp; \
56 memcpy(&tmp, cp, sizeof(tmp)); \
57 x = ntohs(tmp); \
58 cp = (unsigned char*)((uint16_t*)cp + 1); \
61 #define unmarshal_long(cp, x) { \
62 uint32_t tmp; \
63 memcpy(&tmp, cp, sizeof(tmp)); \
64 x = ntohl(tmp); \
65 cp = (unsigned char*)((uint32_t*)cp + 1); \
68 #define unmarshal_long_long(cp, x) { \
69 long long tmp; \
70 memcpy(&tmp, cp, sizeof(tmp)); \
71 x = ((unsigned long long)ntohl(*((uint32_t*)(&tmp) + 0)) << 32) \
72 + ntohl(*((uint32_t*)(&tmp) + 1)); \
73 cp = (unsigned char*)((uint32_t*)cp + 2); \
76 #define unmarshal_ulong_long(cp, x) { \
77 uint32_t tmp[2]; \
78 memcpy(&tmp, cp, sizeof(tmp)); \
79 x = ((unsigned long long)ntohl(tmp[0]) << 32) \
80 + ntohl(tmp[1]); \
81 cp = (unsigned char*)((uint32_t*)cp + 2); \
84 #endif