various trics and changes so that windows compilers, and 32bit systems will not complain about stuff
This commit is contained in:
parent
4e09e54849
commit
ad3b95741e
|
|
@ -110,7 +110,7 @@ public:
|
|||
if (index > 7) return false;
|
||||
|
||||
// magic bit manipulation...
|
||||
return (bool)((1 << index) & _byte);
|
||||
return 0 != ((1 << index) & _byte);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public:
|
|||
* @param size size of the buffer to decode
|
||||
* @return number of bytes that were processed
|
||||
*/
|
||||
size_t parse(const char *buffer, size_t size)
|
||||
uint64_t parse(const char *buffer, size_t size)
|
||||
{
|
||||
return _implementation.parse(ByteBuffer(buffer, size));
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
* @param buffer buffer to decode
|
||||
* @return number of bytes that were processed
|
||||
*/
|
||||
size_t parse(const Buffer &buffer)
|
||||
uint64_t parse(const Buffer &buffer)
|
||||
{
|
||||
return _implementation.parse(buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ public:
|
|||
* @param buffer buffer to decode
|
||||
* @return number of bytes that were processed
|
||||
*/
|
||||
size_t parse(const Buffer &buffer);
|
||||
uint64_t parse(const Buffer &buffer);
|
||||
|
||||
/**
|
||||
* Close the connection
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public:
|
|||
*/
|
||||
operator float() const
|
||||
{
|
||||
return _number / pow(10, _places);
|
||||
return static_cast<float>(_number / pow(10, _places));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,6 +5,18 @@
|
|||
* and big endian byte orders. This header file adds the missing macros
|
||||
*
|
||||
* @author madmongo1 <https://github.com/madmongo1>
|
||||
*
|
||||
* And we have also copied code from the "portable_endian.h" file by
|
||||
* Mathias Panzenböck. His license:
|
||||
*
|
||||
* "License": Public Domain
|
||||
* I, Mathias Panzenböck, place this file hereby into the public
|
||||
* domain. Use it at your own risk for whatever you like. In case
|
||||
* there are jurisdictions that don't support putting things in the
|
||||
* public domain you can also consider it to be "dual licensed"
|
||||
* under the BSD, MIT and Apache licenses, if you want to. This
|
||||
* code is trivial anyway. Consider it an example on how to get the
|
||||
* endian conversion functions on different platforms.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -39,10 +51,87 @@
|
|||
#define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
#define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||
|
||||
// not on apple
|
||||
/**
|
||||
* And on Windows systems weird things are going on as well
|
||||
*/
|
||||
#elif (defined(_WIN16) || defined(_WIN32) || defined(_WIN64) || defined(__WINDOWS__)) && !defined(__CYGWIN__)
|
||||
|
||||
#include <winsock2.h>
|
||||
#pragma comment(lib,"Ws2_32.lib")
|
||||
//# include <sys/param.h>
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
|
||||
#define htobe16(x) htons(x)
|
||||
#define htole16(x) (x)
|
||||
#define be16toh(x) ntohs(x)
|
||||
#define le16toh(x) (x)
|
||||
|
||||
#define htobe32(x) htonl(x)
|
||||
#define htole32(x) (x)
|
||||
#define be32toh(x) ntohl(x)
|
||||
#define le32toh(x) (x)
|
||||
|
||||
#define htobe64(x) htonll(x)
|
||||
#define htole64(x) (x)
|
||||
#define be64toh(x) ntohll(x)
|
||||
#define le64toh(x) (x)
|
||||
|
||||
#elif BYTE_ORDER == BIG_ENDIAN
|
||||
|
||||
/* that would be xbox 360 */
|
||||
#define htobe16(x) (x)
|
||||
#define htole16(x) __builtin_bswap16(x)
|
||||
#define be16toh(x) (x)
|
||||
#define le16toh(x) __builtin_bswap16(x)
|
||||
|
||||
#define htobe32(x) (x)
|
||||
#define htole32(x) __builtin_bswap32(x)
|
||||
#define be32toh(x) (x)
|
||||
#define le32toh(x) __builtin_bswap32(x)
|
||||
|
||||
#define htobe64(x) (x)
|
||||
#define htole64(x) __builtin_bswap64(x)
|
||||
#define be64toh(x) (x)
|
||||
#define le64toh(x) __builtin_bswap64(x)
|
||||
|
||||
#else
|
||||
|
||||
// non-apple systems have their own endian header file
|
||||
#error byte order not supported
|
||||
|
||||
#endif
|
||||
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
/**
|
||||
* OpenBSD handling
|
||||
*/
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
/**
|
||||
* NetBSD handling
|
||||
*/
|
||||
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
||||
#include <sys/endian.h>
|
||||
#define be16toh(x) betoh16(x)
|
||||
#define le16toh(x) letoh16(x)
|
||||
#define be32toh(x) betoh32(x)
|
||||
#define le32toh(x) letoh32(x)
|
||||
#define be64toh(x) betoh64(x)
|
||||
#define le64toh(x) letoh64(x)
|
||||
|
||||
/**
|
||||
* Not on apple, and not on windows
|
||||
*/
|
||||
#else
|
||||
|
||||
// this is the normal linux way of doing things
|
||||
#include <endian.h>
|
||||
|
||||
// end of "#if defined(__APPLE__)"
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public:
|
|||
*/
|
||||
std::string message() const
|
||||
{
|
||||
return std::string(_body, _bodySize);
|
||||
return std::string(_body, static_cast<size_t>(_bodySize));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -47,26 +47,28 @@ public:
|
|||
*/
|
||||
NumericField(ReceivedFrame &frame)
|
||||
{
|
||||
// copy the data from the buffer into the field
|
||||
if (!std::is_floating_point<T>::value)
|
||||
{
|
||||
// convert value based on internal storage size
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 1: _value = frame.nextUint8(); break;
|
||||
case 2: _value = frame.nextUint16(); break;
|
||||
case 4: _value = frame.nextUint32(); break;
|
||||
case 8: _value = frame.nextUint64(); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 4: _value = frame.nextFloat(); break;
|
||||
case 8: _value = frame.nextDouble(); break;
|
||||
}
|
||||
}
|
||||
// The Microsoft Visual Studio compiler thinks that there is an issue
|
||||
// with the following code, so we temporarily disable a specific warning
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
if (std::is_same<int8_t, typename std::remove_cv<T>::type>::value) _value = frame.nextInt8();
|
||||
else if (std::is_same<int16_t, typename std::remove_cv<T>::type>::value) _value = frame.nextInt16();
|
||||
else if (std::is_same<int32_t, typename std::remove_cv<T>::type>::value) _value = frame.nextInt32();
|
||||
else if (std::is_same<int64_t, typename std::remove_cv<T>::type>::value) _value = frame.nextInt64();
|
||||
else if (std::is_same<uint8_t, typename std::remove_cv<T>::type>::value) _value = frame.nextUint8();
|
||||
else if (std::is_same<uint16_t, typename std::remove_cv<T>::type>::value) _value = frame.nextUint16();
|
||||
else if (std::is_same<uint32_t, typename std::remove_cv<T>::type>::value) _value = frame.nextUint32();
|
||||
else if (std::is_same<uint64_t, typename std::remove_cv<T>::type>::value) _value = frame.nextUint64();
|
||||
else if (std::is_same<float, typename std::remove_cv<T>::type>::value) _value = frame.nextFloat();
|
||||
else if (std::is_same<double, typename std::remove_cv<T>::type>::value) _value = frame.nextDouble();
|
||||
|
||||
// re-enable the warning
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,15 +128,6 @@ public:
|
|||
return sizeof(_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum allowed value for this field
|
||||
* @return mixed
|
||||
*/
|
||||
constexpr static T max()
|
||||
{
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write encoded payload to the given buffer.
|
||||
* @param buffer OutBuffer to write to
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ Deferred &ChannelImpl::declareExchange(const std::string &name, ExchangeType typ
|
|||
if (type == ExchangeType::headers)exchangeType = "headers";
|
||||
|
||||
// send declare exchange frame
|
||||
return push(ExchangeDeclareFrame(_id, name, exchangeType, flags & passive, flags & durable, false, arguments));
|
||||
return push(ExchangeDeclareFrame(_id, name, exchangeType, (flags & passive) != 0, (flags & durable) != 0, false, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -274,7 +274,7 @@ Deferred &ChannelImpl::unbindExchange(const std::string &source, const std::stri
|
|||
Deferred &ChannelImpl::removeExchange(const std::string &name, int flags)
|
||||
{
|
||||
// send delete exchange frame
|
||||
return push(ExchangeDeleteFrame(_id, name, flags & ifunused, false));
|
||||
return push(ExchangeDeleteFrame(_id, name, (flags & ifunused) != 0, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -289,7 +289,7 @@ Deferred &ChannelImpl::removeExchange(const std::string &name, int flags)
|
|||
DeferredQueue &ChannelImpl::declareQueue(const std::string &name, int flags, const Table &arguments)
|
||||
{
|
||||
// the frame to send
|
||||
QueueDeclareFrame frame(_id, name, flags & passive, flags & durable, flags & exclusive, flags & autodelete, false, arguments);
|
||||
QueueDeclareFrame frame(_id, name, (flags & passive) != 0, (flags & durable) != 0, (flags & exclusive) != 0, (flags & autodelete) != 0, false, arguments);
|
||||
|
||||
// send the queuedeclareframe
|
||||
auto result = std::make_shared<DeferredQueue>(!send(frame));
|
||||
|
|
@ -388,7 +388,7 @@ DeferredDelete &ChannelImpl::purgeQueue(const std::string &name)
|
|||
DeferredDelete &ChannelImpl::removeQueue(const std::string &name, int flags)
|
||||
{
|
||||
// the frame to send
|
||||
QueueDeleteFrame frame(_id, name, flags & ifunused, flags & ifempty, false);
|
||||
QueueDeleteFrame frame(_id, name, (flags & ifunused) != 0, (flags & ifempty) != 0, false);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto deferred = std::make_shared<DeferredDelete>(!send(frame));
|
||||
|
|
@ -431,17 +431,17 @@ bool ChannelImpl::publish(const std::string &exchange, const std::string &routin
|
|||
|
||||
// the max payload size is the max frame size minus the bytes for headers and trailer
|
||||
uint32_t maxpayload = _connection->maxPayload();
|
||||
uint32_t bytessent = 0;
|
||||
uint64_t bytessent = 0;
|
||||
|
||||
// the buffer
|
||||
const char *data = envelope.body();
|
||||
uint32_t bytesleft = envelope.bodySize();
|
||||
uint64_t bytesleft = envelope.bodySize();
|
||||
|
||||
// split up the body in multiple frames depending on the max frame size
|
||||
while (bytesleft > 0)
|
||||
{
|
||||
// size of this chunk
|
||||
uint32_t chunksize = std::min(maxpayload, bytesleft);
|
||||
uint64_t chunksize = std::min(static_cast<uint64_t>(maxpayload), bytesleft);
|
||||
|
||||
// send out a body frame
|
||||
if (!send(BodyFrame(_id, data + bytessent, chunksize))) return false;
|
||||
|
|
@ -497,7 +497,7 @@ Deferred &ChannelImpl::setQos(uint16_t prefetchCount, bool global)
|
|||
DeferredConsumer& ChannelImpl::consume(const std::string &queue, const std::string &tag, int flags, const Table &arguments)
|
||||
{
|
||||
// the frame to send
|
||||
BasicConsumeFrame frame(_id, queue, tag, flags & nolocal, flags & noack, flags & exclusive, false, arguments);
|
||||
BasicConsumeFrame frame(_id, queue, tag, (flags & nolocal) != 0, (flags & noack) != 0, (flags & exclusive) != 0, false, arguments);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto deferred = std::make_shared<DeferredConsumer>(this, !send(frame));
|
||||
|
|
@ -576,7 +576,7 @@ DeferredCancel &ChannelImpl::cancel(const std::string &tag)
|
|||
DeferredGet &ChannelImpl::get(const std::string &queue, int flags)
|
||||
{
|
||||
// the get frame to send
|
||||
BasicGetFrame frame(_id, queue, flags & noack);
|
||||
BasicGetFrame frame(_id, queue, (flags & noack) != 0);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto deferred = std::make_shared<DeferredGet>(this, !send(frame));
|
||||
|
|
@ -597,7 +597,7 @@ DeferredGet &ChannelImpl::get(const std::string &queue, int flags)
|
|||
bool ChannelImpl::ack(uint64_t deliveryTag, int flags)
|
||||
{
|
||||
// send an ack frame
|
||||
return send(BasicAckFrame(_id, deliveryTag, flags & multiple));
|
||||
return send(BasicAckFrame(_id, deliveryTag, (flags & multiple) != 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -612,12 +612,12 @@ bool ChannelImpl::reject(uint64_t deliveryTag, int flags)
|
|||
if (flags & multiple)
|
||||
{
|
||||
// send a nack frame
|
||||
return send(BasicNackFrame(_id, deliveryTag, true, flags & requeue));
|
||||
return send(BasicNackFrame(_id, deliveryTag, true, (flags & requeue) != 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// send a reject frame
|
||||
return send(BasicRejectFrame(_id, deliveryTag, flags & requeue));
|
||||
return send(BasicRejectFrame(_id, deliveryTag, (flags & requeue) != 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -631,7 +631,7 @@ bool ChannelImpl::reject(uint64_t deliveryTag, int flags)
|
|||
Deferred &ChannelImpl::recover(int flags)
|
||||
{
|
||||
// send a nack frame
|
||||
return push(BasicRecoverFrame(_id, flags & requeue));
|
||||
return push(BasicRecoverFrame(_id, (flags & requeue) != 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -104,13 +104,13 @@ void ConnectionImpl::remove(const ChannelImpl *channel)
|
|||
* @param buffer buffer to decode
|
||||
* @return number of bytes that were processed
|
||||
*/
|
||||
size_t ConnectionImpl::parse(const Buffer &buffer)
|
||||
uint64_t ConnectionImpl::parse(const Buffer &buffer)
|
||||
{
|
||||
// do not parse if already in an error state
|
||||
if (_state == state_closed) return 0;
|
||||
|
||||
// number of bytes processed
|
||||
size_t processed = 0;
|
||||
uint64_t processed = 0;
|
||||
|
||||
// create a monitor object that checks if the connection still exists
|
||||
Monitor monitor(this);
|
||||
|
|
@ -130,7 +130,7 @@ size_t ConnectionImpl::parse(const Buffer &buffer)
|
|||
receivedFrame.process(this);
|
||||
|
||||
// number of bytes processed
|
||||
size_t bytes = receivedFrame.totalSize();
|
||||
uint64_t bytes = receivedFrame.totalSize();
|
||||
|
||||
// add bytes
|
||||
processed += bytes;
|
||||
|
|
|
|||
|
|
@ -81,15 +81,21 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
// we're going to allocated memory, but that should be a size_t, not a uint64_t
|
||||
size_t memory = static_cast<size_t>(_bodySize);
|
||||
|
||||
// prevent truncation
|
||||
if (memory < _bodySize) throw std::runtime_error("message is too big for this system");
|
||||
|
||||
// it does not yet fit, do we have to allocate?
|
||||
if (!_body) _body = new char[_bodySize];
|
||||
if (!_body) _body = new char[memory];
|
||||
_selfAllocated = true;
|
||||
|
||||
// prevent that size is too big
|
||||
if (size > _bodySize - _received) size = _bodySize - _received;
|
||||
|
||||
// append data
|
||||
memcpy((char *)(_body + _received), buffer, size);
|
||||
memcpy(static_cast<void*>(const_cast<char*>(_body) + _received), buffer, static_cast<size_t>(size));
|
||||
|
||||
// we have more data now
|
||||
_received += size;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,9 @@ ReceivedFrame::ReceivedFrame(const Buffer &buffer, uint32_t max) : _buffer(buffe
|
|||
else
|
||||
{
|
||||
// frame is not yet valid
|
||||
_type = _channel = _payloadSize = 0;
|
||||
_type = 0;
|
||||
_channel = 0;
|
||||
_payloadSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue