Exemplo n.º 1
0
        public static object ReadAmf(Stream stm, CRefTable rt)
        {
            int type = stm.ReadByte();

            switch ((DataType)type)
            {
            case DataType.Undefined:
                return(null);

            case DataType.Null:
                return(null);

            case DataType.False:
                //Console.WriteLine(false);
                return(false);

            case DataType.True:
                //Console.WriteLine(true);
                return(true);

            case DataType.Integer:
                uint aaa = ReadInt(stm);
                //Console.WriteLine(aaa);
                return(aaa);

            case DataType.Double:
                double aaa1 = CDataHelper.BE_ReadDouble(stm);
                //Console.WriteLine(aaa1);
                return(aaa1);

            case DataType.String:

                string sss = ReadString(stm, rt);
                //Console.WriteLine(sss);
                return(sss);

            case DataType.XmlDoc:
                break;

            case DataType.Date:
                break;

            case DataType.Array:
                return(ReadArray(stm, rt));

            case DataType.Object:
                return(ReadHashObject(stm, rt));

            case DataType.Xml:
                break;

            case DataType.ByteArray:
                return(CAmf3Helper.GetObject(ReadByteArray(stm, rt)));

            default:
                break;
            }
            //throw new Exception("暂未处理的数据类型"+type);
            return(null);
        }
Exemplo n.º 2
0
        public static CNameObjDict ReadHashObject(Stream stm, CRefTable rt)
        {
            uint       head = ReadInt(stm);
            CObjTraits ot   = null;

            if (IsRefrence(head))
            {
                return(rt.obj[(int)(head >> 1)]);
            }

            if (IsRefrence(head >> 1))
            {
                ot = rt.ot[(int)(head >> 2)];
            }
            else
            {
                ot = new CObjTraits();
                Trace.Assert(((head >> 2) & 0x1) == 0, "暂不支持");
                ot.dynamic = ((head >> 3) & 0x1) != 0;
                int count = (int)(head >> 4);
                ot.name = ReadString(stm, rt);
                ot.keys = new string[count];
                for (int i = 0; i < count; i++)
                {
                    ot.keys[i] = ReadString(stm, rt);
                }
                rt.ot.Add(ot);
            }

            CNameObjDict obj = new CNameObjDict(ot.name);

            for (int i = 0; i < ot.keys.Length; i++)
            {
                obj[ot.keys[i]] = ReadAmf(stm, rt);
            }

            //读取动态属性
            if (ot.dynamic)
            {
                while (true)
                {
                    string key = ReadString(stm, rt);
                    //Console.WriteLine(":::  " + key);
                    if (key == "")
                    {
                        break;
                    }

                    obj[key] = ReadAmf(stm, rt);
                }
            }

            rt.obj.Add(obj);

            return(obj);
        }
Exemplo n.º 3
0
        protected static object ReadAmf(Stream stm, CRefTable rt)
        {
            int type = stm.ReadByte();

            switch ((DataType)type)
            {
            case DataType.Undefined:
                return(null);

            case DataType.Null:
                return(null);

            case DataType.False:
                return(false);

            case DataType.True:
                return(true);

            case DataType.Integer:
                return(ReadInt(stm));

            case DataType.Double:
                return(CDataHelper.BE_ReadDouble(stm));

            case DataType.String:
                return(ReadString(stm, rt));

            case DataType.XmlDoc:
                break;

            case DataType.Date:
                break;

            case DataType.Array:
                return(ReadArray(stm, rt));

            case DataType.Object:
                return(ReadHashObject(stm, rt));

            case DataType.Xml:
                break;

            case DataType.ByteArray:
                break;

            default:
                break;
            }

            Trace.Assert(false, "暂未处理的数据类型");
            return(null);
        }
Exemplo n.º 4
0
        public static byte[] ReadByteArray(Stream stm, CRefTable rt)
        {
            uint head = ReadInt(stm);

            Trace.Assert((head & 0x1) == 0x1);

            int count = (int)(head >> 1);

            byte[] ary = new byte[count];

            for (int i = 0; i < count; i++)
            {
                ary[i] = (byte)stm.ReadByte();
            }

            return(ary);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        protected static string ReadString(Stream stm, CRefTable rt)
        {
            uint head = ReadInt(stm);
            int  len  = (int)(head >> 1);

            if (len <= 0)
            {
                return("");
            }

            if (IsRefrence(head))
            {
                return(rt.str[len]);
            }

            string str = CDataHelper.ReadUtfStr(stm, len);

            rt.str.Add(str);

            return(str);
        }
Exemplo n.º 7
0
        public static CMixArray ReadArray(Stream stm, CRefTable rt)
        {
            uint head = ReadInt(stm);

            Trace.Assert((head & 0x1) == 0x1);

            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);
        }