/// <summary> /// Read AMF packet version. /// </summary> /// <exception cref="FormatException">Data has unknown format.</exception> private static AmfVersion ReadPacketVersion(AmfStreamReader reader) { try { //First two bytes contain message version number return (AmfVersion)reader.ReadUInt16(); } catch (Exception e) { throw new FormatException(Errors.AmfPacketReader_ReadPacketVersion_VersionReadError, e); } }
/// <summary> /// Read a string. /// </summary> /// <remarks> /// Type declaration: /// <c>string-type = string-marker UTF-8</c> /// </remarks> private static string ReadString(AmfStreamReader reader, XmlWriter output = null) { //First 16 bits represents string's (UTF-8) length in bytes var length = reader.ReadUInt16(); var value = ReadUtf8(reader, length); if (output != null) { output.WriteStartElement(AmfxContent.String); output.WriteValue(value); output.WriteEndElement(); } return value; }
/// <summary> /// Read number of following headers/messages. /// </summary> private static uint ReadDataCount(AmfStreamReader reader) { return reader.ReadUInt16(); }
/// <summary> /// Read an object reference. /// </summary> /// <remarks> /// Type declaration: /// <c>reference-type = reference-marker U16</c> /// </remarks> private static void ReadReference(AmfContext context, AmfStreamReader reader, XmlWriter output = null) { var index = reader.ReadUInt16(); if (context.References.Count <= index) throw new SerializationException(string.Format(Errors.Amf0Decoder_ReadReference_BadIndex, index)); WriteReference(index, output); }