Exemple #1
0
        static void Main(string[] args)
        {
            Dictionary <string, object> srcData = new Dictionary <string, object>();

            srcData["test"]  = 123;
            srcData["array"] = new string[] { "a", "b", "c" };

            byte[] buf0 = CAmf0Helper.GetBytes(srcData);
            Console.WriteLine("Amf0: {0}", BitConverter.ToString(buf0));
            object readBack0 = CAmf0Helper.GetObject(buf0);

            Console.WriteLine("decode: {0}", readBack0.ToString());
            Console.WriteLine();

            byte[] buf3 = CAmf3Helper.GetBytes(srcData);
            Console.WriteLine("Amf3: {0}", BitConverter.ToString(buf3));
            object readBack3 = CAmf3Helper.GetObject(buf3);

            Console.WriteLine("decode: {0}", readBack3.ToString());
            Console.WriteLine();
        }
Exemple #2
0
        protected static object ReadAmf(Stream stm, ref bool objEnd)
        {
            int  type = stm.ReadByte();
            bool oe   = true;

            switch ((DataType)type)
            {
            case DataType.Number:
                return(CDataHelper.BE_ReadDouble(stm));

            case DataType.Boolean:
                return(stm.ReadByte() != 0x0);

            case DataType.String:
                return(CDataHelper.BE_ReadShortStr(stm));

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

            case DataType.MovieClip:
                break;

            case DataType.Null:
                return(null);

            case DataType.Undefined:
                return(null);

            case DataType.Reference:
                break;

            case DataType.MixedArray:
                CDataHelper.BE_ReadUInt32(stm);     // highest numeric index
                return(ReadHashObject(stm));

            case DataType.EndOfObject:
                Trace.Assert(!objEnd, "此处不应出现EndOfObject");
                objEnd = true;
                return(null);

            case DataType.Array:
            {
                uint     len = CDataHelper.BE_ReadUInt32(stm);
                object[] ary = new object[len];
                for (uint i = 0; i < len; i++)
                {
                    ary[i] = ReadAmf(stm, ref oe);
                }
                return(ary);
            }

            case DataType.Date:
                break;

            case DataType.LongString:
                return(CDataHelper.BE_ReadLongStr(stm));

            case DataType.Unsupported:
                return(null);

            case DataType.Recordset:
                break;

            case DataType.XML:
                break;

            case DataType.TypedObject:
                break;

            case DataType.AMF3data:
                return(CAmf3Helper.Read(stm));

            default:
                break;
            }

            Trace.Assert(false, "暂未处理的数据类型");
            return(null);
        }
Exemple #3
0
 public static void Write3(Stream stm, object obj)
 {
     stm.WriteByte((byte)DataType.AMF3data);
     CAmf3Helper.Write(stm, obj);
 }