PDG engine v0.9.5
 All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | List of all members
MemBlock Class Reference

holds arbitrary blocks of memory More...

Public Member Functions

number getByte (uint i)
 get a single byte from an specific location in the block More...
 
BinaryString getBytes (uint start, uint len)
 get a subset of the memory block More...
 
BinaryString getData ()
 get the data as a JavaScript string More...
 
number getDataSize ()
 get the number of bytes in the block More...
 
Buffer toBuffer ()
 convert MemBlock to Node.js Buffer object More...
 

Detailed Description

holds arbitrary blocks of memory

Note
API Stability: 2 - Unstable. The API is in the process of settling, but has not yet had sufficient real-world testing to be considered stable. Backwards-compatibility will be maintained if reasonable.

Many functions of PDG, such as Image and Resource data, Streaming I/O, and Networking deal with blocks of memory. Since JavaScript has no way to natively deal with these, PDG adds the MemBlock class to pass those blocks of data between various parts of the PDG libraries.

This class is very similar to the Node.js Buffer class, but has no Node.js dependencies.

Member Function Documentation

getByte ( uint  i)

get a single byte from an specific location in the block

Parameters
ithe offset to the desired byte within the block
Returns
the byte value stored at the offset (0..255)
getBytes ( uint  start,
uint  len 
)

get a subset of the memory block

The data is returned as a JavaScript string with binary data (values from 0..255 represented in JavaScript's native 2 byte per char string format). Use pdg.log.binaryDump() to see the data contents in a human readable hex-dump form.

Parameters
startthe offset in the block to start from
lenthen number of bytes to fetch
Returns
a JavaScript string with binary data
See Also
LogManager.binaryDump
getData ( )

get the data as a JavaScript string

The data is returned as a JavaScript string with binary data (values from 0..255 represented in JavaScript's native 2 byte per char string format). Use pdg.log.binaryDump() to see the data contents in a human readable hex-dump form.

Returns
a JavaScript string with binary data
See Also
LogManager.binaryDump
getDataSize ( )

get the number of bytes in the block

Returns
the count of bytes in the block
toBuffer ( )

convert MemBlock to Node.js Buffer object

Converts a MemBlock into a Node.js Buffer object. See Node.js docs for details on the Buffer class. This makes it easier to use a MemBlock with Node.js calls that work with Buffers.

User Comments