libzmq master
The Intelligent Transport Layer

wire.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007-2009 iMatix Corporation
00003     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00004 
00005     This file is part of 0MQ.
00006 
00007     0MQ is free software; you can redistribute it and/or modify it under
00008     the terms of the GNU Lesser General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     0MQ is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef __ZMQ_WIRE_HPP_INCLUDED__
00022 #define __ZMQ_WIRE_HPP_INCLUDED__
00023 
00024 #include "stdint.hpp"
00025 
00026 namespace zmq
00027 {
00028 
00029     //  Helper functions to convert different integer types to/from network
00030     //  byte order.
00031 
00032     inline void put_uint8 (unsigned char *buffer_, uint8_t value)
00033     {
00034         *buffer_ = value;
00035     }
00036 
00037     inline uint8_t get_uint8 (unsigned char *buffer_)
00038     {
00039         return *buffer_;
00040     }
00041 
00042     inline void put_uint16 (unsigned char *buffer_, uint16_t value)
00043     {
00044         buffer_ [0] = (unsigned char) (((value) >> 8) & 0xff);
00045         buffer_ [1] = (unsigned char) (value & 0xff);
00046     }
00047 
00048     inline uint16_t get_uint16 (unsigned char *buffer_)
00049     {
00050         return
00051             (((uint16_t) buffer_ [0]) << 8) |
00052             ((uint16_t) buffer_ [1]);
00053     }
00054 
00055     inline void put_uint32 (unsigned char *buffer_, uint32_t value)
00056     {
00057         buffer_ [0] = (unsigned char) (((value) >> 24) & 0xff);
00058         buffer_ [1] = (unsigned char) (((value) >> 16) & 0xff);
00059         buffer_ [2] = (unsigned char) (((value) >> 8) & 0xff);
00060         buffer_ [3] = (unsigned char) (value & 0xff);
00061     }
00062 
00063     inline uint32_t get_uint32 (unsigned char *buffer_)
00064     {
00065         return
00066             (((uint32_t) buffer_ [0]) << 24) |
00067             (((uint32_t) buffer_ [1]) << 16) |
00068             (((uint32_t) buffer_ [2]) << 8) |
00069             ((uint32_t) buffer_ [3]);
00070     }
00071 
00072     inline void put_uint64 (unsigned char *buffer_, uint64_t value)
00073     {
00074         buffer_ [0] = (unsigned char) (((value) >> 56) & 0xff);
00075         buffer_ [1] = (unsigned char) (((value) >> 48) & 0xff);
00076         buffer_ [2] = (unsigned char) (((value) >> 40) & 0xff);
00077         buffer_ [3] = (unsigned char) (((value) >> 32) & 0xff);
00078         buffer_ [4] = (unsigned char) (((value) >> 24) & 0xff);
00079         buffer_ [5] = (unsigned char) (((value) >> 16) & 0xff);
00080         buffer_ [6] = (unsigned char) (((value) >> 8) & 0xff);
00081         buffer_ [7] = (unsigned char) (value & 0xff);
00082     }
00083 
00084     inline uint64_t get_uint64 (unsigned char *buffer_)
00085     {
00086         return
00087             (((uint64_t) buffer_ [0]) << 56) |
00088             (((uint64_t) buffer_ [1]) << 48) |
00089             (((uint64_t) buffer_ [2]) << 40) |
00090             (((uint64_t) buffer_ [3]) << 32) |
00091             (((uint64_t) buffer_ [4]) << 24) |
00092             (((uint64_t) buffer_ [5]) << 16) |
00093             (((uint64_t) buffer_ [6]) << 8) |
00094             ((uint64_t) buffer_ [7]);
00095     }
00096 
00097 }
00098 
00099 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines