Exemplo n.º 1
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.WriteList(TestList);
     typeWriter.Write(TestBool);
     typeWriter.Write(TestInt);
     typeWriter.Write(TestFloat);
 }
 protected override void SerializeRequestBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(RoomId);
     typeWriter.Write(CurrentPlayerCount);
     typeWriter.Write((byte)State);
     typeWriter.Write(MaxMatchMakingWeight);
 }
Exemplo n.º 3
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(RoomId);
     typeWriter.Write(MaxPlayers);
     typeWriter.Write(CurrentPlayers);
     typeWriter.WriteDictionary(RoomProperties, typeWriter.Write);
     typeWriter.Write((byte)State);
 }
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.Write((byte)ResultCode);
     typeWriter.Write(Message);
     if (ResultCode == ResultCode.OK)
     {
         SerializeResponseBody(typeWriter);
     }
 }
Exemplo n.º 5
0
 public void Serialize(ITypeWriter typeWriter)
 {
     typeWriter.Write((byte)this.ResultCode);
     typeWriter.Write(this.Message);
     if (this.ResultCode != ResultCode.OK)
     {
         return;
     }
     this.SerializeResponseBody(typeWriter);
 }
Exemplo n.º 6
0
 protected override void SerializeRequestBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(RoomId);
     typeWriter.Write(Players.Count);
     foreach (var property in Players)
     {
         typeWriter.Write(property.Key);
         typeWriter.WriteDictionary(property.Value, typeWriter.Write);
     }
 }
Exemplo n.º 7
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     lock (_mutex)
     {
         typeWriter.Write(IntChanges);
         typeWriter.Write(NullableIntChanges);
         typeWriter.Write(ByteChanges);
         typeWriter.Write(NullableByteChanges);
         typeWriter.Write(NullableFloatChanges);
     }
 }
 public void Serialize(ITypeWriter typeWriter)
 {
     typeWriter.Write((byte)this.ServerRole);
     typeWriter.Write(this.Address);
     typeWriter.Write(Ports.Count);
     foreach (var port in Ports)
     {
         typeWriter.Write(port);
     }
     typeWriter.Write(this.PortsString);
 }
Exemplo n.º 9
0
 public static void WriteNullable <T>(this ITypeWriter writer, T obj) where T : class, ISerializable
 {
     if (obj != null)
     {
         writer.Write(true);
         writer.Write(obj);
     }
     else
     {
         writer.Write(false);
     }
 }
Exemplo n.º 10
0
 public static void Write(this ITypeWriter writer, Guid?guid)
 {
     if (guid.HasValue)
     {
         writer.Write((byte)1);
         writer.Write(guid.Value);
     }
     else
     {
         writer.Write((byte)0);
     }
 }
Exemplo n.º 11
0
 public static void Write(this ITypeWriter typeWriter, byte?value)
 {
     if (value == null)
     {
         typeWriter.Write(false);
     }
     else
     {
         typeWriter.Write(true);
         typeWriter.Write(value.Value);
     }
 }
 public static void WriteList(this ITypeWriter bw, IList <string> list)
 {
     if (list != null && list.Any())
     {
         bw.Write(list.Count);
         for (var i = 0; i < list.Count; i++)
         {
             bw.Write(list[i]);
         }
     }
     else
     {
         bw.Write(0);
     }
 }
 public static void WriteList <T>(this ITypeWriter bw, ICollection <T> list)
     where T : ISerializable
 {
     if (list != null)
     {
         bw.Write(list.Count);
         foreach (var el in list)
         {
             el.Serialize(bw);
         }
     }
     else
     {
         bw.Write(0);
     }
 }
        public static void Write(this ITypeWriter serializer, ConcurrentDictionary <int, ConcurrentDictionary <byte, byte> > dict)
        {
            if (dict == null)
            {
                dict = new ConcurrentDictionary <int, ConcurrentDictionary <byte, byte> >();
            }
            serializer.Write(dict.Count);

            foreach (var item in dict)
            {
                serializer.Write(item.Key);
                serializer.Write(item.Value.Count);
                foreach (var subItem in item.Value)
                {
                    serializer.Write((byte)subItem.Key);
                    serializer.Write(subItem.Value);
                }
            }
        }
        public static void Write(this ITypeWriter typeWriter, HashSet <int> hashSet)
        {
            try
            {
                if (hashSet == null)
                {
                    hashSet = new HashSet <int>();
                }

                typeWriter.Write(hashSet.Count());
                foreach (var item in hashSet)
                {
                    typeWriter.Write(item);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"Error serializing HashSet<int>: {e}");
            }
        }
