The Network Kit Table of Contents | The Network Kit Index |
Derived from: BArchivable
Declared in: be/net/NutBuffer.h
Library: libnetapi.so
Allocation: Constructor only
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.
|
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.
|
A typical destructor.
|
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
B_OK. The data was appended without error.
|
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.
|
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
B_OK. The data was removed without error.
|
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 Network Kit Table of Contents | The Network Kit Index |
Copyright © 2000 Be, Inc. All rights reserved..