當前位置: 首頁>>代碼示例>>C#>>正文


C# ProtoWriter.PopRecursionStack方法代碼示例

本文整理匯總了C#中ProtoBuf.ProtoWriter.PopRecursionStack方法的典型用法代碼示例。如果您正苦於以下問題:C# ProtoWriter.PopRecursionStack方法的具體用法?C# ProtoWriter.PopRecursionStack怎麽用?C# ProtoWriter.PopRecursionStack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProtoBuf.ProtoWriter的用法示例。


在下文中一共展示了ProtoWriter.PopRecursionStack方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EndSubItem

        private static void EndSubItem(SubItemToken token, ProtoWriter writer, PrefixStyle style)
        {
            if (writer.wireType != WireType.None) { throw CreateException(writer); }
            int value = token.value;
            if (writer.depth <= 0) throw CreateException(writer);
            if (writer.depth-- > RecursionCheckDepth)
            {
                writer.PopRecursionStack();
            }
            writer.packedFieldNumber = 0; // ending the sub-item always wipes packed encoding
            if (value < 0)
            {   // group - very simple append
                WriteHeaderCore(-value, WireType.EndGroup, writer);
                writer.wireType = WireType.None;
                return;
            }

            // so we're backfilling the length into an existing sequence
            int len;
            switch(style)
            {
                case PrefixStyle.Fixed32:
                    len = (int)((writer.ioIndex - value) - 4);
                    ProtoWriter.WriteInt32ToBuffer(len, writer.ioBuffer, value);
                    break;
                case PrefixStyle.Fixed32BigEndian:
                    len = (int)((writer.ioIndex - value) - 4);
                    byte[] buffer = writer.ioBuffer;
                    ProtoWriter.WriteInt32ToBuffer(len, buffer, value);
                    // and swap the byte order
                    byte b = buffer[value];
                    buffer[value] = buffer[value + 3];
                    buffer[value + 3] = b;
                    b = buffer[value + 1];
                    buffer[value + 1] = buffer[value + 2];
                    buffer[value + 2] = b;
                    break;
                case PrefixStyle.Base128:
                    // string - complicated because we only reserved one byte;
                    // if the prefix turns out to need more than this then
                    // we need to shuffle the existing data
                    len = (int)((writer.ioIndex - value) - 1);
                    int offset = 0;
                    uint tmp = (uint)len;
                    while ((tmp >>= 7) != 0) offset++;
                    if (offset == 0)
                    {
                        writer.ioBuffer[value] = (byte)(len & 0x7F);
                    }
                    else
                    {
                        DemandSpace(offset, writer);
                        byte[] blob = writer.ioBuffer;
                        Helpers.BlockCopy(blob, value + 1, blob, value + 1 + offset, len);
                        tmp = (uint)len;
                        do
                        {
                            blob[value++] = (byte)((tmp & 0x7F) | 0x80);
                        } while ((tmp >>= 7) != 0);
                        blob[value - 1] = (byte)(blob[value - 1] & ~0x80);
                        writer.position += offset;
                        writer.ioIndex += offset;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException("style");
            }
            // and this object is no longer a blockage
            writer.flushLock--;
        }
開發者ID:nilavghosh,項目名稱:ProtoBuf_Net,代碼行數:70,代碼來源:ProtoWriter.cs

示例2: EndSubItem

 private static void EndSubItem(SubItemToken token, ProtoWriter writer, PrefixStyle style)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (writer.wireType != WireType.None)
     {
         throw ProtoWriter.CreateException(writer);
     }
     int value = token.value;
     if (writer.depth <= 0)
     {
         throw ProtoWriter.CreateException(writer);
     }
     if (writer.depth-- > 25)
     {
         writer.PopRecursionStack();
     }
     writer.packedFieldNumber = 0;
     if (value < 0)
     {
         ProtoWriter.WriteHeaderCore(-value, WireType.EndGroup, writer);
         writer.wireType = WireType.None;
         return;
     }
     switch (style)
     {
     case PrefixStyle.Base128:
     {
         int num = writer.ioIndex - value - 1;
         int num2 = 0;
         uint num3 = (uint)num;
         while ((num3 >>= 7) != 0u)
         {
             num2++;
         }
         if (num2 == 0)
         {
             writer.ioBuffer[value] = (byte)(num & 127);
         }
         else
         {
             ProtoWriter.DemandSpace(num2, writer);
             byte[] array = writer.ioBuffer;
             Helpers.BlockCopy(array, value + 1, array, value + 1 + num2, num);
             num3 = (uint)num;
             do
             {
                 array[value++] = (byte)((num3 & 127u) | 128u);
             }
             while ((num3 >>= 7) != 0u);
             array[value - 1] = (byte)((int)array[value - 1] & -129);
             writer.position += num2;
             writer.ioIndex += num2;
         }
         break;
     }
     case PrefixStyle.Fixed32:
     {
         int num = writer.ioIndex - value - 4;
         ProtoWriter.WriteInt32ToBuffer(num, writer.ioBuffer, value);
         break;
     }
     case PrefixStyle.Fixed32BigEndian:
     {
         int num = writer.ioIndex - value - 4;
         byte[] array2 = writer.ioBuffer;
         ProtoWriter.WriteInt32ToBuffer(num, array2, value);
         byte b = array2[value];
         array2[value] = array2[value + 3];
         array2[value + 3] = b;
         b = array2[value + 1];
         array2[value + 1] = array2[value + 2];
         array2[value + 2] = b;
         break;
     }
     default:
         throw new ArgumentOutOfRangeException("style");
     }
     if (--writer.flushLock == 0 && writer.ioIndex >= 1024)
     {
         ProtoWriter.Flush(writer);
     }
 }
開發者ID:floatyears,項目名稱:Decrypt,代碼行數:85,代碼來源:ProtoWriter.cs


注:本文中的ProtoBuf.ProtoWriter.PopRecursionStack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。