1 /*=--------------------------------------------------------------------------=* 2 * NetBuffer.h -- Interface definition for the BNetBuffer class. 3 * 4 * Written by S.T. Mansfield (thephantom@mac.com) 5 *=--------------------------------------------------------------------------=* 6 * Copyright (c) 2002, The OpenBeOS project. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 * DEALINGS IN THE SOFTWARE. 25 *=--------------------------------------------------------------------------=* 26 */ 27 28 #ifndef _NETBUFFER_H 29 #define _NETBUFFER_H 30 31 #include <BeBuild.h> 32 #include <SupportDefs.h> 33 #include <Archivable.h> 34 #include <socket.h> 35 36 /* 37 * Empty forward declaration to satisfy the GetImpl method. 38 */ 39 class NLPacket; 40 41 class BNetBuffer : public BArchivable 42 { 43 public: 44 BNetBuffer(size_t size = 0); 45 virtual ~BNetBuffer(); 46 47 status_t InitCheck(); 48 49 BNetBuffer(BMessage *archive); 50 virtual status_t Archive(BMessage *into, bool deep = true) const; 51 static BArchivable *Instantiate(BMessage *archive); 52 53 BNetBuffer(const BNetBuffer &); 54 BNetBuffer& operator=(const BNetBuffer &); 55 56 // Mutators. 57 status_t AppendInt8(int8); 58 status_t AppendUint8(uint8); 59 status_t AppendInt16(int16); 60 status_t AppendUint16(uint16); 61 status_t AppendInt32(int32); 62 status_t AppendUint32(uint32); 63 status_t AppendFloat(float); 64 status_t AppendDouble(double); 65 status_t AppendString(const char *); 66 status_t AppendData(const void *, size_t); 67 status_t AppendMessage(const BMessage &); 68 status_t AppendInt64(int64); 69 status_t AppendUint64(uint64); 70 71 status_t RemoveInt8(int8 &); 72 status_t RemoveUint8(uint8 &); 73 status_t RemoveInt16(int16 &); 74 status_t RemoveUint16(uint16 &); 75 status_t RemoveInt32(int32 &); 76 status_t RemoveUint32(uint32 &); 77 status_t RemoveFloat(float &); 78 status_t RemoveDouble(double &); 79 status_t RemoveString(char *, size_t); 80 status_t RemoveData(void *, size_t); 81 status_t RemoveMessage(BMessage &); 82 status_t RemoveInt64(int64 &); 83 status_t RemoveUint64(uint64 &); 84 85 // Accessors. 86 unsigned char *Data() const; 87 size_t Size() const; 88 size_t BytesRemaining() const; 89 90 inline NLPacket *GetImpl() const; 91 92 protected: 93 // Attributes. 94 status_t fInitialized; 95 unsigned char* fData; 96 int32 fDataSize; 97 int32 fStackSize; 98 int32 fCapacity; 99 100 private: 101 // Private class helpers. 102 status_t clone( const BNetBuffer& ); 103 status_t dpop( int32, int32, void* ); 104 status_t dpush( int32, int32, const void* ); 105 status_t resize( int32 NewSize, bool RegenStack = false ); 106 107 // Not used, here to maintain R5 binary compatiblilty. 108 int32 fPrivateData[5]; 109 }; 110 111 112 // WARNING: This method, as it stands, breaks R5 compatibility *STM*. 113 inline NLPacket* BNetBuffer::GetImpl( void ) const 114 { 115 return NULL; // Cheeky, yes; but no Nettle stuff is allowed... 116 } 117 118 #endif // <-- #ifndef _NETBUFFER_H 119 120