/// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="amfMessage"></param>
 public void WriteMessage(AmfPacket amfMessage)
 {
     try
     {
         base.WriteUInt16(amfMessage.Version);
         int headerCount = amfMessage.HeaderCount;
         base.WriteUInt16((ushort)headerCount);
         for(int i = 0; i < headerCount; i++)
         {
             this.WriteHeader(amfMessage.GetHeaderAt(i), ObjectEncoding.Amf0);
         }
         int bodyCount = amfMessage.BodyCount;
         base.WriteUInt16((ushort)bodyCount);
         for(int i = 0; i < bodyCount; i++)
         {
             AmfPacketBody amfBody = amfMessage.GetBodyAt(i);
             if (amfBody == null)
                 throw new InvalidOperationException("amfBody is null");
             amfBody.WriteBody(amfMessage.ObjectEncoding, this);
         }
     }
     catch(Exception)
     {
         throw;
     }
 }
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <returns></returns>
 public AmfPacket ReadAMFMessage()
 {
     // Version stored in the first two bytes.
     ushort version = base.ReadUInt16();
     AmfPacket message = new AmfPacket(version);
     // Read header count.
     int headerCount = base.ReadUInt16();
     for (int i = 0; i < headerCount; i++)
     {
         message.AddHeader(this.ReadHeader());
     }
     // Read header count.
     int bodyCount = base.ReadUInt16();
     for (int i = 0; i < bodyCount; i++)
     {
         AmfPacketBody amfBody = this.ReadBody();
         if( amfBody != null )//not failed
             message.AddBody(amfBody);
     }
     return message;
 }