Exemplo n.º 16
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(ServerIpAddress);
     typeWriter.Write(ServerPort);
     typeWriter.Write(RoomId);
     typeWriter.Write((byte)Status);
     typeWriter.Write(CurrentPlayers);
     typeWriter.Write(MaxPlayers);
     typeWriter.Write(JoinToExisting);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Please, avoid such structures in code
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="dict"></param>
        /// <param name="writeKey"></param>
        /// <typeparam name="TKey"></typeparam>
        public static void WriteDictionary <TKey>(this ITypeWriter writer, Dictionary <TKey, object> dict,
                                                  Action <TKey> writeKey)
        {
            var dictCount = dict.Count;

            writer.Write(dictCount);

            foreach (var entry in dict)
            {
                writeKey(entry.Key);
                WriteObjectValue(writer, entry);
            }
        }
 protected override void SerializeRequestBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(ServerIdentity);
     typeWriter.Write(Name);
     typeWriter.Write(Region);
     typeWriter.Write(PeersCount);
     typeWriter.Write(HttpPort);
     typeWriter.Write(HttpsPort);
 }
Exemplo n.º 19
0
            public async Task StartVisit(ILabeledTreeNode <TypeContext[]> node)
            {
                if (node.Path.Equals(NodePath.RootPath))
                {
                    return;
                }

                var pathLabel = node.Path.GetNodeLabel();
                await _writer.WriteLineAsync($"package {pathLabel} {{");

                foreach (var typeContext in node.Data)
                {
                    WrittenTypes.Add(typeContext.Type);
                    _typeWriter.Write(_writer, typeContext.Type);
                }
            }
        public static void WriteEntity <T>(this ITypeWriter typeWriter, T entity)
            where T : EntityBase
        {
            try
            {
                typeWriter.Write(entity != null);

                if (entity == null)
                {
                    return;
                }

                entity.Serialize(typeWriter);
            }
            catch (Exception e)
            {
                throw new Exception($"Error serializing entity <{typeof(T)}>: {e}");
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Saves the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="format">The format.</param>
        public void Save(object value, Stream stream, IFormat format)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            ITypeWriter contentWriter = this.GetWriter(value.GetType());

            if (contentWriter.BypassFormat)
            {
                format = Format.None;
            }

            using (IFormatWriter formatWriter = format.CreateWriter(stream))
            {
                contentWriter.Write(formatWriter, value);
            }
        }
Exemplo n.º 22
0
        private static void WriteObjectValue <TKey>(ITypeWriter writer, KeyValuePair <TKey, object> entry)
        {
            var value = entry.Value;

            if (value == null)
            {
                value = "";
            }

            writer.Write(SwitchTypeToValue[value.GetType()]);


            if (!SwitchWrite.ContainsKey(value.GetType()))
            {
                throw new Exception($"Type {value.GetType()} is not supported by Write method");
            }

            SwitchWrite[value.GetType()](writer, value);
        }
        public static void Write <T>(this ITypeWriter typeWriter, EntityDictionary <T> list)
            where T : EntityBase
        {
            EntityDictionary <T> list1 = list;

            try
            {
                if (list1 == null)
                {
                    list1 = new EntityDictionary <T>();
                }

                typeWriter.Write(list1.Count());
                foreach (var item in list1)
                {
                    item.Serialize(typeWriter);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"Error serializing EntityDictionary<{typeof(T)}>: {e}");
            }
        }
Exemplo n.º 24
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.WriteList(UpdatedInfoList);
     typeWriter.Write(ChangeId);
 }
 protected override void SerializeResponseBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(CanJoin);
 }
 protected override void SerializeResponseBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(BundleUri);
 }
Exemplo n.º 27
0
 protected override void SerializeBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(Address);
     typeWriter.Write(Ports);
     typeWriter.Write((byte)ServerRole);
     typeWriter.Write(Name);
     typeWriter.Write(Region);
     typeWriter.Write(ClientVersion);
     typeWriter.Write(ActualizedOn);
     typeWriter.Write(IsApproved);
     typeWriter.Write(PeerCount);
     typeWriter.Write(HttpPort);
     typeWriter.Write(HttpsPort);
 }
 protected override void SerializeRequestBody(ITypeWriter typeWriter)
 {
     typeWriter.WriteDictionary(MatchMakingProperties, typeWriter.Write);
     typeWriter.Write(MatchMakingWeight);
 }
Exemplo n.º 29
0
 protected override void SerializeRequestBody(ITypeWriter typeWriter)
 {
     typeWriter.Write(RoomId);
 }
Exemplo n.º 30
0
 public static void Write(this ITypeWriter writer, DateTime?dateTime)
 {
     writer.Write(dateTime?.ToBinary() ?? 0L);
 }