Monkey Documentation

Class DataBuffer

Databuffer objects provide storage for arbitrary data. More...


Constructors:
  • New ( length:Int, direct:Bool=false )
Properties:
Methods:
  • CopyBytes : Void ( srcAddress:Int, dst:DataBuffer, dstAddress:Int, count:Int )
  • Discard : Void ()
  • PeekByte : Int ( address:Int )
  • PeekBytes : Void ( address:Int, bytes:Int[], offset:Int, count:Int )
  • PeekFloat : Float ( address:Int )
  • PeekFloats : Void ( address:Int, floats:Float[], offset:Int, count:Int )
  • PeekInt : Int ( address:Int )
  • PeekInts : Void ( address:Int, ints:Int[], offset:Int, count:Int )
  • PeekShort : Int ( address:Int )
  • PeekShorts : Void ( address:Int, shorts:Int[], offset:Int, count:Int )
  • PeekString : String ( address:Int, encoding:String="utf8" )
  • PeekString : String ( address:Int, count:Int, encoding:String="utf8" )
  • PokeByte : Void ( address:Int, value:Int )
  • PokeBytes : Void ( address:Int, bytes:Int[], offset:Int, count:Int )
  • PokeFloat : Void ( address:Int, value:Float )
  • PokeFloats : Void ( address:Int, floats:Float[], offset:Int, count:Int )
  • PokeInt : Void ( address:Int, value:Int )
  • PokeInts : Void ( address:Int, ints:Int[], offset:Int, count:Int )
  • PokeShort : Void ( address:Int, value:Int )
  • PokeShorts : Void ( address:Int, shorts:Int[], offset:Int, count:Int )
  • PokeString : Int ( address:Int, value:String, encoding:String="utf8" )
Functions:
  • Load : DataBuffer ( path:String )
  • LoadAsync : Void ( path:String, onComplete:IOnLoadDataComplete )

Detailed Discussion

Databuffer objects provide storage for arbitrary data.

Data may be written to a databufffer using one of the 'poke' methods, and read from a databuffer using one of the 'peek' methods.

Parameters that specify buffer addresses or array indices for data transfers are not currently range checked. In general, you should always ensure that these are always valid, ie: >=0 And <=length of the buffer/array. Any transfer count parameters should always be >=0, but will always be clipped to make sure no overreads or overwrites occur.


Constructor Documentation

Method New ( length:Int, direct:Bool=false )

Creates a new data buffer of the specified byte length.

Values can be written into the databuffer using the various 'poke' methods, or read using the 'peek' methods.

The direct parameter should be set to true when creating VBO databuffers for use with OpenGL on android. Direct databuffers cannot be used for reading/writing streams. This parameter only affects the android target and is ignored on all other targets.


Property Documentation

Method Length : Int () Property

Returns the length, in bytes, of the data buffer.


Method Documentation

Method CopyBytes : Void ( srcAddress:Int, dst:DataBuffer, dstAddress:Int, count:Int )

Copies count bytes starting at srcAddress from this buffer to dst.

Method Discard : Void ()

Releases any resources used by the data buffer.

Once discarded, a data buffer should not be used again.

Method PeekByte : Int ( address:Int )

Returns the 8 bit byte contained in the databuffer at address.

Method PeekBytes : Void ( address:Int, bytes:Int[], offset:Int, count:Int )

Copies count bytes starting at address from the databuffer to bytes.

Data is written to bytes starting at index offset.

Method PeekFloat : Float ( address:Int )

Returns the 32 bit float value stored in the data buffer at address.

Method PeekFloats : Void ( address:Int, floats:Float[], offset:Int, count:Int )

Copies count 32 bit floats starting at address from the databuffer to bytes.

Data is written to data starting at index offset.

Method PeekInt : Int ( address:Int )

Returns the 32 bit int value contained in the data buffer at address.

Method PeekInts : Void ( address:Int, ints:Int[], offset:Int, count:Int )

Copies count 32 bit ints starting at address from the databuffer to bytes.

Data is written to ints starting at index offset.

Method PeekShort : Int ( address:Int )

Returns the 16 bit int value contained in the data buffer at address.

Method PeekShorts : Void ( address:Int, shorts:Int[], offset:Int, count:Int )

Copies count 16 bit shorts starting at address from the databuffer to bytes.

Data is written to shorts starting at index offset.

Method PeekString : String ( address:Int, encoding:String="utf8" )

Peeks and returns a string from the data buffer.

Data is read from address up until the end of the data buffer.

The encoding parameter should be one of:

EncodingDescription
"utf8"Unicode
"ascii"8 bit ascii

Method PeekString : String ( address:Int, count:Int, encoding:String="utf8" )

Peeks and returns a string from the data buffer.

Up to count bytes are read from the data buffer starting from address.

The encoding parameter should be one of:

EncodingDescription
"utf8"Unicode
"ascii"8 bit ascii

Method PokeByte : Void ( address:Int, value:Int )

Writes an 8 bit byte into the data buffer at address.

Method PokeBytes : Void ( address:Int, bytes:Int[], offset:Int, count:Int )

Copies count 8 bit bytes from the bytes array to the databuffer.

offset is the starting index within the source array, and address is the starting byte address within the databuffer.

Method PokeFloat : Void ( address:Int, value:Float )

Writes a 32 bit float value into the data buffer at address.

Method PokeFloats : Void ( address:Int, floats:Float[], offset:Int, count:Int )

Copies count 32 bit floats from the floats array to the databuffer.

offset is the starting index within the source array, and address is the starting byte address within the databuffer.

Method PokeInt : Void ( address:Int, value:Int )

Writes a 32 bit int value into the data buffer at address.

Method PokeInts : Void ( address:Int, ints:Int[], offset:Int, count:Int )

Copies count 32 bit ints from the ints array to the databuffer.

offset is the starting index within the source array, and address is the starting byte address within the databuffer.

Method PokeShort : Void ( address:Int, value:Int )

Writes a 16 bit int value into the data buffer at address.

Method PokeShorts : Void ( address:Int, shorts:Int[], offset:Int, count:Int )

Copies count 16 bit shorts from the shorts array to the databuffer.

offset is the starting index within the source array, and address is the starting byte address within the databuffer.

Method PokeString : Int ( address:Int, value:String, encoding:String="utf8" )

Pokes value into the data buffer at location address.

The encoding parameter should be one of:

EncodingDescription
"utf8"Unicode
"ascii"8 bit ascii

The returned value is the number of bytes poked into the databuffer.


Function Documentation

Function Load : DataBuffer ( path:String )

Creates and returns a databuffer containing the binary contents of the specified file.

If the file does not exist or cannot be read, null is returned instead.

See also Resource paths

Function LoadAsync : Void ( path:String, onComplete:IOnLoadDataComplete )

Loads a databuffer asynchronously.

When data has finished loading, the OnLoadDataComplete method of the onComplete object is called.

See also Resource paths