aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2021-09-28 15:14:43 -0700
committerMike Buland <mbuland@penny-arcade.com>2021-09-28 15:14:43 -0700
commitbee0b9c862d5eb325b8c29767a89b3d895b5f5a9 (patch)
treea468749bdfefb64ade353b67b463e49dd4effa54
parent7ebfdb3e7b71fdd315032adb0854e28f0073e1f7 (diff)
downloadlibgats-bee0b9c862d5eb325b8c29767a89b3d895b5f5a9.tar.gz
libgats-bee0b9c862d5eb325b8c29767a89b3d895b5f5a9.tar.bz2
libgats-bee0b9c862d5eb325b8c29767a89b3d895b5f5a9.tar.xz
libgats-bee0b9c862d5eb325b8c29767a89b3d895b5f5a9.zip
Added packet helpers?
-rw-r--r--c++-libbu++/src/object.cpp19
-rw-r--r--c++-libbu++/src/object.h3
2 files changed, 22 insertions, 0 deletions
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 @@
15#include "gats/dictionary.h" 15#include "gats/dictionary.h"
16#include "gats/null.h" 16#include "gats/null.h"
17 17
18#include "gats/gatsstream.h"
19
18#include <stdlib.h> 20#include <stdlib.h>
19 21
20#include <bu/formatter.h> 22#include <bu/formatter.h>
21#include <bu/stream.h> 23#include <bu/stream.h>
24#include <bu/membuf.h>
25#include <bu/staticmembuf.h>
22 26
23#include <bu/sio.h> 27#include <bu/sio.h>
24using namespace Bu; 28using namespace Bu;
@@ -31,6 +35,21 @@ Gats::Object::~Object()
31{ 35{
32} 36}
33 37
38Bu::String Gats::Object::toPacket()
39{
40 Bu::MemBuf mbOut;
41 Gats::GatsStream gsOut( mbOut );
42 gsOut.writeObject( this );
43 return mbOut.getString();
44}
45
46Gats::Object *Gats::Object::fromPacket( const Bu::String &sData )
47{
48 Bu::StaticMemBuf mbIn( sData.getStr(), sData.getSize() );
49 Gats::GatsStream gsIn( mbIn );
50 return gsIn.readObject();
51}
52
34Gats::Object *Gats::Object::read( Bu::Stream &rIn ) 53Gats::Object *Gats::Object::read( Bu::Stream &rIn )
35{ 54{
36 char buf; 55 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
44 virtual void read( Bu::Stream &rIn, char cType )=0; 44 virtual void read( Bu::Stream &rIn, char cType )=0;
45 virtual Object *clone() const=0; 45 virtual Object *clone() const=0;
46 46
47 Bu::String toPacket();
48 static Object *fromPacket( const Bu::String &sData );
49
47 static Object *read( Bu::Stream &rIn ); 50 static Object *read( Bu::Stream &rIn );
48 static Object *strToGats( const Bu::String &sStr ); 51 static Object *strToGats( const Bu::String &sStr );
49 52