mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-03 08:39:49 +02:00
80 lines
2 KiB
C++
80 lines
2 KiB
C++
/***
|
|
This file is part of snapcast
|
|
Copyright (C) 2015 Johannes Pohl
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#ifndef WIRE_CHUNK_H
|
|
#define WIRE_CHUNK_H
|
|
|
|
#include <chrono>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <streambuf>
|
|
#include <vector>
|
|
#include "message.h"
|
|
|
|
|
|
namespace msg
|
|
{
|
|
|
|
class WireChunk : public BaseMessage
|
|
{
|
|
public:
|
|
WireChunk(size_t size = 0) : BaseMessage(message_type::kWireChunk), payloadSize(size)
|
|
{
|
|
payload = (char*)malloc(size);
|
|
}
|
|
|
|
virtual ~WireChunk()
|
|
{
|
|
free(payload);
|
|
}
|
|
|
|
virtual void read(std::istream& stream)
|
|
{
|
|
stream.read(reinterpret_cast<char *>(×tamp.sec), sizeof(int32_t));
|
|
stream.read(reinterpret_cast<char *>(×tamp.usec), sizeof(int32_t));
|
|
stream.read(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
|
payload = (char*)realloc(payload, payloadSize);
|
|
stream.read(payload, payloadSize);
|
|
}
|
|
|
|
virtual uint32_t getSize()
|
|
{
|
|
return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint32_t) + payloadSize;
|
|
}
|
|
|
|
tv timestamp;
|
|
uint32_t payloadSize;
|
|
char* payload;
|
|
|
|
protected:
|
|
virtual void doserialize(std::ostream& stream)
|
|
{
|
|
stream.write(reinterpret_cast<char *>(×tamp.sec), sizeof(int32_t));
|
|
stream.write(reinterpret_cast<char *>(×tamp.usec), sizeof(int32_t));
|
|
stream.write(reinterpret_cast<char *>(&payloadSize), sizeof(uint32_t));
|
|
stream.write(payload, payloadSize);
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|