public void   WriteObject(Amf3Writer writer, object obj)
        {
            if (obj.GetType() != mType)
            {
                throw new Exception("Serializer type mismatch");
            }

            // begin write
            writer.WriteObjectHeader(mClassDef);

            // write all fields using reflection
            foreach (var field in mFieldList)
            {
                // get field value and write it
                object value = field.GetValue(obj);
                writer.Write(value);
            }

            // read all properties using reflection
            foreach (var property in mPropertyList)
            {
                // get property value and write it
                object value = property.GetValue(obj, null);
                writer.Write(value);
            }
        }
Beispiel #2
0
			public int    delta;	// time since last span (in microseconds)

			#region IAmf3Serializable implementation
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(name);
				writer.Write(span);
				writer.Write(delta);
			}
Beispiel #3
0
        public AmfWriter(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Stream     = stream;
            amf3Writer = new Amf3Writer(stream);
        }
Beispiel #4
0
        // this function parses json text, generates class definitions, and writes object graph to output stream
        public static void JsonStringToAmfStream(string jsonText, Stream outStream, bool generateClassDefinitions)
        {
            // parse json
            object jsonRoot = _root.JSON.parse(jsonText);

            // generate class definitions (optionally)
            if (generateClassDefinitions)
            {
                GenerateAndApplyClassDefinitions(jsonRoot);
            }

            // write to amf stream
            var amfWriter = new Amf3Writer(outStream);

            amfWriter.Write(jsonRoot);
        }
Beispiel #5
0
        // this function gets all the default values for a type by creating a dummy instance and serializing them in and out
        public static Amf3Object GetClassDefaultsAsObject(System.Type type)
        {
            // serialize to stream
            var stream    = new MemoryStream();
            var amfWriter = new Amf3Writer(stream);

            // write the defaults to amf stream
            amfWriter.WriteDefaultObjectForType(type);

            stream.Position = 0;

            // read back defaults object
            var amfReader = new Amf3Parser(stream);

            amfReader.OverrideSerializer = new Amf3Object.Serializer();
            return(amfReader.ReadNextObject() as Amf3Object);
        }
Beispiel #6
0
		public Log(Stream stream, bool autoCloseStream = true, int capacity = 1 * 1024)
		{
			mStream = stream;
			mAutoCloseStream = autoCloseStream;

			// allocate log buffer (this can grow)
			mLog   = new LogEntry[capacity];
			mCount = 0;

			// create AMF writer from stream
			mOutput = new Amf3Writer(stream);
			mOutput.TrackArrayReferences = false;

			// set log start time
			mLogStartTime = Stopwatch.GetTimestamp();

			// set log timebase (in microseconds)
			mTimeBase = ToMicroSeconds(mLogStartTime);
		}
Beispiel #7
0
        public void Serialize(Amf3Writer writer)
        {
            writer.WriteObjectHeader(ClassDef, this);

            // write class properties
            for (int i = 0; i < Values.Length; i++)
            {
                writer.Write(Values[i]);
            }

            if (ClassDef.Dynamic)
            {
                // write dynamic properties
                // TODO: this is a little weird and shouldnt be here.. should be handled by the writer
                foreach (var kvp in DynamicProperties)
                {
                    writer.TypelessWrite(kvp.Key);
                    writer.Write(kvp.Value);
                }

                // write terminator
                writer.TypelessWrite("");
            }
        }
Beispiel #8
0
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(name);
				writer.Write(value);
			}
        public void   WriteObject(Amf3Writer writer, object obj)
        {
            var expando = (ExpandoObject)obj;

            writer.Write(expando);
        }
Beispiel #10
0
		public void Serialize(Amf3Writer writer)
		{
			writer.Write(this);
		}
Beispiel #11
0
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(xmin);
				writer.Write(xmax);
				writer.Write(ymin);
				writer.Write(ymax);
			}
Beispiel #12
0
 public void Serialize(Amf3Writer writer)
 {
     writer.Write(this);
 }
Beispiel #13
0
		private static void FlushLog(Amf3Writer output)
		{
			// write all log entries
			for (int i=0; i < sLogCount; i++) {
				WriteLogEntry(ref sLog[i], ref sLogTimeBase, output);
			}
			// clear log
			sLogCount = 0;
		}
Beispiel #14
0
		private static void WriteLogEntry(ref LogEntry entry, ref int timeBase, Amf3Writer output)
		{
			if (entry.Span == LogValue) {
				// emit Value
				output.WriteObjectHeader(Protocol.Value.ClassDef);
				output.Write(entry.Name);
				output.Write(entry.Value);
			} else 	if (entry.Span == LogTime) {
				// emit Time
				int time = ToMicroSeconds(entry.Time);
				int delta = time - timeBase; 
				timeBase = time;

				output.WriteObjectHeader(Protocol.Time.ClassDef);
				output.Write(entry.Name);
				output.Write(delta);
			} else {
				// emit Span or SpanValue
				// convert times to microseconds for output
				int time      = ToMicroSeconds(entry.Time);
				int beginTime = ToMicroSeconds(entry.Time - entry.Span);

				// compute span and delta in microseconds
				// this must be done this exact way to preserve rounding errors across spans
				// if not, the server may produce an error if a span exceeds its expected length
				int span  = time - beginTime;
				int delta = time - timeBase; 
				timeBase = time;

				if (entry.Value == null) {
					output.WriteObjectHeader(Protocol.Span.ClassDef);
					output.Write(entry.Name);
					output.Write(span);
					output.Write(delta);
				} else {
					output.WriteObjectHeader(Protocol.SpanValue.ClassDef);
					output.Write(entry.Name);
					output.Write(span);
					output.Write(delta);
					output.Write(entry.Value);
				}
			}
		}
