00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef DATAGRAM_H
00020 #define DATAGRAM_H
00021
00022 #include "pandabase.h"
00023
00024 #include "numeric_types.h"
00025 #include "typedObject.h"
00026 #include "littleEndian.h"
00027 #include "bigEndian.h"
00028 #include "pta_uchar.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class EXPCL_PANDAEXPRESS Datagram : public TypedObject {
00048 PUBLISHED:
00049 INLINE Datagram();
00050 INLINE Datagram(const void *data, size_t size);
00051 INLINE Datagram(const string &data);
00052 INLINE Datagram(const Datagram ©);
00053 INLINE void operator = (const Datagram ©);
00054
00055 virtual ~Datagram();
00056
00057 virtual void clear();
00058 void dump_hex(ostream &out) const;
00059
00060 INLINE void add_bool(bool value);
00061 INLINE void add_int8(PN_int8 value);
00062 INLINE void add_uint8(PN_uint8 value);
00063
00064
00065 INLINE void add_int16(PN_int16 value);
00066 INLINE void add_int32(PN_int32 value);
00067 INLINE void add_int64(PN_int64 value);
00068 INLINE void add_uint16(PN_uint16 value);
00069 INLINE void add_uint32(PN_uint32 value);
00070 INLINE void add_uint64(PN_uint64 value);
00071 INLINE void add_float32(float value);
00072 INLINE void add_float64(PN_float64 value);
00073
00074
00075 INLINE void add_be_int16(PN_int16 value);
00076 INLINE void add_be_int32(PN_int32 value);
00077 INLINE void add_be_int64(PN_int64 value);
00078 INLINE void add_be_uint16(PN_uint16 value);
00079 INLINE void add_be_uint32(PN_uint32 value);
00080 INLINE void add_be_uint64(PN_uint64 value);
00081 INLINE void add_be_float32(float value);
00082 INLINE void add_be_float64(PN_float64 value);
00083
00084 INLINE void add_string(const string &str);
00085 INLINE void add_z_string(string str);
00086 INLINE void add_fixed_string(const string &str, size_t size);
00087
00088 void pad_bytes(size_t size);
00089 void append_data(const void *data, size_t size);
00090 INLINE void append_data(const string &data);
00091
00092 INLINE string get_message() const;
00093 INLINE const void *get_data() const;
00094 INLINE size_t get_length() const;
00095
00096 INLINE bool operator == (const Datagram &other) const;
00097 INLINE bool operator != (const Datagram &other) const;
00098 INLINE bool operator < (const Datagram &other) const;
00099
00100 private:
00101 PTA_uchar _data;
00102
00103
00104 public:
00105 static TypeHandle get_class_type() {
00106 return _type_handle;
00107 }
00108 static void init_type() {
00109 TypedObject::init_type();
00110 register_type(_type_handle, "Datagram",
00111 TypedObject::get_class_type());
00112 }
00113 virtual TypeHandle get_type() const {
00114 return get_class_type();
00115 }
00116 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00117
00118 private:
00119 static TypeHandle _type_handle;
00120 };
00121
00122 #include "datagram.I"
00123
00124 #endif