mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-09 22:31:55 +02:00
refactoring
git-svn-id: svn://elaine/murooma/trunk@328 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
611b2a6c9f
commit
c40bfda64c
35 changed files with 192 additions and 178 deletions
59
message/header.h
Normal file
59
message/header.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef HEADER_MESSAGE_H
|
||||
#define HEADER_MESSAGE_H
|
||||
|
||||
#include "message.h"
|
||||
|
||||
namespace msg
|
||||
{
|
||||
|
||||
class Header : public BaseMessage
|
||||
{
|
||||
public:
|
||||
Header(const std::string& codecName = "", size_t size = 0) : BaseMessage(message_type::kHeader), payloadSize(size), codec(codecName)
|
||||
{
|
||||
payload = (char*)malloc(size);
|
||||
}
|
||||
|
||||
virtual ~Header()
|
||||
{
|
||||
free(payload);
|
||||
}
|
||||
|
||||
virtual void read(std::istream& stream)
|
||||
{
|
||||
int16_t size;
|
||||
stream.read(reinterpret_cast<char *>(&size), sizeof(int16_t));
|
||||
codec.resize(size);
|
||||
stream.read(&codec[0], size);
|
||||
|
||||
stream.read(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
||||
payload = (char*)realloc(payload, payloadSize);
|
||||
stream.read(payload, payloadSize);
|
||||
}
|
||||
|
||||
virtual uint32_t getSize()
|
||||
{
|
||||
return sizeof(int16_t) + codec.size() + sizeof(uint32_t) + payloadSize;
|
||||
}
|
||||
|
||||
uint32_t payloadSize;
|
||||
char* payload;
|
||||
std::string codec;
|
||||
|
||||
protected:
|
||||
virtual void doserialize(std::ostream& stream)
|
||||
{
|
||||
int16_t size(codec.size());
|
||||
stream.write(reinterpret_cast<char *>(&size), sizeof(int16_t));
|
||||
stream.write(codec.c_str(), size);
|
||||
stream.write(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
||||
stream.write(payload, payloadSize);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue