예제 #1
0
        public void ReadRepeated <T>(AddRepeatedItem <T> addItem, RepeatedType <T> type,
                                     PrepareForRepeatedItems prepareForRepeatedItems = null)
        {
            var read = type.ReadElement;

            var tag = _lastTag;

            if (ProtoRepeatedInfo <T> .IsPackedRepeatedField(tag))
            {
                // packed

                // read repeated size
                var totalSize = ReadByteSize();
                if (totalSize <= 0)
                {
                    return;
                }

                // try call prepare to add items
                if (prepareForRepeatedItems != null)
                {
                    var fixedSize = ProtoSizeCalc.GetFixedBaseTypeSize(type.BaseType);
                    if (fixedSize != 0)
                    {
                        var count = totalSize / fixedSize;
                        prepareForRepeatedItems(count);
                    }
                }

                // set length limit for this message
                var captureLength = SetView(totalSize);
                // end here will return view's end
                while (!End)
                {
                    addItem(read(this));
                }
                RestoreView(captureLength);
            }
            else
            {
                do
                {
                    addItem(read(this));
                } while (ReadTagIfEquals(tag));
            }
        }
예제 #2
0
 public ProtoOutputStream(ProtoSizeCalc sizeCalc, byte[] buffer) : base(buffer)
 {
     _sizeCalc = sizeCalc;
 }
예제 #3
0
 public ProtoOutputStream(ProtoSizeCalc sizeCalc, byte[] buffer, int index, int count)
     : base(buffer, index, count)
 {
     _sizeCalc = sizeCalc;
 }