libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
wire.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_WIRE_HPP_INCLUDED__
31 #define __ZMQ_WIRE_HPP_INCLUDED__
32 
33 #include "stdint.hpp"
34 
35 namespace zmq
36 {
37 
38  // Helper functions to convert different integer types to/from network
39  // byte order.
40 
41  inline void put_uint8 (unsigned char *buffer_, uint8_t value)
42  {
43  *buffer_ = value;
44  }
45 
46  inline uint8_t get_uint8 (const unsigned char *buffer_)
47  {
48  return *buffer_;
49  }
50 
51  inline void put_uint16 (unsigned char *buffer_, uint16_t value)
52  {
53  buffer_ [0] = (unsigned char) (((value) >> 8) & 0xff);
54  buffer_ [1] = (unsigned char) (value & 0xff);
55  }
56 
57  inline uint16_t get_uint16 (const unsigned char *buffer_)
58  {
59  return
60  (((uint16_t) buffer_ [0]) << 8) |
61  ((uint16_t) buffer_ [1]);
62  }
63 
64  inline void put_uint32 (unsigned char *buffer_, uint32_t value)
65  {
66  buffer_ [0] = (unsigned char) (((value) >> 24) & 0xff);
67  buffer_ [1] = (unsigned char) (((value) >> 16) & 0xff);
68  buffer_ [2] = (unsigned char) (((value) >> 8) & 0xff);
69  buffer_ [3] = (unsigned char) (value & 0xff);
70  }
71 
72  inline uint32_t get_uint32 (const unsigned char *buffer_)
73  {
74  return
75  (((uint32_t) buffer_ [0]) << 24) |
76  (((uint32_t) buffer_ [1]) << 16) |
77  (((uint32_t) buffer_ [2]) << 8) |
78  ((uint32_t) buffer_ [3]);
79  }
80 
81  inline void put_uint64 (unsigned char *buffer_, uint64_t value)
82  {
83  buffer_ [0] = (unsigned char) (((value) >> 56) & 0xff);
84  buffer_ [1] = (unsigned char) (((value) >> 48) & 0xff);
85  buffer_ [2] = (unsigned char) (((value) >> 40) & 0xff);
86  buffer_ [3] = (unsigned char) (((value) >> 32) & 0xff);
87  buffer_ [4] = (unsigned char) (((value) >> 24) & 0xff);
88  buffer_ [5] = (unsigned char) (((value) >> 16) & 0xff);
89  buffer_ [6] = (unsigned char) (((value) >> 8) & 0xff);
90  buffer_ [7] = (unsigned char) (value & 0xff);
91  }
92 
93  inline uint64_t get_uint64 (const unsigned char *buffer_)
94  {
95  return
96  (((uint64_t) buffer_ [0]) << 56) |
97  (((uint64_t) buffer_ [1]) << 48) |
98  (((uint64_t) buffer_ [2]) << 40) |
99  (((uint64_t) buffer_ [3]) << 32) |
100  (((uint64_t) buffer_ [4]) << 24) |
101  (((uint64_t) buffer_ [5]) << 16) |
102  (((uint64_t) buffer_ [6]) << 8) |
103  ((uint64_t) buffer_ [7]);
104  }
105 
106 }
107 
108 #endif
void put_uint8(unsigned char *buffer_, uint8_t value)
Definition: wire.hpp:41
uint16_t get_uint16(const unsigned char *buffer_)
Definition: wire.hpp:57
void put_uint32(unsigned char *buffer_, uint32_t value)
Definition: wire.hpp:64
uint32_t get_uint32(const unsigned char *buffer_)
Definition: wire.hpp:72
uint8_t get_uint8(const unsigned char *buffer_)
Definition: wire.hpp:46
uint64_t get_uint64(const unsigned char *buffer_)
Definition: wire.hpp:93
void put_uint64(unsigned char *buffer_, uint64_t value)
Definition: wire.hpp:81
void put_uint16(unsigned char *buffer_, uint16_t value)
Definition: wire.hpp:51
Definition: address.hpp:35