예제 #1
0
        public AMFMessage ReadAMFMessage()
        {
            // Version stored in the first two bytes.
            ushort version = base.ReadUInt16();

            AMFMessage message = new AMFMessage(version);

            // Read header count.
            int headerCount = base.ReadUInt16();

            for (int i = 0; i < headerCount; i++)
            {
                message.AddHeader(ReadHeader());
            }

            // Read header count.
            int bodyCount = base.ReadUInt16();

            for (int i = 0; i < bodyCount; i++)
            {
                AMFBody amfBody = ReadBody();

                if (amfBody != null)
                {
                    message.AddBody(amfBody);
                }
            }

            return(message);
        }
예제 #2
0
        public void WriteMessage(AMFMessage amfMessage)
        {
            try
            {
                base.WriteShort(amfMessage.Version);

                int headerCount = amfMessage.HeaderCount;

                base.WriteShort(headerCount);

                for (int i = 0; i < headerCount; i++)
                {
                    this.WriteHeader(amfMessage.GetHeaderAt(i), ObjectEncoding.AMF0);
                }

                int bodyCount = amfMessage.BodyCount;

                base.WriteShort(bodyCount);

                for (int i = 0; i < bodyCount; i++)
                {
                    ResponseBody responseBody = amfMessage.GetBodyAt(i) as ResponseBody;

                    if (responseBody != null && !responseBody.IgnoreResults)
                    {
                        if (this.BaseStream.CanSeek)
                        {
                            long position = this.BaseStream.Position;

                            try
                            {
                                responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                            }
                            catch (Exception exception)
                            {
                                throw exception;
                            }
                        }
                        else
                        {
                            responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody amfBody = amfMessage.GetBodyAt(i);

                        amfBody.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }