Avoid LocalConnection 40k Size Limit When a Data Object Can Be Greater Than 40k

The Flash engine LocalConnectionhas a file size limit of 40k for individual messages sent to send(). I am faced with a situation where I have a complex object that I need to send, which may turn out to be too large.

I can split the object into several smaller ones, but I want to do it in an efficient way. Perhaps I can have hundreds of smaller objects, and I don’t want to send them separately. In addition, each object can be of arbitrary size, so I can’t just select a certain number to group them.

Is there a way to determine the size of an object before sending it? If so, I could use this to do some quick calculations, and then split the object somewhat optimally (or just send directly if it's small enough).

+3
source share
2 answers

I found a way to at least estimate the size of an object before sending it to LocalConnection by creating a temporary SharedObject with data. Since SharedObject is not written to disk, it works even if local storage is not allowed.

Here is the function I'm going to use to determine the size:

public static function getObjectSize(o:Object):Number {
  var so:SharedObject = SharedObject.getLocal("__getObjectSizeHelper");
  so.data.o = o;
  var size:Number = so.getSize();
  so.clear();
  return size;
}

, , . , ( 100%, , , , , ). , . , . , , ( , 1 , 2 3).

.

, , :

public static function isTooBigForLC(o:Object):Boolean {
  return getObjectSize(o) > 35000;
}

public static function splitArrayForLC(a:Array):Array {
  if (!isTooBigForLC(a)) { return [a]; }

  if (a.length <= 1) {
    LOG.warn("individual object is too big for LocalConnection! Skipping");
    return [];
  }

  var mid:Number = Math.floor(a.length / 2);

  var left:Array = splitArrayForLC(a.slice(0, mid));
  var right:Array = splitArrayForLC(a.slice(mid));

  return left.concat(right);
}

, , "" . .

( ) :

http://gist.github.com/224258

+1

100%, Ultrashock , : http://www.ultrashock.com/forums/actionscript/40k-byte-size-limit-on-localconnection-56395.html

" XML , . , LocalConnection, . " " 40K."

, , , .

0

Source: https://habr.com/ru/post/1721327/


All Articles