private static AMF0ObjectProperty FromBody(RTMPMessageBody body) { BinaryReader br = body.MemoryReader; ushort namelen = br.ReadUShort(); byte next = br.ReadByte(); if (namelen == 0 && next == 9) { return(null); } br.BaseStream.Position--; string name = body.ReadString(namelen); //Encoding.UTF8.GetString(bytes, index, namelen); byte type = br.ReadByte(); switch (type) { case 0: //number double var = br.ReadDouble(); //BitConverter.ToDouble(bytes, index); return(new AMF0ObjectProperty(name, var)); case 2: //string ushort strlen = br.ReadUShort(); //BitConverter.ToUInt16(bytes, index); string value = body.ReadString(strlen); //Encoding.UTF8.GetString(bytes, index, strlen); return(new AMF0ObjectProperty(name, value)); case 8: //ECMA array uint arrayLength = br.ReadUInt(); //BitConverter.ToUInt32(bytes, index); AMF0ECMAArray array = new AMF0ECMAArray(); AMF0ObjectProperty arrayprop; while ((arrayprop = FromBody(body)) != null) { array.props.Add(arrayprop); } return(new AMF0ObjectProperty(name, array)); default: throw new Exception("not yet implemented type"); } }
private static AMF0ObjectProperty FromBody(RTMPMessageBody body) { BinaryReader br = body.MemoryReader; ushort namelen = br.ReadUShort(); byte next = br.ReadByte(); if (namelen == 0 && next == 9) { return null; } br.BaseStream.Position--; string name = body.ReadString(namelen);//Encoding.UTF8.GetString(bytes, index, namelen); byte type = br.ReadByte(); switch (type) { case 0://number double var = br.ReadDouble();//BitConverter.ToDouble(bytes, index); return new AMF0ObjectProperty(name, var); case 2://string ushort strlen = br.ReadUShort();//BitConverter.ToUInt16(bytes, index); string value = body.ReadString(strlen);//Encoding.UTF8.GetString(bytes, index, strlen); return new AMF0ObjectProperty(name, value); case 8://ECMA array uint arrayLength = br.ReadUInt();//BitConverter.ToUInt32(bytes, index); AMF0ECMAArray array = new AMF0ECMAArray(); AMF0ObjectProperty arrayprop; while ((arrayprop = FromBody(body)) != null) { array.props.Add(arrayprop); } return new AMF0ObjectProperty(name, array); default: throw new Exception("not yet implemented type"); } }