Carapace

Buffer Class

A Buffer is a useful class for the communications functions. It can be made to wrap up an existing String or Binary item and is typically used for sending or receiving data over a communications channel.

Buffer Creation

The following creates a Buffer with a space for 128 bytes:

    (create Buffer 128)

To create a buffer of the same size as a Binary or String object, and containing the same data:

    (create Buffer "Hello there!")

    (create Buffer 0x"0102030005")

Buffer Properties

None

Buffer Methods

method name description
length return the length of the buffered data
bufferLength return the length of the buffer -- ie. the maximum length of data which can be held
string convert the buffered data to a string -- note that strings are terminated by a null (hex value 00) character
binary convert the buffered data to a binary
fromFile fill the buffer with data from the contents of the supplied file
extract extract a range of bytes from the binary data and return them
append append the supplied bytes to the end of the buffered data
prepend prepend the supplied bytes at the start of the buffered data
reset reset the buffer, removing any stored data but keeping the buffer size unchanged
consume consume the supplied number of bytes from the beginning of the buffered data
== test equality of buffers
!= test inequality of buffers


length

Return the length of the buffered data.

Arguments: none

Return type: Integer


bufferLength

Return the length of the buffer -- ie. the maximum length of data which can be held within the buffer.

Arguments: none

Return type: Integer


string

Convert the buffered data to a string -- note that strings are terminated by a null (hex value 00) character.

Arguments: none

Return type: String


binary

Convert the buffered data to a binary .

Arguments: none

Return type: Binary


fromFile

Fill the buffer with data from the contents of the supplied file. This surgically alters the buffer.

Arguments:

filenameString

Return type: the empty List ()


extract

Extract a range of bytes from the buffered data and return them. This is similar to the substring method for a String.

Arguments:

startInteger
length (optional)Integer

Return type: Binary


append

Append the supplied bytes to the end of the buffered data. This surgically alters the buffer.

Arguments:

data String or Binary

Return type: the empty List () is returned.


prepend

Prepend the supplied bytes to the start of the buffered data. This surgically alters the buffer.

Arguments:

data String or Binary

Return type: the empty List () is returned.


reset

Reset the buffer, removing any stored data but keeping the buffer size unchanged.

Arguments: none

Return type: the empty List () is returned.


consume

Consume the supplied number of bytes from the beginning of the buffered data.

Arguments:

nBytes Integer

Return type: the empty List () is returned.


==

Test equality of buffers. If the items are the same, the Symbol true is returned, otherwise the empty List () is returned.

Arguments:

itemBinary

Return type: Symbol true or the empty List ()


!=

Test in-equality of buffers. If the items are the different, the Symbol true is returned, otherwise the empty List () is returned.

Arguments:

itemBinary

Return type: Symbol true or the empty List ()


Contents Index Current topic: objects Related links: built-in objects