Cogs.Foundation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Cogs::Network::Message Class Referencefinal

#include <Message.h>

Inheritance diagram for Cogs::Network::Message:
Cogs::Memory::MemoryBuffer

Public Types

using Ptr = std::shared_ptr< Message >
 
- Public Types inherited from Cogs::Memory::MemoryBuffer
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
 
- Public Member Functions inherited from Cogs::Memory::MemoryBuffer
 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
 
MemoryBufferoperator= (MemoryBuffer &&other) noexcept
 
 MemoryBuffer (const MemoryBuffer &)=delete
 
MemoryBufferoperator= (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 AllocatorgetAllocator () 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
 
Messageoperator= (const Message &)=delete
 
Messageoperator= (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
 

Member Typedef Documentation

◆ Pool

using Cogs::Network::Message::Pool = std::vector<Message*>
private

◆ Ptr

using Cogs::Network::Message::Ptr = std::shared_ptr<Message>

Constructor & Destructor Documentation

◆ Message() [1/4]

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().

◆ Message() [2/4]

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.

◆ Message() [3/4]

Cogs::Network::Message::Message ( const Message src)
delete

◆ Message() [4/4]

Cogs::Network::Message::Message ( Message &&  )
privatedelete

Member Function Documentation

◆ allocate()

Cogs::Network::Message::Ptr Cogs::Network::Message::allocate ( uint32_t  id)
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().

◆ deleteMessage()

void Cogs::Network::Message::deleteMessage ( Message message)
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().

◆ duplicate()

Cogs::Network::Message::Ptr Cogs::Network::Message::duplicate ( const Message src)
static

Duplicates the provided message.

*============================================================================================

References Cogs::Memory::MemoryBuffer::data(), getID(), and Cogs::Memory::MemoryBuffer::size().

◆ flush()

void Cogs::Network::Message::flush ( )
static

Flushes any messages pooled for reuse.

Typically called during application shutdown. *============================================================================================

◆ getID()

uint32_t Cogs::Network::Message::getID ( ) const
inline

Referenced by duplicate().

◆ operator=() [1/2]

Message & Cogs::Network::Message::operator= ( const Message )
privatedelete

◆ operator=() [2/2]

Message & Cogs::Network::Message::operator= ( Message &&  )
privatedelete

Friends And Related Function Documentation

◆ MessageHub

friend class MessageHub
friend

Member Data Documentation

◆ identifier

uint32_t Cogs::Network::Message::identifier = 0
private

Referenced by allocate(), and Message().

◆ messagePool

Cogs::Network::Message::Pool Cogs::Network::Message::messagePool
staticprivate

Referenced by allocate().

◆ mutex

Cogs::Mutex Cogs::Network::Message::mutex
staticprivate

Referenced by allocate().


The documentation for this class was generated from the following files: