annotate Core/Endianness.h @ 1959:45c4387a379c

Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Apr 2016 16:26:22 +0200
parents 533ff46e944b
children 869a87c08673
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 ** LINUX ARCHITECTURES
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #if defined(__linux)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 # include <endian.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 ** WINDOWS ARCHITECTURES
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 **
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1939
diff changeset
48 ** On Windows x86, "host" will always be little-endian ("le").
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #if defined(_WIN32)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 # if defined(_MSC_VER)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 // http://msdn.microsoft.com/en-us/library/a3140177.aspx
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 # define be16toh(x) _byteswap_ushort(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 # define be32toh(x) _byteswap_ulong(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 # define be64toh(x) _byteswap_uint64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 # else // MinGW
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 # define be16toh(x) __builtin_bswap16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 # define be32toh(x) __builtin_bswap32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 # define be64toh(x) __builtin_bswap64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 # endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 # define htobe16(x) be16toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 # define htobe32(x) be32toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 # define htobe64(x) be64toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 # define htole16(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 # define htole32(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 # define htole64(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 # define le16toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 # define le32toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 # define le64toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ** FREEBSD ARCHITECTURES
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 # include <arpa/inet.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ** APPLE ARCHITECTURES (including OS X)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 #if defined(__APPLE__)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 # include <libkern/OSByteOrder.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 # define be16toh(x) OSSwapBigToHostInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 # define be32toh(x) OSSwapBigToHostInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 # define be64toh(x) OSSwapBigToHostInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 # define htobe16(x) OSSwapHostToBigInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 # define htobe32(x) OSSwapHostToBigInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 # define htobe64(x) OSSwapHostToBigInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 # define htole16(x) OSSwapHostToLittleInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 # define htole32(x) OSSwapHostToLittleInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 # define htole64(x) OSSwapHostToLittleInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 # define le16toh(x) OSSwapLittleToHostInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 # define le32toh(x) OSSwapLittleToHostInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 # define le64toh(x) OSSwapLittleToHostInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #endif