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 m_init; 95 96 private: 97 virtual void _ReservedBNetBufferFBCCruft1(); 98 virtual void _ReservedBNetBufferFBCCruft2(); 99 virtual void _ReservedBNetBufferFBCCruft3(); 100 virtual void _ReservedBNetBufferFBCCruft4(); 101 virtual void _ReservedBNetBufferFBCCruft5(); 102 virtual void _ReservedBNetBufferFBCCruft6(); 103 104 unsigned char* fData; 105 int32 fDataSize; 106 int32 fStackSize; 107 int32 fCapacity; 108 109 // Not used, here to maintain R5 binary compatiblilty. 110 int32 fPrivateData[5]; 111 112 // Private class helpers. 113 status_t clone( const BNetBuffer& ); 114 status_t dpop( int32, int32, void* ); 115 status_t dpush( int32, int32, const void* ); 116 status_t resize( int32 NewSize, bool RegenStack = false ); 117 }; 118 119 120 inline NLPacket* BNetBuffer::GetImpl( void ) const 121 { 122 return NULL; 123 } 124 125 #endif // <-- #ifndef _NETBUFFER_H 126 127 /*=------------------------------------------------------------------- End -=*/ 128 129