/// <summary> /// Reads an object from the underling stream. /// </summary> /// <param name="amfTypeMarker"> /// An <see cref="T:Photon.SocketServer.Rpc.Protocols.Amf3.Amf3TypeMarker"/> which indicates which type of object to read. /// </param> /// <param name="result"> /// The result. /// </param> /// <returns> /// The object that has been read. /// </returns> private bool Read(Amf3TypeMarker amfTypeMarker, out object result) { switch (amfTypeMarker) { case Amf3TypeMarker.Undefined: case Amf3TypeMarker.Null: result = null; return(true); case Amf3TypeMarker.False: result = false; return(true); case Amf3TypeMarker.True: result = true; return(true); case Amf3TypeMarker.Integer: result = this.ReadInteger(); return(true); case Amf3TypeMarker.Double: result = this.binaryReader.ReadDouble(); return(true); case Amf3TypeMarker.String: string str; if (!this.ReadString(out str)) { result = null; return(true); } result = str; return(true); case Amf3TypeMarker.Date: return(this.ReadDateTime(out result)); case Amf3TypeMarker.Array: return(this.ReadArray(out result)); case Amf3TypeMarker.Object: return(this.ReadObject(out result)); case Amf3TypeMarker.ByteArray: result = this.ReadByteArray(); return(true); } if (log.IsDebugEnabled) { log.DebugFormat("Unknown amf3 type marker {0} at position {1}", new object[] { amfTypeMarker, this.binaryReader.BaseStream.Position }); } result = null; return(false); }
/// <summary> /// Convert type marker to an AMFX type name. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string ToAmfxName(this Amf3TypeMarker value) { switch (value) { case Amf3TypeMarker.Null: case Amf3TypeMarker.Undefined: return(AmfxContent.Null); case Amf3TypeMarker.False: return(AmfxContent.False); case Amf3TypeMarker.True: return(AmfxContent.True); case Amf3TypeMarker.Integer: return(AmfxContent.Integer); case Amf3TypeMarker.Double: return(AmfxContent.Double); case Amf3TypeMarker.String: return(AmfxContent.String); case Amf3TypeMarker.Date: return(AmfxContent.Date); case Amf3TypeMarker.ByteArray: return(AmfxContent.ByteArray); case Amf3TypeMarker.Xml: case Amf3TypeMarker.XmlDocument: return(AmfxContent.Xml); case Amf3TypeMarker.Array: return(AmfxContent.Array); case Amf3TypeMarker.Object: return(AmfxContent.Object); default: throw new NotSupportedException("Type '" + value + "' is not supported."); } }
/// <summary> /// Read a value of a given type from current reader's position. /// </summary> /// <remarks> /// Current reader position must be just after a value type marker of a type to read. /// </remarks> /// <param name="context"> /// AMF decoding context. /// </param> /// <param name="reader"> /// AMF reader. /// </param> /// <param name="type"> /// Type of the value to read. /// </param> /// <param name="output"> /// AMFX output. /// </param> /// <exception cref="NotSupportedException"> /// AMF type is not supported. /// </exception> /// <exception cref="FormatException"> /// Unknown data format. /// </exception> /// <exception cref="SerializationException"> /// Error during deserialization. /// </exception> private void ReadValue(AmfContext context, AmfStreamReader reader, Amf3TypeMarker type, XmlWriter output = null) { #if DEBUG Debug.WriteLine(Errors.Amf3Decoder_ReadValue_Debug, type, reader.BaseStream.Position); #endif switch (type) { case Amf3TypeMarker.Null: case Amf3TypeMarker.Undefined: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.False: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.True: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.Integer: ReadInteger(reader, output); break; case Amf3TypeMarker.Double: ReadDouble(reader, output); break; case Amf3TypeMarker.String: ReadString(context, reader, output); break; case Amf3TypeMarker.Date: ReadDate(context, reader, output); break; case Amf3TypeMarker.ByteArray: ReadByteArray(context, reader, output); break; case Amf3TypeMarker.Xml: case Amf3TypeMarker.XmlDocument: ReadXml(context, reader, output); break; case Amf3TypeMarker.Array: this.ReadArray(context, reader, output); break; case Amf3TypeMarker.Object: this.ReadObject(context, reader, output); break; default: throw new NotSupportedException("Type '" + type + "' is not supported."); } if (output != null) { output.Flush(); } }
/// <summary> /// Write an AMF0 type marker. /// </summary> private static void WriteTypeMarker(AmfStreamWriter writer, Amf3TypeMarker marker) { writer.Write((byte)marker); }
/// <summary> /// Write an AMF0 type marker. /// </summary> /// <param name="writer"> /// The writer. /// </param> /// <param name="marker"> /// The marker. /// </param> private static void WriteTypeMarker(AmfStreamWriter writer, Amf3TypeMarker marker) { writer.Write((byte)marker); }
/// <summary> /// Read a value of a given type from current reader's position. /// </summary> /// <remarks> /// Current reader position must be just after a value type marker of a type to read. /// </remarks> /// <param name="context">AMF decoding context.</param> /// <param name="reader">AMF reader.</param> /// <param name="type">Type of the value to read.</param> /// <param name="output">AMFX output.</param> /// <exception cref="NotSupportedException">AMF type is not supported.</exception> /// <exception cref="FormatException">Unknown data format.</exception> /// <exception cref="SerializationException">Error during deserialization.</exception> private void ReadValue(AmfContext context, AmfStreamReader reader, Amf3TypeMarker type, XmlWriter output = null) { #if DEBUG Debug.WriteLine(string.Format(Errors.Amf3Decoder_ReadValue_Debug, type, reader.BaseStream.Position)); #endif switch (type) { case Amf3TypeMarker.Null: case Amf3TypeMarker.Undefined: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.False: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.True: WriteEmptyElement(type.ToAmfxName(), output); break; case Amf3TypeMarker.Integer: ReadInteger(reader, output); break; case Amf3TypeMarker.Double: ReadDouble(reader, output); break; case Amf3TypeMarker.String: ReadString(context, reader, output); break; case Amf3TypeMarker.Date: ReadDate(context, reader, output); break; case Amf3TypeMarker.ByteArray: ReadByteArray(context, reader, output); break; case Amf3TypeMarker.Xml: case Amf3TypeMarker.XmlDocument: ReadXml(context, reader, output); break; case Amf3TypeMarker.Array: ReadArray(context, reader, output); break; case Amf3TypeMarker.Object: ReadObject(context, reader, output); break; default: throw new NotSupportedException("Type '" + type + "' is not supported."); } if (output != null) output.Flush(); }
/// <summary> /// Reads the next object from the underling stream. /// </summary> /// <param name="result">The result.</param> /// <returns>The object that has been read.</returns> public bool Read(out object result) { Amf3TypeMarker amfTypeMarker = (Amf3TypeMarker)this.binaryReader.ReadByte(); return(this.Read(amfTypeMarker, out result)); }