This page has been translated automatically.
UnigineScript
The Language
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Buffer Class

This class allows to allocate buffers to store data in the memory (unlike File which is stored locally). The buffer uses either Unigine allocator (if #define USE_MEMORY is set, by default) or a system allocator.

Buffer Class

This class inherits from Stream

Members


Buffer (int size)

Constructor. Creates a new buffer of the specified size.

Arguments

  • int size - Buffer size.

void allocate (int size)

Allocates the required memory without resizing the buffer. (It will be resized dynamically when the allocated memory is filled).

Arguments

  • int size - Size of the allocated memory in bytes.

void clear ()

Clears the size of the buffer to 0.

int compress (Stream dest, int quality)

Compresses the buffer and writes it into the given stream.

Arguments

  • Stream dest - Destination stream.
  • int quality - Compression quality (0 is for a fast compression, 1 is for a small size).

Return value

Returns 1 if the data was successfully compressed; otherwise, 0.

int decode (string src)

Decodes a base64 encoded string into the buffer.

Arguments

  • string src - Source base64 encoded string.

Return value

Returns 1 if the data was successfully decoded; otherwise, 0.

int decompress (Stream src)

Reads and decompresses a previously compressed buffer from a given stream.

Arguments

  • Stream src - Stream to read data from.

Return value

Returns 1 if the buffer was successfully decompressed; otherwise, 0.

StringStack<256> encode ()

Encodes the buffer into the base64 encoded string.

Return value

Base64 encoded string.

int eof ()

Tests if the end of the buffer has been reached.

Return value

1 if the end of buffer is reached; otherwise, 0.

int flush ()

Flushes the buffer. This function has an empty body; it is created for Buffer class to have the same number of methods as File class has.

Return value

Returns 1 if the buffer was successfully flushed; otherwise, 0 is returned.

int getSize ()

Returns the current size of the buffer.

Return value

Size of the buffer.

int get (int offset)

Returns the value of the specified byte in the buffer.

Arguments

  • int offset - Offset in bytes.

Return value

Byte value.

int getc ()

Gets the next symbol from the buffer.

Return value

Character read from a buffer.

void reserve (int size)

Reserves the buffer, i.e. allocates (size * 1.5) bytes without resizing the buffer. (It will be resized dynamically when the allocated memory is filled).

Arguments

  • int size - Size of the allocated memory in bytes.

void resize (int size)

Allocates the required memory and resizes the buffer.

Arguments

  • int size - Size of the buffer in bytes.

int seekCur (int offset)

Seeks to position relative to the current offset.

Arguments

  • int offset - Offset in bytes from the current position of the indicator.

Return value

Returns 1 if the new buffer position indicator was successfully set; otherwise, 0 is returned.

int seekEnd (int offset)

Seeks to position relative to the end of the buffer.

Arguments

  • int offset - Offset in bytes from the end of the buffer.

Return value

Returns 1 if the buffer position indicator was successfully set; otherwise, 0 is returned.

int seekSet (int offset)

Seeks to position relative to the start of buffer.

Arguments

  • int offset - Offset in bytes from the beginning of the buffer.

Return value

Returns 1 if the buffer position indicator was successfully set; otherwise, 0 is returned.

void set (int offset, int value)

Sets the value of the specified byte in the buffer.

Arguments

  • int offset - Buffer offset.
  • int value - Byte value.

int tell ()

Gets the current buffer offset position indicator.

Return value

Returns the current buffer offset.
Last update: 2017-07-03
Build: ()