1 /* 2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _NETBUFFER_H 6 #define _NETBUFFER_H 7 8 9 #include <BeBuild.h> 10 #include <SupportDefs.h> 11 #include <Archivable.h> 12 13 #include <sys/socket.h> 14 15 16 class BNetBuffer : public BArchivable { 17 public: 18 BNetBuffer(size_t size = 0); 19 virtual ~BNetBuffer(); 20 21 status_t InitCheck(); 22 23 BNetBuffer(BMessage* archive); 24 virtual status_t Archive(BMessage* into, bool deep = true) const; 25 static BArchivable* Instantiate(BMessage* archive); 26 27 BNetBuffer(const BNetBuffer &); 28 BNetBuffer& operator=(const BNetBuffer &); 29 30 // Mutators. 31 status_t AppendInt8(int8); 32 status_t AppendUint8(uint8); 33 status_t AppendInt16(int16); 34 status_t AppendUint16(uint16); 35 status_t AppendInt32(int32); 36 status_t AppendUint32(uint32); 37 status_t AppendFloat(float); 38 status_t AppendDouble(double); 39 status_t AppendString(const char *); 40 status_t AppendData(const void *, size_t); 41 status_t AppendMessage(const BMessage &); 42 status_t AppendInt64(int64); 43 status_t AppendUint64(uint64); 44 45 status_t RemoveInt8(int8 &); 46 status_t RemoveUint8(uint8 &); 47 status_t RemoveInt16(int16 &); 48 status_t RemoveUint16(uint16 &); 49 status_t RemoveInt32(int32 &); 50 status_t RemoveUint32(uint32 &); 51 status_t RemoveFloat(float &); 52 status_t RemoveDouble(double &); 53 status_t RemoveString(char *, size_t); 54 status_t RemoveData(void *, size_t); 55 status_t RemoveMessage(BMessage &); 56 status_t RemoveInt64(int64 &); 57 status_t RemoveUint64(uint64 &); 58 59 // Accessors. 60 unsigned char* Data() const; 61 size_t Size() const; 62 size_t BytesRemaining() const; 63 64 private: 65 virtual void _ReservedBNetBufferFBCCruft1(); 66 virtual void _ReservedBNetBufferFBCCruft2(); 67 virtual void _ReservedBNetBufferFBCCruft3(); 68 virtual void _ReservedBNetBufferFBCCruft4(); 69 virtual void _ReservedBNetBufferFBCCruft5(); 70 virtual void _ReservedBNetBufferFBCCruft6(); 71 72 // Private class helpers. 73 status_t clone(const BNetBuffer&); 74 status_t dpop(int32, int32, void*); 75 status_t dpush(int32, int32, const void*); 76 status_t resize(int32 newSize, bool regenStack = false); 77 78 status_t fInit; 79 uint8* fData; 80 int32 fDataSize; 81 int32 fStackSize; 82 int32 fCapacity; 83 int32 _reserved[5]; 84 }; 85 86 #endif // _NETBUFFER_H 87