From bee0b9c862d5eb325b8c29767a89b3d895b5f5a9 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 28 Sep 2021 15:14:43 -0700 Subject: Added packet helpers? --- c++-libbu++/src/object.cpp | 19 +++++++++++++++++++ c++-libbu++/src/object.h | 3 +++ 2 files changed, 22 insertions(+) (limited to 'c++-libbu++/src') diff --git a/c++-libbu++/src/object.cpp b/c++-libbu++/src/object.cpp index 61471b9..7cd50e6 100644 --- a/c++-libbu++/src/object.cpp +++ b/c++-libbu++/src/object.cpp @@ -15,10 +15,14 @@ #include "gats/dictionary.h" #include "gats/null.h" +#include "gats/gatsstream.h" + #include #include #include +#include +#include #include using namespace Bu; @@ -31,6 +35,21 @@ Gats::Object::~Object() { } +Bu::String Gats::Object::toPacket() +{ + Bu::MemBuf mbOut; + Gats::GatsStream gsOut( mbOut ); + gsOut.writeObject( this ); + return mbOut.getString(); +} + +Gats::Object *Gats::Object::fromPacket( const Bu::String &sData ) +{ + Bu::StaticMemBuf mbIn( sData.getStr(), sData.getSize() ); + Gats::GatsStream gsIn( mbIn ); + return gsIn.readObject(); +} + Gats::Object *Gats::Object::read( Bu::Stream &rIn ) { char buf; diff --git a/c++-libbu++/src/object.h b/c++-libbu++/src/object.h index 62da7c1..859e126 100644 --- a/c++-libbu++/src/object.h +++ b/c++-libbu++/src/object.h @@ -44,6 +44,9 @@ namespace Gats virtual void read( Bu::Stream &rIn, char cType )=0; virtual Object *clone() const=0; + Bu::String toPacket(); + static Object *fromPacket( const Bu::String &sData ); + static Object *read( Bu::Stream &rIn ); static Object *strToGats( const Bu::String &sStr ); -- cgit v1.2.3