示例#1
0
 private void Write(AmfTypeCode code)
 {
     Stream.WriteByte((byte)code);
 }
        public object ReadNextObject()
        {
            int b = stream.ReadByte();

            if (b < 0)
            {
                throw new EndOfStreamException();
            }

            AmfTypeCode code = (AmfTypeCode)b;

            switch (code)
            {
            case AmfTypeCode.Number:
                return(ReadNumber());

            case AmfTypeCode.Boolean:
                return(ReadBoolean());

            case AmfTypeCode.String:
                return(ReadString());

            case AmfTypeCode.Object:
                return(ReadObject());

            case AmfTypeCode.Null:
                return(null);

            case AmfTypeCode.Undefined:
                return(null);

            case AmfTypeCode.EndOfObject:
                return(EndOfObjectMarker);

            case AmfTypeCode.Array:
                return(ReadArray());

            case AmfTypeCode.Date:
                return(ReadDate());

            case AmfTypeCode.LongString:
            case AmfTypeCode.Xml:
                return(ReadLongString());

            case AmfTypeCode.TypedObject:
                return(ReadTypedObject());

            case AmfTypeCode.Amf3Data:
                if (amf3Parser == null || !PreserveAmf3Context)
                {
                    amf3Parser = new Amf3Parser(stream);
                }

                Amf3Wrapper wrapper = new Amf3Wrapper(amf3Parser.ReadNextObject());

                if (!PreserveAmf3Context)
                {
                    amf3Parser = null;
                }

                return(wrapper);
            }

            throw new InvalidOperationException("Cannot parse type " + code);
        }