Beispiel #1
0
        public static int SizeDouble(int fieldIndex, double value)
        {
            if (value < double.Epsilon)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed64)) + 8);
        }
Beispiel #2
0
        public static int SizeFloat(int fieldIndex, float value)
        {
            if (value < float.Epsilon)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed32)) + 4);
        }
Beispiel #3
0
        public static int SizeBool(int fieldIndex, bool value)
        {
            if (value == false)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + 1);
        }
Beispiel #4
0
        public static int SizeUInt64(int fieldIndex, ulong value)
        {
            if (value == 0)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                   ComputeRawVarint64Size(value));
        }
Beispiel #5
0
        public static int SizeUInt32(int fieldIndex, uint value)
        {
            if (value == 0)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                   GetVarint32Size(value));
        }
Beispiel #6
0
        public static int SizeFloat(int fieldIndex, List <float> value)
        {
            if (value == null || value.Count == 0)
            {
                return(0);
            }

            int size = value.Count * 4;

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) +
                   GetVarint32Size((uint)size) +
                   size);
        }
Beispiel #7
0
        public static int SizeString(int fieldIndex, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(0);
            }

            int strLen = Encoding.UTF8.GetByteCount(value);

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                   GetVarint32Size((uint)strLen) +
                   strLen);
        }
Beispiel #8
0
        public static int SizeBytes(int fieldIndex, byte[] value)
        {
            if (value == null || value.Length == 0)
            {
                return(0);
            }

            int size = value.Length;

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) +
                   GetVarint32Size((uint)size) +
                   size);
        }
Beispiel #9
0
        public static int SizeInt64(int fieldIndex, long value)
        {
            if (value == 0)
            {
                return(0);
            }

            if (value > 0)
            {
                return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                       ComputeRawVarint64Size((ulong)value));
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed64)) + 8);
        }
Beispiel #10
0
        public static int SizeInt32(int fieldIndex, int value)
        {
            if (value == 0)
            {
                return(0);
            }

            if (value > 0)
            {
                return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                       GetVarint32Size((uint)value));
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed32)) + 4);
        }
Beispiel #11
0
        public static int SizeEnum <T>(int fieldIndex, List <T> value) where T : struct, IConvertible
        {
            if (value == null || value.Count == 0)
            {
                return(0);
            }

            int size = 0;

            for (int i = 0; i < value.Count; i++)
            {
                size += GetVarint32Size((uint)Convert.ToInt32(value[i]));
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) +
                   GetVarint32Size((uint)size) +
                   size);
        }
Beispiel #12
0
        public static int SizeStruct(int fieldIndex, IProtoStruct value)
        {
            if (value == null)
            {
                return(0);
            }

            var size = value.GetSize();

            if (size == 0)
            {
                return(0);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) +
                   GetVarint32Size((uint)size) +
                   size);
        }
Beispiel #13
0
        public static int SizeUInt64(int fieldIndex, List <ulong> value)
        {
            if (value == null || value.Count == 0)
            {
                return(0);
            }

            int size = 0;

            for (int i = 0; i < value.Count; i++)
            {
                size += ComputeRawVarint64Size(value[i]);
            }

            return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) +
                   GetVarint32Size((uint)size) +
                   size);
        }
Beispiel #14
0
 void WriteTag(int fieldNumber, WireFormat.WireType type)
 {
     WriteVarint32(WireFormat.MakeTag(fieldNumber, type));
 }