Пример #1
0
 private void Write(object obj)
 {
     if (obj is int @int)
     {
         WriteInt32(@int);
     }
     else if (obj is ushort @ushort)
     {
         WriteUShort(@ushort);
     }
     else if (obj is short @short)
     {
         WriteShort(@short);
     }
     else if (obj is bool @bool)
     {
         WriteBool(@bool);
     }
     else if (obj is long @long)
     {
         WriteLong(@long);
     }
     else if (obj is ulong @ulong)
     {
         WriteULong(@ulong);
     }
     else if (obj is byte @byte)
     {
         WriteByte(@byte);
     }
     else if (obj is float @float)
     {
         WriteFloat(@float);
     }
     else if (obj is double @double)
     {
         WriteDouble(@double);
     }
     else if (obj is byte[] bytes)
     {
         WritePrefixedBytes(bytes);
     }
     else if (obj is Enum)
     {
         Write(Convert.ToInt32(obj));
     }
     else if (obj is string @string)
     {
         WriteString(@string);
     }
     else if (obj is Array arr)
     {
         Write(arr.Length);
         foreach (object o in arr)
         {
             Write(o);
         }
     }
     else if (obj is IList list)
     {
         Write(list.Count);
         foreach (object o in list)
         {
             Write(o);
         }
     }
     else
     {
         ServerLog.Error($"MP ByteWriter.Write: Unknown type {obj.GetType()}");
     }
 }