aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Collections/RepeatedFieldExtensions.cs
blob: c5a934a1c5c402d813028e8256e1da20417a8096 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Google.Protobuf.Collections
{
    public static class RepeatedFieldExtensions
    {
        internal static uint CalculateSize<T>(this RepeatedField<T> list, Func<T, int> sizeComputer)
        {
            int size = 0;
            foreach (var item in list)
            {
                size += sizeComputer(item);
            }
            return (uint)size;
        }

        /*
        /// <summary>
        /// Calculates the serialized data size, including one tag per value.
        /// </summary>
        public static int CalculateTotalSize<T>(this RepeatedField<T> list, int tagSize, Func<T, int> sizeComputer)
        {
            if (list.Count == 0)
            {
                return 0;
            }
            return (int)(dataSize + tagSize * list.Count);
        }

        /// <summary>
        /// Calculates the serialized data size, as a packed array (tag, length, data).
        /// </summary>
        public static int CalculateTotalPackedSize(int tagSize)
        {
            if (Count == 0)
            {
                return 0;
            }
            uint dataSize = CalculateSize();
            return tagSize + CodedOutputStream.ComputeRawVarint32Size(dataSize) + (int)dataSize;
        }
        */
    }
}