public override sealed AmfHeaderDescriptor ReadPacketHeader(Stream stream) { var reader = new AmfStreamReader(stream); var context = CreateDefaultContext(); try { var descriptor = new AmfHeaderDescriptor { Name = ReadString(reader), MustUnderstand = reader.ReadBoolean() }; reader.ReadInt32(); //Header length context.ResetReferences(); return descriptor; } catch (Exception e) { throw new FormatException(Errors.Amf0Deserializer_ReadPacketHeaders_InvalidFormat, e); } }
/// <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 stream 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, Amf0TypeMarker type, XmlWriter output = null) { switch (type) { case Amf0TypeMarker.Null: case Amf0TypeMarker.Undefined: break; case Amf0TypeMarker.Boolean: reader.ReadBoolean(); break; case Amf0TypeMarker.Number: reader.ReadDouble(); break; case Amf0TypeMarker.String: ReadString(reader, output); break; case Amf0TypeMarker.LongString: ReadLongString(reader, output); break; case Amf0TypeMarker.Date: ReadDate(reader, output); break; case Amf0TypeMarker.XmlDocument: ReadXml(reader, output); break; case Amf0TypeMarker.Reference: ReadReference(context, reader, output); break; case Amf0TypeMarker.Object: ReadObject(context, reader, output); break; case Amf0TypeMarker.TypedObject: ReadObject(context, reader, output, true); break; case Amf0TypeMarker.EcmaArray: ReadEcmaArray(context, reader, output); break; case Amf0TypeMarker.StrictArray: ReadStrictArray(context, reader, output); break; case Amf0TypeMarker.MovieClip: case Amf0TypeMarker.RecordSet: case Amf0TypeMarker.Unsupported: throw new NotSupportedException(string.Format(Errors.Amf0Deserializer_ReadValue_UnsupportedType, type)); default: throw new FormatException(string.Format(Errors.Amf0Decoder_ReadValue_UnknownType, (byte)type)); } if (output != null) output.Flush(); }