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" #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) { int sosc::Packet::Parse(const std::string& data, std::string* extra) {
const unsigned char* raw = const unsigned char* raw =
(const unsigned char*)data.c_str(); (const unsigned char*)data.c_str();

View file

@ -18,13 +18,25 @@
namespace sosc { namespace sosc {
class Packet { class Packet {
public: public:
void Clear(); bool AddRegion(std::string data);
void AddRegion(int index = -1); bool AddRegions(std::vector<std::string> data);
std::string ToString() const;
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); int Parse(const std::string& data, std::string* extra = nullptr);
bool Check(int region_count, ...); bool Check(int region_count, ...);
inline void SetId(uint8_t id) const {
this->id = id;
}
inline uint8_t GetId() const { inline uint8_t GetId() const {
return this->id; return this->id;
} }
@ -34,6 +46,14 @@ public:
{ {
return regions[index]; 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: private:
uint8_t id; uint8_t id;
std::vector<std::string> regions; std::vector<std::string> regions;