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.
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")
| 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 |
lengthReturn the length of the buffered data.
Arguments: none
Return type: Integer
bufferLengthReturn 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
binaryConvert the buffered data to a binary .
Arguments: none
Return type: Binary
fromFileFill the buffer with data from the contents of the supplied file. This surgically alters the buffer.
Arguments:
| filename | String |
Return type: the empty List ()
extractExtract a range of bytes from the buffered data and return them. This is similar to the substring method for a String.
Arguments:
| start | Integer |
| length (optional) | Integer |
Return type: Binary
appendAppend 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.
prependPrepend 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.
resetReset the buffer, removing any stored data but keeping the buffer size unchanged.
Arguments: none
Return type: the empty List ()
is returned.
consumeConsume 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:
| item | Binary |
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:
| item | Binary |
Return type: Symbol true
or the empty List ()
| Contents | Index | Current topic: objects | Related links: built-in objects |