AMF协议的数据读取代码解析(1)(3)
- byte[] buffer=new byte[]{0x73,0x68,0x61,0x6E,0x67,0x67,0x75,0x61};//03 00 08 73 68 61 6E 67 67 75 61
- string str=System.Text.Encoding.UTF8.GetString(buffer);
3.Object在.net中对应的就是Hashtable,内容由UTF8字符串作为Key,其他AMF协议类型作为Value,该对象由3个字节:00 00 09来表示结束。C#中读取该对象使用如下方法:
- private Hashtable ReadUntypedObject()
- { Hashtable hash = new Hashtable();
- string key = ReadShortString();
- for (byte type = ReadByte(); type != 9; type = ReadByte())
- {hash.Add(key, ReadData(type));
- key = ReadShortString(); }
- return hash;}
4.Null就是空对象,该对象只占用一个字节,那就是Null对象标识0x05。
5. Undefined 也是只占用一个字节0x06。
6.MixedArray相当于Hashtable,与3不同的是该对象定义了Hashtable的大小。读取该对象的C#代码是:
- private Hashtable ReadDictionary()
- { int size = ReadInt32();
- Hashtable hash = new Hashtable(size);
- string key = ReadShortString();
- for (byte type = ReadByte(); type != 9; type = ReadByte())
- {object value = ReadData(type);
- hash.Add(key, value);
- key = ReadShortString(); }
- return hash;}
评论暂时关闭