Fast way to dump an array as a string in extension?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Fast way to dump an array as a string in extension?

Postby mixart » 29 Apr 2012, 13:04

Trying to find out if there is a fast way to dump a nested SFSarray as a string to a text file (in an extension).

It seems SFSArray.toString() only converts simple objects to strings, not a whole array (like actionscript does).

So I have to iterate through each array and sub array like this:

Code: Select all

String finalString = "";
   for(int i=0; i<mainArray.size(); i++){
            subArray = (ISFSArray) mainArray.getElementAt(i);
            for(int j=0; j<subArray.size(); j++){
                                       //my toString() here is because my array contains mixed data types so I need to convert them each to strings to save them to the final string
               subStr = subArray.getElementAt(j).toString();
               finalString += subStr;
            }
         }


Is there no easier/more efficient way to do this via the API?
P.s. My arrays are a few hundred K of data (sometimes approaching 1 MB).
User avatar
Lapo
Site Admin
Posts: 21685
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Fast way to dump an array as a string in extension?

Postby Lapo » 30 Apr 2012, 13:21

SFSArray.getDump() :)
Lapo
--
gotoAndPlay()
...addicted to flash games
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Fast way to dump an array as a string in extension?

Postby mixart » 01 May 2012, 07:17

Not really what I was after... getDump() includes a pretty huge bloated amount of data (text such as datatype for each piece of data and also lots of tab data, etc.).

E.g. a getDump outputs:

Code: Select all

(sfs_array)
               (utf_string) pen
               (utf_string) 154,75|1454,575|1154,475|81564,745|1354,765
               (int) 4
               (int) 100
               (utf_string) username27
(sfs_array)
               (utf_string) pen
               (utf_string) 154,75|1454,575|1154,475|81564,745|1354,765
               (int) 4
               (int) 100
               (utf_string) username27


When all I want is the data as a string like this:

Code: Select all

pen,154,75|1454,575|1154,475|81564,745|1354,765,4,100,username27,pen,154,75|1454,575|1154,475|81564,745|1354,765,4,100,username27


I guess I could replace/strip all the unnecessary data here, but that would probably be slower than just looping through the arrays to extract the data.

In my SFSx1 extension (actionscript extension) I simply used myArray.toString() to achieve this.
It would be really cool if in the API "toString" worked on Arrays in this way :)
User avatar
Lapo
Site Admin
Posts: 21685
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Fast way to dump an array as a string in extension?

Postby Lapo » 02 May 2012, 07:39

The SFSArray can contain any number of other SFSObject/Array nested within, therefore getDump() provides a full-depth view of the object.
Lapo

--

gotoAndPlay()

...addicted to flash games
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Fast way to dump an array as a string in extension?

Postby mixart » 02 May 2012, 11:01

I understand getdump and it's value - great for debugging. I was just hoping there was something for my needs - which is a dump that's compact for the purpose of saving data to a file that is imported into other web apps.

I ended up just using for loops - does the job.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 30 guests