1 #pragma once
2 #include "FastNet/core/ClassFactory.h"
3 #include "FastNet/core/Stream.h"
4 #include "FastNet/core/App.h"
5 #include "FastNet/core/Cfg.h"
6
7
8 namespacepkt{9 namespacedemo{10
11 usingFastNet::UInt8;12 usingFastNet::UInt16;13 usingFastNet::UInt32;14 usingFastNet::UInt64;15 usingFastNet::Int8;16 usingFastNet::Int16;17 usingFastNet::Int32;18 usingFastNet::Int64;19 usingFastNet::Double;20 usingFastNet::Float;21 usingFastNet::String;22 usingFastNet::Bool;23 enum classDemoEnum:FastNet::Int32 {24 one = 1,25 two = 2,26 };27
28 struct DemoStruct : publicFastNet::Struct {29 bool operator==(DemoStruct const& ) const { return false; }30 bool operator!=(DemoStruct const& ) const { return true; }31 DefStruct("pkt.demo.DemoStruct",610075309,217574281)32 UInt8 u8=0;33 UInt16 u16=0;34 UInt32 u32=0;35 UInt64 u64=0;36 Int8 i8=0;37 Int16 i16=0;38 Int32 i32=0;39 Int64 i64=0;40 Float f=0.0f;41 Double d=0.0;42 Bool b=false;43 String s="";44 DemoEnum de=(DemoEnum)0;45
46 virtual void Deserialize(FastNet::StreamRead&stream) {47 stream.read(u8);48 stream.read(u16);49 stream.read(u32);50 stream.read(u64);51 stream.read(i8);52 stream.read(i16);53 stream.read(i32);54 stream.read(i64);55 stream.read(f);56 stream.read(d);57 stream.read(b);58 stream.read(s);59 stream.read(de);60 }61
62 virtual void Serialize(FastNet::StreamWrite&stream) {63 stream.write(u8);64 stream.write(u16);65 stream.write(u32);66 stream.write(u64);67 stream.write(i8);68 stream.write(i16);69 stream.write(i32);70 stream.write(i64);71 stream.write(f);72 stream.write(d);73 stream.write(b);74 stream.write(s);75 stream.write(de);76 }77
78 virtual FastNet::UInt32 SerializeSize() override{79 FastNet::UInt32 size(0);80 CalcSerializeSize(size,u8);81 CalcSerializeSize(size,u16);82 CalcSerializeSize(size,u32);83 CalcSerializeSize(size,u64);84 CalcSerializeSize(size,i8);85 CalcSerializeSize(size,i16);86 CalcSerializeSize(size,i32);87 CalcSerializeSize(size,i64);88 CalcSerializeSize(size,f);89 CalcSerializeSize(size,d);90 CalcSerializeSize(size,b);91 CalcSerializeSize(size,s);92 CalcSerializeSize(size,de);93 returnsize;94 }95
96 virtual void Reset() override{97 u8=0;98 u16=0;99 u32=0;100 u64=0;101 i8=0;102 i16=0;103 i32=0;104 i64=0;105 f=0.0f;106 d=0.0;107 b=false;108 s="";109 de=(DemoEnum)0;110 }111
112 static voidExport(){113 boost::python::class_,boost::shared_ptr,boost::noncopyable> _e("DemoStruct");114 boost::python::scope _s =_e;115 _e.def_readwrite("u8",&DemoStruct::u8);116 _e.def_readwrite("u16",&DemoStruct::u16);117 _e.def_readwrite("u32",&DemoStruct::u32);118 _e.def_readwrite("u64",&DemoStruct::u64);119 _e.def_readwrite("i8",&DemoStruct::i8);120 _e.def_readwrite("i16",&DemoStruct::i16);121 _e.def_readwrite("i32",&DemoStruct::i32);122 _e.def_readwrite("i64",&DemoStruct::i64);123 _e.def_readwrite("f",&DemoStruct::f);124 _e.def_readwrite("d",&DemoStruct::d);125 _e.def_readwrite("b",&DemoStruct::b);126 _e.def_readwrite("s",&DemoStruct::s);127 _e.def_readwrite("de",&DemoStruct::de);128 _e.add_static_property("sClsId",&DemoStruct::sClsId);129 _e.add_static_property("sClsName",&DemoStruct::sClsName);130 _e.add_static_property("sSignId",&DemoStruct::sSignId);131 }132 };133
134 class DemoMessage final: publicFastNet::Message {135 public:136 DefStruct("pkt.demo.DemoMessage",3264359728,2340124217)137 UInt8 u8=0;138 UInt16 u16=0;139 UInt32 u32=0;140 UInt64 u64=0;141 Int8 i8=0;142 Int16 i16=0;143 Int32 i32=0;144 Int64 i64=0;145 Float f=0.0f;146 Double d=0.0;147 Bool b=false;148 String s="";149 DemoEnum de=(DemoEnum)0;150 DemoStruct ds;151 std::vectorarr;152 std::vectorarr2;153 std::mapdict2;154 std::mapdict3;155
156 virtual void Deserialize(FastNet::StreamRead&stream) {157 stream.read(u8);158 stream.read(u16);159 stream.read(u32);160 stream.read(u64);161 stream.read(i8);162 stream.read(i16);163 stream.read(i32);164 stream.read(i64);165 stream.read(f);166 stream.read(d);167 stream.read(b);168 stream.read(s);169 stream.read(de);170 stream.read(ds);171 stream.read(arr);172 stream.read(arr2);173 stream.read(dict2);174 stream.read(dict3);175 }176
177 virtual void Serialize(FastNet::StreamWrite&stream) {178 stream.write(u8);179 stream.write(u16);180 stream.write(u32);181 stream.write(u64);182 stream.write(i8);183 stream.write(i16);184 stream.write(i32);185 stream.write(i64);186 stream.write(f);187 stream.write(d);188 stream.write(b);189 stream.write(s);190 stream.write(de);191 stream.write(ds);192 stream.write(arr);193 stream.write(arr2);194 stream.write(dict2);195 stream.write(dict3);196 }197
198 virtual FastNet::UInt32 SerializeSize() override{199 FastNet::UInt32 size(0);200 CalcSerializeSize(size,u8);201 CalcSerializeSize(size,u16);202 CalcSerializeSize(size,u32);203 CalcSerializeSize(size,u64);204 CalcSerializeSize(size,i8);205 CalcSerializeSize(size,i16);206 CalcSerializeSize(size,i32);207 CalcSerializeSize(size,i64);208 CalcSerializeSize(size,f);209 CalcSerializeSize(size,d);210 CalcSerializeSize(size,b);211 CalcSerializeSize(size,s);212 CalcSerializeSize(size,de);213 CalcSerializeSize(size,ds);214 CalcSerializeSize(size,arr);215 CalcSerializeSize(size,arr2);216 CalcSerializeSize(size,dict2);217 CalcSerializeSize(size,dict3);218 returnsize;219 }220
221 virtual void Reset() override{222 u8=0;223 u16=0;224 u32=0;225 u64=0;226 i8=0;227 i16=0;228 i32=0;229 i64=0;230 f=0.0f;231 d=0.0;232 b=false;233 s="";234 de=(DemoEnum)0;235 ds.Reset();236 arr.clear();237 arr2.clear();238 dict2.clear();239 dict3.clear();240 }241
242 static voidExport(){243 boost::python::class_,boost::shared_ptr,boost::noncopyable> _e("DemoMessage");244 boost::python::scope _s =_e;245 _e.def_readwrite("u8",&DemoMessage::u8);246 _e.def_readwrite("u16",&DemoMessage::u16);247 _e.def_readwrite("u32",&DemoMessage::u32);248 _e.def_readwrite("u64",&DemoMessage::u64);249 _e.def_readwrite("i8",&DemoMessage::i8);250 _e.def_readwrite("i16",&DemoMessage::i16);251 _e.def_readwrite("i32",&DemoMessage::i32);252 _e.def_readwrite("i64",&DemoMessage::i64);253 _e.def_readwrite("f",&DemoMessage::f);254 _e.def_readwrite("d",&DemoMessage::d);255 _e.def_readwrite("b",&DemoMessage::b);256 _e.def_readwrite("s",&DemoMessage::s);257 _e.def_readwrite("de",&DemoMessage::de);258 _e.def_readwrite("ds",&DemoMessage::ds);259 FastNet::App::RegisterStlVector >("v_2553082456");260 _e.def_readwrite("arr",&DemoMessage::arr);261 FastNet::App::RegisterStlVector >("v_2147306297");262 _e.def_readwrite("arr2",&DemoMessage::arr2);263 FastNet::App::RegisterStlMap >("m_2979050852");264 _e.def_readwrite("dict2",&DemoMessage::dict2);265 FastNet::App::RegisterStlMap,true>("m_3331818994");266 _e.def_readwrite("dict3",&DemoMessage::dict3);267 _e.add_static_property("sClsId",&DemoMessage::sClsId);268 _e.add_static_property("sClsName",&DemoMessage::sClsName);269 _e.add_static_property("sSignId",&DemoMessage::sSignId);270 }271 };272
273
274 } //end namespace demo
275 } //end namespace pkt