Cogs.Foundation
|
#include <Message.h>
Public Types | |
using | Ptr = std::shared_ptr< Message > |
![]() | |
enum class | Anchor { Start , Current , End } |
Public Member Functions | |
Message () | |
Constructs a new Message instance. | |
Message (uint32_t id, const Message &message) | |
Constructs a Message instance that borrows the MemoryBuffer owned by the message passed to this function. | |
Message (const Message &src)=delete | |
uint32_t | getID () const |
![]() | |
MemoryBuffer ()=default | |
MemoryBuffer (MemBlockType type) | |
MemoryBuffer (size_t size, MemBlockType type) | |
MemoryBuffer (size_t size, bool onlyReserve=false, MemBlockType type=MemBlockType::Block) | |
MemoryBuffer (Allocator *allocator, MemBlockType type=MemBlockType::Block) | |
MemoryBuffer (size_t size, Allocator *allocator, MemBlockType type=MemBlockType::Block) | |
MemoryBuffer (const void *memory, size_t size) | |
MemoryBuffer (MemoryBuffer &&other) noexcept | |
MemoryBuffer & | operator= (MemoryBuffer &&other) noexcept |
MemoryBuffer (const MemoryBuffer &)=delete | |
MemoryBuffer & | operator= (const MemoryBuffer &)=delete |
~MemoryBuffer () | |
void | changeType (MemBlockType newType) |
void | reset (size_t size, Allocator *allocator) |
bool | resize (size_t size, bool keep=true, bool forceRealloc=false) |
bool | reserve (size_t size) |
void | copy (const MemoryBuffer &other) |
void | clear () |
void * | data () |
const void * | data () const |
void * | dataFromPos () |
const void * | dataFromPos () const |
size_t | size () const |
bool | empty () const |
void * | grow (size_t bytes) |
void | swap (MemoryBuffer &other) |
const Allocator * | getAllocator () const |
size_t | read (void *buffer, size_t noofbytes) |
uint8_t | read8 () |
uint16_t | read16 () |
uint32_t | read32 () |
uint64_t | read64 () |
float | readFloat () |
double | readDouble () |
glm::vec2 | readFloat2 () |
glm::vec3 | readFloat3 () |
glm::vec4 | readFloat4 () |
glm::quat | readQuaternion () |
glm::mat4 | readMatrix () |
std::string | readString () |
bool | write (const void *buffer, size_t noofbytes) |
bool | write8 (uint8_t value) |
bool | write16 (uint16_t value) |
bool | write32 (uint32_t value) |
bool | write64 (uint64_t value) |
bool | writeFloat (float value) |
bool | writeDouble (double value) |
bool | writeFloat2 (const glm::vec2 &value) |
bool | writeFloat3 (const glm::vec3 &value) |
bool | writeFloat4 (const glm::vec4 &value) |
bool | writeQuaternion (const glm::quat &value) |
bool | writeMatrix (const glm::mat4 &value) |
bool | writeString (const StringView &str) |
void | seek (int64_t offset, Anchor from) |
size_t | pos () const |
size_t | unreadSize () const |
bool | areContentsEqual (const MemoryBuffer &rhs) const |
Static Public Member Functions | |
static Ptr | allocate (uint32_t id) |
Retrieves an existing message from the pool, or creates a new one if the pool is empty. | |
static Ptr | duplicate (const Message &src) |
Duplicates the provided message. | |
static void | flush () |
Flushes any messages pooled for reuse. | |
Private Types | |
using | Pool = std::vector< Message * > |
Private Member Functions | |
Message (Message &&)=delete | |
Message & | operator= (const Message &)=delete |
Message & | operator= (Message &&)=delete |
Static Private Member Functions | |
static void | deleteMessage (Message *msg) |
Deleter function called by shared_ptr when the last reference to message is destroyed. | |
Private Attributes | |
uint32_t | identifier = 0 |
Static Private Attributes | |
static Pool | messagePool |
static Mutex | mutex |
Friends | |
class | MessageHub |
|
private |
using Cogs::Network::Message::Ptr = std::shared_ptr<Message> |
Cogs::Network::Message::Message | ( | ) |
Constructs a new Message instance.
Called by allocate when no messages are available in the pool. The new message will have 1KB of payload memory reserved automatically. *============================================================================================
Referenced by allocate().
Cogs::Network::Message::Message | ( | uint32_t | id, |
const Message & | message | ||
) |
Constructs a Message instance that borrows the MemoryBuffer owned by the message passed to this function.
This overload is used when processing messages to provide a hub-independent view into the message payload. *============================================================================================
References identifier.
|
delete |
|
privatedelete |
|
static |
Retrieves an existing message from the pool, or creates a new one if the pool is empty.
*============================================================================================
References deleteMessage(), identifier, Message(), messagePool, and mutex.
Referenced by Cogs::Network::ConnectionHub::processIncoming().
|
staticprivate |
Deleter function called by shared_ptr when the last reference to message is destroyed.
This function returns the message object to the pool for reuse. The message destructor will not be called to ensure memory allocated for message payloads is retained and reused. *============================================================================================
References Cogs::Memory::MemoryBuffer::resize().
Referenced by allocate().
|
static |
Duplicates the provided message.
*============================================================================================
References Cogs::Memory::MemoryBuffer::data(), getID(), and Cogs::Memory::MemoryBuffer::size().
|
static |
Flushes any messages pooled for reuse.
Typically called during application shutdown. *============================================================================================
|
inline |
Referenced by duplicate().
|
friend |
|
private |
Referenced by allocate(), and Message().
|
staticprivate |
Referenced by allocate().
|
staticprivate |
Referenced by allocate().