The Be Book The Network Kit The Network Kit Index

BNetBuffer

Derived from: BArchivable
Declared in:  be/net/NutBuffer.h
Library: libnetapi.so
Allocation: Constructor only
Summary:  more...


The BNetBuffer class provides an easy way to construct network buffers consisting of any sort of data, for use by the BNetEndpoint class.

Once you've created a BNetBuffer, you can append data to it by using a series of functions designed to add various types of data. For example, to create a buffer and place the long integer 2 followed by the string "This is a test." in it, you could do this:

BNetBuffer buffer(512);
buffer.AppendInt32(2);
buffer.AppendString("This is a test.");

The AppendInt32() function automatically handles conversion of the value into network byte order, as do all of the AppendXXX() functions for integer values (16-bit, 32-bit, and 64-bit, signed or unsigned). Likewise, the RemoveXXX() functions peel data out of a buffer, and they too are endian-aware.


Constructor and Destructor


BNetBuffer()

BNetBuffer(size_t size = 0)
BNetBuffer(const BNetBuffer &from)
BNetBuffer(BMessage *archive)

Creates a BNetBuffer. The first form creates a new buffer capable of holding up to size bytes of data. In this case, the buffer begins life empty.

The second form creates a new buffer which is an exact duplicate of the BNetBuffer specified by the from argument, including any data that might already be in the buffer. The third form reconstructs an archived BNetBuffer.


~BNetBuffer

virtual ~BNetEndpoint()

A typical destructor.


Member Functions


AppendInt8() , AppendUint8() , AppendInt16() , AppendUint16() , AppendInt32() , AppendUint32() , AppendInt64() , AppendUint64() , AppendFloat() , AppendDouble() , AppendString() , AppendData() , AppendMessage()

status_t AppendInt8(int8 value)
status_t AppendUint8(uint8 value)
status_t AppendInt16(int16 value)
status_t AppendUint16(uint16 value)
status_t AppendInt32(int32 value)
status_t AppendUint32(uint32 value)
status_t AppendInt64(int64 value)
status_t AppendUint64(uint64 value)
status_t AppendFloat(float value)
status_t AppendDouble(double value)
status_t AppendString(const char *string)
status_t AppendData(const void *data, size_t size)
status_t AppendMessage(BMessage &message)

Appends the specified data type to the end of the buffer. Integer values are automatically converted to network byte ordering (but floats and doubles are not, nor are values inside structures added using AppendData()).

Strings are appended as null-terminated strings.

AppendData() copies size bytes from the buffer pointed at by data.

RETURN CODES


Data() , Size() , BytesRemaining()

unsigned char *Data(void) const
size_t Size(void) const
size_t BytesRemaining(void) const

Data() returns a pointer to the BNetBuffer's internal data buffer.

Size() returns the number of bytes currently in the buffer.

BytesRemaining() returns the number of unused bytes in the buffer.


RemoveInt8() , RemoveUint8() , RemoveInt16() , RemoveUint16() , RemoveInt32() , RemoveUint32() , RemoveInt64() , RemoveUint64() , RemoveFloat() , RemoveDouble() , RemoveString() , RemoveData() , RemoveMessage()

status_t RemoveInt8(int8 &value)
status_t RemoveUint8(uint8 &value)
status_t RemoveInt16(int16 &value)
status_t RemoveUint16(uint16 &value)
status_t RemoveInt32(int32 &value)
status_t RemoveUint32(uint32 &value)
status_t RemoveInt64(int64 &value)
status_t RemoveUint64(uint64 &value)
status_t RemoveFloat(float &value)
status_t RemoveDouble(double &value)
status_t RemoveString(char *string, size_t size)
status_t RemoveData(void *data, size_t size)
status_t RemoveMessage(BMessage &message)

Removes the specified data type from the buffer. Integer values are automatically converted from network byte ordering (but floats and doubles are not, nor are values inside structures removed using RemoveData()).

Strings are removed as null-terminated strings, up to size bytes. Be sure the string buffer is at least size bytes long.

RemoveData() removes size bytes and copies them into the buffer pointed at by data. Be sure the data buffer is at least size bytes long.

These functions start at the beginning of the buffer. After each item is removed, the next Remove...() call will start at the next byte in the buffer.

RETURN CODES


Size() see Data()


Operators


= (assignment)

BNetBuffer &operator =(const BNetBuffer &from)

Copies the BNetBuffer specified by from into the left-side object, thereby duplicating that object. If from is connected, the left-side object will duplicate and open the same connection. Even the data in the buffer is copied, if there is any.


The Be Book The Network Kit The Network Kit Index

The Be Book,
...in lovely HTML...
for BeOS Release 5.

Copyright © 2000 Be, Inc. All rights reserved..