mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[9551] Add and use PackedGuid wrapper.
Also * use more wide bytebuff << >> operators for objects * use at read packet faisl alsways exception way instead some time used bool results.
This commit is contained in:
parent
ad9243ebd0
commit
c8fd454a79
26 changed files with 351 additions and 340 deletions
|
|
@ -20,8 +20,7 @@
|
|||
#define MANGOS_OBJECT_GUID_H
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
class ByteBuffer;
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
enum TypeID
|
||||
{
|
||||
|
|
@ -114,6 +113,14 @@ inline bool IsGuidHaveEnPart(uint64 const& guid)
|
|||
#define GUID_LOPART(x) (IsGuidHaveEnPart(x) ? _GUID_LOPART_3(x) : _GUID_LOPART_2(x))
|
||||
|
||||
//*** Must be replaced by ObjectGuid use END ***
|
||||
class ObjectGuid;
|
||||
class PackedGuid;
|
||||
|
||||
struct PackedGuidReader
|
||||
{
|
||||
explicit PackedGuidReader(ObjectGuid& guid) : m_guidRef(guid) {}
|
||||
ObjectGuid& m_guidRef;
|
||||
};
|
||||
|
||||
class ObjectGuid
|
||||
{
|
||||
|
|
@ -123,6 +130,8 @@ class ObjectGuid
|
|||
ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) : m_guid(uint64(counter) | (uint64(entry) << 24) | (uint64(hi) << 48)) {}
|
||||
|
||||
public: // modifiers
|
||||
PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); }
|
||||
|
||||
void Set(uint64 const& guid) { m_guid = guid; }
|
||||
|
||||
// Possible removed in future for more strict control type conversions
|
||||
|
|
@ -170,6 +179,8 @@ class ObjectGuid
|
|||
default: return TYPEID_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
PackedGuid WriteAsPacked() const;
|
||||
public: // accessors - for debug
|
||||
char const* GetTypeName() const;
|
||||
std::string GetString() const;
|
||||
|
|
@ -198,7 +209,32 @@ class ObjectGuid
|
|||
uint64 m_guid;
|
||||
};
|
||||
|
||||
class PackedGuid
|
||||
{
|
||||
friend ByteBuffer& operator<< (ByteBuffer& buf, PackedGuid const& guid);
|
||||
|
||||
public: // constructors
|
||||
explicit PackedGuid() { m_packedGuid.appendPackGUID(0); }
|
||||
explicit PackedGuid(uint64 const& guid) { m_packedGuid.appendPackGUID(guid); }
|
||||
explicit PackedGuid(ObjectGuid const& guid) { m_packedGuid.appendPackGUID(guid.GetRawValue()); }
|
||||
|
||||
public: // modifiers
|
||||
void Set(uint64 const& guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid); }
|
||||
void Set(ObjectGuid const& guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid.GetRawValue()); }
|
||||
|
||||
public: // accessors
|
||||
size_t size() const { return m_packedGuid.size(); }
|
||||
|
||||
private: // fields
|
||||
ByteBuffer m_packedGuid;
|
||||
};
|
||||
|
||||
ByteBuffer& operator<< (ByteBuffer& buf, ObjectGuid const& guid);
|
||||
ByteBuffer& operator>> (ByteBuffer& buf, ObjectGuid& guid);
|
||||
|
||||
ByteBuffer& operator<< (ByteBuffer& buf, PackedGuid const& guid);
|
||||
ByteBuffer& operator>> (ByteBuffer& buf, PackedGuidReader& guid);
|
||||
|
||||
inline PackedGuid ObjectGuid::WriteAsPacked() const { return PackedGuid(*this); }
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue