xref: /haiku/src/add-ons/kernel/file_systems/netfs/headers/shared/RequestUnflattener.h (revision 5a1d355fdf2747f80f8c46e2539f844a0b813346)
1 // RequestUnflattener.h
2 
3 #ifndef NET_FS_REQUEST_UNFLATTENER_H
4 #define NET_FS_REQUEST_UNFLATTENER_H
5 
6 #include <SupportDefs.h>
7 
8 #include "Request.h"
9 #include "HashString.h"
10 
11 // Reader
12 class Reader {
13 public:
14 								Reader();
15 	virtual						~Reader();
16 
17 	virtual	status_t			Read(void* buffer, int32 size) = 0;
18 	virtual	status_t			Read(int32 size, void** buffer,
19 									bool* mustFree);
20 	virtual	status_t			Skip(int32 size);
21 };
22 
23 // RequestUnflattener
24 class RequestUnflattener : public RequestMemberVisitor {
25 public:
26 								RequestUnflattener(Reader* reader);
27 
28 			status_t			GetStatus() const;
29 			int32				GetBytesRead() const;
30 
31 	virtual	void				Visit(RequestMember* member, bool& data);
32 	virtual	void				Visit(RequestMember* member, int8& data);
33 	virtual	void				Visit(RequestMember* member, uint8& data);
34 	virtual	void				Visit(RequestMember* member, int16& data);
35 	virtual	void				Visit(RequestMember* member, uint16& data);
36 	virtual	void				Visit(RequestMember* member, int32& data);
37 	virtual	void				Visit(RequestMember* member, uint32& data);
38 	virtual	void				Visit(RequestMember* member, int64& data);
39 	virtual	void				Visit(RequestMember* member, uint64& data);
40 	virtual	void				Visit(RequestMember* member, Data& data);
41 	virtual	void				Visit(RequestMember* member, StringData& data);
42 	virtual	void				Visit(RequestMember* member,
43 									RequestMember& subMember);
44 	virtual	void				Visit(RequestMember* member,
45 									FlattenableRequestMember& subMember);
46 
47 			status_t			Read(void* buffer, int32 size);
48 			status_t			Read(int32 size, void*& buffer, bool& mustFree);
49 			status_t			Align(int32 align);
50 
51 			status_t			ReadBool(bool& data);
52 			status_t			ReadInt32(int32& data);
53 			status_t			ReadData(void*& buffer, int32& size,
54 									bool& mustFree);
55 			status_t			ReadString(HashString& string);
56 
57 private:
58 			Reader*				fReader;
59 			status_t			fStatus;
60 			int32				fBytesRead;
61 };
62 
63 #endif	// NET_FS_REQUEST_UNFLATTENER_H
64