Exemplo n.º 1
0
        /// <summary>
        /// Adds a Serializer that can de/serialize objects of the specialized type to the Serializers
        /// </summary>
        /// <param name="type">Type that can be de/serialized</param>
        /// <param name="packetSerializer">The Serializer that can de/serialize objects of type</param>
        public static void AddSerializer(Type type, ASerializer packetSerializer)
        {
            if (CanSerialize(type))
            {
                return;
            }
            object key = BaseSerializer.GetKey(type);

            KeyTypeCache.Add(key, type);
            TypeKeyCache.Add(type, key);
            Serializers.Add(type, packetSerializer);
        }
Exemplo n.º 2
0
        public static byte[] WriteArray <T>(T[] input)
        {
            int                   len = input.Length;
            ASerializer           s   = SerializableTypes[typeof(T)];
            MemoryStream          ms  = new MemoryStream();
            PrimitiveValueWrapper pvw = new PrimitiveValueWrapper(ms);

            pvw.Write(len);
            for (int i = 0; i < input.Length; i++)
            {
                s.Serialize(pvw, input[i]);
            }
            pvw.CompleteWrite();
            byte[] ret = ms.ToArray();
            ms.Close();
            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a Serializer that can de/serialize objects of the specialized type to the Serializers
        /// </summary>
        /// <param name="type">Type that can be de/serialized</param>
        /// <param name="packetSerializer">The Serializer that can de/serialize objects of type</param>
        public void AddSerializer(Type type, ASerializer packetSerializer)
        {
            if (CanSerialize(type))
            {
                return;
            }

            if (Serializers.ContainsKey(type))
            {
                Console.WriteLine("");
            }

            object key = BaseSerializer.GetKey(type);

            KeyTypeCache.Add(key, type);
            TypeKeyCache.Add(type, key);
            Serializers.Add(type, packetSerializer);
        }
Exemplo n.º 4
0
        public static T[] ReadArray <T>(byte[] input)
        {
            int         len = ReadInt(input);
            ASerializer s   = SerializableTypes[typeof(T)];

            T[]          ret = new T[len];
            MemoryStream ms  = new MemoryStream(input);

            ms.Position = sizeof(int); //Move the Position to the begin of the array
            PrimitiveValueWrapper pvw = new PrimitiveValueWrapper(ms);

            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = (T)s.Deserialize(pvw);
            }

            return(ret);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeSerialization"/> class.
 /// </summary>
 /// <param name="internalSerializer">The internal serializer.</param>
 /// <param name="serializer">The serializer.</param>
 public CompositeSerialization(IInternalSerializer internalSerializer,
                               ASerializer serializer)
 {
     InternalSerializer = internalSerializer;
     Serializer         = serializer;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a Serializer that can de/serialize objects of type T to the Serializers
 /// </summary>
 /// <typeparam name="T">Type of object that is de/serializable</typeparam>
 /// <param name="packetSerializer">The Serializer that can de/serialize objects of type T</param>
 public void AddSerializer <T>(ASerializer packetSerializer)
 {
     AddSerializer(typeof(T), packetSerializer);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeSerialization"/> class.
 /// </summary>
 /// <param name="internalSerializer">The internal serializer.</param>
 /// <param name="serializer">The serializer.</param>
 public CompositeSerialization(IInternalSerializer internalSerializer,
     ASerializer serializer)
 {
     InternalSerializer = internalSerializer;
     Serializer = serializer;
 }