nalchi
Loading...
Searching...
No Matches
shared_payload.hpp
1#pragma once
2
3#include "nalchi/export.hpp"
4
5#include <atomic>
6#include <cstdint>
7
8struct SteamNetworkingMessage_t;
9
10namespace nalchi
11{
12
20{
21 using ref_count_t = std::atomic<std::int32_t>;
22 using alloc_size_t = std::uint32_t;
23
24 void* ptr;
25
31 NALCHI_API static shared_payload allocate(alloc_size_t size);
32
39 NALCHI_API static void force_deallocate(shared_payload payload);
40
43 NALCHI_API auto size() const -> alloc_size_t;
44
52 NALCHI_API auto word_ceiled_size() const -> alloc_size_t;
53
59 NALCHI_API auto internal_alloc_size() const -> alloc_size_t;
60
67 NALCHI_API bool used_bit_stream() const;
68
69private:
70 friend class bit_stream_writer;
71
73 void set_used_bit_stream(bool);
74
75private:
76 friend class socket_extensions;
77
78 NALCHI_API void add_to_message(SteamNetworkingMessage_t* msg, int logical_bytes_length);
79
80 void increase_ref_count();
81 void decrease_ref_count_and_deallocate_if_zero();
82
83 static void decrease_ref_count_and_deallocate_if_zero_callback(SteamNetworkingMessage_t* msg);
84
85private:
86 auto ref_count() -> ref_count_t&;
87 auto ref_count() const -> const ref_count_t&;
88
89 auto payload_size_and_bit_stream_used_flag() -> alloc_size_t&;
90 auto payload_size_and_bit_stream_used_flag() const -> const alloc_size_t&;
91};
92
93} // namespace nalchi
Helper stream to write bits to your buffer.
Definition bit_stream.hpp:90
Extensions for ISteamNetworkingSockets.
Definition socket_extensions.hpp:21
Shared payload to store data to send.
Definition shared_payload.hpp:20
bool used_bit_stream() const
Check if this payload used bit_stream_writer to fill its content.
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 t...
static shared_payload allocate(alloc_size_t size)
Allocates a shared payload that can be used to send some data.
void * ptr
Pointer to the payload, allocated by nalchi.
Definition shared_payload.hpp:24
auto internal_alloc_size() const -> alloc_size_t
Gets the actual allocated size, which includes hidden ref count & size fields.
static void force_deallocate(shared_payload payload)
Force deallocates the shared payload without sending it.