xref: /haiku/headers/os/net/NetBuffer.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 /*
2  * Copyright 2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *              Bruno Albuquerque, bga@bug-br.org.br
7  */
8 
9 #ifndef _NETBUFFER_H
10 #define _NETBUFFER_H
11 
12 #include <Archivable.h>
13 #include <SupportDefs.h>
14 
15 
16 class BMessage;
17 class DynamicBuffer;
18 
19 
20 class BNetBuffer : public BArchivable {
21 public:
22 	BNetBuffer(size_t size = 0);
23 
24 	virtual ~BNetBuffer();
25 
26 	BNetBuffer(const BNetBuffer& buffer);
27 	BNetBuffer(BMessage* archive);
28 
29 	BNetBuffer& operator=(const BNetBuffer& buffer);
30 
31 	virtual	status_t Archive(BMessage* into, bool deep = true) const;
32 	static BArchivable* Instantiate(BMessage* archive);
33 
34 	status_t InitCheck();
35 
36 	status_t AppendInt8(int8 data);
37 	status_t AppendUint8(uint8 data);
38 	status_t AppendInt16(int16 data);
39 	status_t AppendUint16(uint16 data);
40 	status_t AppendInt32(int32 data);
41 	status_t AppendUint32(uint32 data);
42 	status_t AppendFloat(float data);
43 	status_t AppendDouble(double data);
44 	status_t AppendString(const char* data);
45 	status_t AppendData(const void* data, size_t size);
46 	status_t AppendMessage(const BMessage& data);
47 	status_t AppendInt64(int64 data);
48 	status_t AppendUint64(uint64 data);
49 
50  	status_t RemoveInt8(int8& data);
51 	status_t RemoveUint8(uint8& data);
52 	status_t RemoveInt16(int16& data);
53 	status_t RemoveUint16(uint16& data);
54 	status_t RemoveInt32(int32& data);
55 	status_t RemoveUint32(uint32& data);
56 	status_t RemoveFloat(float& data);
57 	status_t RemoveDouble(double& data);
58 	status_t RemoveString(char* data, size_t size);
59 	status_t RemoveData(void* data, size_t size);
60 	status_t RemoveMessage(BMessage& data);
61 	status_t RemoveInt64(int64& data);
62 	status_t RemoveUint64(uint64& data);
63 
64 	unsigned char* Data() const;
65 	size_t Size() const;
66 	size_t BytesRemaining() const;
67 
68 	inline DynamicBuffer* GetImpl() const;
69 
70 protected:
71 	status_t fInit;
72 
73 private:
74 	virtual	void		_ReservedBNetBufferFBCCruft1();
75 	virtual	void		_ReservedBNetBufferFBCCruft2();
76 	virtual	void		_ReservedBNetBufferFBCCruft3();
77 	virtual	void		_ReservedBNetBufferFBCCruft4();
78 	virtual	void		_ReservedBNetBufferFBCCruft5();
79 	virtual	void		_ReservedBNetBufferFBCCruft6();
80 
81 	DynamicBuffer* 		fImpl;
82 	int32				__ReservedBNetBufferFBCCruftData[8];
83 
84 };
85 
86 
87 inline DynamicBuffer*
88 BNetBuffer::GetImpl() const
89 {
90 	return fImpl;
91 }
92 
93 #endif  // _NET_BUFFER_H
94