Ejemplo n.º 1
0
        protected static CMixArray ReadArray(Stream stm, CRefTable rt)
        {
            uint head = ReadInt(stm);

            int       count = (int)(head >> 1);
            CMixArray ary   = new CMixArray(count);

            for (string key = ReadString(stm, rt); key != ""; key = ReadString(stm, rt))
            {
                ary[key] = ReadAmf(stm, rt);
            }

            for (int i = 0; i < count; i++)
            {
                ary[i] = ReadAmf(stm, rt);
            }

            return(ary);
        }
Ejemplo n.º 2
0
 protected static void WriteAmf(Stream stm, object obj)
 {
     if (obj == null)
     {
         stm.WriteByte((byte)DataType.Null);
     }
     else if (obj is byte || (obj is int && (uint)(int)obj < MaxU29) || (obj is uint && (uint)obj < MaxU29))
     {
         stm.WriteByte((byte)DataType.Integer);
         WriteInt(stm, uint.Parse(obj.ToString()));
     }
     else if (obj is int || obj is uint || obj is float || obj is double)
     {
         stm.WriteByte((byte)DataType.Double);
         CDataHelper.BE_WriteDouble(stm, double.Parse(obj.ToString()));
     }
     else if (obj is bool)
     {
         if ((bool)obj)
         {
             stm.WriteByte((byte)DataType.True);
         }
         else
         {
             stm.WriteByte((byte)DataType.False);
         }
     }
     else if (obj is string)
     {
         stm.WriteByte((byte)DataType.String);
         WriteString(stm, obj as string);
     }
     else if (obj is CMixArray)
     {
         stm.WriteByte((byte)DataType.Array);
         CMixArray ary  = obj as CMixArray;
         uint      head = ((uint)ary.FixedLength << 1) | 1;
         WriteInt(stm, head);
         foreach (KeyValuePair <string, object> pair in ary.Dynamic)
         {
             WriteString(stm, pair.Key);
             WriteAmf(stm, pair.Value);
         }
         WriteString(stm, "");
         foreach (object o in ary.Fixed)
         {
             WriteAmf(stm, o);
         }
     }
     else if (obj is Array)
     {
         stm.WriteByte((byte)DataType.Array);
         Array ary  = obj as Array;
         uint  head = ((uint)ary.Length << 1) | 1;
         WriteInt(stm, head);
         WriteString(stm, "");
         foreach (object o in ary)
         {
             WriteAmf(stm, o);
         }
     }
     else if (obj is IDictionary)
     {
         stm.WriteByte((byte)DataType.Object);
         IDictionary dic  = obj as IDictionary;
         uint        head = 0x0B;
         WriteInt(stm, head);
         if (obj is CNameObjDict)
         {
             WriteString(stm, (obj as CNameObjDict).className);
         }
         else
         {
             WriteString(stm, "");
         }
         foreach (DictionaryEntry e in obj as IDictionary)
         {
             if (e.Key.ToString() == "" && e.Value is string)
             {
                 continue;
             }
             WriteString(stm, e.Key.ToString());
             WriteAmf(stm, e.Value);
         }
         WriteString(stm, "");
     }
     else
     {
         stm.WriteByte((byte)DataType.Undefined);
     }
 }