bereavement

This commit is contained in:
malloc 2018-03-09 09:38:17 -06:00
parent c62a73544b
commit 94e02c37bf
2 changed files with 38 additions and 3 deletions

View file

@ -1,5 +1,20 @@
#include "packet.hpp"
bool sosc::Packet::AddRegion(std::string data) {
if(this->regions.size() == 256)
return false;
this->regions.push_back(data);
return true;
}
bool sosc::Packet::AddRegions(std::vector<std::string> data) {
if(this->regions.size() + data.size() > 256)
return false;
}
int sosc::Packet::Parse(const std::string& data, std::string* extra) {
const unsigned char* raw =
(const unsigned char*)data.c_str();

View file

@ -18,13 +18,25 @@
namespace sosc {
class Packet {
public:
void Clear();
void AddRegion(int index = -1);
std::string ToString() const;
bool AddRegion(std::string data);
bool AddRegions(std::vector<std::string> data);
void SetRegion(uint8_t index);
void SetRegions(uint8_t start, std::vector<std::string> data);
void DeleteRegion(uint8_t index);
void DeleteRegions(uint8_t start, uint8_t length);
inline void Clear() const {
this->regions.clear();
}
int Parse(const std::string& data, std::string* extra = nullptr);
bool Check(int region_count, ...);
inline void SetId(uint8_t id) const {
this->id = id;
}
inline uint8_t GetId() const {
return this->id;
}
@ -34,6 +46,14 @@ public:
{
return regions[index];
}
std::string ToString() const;
inline operator std::string () const {
return this->ToString();
}
inline operator const char* () const {
return this->ToString().c_str();
}
private:
uint8_t id;
std::vector<std::string> regions;