Beispiel #1
0
 /*
  * Private Functions
  */
 private void AppendPacket(ref BitArray ba, ref Hashtable ht, ref PacketWriter pw, bool create = true)
 {
     for (int i = 0; i < ba.Length; i++) //Iterate each bit array, get hashtable values and append to the packet correctly
     {
         if (ba.Get(i) && ht[i] != null)
         {
             var data = ht[i];
             if (data is byte)
             {
                 pw.WriteUInt8((byte)ht[i]);
             }
             else if (data is sbyte)
             {
                 pw.WriteInt8((sbyte)ht[i]);
             }
             else if (data is UInt16)
             {
                 pw.WriteUInt16((UInt16)ht[i]);
             }
             else if (data is short)
             {
                 pw.WriteInt16((short)ht[i]);
             }
             else if (data is UInt32)
             {
                 pw.WriteUInt32((UInt32)ht[i]);
             }
             else if (data is int)
             {
                 pw.WriteInt32((int)ht[i]);
             }
             else if (data is UInt64)
             {
                 pw.WriteUInt64((UInt64)ht[i]);
             }
             else if (data is Int64)
             {
                 pw.WriteInt64((Int64)ht[i]);
             }
             else if (data is float)
             {
                 pw.WriteFloat((float)ht[i]);
             }
             else if (data is string)
             {
                 pw.WriteString((string)ht[i]);
             }
             else if (data is double)
             {
                 pw.WriteDouble((double)ht[i]);
             }
             else if (data is byte[])
             {
                 foreach (byte b in ((byte[])data)) //Adds a byte array as a list of uint8s
                 {
                     pw.WriteUInt8(b);
                 }
             }
         }
         else if (create)
         {
             pw.WriteUInt32(0);
         }
     }
 }