nalchi
All Classes Files Functions Variables Typedefs Pages Concepts
nalchi::shared_payload Struct Reference

Shared payload to store data to send. More...

#include <nalchi/shared_payload.hpp>

Public Types

using ref_count_t = std::atomic<std::int32_t>
 
using alloc_size_t = std::uint32_t
 

Public Member Functions

auto size () const -> alloc_size_t
 Gets the requested allocation size of the payload.
 
auto word_ceiled_size () const -> alloc_size_t
 Gets the payload size that's ceiled to bit_stream_writer::word_size, which is guaranteed to be safe to access.
 
auto internal_alloc_size () const -> alloc_size_t
 Gets the actual allocated size, which includes hidden ref count & size fields.
 
bool used_bit_stream () const
 Check if this payload used bit_stream_writer to fill its content.
 

Static Public Member Functions

static shared_payload allocate (alloc_size_t size)
 Allocates a shared payload that can be used to send some data.
 
static void force_deallocate (shared_payload payload)
 Force deallocates the shared payload without sending it.
 

Public Attributes

void * ptr
 Pointer to the payload, allocated by nalchi.
 

Friends

class bit_stream_writer
 
class socket_extensions
 

Detailed Description

Shared payload to store data to send.

The payload is "shared" when it is used for multicast.

Note
As ptr has a hidden reference count & alloc size fields on front, you can't just use your own buffer as a ptr;
You need to call allocate() to allocate the shared_payload.

Member Function Documentation

◆ allocate()

static shared_payload nalchi::shared_payload::allocate ( alloc_size_t size)
static

Allocates a shared payload that can be used to send some data.

Note
You should check if ptr is nullptr or not to see if the allocation has been successful.
Parameters
sizeSpace in bytes to allocate.
Returns
Shared payload instance that might hold allocated buffer.

◆ force_deallocate()

static void nalchi::shared_payload::force_deallocate ( shared_payload payload)
static

Force deallocates the shared payload without sending it.

Note
If you send the payload, nalchi takes the ownership of the payload and releases it automatically.
So, you should not call this if you already sent the payload.

Calling this is only necessary when you have some exceptions in your program that prevents sending the allocated payload.
Parameters
payloadShared payload to force deallocate.

◆ internal_alloc_size()

auto nalchi::shared_payload::internal_alloc_size ( ) const -> alloc_size_t

Gets the actual allocated size, which includes hidden ref count & size fields.

This is meant to be only used by the internal API.

Returns
Size of the allocated space in bytes.

◆ size()

auto nalchi::shared_payload::size ( ) const -> alloc_size_t

Gets the requested allocation size of the payload.

Returns
Size of the payload in bytes.

◆ used_bit_stream()

bool nalchi::shared_payload::used_bit_stream ( ) const

Check if this payload used bit_stream_writer to fill its content.

If this is true, the send size will be automatically ceiled to multiple of bit_stream_reader::word_size when you send it.
This is to maintain compatibility with bit_stream_reader on the receiving side.

Returns
Whether the payload used bit_stream_writer or not.

◆ word_ceiled_size()

auto nalchi::shared_payload::word_ceiled_size ( ) const -> alloc_size_t

Gets the payload size that's ceiled to bit_stream_writer::word_size, which is guaranteed to be safe to access.

As this size is ceiled to multiple of bit_stream_writer::word_size, it can be bigger than the requested allocation size.
This is to maintain compatibility with bit_stream_writer.

Returns
Size of the payload in bytes.

The documentation for this struct was generated from the following file: