00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef DATAGRAM_H
00016 #define DATAGRAM_H
00017
00018 #include "pandabase.h"
00019
00020 #include "numeric_types.h"
00021 #include "typedObject.h"
00022 #include "littleEndian.h"
00023 #include "bigEndian.h"
00024 #include "pta_uchar.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 class EXPCL_PANDAEXPRESS Datagram : public TypedObject {
00044 PUBLISHED:
00045 INLINE Datagram();
00046 INLINE Datagram(const void *data, size_t size);
00047 INLINE Datagram(const string &data);
00048 INLINE Datagram(const Datagram ©);
00049 INLINE void operator = (const Datagram ©);
00050
00051 virtual ~Datagram();
00052
00053 virtual void clear();
00054 void dump_hex(ostream &out, unsigned int indent=0) const;
00055
00056 INLINE void add_bool(bool value);
00057 INLINE void add_int8(PN_int8 value);
00058 INLINE void add_uint8(PN_uint8 value);
00059
00060
00061 INLINE void add_int16(PN_int16 value);
00062 INLINE void add_int32(PN_int32 value);
00063 INLINE void add_int64(PN_int64 value);
00064 INLINE void add_uint16(PN_uint16 value);
00065 INLINE void add_uint32(PN_uint32 value);
00066 INLINE void add_uint64(PN_uint64 value);
00067 INLINE void add_float32(PN_float32 value);
00068 INLINE void add_float64(PN_float64 value);
00069 INLINE void add_stdfloat(PN_stdfloat value);
00070
00071
00072 INLINE void add_be_int16(PN_int16 value);
00073 INLINE void add_be_int32(PN_int32 value);
00074 INLINE void add_be_int64(PN_int64 value);
00075 INLINE void add_be_uint16(PN_uint16 value);
00076 INLINE void add_be_uint32(PN_uint32 value);
00077 INLINE void add_be_uint64(PN_uint64 value);
00078 INLINE void add_be_float32(PN_float32 value);
00079 INLINE void add_be_float64(PN_float64 value);
00080
00081 INLINE void add_string(const string &str);
00082 INLINE void add_string32(const string &str);
00083 INLINE void add_z_string(string str);
00084 INLINE void add_fixed_string(const string &str, size_t size);
00085 void add_wstring(const wstring &str);
00086
00087 void pad_bytes(size_t size);
00088 void append_data(const void *data, size_t size);
00089 INLINE void append_data(const string &data);
00090
00091 void assign(const void *data, size_t size);
00092
00093 INLINE string get_message() const;
00094 INLINE const void *get_data() const;
00095 INLINE size_t get_length() const;
00096
00097 INLINE void set_array(PTA_uchar data);
00098 INLINE void copy_array(CPTA_uchar data);
00099 INLINE CPTA_uchar get_array() const;
00100 INLINE PTA_uchar modify_array();
00101
00102 INLINE void set_stdfloat_double(bool stdfloat_double);
00103 INLINE bool get_stdfloat_double() const;
00104
00105 INLINE bool operator == (const Datagram &other) const;
00106 INLINE bool operator != (const Datagram &other) const;
00107 INLINE bool operator < (const Datagram &other) const;
00108
00109 void output(ostream &out) const;
00110 void write(ostream &out, unsigned int indent=0) const;
00111
00112 private:
00113 PTA_uchar _data;
00114 bool _stdfloat_double;
00115
00116 public:
00117
00118 static TypeHandle get_class_type() {
00119 return _type_handle;
00120 }
00121 static void init_type() {
00122 TypedObject::init_type();
00123 register_type(_type_handle, "Datagram",
00124 TypedObject::get_class_type());
00125 }
00126 virtual TypeHandle get_type() const {
00127 return get_class_type();
00128 }
00129 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00130
00131
00132 private:
00133 static TypeHandle _type_handle;
00134 };
00135
00136
00137
00138
00139
00140
00141 INLINE void
00142 generic_write_datagram(Datagram &dest, bool value);
00143 INLINE void
00144 generic_write_datagram(Datagram &dest, int value);
00145 INLINE void
00146 generic_write_datagram(Datagram &dest, float value);
00147 INLINE void
00148 generic_write_datagram(Datagram &dest, double value);
00149 INLINE void
00150 generic_write_datagram(Datagram &dest, const string &value);
00151 INLINE void
00152 generic_write_datagram(Datagram &dest, const wstring &value);
00153
00154
00155 #include "datagram.I"
00156
00157 #endif