Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
detail::InputMessageReader Class Reference

#include <PluginIPCUtils.h>

Collaboration diagram for detail::InputMessageReader:
[legend]

Public Member Functions

void ConsumeBytes (const void *bytes, size_t length)
 fills internal buffer More...
 
bool CanPop () const noexcept
 
wxString Pop ()
 

Private Attributes

std::vector< char > mBuffer
 

Detailed Description

Stores consumed bytes into buffer, so that individual messages can be extracted later.

Definition at line 41 of file PluginIPCUtils.h.

Member Function Documentation

◆ CanPop()

bool InputMessageReader::CanPop ( ) const
noexcept
Returns
true if buffer contains at least one complete message

Definition at line 66 of file PluginIPCUtils.cpp.

67{
68 if(mBuffer.size() >= HeaderBlockSize)
69 {
70 auto expectedSize = *reinterpret_cast<const HeaderBlock*>(mBuffer.data());
71 return mBuffer.size() >= expectedSize + HeaderBlockSize;
72 }
73 return false;
74}
std::vector< char > mBuffer

References anonymous_namespace{PluginIPCUtils.cpp}::HeaderBlockSize, and mBuffer.

◆ ConsumeBytes()

void InputMessageReader::ConsumeBytes ( const void *  bytes,
size_t  length 
)

fills internal buffer

Definition at line 59 of file PluginIPCUtils.cpp.

60{
61 auto from = mBuffer.size();
62 mBuffer.resize(from + length);
63 std::memcpy(&mBuffer[from], bytes, length);
64}

References mBuffer.

◆ Pop()

wxString InputMessageReader::Pop ( )

extracts message from the buffer, use CanPop() to check if message is present first

Definition at line 76 of file PluginIPCUtils.cpp.

77{
78 wxString message;
79 const auto length = *reinterpret_cast<const HeaderBlock*>(mBuffer.data());
80 assert(mBuffer.size() >= length + HeaderBlockSize);
81 if(length > 0)
82 message = wxString::FromUTF8(mBuffer.data() + HeaderBlockSize, length);
83 mBuffer.erase(mBuffer.begin(), mBuffer.begin() + HeaderBlockSize + length);
84 return message;
85}

References anonymous_namespace{PluginIPCUtils.cpp}::HeaderBlockSize, and mBuffer.

Member Data Documentation

◆ mBuffer

std::vector<char> detail::InputMessageReader::mBuffer
private

Definition at line 43 of file PluginIPCUtils.h.

Referenced by CanPop(), ConsumeBytes(), and Pop().


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