buffer_peek

The buffer_peek function reads a piece of data of a certain type from the given buffer at an arbitrary offset position (in bytes).

Like the buffer_read function, this function also reads data from a buffer. buffer_read(), however, always reads at the buffer's current "seek" position and advances this position by the number of bytes being read. This function allows you to read a given piece of data without changing the current seek position. You simply supply the function with a buffer, and then an offset position (from the buffer start) within that buffer to read from, as well as the data type that you want to read.

NOTE Using the incorrect data type for the data being read will result in erroneous values!

If the function succeeds it returns the value that was read (a real, string, boolean, etc.), if it fails it returns simply undefined.

 

Syntax:

buffer_peek(buffer, offset, type);

Argument Type Description
buffer Buffer The buffer to use.
offset Real The offset position (in bytes) within the buffer to read the given data from.
type Buffer Data Type Constant The type of data that is to be read from the buffer (see the list of constants here).

 

Returns:

Real, BooleanString or undefined (if it fails)

 

Example:

var _red = buffer_peek(buff, 1, buffer_u8);
var _green = buffer_peek(buff, 2, buffer_u8);
var _blue = buffer_peek(buff, 3, buffer_u8);
image_blend = make_colour_rgb(_red, _green, _blue);

The above code gets three values from three different positions within the buffer stored in the variable buff and then uses those values to set the image_blend of the calling instance.