5 #include "support/Flattenable.h"
6 #include "util/String.h"
28 ZGPeerID(uint64 highBits, uint64 lowBits) : _highBits(highBits), _lowBits(lowBits) {}
33 bool operator == (
const ZGPeerID & rhs)
const {
return ((_highBits == rhs._highBits)&&(_lowBits == rhs._lowBits));}
43 bool operator < (
const ZGPeerID & rhs)
const {
return ((_highBits < rhs._highBits)||((_highBits == rhs._highBits)&&(_lowBits < rhs._lowBits)));}
53 bool operator > (
const ZGPeerID & rhs)
const {
return ((_highBits > rhs._highBits)||((_highBits == rhs._highBits)&&(_lowBits > rhs._lowBits)));}
66 bool IsValid()
const {
return ((_highBits != 0)||(_lowBits != 0));}
73 _highBits = _lowBits = 0;
75 const char * colon = strchr(s(),
':');
78 _highBits = Atoxll(s());
79 _lowBits = Atoxll(colon+1);
87 muscleSprintf(buf, XINT64_FORMAT_SPEC
":" XINT64_FORMAT_SPEC, _highBits, _lowBits);
104 uint32
CalculateChecksum()
const {
return CalculateChecksumForUint64(_highBits) + (3*CalculateChecksumForUint64(_lowBits));}
111 muscleCopyOut(&buffer[0*
sizeof(uint64)], B_HOST_TO_LENDIAN_INT64(_highBits));
112 muscleCopyOut(&buffer[1*
sizeof(uint64)], B_HOST_TO_LENDIAN_INT64(_lowBits));
124 _highBits = B_LENDIAN_TO_HOST_INT64(muscleCopyIn<uint64>(&buffer[0*
sizeof(int64)]));
125 _lowBits = B_LENDIAN_TO_HOST_INT64(muscleCopyIn<uint64>(&buffer[1*
sizeof(int64)]));
ZGPeerID()
Default constructor – sets the ZGPeerID to its invalid state (all zeroes)
ZGPeerID & operator=(const ZGPeerID &rhs)
Assignment operator.
static MUSCLE_CONSTEXPR uint32 TypeCode()
Part of the Flattenable pseudo-interface: Returns ZG_PEER_ID_TYPE.
bool operator>=(const ZGPeerID &rhs) const
Comparison operator; returns true iff this ZGPeerID is greater than or equal to (rhs) ...
bool operator>(const ZGPeerID &rhs) const
Comparison operator; returns true iff this ZGPeerID is greater than (rhs)
void Flatten(uint8 *buffer) const
Copies this point into an endian-neutral flattened buffer.
static MUSCLE_CONSTEXPR bool IsFixedSize()
Part of the Flattenable pseudo-interface: Returns true.
String ToString() const
Returns a String representation of this peer ID (e.g.
uint32 HashCode() const
This is implemented so that if ZGPeerID is used as the key in a Hashtable, the HashCode() method will...
The zg namespace contains the public API of the ZG library.
bool operator==(const ZGPeerID &rhs) const
Equality operator; returns true iff this ZGPeerID is equal to (rhs)
bool operator<(const ZGPeerID &rhs) const
Comparison operator; returns true iff this ZGPeerID is less than (rhs)
bool IsValid() const
Returns true iff the ZGPeerID has any non-zero bits in it.
bool operator!=(const ZGPeerID &rhs) const
Inequality operator; returns true iff this ZGPeerID is not equal to (rhs)
static MUSCLE_CONSTEXPR bool AllowsTypeCode(uint32 tc)
Returns true iff (tc) equals ZG_PEER_ID_TYPE.
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
bool operator<=(const ZGPeerID &rhs) const
Comparison operator; returns true iff this ZGPeerID is less than or equal to (rhs) ...
ZGPeerID(uint64 highBits, uint64 lowBits)
Explicit constructor.
static MUSCLE_CONSTEXPR uint32 FlattenedSize()
Part of the Flattenable pseudo-interface: 2*sizeof(uint64)
void FromString(const String &s)
Sets this peer ID from the specified String representation (in the format used by ToString())...
status_t Unflatten(const uint8 *buffer, uint32 size)
Restores this point from an endian-neutral flattened buffer.
uint32 CalculateChecksum() const
Returns a 32-bit checksum for this object.