1 line
26 KiB
JavaScript
1 line
26 KiB
JavaScript
|
Ext.define("Ext.data.amf.Encoder",{alias:"data.amf.Encoder",config:{format:3},bytes:[],constructor:function(a){this.initConfig(a);this.clear()},clear:function(){this.bytes=[]},applyFormat:function(b){var a={0:{writeUndefined:this.write0Undefined,writeNull:this.write0Null,writeBoolean:this.write0Boolean,writeNumber:this.write0Number,writeString:this.write0String,writeXml:this.write0Xml,writeDate:this.write0Date,writeArray:this.write0Array,writeGenericObject:this.write0GenericObject},3:{writeUndefined:this.write3Undefined,writeNull:this.write3Null,writeBoolean:this.write3Boolean,writeNumber:this.write3Number,writeString:this.write3String,writeXml:this.write3Xml,writeDate:this.write3Date,writeArray:this.write3Array,writeGenericObject:this.write3GenericObject}}[b];if(a){Ext.apply(this,a);return b}else{return}},writeObject:function(b){var a=typeof(b);if(a==="undefined"){this.writeUndefined()}else{if(b===null){this.writeNull()}else{if(Ext.isBoolean(b)){this.writeBoolean(b)}else{if(Ext.isString(b)){this.writeString(b)}else{if(a==="number"||b instanceof Number){this.writeNumber(b)}else{if(a==="object"){if(b instanceof Date){this.writeDate(b)}else{if(Ext.isArray(b)){this.writeArray(b)}else{if(this.isXmlDocument(b)){this.writeXml(b)}else{this.writeGenericObject(b)}}}}else{}}}}}}},write3Undefined:function(){this.writeByte(0)},write0Undefined:function(){this.writeByte(6)},write3Null:function(){this.writeByte(1)},write0Null:function(){this.writeByte(5)},write3Boolean:function(a){if(a){this.writeByte(3)}else{this.writeByte(2)}},write0Boolean:function(a){this.writeByte(1);if(a){this.writeByte(1)}else{this.writeByte(0)}},encode29Int:function(d){var e=[],a=d,c,b;if(a==0){return[0]}if(a>2097151){c=a&255;e.unshift(c);a=a>>8}while(a>0){c=a&127;e.unshift(c);a=a>>7}for(b=0;b<e.length-1;b++){e[b]=e[b]|128}return e},write3Number:function(c){var d;var a=536870911,b=-268435455;if(c instanceof Number){c=c.valueOf()}if(c%1===0&&c>=b&&c<=a){c=c&a;d=this.encode29Int(c);d.unshift(4);this.writeBytes(d)}else{d=this.encodeDouble(c);d.unshift(5);this.writeBytes(d)}},write0Number:function(a){var b;if(a instanceof Number){a=a.valueOf()}b=this.encodeDouble(a);b.unshift(0);this.writeBytes(b)},encodeUtf8Char:function(h){var f=[],g,a,e,d;if(h<=127){f.push(h)}else{if(h<=2047){a=2}else{if(h<=65535){a=3}else{a=4}}d=128;for(e=1;e<a;e++){g=(h&63)|128;f.unshift(g);h=h>>6;d=(d>>1)|128}g=h|d;f.unshift(g)}return f},encodeUtf8String:function(d){var a,c=[];for(a=0;a<d.length;a++){var b=this.encodeUtf8Char(d.charCodeAt(a));Ext.Array.push(c,b)}return c},encode3Utf8StringLen:function(c){var a=c.length,b=[];if(a<=268435455){a=a<<1;a=a|1;b=this.encode29Int(a)}else{}return b},write3String:function(b){if(b==""){this.writeByte(6);this.writeByte(1)}else{var c=this.encodeUtf8String(b);var a=this.encode3Utf8StringLen(c);this.writeByte(6);this.writeBytes(a);this.writeBytes(c)}},encodeXInt:function(c,d){var b=[],a;for(a=0;a<d;a++){b.unshift(c&255);c=c>>8}return b},write0String:function(c){if(c==""){this.writeByte(2);this.writeBytes([0,0])}else{var d=this.encodeUtf8String(c);var b;var a;if(d.length<=65535){b=2;a=this.encodeXInt(d.length,2)}else{b=12;a=this.encodeXInt(d.length,4)}this.writeByte(b);this.writeBytes(a);this.writeBytes(d)}},write3XmlWithType:function(c,a){var e=this.convertXmlToString(c);if(e==""){this.writeByte(a);this.writeByte(1)}else{var d=this.encodeUtf8String(e);var b=this.encode3Utf8StringLen(d);this.writeByte(a);this.writeBytes(b);this.writeBytes(d)}},write3XmlDocument:function(a){this.write3XmlWithType(a,7)},write3Xml:function(a){this.write3XmlWithType(a,11)},write0Xml:function(b){var d=this.convertXmlToString(b);this.writeByte(15);var c=this.encodeUtf8String(d);var a=this.encodeXInt(c.length,4);this.writeBytes(a);this.writeBytes(c)},write3Date:function(a){this.writeByte(8);this.writeBytes(this.encode29Int(1));this.writeBytes(this.encodeDouble(new Number(a)))},write0Date:function(a){this.writeByte(11);this.writeBytes(this.encodeDouble(new Number(a)));this.writeBytes([0,0])},write3Array:function(b){this.writeByte(9);var a=b.length;a=a<<1;a=a|1;this.writeBytes(this.
|