From 94e02c37bff72e51388cf85541ee023657153661 Mon Sep 17 00:00:00 2001 From: malloc Date: Fri, 9 Mar 2018 09:38:17 -0600 Subject: [PATCH] bereavement --- server/src/sock/packet.cpp | 15 +++++++++++++++ server/src/sock/packet.hpp | 26 +++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/server/src/sock/packet.cpp b/server/src/sock/packet.cpp index 8156baf..5563382 100644 --- a/server/src/sock/packet.cpp +++ b/server/src/sock/packet.cpp @@ -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 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(); diff --git a/server/src/sock/packet.hpp b/server/src/sock/packet.hpp index c5192e6..023b010 100644 --- a/server/src/sock/packet.hpp +++ b/server/src/sock/packet.hpp @@ -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 data); + + void SetRegion(uint8_t index); + void SetRegions(uint8_t start, std::vector 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 regions;