BNetBuffer

Constructor and Destructor

BNetBuffer()

BNetBuffer::BNetBuffer(size_t size = 0)
BNetBuffer::BNetBuffer(const BNetBuffer &from)
BNetBuffer::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 BNetBuffer::~BNetBuffer()

A typical destructor.

Member Functions

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

status_t BNetBuffer::AppendInt8(int8 value)
status_t BNetBuffer::AppendUint8(uint8 value)
status_t BNetBuffer::AppendInt16(int16 value)
status_t BNetBuffer::AppendUint16(uint16 value)
status_t BNetBuffer::AppendInt32(int32 value)
status_t BNetBuffer::AppendUint32(uint32 value)
status_t BNetBuffer::AppendInt64(int64 value)
status_t BNetBuffer::Appenduint64(uint64 value)
status_t BNetBuffer::AppendFloat(float value)
status_t BNetBuffer::AppendDouble(double value)
status_t BNetBuffer::AppendString(const char *string)
status_t BNetBuffer::AppendData(const void *data, size_t size)
status_t BNetBuffer::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 Code

Description

B_OK

The data was appended without error.

B_ERROR

The data couldn’t be appended.

Data(), Size(), BytesRemaining()

unsigned char *BNetBuffer::Data() const
size_t BNetBuffer::Size() const
size_t BNetBuffer::BytesRemaining() 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 BNetBuffer::RemoveInt8(int8 &value)
status_t BNetBuffer::RemoveUint8(uint8 &value)
status_t BNetBuffer::RemoveInt16(int16 &value)
status_t BNetBuffer::RemoveUint16(uint16 &value)
status_t BNetBuffer::RemoveInt32(int32 &value)
status_t BNetBuffer::RemoveUint32(uint32 &value)
status_t BNetBuffer::RemoveInt64(int64 &value)
status_t BNetBuffer::Removeuint64(uint64 &value)
status_t BNetBuffer::RemoveFloat(float &value)
status_t BNetBuffer::RemoveDouble(double &value)
status_t BNetBuffer::RemoveString(const char *string, size_t size)
status_t BNetBuffer::RemoveData(const void *data, size_t size)
status_t BNetBuffer::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 Code

Description

B_OK

The data was removed without error.

B_ERROR

The data couldn’t be removed.

Operators

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.