Buffer2Complex - Read complex data from a buffer string

Top  Previous  Next

Syntax

<returnValue> := Buffer2Complex( <cDataBuffer>, @<outData>, [<nStringType>] )

Parameters

<cDataBuffer>

 

Buffer string of data to be analyzed according to <outData> and to be read into <outData>. The data type must be "C" for this analysis. If <cDatabuffer>'s type is not character,  Buffer2Complex returns the value NIL without doing anything.

 

<outData>

 

This parameter provides Buffer2Complex with the necessary structural information to analyze <cDataBuffer> and at the same time holds the target element(s) for the information extracted from <cDataBuffer>. <outData> will normally be the array that was passed to Complex2Buffer beforehand. It is used to determine the organization, length and type of the elements in <cDataBuffer> when they are read, converted and moved into the target elements in <outData>.

 

<nStringType>

 

This parameter's value determines the interpretation of all strings found in <cDataBuffer>. See Cockpit string types for details. The default for <nStringType> is STRINGTYPE_BINARY.

Return value

The converted complex data from <cDataBuffer>. If <outData> is passed by reference, <returnValue> is identical to <outData> after the call.

Description

Buffer2Complex analyzes the data buffer passed in as <cDataBuffer> according to the structural, type and length information found in <outData>. Each element extracted from <cDataBuffer> is assigned to a target element in <outData>. If structures are found in <outData>, their :Unlock() method is called.

 

Buffer2Complex is the inverse function to Complex2Buffer.

 

Data extraction from <cDataBuffer> into <outData> is done according to the following table.

 

Data type of target element in <outData>

Conversion of extracted string data before assignment to target element

Numeric

4 bytes are extracted from <cDataBuffer>. The data is interpreted as LONG value and Bin2L is applied before assignment to the target element in <outData>.

Character

String data is handled as requested in <nStringType>. See Cockpit string types for details.

Logical

4 bytes are extracted from <cDataBuffer>. If they resemble the LONG value 0, .F. is assigned to the target element, otherwise .T. is assigned to the target element in <outData>.

Undefined (NIL)

4 bytes are extracted from <cDataBuffer>. If they resemble the LONG value 0, the target element remains unchanged. Otherwise Bin2L is applied to the extracted string and the resulting LONG value is assigned to the target element in <outData>.

Structure

A string of :bufferSize bytes size is extracted from <cDataBuffer>. This string is assigned to the :buffer member of the structure object. After assignment the structure's :Unlock() method is called passing .T. as parameter to read back all pointer data.

Fake object

4 bytes are extracted from <cDataBuffer>. The data is interpreted as LONG value and Bin2L is applied. The resulting value is assigned to the :handle member of the object. If you expect a handle to be extracted from <cDataBuffer>, pass a newly created object of the appropriate class in <outData>.

COM interface

4 bytes are extracted from <cDataBuffer>. The data is interpreted as LONG value and Bin2L is applied. The resulting value is assigned to the :baseAddress member.  If you expect a base address of an interface to be extracted from <cDataBuffer>, pass a newly created interface object of the expected class in <outData>.

Array

Arrays are traversed from first to last element and the above extractions are applied to every element. If an array element is another array, this array is traversed before continuing in the containing array.

 

Classification

Core

Category

Array and string utility

Quick Info

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

See also

Complex2Buffer

Example

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "CockpitPlatformLibs.ch"

#INCLUDE "StringTypes.ch"

 

FUNCTION Main

 

LOCAL complexdata

LOCAL rect := RECT():New()

LOCAL buffer, value

 

* Initialize the RECT structure

rect:left := 10

rect:top  := 20

rect:right := 30

rect:bottom := 40

 

* Set up some complex data. Please note that the RECT structure does not contain

* pointer members and hence we don't have to release any pointer memory with

* UnlockComplex or Buffer2Complex.

complexData := { 1, .T., NIL, { rect, Window():New() } , "Test string" }

 

* Now put together the buffer string

buffer := Complex2Buffer(complexdata)

 

* Let's change some values in the buffer

buffer := Stuff(buffer,1,4,L2Bin(1234567890))  && The numeric value is changed

buffer := Stuff(buffer,5,4,L2Bin(0))           && The logical value is set to .F.

buffer := Stuff(buffer,9,4,L2Bin(1))           && The NIL value is changed to 1

buffer := Stuff(buffer,13,8,L2Bin(1)+L2Bin(2)) && The first two coordinates in

                                              && the RECT structure ar changed

 

* The Desktop-Window-Handle is prepared for return

buffer := Stuff(buffer,29,4,L2Bin(GetDesktopWindow():handle))

 

* Change "Test String" to "Fast string"

buffer := Stuff(buffer,33,4,"Fast")

 

* Now read the data back

Buffer2Complex(buffer,@complexdata)

 

* Display the changed data

? complexdata

? rect:left,rect:top,rect:right,rect:bottom,complexData[4][2]:handle

 

RETURN NIL