openfl
Version:
A fast, productive library for 2D cross-platform development.
289 lines (271 loc) • 7.06 kB
JavaScript
// Class: openfl.utils._internal.format.amf3.AMF3Writer
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../../../../hxClasses_stub").default;
var $hxEnums = require("./../../../../../hxEnums_stub").default;
var $import = require("./../../../../../import_stub").default;
function _$UInt_UInt_$Impl_$() {return require("./../../../../../_UInt/UInt_Impl_");}
function haxe_io_Bytes() {return require("./../../../../../haxe/io/Bytes");}
function haxe_io_Encoding() {return require("./../../../../../haxe/io/Encoding");}
function Type() {return require("./../../../../../Type");}
function Reflect() {return require("./../../../../../Reflect");}
function openfl_Lib() {return require("./../../../../../openfl/Lib");}
function openfl_utils_ByteArrayData() {return require("./../../../../../openfl/utils/ByteArrayData");}
function openfl_utils__$ByteArray_ByteArray_$Impl_$() {return require("./../../../../../openfl/utils/_ByteArray/ByteArray_Impl_");}
function Lambda() {return require("./../../../../../Lambda");}
// Constructor
var AMF3Writer = function(o) {
this.o = o;
o.set_bigEndian(true);
}
// Meta
AMF3Writer.__name__ = "openfl.utils._internal.format.amf3.AMF3Writer";
AMF3Writer.__isInterface__ = false;
AMF3Writer.prototype = {
writeInt: function(i) {
if(i > 268435455 || i < -268435456) {
this.o.writeByte(5);
this.o.writeDouble(i);
} else {
this.o.writeByte(4);
this.writeUInt(i);
}
},
writeUInt: function(u,shiftLeft) {
if(shiftLeft == null) {
shiftLeft = false;
}
if(shiftLeft) {
u = u << 1 | 1;
}
if((u >>> 31 & 1) == 1) {
u = u & 536870911;
}
var bits = 22;
var started = false;
var chunk = u >>> bits - 1;
if((_$UInt_UInt_$Impl_$().default).gt(chunk,0)) {
chunk = chunk >>> 1;
this.o.writeByte(chunk | 128);
u = u - (chunk << bits);
++bits;
started = true;
}
bits -= 8;
chunk = u >>> bits;
if(started || (_$UInt_UInt_$Impl_$().default).gt(chunk,0)) {
this.o.writeByte(chunk | 128);
u = u - (chunk << bits);
started = true;
}
bits -= 7;
chunk = u >>> bits;
if(started || (_$UInt_UInt_$Impl_$().default).gt(chunk,0)) {
this.o.writeByte(chunk | 128);
u = u - (chunk << bits);
started = true;
}
this.o.writeByte(u);
},
writeString: function(s) {
var bytes = (haxe_io_Bytes().default).ofString(s,(haxe_io_Encoding().default).UTF8);
this.writeUInt(bytes.length,true);
this.o.writeBytes(bytes,0,bytes.length);
},
writeIntVector: function(v) {
this.writeUInt(v.get_length(),true);
this.o.writeByte(v.fixed ? 1 : 0);
var _g = 0;
var _g1 = v.get_length();
while(_g < _g1) {
var r = _g++;
this.o.writeInt32(v[r]);
}
},
writeFloatVector: function(v) {
this.writeUInt(v.get_length(),true);
this.o.writeByte(v.fixed ? 1 : 0);
var _g = 0;
var _g1 = v.get_length();
while(_g < _g1) {
var r = _g++;
this.o.writeDouble(v[r]);
}
},
writeObjectVector: function(v,type) {
this.writeUInt(v.get_length(),true);
this.o.writeByte(v.fixed ? 1 : 0);
this.o.writeString(type);
var _g = 0;
var _g1 = v.get_length();
while(_g < _g1) {
var r = _g++;
this.write(v[r]);
}
},
writeObject: function(h,size,className) {
if(size == null) {
this.o.writeByte(11);
} else {
this.writeUInt(size << 4 | 3);
}
this.o.writeByte(1);
if(size == null) {
var f = h.keys();
while(f.hasNext()) {
var f1 = f.next();
this.writeString(f1);
this.write(h.get(f1));
}
this.o.writeByte(1);
} else {
var k = [];
var f2 = h.keys();
while(f2.hasNext()) {
var f3 = f2.next();
k.push(f3);
this.writeString(f3);
}
var _g = 0;
var _g1 = k.length;
while(_g < _g1) {
var i = _g++;
this.write(h.get(k[i]));
}
}
},
writeExternal: function(external) {
var isExternal = true;
var isDynamic = false;
var traitsCount = 0;
this.writeUInt(3 | (isExternal ? 4 : 0) | (isDynamic ? 8 : 0) | traitsCount << 4);
var cls = (Type().default).getClass(external);
var className = null;
if((Reflect().default).hasField((openfl_Lib().default).__registeredClasses,cls)) {
className = (Reflect().default).field((openfl_Lib().default).__registeredClasses,cls);
}
if(className == null) {
className = (Type().default).getClassName(cls);
}
this.writeString(className);
var this1 = new (openfl_utils_ByteArrayData().default)(0);
var ba = this1;
ba.set_endian("bigEndian");
external.writeExternal(ba);
this.o.writeBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(ba),0,(openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(ba));
},
write: function(v) {
var o = this.o;
switch(v._hx_index) {
case 0:
o.writeByte(0);
break;
case 1:
o.writeByte(1);
break;
case 2:
var b = v.b;
o.writeByte(b ? 3 : 2);
break;
case 3:
var i = v.i;
this.writeInt(i);
break;
case 4:
var n = v.f;
o.writeByte(5);
o.writeDouble(n);
break;
case 5:
var s = v.s;
o.writeByte(6);
this.writeString(s);
break;
case 6:
var d = v.d;
o.writeByte(8);
o.writeByte(1);
o.writeDouble(d.getTime());
break;
case 7:
var className = v.className;
var n1 = v.size;
var h = v.fields;
o.writeByte(10);
this.writeObject(h,n1,className);
break;
case 8:
var e = v.o;
o.writeByte(10);
this.writeExternal(e);
break;
case 9:
var extra = v.extra;
var a = v.values;
o.writeByte(9);
this.writeUInt(a.length,true);
if(extra != null) {
var mk = extra.keys();
while(mk.hasNext()) {
var mk1 = mk.next();
o.writeString(mk1);
this.write(extra.get(mk1));
}
}
o.writeByte(1);
var _g = 0;
while(_g < a.length) {
var f = a[_g];
++_g;
this.write(f);
}
break;
case 10:
var v1 = v.v;
o.writeByte(13);
this.writeIntVector(v1);
break;
case 11:
var v2 = v.v;
o.writeByte(15);
this.writeFloatVector(v2);
break;
case 12:
var _g15 = v.type;
var v3 = v.v;
o.writeByte(16);
this.writeObjectVector(v3);
break;
case 13:
var x = v.x;
o.writeByte(11);
this.writeString(x.toString());
break;
case 14:
var b1 = v.ba;
o.writeByte(12);
this.writeUInt((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(b1),true);
o.write((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(b1));
break;
case 15:
var m = v.m;
o.writeByte(17);
this.writeUInt((Lambda().default).count(m),true);
o.writeByte(0);
var f1 = m.keys();
while(f1.hasNext()) {
var f2 = f1.next();
this.write(f2);
this.write(m.get(f2));
}
break;
}
}
};
AMF3Writer.prototype.__class__ = AMF3Writer.prototype.constructor = $hxClasses["openfl.utils._internal.format.amf3.AMF3Writer"] = AMF3Writer;
// Init
// Statics
// Export
exports.default = AMF3Writer;