Add ability to send strings over network.

This commit is contained in:
Bartosz Taudul 2017-09-14 19:24:35 +02:00
parent f3ce055568
commit f61f50385d
3 changed files with 24 additions and 0 deletions

View File

@ -145,4 +145,25 @@ bool Profiler::SendData( const char* data, size_t len )
return true;
}
bool Profiler::SendString( uint64_t str )
{
auto ptr = (const char*)str;
QueueHeader hdr;
hdr.type = QueueType::StringData;
hdr.id = str;
char buf[TargetFrameSize];
memcpy( buf, &hdr, sizeof( hdr ) );
auto len = strlen( ptr );
assert( len < TargetFrameSize - sizeof( hdr ) - sizeof( uint16_t ) );
assert( len <= std::numeric_limits<uint16_t>::max() );
uint16_t l16 = len;
memcpy( buf + sizeof( hdr ), &l16, sizeof( l16 ) );
memcpy( buf + sizeof( hdr ) + sizeof( l16 ), ptr, l16 );
return SendData( buf, sizeof( hdr ) + sizeof( l16 ) + l16 );
}
}

View File

@ -36,6 +36,7 @@ private:
void Worker();
bool SendData( const char* data, size_t len );
bool SendString( uint64_t ptr );
static Profiler* Instance();
static moodycamel::ProducerToken& GetToken()

View File

@ -10,6 +10,7 @@ enum class QueueType : uint8_t
{
ZoneBegin,
ZoneEnd,
StringData,
NUM_TYPES
};
@ -55,6 +56,7 @@ enum { QueueItemSize = sizeof( QueueItem ) };
static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
sizeof( QueueHeader ) + sizeof( QueueZoneEnd ),
sizeof( QueueHeader ),
};
static_assert( sizeof( QueueDataSize ) / sizeof( size_t ) == (uint8_t)QueueType::NUM_TYPES, "QueueDataSize mismatch" );