#ifndef _NET_MESSAGE_INC #define _NET_MESSAGE_INC #include "collection.h" class NMString { public: NMString(); NMString(const NMString &other); NMString(char *t); virtual ~NMString(); const bool operator<(const NMString &other) const; const bool operator==(const NMString &other) const; NMString &operator=(const NMString &other); char *text; }; class KeyValue: public Pair { public: KeyValue(const NMString &k, const NMString &v): Pair(k, v) {} KeyValue &operator=(const KeyValue &other) { first = other.first; second = other.second; return *this; } }; class Dictionary: public LinkedList< KeyValue > { public: Dictionary(); virtual ~Dictionary(); virtual int parse(char *data, int size); bool get_string(char *key, char *buff, int buffsize); int get_int(char *key); virtual void add_string(char *key, char *buff); void add_int(char *key, int i); int make_body(char *buff, int size); }; class NetMessage: public Map { public: NetMessage(); virtual ~NetMessage(); int parse(char *data, int size); bool get_string(char *key, char *buff, int buffsize); int get_int(char *key); bool get_data(char *key, char *buff, int *size); Dictionary get_dict(char *key); static char *unescape_inplace(char *val); }; class ClientNetMessage: public Dictionary { public: ClientNetMessage(); virtual ~ClientNetMessage(); int make_packet(char *buff, int size); void add_string(char *key, char *buff); bool add_data(char *key, char *buff, int size); void add_dict(char *key, Dictionary &d); static char *escape(char *val); }; #endif