Beispiel #15
0
		private static void BeginSession(Stream stream)
		{
			// create AMF writer from stream
			sOutput = new Amf3Writer(stream);
			sOutput.TrackArrayReferences = false;

			// reset time marker
			ResetLog();

			var appName = PlayScript.Player.ApplicationClass.Name;
			var swfVersion = 21;
			var swfSize = 4 * 1024 * 1024;

			// write telemetry version
			WriteValue(".tlm.version", Session.Version);
			WriteValue(".tlm.meta", Session.Meta);

			// write player info
			WriteValue(".player.version", "11,8,800,94");
//			WriteValue(".player.airversion", "3.8.0.910");
			WriteValue(".player.type", "PlayScript");
			WriteValue(".player.debugger", flash.system.Capabilities.isDebugger); 
			WriteValue(".player.global.date", new _root.Date().getTime());
			WriteValue(".player.instance", 0);
			WriteValue(".player.scriptplayerversion", swfVersion);

#if PLATFORM_MONOMAC
			// write platform info (this is faked)
			WriteValue(".platform.capabilities", "&M=Adobe%20Macintosh&R=1920x1200&COL=color&AR=1.0&OS=Mac%20OS%2010.7.4&ARCH=x86&L=en&PR32=t&PR64=t&LS=en;ja;fr;de;es;it;pt;pt-PT;nl;sv;nb;da;fi;ru;pl;zh-Hans;zh-Hant;ko;ar;cs;hu;tr");
			WriteValue(".platform.cpucount", 4);

			// write gpu info (this is faked)
			WriteValue(".platform.gpu.kind", "opengl");

#else
			// write platform info (this is faked)
			WriteValue(".platform.capabilities", "&M=Adobe iOS&R=640x960&COL=color&AR=1&OS=iPhone OS 6.1 iPhone5,1&ARCH=ARM&L=en&IME=false&PR32=true&PR64=false&LS=en;fr;de;ja;nl;it;es;pt;pt-PT;da;fi;nb;sv;ko;zh-Hans;zh-Hant;ru;pl;tr;uk;ar;hr;cs;el;he;ro;sk;th;id;ms;en-GB;ca;hu;vi");
			WriteValue(".platform.cpucount", 2);

			// write gpu info (this is faked)
			WriteValue(".platform.gpu.kind", "opengles2");
			WriteValue(".platform.gpu.vendor", "Imagination Technologies");
			WriteValue(".platform.gpu.renderer", "PowerVR SGX 535");
			WriteValue(".platform.gpu.version", "OpenGL ES 2.0 IMGSGX535-63.24");
			WriteValue(".platform.gpu.shadinglanguageversion", "OpenGL ES GLSL ES 1.0");
			WriteValue(".platform.3d.driverinfo", "OpenGL Vendor=Imagination Technologies Version=OpenGL ES 2.0 IMGSGX535-63.24 Renderer=PowerVR SGX 535 GLSL=OpenGL ES GLSL ES 1.0");
#endif


			// write memory stats
			WriteValue(".mem.total", 8 * 1024);
			WriteValue(".mem.used", 4 * 1024);
			WriteValue(".mem.managed", 0);
			WriteValue(".mem.managed.used", 0);
			WriteValue(".mem.telemetry.overhead", 0);

			// write telemetry categories
			WriteValue(".tlm.category.disable",  "3D");
			WriteValue(".tlm.category.disable",  "sampler");
			WriteValue(".tlm.category.disable",  "displayobjects");
			WriteValue(".tlm.category.enable",   "alloctraces");
			WriteValue(".tlm.category.disable",  "allalloctraces");
			WriteValue(".tlm.category.enable",   "customMetrics");

			WriteValue(".network.loadmovie", "app:/" + appName );
			WriteValue(".rend.display.mode", "auto");

			// SWF startup timestamp
			WriteTime(".swf.start");

			// write swf stats
			WriteSWFStats(appName, 800, 600, 60, swfVersion, swfSize);

			// write memory stats
			WriteMemoryStats();

			// start detailed metrics
			WriteValue(".tlm.category.start", "alloctraces");
			WriteValue(".tlm.category.start", "customMetrics");

			// enable 'advanced telemetry'
			WriteValue(".tlm.detailedMetrics.start", true);

			Flush();
		}
Beispiel #16
0
            public void   WriteObject(Amf3Writer writer, object obj)
            {
                var amfObj = (Amf3Object)obj;

                amfObj.Serialize(writer);
            }
Beispiel #17
0
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(xmin);
				writer.Write(xmax);
				writer.Write(ymin);
				writer.Write(ymax);
				writer.Write(name);
				writer.Write(symbolname);
				writer.Write(modified);
			}
Beispiel #18
0
 void IAmf3Serializable.Serialize(Amf3Writer writer)
 {
     writer.Write(this);
 }
Beispiel #19
0
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(time);
				writer.Write(id);
			}
Beispiel #20
0
			public void Serialize(Amf3Writer writer)
			{
				writer.WriteObjectHeader(ClassDef);
				writer.Write(time);
				writer.Write(numticks);
				writer.Write(ticktimes);
				writer.Write(callstack);
			}
Beispiel #21
0
		void IAmf3Serializable.Serialize(Amf3Writer writer)
		{
			writer.Write(this);
		}