Exemplo n.º 1
0
        private static int CalculateSize(Type value)
        {
            if (value == null)
            {
                return(SerializedSizeCalculatorHelper <Guid, SerializedSizeCalculator> .CalculateSerializedSize(Guid.Empty));
            }
            if (value.IsArray)
            {
                int num = SerializedSizeCalculatorHelper <Guid, SerializedSizeCalculator> .CalculateSerializedSize(SerializedSizeCalculator.arrayGuid);

                num += SerializedSizeCalculator.CalculateSize(value.GetElementType());
                return(num + SerializedSizeCalculator.CalculateSizeCount(value.Name.EndsWith("[]") ? 0 : value.GetArrayRank()));
            }
            if (value.IsGenericType)
            {
                int num2 = SerializedSizeCalculatorHelper <Guid, SerializedSizeCalculator> .CalculateSerializedSize(value.GetGenericTypeDefinition().GUID);

                foreach (Type value2 in value.GetGenericArguments())
                {
                    num2 += SerializedSizeCalculator.CalculateSize(value2);
                }
                return(num2);
            }
            return(SerializedSizeCalculatorHelper <Guid, SerializedSizeCalculator> .CalculateSerializedSize(value.GUID));
        }
Exemplo n.º 2
0
 private static int CalculateSize(ArraySegment <sbyte> value)
 {
     if (value.Array != null)
     {
         return(SerializedSizeCalculator.CalculateSizeCount(value.Count + 1) + value.Count);
     }
     return(1);
 }
Exemplo n.º 3
0
 private static int CalculateSize(ICollection <double> value)
 {
     if (value != null)
     {
         return(SerializedSizeCalculator.CalculateSizeCount(value.Count + 1) + value.Count * 8);
     }
     return(1);
 }
Exemplo n.º 4
0
 private static int CalculateSize(IList <bool> value)
 {
     if (value != null)
     {
         return(SerializedSizeCalculator.CalculateSizeCount(value.Count + 1) + value.Count);
     }
     return(1);
 }
Exemplo n.º 5
0
        public static Packet ToBinary(object value)
        {
            int             length          = SerializedSizeCalculator.Calculate <object>(value);
            SerializeWriter serializeWriter = new SerializeWriter(length, 0);

            SerializeWriterHelper <object, SerializeWriter> .Serialize(ref serializeWriter, value);

            return(serializeWriter.data);
        }
Exemplo n.º 6
0
        private static int CalculateSize(string value)
        {
            if (value == null)
            {
                return(1);
            }
            int byteCount = Encoding.UTF8.GetByteCount(value);

            return(SerializedSizeCalculator.CalculateSizeCount(byteCount + 1) + byteCount);
        }
Exemplo n.º 7
0
        private static int CalculateSize <T>(ICollection <T> values)
        {
            if (values == null)
            {
                return(1);
            }
            int num = SerializedSizeCalculator.CalculateSizeCount(values.Count + 1);

            foreach (T value in values)
            {
                num += SerializedSizeCalculatorHelper <T, SerializedSizeCalculator> .CalculateSerializedSize(value);
            }
            return(num);
        }
Exemplo n.º 8
0
        private static int CalculateSize(ICollection <string> values)
        {
            if (values == null)
            {
                return(1);
            }
            int num = SerializedSizeCalculator.CalculateSizeCount(values.Count + 1);

            foreach (string value in values)
            {
                num += SerializedSizeCalculator.CalculateSize(value);
            }
            return(num);
        }
Exemplo n.º 9
0
        private int CalculateSize(ICollection values)
        {
            if (values == null)
            {
                return(1);
            }
            int num = SerializedSizeCalculator.CalculateSizeCount(values.Count + 1);

            foreach (object value in values)
            {
                num += SerializedSizeCalculatorHelper <object, SerializedSizeCalculator> .CalculateSerializedSize(value);
            }
            return(num);
        }
Exemplo n.º 10
0
        private static int CalculateSize <T>(ArraySegment <T> value)
        {
            int num  = SerializedSizeCalculator.CalculateSizeCount(value.Count + 1);
            int i    = value.Offset;
            int num2 = value.Offset + value.Count;

            while (i < num2)
            {
                num += SerializedSizeCalculatorHelper <T, SerializedSizeCalculator> .CalculateSerializedSize(value.Array[i]);

                i++;
            }
            return(num);
        }
Exemplo n.º 11
0
        public static Packet ToBinary <T>(T value)
        {
            int categoryId = ClassInfo <T> .CategoryId;

            if (categoryId == 0)
            {
                return(SerializeWriter.ToBinary(value));
            }
            int             length          = SerializedSizeCalculator.Calculate <T>(value);
            SerializeWriter serializeWriter = new SerializeWriter(length, categoryId);

            SerializeWriterHelper <T, SerializeWriter> .Serialize(ref serializeWriter, value);

            return(serializeWriter.data);
        }
Exemplo n.º 12
0
        private static int CalculateSize(IList <Type> value)
        {
            if (value == null)
            {
                return(1);
            }
            int num   = SerializedSizeCalculator.CalculateSizeCount(value.Count + 1);
            int i     = 0;
            int count = value.Count;

            while (i < count)
            {
                num += SerializedSizeCalculator.CalculateSize(value[i]);
                i++;
            }
            return(num);
        }