1 // RequestFlattener.h 2 3 #ifndef NET_FS_REQUEST_FLATTENER_H 4 #define NET_FS_REQUEST_FLATTENER_H 5 6 #include <DataIO.h> 7 8 #include "Request.h" 9 10 // Writer 11 class Writer { 12 public: 13 Writer(); 14 virtual ~Writer(); 15 16 virtual status_t Write(const void* buffer, int32 size) = 0; 17 virtual status_t Pad(int32 size); 18 }; 19 20 // DataIOWriter 21 class DataIOWriter : public Writer { 22 public: 23 DataIOWriter(BDataIO* dataIO); 24 virtual ~DataIOWriter(); 25 26 virtual status_t Write(const void* buffer, int32 size); 27 28 private: 29 BDataIO* fDataIO; 30 }; 31 32 // DummyWriter 33 class DummyWriter : public Writer { 34 public: 35 DummyWriter(); 36 virtual ~DummyWriter(); 37 38 virtual status_t Write(const void* buffer, int32 size); 39 }; 40 41 // RequestFlattener 42 class RequestFlattener : public RequestMemberVisitor { 43 public: 44 RequestFlattener(Writer* writer); 45 46 status_t GetStatus() const; 47 int32 GetBytesWritten() const; 48 49 virtual void Visit(RequestMember* member, bool& data); 50 virtual void Visit(RequestMember* member, int8& data); 51 virtual void Visit(RequestMember* member, uint8& data); 52 virtual void Visit(RequestMember* member, int16& data); 53 virtual void Visit(RequestMember* member, uint16& data); 54 virtual void Visit(RequestMember* member, int32& data); 55 virtual void Visit(RequestMember* member, uint32& data); 56 virtual void Visit(RequestMember* member, int64& data); 57 virtual void Visit(RequestMember* member, uint64& data); 58 virtual void Visit(RequestMember* member, Data& data); 59 virtual void Visit(RequestMember* member, StringData& data); 60 virtual void Visit(RequestMember* member, 61 RequestMember& subMember); 62 virtual void Visit(RequestMember* member, 63 FlattenableRequestMember& subMember); 64 65 status_t Write(const void* buffer, int32 size); 66 status_t Align(int32 align); 67 68 status_t WriteBool(bool data); 69 status_t WriteInt32(int32 data); 70 status_t WriteData(const void* buffer, int32 size); 71 status_t WriteString(const char* string); 72 73 private: 74 Writer* fWriter; 75 status_t fStatus; 76 int32 fBytesWritten; 77 }; 78 79 80 #endif // NET_FS_REQUEST_FLATTENER_H 81